7011 - tile: keep garbage out of the stack

This commit is contained in:
Kartik Agaram 2020-10-12 11:39:28 -07:00
parent 598f942624
commit 6c21568f03
3 changed files with 28 additions and 14 deletions

View File

@ -1,5 +1,6 @@
# Helpers for decimal ints.
# if slice doesn't contain a decimal number, return 0
parse-decimal-int-from-slice: # in: (addr slice) -> out/eax: int
# . prologue
55/push-ebp
@ -18,6 +19,7 @@ $parse-decimal-int-from-slice:end:
5d/pop-to-ebp
c3/return
# if slice doesn't contain a decimal number, return 0
parse-decimal-int: # in: (addr array byte) -> result/eax: int
# . prologue
55/push-ebp
@ -110,8 +112,19 @@ $parse-decimal-int-helper:loop:
# if (curr >= in->end) break
39/compare %esi 7/r32/edi
73/jump-if-addr>= break/disp8
# digit = from-decimal-char(*curr)
# if !is-decimal-digit?(*curr) return 0
8a/copy-byte *esi 1/r32/CL
50/push-eax
(is-decimal-digit? %ecx) # => eax
{
3d/compare-eax-and 0/imm32/false
75/jump-if-!= break/disp8
58/pop-to-eax
b8/copy-to-eax 0/imm32
eb/jump $parse-decimal-int-helper:negate/disp8
}
58/pop-to-eax
# digit = from-decimal-char(*curr)
81 5/subop/subtract %ecx 0x30/imm32/zero
# TODO: error checking
# result = result * 10 + digit

View File

@ -563,6 +563,9 @@ fn render _env: (addr environment) {
fn render-sandbox screen: (addr screen), functions: (addr handle function), bindings: (addr table), _sandbox: (addr sandbox), top-row: int, left-col: int {
var sandbox/esi: (addr sandbox) <- copy _sandbox
#? print-string 0, "rendering sandbox from "
#? print-int32-decimal 0, left-col
#? print-string 0, "\n"
# expanded-words
var expanded-words/edi: (addr handle call-path) <- get sandbox, expanded-words
# line
@ -714,6 +717,9 @@ fn render-line screen: (addr screen), functions: (addr handle function), binding
#? increment top-row
# render main column
var old-col/edx: int <- copy curr-col
#? print-string 0, "rendering line from "
#? print-int32-decimal 0, curr-col
#? print-string 0, "\n"
curr-col <- render-column screen, functions, bindings, line, curr-word, top-row, curr-col
# cache cursor column if necessary
$render-line:cache-cursor-column: {
@ -747,6 +753,9 @@ fn render-column screen: (addr screen), functions: (addr handle function), bindi
# indent stack
var indented-col/ebx: int <- copy left-col
indented-col <- add 1 # margin-right - 2 for padding spaces
#? print-string 0, "rendering stack from "
#? print-int32-decimal 0, indented-col
#? print-string 0, "\n"
# compute stack
var stack: value-stack
var stack-addr/edi: (addr value-stack) <- address stack
@ -761,6 +770,9 @@ fn render-column screen: (addr screen), functions: (addr handle function), bindi
{
compare i, 0
break-if-<=
#? print-string 0, "rendering stack row from "
#? print-int32-decimal 0, indented-col
#? print-string 0, "\n"
move-cursor screen, curr-row, indented-col
{
var val/eax: int <- pop-int-from-value-stack stack-addr

View File

@ -75,20 +75,9 @@ fn test {
var env-storage: environment
var env/esi: (addr environment) <- address env-storage
initialize-environment-with-fake-screen env, 0x30, 0xa0 # 48 rows, 160 columns
var g/eax: grapheme <- copy 0x31 # '1'
process env, g
g <- copy 0x20 # space
process env, g
g <- copy 0x32 # '2'
process env, g
g <- copy 0x445b1b # left-arrow
process env, g
g <- copy 0x445b1b # left-arrow
process env, g
g <- copy 0x445b1b # left-arrow
process env, g
g <- copy 5 # <ctrl-e>
var g/eax: grapheme <- copy 0x73 # 's'
process env, g
render env
}
fn repl {