about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-02-22 22:35:08 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-02-22 22:35:08 -0800
commit0580b5074417d795289beb8f5edec3110a53c333 (patch)
tree25465d75bd2c5953ced6dea67af86e487dc73acb
parentfdc3df04300f20fac81792d1f5ee1e170a5644ec (diff)
downloadmu-0580b5074417d795289beb8f5edec3110a53c333.tar.gz
7789
Start adding some lines to the trace. Never shown yet.
-rw-r--r--baremetal/mu-init.subx1
-rw-r--r--baremetal/shell/read.mu45
-rw-r--r--baremetal/shell/sandbox.mu32
-rw-r--r--baremetal/shell/trace.mu15
4 files changed, 58 insertions, 35 deletions
diff --git a/baremetal/mu-init.subx b/baremetal/mu-init.subx
index b9479101..26b83451 100644
--- a/baremetal/mu-init.subx
+++ b/baremetal/mu-init.subx
@@ -8,7 +8,6 @@
 
 # initialize stack
 bd/copy-to-ebp 0/imm32
-#? (test-run-move-cursor-into-trace)
 # always first run tests
 (run-tests)
 (num-test-failures)  # => eax
diff --git a/baremetal/shell/read.mu b/baremetal/shell/read.mu
index 24d5df13..5ebf98db 100644
--- a/baremetal/shell/read.mu
+++ b/baremetal/shell/read.mu
@@ -1,11 +1,8 @@
 # out is not allocated
 fn read-cell in: (addr gap-buffer), out: (addr handle cell), trace: (addr trace) {
-  # TODO:
-  #   tokenize
-  #   insert parens
-  #   transform infix
-  #   token tree
-  #   syntax tree
+  trace-text trace, "read", ""
+  trace-lower trace
+  trace-text trace, "read", "tokenize"
   rewind-gap-buffer in
   var token-storage: (stream byte 0x1000)  # strings can be large
   var token/ecx: (addr stream byte) <- address token-storage
@@ -20,20 +17,36 @@ fn read-cell in: (addr gap-buffer), out: (addr handle cell), trace: (addr trace)
     read-symbol token, out
     loop
   }
