diff options
-rw-r--r-- | shell/gap-buffer.mu | 15 | ||||
-rw-r--r-- | shell/main.mu | 27 |
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) { |