about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-02-15 21:34:02 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-02-15 21:34:02 -0800
commitff1b342442c0c448e3a102219e6a746e79fb26d3 (patch)
tree000ba3c6bf322f4ff7b61f5d629527f8288419f4
parente6bc2aa77130cbf44a349f2f1a0c1c1eb33f2def (diff)
downloadmu-ff1b342442c0c448e3a102219e6a746e79fb26d3.tar.gz
748
-rw-r--r--mu.arc49
-rw-r--r--trace.arc.t22
-rw-r--r--trace.mu2
3 files changed, 60 insertions, 13 deletions
diff --git a/mu.arc b/mu.arc
index 2182daf5..2651979e 100644
--- a/mu.arc
+++ b/mu.arc
@@ -1654,7 +1654,7 @@
 (def memory-contains-array (addr value)
   (or
     (and (>= memory*.addr len.value)
-         (loop (addr (+ addr 1)
+         (loop (addr (+ addr 1)  ; skip count
                 idx  0)
            (if (>= idx len.value)
                  t
@@ -1667,7 +1667,7 @@
 (def memory-contains-array-verbose (addr value)
   (prn "Mismatch when looking at @addr, size @memory*.addr vs @len.value")
   (and (>= memory*.addr len.value)
-       (loop (addr (+ addr 1)
+       (loop (addr (+ addr 1)  ; skip count
               idx  0)
          (and (< idx len.value) (prn "comparing @idx: @memory*.addr and @value.idx"))
          (if (>= idx len.value)
@@ -1679,6 +1679,24 @@
              :else
                (recur (+ addr 1) (+ idx 1))))))
 
+(def screen-contains (addr width value)
+  (or (memory-contains-array addr value)
+      (do ;(memory-contains-array-verbose addr value)
+          (prn "Screen contents:")
+          (with (row-start-addr  (+ addr 1)  ; skip count
+                 idx  0)
+            (for row 0  (< row (/ len.value width))  (do ++.row  (++ row-start-addr width))
+              (pr ". ")
+              (for col 0  (< col width)  ++.col
+                (with (expected  value.idx
+                       got  (memory* (+ col row-start-addr)))
+                  (if (is expected got)
+                    (do (pr got)  (pr " "))
+                    (do (pr "X")  (pr got))))
+                ++.idx)
+              (prn " .")
+              )))))
+
 ; run code in tests
 (mac run-code (name . body)
   ; careful to avoid re-processing functions and adding noise to traces
@@ -2686,6 +2704,33 @@
   (cursor-left x:terminal-address)
 )
 
+(init-fn clear-line
+  (default-space:space-address <- new space:literal 30:literal)
+  (x:terminal-address <- next-input)
+  { begin
+    (break-unless x:terminal-address)
+    (n:integer <- get x:terminal-address/deref num-cols:offset)
+    (col:integer-address <- get-address x:terminal-address/deref cursor-col:offset)
+    (orig-col:integer <- copy col:integer-address/deref)
+    ; space over the entire line
+    { begin
+      (done?:boolean <- greater-or-equal col:integer-address/deref n:integer)
+      (break-if done?:boolean)
+      (print-character x:terminal-address ((#\space literal)))  ; implicitly updates 'col'
+      (loop)
+    }
+    ; now back to where the cursor was
+    { begin
+      (done?:boolean <- lesser-or-equal col:integer-address/deref orig-col:integer)
+      (break-if done?:boolean)
+      (cursor-left x:terminal-address)
+      (loop)
+    }
+    (reply)
+  }
+  (clear-line-on-host)
+)
+
 (init-fn print-character
   (default-space:space-address <- new space:literal 30:literal)
   (x:terminal-address <- next-input)
diff --git a/trace.arc.t b/trace.arc.t
index acef6f80..b8deec29 100644
--- a/trace.arc.t
+++ b/trace.arc.t
@@ -36,7 +36,7 @@ schedule:  done with routine")
   (awhen rep.routine!error
     (prn "error - " it)))
 ;? (prn memory*.1)
-(when (~memory-contains-array memory*.1
+(when (~screen-contains memory*.1 70
          (+ "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal)))                 "
             "+ main/ 0 : 1 => ((1 integer))                                        "
             "+ main/ 1 : (((2 integer)) <- ((copy)) ((3 literal)))                 "
@@ -80,7 +80,7 @@ schedule:  done with routine")
 (each routine completed-routines*
   (awhen rep.routine!error
     (prn "error - " it)))
-(when (~memory-contains-array memory*.2
+(when (~screen-contains memory*.2 70
          (+ "                                                                      "
             "                                                                      "
             "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal)))                 "
@@ -93,7 +93,7 @@ schedule:  done with routine")
 
 (run-code main2
   (print-character 1:terminal-address/raw ((#\* literal))))
-(when (~memory-contains-array memory*.2
+(when (~screen-contains memory*.2 70
          (+ "                                                                      "
             "                                                                      "
             "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal)))                 "
@@ -148,7 +148,7 @@ schedule:  done with routine")
 (each routine completed-routines*
   (awhen rep.routine!error
     (prn "error - " it)))
-(when (~memory-contains-array memory*.4
+(when (~screen-contains memory*.4 70
          (+ "                                                                      "
             "                                                                      "
             "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal)))                 "
@@ -172,7 +172,7 @@ schedule:  done with routine")
   (replace-character 2:terminal-address/raw ((#\* literal)))
   )
 ; cursor is now at line 3
-(when (~memory-contains-array memory*.4
+(when (~screen-contains memory*.4 70
          (+ "                                                                      "
             "                                                                      "
             "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal)))                 "
@@ -196,7 +196,7 @@ schedule:  done with routine")
   )
 ; cursor doesn't go beyond the first line printed
 ; stuff on screen before screen-state was initialized is inviolate
-(when (~memory-contains-array memory*.4
+(when (~screen-contains memory*.4 70
          (+ "                                                                      "
             "                                                                      "
             "* main/ 0 : (((1 integer)) <- ((copy)) ((1 literal)))                 "
@@ -219,7 +219,7 @@ schedule:  done with routine")
   (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
   (replace-character 2:terminal-address/raw ((#\* literal)))
   )
-(when (~memory-contains-array memory*.4
+(when (~screen-contains memory*.4 70
          (+ "                                                                      "
             "                                                                      "
             "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal)))                 "
@@ -242,7 +242,7 @@ schedule:  done with routine")
   (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
   (replace-character 2:terminal-address/raw ((#\* literal)))
   )
-(when (~memory-contains-array memory*.4
+(when (~screen-contains memory*.4 70
          (+ "                                                                      "
             "                                                                      "
             "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal)))                 "
@@ -290,7 +290,7 @@ schedule:  done with routine")
 (each routine completed-routines*
   (awhen rep.routine!error
     (prn "error - " it)))
-(when (~memory-contains-array memory*.4
+(when (~screen-contains memory*.4 70
          (+ "                                                                      "
             "                                                                      "
             "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal)))                 "
@@ -309,7 +309,7 @@ schedule:  done with routine")
   (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
   )
 ; final line is expanded
-(when (~memory-contains-array memory*.4
+(when (~screen-contains memory*.4 70
          (+ "                                                                      "
             "                                                                      "
             "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal)))                 "
@@ -325,7 +325,7 @@ schedule:  done with routine")
 (run-code main3
   (replace-character 2:terminal-address/raw ((#\* literal)))
   )
-(when (~memory-contains-array memory*.4
+(when (~screen-contains memory*.4 70
          (+ "                                                                      "
             "                                                                      "
             "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal)))                 "
diff --git a/trace.mu b/trace.mu
index 3444d053..60bff37e 100644
--- a/trace.mu
+++ b/trace.mu
@@ -111,6 +111,7 @@
   (screen:terminal-address <- next-input)
   (x:trace-address <- next-input)
   (l:string-address <- get x:trace-address/deref label:offset)
+  (clear-line screen:terminal-address)
   (print-string screen:terminal-address l:string-address)
   (print-character screen:terminal-address ((#\space literal)))
   (print-character screen:terminal-address ((#\: literal)))
@@ -124,6 +125,7 @@
   (screen:terminal-address <- next-input)
   (x:instruction-trace-address <- next-input)
   (screen-state:space-address <- next-input)
+  (clear-line screen:terminal-address)
   (print-character screen:terminal-address ((#\- literal)))
   (print-character screen:terminal-address ((#\space literal)))
   ; print call stack