fn render-value-at screen: (addr screen), row: int, col: int, _val: (addr value), top-level?: boolean { move-cursor screen, row, col var val/esi: (addr value) <- copy _val var val-type/ecx: (addr int) <- get val, type # per-type rendering logic goes here compare *val-type, 1/string { break-if-!= var val-ah/eax: (addr handle array byte) <- get val, text-data var val-string/eax: (addr array byte) <- lookup *val-ah compare val-string, 0 break-if-= var orig-len/ecx: int <- length val-string var truncated: (handle array byte) var truncated-ah/esi: (addr handle array byte) <- address truncated substring val-string, 0, 0xc, truncated-ah var truncated-string/eax: (addr array byte) <- lookup *truncated-ah var len/edx: int <- length truncated-string start-color screen, 0xf2, 7 print-code-point screen, 0x275d/open-quote print-string screen, truncated-string compare len, orig-len { break-if-= print-code-point screen, 0x2026/ellipses } print-code-point screen, 0x275e/close-quote reset-formatting screen return } compare *val-type, 2/array { 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-at screen, row, col, val-array return } compare *val-type, 3/file { break-if-!= var val-ah/eax: (addr handle buffered-file) <- get val, file-data var val-file/eax: (addr buffered-file) <- lookup *val-ah start-color screen, 0, 7 # TODO print-string screen, " FILE " return } compare *val-type, 4/screen { break-if-!= #? print-string 0, "render-screen" var val-ah/eax: (addr handle screen) <- get val, screen-data var val-screen/eax: (addr screen) <- lookup *val-ah render-screen screen, row, col, val-screen #? print-string 0, "}\n" return } # render ints by default for now var val-num/eax: (addr float) <- get val, number-data render-number screen, *val-num, top-level? } # synaesthesia # TODO: right-justify fn render-number screen: (addr screen), val: float, top-level?: boolean { # if we're inside an array, don't color compare top-level?, 0 { break-if-!= print-float-decimal-approximate screen, val, 3 return } var val-int/eax: int <- convert val var bg/eax: int <- hash-color val-int var fg/ecx: int <- copy 7 { compare bg, 2 break-if-!= fg <- copy 0 } { compare bg, 3 break-if-!= fg <- copy 0 } { compare bg, 6 break-if-!= fg <- copy 0 } start-color screen, fg, bg print-grapheme screen, 0x20/space print-float-decimal-approximate screen, val, 3 print-grapheme screen, 0x20/space } 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/[ increment col var a/esi: (addr array value) <- copy _a var max/ecx: int <- length a var i/eax: int <- copy 0 { compare i, max break-if->= { compare i, 0 break-if-= print-string screen, " " } var off/ecx: (offset value) <- compute-offset a, i var x/ecx: (addr value) <- index a, off render-value-at screen, row, col, x, 0 { var w/eax: int <- value-width x, 0 add-to col, w increment col } i <- increment loop } print-grapheme screen, 0x5d/] } fn render-screen screen: (addr screen),
(function main [
  (x:integer <- copy 1:literal)
  (y:integer <- copy 3:literal)
  (z:integer <- add x:integer y:integer)
  ($dump-memory)
])
loop } copy-array-object src, dest-ah return } compare *type, 3/file { break-if-!= #? print-string 0, "file value\n" var src-filename-ah/eax: (addr handle array byte) <- get src, filename var _src-filename/eax: (addr array byte) <- lookup *src-filename-ah var src-filename/ecx: (addr array byte) <- copy _src-filename var dest-filename-ah/ebx: (addr handle array byte) <- get dest, filename copy-array-object src-filename, dest-filename-ah var src-file-ah/eax: (addr handle buffered-file) <- get src, file-data var src-file/eax: (addr buffered-file) <- lookup *src-file-ah var dest-file-ah/edx: (addr handle buffered-file) <- get dest, file-data copy-file src-file, dest-file-ah, src-filename return } compare *type, 4/screen { break-if-!= #? print-string 0, "screen value\n" var src-screen-ah/eax: (addr handle screen) <- get src, screen-data var _src-screen/eax: (addr screen) <- lookup *src-screen-ah var src-screen/ecx: (addr screen) <- copy _src-screen var dest-screen-ah/eax: (addr handle screen) <- get dest, screen-data allocate dest-screen-ah var dest-screen/eax: (addr screen) <- lookup *dest-screen-ah copy-object src-screen, dest-screen var dest-screen-data-ah/ebx: (addr handle array screen-cell) <- get dest-screen, data var src-screen-data-ah/eax: (addr handle array screen-cell) <- get src-screen, data var src-screen-data/eax: (addr array screen-cell) <- lookup *src-screen-data-ah copy-array-object src-screen-data, dest-screen-data-ah return } }