diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-10-26 22:35:20 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-10-26 23:45:40 -0700 |
commit | 0f9a65dc0d10d93319eacf8ccff75a068e5f97a8 (patch) | |
tree | a34427229e12d9cbea59d71d4a94825ee24f4c85 /apps/tile/rpn.mu | |
parent | f3d1929033856ac12db84435c317c5a288f898b3 (diff) | |
download | mu-0f9a65dc0d10d93319eacf8ccff75a068e5f97a8.tar.gz |
7120 - tile: array of lines from file
Requires a quick hacky change to Mu compiler.
Diffstat (limited to 'apps/tile/rpn.mu')
-rw-r--r-- | apps/tile/rpn.mu | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/apps/tile/rpn.mu b/apps/tile/rpn.mu index 7b65b71c..2529e5ca 100644 --- a/apps/tile/rpn.mu +++ b/apps/tile/rpn.mu @@ -206,6 +206,52 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch: copy-handle empty, target-file-ah break $evaluate:process-word } + { + var is-lines?/eax: boolean <- stream-data-equal? curr-stream, "lines" + compare is-lines?, 0 + break-if-= + # pop target-val from out + var out2/esi: (addr value-stack) <- copy out + var top-addr/ecx: (addr int) <- get out2, top + compare *top-addr, 0 + break-if-<= + 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 + # check target-val is a file + var target-type-addr/eax: (addr int) <- get target-val, type + compare *target-type-addr, 3 # file + break-if-!= + # read all lines from file and save as an array of strings in target-val + # read target-val as a filename and save the handle in target-val + var file-ah/eax: (addr handle buffered-file) <- get target-val, file-data + var file/eax: (addr buffered-file) <- lookup *file-ah + var h: (handle array (handle array byte)) + var ah/ecx: (addr handle array (handle array byte)) <- address h +#? enable-screen-type-mode +#? clear-screen 0 + read-lines file, ah +#? { +#? var x/eax: (addr array (handle array byte)) <- lookup h +#? var len/eax: int <- length x +#? var foo/eax: int <- copy len +#? print-string 0, "aa: " +#? print-int32-hex 0, foo +#? print-string 0, "\n" +#? } + var target/eax: (addr handle array value) <- get target-val, array-data + save-lines h, target + # save result into target-val + var type-addr/eax: (addr int) <- get target-val, type + copy-to *type-addr, 2 # array + var target-file-ah/eax: (addr handle buffered-file) <- get target-val, file-data + var empty: (handle buffered-file) + copy-handle empty, target-file-ah + break $evaluate:process-word + } # if curr-stream defines a binding, save top of stack to bindings { var done?/eax: boolean <- stream-empty? curr-stream |