about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-05-07 09:49:16 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-05-07 09:49:16 -0700
commit74be534e2be007f0729092c49a90ca8e410150a8 (patch)
treebde87d2626b3274db039e87adbb38cd7f1813e01
parent7105b73fd3f0952a62de125ee70fe81a9ae683fd (diff)
downloadmu-74be534e2be007f0729092c49a90ca8e410150a8.tar.gz
starting to implement first macros
Another commit, another bugfix.

Some snippets from my currently exploding todo list:

- always investigate lookup errors immediately. Beyond the root cause, they should never happen at the moment, while we aren't reclaiming memory.
  we should always return a more precise error message. Usually involving null pointer checks.

- on abort, print out stack trace
  - emit mapping of labels to addresses during survey
  - store a mapping of symbols somewhere in the code image

- stop allocating 1KB per token; expand space for tokens as needed
-rw-r--r--shell/data.limg4
-rw-r--r--shell/evaluate.mu9
-rw-r--r--shell/global.mu6
-rw-r--r--shell/sandbox.mu1
4 files changed, 20 insertions, 0 deletions
diff --git a/shell/data.limg b/shell/data.limg
index 14eab44e..b3750892 100644
--- a/shell/data.limg
+++ b/shell/data.limg
@@ -1,5 +1,9 @@
 (
   (globals . (
+    (mac . [(def mac (litmac litfn () (name params . body)
+  `(def ,name (litmac litfn () ,params ,@body))))])
+    (when . [(mac when (cond body)
+  `(if ,cond ,body ()))])
     (hline . [(def hline (fn (screen y color)
   (hline1 screen y 0 (width screen) color)))])
     (hline1 . [(def hline1 (fn (screen y lo hi color)
diff --git a/shell/evaluate.mu b/shell/evaluate.mu
index 1bccfbfe..eb0b1e42 100644
--- a/shell/evaluate.mu
+++ b/shell/evaluate.mu
@@ -472,6 +472,15 @@ fn evaluate _in-ah: (addr handle cell), _out-ah: (addr handle cell), env-h: (han
     increment call-number
     evaluate left-ah, left-out-ah, env-h, globals, trace, screen-cell, keyboard-cell, call-number
     debug-print "B", 4/fg, 0xc5/bg=blue-bg
+    # a trip wire in case we're running without a trace (e.g. when loading the initial state from disk)
+    {
+      var left-out/eax: (addr cell) <- lookup *left-out-ah
+      compare left-out, 0
+      {
+        break-if-!=
+        abort "unknown variable"
+      }
+    }
     #
     curr-out-ah <- get curr-out, right
     var right-ah/eax: (addr handle cell) <- get curr, right
diff --git a/shell/global.mu b/shell/global.mu
index c5f6b171..93ae4020 100644
--- a/shell/global.mu
+++ b/shell/global.mu
@@ -63,6 +63,7 @@ fn initialize-globals _self: (addr global-table) {
 }
 
 fn load-globals in: (addr handle cell), self: (addr global-table) {
+#?   draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "a", 2/fg 0/bg
   var remaining-ah/esi: (addr handle cell) <- copy in
   {
     var _remaining/eax: (addr cell) <- lookup *remaining-ah
@@ -70,6 +71,7 @@ fn load-globals in: (addr handle cell), self: (addr global-table) {
     var done?/eax: boolean <- nil? remaining
     compare done?, 0/false
     break-if-!=
+#?     draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "b", 2/fg 0/bg
     var curr-ah/eax: (addr handle cell) <- get remaining, left
     var curr/eax: (addr cell) <- lookup *curr-ah
     remaining-ah <- get remaining, right
@@ -83,10 +85,14 @@ fn load-globals in: (addr handle cell), self: (addr global-table) {
     allocate value-gap-buffer-ah
     var value-gap-buffer/eax: (addr gap-buffer) <- lookup *value-gap-buffer-ah
     initialize-gap-buffer value-gap-buffer, 0x1000/4KB
+#?     draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "w", 2/fg 0/bg
     load-gap-buffer-from-stream value-gap-buffer, value-data
+#?     draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "x", 2/fg 0/bg
     read-evaluate-and-move-to-globals value-gap-buffer-ah, self
+#?     draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0/screen, "y", 2/fg 0/bg
     loop
   }
+#?   abort "zz"
 }
 
 fn write-globals out: (addr stream byte), _self: (addr global-table) {
diff --git a/shell/sandbox.mu b/shell/sandbox.mu
index 2d77731a..d07d2f87 100644
--- a/shell/sandbox.mu
+++ b/shell/sandbox.mu
@@ -639,6 +639,7 @@ fn read-evaluate-and-move-to-globals _in-ah: (addr handle gap-buffer), globals:
   var read-result-h: (handle cell)
   var read-result-ah/esi: (addr handle cell) <- address read-result-h
   read-cell in, read-result-ah, 0/no-trace
+  macroexpand read-result-ah, globals, 0/no-trace
   var nil-storage: (handle cell)
   var nil-ah/eax: (addr handle cell) <- address nil-storage
   allocate-pair nil-ah