about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-01-18 11:55:22 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-01-18 11:55:22 -0800
commit4d1f6bd73041c11a58287816a6b645df32b4dff1 (patch)
treeda4aa54e951a2062efecfec6366f63fa8fa3b8e9
parentaa253cd371753751bbe3e233978407b71ca28526 (diff)
downloadmu-4d1f6bd73041c11a58287816a6b645df32b4dff1.tar.gz
593 - clean up the raw stdin address
-rw-r--r--chessboard-cursor.arc.t47
-rw-r--r--chessboard-cursor.mu26
2 files changed, 39 insertions, 34 deletions
diff --git a/chessboard-cursor.arc.t b/chessboard-cursor.arc.t
index 43e6890b..991db2c5 100644
--- a/chessboard-cursor.arc.t
+++ b/chessboard-cursor.arc.t
@@ -6,29 +6,30 @@
 (add-code
   '((function! main [
       (default-space:space-address <- new space:literal 30:literal/capacity)
-      (1:channel-address/raw <- init-channel 1:literal)
+      (stdin:channel-address <- init-channel 1:literal)
       (screen:terminal-address <- init-fake-terminal 20:literal 10:literal)
       (2:string-address/raw <- get screen:terminal-address/deref data:offset)
-      (r:integer/routine <- fork read-move:fn nil:literal/globals 2000:literal/limit screen:terminal-address)
+      (r:integer/routine <- fork read-move:fn nil:literal/globals 2000:literal/limit stdin:channel-address screen:terminal-address)
       (c:character <- copy ((#\a literal)))
       (x:tagged-value <- save-type c:character)
-      (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value)
+      (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
       (c:character <- copy ((#\2 literal)))
       (x:tagged-value <- save-type c:character)
-      (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value)
+      (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
       (c:character <- copy ((#\- literal)))
       (x:tagged-value <- save-type c:character)
-      (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value)
+      (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
       (c:character <- copy ((#\a literal)))
       (x:tagged-value <- save-type c:character)
-      (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value)
+      (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
       (c:character <- copy ((#\4 literal)))
       (x:tagged-value <- save-type c:character)
-      (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value)
+      (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
       (sleep until-routine-done:literal r:integer/routine)
      ])))
 ;? (set dump-trace*)
 ;? (= dump-trace* (obj whitelist '("schedule")))
+;? (= dump-trace* (obj whitelist '("schedule" "run")))
 (run 'main)
 (each routine completed-routines*
 ;?   (prn "  " routine)
@@ -46,22 +47,22 @@
 (add-code
   '((function! main [
       (default-space:space-address <- new space:literal 30:literal/capacity)
-      (1:channel-address/raw <- init-channel 1:literal)
+      (stdin:channel-address <- init-channel 1:literal)
       (screen:terminal-address <- init-fake-terminal 20:literal 10:literal)
       (2:string-address/raw <- get screen:terminal-address/deref data:offset)
-      (r:integer/routine <- fork-helper read-move:fn nil:literal/globals 2000:literal/limit screen:terminal-address)
+      (r:integer/routine <- fork-helper read-move:fn nil:literal/globals 2000:literal/limit stdin:channel-address screen:terminal-address)
       (c:character <- copy ((#\a literal)))
       (x:tagged-value <- save-type c:character)
-      (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value)
+      (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
       (c:character <- copy ((#\2 literal)))
       (x:tagged-value <- save-type c:character)
-      (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value)
+      (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
       (c:character <- copy ((#\- literal)))
       (x:tagged-value <- save-type c:character)
-      (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value)
+      (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
       (c:character <- copy ((#\a literal)))
       (x:tagged-value <- save-type c:character)
-      (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value)
+      (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
       (sleep until-routine-done:literal r:integer/routine)
      ])))
 (run 'main)
@@ -76,12 +77,12 @@
 (add-code
   '((function! main [
       (default-space:space-address <- new space:literal 30:literal/capacity)
-      (1:channel-address/raw <- init-channel 1:literal)
+      (stdin:channel-address <- init-channel 1:literal)
       (dummy:terminal-address <- init-fake-terminal 20:literal 10:literal)
-      (r:integer/routine <- fork-helper read-move:fn nil:literal/globals nil:literal/limit dummy:terminal-address)
+      (r:integer/routine <- fork-helper read-move:fn nil:literal/globals 2000:literal/limit stdin:channel-address dummy:terminal-address)
       (c:character <- copy ((#\q literal)))
       (x:tagged-value <- save-type c:character)
-      (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value)
+      (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
       (sleep until-routine-done:literal r:integer/routine)
      ])))
 (run 'main)
@@ -94,12 +95,12 @@
 (add-code
   '((function! main [
       (default-space:space-address <- new space:literal 30:literal/capacity)
-      (1:channel-address/raw <- init-channel 1:literal)
+      (stdin:channel-address <- init-channel 1:literal)
       (dummy:terminal-address <- init-fake-terminal 20:literal 10:literal)
-      (r:integer/routine <- fork-helper read-file:fn nil:literal/globals nil:literal/limit dummy:terminal-address)
+      (r:integer/routine <- fork-helper read-file:fn nil:literal/globals 2000:literal/limit stdin:channel-address dummy:terminal-address)
       (c:character <- copy ((#\i literal)))
       (x:tagged-value <- save-type c:character)
-      (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value)
+      (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
       (sleep until-routine-done:literal r:integer/routine)
      ])))
 ;? (= dump-trace* (obj whitelist '("schedule")))
@@ -117,12 +118,12 @@
 (add-code
   '((function! main [
       (default-space:space-address <- new space:literal 30:literal/capacity)
-      (1:channel-address/raw <- init-channel 1:literal)
+      (stdin:channel-address <- init-channel 1:literal)
       (dummy:terminal-address <- init-fake-terminal 20:literal 10:literal)
-      (r:integer/routine <- fork-helper read-rank:fn nil:literal/globals nil:literal/limit dummy:terminal-address)
+      (r:integer/routine <- fork-helper read-rank:fn nil:literal/globals 2000:literal/limit stdin:channel-address dummy:terminal-address)
       (c:character <- copy ((#\9 literal)))
       (x:tagged-value <- save-type c:character)
-      (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value)
+      (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
       (sleep until-routine-done:literal r:integer/routine)
      ])))
 (run 'main)
@@ -178,7 +179,7 @@
   '((function! main [
       (default-space:space-address <- new space:literal 30:literal/capacity)
       ; hook up stdin
-      (1:channel-address/raw <- init-channel 1:literal)
+      (stdin:channel-address <- init-channel 1:literal)
       ; fake screen
       (screen:terminal-address <- init-fake-terminal 20:literal 10:literal)
       ; initial position
diff --git a/chessboard-cursor.mu b/chessboard-cursor.mu
index 6d230384..c23f738b 100644
--- a/chessboard-cursor.mu
+++ b/chessboard-cursor.mu
@@ -97,16 +97,17 @@
 
 (function read-move [
   (default-space:space-address <- new space:literal 30:literal)
+  (stdin:channel-address <- next-input)
   (screen:terminal-address <- next-input)
-  (from-file:integer <- read-file screen:terminal-address)
+  (from-file:integer <- read-file stdin:channel-address screen:terminal-address)
   { begin
     (break-if from-file:integer)
     (reply nil:literal)
   }
-  (from-rank:integer <- read-rank screen:terminal-address)
-  (expect-stdin screen:terminal-address ((#\- literal)))
-  (to-file:integer <- read-file screen:terminal-address)
-  (to-rank:integer <- read-rank screen:terminal-address)
+  (from-rank:integer <- read-rank stdin:channel-address screen:terminal-address)
+  (expect-stdin stdin:channel-address screen:terminal-address ((#\- literal)))
+  (to-file:integer <- read-file stdin:channel-address screen:terminal-address)
+  (to-rank:integer <- read-rank stdin:channel-address screen:terminal-address)
   ; construct the move object
   (result:move-address <- new move:literal)
   (f:integer-integer-pair-address <- get-address result:move-address/deref from:offset)
@@ -125,8 +126,9 @@
 ; todo: assumes stdin is always at raw address 1
 (function read-file [
   (default-space:space-address <- new space:literal 30:literal)
+  (stdin:channel-address <- next-input)
   (screen:terminal-address <- next-input)
-  (x:tagged-value 1:channel-address/raw/deref <- read 1:channel-address/raw)
+  (x:tagged-value stdin:channel-address/deref <- read stdin:channel-address)
   (a:character <- copy ((#\a literal)))
   (file-base:integer <- character-to-integer a:character)
   (c:character <- maybe-coerce x:tagged-value character:literal)
@@ -148,8 +150,9 @@
 
 (function read-rank [
   (default-space:space-address <- new space:literal 30:literal)
+  (stdin:channel-address <- next-input)
   (screen:terminal-address <- next-input)
-  (x:tagged-value 1:channel-address/raw/deref <- read 1:channel-address/raw)
+  (x:tagged-value stdin:channel-address/deref <- read stdin:channel-address)
   (c:character <- maybe-coerce x:tagged-value character:literal)
   (print-character screen:terminal-address c:character)
   { begin
@@ -171,9 +174,10 @@
 
 (function expect-stdin [
   (default-space:space-address <- new space:literal 30:literal)
+  (stdin:channel-address <- next-input)
   (screen:terminal-address <- next-input)
   ; slurp hyphen
-  (x:tagged-value 1:channel-address/raw/deref <- read 1:channel-address/raw)
+  (x:tagged-value stdin:channel-address/deref <- read stdin:channel-address)
   (c:character <- maybe-coerce x:tagged-value character:literal)
   (print-character screen:terminal-address c:character)
   (expected:character <- next-input)
@@ -213,8 +217,8 @@
   (b:board-address <- init-board initial-position:list-address)
   (cursor-mode)
   ; hook up stdin
-  (1:channel-address/raw <- init-channel 1:literal)
-  (fork-helper send-keys-to-stdin:fn nil:literal/globals nil:literal/limit 1:channel-address/raw)
+  (stdin:channel-address <- init-channel 1:literal)
+  (fork-helper send-keys-to-stdin:fn nil:literal/globals nil:literal/limit stdin:channel-address)
   { begin
     ; print any stray characters from keyboard *before* clearing screen
     (clear-screen nil:literal/terminal)
@@ -228,7 +232,7 @@
     (print-primitive-to-host (("Hit 'q' to exit." literal)))
     (cursor-to-next-line nil:literal/terminal)
     (print-primitive-to-host (("move: " literal)))
-    (m:move-address <- read-move nil:literal/terminal)
+    (m:move-address <- read-move stdin:channel-address nil:literal/terminal)
     (break-unless m:move-address)
     (b:board-address <- make-move b:board-address m:move-address)
     (loop)