about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-04-15 21:05:55 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-04-15 21:05:55 -0700
commit9d367ec2ed0091e1042f1cc8cf10c78d134dac3c (patch)
treed22a5111c6364aa873fdfedbac04500d3662a8ff
parent0f760bd60c3861766b2e50009bf2b958f5f65f8b (diff)
downloadmu-9d367ec2ed0091e1042f1cc8cf10c78d134dac3c.tar.gz
shell: start persisting global bindings
-rw-r--r--shell/global.mu36
-rw-r--r--shell/sandbox.mu5
2 files changed, 39 insertions, 2 deletions
diff --git a/shell/global.mu b/shell/global.mu
index 3410654d..eb88d5fe 100644
--- a/shell/global.mu
+++ b/shell/global.mu
@@ -45,7 +45,41 @@ fn initialize-globals _self: (addr global-table) {
 }
 
 fn write-globals out: (addr stream byte), _self: (addr global-table) {
-  write out, "  (globals . ())\n"
+  var self/esi: (addr global-table) <- copy _self
+  write out, "  (globals . (\n"
+  var data-ah/eax: (addr handle array global) <- get self, data
+  var data/eax: (addr array global) <- lookup *data-ah
+  var final-index/edx: (addr int) <- get self, final-index
+  var curr-index/ecx: int <- copy 1/skip-0
+  {
+    compare curr-index, *final-index
+    break-if->
+    var curr-offset/ebx: (offset global) <- compute-offset data, curr-index
+    var curr/ebx: (addr global) <- index data, curr-offset
+    var curr-value-ah/edx: (addr handle cell) <- get curr, value
+    var curr-value/eax: (addr cell) <- lookup *curr-value-ah
+    var curr-type/eax: (addr int) <- get curr-value, type
+    {
+      compare *curr-type, 4/primitive-function
+      break-if-=
+      compare *curr-type, 5/screen
+      break-if-=
+      compare *curr-type, 6/keyboard
+      break-if-=
+      compare *curr-type, 3/stream  # not implemented yet
+      break-if-=
+      write out, "    ("
+      var curr-name-ah/eax: (addr handle array byte) <- get curr, name
+      var curr-name/eax: (addr array byte) <- lookup *curr-name-ah
+      write out, curr-name
+      write out, " . "
+      print-cell curr-value-ah, out, 0/no-trace
+      write out, ")\n"
+    }
+    curr-index <- increment
+    loop
+  }
+  write out, "  ))\n"
 }
 
 fn render-globals screen: (addr screen), _self: (addr global-table), xmin: int, ymin: int, xmax: int, ymax: int {
diff --git a/shell/sandbox.mu b/shell/sandbox.mu
index a2fe3758..6355baa8 100644
--- a/shell/sandbox.mu
+++ b/shell/sandbox.mu
@@ -521,7 +521,10 @@ fn edit-sandbox _self: (addr sandbox), key: byte, globals: (addr global-table),
   {
     compare g, 0x13/ctrl-s
     break-if-!=
-    #
+    # minor gotcha here: any bindings created later in this iteration won't be
+    # persisted.
+    # That's ok since we don't clear the gap buffer. If we start doing so
+    # we'll need to revisit where serialization happens.
     store-state data-disk, self, globals
     # run sandbox
     var data-ah/eax: (addr handle gap-buffer) <- get self, data