about summary refs log tree commit diff stats
path: root/shell
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-04-15 19:56:16 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-04-15 19:56:16 -0700
commit04da8ff8b0f3941f98123f821156ff445bfdb153 (patch)
tree2bd1ddfe2443ee75f3f7b55843d948ed7d6efe35 /shell
parent613b1d5734cf119494ef5921ec86bd6cf5e3e6ea (diff)
downloadmu-04da8ff8b0f3941f98123f821156ff445bfdb153.tar.gz
add some structure to the serialization format
Diffstat (limited to 'shell')
-rw-r--r--shell/gap-buffer.mu8
-rw-r--r--shell/main.mu18
2 files changed, 24 insertions, 2 deletions
diff --git a/shell/gap-buffer.mu b/shell/gap-buffer.mu
index f4ddc7dd..030bf837 100644
--- a/shell/gap-buffer.mu
+++ b/shell/gap-buffer.mu
@@ -64,6 +64,14 @@ fn emit-gap-buffer _self: (addr gap-buffer), out: (addr stream byte) {
   emit-stack-from-top right, out
 }
 
+fn append-gap-buffer _self: (addr gap-buffer), out: (addr stream byte) {
+  var self/esi: (addr gap-buffer) <- copy _self
+  var left/eax: (addr grapheme-stack) <- get self, left
+  emit-stack-from-bottom left, out
+  var right/eax: (addr grapheme-stack) <- get self, right
+  emit-stack-from-top right, out
+}
+
 # dump stack from bottom to top
 fn emit-stack-from-bottom _self: (addr grapheme-stack), out: (addr stream byte) {
   var self/esi: (addr grapheme-stack) <- copy _self
diff --git a/shell/main.mu b/shell/main.mu
index 831c7f09..47028035 100644
--- a/shell/main.mu
+++ b/shell/main.mu
@@ -50,12 +50,24 @@ fn load-sandbox data-disk: (addr disk), _self: (addr sandbox) {
     break-if-!=
     return
   }
+  # sandbox = assoc(initial-root, 'sandbox)
+  var sandbox-literal-storage: (handle cell)
+  var sandbox-literal-ah/eax: (addr handle cell) <- address sandbox-literal-storage
+  new-symbol sandbox-literal-ah, "sandbox"
+  var sandbox-literal/eax: (addr cell) <- lookup *sandbox-literal-ah
+  var sandbox-cell-storage: (handle cell)
+  var sandbox-cell-ah/edx: (addr handle cell) <- address sandbox-cell-storage
+  lookup-symbol sandbox-literal, sandbox-cell-ah, *initial-root, 0/no-globals, 0/no-trace, 0/no-screen, 0/no-keyboard
   # print: cell -> stream
-  print-cell initial-root, s, 0/no-trace
+  print-cell sandbox-cell-ah, s, 0/no-trace
   # stream -> gap-buffer
   load-gap-buffer-from-stream data, s
 }
 
+# Save state as an alist of alists:
+#   ((globals . ((a . (fn ...))
+#                ...))
+#    (sandbox . ...))
 fn store-sandbox data-disk: (addr disk), _self: (addr sandbox) {
   compare data-disk, 0/no-disk
   {
@@ -67,6 +79,8 @@ fn store-sandbox data-disk: (addr disk), _self: (addr sandbox) {
   var data/eax: (addr gap-buffer) <- lookup *data-ah
   var stream-storage: (stream byte 0x200)
   var stream/edi: (addr stream byte) <- address stream-storage
-  emit-gap-buffer data, stream
+  write stream, "((sandbox . "
+  append-gap-buffer data, stream
+  write stream, "))"
   store-sector data-disk, 0/lba, stream
 }