about summary refs log tree commit diff stats
path: root/baremetal/shell
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-02-26 21:19:11 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-02-26 21:19:11 -0800
commitf4bf14b33889a0e6a15fbf76c3b64d49ec904efc (patch)
tree866b017c8d7ae9d5e7acaac4a34bf245b1eee5ec /baremetal/shell
parentf95fdafa5b45d1dc72c2e85c04102238e584ea7c (diff)
downloadmu-f4bf14b33889a0e6a15fbf76c3b64d49ec904efc.tar.gz
7807
Diffstat (limited to 'baremetal/shell')
-rw-r--r--baremetal/shell/read.mu126
1 files changed, 67 insertions, 59 deletions
diff --git a/baremetal/shell/read.mu b/baremetal/shell/read.mu
index 19a38501..a1cb95bf 100644
--- a/baremetal/shell/read.mu
+++ b/baremetal/shell/read.mu
@@ -39,6 +39,7 @@ fn next-token in: (addr gap-buffer), out: (addr stream byte), trace: (addr trace
       write-int32-hex stream, gval
       trace trace, "read", stream
     }
+    # digit
     {
       var digit?/eax: boolean <- is-decimal-digit? g
       compare digit?, 0/false
@@ -46,7 +47,14 @@ fn next-token in: (addr gap-buffer), out: (addr stream byte), trace: (addr trace
       next-number-token in, out, trace
       break $next-token:body
     }
-    next-symbol-token in, out, trace
+    # other symbol char
+    {
+      var symbol?/eax: boolean <- is-symbol-grapheme? g
+      compare symbol?, 0/false
+      break-if-=
+      next-symbol-token in, out, trace
+      break $next-token:body
+    }
   }
   trace-higher trace
   var stream-storage: (stream byte 0x40)
@@ -87,6 +95,64 @@ fn next-symbol-token in: (addr gap-buffer), out: (addr stream byte), trace: (add
   trace-higher trace
 }
 
+fn next-number-token in: (addr gap-buffer), out: (addr stream byte), trace: (addr trace) {
+  trace-text trace, "read", "looking for a number"
+  trace-lower trace
+  $next-number-token:loop: {
+    var done?/eax: boolean <- gap-buffer-scan-done? in
+    compare done?, 0/false
+    break-if-!=
+    var g/eax: grapheme <- peek-from-gap-buffer in
+    {
+      var stream-storage: (stream byte 0x40)
+      var stream/esi: (addr stream byte) <- address stream-storage
+      write stream, "next: "
+      var gval/eax: int <- copy g
+      write-int32-hex stream, gval
+      trace trace, "read", stream
+    }
+    # if not symbol grapheme, return
+    {
+      var symbol-grapheme?/eax: boolean <- is-symbol-grapheme? g
+      compare symbol-grapheme?, 0/false
+      break-if-!=
+      trace-text trace, "read", "stop"
+      break $next-number-token:loop
+    }
+    # if not digit grapheme, abort
+    {
+      var digit?/eax: boolean <- is-decimal-digit? g
+      compare digit?, 0/false
+      break-if-!=
+      error trace, "invalid number"
+      return
+    }
+    trace-text trace, "read", "append"
+    var g/eax: grapheme <- read-from-gap-buffer in
+    write-grapheme out, g
+    loop
+  }
+  trace-higher trace
+}
+
+fn read-symbol in: (addr stream byte), _out: (addr handle cell) {
+  rewind-stream in
+  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 <- stream-empty? in
+    compare done?, 0/false
+    break-if-!=
+    var g/eax: grapheme <- read-grapheme in
+    write-grapheme out-data, g
+    loop
+  }
+}
+
 fn is-symbol-grapheme? g: grapheme -> _/eax: boolean {
   ## whitespace
   compare g, 9/tab
@@ -254,61 +320,3 @@ fn is-symbol-grapheme? g: grapheme -> _/eax: boolean {
   }
   return 1/true
 }
-
-fn next-number-token in: (addr gap-buffer), out: (addr stream byte), trace: (addr trace) {
-  trace-text trace, "read", "looking for a number"
-  trace-lower trace
-  $next-number-token:loop: {
-    var done?/eax: boolean <- gap-buffer-scan-done? in
-    compare done?, 0/false
-    break-if-!=
-    var g/eax: grapheme <- peek-from-gap-buffer in
-    {
-      var stream-storage: (stream byte 0x40)
-      var stream/esi: (addr stream byte) <- address stream-storage
-      write stream, "next: "
-      var gval/eax: int <- copy g
-      write-int32-hex stream, gval
-      trace trace, "read", stream
-    }
-    # if not symbol grapheme, return
-    {
-      var symbol-grapheme?/eax: boolean <- is-symbol-grapheme? g
-      compare symbol-grapheme?, 0/false
-      break-if-!=
-      trace-text trace, "read", "stop"
-      break $next-number-token:loop
-    }
-    # if not digit grapheme, abort
-    {
-      var digit?/eax: boolean <- is-decimal-digit? g
-      compare digit?, 0/false
-      break-if-!=
-      error trace, "invalid number"
-      return
-    }
-    trace-text trace, "read", "append"
-    var g/eax: grapheme <- read-from-gap-buffer in
-    write-grapheme out, g
-    loop
-  }
-  trace-higher trace
-}
-
-fn read-symbol in: (addr stream byte), _out: (addr handle cell) {
-  rewind-stream in
-  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 <- stream-empty? in
-    compare done?, 0/false
-    break-if-!=
-    var g/eax: grapheme <- read-grapheme in
-    write-grapheme out-data, g
-    loop
-  }
-}
pre>19
20
21
22
23
24
25
26
27
28
29
30