6829 - tile: colorize values on the stack

This commit is contained in:
Kartik Agaram 2020-09-21 21:27:44 -07:00
parent 2404478a7f
commit e655f673b5
4 changed files with 78 additions and 7 deletions

View File

@ -81,3 +81,11 @@ fn test-try-divide-9 {
var result/eax: int <- try-divide 0x1c, 3 # 28/3
check-ints-equal result, 9, "F - try-divide-9\n"
}
# only positive inouts for now
fn try-modulo nr: int, dr: int -> result/eax: int {
var tmp/eax: int <- try-divide nr, dr
tmp <- multiply dr
tmp <- subtract nr
result <- negate
}

BIN
apps/mu

Binary file not shown.

View File

@ -18940,6 +18940,45 @@ _Primitive-compare-mem-with-literal: # (payload primitive)
0/imm32/no-disp32
0/imm32/output-is-write-only
0x11/imm32/alloc-id:fake
_Primitive-negate-reg/imm32/next
# - negate
_Primitive-negate-reg: # (payload primitive)
0x11/imm32/alloc-id:fake:payload
# var1/reg <- negate => f7 3/subop/negate var1/rm32
0x11/imm32/alloc-id:fake
_string-negate/imm32/name
0/imm32/no-inouts
0/imm32/no-inouts
0x11/imm32/alloc-id:fake
Single-int-var-in-some-register/imm32/outputs
0x11/imm32/alloc-id:fake
_string_f7_subop_negate/imm32/subx-name
3/imm32/rm32-is-first-output
0/imm32/no-r32
0/imm32/no-imm32
0/imm32/no-imm8
0/imm32/no-disp32
0/imm32/output-is-write-only
0x11/imm32/alloc-id:fake
_Primitive-negate-mem/imm32/next
_Primitive-negate-mem: # (payload primitive)
0x11/imm32/alloc-id:fake:payload
# negate var1 => f7 3/subop/negate var1/rm32
0x11/imm32/alloc-id:fake
_string-negate/imm32/name
0x11/imm32/alloc-id:fake
Single-int-var-in-mem/imm32/inouts
0/imm32/no-outputs
0/imm32/no-outputs
0x11/imm32/alloc-id:fake
_string_f7_subop_negate/imm32/subx-name
1/imm32/rm32-is-first-inout
0/imm32/no-r32
0/imm32/no-imm32
0/imm32/no-imm8
0/imm32/no-disp32
0/imm32/output-is-write-only
0x11/imm32/alloc-id:fake
_Primitive-multiply-reg-by-reg/imm32/next
# - multiply
_Primitive-multiply-reg-by-reg: # (payload primitive)
@ -19951,6 +19990,11 @@ _string-multiply: # (payload array byte)
# "multiply"
0x8/imm32/size
0x6d/m 0x75/u 0x6c/l 0x74/t 0x69/i 0x70/p 0x6c/l 0x79/y
_string-negate: # (payload array byte)
0x11/imm32/alloc-id:fake:payload
# "negate"
0x6/imm32/size
0x6e/n 0x65/e 0x67/g 0x61/a 0x74/t 0x65/e
_string-or: # (payload array byte)
0x11/imm32/alloc-id:fake:payload
# "or"
@ -20408,6 +20452,11 @@ _string_e9_jump_loop: # (payload array byte)
# "e9/jump loop/disp32"
0x13/imm32/size
0x65/e 0x39/9 0x2f/slash 0x6a/j 0x75/u 0x6d/m 0x70/p 0x20/space 0x6c/l 0x6f/o 0x6f/o 0x70/p 0x2f/slash 0x64/d 0x69/i 0x73/s 0x70/p 0x33/3 0x32/2
_string_f7_subop_negate:
0x11/imm32/alloc-id:fake:payload
# "f7 3/subop/negate"
0x11/imm32/size
0x66/f 0x37/7 0x20/space 0x33/3 0x2f/slash 0x73/s 0x75/u 0x62/b 0x6f/o 0x70/p 0x2f/slash 0x6e/n 0x65/e 0x67/g 0x61/a 0x74/t 0x65/e
_string_ff_subop_increment: # (payload array byte)
0x11/imm32/alloc-id:fake:payload
# "ff 0/subop/increment"

View File

@ -192,7 +192,7 @@ fn render _env: (addr environment) {
# - Return the farthest column written.
# - If final-word is same as cursor-word, do some additional computation to set
# cursor-col-a.
fn render-column screen: (addr screen), first-word: (addr word), final-word: (addr word), botleft-col: int, cursor-word: (addr word), cursor-col-a: (addr int) -> right-col/ecx: int {
fn render-column screen: (addr screen), first-word: (addr word), final-word: (addr word), left-col: int, cursor-word: (addr word), cursor-col-a: (addr int) -> right-col/ecx: int {
var max-width/ecx: int <- copy 0
{
# render stack for all but final column
@ -202,8 +202,8 @@ fn render-column screen: (addr screen), first-word: (addr word), final-word: (ad
compare next, 0
break-if-=
# indent stack
var indented-col/ebx: int <- copy botleft-col
indented-col <- add 2
var indented-col/ebx: int <- copy left-col
indented-col <- add 1
# compute stack
var stack: int-stack
var stack-addr/edi: (addr int-stack) <- address stack
@ -218,7 +218,7 @@ fn render-column screen: (addr screen), first-word: (addr word), final-word: (ad
move-cursor screen, curr-row, indented-col
{
var val/eax: int <- pop-int-stack stack-addr
print-int32-decimal screen, val
render-integer screen, val
var size/eax: int <- decimal-size val
compare size, max-width
break-if-<=
@ -231,7 +231,8 @@ fn render-column screen: (addr screen), first-word: (addr word), final-word: (ad
}
# render word, initialize result
move-cursor screen, 3, botleft-col # input-row
reset-formatting screen
move-cursor screen, 3, left-col # input-row
print-word screen, final-word
{
var size/eax: int <- word-length final-word
@ -246,13 +247,26 @@ fn render-column screen: (addr screen), first-word: (addr word), final-word: (ad
compare f, cursor-word
break-if-!=
var cursor-index/eax: int <- cursor-index cursor-word
cursor-index <- add botleft-col
cursor-index <- add left-col
var dest/edi: (addr int) <- copy cursor-col-a
copy-to *dest, cursor-index
}
# post-process right-col
right-col <- copy max-width
right-col <- add botleft-col
right-col <- add left-col
right-col <- add 3 # margin-right
}
# synaesthesia
fn render-integer screen: (addr screen), val: int {
var fg/eax: int <- hash-color val
start-color screen, fg, 7
print-grapheme screen, 0x20 # space
print-int32-decimal screen, val
print-grapheme screen, 0x20 # space
}
fn hash-color val: int -> result/eax: int {
result <- try-modulo val, 7 # assumes that 7 is always the background color
}