about summary refs log tree commit diff stats
path: root/chessboard.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-04-27 22:28:55 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-04-27 22:28:55 -0700
commit5b22547bb352f6e5a98ddd8ff42f37861a8e16ea (patch)
treecf531cce10d5f570f55dd54a46361dad882a14f6 /chessboard.mu
parentb1ddb414006352b2d3af3652263a536acbd2702e (diff)
downloadmu-5b22547bb352f6e5a98ddd8ff42f37861a8e16ea.tar.gz
2880
Turns out we don't need a primitive to return an empty value of
arbitrary type. Just create it on the heap using 'new'.

But this uncovered *yet* another bug, sigh. When I specialize generic
functions I was running all transforms on the generated functions after
specialization completed. But there's one transform that includes code
from elsewhere. If such code included type-ingredients -- kaboom. Now
fixed and there's a test, so I've got that going for me which is nice.
Diffstat (limited to 'chessboard.mu')
-rw-r--r--chessboard.mu11
1 files changed, 7 insertions, 4 deletions
diff --git a/chessboard.mu b/chessboard.mu
index 7ead26cb..57e40b19 100644
--- a/chessboard.mu
+++ b/chessboard.mu
@@ -260,7 +260,8 @@ def read-move stdin:address:source:character, screen:address:screen -> result:ad
 def read-file stdin:address:source:character, screen:address:screen -> file:number, quit:boolean, error:boolean, stdin:address:source:character, screen:address:screen [
   local-scope
   load-ingredients
-  c:character, stdin <- read stdin
+  c:character, eof?:boolean, stdin <- read stdin
+  return-if eof?, 0/dummy, 1/quit, 0/error
   {
     q-pressed?:boolean <- equal c, 81/Q
     break-unless q-pressed?
@@ -302,11 +303,12 @@ def read-file stdin:address:source:character, screen:address:screen -> file:numb
   return file, 0/quit, 0/error
 ]
 
-# valid values: 0-7, -1 (quit), -2 (error)
+# valid values for rank: 0-7
 def read-rank stdin:address:source:character, screen:address:screen -> rank:number, quit?:boolean, error?:boolean, stdin:address:source:character, screen:address:screen [
   local-scope
   load-ingredients
-  c:character, stdin <- read stdin
+  c:character, eof?:boolean, stdin <- read stdin
+  return-if eof?, 0/dummy, 1/quit, 0/error
   {
     q-pressed?:boolean <- equal c, 8/Q
     break-unless q-pressed?
@@ -347,7 +349,8 @@ def read-rank stdin:address:source:character, screen:address:screen -> rank:numb
 def expect-from-channel stdin:address:source:character, expected:character, screen:address:screen -> result:boolean, stdin:address:source:character, screen:address:screen [
   local-scope
   load-ingredients
-  c:character, stdin <- read stdin
+  c:character, eof?:boolean, stdin <- read stdin
+  return-if eof? 1/true
   {
     match?:boolean <- equal c, expected
     break-if match?