about summary refs log tree commit diff stats
path: root/apps/tile
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-10-18 20:51:47 -0700
committerKartik Agaram <vc@akkartik.com>2020-10-18 20:51:47 -0700
commit47497ea5525e7b130136378838f8e18a9d1c8176 (patch)
tree3f8feff4b36b2c7da3fe298550875ad4c65d3f2c /apps/tile
parent82d1fe7c9cf50d63621233e4958a44afe4af9fbf (diff)
downloadmu-47497ea5525e7b130136378838f8e18a9d1c8176.tar.gz
7057 - tile: back to names
We can now create new bindings for names while evaluating lines.
Diffstat (limited to 'apps/tile')
-rw-r--r--apps/tile/rpn.mu49
1 files changed, 44 insertions, 5 deletions
diff --git a/apps/tile/rpn.mu b/apps/tile/rpn.mu
index a1ce7ec8..dde99826 100644
--- a/apps/tile/rpn.mu
+++ b/apps/tile/rpn.mu
@@ -48,6 +48,26 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch:
         push-int-to-value-stack out, a
         break $evaluate:process-word
       }
+      # if curr-stream defines a binding, save top of stack to bindings
+      {
+        var new-byte/eax: byte <- read-byte curr-stream
+        compare new-byte, 0x3d  # '='
+        break-if-!=
+        var key-h: (handle array byte)
+        var key/ecx: (addr handle array byte) <- address key-h
+        stream-to-string curr-stream, key
+        var foo/eax: (addr array byte) <- lookup *key
+        var val/eax: int <- pop-int-from-value-stack out
+        bind-int-in-table bindings, key, val
+        var line/eax: (addr line) <- copy scratch
+        var next-line-ah/eax: (addr handle line) <- get line, next
+        var next-line/eax: (addr line) <- lookup *next-line-ah
+        compare next-line, 0
+        break-if-= $evaluate:process-word
+        evaluate functions, bindings, next-line, end, out
+        break $evaluate:process-word
+      }
+      rewind-stream curr-stream
       # if curr-stream is a known function name, call it appropriately
       {
         var callee-h: (handle function)
@@ -73,11 +93,6 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch:
         var val/eax: (addr value) <- lookup *val-ah
         compare val, 0
         break-if-=
-#?         print-string-to-real-screen "value of "
-#?         print-string-to-real-screen curr-string
-#?         print-string-to-real-screen " is "
-#?         print-int32-hex-to-real-screen result
-#?         print-string-to-real-screen "\n"
         push-value-stack out, val
         break $evaluate:process-word
       }
@@ -98,6 +113,30 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch:
   }
 }
 
+fn test-evaluate {
+  var line-storage: line
+  var line/esi: (addr line) <- address line-storage
+  var first-word-ah/eax: (addr handle word) <- get line-storage, data
+  allocate-word-with first-word-ah, "3"
+  append-word-with *first-word-ah, "=a"
+  var next-line-ah/eax: (addr handle line) <- get line-storage, next
+  allocate next-line-ah
+  var next-line/eax: (addr line) <- lookup *next-line-ah
+  var first-word-ah/eax: (addr handle word) <- get next-line, data
+  allocate-word-with first-word-ah, "a"
+  var functions-storage: (handle function)
+  var functions/ecx: (addr handle function) <- address functions-storage
+  var table-storage: table
+  var table/ebx: (addr table) <- address table-storage
+  initialize-table table, 0x10
+  var stack-storage: value-stack
+  var stack/edi: (addr value-stack) <- address stack-storage
+  initialize-value-stack stack, 0x10
+  evaluate functions, table, line, 0, stack
+  var x/eax: int <- pop-int-from-value-stack stack
+  check-ints-equal x, 3, "F - test-evaluate"
+}
+
 fn find-function first: (addr handle function), name: (addr stream byte), out: (addr handle function) {
   var curr/esi: (addr handle function) <- copy first
   $find-function:loop: {