about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-02-16 02:32:06 -0800
committerKartik K. Agaram <vc@akkartik.com>2015-02-16 02:46:20 -0800
commit333a2d3fab87c274cba917d31e8b95634e41e943 (patch)
treebe4844aa95f62c94ee17061633a368329603f847
parent2590658547c0a391e15943c054eb588af3ba4356 (diff)
downloadmu-333a2d3fab87c274cba917d31e8b95634e41e943.tar.gz
756 - first scenario for collapse
-rw-r--r--trace.arc.t77
-rw-r--r--trace.mu54
2 files changed, 103 insertions, 28 deletions
diff --git a/trace.arc.t b/trace.arc.t
index 2614e722..bed3e8ef 100644
--- a/trace.arc.t
+++ b/trace.arc.t
@@ -139,7 +139,7 @@ schedule:  done with routine")
       ; we have no way yet to test special keys like up-arrow
       (s:string-address <- new "k")
       (k:keyboard-address <- init-keyboard s:string-address)
-      (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
+      (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
       ; draw cursor
       (replace-character 2:terminal-address/raw ((#\* literal)))
       (4:string-address/raw <- get 2:terminal-address/raw/deref data:offset)
@@ -166,9 +166,9 @@ schedule:  done with routine")
   ; move cursor up 3 more lines
   (s:string-address <- new "kkk")
   (k:keyboard-address <- init-keyboard s:string-address)
-  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
-  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
-  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
+  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
+  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
+  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
   (replace-character 2:terminal-address/raw ((#\* literal)))
   )
 ; cursor is now at line 3
@@ -189,9 +189,9 @@ schedule:  done with routine")
   (replace-character 2:terminal-address/raw ((#\+ literal)))
   (s:string-address <- new "kkk")
   (k:keyboard-address <- init-keyboard s:string-address)
-  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
-  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
-  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
+  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
+  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
+  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
   (replace-character 2:terminal-address/raw ((#\* literal)))
   )
 ; cursor doesn't go beyond the first line printed
@@ -213,10 +213,10 @@ schedule:  done with routine")
   (replace-character 2:terminal-address/raw ((#\+ literal)))
   (s:string-address <- new "jjjj")
   (k:keyboard-address <- init-keyboard s:string-address)
-  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
-  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
-  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
-  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
+  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
+  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
+  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
+  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
   (replace-character 2:terminal-address/raw ((#\* literal)))
   )
 (when (~screen-contains memory*.4 70
@@ -236,10 +236,10 @@ schedule:  done with routine")
   (replace-character 2:terminal-address/raw ((#\+ literal)))
   (s:string-address <- new "jjjj")
   (k:keyboard-address <- init-keyboard s:string-address)
-  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
-  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
-  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
-  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
+  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
+  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
+  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
+  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
   (replace-character 2:terminal-address/raw ((#\* literal)))
   )
 (when (~screen-contains memory*.4 70
@@ -305,8 +305,8 @@ schedule:  done with routine")
   ; move cursor to final line and expand
   (s:string-address <- new "k\n")
   (k:keyboard-address <- init-keyboard s:string-address)
-  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
-  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
+  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
+  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
   )
 ; final line is expanded
 (when (~screen-contains memory*.4 70
@@ -372,9 +372,9 @@ schedule:  done with routine")
       ; expand penultimate line
       (s:string-address <- new "kk\n")
       (k:keyboard-address <- init-keyboard s:string-address)
-      (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
-      (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
-      (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
+      (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
+      (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
+      (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
       (4:string-address/raw <- get 2:terminal-address/raw/deref data:offset)
     ])))
 (run 'main)
@@ -395,7 +395,7 @@ schedule:  done with routine")
   (prn "F - process-key: expanding a line continues to print lines after it"))
 
 (reset)
-(new-trace "process-key-skip-expanded")
+(new-trace "process-key-expanded")
 (add-code:readfile "trace.mu")
 (add-code
   '((function! main [
@@ -427,10 +427,10 @@ schedule:  done with routine")
       ; expand penultimate line, then move one line down and draw cursor
       (s:string-address <- new "kk\nj")
       (k:keyboard-address <- init-keyboard s:string-address)
-      (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
-      (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
-      (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
-      (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
+      (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
+      (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
+      (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
+      (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
       (replace-character 2:terminal-address/raw ((#\* literal)))
       (4:string-address/raw <- get 2:terminal-address/raw/deref data:offset)
     ])))
@@ -459,7 +459,7 @@ schedule:  done with routine")
   ; move cursor back up one line
   (s:string-address <- new "k")
   (k:keyboard-address <- init-keyboard s:string-address)
-  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw 1:instruction-trace-address-array-address/raw)
+  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
   ; show cursor
   (replace-character 2:terminal-address/raw ((#\* literal)))
   )
@@ -479,5 +479,30 @@ schedule:  done with routine")
             "   mem : ((2 integer)) => 3                                           "
             "+ main/ 2 : 4 => ((3 integer))                                        "))
   (prn "F - process-key: navigation moves between top-level lines only"))
+(run-code main3
+  (default-space:space-address <- new space:literal 30:literal/capacity)
+  ; reset previous cursor
+  (replace-character 2:terminal-address/raw ((#\+ literal)))
+  ; press enter
+  (s:string-address <- new "\n")
+  (k:keyboard-address <- init-keyboard s:string-address)
+  (process-key 3:space-address/raw/screen-state k:keyboard-address 2:terminal-address/raw)
+  )
+(each routine completed-routines*
+  (awhen rep.routine!error
+    (prn "error - " it)))
+; expanded trace should now be collapsed
+(when (~screen-contains memory*.4 70
+         (+ "                                                                      "
+            "                                                                      "
+            "+ main/ 0 : (((1 integer)) <- ((copy)) ((1 literal)))                 "
+            "+ main/ 0 : 1 => ((1 integer))                                        "
+            "+ main/ 1 : (((2 integer)) <- ((copy)) ((3 literal)))                 "
+            "+ main/ 1 : 3 => ((2 integer))                                        "
+            "+ main/ 2 : (((3 integer)) <- ((add)) ((1 integer)) ((2 integer)))    "
+            "+ main/ 2 : 4 => ((3 integer))                                        "
+            "                                                                      "
+            "                                                                      "))
+  (prn "F - process-key: navigation moves between top-level lines only"))
 
 (reset)
diff --git a/trace.mu b/trace.mu
index f3f37673..6a90bd7d 100644
--- a/trace.mu
+++ b/trace.mu
@@ -337,6 +337,12 @@
     (at-bottom?:boolean <- greater-or-equal cursor-row:integer/space:1 height:integer/space:1)
     (break-unless at-bottom?:boolean)
     (height:integer/space:1 <- add height:integer/space:1 1:literal)
+    ; update max-rows if necessary
+    { begin
+      (grow-max?:boolean <- greater-than height:integer/space:1 max-rows:integer/space:1)
+      (break-unless grow-max?:boolean)
+      (max-rows:integer/space:1 <- copy height:integer/space:1)
+    }
   }
   (cursor-row:integer/space:1 <- add cursor-row:integer/space:1 1:literal)
   (cursor-to-next-line screen:terminal-address)
@@ -356,6 +362,7 @@
   (screen:terminal-address <- next-input)
   (i:integer <- next-input)
   (len:integer <- length traces:instruction-trace-address-array-address/space:1/deref)
+  ; print remaining traces collapsed
   { begin
     (done?:boolean <- greater-or-equal i:integer len:integer)
     (break-if done?:boolean)
@@ -364,6 +371,18 @@
     (i:integer <- add i:integer 1:literal)
     (loop)
   }
+  ; empty any remaining lines
+;?   ($print i:integer) ;? 1
+;?   ($print ((#\space literal))) ;? 1
+;?   ($print max-rows:integer/space:1) ;? 1
+  { begin
+    (done?:boolean <- greater-or-equal i:integer max-rows:integer/space:1)
+    (break-if done?:boolean)
+    (clear-line screen:terminal-address)
+    (down 0:space-address/screen-state screen:terminal-address)
+    (i:integer <- add i:integer 1:literal)
+    (loop)
+  }
 ])
 
 ;; modify screen state in response to a single key
@@ -403,14 +422,45 @@
     (down 0:space-address/screen-state screen:terminal-address)
     (reply nil:literal)
   }
-  ; enter: expand current row
+  ; enter: expand/collapse current row
   { begin
     (toggle?:boolean <- equal c:character ((#\newline literal)))
     (break-unless toggle?:boolean)
     (original-row:integer <- copy cursor-row:integer/space:1)
+    ; is expanded-row already set?
+    { begin
+      (expanded?:boolean <- greater-or-equal expanded-row:integer/space:1 0:literal)
+      (break-unless expanded?:boolean)
+      { begin
+        ; are we at the expanded row?
+        (at-expanded?:boolean <- equal cursor-row:integer/space:1 expanded-row:integer/space:1)
+        (break-unless at-expanded?:boolean)
+        ; print remaining lines collapsed and return
+        (expanded-row:integer/space:1 <- copy -1:literal)
+        (print-traces-collapsed-from 0:space-address/screen-state screen:terminal-address cursor-row:integer/space:1)
+        (back-to 0:space-address/screen-state screen:terminal-address original-row:integer)
+        (reply)
+      }
+      ; are we below the expanded row?
+      { begin
+        (below-expanded?:boolean <- greater-than cursor-row:integer/space:1 expanded-row:integer/space:1)
+        (break-unless below-expanded?:boolean)
+        ; scan up to expanded row
+        { begin
+          (at-expanded?:boolean <- equal cursor-row:integer/space:1 expanded-row:integer/space:1)
+          (break-if at-expanded?:boolean)
+          (up 0:space-address screen:terminal-address)
+          (loop)
+        }
+        ; collapse
+        ; keep printing until we return to original row
+        ; fall through
+      }
+    }
+    ; expand original row and print traces below it
+    (expanded-row:integer/space:1 <- copy original-row:integer)
     (tr:instruction-trace-address <- index traces:instruction-trace-address-array-address/space:1/deref cursor-row:integer/space:1)  ; assumes cursor row is a valid index into traces, ie no expanded rows
     (print-instruction-trace screen:terminal-address tr:instruction-trace-address 0:space-address/screen-state)
-    (expanded-row:integer/space:1 <- copy original-row:integer)
     (next-row:integer <- add original-row:integer 1:literal)
     (print-traces-collapsed-from 0:space-address/screen-state screen:terminal-address next-row:integer)
     (back-to 0:space-address/screen-state screen:terminal-address original-row:integer)