diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-02-21 21:21:36 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-02-21 21:21:39 -0800 |
commit | 7e9e65eece359d6bb28d202eec035cf7acc5118a (patch) | |
tree | bc342dbee0f97e684aabed0c415e6a6722c16da1 /baremetal/shell | |
parent | d7c7488398474d8310539e850edd0c3de2030d3d (diff) | |
download | mu-7e9e65eece359d6bb28d202eec035cf7acc5118a.tar.gz |
7771
We might not scan directly through the gap buffer after all. Premature optimization?
Diffstat (limited to 'baremetal/shell')
-rw-r--r-- | baremetal/shell/cell.mu | 12 | ||||
-rw-r--r-- | baremetal/shell/eval.mu | 19 | ||||
-rw-r--r-- | baremetal/shell/main.mu | 5 | ||||
-rw-r--r-- | baremetal/shell/sandbox.mu | 9 |
4 files changed, 42 insertions, 3 deletions
diff --git a/baremetal/shell/cell.mu b/baremetal/shell/cell.mu new file mode 100644 index 00000000..c4f3311e --- /dev/null +++ b/baremetal/shell/cell.mu @@ -0,0 +1,12 @@ +type cell { + type: int + # type 0: pair + left: (handle cell) + right: (handle cell) + # type 1: number + number-data: float + # type 2: symbol + # type 3: string + text-data: (handle array byte) + # TODO: array, (associative) table, stream +} diff --git a/baremetal/shell/eval.mu b/baremetal/shell/eval.mu new file mode 100644 index 00000000..8af64a95 --- /dev/null +++ b/baremetal/shell/eval.mu @@ -0,0 +1,19 @@ +type interpreter { + # tokenize + # insert parens + # transform infix + # token tree + # syntax tree +} + +fn evaluate _self: (addr interpreter), in: (addr stream byte), out: (addr stream byte) { + clear-stream out + { + var done?/eax: boolean <- stream-empty? in + compare done?, 0/false + break-if-!= + var g/eax: grapheme <- read-grapheme in + write-grapheme out, g + loop + } +} diff --git a/baremetal/shell/main.mu b/baremetal/shell/main.mu index 262b9829..f3f6240c 100644 --- a/baremetal/shell/main.mu +++ b/baremetal/shell/main.mu @@ -2,6 +2,9 @@ # A Lisp with indent-sensitivity and infix, no macros. Commas are ignored. fn main { + var interpreter-storage: interpreter + var interpreter/edi: (addr interpreter) <- address interpreter-storage +#? initialize-interpreter interpreter var sandbox-storage: sandbox var sandbox/esi: (addr sandbox) <- address sandbox-storage initialize-sandbox sandbox @@ -12,7 +15,7 @@ fn main { compare key, 0 loop-if-= # no way to quit right now; just reboot - edit-sandbox sandbox, key + edit-sandbox sandbox, key, interpreter } loop } diff --git a/baremetal/shell/sandbox.mu b/baremetal/shell/sandbox.mu index 26646cbe..d1a24c47 100644 --- a/baremetal/shell/sandbox.mu +++ b/baremetal/shell/sandbox.mu @@ -59,7 +59,7 @@ fn render-sandbox screen: (addr screen), _self: (addr sandbox), _x: int, _y: int var dummy/eax: int <- draw-stream-rightward screen, value, _x, 0x30/xmax, y, 7/fg=grey, 0/bg } -fn edit-sandbox _self: (addr sandbox), key: byte { +fn edit-sandbox _self: (addr sandbox), key: byte, interpreter: (addr interpreter) { var self/esi: (addr sandbox) <- copy _self var g/edx: grapheme <- copy key { @@ -72,9 +72,14 @@ fn edit-sandbox _self: (addr sandbox), key: byte { compare g, 0x13/ctrl-s break-if-!= # ctrl-s: run sandbox(es) + var buffer-storage: (stream byte 0x1000) + var buffer/edi: (addr stream byte) <- address buffer-storage + var data-ah/eax: (addr handle gap-buffer) <- get self, data + var data/eax: (addr gap-buffer) <- lookup *data-ah + emit-gap-buffer data, buffer var value-ah/eax: (addr handle stream byte) <- get self, value var value/eax: (addr stream byte) <- lookup *value-ah - write value, "=> LISP" + evaluate interpreter, buffer, value return } add-grapheme-to-sandbox self, g |