about summary refs log tree commit diff stats
path: root/shell
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-04-14 22:04:38 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-04-14 22:04:42 -0700
commit2359e5ed63d3fc7dcd70c9c95827e781a23afbe2 (patch)
tree609ff2e637433cc77b7076fc9da73c12541d764b /shell
parent8db35826e6d96c3248d62a40c2b5137e5bdc0f1e (diff)
downloadmu-2359e5ed63d3fc7dcd70c9c95827e781a23afbe2.tar.gz
shell: load data disk as s-expr rather than string
Diffstat (limited to 'shell')
-rw-r--r--shell/gap-buffer.mu15
-rw-r--r--shell/main.mu27
2 files changed, 29 insertions, 13 deletions
diff --git a/shell/gap-buffer.mu b/shell/gap-buffer.mu
index 53f3bd54..ab515812 100644
--- a/shell/gap-buffer.mu
+++ b/shell/gap-buffer.mu
@@ -40,6 +40,21 @@ fn initialize-gap-buffer-with self: (addr gap-buffer), s: (addr array byte) {
   }
 }
 
+fn load-gap-buffer-from-stream self: (addr gap-buffer), in: (addr stream byte) {
+  rewind-stream in
+  {
+    var done?/eax: boolean <- stream-empty? in
+    compare done?, 0/false
+    break-if-!=
+    var key/eax: byte <- read-byte in
+    compare key, 0/null
+    break-if-=
+    var g/eax: grapheme <- copy key
+    edit-gap-buffer self, g
+    loop
+  }
+}
+
 fn emit-gap-buffer _self: (addr gap-buffer), out: (addr stream byte) {
   var self/esi: (addr gap-buffer) <- copy _self
   clear-stream out
diff --git a/shell/main.mu b/shell/main.mu
index 0aa034e5..5f9f919e 100644
--- a/shell/main.mu
+++ b/shell/main.mu
@@ -23,8 +23,9 @@ fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk)
   }
 }
 
-# Read a null-terminated sequence of keys from disk and load them into
-# sandbox.
+# Read an s-expression from data-disk to sandbox.
+# Gotcha: saved state with syntax errors may not load, and may need to be
+# edited as a disk image to get it to load.
 fn load-sandbox data-disk: (addr disk), _self: (addr sandbox) {
   var self/eax: (addr sandbox) <- copy _self
   var data-ah/eax: (addr handle gap-buffer) <- get self, data
@@ -35,17 +36,17 @@ fn load-sandbox data-disk: (addr disk), _self: (addr sandbox) {
   var s/ebx: (addr stream byte) <- address s-storage
   load-sector data-disk, 0/lba, s
   # stream -> gap-buffer
-  {
-    var done?/eax: boolean <- stream-empty? s
-    compare done?, 0/false
-    break-if-!=
-    var key/eax: byte <- read-byte s
-    compare key, 0/null
-    break-if-=
-    var g/eax: grapheme <- copy key
-    edit-gap-buffer data, g
-    loop
-  }
+  load-gap-buffer-from-stream data, s
+  clear-stream s
+  # read: gap-buffer -> cell
+  var initial-root-storage: (handle cell)
+  var initial-root/ecx: (addr handle cell) <- address initial-root-storage
+  read-cell data, initial-root, 0/no-trace
+  clear-gap-buffer data
+  # print: cell -> stream
+  print-cell initial-root, s, 0/no-trace
+  # stream -> gap-buffer
+  load-gap-buffer-from-stream data, s
 }
 
 fn store-sandbox data-disk: (addr disk), _self: (addr sandbox) {