about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-03-04 21:24:48 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-03-04 22:05:39 -0800
commite5ff0c39a6762ea60f8deef2f21efda8b5115e3b (patch)
treebf24c6b30106ebb453ae4679e115f4c23cb11314
parent57c3617ef6570b1499270f9b2b498b5bbb3220ea (diff)
downloadmu-e5ff0c39a6762ea60f8deef2f21efda8b5115e3b.tar.gz
7849 - shell: literal numbers
-rw-r--r--shell/eval.mu26
-rw-r--r--shell/read.mu1
-rw-r--r--shell/sandbox.mu12
3 files changed, 36 insertions, 3 deletions
diff --git a/shell/eval.mu b/shell/eval.mu
index e69de29b..b8284426 100644
--- a/shell/eval.mu
+++ b/shell/eval.mu
@@ -0,0 +1,26 @@
+fn evaluate _in: (addr handle cell), out: (addr handle cell), trace: (addr trace) {
+  trace-text trace, "eval", "evaluate"
+  trace-lower trace
+  var in/eax: (addr handle cell) <- copy _in
+  var in-addr/eax: (addr cell) <- lookup *in
+  {
+    var is-nil?/eax: boolean <- is-nil? in-addr
+    compare is-nil?, 0/false
+    break-if-=
+    # nil is a literal
+    copy-object _in, out
+    trace-higher trace
+    return
+  }
+  var in-type/ecx: (addr int) <- get in-addr, type
+  compare *in-type, 1/number
+  {
+    break-if-!=
+    # numbers are literals
+    copy-object _in, out
+    trace-higher trace
+    return
+  }
+  copy-object _in, out
+  trace-higher trace
+}
diff --git a/shell/read.mu b/shell/read.mu
index d3e1dc86..96ec8d9f 100644
--- a/shell/read.mu
+++ b/shell/read.mu
@@ -1,4 +1,3 @@
-# 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
diff --git a/shell/sandbox.mu b/shell/sandbox.mu
index 49c2a5f9..6f25474a 100644
--- a/shell/sandbox.mu
+++ b/shell/sandbox.mu
@@ -174,9 +174,17 @@ fn run in: (addr gap-buffer), out: (addr stream byte), trace: (addr trace) {
     break-if-=
     return
   }
-  # TODO: eval
+  var eval-result-storage: (handle cell)
+  var eval-result/edi: (addr handle cell) <- address eval-result-storage
+  evaluate read-result, eval-result, trace
+  var error?/eax: boolean <- has-errors? trace
+  {
+    compare error?, 0/false
+    break-if-=
+    return
+  }
   clear-stream out
-  print-cell read-result, out, trace
+  print-cell eval-result, out, trace
   mark-lines-dirty trace
 }