diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-10-25 20:00:36 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-10-25 20:00:36 -0700 |
commit | bdf1bf77774ae3e2b66eb9c6ce87b52b2b646fd6 (patch) | |
tree | 6f0a9c46793798c3fb3978355d84665d45f1d55b /apps/tile | |
parent | ad54c696678318126e41058182335e2bf5b30d88 (diff) | |
download | mu-bdf1bf77774ae3e2b66eb9c6ce87b52b2b646fd6.tar.gz |
7103 - tile: first primitive for strings
Diffstat (limited to 'apps/tile')
-rw-r--r-- | apps/tile/environment.mu | 2 | ||||
-rw-r--r-- | apps/tile/main.mu | 13 | ||||
-rw-r--r-- | apps/tile/rpn.mu | 38 | ||||
-rw-r--r-- | apps/tile/value-stack.mu | 6 |
4 files changed, 58 insertions, 1 deletions
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu index ed2b2c1b..1a0359b6 100644 --- a/apps/tile/environment.mu +++ b/apps/tile/environment.mu @@ -1466,7 +1466,7 @@ fn clear-canvas _env: (addr environment) { print-string screen, "functions:" start-col <- add 2 move-cursor screen, 2, start-col - print-string screen, "+ - *" + print-string screen, "+ - * len" # currently defined functions var row/ebx: int <- copy 5 var functions/esi: (addr handle function) <- get env, functions diff --git a/apps/tile/main.mu b/apps/tile/main.mu index 08e6532b..714695fd 100644 --- a/apps/tile/main.mu +++ b/apps/tile/main.mu @@ -77,6 +77,19 @@ fn test { initialize-environment-with-fake-screen env, 5, 0xa var g/eax: grapheme <- copy 0x22 # '"' process env, g + g <- copy 0x61 # 'a' + process env, g + g <- copy 0x22 # '"' + process env, g + g <- copy 0x20 # space + process env, g + g <- copy 0x6c # 'l' + process env, g + g <- copy 0x65 # 'e' + process env, g + g <- copy 0x6e # 'n' + print-string 0, "--\n" + process env, g render env } diff --git a/apps/tile/rpn.mu b/apps/tile/rpn.mu index cf0766b0..3f331639 100644 --- a/apps/tile/rpn.mu +++ b/apps/tile/rpn.mu @@ -48,6 +48,44 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch: push-int-to-value-stack out, a break $evaluate:process-word } + { + var is-len?/eax: boolean <- stream-data-equal? curr-stream, "len" + compare is-len?, 0 + break-if-= +#? print-string 0, "is len\n" + var out2/esi: (addr value-stack) <- copy out + var top-addr/ecx: (addr int) <- get out2, top + compare *top-addr, 0 + break-if-<= +#? print-string 0, "stack has stuff\n" + var data-ah/eax: (addr handle array value) <- get out2, data + var data/eax: (addr array value) <- lookup *data-ah + var top/edx: int <- copy *top-addr + top <- decrement + var dest-offset/edx: (offset value) <- compute-offset data, top + var target-val/edx: (addr value) <- index data, dest-offset + var target-type-addr/eax: (addr int) <- get target-val, type +#? print-string 0, "checking type: " +#? { +#? var foo/eax: int <- copy target-type-addr +#? print-int32-hex 0, foo +#? } +#? print-string 0, "\n" + compare *target-type-addr, 1 # string + break-if-!= +#? print-string 0, "is string\n" + var src-ah/eax: (addr handle array byte) <- get target-val, text-data + var src/eax: (addr array byte) <- lookup *src-ah + var result/ebx: int <- length src + var type-addr/eax: (addr int) <- get target-val, type + copy-to *type-addr, 0 # int + var target-string-ah/eax: (addr handle array byte) <- get target-val, text-data + var empty: (handle array byte) + copy-handle empty, target-string-ah + var target/eax: (addr int) <- get target-val, int-data + copy-to *target, result + break $evaluate:process-word + } # if curr-stream defines a binding, save top of stack to bindings { var done?/eax: boolean <- stream-empty? curr-stream diff --git a/apps/tile/value-stack.mu b/apps/tile/value-stack.mu index 7050442d..093e8846 100644 --- a/apps/tile/value-stack.mu +++ b/apps/tile/value-stack.mu @@ -45,6 +45,12 @@ fn push-string-to-value-stack _self: (addr value-stack), val: (handle array byte var dest-addr2/eax: (addr handle array byte) <- get dest-addr, text-data copy-handle val, dest-addr2 var dest-addr3/eax: (addr int) <- get dest-addr, type +#? print-string 0, "setting type to 1: " +#? { +#? var foo/eax: int <- copy dest-addr3 +#? print-int32-hex 0, foo +#? } +#? print-string 0, "\n" copy-to *dest-addr3, 1 # type string increment *top-addr } |