This commit is contained in:
Kartik K. Agaram 2021-02-27 13:05:07 -08:00
parent 03178cde6f
commit cb66df2e97
5 changed files with 33 additions and 11 deletions

View File

@ -1,4 +1,6 @@
fn parse-sexpression tokens: (addr stream cell), _out: (addr handle cell), trace: (addr trace) {
trace-text trace, "read", "parse"
trace-lower trace
rewind-stream tokens
var curr-token-storage: cell
var curr-token/ecx: (addr cell) <- address curr-token-storage
@ -10,6 +12,7 @@ fn parse-sexpression tokens: (addr stream cell), _out: (addr handle cell), trace
var curr-token-data-ah/eax: (addr handle stream byte) <- get curr-token, text-data
var _curr-token-data/eax: (addr stream byte) <- lookup *curr-token-data-ah
var curr-token-data/esi: (addr stream byte) <- copy _curr-token-data
trace trace, "read", curr-token-data
# number
var is-number-token?/eax: boolean <- is-number-token? curr-token
compare is-number-token?, 0/false
@ -24,6 +27,14 @@ fn parse-sexpression tokens: (addr stream cell), _out: (addr handle cell), trace
var out-addr/eax: (addr cell) <- lookup *out
var dest/edi: (addr float) <- get out-addr, number-data
copy-to *dest, val-float
{
var stream-storage: (stream byte 0x40)
var stream/ecx: (addr stream byte) <- address stream-storage
trace-higher trace
write stream, "=> number "
print-number out-addr, stream, 0/no-trace
trace trace, "read", stream
}
return
}
# Temporary default: just convert first token to symbol and return it.

View File

@ -1,4 +1,4 @@
fn print-cell _in: (addr handle cell), out: (addr stream byte) {
fn print-cell _in: (addr handle cell), out: (addr stream byte), trace: (addr trace) {
clear-stream out
var in/eax: (addr handle cell) <- copy _in
var in-addr/eax: (addr cell) <- lookup *in
@ -6,18 +6,23 @@ fn print-cell _in: (addr handle cell), out: (addr stream byte) {
compare *in-type, 1/number
{
break-if-!=
print-number in-addr, out
print-number in-addr, out, trace
return
}
compare *in-type, 2/symbol
{
break-if-!=
print-symbol in-addr, out
print-symbol in-addr, out, trace
return
}
}
fn print-symbol _in: (addr cell), out: (addr stream byte) {
fn print-symbol _in: (addr cell), out: (addr stream byte), trace: (addr trace) {
{
compare trace, 0
break-if-=
trace-text trace, "print", "symbol"
}
var in/esi: (addr cell) <- copy _in
var data-ah/eax: (addr handle stream byte) <- get in, text-data
var _data/eax: (addr stream byte) <- lookup *data-ah
@ -33,7 +38,12 @@ fn print-symbol _in: (addr cell), out: (addr stream byte) {
}
}
fn print-number _in: (addr cell), out: (addr stream byte) {
fn print-number _in: (addr cell), out: (addr stream byte), trace: (addr trace) {
{
compare trace, 0
break-if-=
trace-text trace, "print", "number"
}
var in/esi: (addr cell) <- copy _in
var val/eax: (addr float) <- get in, number-data
write-float-decimal-approximate out, *val, 3/precision

View File

@ -175,7 +175,7 @@ fn run in: (addr gap-buffer), out: (addr stream byte), trace: (addr trace) {
return
}
# TODO: eval
print-cell read-result, out
print-cell read-result, out, trace
mark-lines-dirty trace
}

View File

@ -8,14 +8,14 @@ fn tokenize in: (addr gap-buffer), out: (addr stream cell), trace: (addr trace)
rewind-gap-buffer in
var token-storage: cell
var token/edx: (addr cell) <- address token-storage
# initialize token
var dest-ah/eax: (addr handle stream byte) <- get token, text-data
populate-stream dest-ah, 0x40/max-token-size
#
{
var done?/eax: boolean <- gap-buffer-scan-done? in
compare done?, 0/false
break-if-!=
# initialize token data each iteration to avoid aliasing
var dest-ah/eax: (addr handle stream byte) <- get token, text-data
populate-stream dest-ah, 0x40/max-token-size
#
next-token in, token, trace
var error?/eax: boolean <- has-errors? trace
compare error?, 0/false
@ -23,7 +23,7 @@ fn tokenize in: (addr gap-buffer), out: (addr stream cell), trace: (addr trace)
break-if-=
return
}
write-to-stream out, token
write-to-stream out, token # shallow-copy text-data
loop
}
trace-higher trace

View File

@ -90,6 +90,7 @@ fn trace _self: (addr trace), label: (addr array byte), message: (addr stream by
var offset/ecx: (offset trace-line) <- compute-offset data, index
var dest/eax: (addr trace-line) <- index data, offset
var depth/ecx: (addr int) <- get self, curr-depth
rewind-stream message
initialize-trace-line *depth, label, message, dest
increment *index-addr
}