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)
])