diff options
-rw-r--r-- | apps/tile/data.mu | 87 | ||||
-rw-r--r-- | apps/tile/environment.mu | 4 | ||||
-rw-r--r-- | apps/tile/rpn.mu | 2 |
3 files changed, 93 insertions, 0 deletions
diff --git a/apps/tile/data.mu b/apps/tile/data.mu index abfaabcc..44f2149b 100644 --- a/apps/tile/data.mu +++ b/apps/tile/data.mu @@ -261,6 +261,93 @@ fn create-primitive-functions _self: (addr handle function) { prev-word-ah <- get tmp, prev copy-object curr-word-ah, prev-word-ah tmp <- lookup *prev-word-ah + # x 1- = x 1 - + var next/esi: (addr handle function) <- get f, next + allocate next + var _f/eax: (addr function) <- lookup *next + var f/esi: (addr function) <- copy _f + var name-ah/eax: (addr handle array byte) <- get f, name + populate-text-with name-ah, "1-" + var args-ah/eax: (addr handle word) <- get f, args + allocate args-ah + var args/eax: (addr word) <- lookup *args-ah + initialize-word-with args, "x" + var body-ah/eax: (addr handle line) <- get f, body + allocate body-ah + var body/eax: (addr line) <- lookup *body-ah + initialize-line body + var curr-word-ah/ecx: (addr handle word) <- get body, data + # *curr-word = "x" + allocate curr-word-ah + var tmp/eax: (addr word) <- lookup *curr-word-ah + curr-word <- copy tmp + initialize-word-with curr-word, "x" + # *curr-word->next = "1" + next-word-ah <- get curr-word, next + allocate next-word-ah + tmp <- lookup *next-word-ah + initialize-word-with tmp, "1" + # *curr-word->next->prev = curr-word + prev-word-ah <- get tmp, prev + copy-object curr-word-ah, prev-word-ah + # curr-word = curr-word->next + curr-word-ah <- copy next-word-ah + curr-word <- copy tmp + # *curr-word->next = "-" + next-word-ah <- get curr-word, next + allocate next-word-ah + tmp <- lookup *next-word-ah + initialize-word-with tmp, "-" + # *curr-word->next->prev = curr-word + prev-word-ah <- get tmp, prev + copy-object curr-word-ah, prev-word-ah + tmp <- lookup *prev-word-ah + # x y sub = x y - + var next/esi: (addr handle function) <- get f, next + allocate next + var _f/eax: (addr function) <- lookup *next + var f/esi: (addr function) <- copy _f + var name-ah/eax: (addr handle array byte) <- get f, name + populate-text-with name-ah, "sub" + # critical lesson: args are stored in reverse order + var args-ah/eax: (addr handle word) <- get f, args + allocate args-ah + var args/eax: (addr word) <- lookup *args-ah + initialize-word-with args, "y" + var next-arg-ah/eax: (addr handle word) <- get args, next + allocate next-arg-ah + var next-arg/eax: (addr word) <- lookup *next-arg-ah + initialize-word-with next-arg, "x" + var body-ah/eax: (addr handle line) <- get f, body + allocate body-ah + var body/eax: (addr line) <- lookup *body-ah + initialize-line body + var curr-word-ah/ecx: (addr handle word) <- get body, data + # *curr-word = "x" + allocate curr-word-ah + var tmp/eax: (addr word) <- lookup *curr-word-ah + curr-word <- copy tmp + initialize-word-with curr-word, "x" + # *curr-word->next = "y" + next-word-ah <- get curr-word, next + allocate next-word-ah + tmp <- lookup *next-word-ah + initialize-word-with tmp, "y" + # *curr-word->next->prev = curr-word + prev-word-ah <- get tmp, prev + copy-object curr-word-ah, prev-word-ah + # curr-word = curr-word->next + curr-word-ah <- copy next-word-ah + curr-word <- copy tmp + # *curr-word->next = "-" + next-word-ah <- get curr-word, next + allocate next-word-ah + tmp <- lookup *next-word-ah + initialize-word-with tmp, "-" + # *curr-word->next->prev = curr-word + prev-word-ah <- get tmp, prev + copy-object curr-word-ah, prev-word-ah + tmp <- lookup *prev-word-ah } fn function-body functions: (addr handle function), _word: (addr handle word), out: (addr handle line) { diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu index 88035bcc..1017edd5 100644 --- a/apps/tile/environment.mu +++ b/apps/tile/environment.mu @@ -1258,6 +1258,10 @@ fn clear-canvas _env: (addr environment) { print-string screen, "x 2+ = x 1+ 1+" move-cursor screen, 6, 2 print-string screen, "x square = x x *" + move-cursor screen, 7, 2 + print-string screen, "x 1- = x 1 -" + move-cursor screen, 8, 2 + print-string screen, "x y sub = x y -" } fn real-grapheme? g: grapheme -> result/eax: boolean { diff --git a/apps/tile/rpn.mu b/apps/tile/rpn.mu index 7c894f55..44108580 100644 --- a/apps/tile/rpn.mu +++ b/apps/tile/rpn.mu @@ -183,6 +183,8 @@ fn perform-call _callee: (addr function), caller-stack: (addr value-stack), func push-int-to-value-stack caller-stack, result } +# pop args from the caller-stack and bind them to successive args +# implies: function args are stored in reverse order fn bind-args _callee: (addr function), caller-stack: (addr value-stack), table: (addr table) { var callee/ecx: (addr function) <- copy _callee var curr-arg-ah/eax: (addr handle word) <- get callee, args |