about summary refs log tree commit diff stats
path: root/baremetal/shell
diff options
context:
space:
mode:
Diffstat (limited to 'baremetal/shell')
-rw-r--r--baremetal/shell/read.mu38
1 files changed, 21 insertions, 17 deletions
diff --git a/baremetal/shell/read.mu b/baremetal/shell/read.mu
index 0c959d78..9078f7c5 100644
--- a/baremetal/shell/read.mu
+++ b/baremetal/shell/read.mu
@@ -1,10 +1,28 @@
 # out is not allocated
 fn read-cell in: (addr gap-buffer), _out: (addr handle cell), trace: (addr trace) {
+  var tokens-storage: (stream cell 0x100)
+  var tokens/ecx: (addr stream cell) <- address tokens-storage
+  tokenize in, tokens, trace
+  # TODO: insert parens
+  # TODO: transform infix
+  # TODO: parse. For now we just convert first token into a symbol and return it.
+  var empty?/eax: boolean <- stream-empty? tokens
+  compare empty?, 0/false
+  {
+    break-if-!=
+    var out/eax: (addr handle cell) <- copy _out
+    allocate out
+    var out-addr/eax: (addr cell) <- lookup *out
+    read-from-stream tokens, out-addr
+    var type/ecx: (addr int) <- get out-addr, type
+    copy-to *type, 2/symbol
+  }
+}
+
+fn tokenize in: (addr gap-buffer), out: (addr stream cell), trace: (addr trace) {
   trace-text trace, "read", "tokenize"
   trace-lower trace
   rewind-gap-buffer in
-  var tokens-storage: (stream cell 0x100)
-  var tokens/ecx: (addr stream cell) <- address tokens-storage
   var token-storage: cell
   var token/edx: (addr cell) <- address token-storage
   # initialize token
@@ -22,23 +40,9 @@ fn read-cell in: (addr gap-buffer), _out: (addr handle cell), trace: (addr trace
       break-if-=
       return
     }
-    write-to-stream tokens, token
+    write-to-stream out, token
     loop
   }
-  # TODO: insert parens
-  # TODO: transform infix
-  # TODO: parse. For now we just convert first token into a symbol and return it.
-  var empty?/eax: boolean <- stream-empty? tokens
-  compare empty?, 0/false
-  {
-    break-if-!=
-    var out/eax: (addr handle cell) <- copy _out
-    allocate out
-    var out-addr/eax: (addr cell) <- lookup *out
-    read-from-stream tokens, out-addr
-    var type/ecx: (addr int) <- get out-addr, type
-    copy-to *type, 2/symbol
-  }
   trace-higher trace
 }