diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-09-24 21:17:25 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-09-24 21:17:25 -0700 |
commit | 0ecd596b7040d6e3ccb5237004a46b0199e40cd0 (patch) | |
tree | 7c1311b874800dcb574710a0ae88ce7d117a7915 /apps | |
parent | a04f816cff4a2a558a522b859f8339637db6b726 (diff) | |
download | mu-0ecd596b7040d6e3ccb5237004a46b0199e40cd0.tar.gz |
6853 - tile: initialize a test function definition
Diffstat (limited to 'apps')
-rw-r--r-- | apps/tile/data.mu | 56 | ||||
-rw-r--r-- | apps/tile/rpn.mu | 3 | ||||
-rw-r--r-- | apps/tile/word.mu | 1 |
3 files changed, 59 insertions, 1 deletions
diff --git a/apps/tile/data.mu b/apps/tile/data.mu index bdd42ce5..a4ee5b4c 100644 --- a/apps/tile/data.mu +++ b/apps/tile/data.mu @@ -11,7 +11,8 @@ type sandbox { } type function { - args: (handle word) + name: (handle array byte) + args: (handle word) # in reverse order body: (handle line) # some sort of indication of spatial location next: (handle function) @@ -58,6 +59,8 @@ type table { # if 'out' is non-null, save the first word of the program there fn initialize-program _program: (addr program), out: (addr handle word) { var program/esi: (addr program) <- copy _program + var defs/eax: (addr handle function) <- get program, defs + create-primitive-defs defs var sandbox-ah/eax: (addr handle sandbox) <- get program, sandboxes allocate sandbox-ah var sandbox/eax: (addr sandbox) <- lookup *sandbox-ah @@ -97,3 +100,54 @@ fn initialize-word _self: (addr word) { initialize-gap-buffer data # TODO: sometimes initialize box-data rather than scalar-data } + +fn create-primitive-defs _self: (addr handle function) { + # x 2* = x 2 * + var self/esi: (addr handle function) <- copy _self + allocate self + var _f/eax: (addr function) <- lookup *self + var f/esi: (addr function) <- copy _f + var name-ah/eax: (addr handle array byte) <- get f, name + populate-text-with name-ah, "2*" + 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, 0 + var curr-word-ah/ecx: (addr handle word) <- get body, data + allocate curr-word-ah + var curr-word/eax: (addr word) <- lookup *curr-word-ah + initialize-word-with curr-word, "x" + curr-word-ah <- get curr-word, next + allocate curr-word-ah + curr-word <- lookup *curr-word-ah + initialize-word-with curr-word, "2" + curr-word-ah <- get curr-word, next + allocate curr-word-ah + curr-word <- lookup *curr-word-ah + initialize-word-with curr-word, "*" + # TODO: populate prev pointers +} + +fn populate-text-with _out: (addr handle array byte), _in: (addr array byte) { + var in/esi: (addr array byte) <- copy _in + var n/ecx: int <- length in + var out/edx: (addr handle array byte) <- copy _out + populate out, n + var _out-addr/eax: (addr array byte) <- lookup *out + var out-addr/edx: (addr array byte) <- copy _out-addr + var i/eax: int <- copy 0 + { + compare i, n + break-if->= + var src/esi: (addr byte) <- index in, i + var val/ecx: byte <- copy-byte *src + var dest/edi: (addr byte) <- index out-addr, i + copy-byte-to *dest, val + i <- increment + loop + } +} diff --git a/apps/tile/rpn.mu b/apps/tile/rpn.mu index 4f9a926c..83f6e909 100644 --- a/apps/tile/rpn.mu +++ b/apps/tile/rpn.mu @@ -46,6 +46,9 @@ fn evaluate defs: (addr function), bindings: (addr table), scratch: (addr line), push-int-stack out, a break $evaluate:process-word } + # HERE: if curr-text is a known function name, call it appropriately + { + } # otherwise it's an int { var n/eax: int <- parse-decimal-int-from-stream curr-text diff --git a/apps/tile/word.mu b/apps/tile/word.mu index e0d20f56..d8b7778a 100644 --- a/apps/tile/word.mu +++ b/apps/tile/word.mu @@ -3,6 +3,7 @@ fn initialize-word-with _self: (addr word), s: (addr array byte) { var self/esi: (addr word) <- copy _self var data-ah/eax: (addr handle gap-buffer) <- get self, scalar-data + allocate data-ah var data/eax: (addr gap-buffer) <- lookup *data-ah initialize-gap-buffer-with data, s } |