From 47497ea5525e7b130136378838f8e18a9d1c8176 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sun, 18 Oct 2020 20:51:47 -0700 Subject: 7057 - tile: back to names We can now create new bindings for names while evaluating lines. --- apps/tile/rpn.mu | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'apps') 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: { -- cgit 1.4.1-2-gfad0