diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-05-14 12:39:12 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-05-14 12:39:12 -0700 |
commit | 5d6d9110314f68ad8d43bfab1e2b50886c1cde9f (patch) | |
tree | f7cedd9d0631feaf69a37cb1a873fea716d4205a | |
parent | 85da949ef338205566cda37f63b523933aa020bf (diff) | |
download | mu-5d6d9110314f68ad8d43bfab1e2b50886c1cde9f.tar.gz |
1372 - new chessboard test no longer hanging
Still failing, though.
-rw-r--r-- | 061channel.mu | 3 | ||||
-rw-r--r-- | 074keyboard.mu | 2 | ||||
-rw-r--r-- | 075scenario_keyboard.cc | 10 | ||||
-rw-r--r-- | 076scenario_keyboard_test.mu | 10 | ||||
-rw-r--r-- | chessboard.mu | 39 |
5 files changed, 37 insertions, 27 deletions
diff --git a/061channel.mu b/061channel.mu index 7082d663..e3f039dd 100644 --- a/061channel.mu +++ b/061channel.mu @@ -320,6 +320,9 @@ recipe buffer-lines [ line:address:buffer <- buffer-append line:address:buffer, c:character line-done?:boolean <- equal c:character, 10:literal/newline break-if line-done?:boolean + # stop buffering on eof (currently only generated by fake keyboard) + empty-fake-keyboard?:boolean <- equal c:character, 0:literal/eof + break-if empty-fake-keyboard?:boolean loop } #? return-to-console #? 1 diff --git a/074keyboard.mu b/074keyboard.mu index 34f6789c..a991a71b 100644 --- a/074keyboard.mu +++ b/074keyboard.mu @@ -29,7 +29,7 @@ recipe read-key [ { done?:boolean <- greater-or-equal idx:address:number/deref, max:number break-unless done?:boolean - reply 0:literal, 0:literal/found, x:address:keyboard/same-as-ingredient:0 + reply 0:literal/eof, 1:literal/found, x:address:keyboard/same-as-ingredient:0 } c:character <- index buf:address:array:character/deref, idx:address:number/deref idx:address:number/deref <- add idx:address:number/deref, 1:literal diff --git a/075scenario_keyboard.cc b/075scenario_keyboard.cc index 0de6a2eb..039f10c8 100644 --- a/075scenario_keyboard.cc +++ b/075scenario_keyboard.cc @@ -15,13 +15,13 @@ scenario keyboard-in-scenario [ ] memory-should-contain [ 1 <- 97 # 'a' - 2 <- 1 # first read-key call found a character + 2 <- 1 3 <- 98 # 'b' - 4 <- 1 # second read-key call found a character + 4 <- 1 5 <- 99 # 'c' - 6 <- 1 # third read-key call found a character - 7 <- 0 - 8 <- 0 # fourth read-key call didn't find a character + 6 <- 1 + 7 <- 0 # eof + 8 <- 1 ] ] diff --git a/076scenario_keyboard_test.mu b/076scenario_keyboard_test.mu index 67a965b1..7e6ccee3 100644 --- a/076scenario_keyboard_test.mu +++ b/076scenario_keyboard_test.mu @@ -12,12 +12,12 @@ scenario read-key-in-mu [ ] memory-should-contain [ 1 <- 97 # 'a' - 2 <- 1 # first read-key call found a character + 2 <- 1 3 <- 98 # 'b' - 4 <- 1 # second read-key call found a character + 4 <- 1 5 <- 99 # 'c' - 6 <- 1 # third read-key call found a character - 7 <- 0 - 8 <- 0 # fourth read-key call didn't find a character + 6 <- 1 + 7 <- 0 # eof + 8 <- 1 ] ] diff --git a/chessboard.mu b/chessboard.mu index 101078b8..dd0d388f 100644 --- a/chessboard.mu +++ b/chessboard.mu @@ -27,8 +27,10 @@ recipe main [ scenario print-board-and-read-move [ assume-screen 30:literal/width, 12:literal/height + # initialize keyboard to type in a move, then quit assume-keyboard [a2-a4 -] # newline is important +q +] run [ screen:address, keyboard:address <- chessboard screen:address, keyboard:address ] @@ -38,9 +40,9 @@ scenario print-board-and-read-move [ .7 | p p p p p p p p . .6 | . .5 | . - .4 | . + .4 | P . .3 | . - .2 | P P P P P P P P . + .2 | P P P P P P P . .1 | R N B Q K B N R . . +---------------- . . a b c d e f g h . @@ -50,13 +52,13 @@ scenario print-board-and-read-move [ ] recipe chessboard [ -#? $start-tracing [schedule] #? 1 +#? $start-tracing [schedule] #? 2 #? $start-tracing #? 1 default-space:address:array:location <- new location:type, 30:literal screen:address <- next-ingredient keyboard:address <- next-ingredient - $print [screen: ], screen:address, [, keyboard: ], keyboard:address, [ -] +#? $print [screen: ], screen:address, [, keyboard: ], keyboard:address, [ +#? ] #? 1 board:address:array:address:array:character <- initial-position # hook up stdin stdin:address:channel <- init-channel 10:literal/capacity @@ -68,31 +70,31 @@ recipe chessboard [ msg:address:array:character <- new [Stupid text-mode chessboard. White pieces in uppercase; black pieces in lowercase. No checking for legal moves. ] print-string screen:address, msg:address:array:character - $print [aaa -] +#? $print [aaa +#? ] #? 1 cursor-to-next-line screen:address print-board screen:address, board:address:array:address:array:character cursor-to-next-line screen:address msg:address:array:character <- new [Type in your move as <from square>-<to square>. For example: 'a2-a4'. Then press <enter>. ] print-string screen:address, msg:address:array:character - $print [bbb -] +#? $print [bbb +#? ] #? 1 cursor-to-next-line screen:address msg:address:array:character <- new [Hit 'q' to exit. ] print-string screen:address, msg:address:array:character - $print [ccc -] +#? $print [ccc +#? ] #? 1 { cursor-to-next-line screen:address msg:address:array:character <- new [move: ] print-string screen:address, msg:address:array:character - $print [ddd -] +#? $print [ddd +#? ] #? 1 m:address:move, quit:boolean, error:boolean <- read-move buffered-stdin:address:channel, screen:address - $print [eee -] +#? $print [eee +#? ] #? 1 break-if quit:boolean, +quit:offset buffered-stdin:address:channel <- clear-channel buffered-stdin:address:channel # cleanup after error. todo: test this? loop-if error:boolean @@ -298,6 +300,11 @@ recipe read-file [ reply 0:literal/dummy, 1:literal/quit, 0:literal/error } { + empty-fake-keyboard?:boolean <- equal c:character, 0:literal/eof + break-unless empty-fake-keyboard?:boolean + reply 0:literal/dummy, 1:literal/quit, 0:literal/error + } + { newline?:boolean <- equal c:character, 10:literal/newline break-unless newline?:boolean error-message:address:array:character <- new [that's not enough] |