diff options
author | Kartik Agaram <vc@akkartik.com> | 2020-11-06 16:25:38 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2020-11-06 17:46:27 -0800 |
commit | aa96c23f0cb3b5b18202e755fc7cd2c700b7216a (patch) | |
tree | f5b2dfeaed5ec4de92ec4e40119fc34078ec9105 /apps/tile | |
parent | abba997d1bc7357f0509821c995833be66a749a0 (diff) | |
download | mu-aa96c23f0cb3b5b18202e755fc7cd2c700b7216a.tar.gz |
7198 - tile: primitive 'print'
Diffstat (limited to 'apps/tile')
-rw-r--r-- | apps/tile/environment.mu | 2 | ||||
-rw-r--r-- | apps/tile/rpn.mu | 37 | ||||
-rw-r--r-- | apps/tile/value.mu | 10 |
3 files changed, 43 insertions, 6 deletions
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu index c574b551..77949e21 100644 --- a/apps/tile/environment.mu +++ b/apps/tile/environment.mu @@ -1388,7 +1388,7 @@ fn render-column screen: (addr screen), functions: (addr handle function), bindi var top/ecx: int <- copy *top-addr var dest-offset/ecx: (offset value) <- compute-offset data, top var val/eax: (addr value) <- index data, dest-offset - render-value screen, curr-row, indented-col, val, max-width + render-value-at screen, curr-row, indented-col, val, max-width } curr-row <- increment loop diff --git a/apps/tile/rpn.mu b/apps/tile/rpn.mu index a4d10879..06d3a57d 100644 --- a/apps/tile/rpn.mu +++ b/apps/tile/rpn.mu @@ -291,6 +291,43 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch: copy-handle screen-h, dest break $evaluate:process-word } + { + var is-print?/eax: boolean <- stream-data-equal? curr-stream, "print" + compare is-print?, 0 + break-if-= + var out2/esi: (addr value-stack) <- copy out + var top-addr/ecx: (addr int) <- get out2, top + compare *top-addr, 0 + break-if-<= + # pop string 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-<= + decrement *top-addr + var data-ah/eax: (addr handle array value) <- get out2, data + var _data/eax: (addr array value) <- lookup *data-ah + var data/edi: (addr array value) <- copy _data + var top/eax: int <- copy *top-addr + var dest-offset/edx: (offset value) <- compute-offset data, top + var s/esi: (addr value) <- index data, dest-offset + # select screen from top of out (but don't pop it) + compare *top-addr, 0 + break-if-<= + var top/eax: 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 type/eax: (addr int) <- get target-val, type + compare *type, 4 # screen + break-if-!= + var dest-ah/eax: (addr handle screen) <- get target-val, screen-data + var dest/eax: (addr screen) <- lookup *dest-ah + var r/ecx: (addr int) <- get dest, cursor-row + var c/edx: (addr int) <- get dest, cursor-col + render-value-at dest, *r, *c, s, 0 + break $evaluate:process-word + } ## HACKS: we're trying to avoid turning this into Forth { var is-dup?/eax: boolean <- stream-data-equal? curr-stream, "dup" diff --git a/apps/tile/value.mu b/apps/tile/value.mu index b874ac16..3dfa2855 100644 --- a/apps/tile/value.mu +++ b/apps/tile/value.mu @@ -1,7 +1,7 @@ ## Rendering values -fn render-value screen: (addr screen), row: int, col: int, _val: (addr value), max-width: int { +fn render-value-at screen: (addr screen), row: int, col: int, _val: (addr value), max-width: int { move-cursor screen, row, col var val/esi: (addr value) <- copy _val var val-type/ecx: (addr int) <- get val, type @@ -41,7 +41,7 @@ fn render-value screen: (addr screen), row: int, col: int, _val: (addr value), m break-if-!= var val-ah/eax: (addr handle array value) <- get val, array-data var val-array/eax: (addr array value) <- lookup *val-ah - render-array screen, row, col, val-array + render-array-at screen, row, col, val-array return } compare *val-type, 3 # file @@ -101,7 +101,7 @@ $render-integer:body: { } } -fn render-array screen: (addr screen), row: int, col: int, _a: (addr array value) { +fn render-array-at screen: (addr screen), row: int, col: int, _a: (addr array value) { start-color screen, 0xf2, 7 # don't surround in spaces print-grapheme screen, 0x5b # '[' @@ -119,7 +119,7 @@ fn render-array screen: (addr screen), row: int, col: int, _a: (addr array value } var off/ecx: (offset value) <- compute-offset a, i var x/ecx: (addr value) <- index a, off - render-value screen, row, col, x, 0 + render-value-at screen, row, col, x, 0 { var w/eax: int <- value-width x, 0 add-to col, w @@ -289,7 +289,7 @@ fn value-width _v: (addr value), top-level: boolean -> _/eax: int { return 0 } -# keep sync'd with render-array +# keep sync'd with render-array-at fn array-width _a: (addr array value) -> _/eax: int { var a/esi: (addr array value) <- copy _a var max/ecx: int <- length a |