about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-04-15 21:40:48 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-04-15 21:40:48 -0700
commit5b20f177b6743f9a72b4a4b38da973a33f3f4ced (patch)
treec07782be52e8615721c11bb04c253a20c516d6d1
parent9d367ec2ed0091e1042f1cc8cf10c78d134dac3c (diff)
downloadmu-5b20f177b6743f9a72b4a4b38da973a33f3f4ced.tar.gz
shell: restore bindings after restart
-rw-r--r--shell/global.mu37
-rw-r--r--shell/main.mu15
2 files changed, 52 insertions, 0 deletions
diff --git a/shell/global.mu b/shell/global.mu
index eb88d5fe..94c334e1 100644
--- a/shell/global.mu
+++ b/shell/global.mu
@@ -44,6 +44,27 @@ fn initialize-globals _self: (addr global-table) {
   # keep sync'd with render-primitives
 }
 
+fn load-globals in: (addr handle cell), self: (addr global-table) {
+  var remaining-ah/esi: (addr handle cell) <- copy in
+  {
+    var _remaining/eax: (addr cell) <- lookup *remaining-ah
+    var remaining/ecx: (addr cell) <- copy _remaining
+    var done?/eax: boolean <- nil? remaining
+    compare done?, 0/false
+    break-if-!=
+    var curr-ah/eax: (addr handle cell) <- get remaining, left
+    var curr/eax: (addr cell) <- lookup *curr-ah
+    remaining-ah <- get remaining, right
+    var name-ah/ecx: (addr handle cell) <- get curr, left
+    var value-ah/ebx: (addr handle cell) <- get curr, right
+    var name/eax: (addr cell) <- lookup *name-ah
+    var name-data-ah/eax: (addr handle stream byte) <- get name, text-data
+    var name-data/eax: (addr stream byte) <- lookup *name-data-ah
+    append-global-binding-of-stream self, name-data, *value-ah
+    loop
+  }
+}
+
 fn write-globals out: (addr stream byte), _self: (addr global-table) {
   var self/esi: (addr global-table) <- copy _self
   write out, "  (globals . (\n"
@@ -227,6 +248,22 @@ fn append-global _self: (addr global-table), name: (addr array byte), value: (ha
   copy-handle value, curr-value-ah
 }
 
+fn append-global-binding-of-stream _self: (addr global-table), name: (addr stream byte), value: (handle cell) {
+  var self/esi: (addr global-table) <- copy _self
+  var final-index-addr/ecx: (addr int) <- get self, final-index
+  increment *final-index-addr
+  var curr-index/ecx: int <- copy *final-index-addr
+  var data-ah/eax: (addr handle array global) <- get self, data
+  var data/eax: (addr array global) <- lookup *data-ah
+  var curr-offset/esi: (offset global) <- compute-offset data, curr-index
+  var curr/esi: (addr global) <- index data, curr-offset
+  var curr-name-ah/eax: (addr handle array byte) <- get curr, name
+  rewind-stream name
+  stream-to-array name, curr-name-ah
+  var curr-value-ah/eax: (addr handle cell) <- get curr, value
+  copy-handle value, curr-value-ah
+}
+
 fn lookup-symbol-in-globals _sym: (addr cell), out: (addr handle cell), _globals: (addr global-table), trace: (addr trace), screen-cell: (addr handle cell), keyboard-cell: (addr handle cell) {
   var sym/eax: (addr cell) <- copy _sym
   var sym-name-ah/eax: (addr handle stream byte) <- get sym, text-data
diff --git a/shell/main.mu b/shell/main.mu
index a13e6b83..8abc6ed1 100644
--- a/shell/main.mu
+++ b/shell/main.mu
@@ -48,6 +48,21 @@ fn load-state data-disk: (addr disk), _sandbox: (addr sandbox), globals: (addr g
     break-if-!=
     return
   }
+  # load globals from assoc(initial-root, 'globals)
+  var globals-literal-storage: (handle cell)
+  var globals-literal-ah/eax: (addr handle cell) <- address globals-literal-storage
+  new-symbol globals-literal-ah, "globals"
+  var globals-literal/eax: (addr cell) <- lookup *globals-literal-ah
+  var globals-cell-storage: (handle cell)
+  var globals-cell-ah/edx: (addr handle cell) <- address globals-cell-storage
+  lookup-symbol globals-literal, globals-cell-ah, *initial-root, 0/no-globals, 0/no-trace, 0/no-screen, 0/no-keyboard
+  var globals-cell/eax: (addr cell) <- lookup *globals-cell-ah
+  compare globals-cell, 0
+  {
+    break-if-!=
+    return
+  }
+  load-globals globals-cell-ah, globals
   # sandbox = assoc(initial-root, 'sandbox)
   var sandbox-literal-storage: (handle cell)
   var sandbox-literal-ah/eax: (addr handle cell) <- address sandbox-literal-storage