about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-02-21 22:06:03 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-02-21 22:08:13 -0800
commit210c48370a9cfda64e421440df4bb378b0167d0b (patch)
tree18d84e300ca78107243cf3237735dbf0bf7895ea
parent19f93c7457529a4dc04638eef5de878475067aa8 (diff)
downloadmu-210c48370a9cfda64e421440df4bb378b0167d0b.tar.gz
7777
Same identity REPL, but now going through some symbol processing.
-rw-r--r--baremetal/shell/cell.mu12
-rw-r--r--baremetal/shell/print.mu28
-rw-r--r--baremetal/shell/read.mu25
-rw-r--r--baremetal/shell/sandbox.mu20
4 files changed, 69 insertions, 16 deletions
diff --git a/baremetal/shell/cell.mu b/baremetal/shell/cell.mu
index c4f3311e..fe1dd6b6 100644
--- a/baremetal/shell/cell.mu
+++ b/baremetal/shell/cell.mu
@@ -7,6 +7,16 @@ type cell {
   number-data: float
   # type 2: symbol
   # type 3: string
-  text-data: (handle array byte)
+  text-data: (handle stream byte)
   # TODO: array, (associative) table, stream
 }
+
+fn new-symbol _out: (addr handle cell) {
+  var out/eax: (addr handle cell) <- copy _out
+  allocate out
+  var out-addr/eax: (addr cell) <- lookup *out
+  var type/ecx: (addr int) <- get out-addr, type
+  copy-to *type, 2/symbol
+  var dest-ah/eax: (addr handle stream byte) <- get out-addr, text-data
+  populate-stream dest-ah, 0x40/max-symbol-size
+}
diff --git a/baremetal/shell/print.mu b/baremetal/shell/print.mu
new file mode 100644
index 00000000..f8e9de31
--- /dev/null
+++ b/baremetal/shell/print.mu
@@ -0,0 +1,28 @@
+fn print-cell _in: (addr handle cell), out: (addr stream byte) {
+  clear-stream out
+  var in/eax: (addr handle cell) <- copy _in
+  var in-addr/eax: (addr cell) <- lookup *in
+  var in-type/ecx: (addr int) <- get in-addr, type
+  compare *in-type, 2/symbol
+  {
+    break-if-!=
+    print-symbol in-addr, out
+    return
+  }
+}
+
+fn print-symbol _in: (addr cell), out: (addr stream byte) {
+  var in/esi: (addr cell) <- copy _in
+  var data-ah/eax: (addr handle stream byte) <- get in, text-data
+  var _data/eax: (addr stream byte) <- lookup *data-ah
+  var data/esi: (addr stream byte) <- copy _data
+  rewind-stream data
+  {
+    var done?/eax: boolean <- stream-empty? data
+    compare done?, 0/false
+    break-if-!=
+    var g/eax: grapheme <- read-grapheme data
+    write-grapheme out, g
+    loop
+  }
+}
diff --git a/baremetal/shell/read.mu b/baremetal/shell/read.mu
new file mode 100644
index 00000000..ba575d83
--- /dev/null
+++ b/baremetal/shell/read.mu
@@ -0,0 +1,25 @@
+# out is not allocated
+fn read-cell in: (addr gap-buffer), _out: (addr handle cell) {
+  # TODO:
+  #   tokenize
+  #   insert parens
+  #   transform infix
+  #   token tree
+  #   syntax tree
+  rewind-gap-buffer in
+  # read symbol
+  var out/eax: (addr handle cell) <- copy _out
+  new-symbol out
+  var out-a/eax: (addr cell) <- lookup *out
+  var out-data-ah/eax: (addr handle stream byte) <- get out-a, text-data
+  var _out-data/eax: (addr stream byte) <- lookup *out-data-ah
+  var out-data/edi: (addr stream byte) <- copy _out-data
+  {
+    var done?/eax: boolean <- gap-buffer-scan-done? in
+    compare done?, 0/false
+    break-if-!=
+    var g/eax: grapheme <- read-from-gap-buffer in
+    write-grapheme out-data, g
+    loop
+  }
+}
diff --git a/baremetal/shell/sandbox.mu b/baremetal/shell/sandbox.mu
index cdce1512..c89814d4 100644
--- a/baremetal/shell/sandbox.mu
+++ b/baremetal/shell/sandbox.mu
@@ -102,19 +102,9 @@ fn edit-sandbox _self: (addr sandbox), key: byte {
 }
 
 fn run in: (addr gap-buffer), out: (addr stream byte) {
-  # tokenize
-  # insert parens
-  # transform infix
-  # token tree
-  # syntax tree
-  rewind-gap-buffer in
-  clear-stream out
-  {
-    var done?/eax: boolean <- gap-buffer-scan-done? in
-    compare done?, 0/false
-    break-if-!=
-    var g/eax: grapheme <- read-from-gap-buffer in
-    write-grapheme out, g
-    loop
-  }
+  var read-result-storage: (handle cell)
+  var read-result/esi: (addr handle cell) <- address read-result-storage
+  read-cell in, read-result
+  # TODO: eval
+  print-cell read-result, out
 }