diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-02-27 13:05:07 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-02-27 13:05:07 -0800 |
commit | cb66df2e97bd7cd9858bee9218ed37c4a977b43b (patch) | |
tree | 0bb3ce9d038d593a58c50fa9da9cc09c6c716c00 /baremetal/shell | |
parent | 03178cde6fd47f4eebb49852199681355bff5a14 (diff) | |
download | mu-cb66df2e97bd7cd9858bee9218ed37c4a977b43b.tar.gz |
7819
Diffstat (limited to 'baremetal/shell')
-rw-r--r-- | baremetal/shell/parse.mu | 11 | ||||
-rw-r--r-- | baremetal/shell/print.mu | 20 | ||||
-rw-r--r-- | baremetal/shell/sandbox.mu | 2 | ||||
-rw-r--r-- | baremetal/shell/tokenize.mu | 10 | ||||
-rw-r--r-- | baremetal/shell/trace.mu | 1 |
5 files changed, 33 insertions, 11 deletions
diff --git a/baremetal/shell/parse.mu b/baremetal/shell/parse.mu index f55adf6d..dd87ae0e 100644 --- a/baremetal/shell/parse.mu +++ b/baremetal/shell/parse.mu @@ -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. diff --git a/baremetal/shell/print.mu b/baremetal/shell/print.mu index 13605fef..1b188942 100644 --- a/baremetal/shell/print.mu +++ b/baremetal/shell/print.mu @@ -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 diff --git a/baremetal/shell/sandbox.mu b/baremetal/shell/sandbox.mu index 21cb49fd..c8841378 100644 --- a/baremetal/shell/sandbox.mu +++ b/baremetal/shell/sandbox.mu @@ -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 } diff --git a/baremetal/shell/tokenize.mu b/baremetal/shell/tokenize.mu index 07ba9f8a..6e8cca0c 100644 --- a/baremetal/shell/tokenize.mu +++ b/baremetal/shell/tokenize.mu @@ -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 diff --git a/baremetal/shell/trace.mu b/baremetal/shell/trace.mu index 0bd3ac5f..df8843f4 100644 --- a/baremetal/shell/trace.mu +++ b/baremetal/shell/trace.mu @@ -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 } |