7101 - tile: remove quotes when evaluating strings

This found several bugs due to me not checking for null strings.
This commit is contained in:
Kartik Agaram 2020-10-25 18:45:11 -07:00
parent 8a6ad45d8d
commit a148b23a22
19 changed files with 49 additions and 7 deletions

View File

@ -25,6 +25,9 @@ write: # f: fd or (addr stream byte), s: (addr array byte)
# . prologue
55/push-ebp
89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp
# if (s == 0) return
81 7/subop/compare 1/mod/*+disp8 5/rm32/ebp . . . . 0xc/disp8 0/imm32 # compare *(ebp+12)
74/jump-if-= $write:end/disp8
# if (f < 0x08000000) _write(f, s) and return # f can't be a user-mode address, so treat it as a kernel file descriptor
81 7/subop/compare 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 0x08000000/imm32 # compare *(ebp+8)
73/jump-if-addr>= $write:fake/disp8

View File

@ -113,3 +113,44 @@ test-stream-to-string:
89/<- %esp 5/r32/ebp
5d/pop-to-ebp
c3/return
# like stream-to-string but ignore surrounding quotes
# we might do other stuff here later
unquote-stream-to-string: # in: (addr stream _), out: (addr handle array _)
# . prologue
55/push-ebp
89/<- %ebp 4/r32/esp
# . save registers
50/push-eax
51/push-ecx
52/push-edx
56/push-esi
# esi = s
8b/-> *(ebp+8) 6/r32/esi
# var len/ecx: int = s->write - s->read - 2
8b/-> *esi 1/r32/ecx
2b/subtract *(esi+4) 1/r32/ecx
81 7/subop/compare %ecx 2/imm32
7c/jump-if-< $unquote-stream-to-string:end/disp8
81 5/subop/subtract %ecx 2/imm32
# allocate
(allocate-array Heap %ecx *(ebp+0xc))
# var in/edx: (addr byte) = s->data + s->read + 1
8b/-> *(esi+4) 2/r32/edx
8d/copy-address *(esi+edx+0xd) 2/r32/edx # Stream-data + 1
# var dest/eax: (addr byte) = data for out
8b/-> *(ebp+0xc) 0/r32/eax
(lookup *eax *(eax+4)) # => eax
8d/copy-address *(eax+4) 0/r32/eax
#
(copy-bytes %edx %eax %ecx)
$unquote-stream-to-string:end:
# . restore registers
5e/pop-to-esi
5a/pop-to-edx
59/pop-to-ecx
58/pop-to-eax
# . epilogue
89/<- %esp 5/r32/ebp
5d/pop-to-ebp
c3/return

1
400.mu
View File

@ -177,6 +177,7 @@ sig new-buffered-file out: (addr handle buffered-file)
sig stream-empty? s: (addr stream _) -> result/eax: boolean
sig stream-full? s: (addr stream _) -> result/eax: boolean
sig stream-to-string in: (addr stream _), out: (addr handle array _)
sig unquote-stream-to-string in: (addr stream _), out: (addr handle array _)
sig stream-first s: (addr stream byte) -> result/eax: byte
sig stream-final s: (addr stream byte) -> result/eax: byte

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
apps/hex

Binary file not shown.

BIN
apps/mu

Binary file not shown.

BIN
apps/pack

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -77,12 +77,7 @@ fn test {
initialize-environment-with-fake-screen env, 5, 0xa
var g/eax: grapheme <- copy 0x22 # '"'
process env, g
g <- copy 0x31 # '1'
process env, g
g <- copy 0x20 # space
process env, g
g <- copy 0x33 # '3'
process env, g
render env
}
fn repl {

View File

@ -109,7 +109,7 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch:
break-if-!=
var h: (handle array byte)
var s/eax: (addr handle array byte) <- address h
stream-to-string curr-stream, s # leak
unquote-stream-to-string curr-stream, s # leak
push-string-to-value-stack out, *s
break $evaluate:process-word
}

View File

@ -130,6 +130,8 @@ fn value-stack-max-width _self: (addr value-stack) -> result/eax: int {
break-if-!=
var s-ah/eax: (addr handle array byte) <- get g, text-data
var s/eax: (addr array byte) <- lookup *s-ah
compare s, 0
break-if-=
var w/eax: int <- length s
compare w, out
break-if-<=