diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/tile/data.mu | 2 | ||||
-rw-r--r-- | apps/tile/rpn.mu | 29 |
2 files changed, 23 insertions, 8 deletions
diff --git a/apps/tile/data.mu b/apps/tile/data.mu index 9b852a82..6f0f6e48 100644 --- a/apps/tile/data.mu +++ b/apps/tile/data.mu @@ -31,6 +31,8 @@ type word { scalar-data: (handle gap-buffer) text-data: (handle array byte) box-data: (handle line) # recurse + # other metadata attached to this word + subsidiary-stack: (handle value-stack) # if this word is a call next: (handle word) prev: (handle word) } diff --git a/apps/tile/rpn.mu b/apps/tile/rpn.mu index 2b45d981..fe22752b 100644 --- a/apps/tile/rpn.mu +++ b/apps/tile/rpn.mu @@ -51,12 +51,16 @@ fn evaluate defs: (addr handle function), bindings: (addr table), scratch: (addr # if curr-stream is a known function name, call it appropriately { var callee-h: (handle function) - var callee-ah/eax: (addr handle function) <- address callee-h - find-function defs, curr-stream, callee-ah - var callee/eax: (addr function) <- lookup *callee-ah + var callee/ecx: (addr function) <- copy 0 + { + var callee-ah/eax: (addr handle function) <- address callee-h + find-function defs, curr-stream, callee-ah + var _callee/eax: (addr function) <- lookup *callee-ah + callee <- copy _callee + } compare callee, 0 break-if-= - perform-call callee, out, defs + perform-call callee, out, defs, curr break $evaluate:process-word } # if it's a name, push its value @@ -119,7 +123,7 @@ fn find-function first: (addr handle function), name: (addr stream byte), out: ( } } -fn perform-call _callee: (addr function), caller-stack: (addr value-stack), defs: (addr handle function) { +fn perform-call _callee: (addr function), caller-stack: (addr value-stack), defs: (addr handle function), _current-word: (addr word) { var callee/ecx: (addr function) <- copy _callee # create bindings for args var table-storage: table @@ -153,10 +157,14 @@ fn perform-call _callee: (addr function), caller-stack: (addr value-stack), defs } # obtain body var body-ah/eax: (addr handle line) <- get callee, body - var body/eax: (addr line) <- lookup *body-ah + var _body/eax: (addr line) <- lookup *body-ah + var body/ebx: (addr line) <- copy _body # perform call - var stack-storage: value-stack - var stack/edi: (addr value-stack) <- address stack-storage + var stack-storage: (handle value-stack) + var stack-ah/edi: (addr handle value-stack) <- address stack-storage + allocate stack-ah + var _stack/eax: (addr value-stack) <- lookup *stack-ah + var stack/edx: (addr value-stack) <- copy _stack initialize-value-stack stack, 0x10 #? print-string-to-real-screen "about to enter recursive eval\n" evaluate defs, table, body, 0, stack @@ -164,6 +172,11 @@ fn perform-call _callee: (addr function), caller-stack: (addr value-stack), defs # stitch result from stack into caller var result/eax: int <- pop-int-from-value-stack stack push-int-to-value-stack caller-stack, result + # attach callee stack to curr-word in case it needs to be rendered + push-int-to-value-stack stack, result + var current-word/esi: (addr word) <- copy _current-word + var dest/eax: (addr handle value-stack) <- get current-word, subsidiary-stack + copy-object stack-ah, dest } # Copy of 'simplify' that just tracks the maximum stack depth needed |