+  trace-higher trace  # tokenize
+  # TODO:
+  #   insert parens
+  #   transform infix
+  #   token tree
+  #   syntax tree
+  trace-higher trace  # read
 }
 
 fn next-token in: (addr gap-buffer), out: (addr stream byte), trace: (addr trace) {
-  clear-stream out
-  skip-whitespace-from-gap-buffer in
-  var g/eax: grapheme <- peek-from-gap-buffer in
-  {
-    var digit?/eax: boolean <- is-decimal-digit? g
-    compare digit?, 0/false
-    break-if-=
-    next-number-token in, out, trace
-    return
+  trace-text trace, "read", "next-token"
+  trace-lower trace
+  $next-token:body: {
+    clear-stream out
+    skip-whitespace-from-gap-buffer in
+    var g/eax: grapheme <- peek-from-gap-buffer in
+    {
+      var digit?/eax: boolean <- is-decimal-digit? g
+      compare digit?, 0/false
+      break-if-=
+      next-number-token in, out, trace
+      break $next-token:body
+    }
+    next-symbol-token in, out, trace
   }
-  next-symbol-token in, out, trace
+  trace-higher trace
+  var stream-storage: (stream byte 0x40)
+  var stream/eax: (addr stream byte) <- address stream-storage
+  write stream, "next-token: result"
+  trace trace, "read", stream
 }
 
 fn next-symbol-token in: (addr gap-buffer), out: (addr stream byte), trace: (addr trace) {
diff --git a/baremetal/shell/sandbox.mu b/baremetal/shell/sandbox.mu
index d7fed376..3e37eac9 100644
--- a/baremetal/shell/sandbox.mu
+++ b/baremetal/shell/sandbox.mu
@@ -191,7 +191,8 @@ fn test-run-integer {
   #
   render-sandbox screen, sandbox, 0/x, 0/y
   check-screen-row screen, 0/y, "1    ", "F - test-run-integer/0"
-  check-screen-row screen, 1/y, "=> 1 ", "F - test-run-integer/1"
+  check-screen-row screen, 1/y, "...  ", "F - test-run-integer/1"
+  check-screen-row screen, 2/y, "=> 1 ", "F - test-run-integer/2"
 }
 
 fn test-run-error-invalid-integer {
@@ -210,34 +211,39 @@ fn test-run-error-invalid-integer {
   #
   render-sandbox screen, sandbox, 0/x, 0/y
   check-screen-row screen, 0/y, "1a             ", "F - test-run-error-invalid-integer/0"
-  check-screen-row screen, 1/y, "invalid number ", "F - test-run-error-invalid-integer/1"
+  check-screen-row screen, 1/y, "...            ", "F - test-run-error-invalid-integer/0"
+  check-screen-row screen, 2/y, "invalid number ", "F - test-run-error-invalid-integer/2"
 }
 
 fn test-run-move-cursor-into-trace {
   var sandbox-storage: sandbox
   var sandbox/esi: (addr sandbox) <- address sandbox-storage
   initialize-sandbox sandbox
-  # type "1a"
+  # type "12"
   edit-sandbox sandbox, 0x31/1
-  edit-sandbox sandbox, 0x61/a
+  edit-sandbox sandbox, 0x32/2
   # eval
   edit-sandbox sandbox, 0x13/ctrl-s
   # setup: screen
   var screen-on-stack: screen
   var screen/edi: (addr screen) <- address screen-on-stack
-  initialize-screen screen, 0x10, 4
+  initialize-screen screen, 0x10, 8
   #
   render-sandbox screen, sandbox, 0/x, 0/y
-  check-screen-row screen,                                  0/y, "1a             ", "F - test-run-move-cursor-into-trace/pre-0"
-  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y, "  |            ", "F - test-run-move-cursor-into-trace/pre-0/cursor"
-  check-screen-row screen,                                  1/y, "invalid number ", "F - test-run-move-cursor-into-trace/pre-1"
-  check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, "               ", "F - test-run-move-cursor-into-trace/pre-1/cursor"
+  check-screen-row screen,                                  0/y, "12    ", "F - test-run-move-cursor-into-trace/pre-0"
+  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y, "  |   ", "F - test-run-move-cursor-into-trace/pre-0/cursor"
+  check-screen-row screen,                                  1/y, "...   ", "F - test-run-move-cursor-into-trace/pre-1"
+  check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, "      ", "F - test-run-move-cursor-into-trace/pre-1/cursor"
+  check-screen-row screen,                                  2/y, "=> 12 ", "F - test-run-move-cursor-into-trace/pre-2"
+  check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, "      ", "F - test-run-move-cursor-into-trace/pre-2/cursor"
   # move cursor down
   edit-sandbox sandbox, 4/ctrl-d
   #
   render-sandbox screen, sandbox, 0/x, 0/y
-  check-screen-row screen,                                  0/y, "1a             ", "F - test-run-move-cursor-into-trace/0"
-  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y, "               ", "F - test-run-move-cursor-into-trace/0/cursor"
-  check-screen-row screen,                                  1/y, "invalid number ", "F - test-run-move-cursor-into-trace/1"
-  check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, "|||||||||||||| ", "F - test-run-move-cursor-into-trace/1/cursor"
+  check-screen-row screen,                                  0/y, "12    ", "F - test-run-move-cursor-into-trace/0"
+  check-background-color-in-screen-row screen, 7/bg=cursor, 0/y, "      ", "F - test-run-move-cursor-into-trace/0/cursor"
+  check-screen-row screen,                                  1/y, "...   ", "F - test-run-move-cursor-into-trace/1"
+  check-background-color-in-screen-row screen, 7/bg=cursor, 1/y, "|||   ", "F - test-run-move-cursor-into-trace/1/cursor"
+  check-screen-row screen,                                  2/y, "      ", "F - test-run-move-cursor-into-trace/2"
+  check-background-color-in-screen-row screen, 7/bg=cursor, 2/y, "      ", "F - test-run-move-cursor-into-trace/2/cursor"
 }
diff --git a/baremetal/shell/trace.mu b/baremetal/shell/trace.mu
index d3549f2a..b3a4666a 100644
--- a/baremetal/shell/trace.mu
+++ b/baremetal/shell/trace.mu
@@ -60,11 +60,15 @@ fn trace _self: (addr trace), label: (addr array byte), data: (addr stream byte)
   write-to-stream dest, line
 }
 
-fn error self: (addr trace), data: (addr array byte) {
-  var s: (stream byte 0x100)
-  var s-a/eax: (addr stream byte) <- address s
-  write s-a, data
-  trace self, "error", s-a
+fn trace-text self: (addr trace), label: (addr array byte), s: (addr array byte) {
+  var data-storage: (stream byte 0x100)
+  var data/eax: (addr stream byte) <- address data-storage
+  write data, s
+  trace self, label, data
+}
+
+fn error self: (addr trace), message: (addr array byte) {
+  trace-text self, "error", message
 }
 
 fn initialize-trace-line depth: int, label: (addr array byte), data: (addr stream byte), _out: (addr trace-line) {
@@ -137,6 +141,7 @@ fn render-trace screen: (addr screen), _self: (addr trace), xmin: int, ymin: int
       var x/eax: int <- copy xmin
       x, y <- draw-text-wrapping-right-then-down screen, "...", xmin, ymin, xmax, ymax, x, y, 9/fg=trace, bg
       y <- increment
+      already-hiding-lines? <- copy 1/true
     }
     loop
   }