about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-01-25 02:25:50 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-01-25 02:25:50 -0800
commit4ca73eb66a57f32085be56c64ce316b82084602f (patch)
tree16f05bef3ed535f24b6426a60d83398d0967f7ad
parentbee53b4b169feab631658b5450328a317779831a (diff)
downloadmu-4ca73eb66a57f32085be56c64ce316b82084602f.tar.gz
620 - fix broken examples and tests again
I just did this in 611; what's the point of all this if tests can't stay
passing?

I don't understand why buffered-stdin.mu needs to preempt itself. stdin
and buffered-stdin somehow end up sharing a single circular buffer,
that's probably causing a race condition.
-rw-r--r--buffered-stdin.mu26
-rw-r--r--chessboard.arc.t22
-rw-r--r--chessboard.mu2
-rw-r--r--mu.arc39
4 files changed, 63 insertions, 26 deletions
diff --git a/buffered-stdin.mu b/buffered-stdin.mu
index 7db3e291..a0e39154 100644
--- a/buffered-stdin.mu
+++ b/buffered-stdin.mu
@@ -1,4 +1,4 @@
-; reads lines, prints when you hit 'enter'
+; reads lines, prints them back when you hit 'enter'
 ; dies if you wait a while, because so far we never free memory
 (function main [
   (default-space:space-address <- new space:literal 30:literal)
@@ -10,18 +10,20 @@
   ; buffer stdin
   (buffered-stdin:channel-address <- init-channel 1:literal)
   (fork-helper buffer-stdin:fn nil:literal/globals nil:literal/limit stdin:channel-address buffered-stdin:channel-address)
-  ; now read characters from the buffer until a 'enter' is typed
-  (s:string-address <- new "? ")
-  (print-string nil:literal/terminal s:string-address)
   { begin
-    (x:tagged-value stdin:channel-address/deref <- read buffered-stdin:channel-address)
-    (c:character <- maybe-coerce x:tagged-value character:literal)
-;?     (print-primitive-to-host (("AAA " literal))) ;? 0
-;?     (print-primitive-to-host c:character) ;? 0
-;?     (print-primitive-to-host (("\n" literal))) ;? 0
-    (done?:boolean <- equal c:character ((#\newline literal)))
-    (break-if done?:boolean)
-    (print-character nil:literal/terminal c:character)
+    ; now read characters from the buffer until 'enter' is typed
+    (s:string-address <- new "? ")
+    (print-string nil:literal/terminal s:string-address)
+    { begin
+      (x:tagged-value stdin:channel-address/deref <- read buffered-stdin:channel-address)
+      (c:character <- maybe-coerce x:tagged-value character:literal)
+;?       (print-primitive-to-host (("AAA " literal))) ;? 1
+;?       (print-primitive-to-host c:character) ;? 1
+;?       (print-primitive-to-host (("\n" literal))) ;? 1
+      (print-character nil:literal/terminal c:character)
+      (line-done?:boolean <- equal c:character ((#\newline literal)))
+      (loop-unless line-done?:boolean)
+    }
     (loop)
   }
 ])
diff --git a/chessboard.arc.t b/chessboard.arc.t
index e089a52d..78f9531a 100644
--- a/chessboard.arc.t
+++ b/chessboard.arc.t
@@ -2,7 +2,7 @@
 
 (reset)
 (new-trace "read-move-legal")
-(add-code:readfile "chessboard-cursor.mu")
+(add-code:readfile "chessboard.mu")
 (add-code
   '((function! main [
       (default-space:space-address <- new space:literal 30:literal/capacity)
@@ -23,6 +23,9 @@
       (c:character <- copy ((#\4 literal)))
       (x:tagged-value <- save-type c:character)
       (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
+      (c:character <- copy ((#\newline literal)))
+      (x:tagged-value <- save-type c:character)
+      (stdin:channel-address/deref <- write stdin:channel-address x:tagged-value)
       (sleep until-routine-done:literal r:integer/routine)
      ])))
 ;? (set dump-trace*)
@@ -41,7 +44,7 @@
 
 (reset)
 (new-trace "read-move-incomplete")
-(add-code:readfile "chessboard-cursor.mu")
+(add-code:readfile "chessboard.mu")
 ; initialize some variables at specific raw locations
 ;? (prn "== init")
 (run-code test-init
@@ -77,6 +80,9 @@
     (1:channel-address/raw/deref <- write 1:channel-address/raw 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)
+    (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))
   ; check that read-move consumes them and then goes to sleep
   (when (ran-to-completion 'read-move)
@@ -88,7 +94,7 @@
 ;?   (set dump-trace*)
   (run-code send-final-key
     (default-space:space-address <- new space:literal 30:literal/capacity)
-    (c:character <- copy ((#\4 literal)))
+    (c:character <- copy ((#\newline literal)))
     (x:tagged-value <- save-type c:character)
     (1:channel-address/raw/deref <- write 1:channel-address/raw x:tagged-value))
   ; check that read-move consumes it and -- this time -- returns
@@ -98,7 +104,7 @@
 
 (reset)
 (new-trace "read-move-quit")
-(add-code:readfile "chessboard-cursor.mu")
+(add-code:readfile "chessboard.mu")
 (add-code
   '((function! main [
       (default-space:space-address <- new space:literal 30:literal/capacity)
@@ -116,7 +122,7 @@
 
 (reset)
 (new-trace "read-illegal-file")
-(add-code:readfile "chessboard-cursor.mu")
+(add-code:readfile "chessboard.mu")
 (add-code
   '((function! main [
       (default-space:space-address <- new space:literal 30:literal/capacity)
@@ -139,7 +145,7 @@
 
 (reset)
 (new-trace "read-illegal-rank")
-(add-code:readfile "chessboard-cursor.mu")
+(add-code:readfile "chessboard.mu")
 (add-code
   '((function! main [
       (default-space:space-address <- new space:literal 30:literal/capacity)
@@ -159,7 +165,7 @@
 
 (reset)
 (new-trace "print-board")
-(add-code:readfile "chessboard-cursor.mu")
+(add-code:readfile "chessboard.mu")
 (add-code
   '((function! main [
       (default-space:space-address <- new space:literal 30:literal/capacity)
@@ -199,7 +205,7 @@
 ; todo: how to fold this more elegantly with the previous test?
 (reset)
 (new-trace "make-move")
-(add-code:readfile "chessboard-cursor.mu")
+(add-code:readfile "chessboard.mu")
 (add-code
   '((function! main [
       (default-space:space-address <- new space:literal 30:literal/capacity)
diff --git a/chessboard.mu b/chessboard.mu
index 9479ab24..b26401ab 100644
--- a/chessboard.mu
+++ b/chessboard.mu
@@ -243,7 +243,7 @@
 ;?     (print-primitive-to-host (("\n" literal))) ;? 1
 ;?     (print-primitive-to-host buffered-stdin:channel-address) ;? 1
 ;?     (print-primitive-to-host (("\n" literal))) ;? 1
-;?     (dump-memory) ;? 1
+;?     ($dump-memory) ;? 1
 ;?     (cursor-mode) ;? 1
     (break-unless m:move-address)
     (b:board-address <- make-move b:board-address m:move-address)
diff --git a/mu.arc b/mu.arc
index 46c28494..1f9c1062 100644
--- a/mu.arc
+++ b/mu.arc
@@ -739,10 +739,32 @@
                     (prn ($.rgb-red pixel) " " ($.rgb-blue pixel) " " ($.rgb-green pixel))
                     ($:rgb-red pixel))
 
-                ; debugging aide
-                dump-memory
+                ; debugging aides
+                $dump-memory
                   (do1 nil
                     (prn:repr int-canon.memory*))
+                $start-tracing
+                  (do1 nil
+                    (set dump-trace*))
+                $stop-tracing
+                  (do1 nil
+                    (wipe dump-trace*))
+                $dump-channel
+                  (do1 nil
+                    ($.close-charterm)
+                    (withs (x (m arg.0)
+                            y (memory* (+ x 2)))
+                      (prn label.routine* " -- " x " -- " (list (memory* x)
+                                                                (memory* (+ x 1))
+                                                                (memory* (+ x 2)))
+                                                   " -- " (list (memory* y)
+                                                                (memory* (+ y 1))
+                                                                (repr:memory* (+ y 2))
+                                                                (memory* (+ y 3))
+                                                                (repr:memory* (+ y 4)))))
+                    ($.open-charterm))
+                $quit
+                  (quit)
 
                 ; user-defined functions
                 next-input
@@ -1680,6 +1702,7 @@
 (init-fn read
   (default-space:space-address <- new space:literal 30:literal)
   (chan:channel-address <- next-input)
+;?   ($dump-channel chan:channel-address) ;? 1
   { begin
     ; block if chan is empty
     (empty:boolean <- empty? chan:channel-address/deref)
@@ -2030,6 +2053,9 @@
   ; repeat forever
   { begin
     (line:buffer-address <- init-buffer 30:literal)
+    ; todo: why do we need this?
+    (sleep for-some-cycles:literal 1:literal)
+;?     ($dump-channel 1093:literal) ;? 1
     ; read characters from stdin until newline, copy into line
     { begin
       (x:tagged-value stdin:channel-address/deref <- read stdin:channel-address)
@@ -2047,15 +2073,13 @@
         (loop 2:blocks)
       }
       (line:buffer-address <- append line:buffer-address c:character)
-      (line-contents:string-address <- get line:buffer-address/deref data:offset)
       (line-done?:boolean <- equal c:character ((#\newline literal)))
       (break-if line-done?:boolean)
       (eof?:boolean <- equal c:character ((#\null literal)))
-      (break-if eof?:boolean)
+      (break-if eof?:boolean 2:blocks)
       (loop)
     }
     ; copy line into buffered-stdout
-    (break-if eof?:boolean)
     (i:integer <- copy 0:literal)
     (line-contents:string-address <- get line:buffer-address/deref data:offset)
     (max:integer <- get line:buffer-address/deref length:offset)
@@ -2064,7 +2088,12 @@
       (break-if done?:boolean)
       (c:character <- index line-contents:string-address/deref i:integer)
       (curr:tagged-value <- save-type c:character)
+;?       ($dump-channel 1093:literal) ;? 1
+;?       ($start-tracing) ;? 1
       (buffered-stdin:channel-address/deref <- write buffered-stdin:channel-address curr:tagged-value)
+;?       ($stop-tracing) ;? 1
+;?       ($dump-channel 1093:literal) ;? 1
+;?       ($quit) ;? 1
       (i:integer <- add i:integer 1:literal)
       (loop)
     }