From 4d0fd93cb07d928dc7d9eb8e215cd8a033f9feb8 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 26 Feb 2021 22:08:26 -0800 Subject: 7813 --- baremetal/shell/read.mu | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/baremetal/shell/read.mu b/baremetal/shell/read.mu index 0c959d78..9078f7c5 100644 --- a/baremetal/shell/read.mu +++ b/baremetal/shell/read.mu @@ -1,10 +1,28 @@ # out is not allocated fn read-cell in: (addr gap-buffer), _out: (addr handle cell), trace: (addr trace) { + var tokens-storage: (stream cell 0x100) + var tokens/ecx: (addr stream cell) <- address tokens-storage + tokenize in, tokens, trace + # TODO: insert parens + # TODO: transform infix + # TODO: parse. For now we just convert first token into a symbol and return it. + var empty?/eax: boolean <- stream-empty? tokens + compare empty?, 0/false + { + break-if-!= + var out/eax: (addr handle cell) <- copy _out + allocate out + var out-addr/eax: (addr cell) <- lookup *out + read-from-stream tokens, out-addr + var type/ecx: (addr int) <- get out-addr, type + copy-to *type, 2/symbol + } +} + +fn tokenize in: (addr gap-buffer), out: (addr stream cell), trace: (addr trace) { trace-text trace, "read", "tokenize" trace-lower trace rewind-gap-buffer in - var tokens-storage: (stream cell 0x100) - var tokens/ecx: (addr stream cell) <- address tokens-storage var token-storage: cell var token/edx: (addr cell) <- address token-storage # initialize token @@ -22,23 +40,9 @@ fn read-cell in: (addr gap-buffer), _out: (addr handle cell), trace: (addr trace break-if-= return } - write-to-stream tokens, token + write-to-stream out, token loop } - # TODO: insert parens - # TODO: transform infix - # TODO: parse. For now we just convert first token into a symbol and return it. - var empty?/eax: boolean <- stream-empty? tokens - compare empty?, 0/false - { - break-if-!= - var out/eax: (addr handle cell) <- copy _out - allocate out - var out-addr/eax: (addr cell) <- lookup *out - read-from-stream tokens, out-addr - var type/ecx: (addr int) <- get out-addr, type - copy-to *type, 2/symbol - } trace-higher trace } -- cgit 1.4.1-2-gfad0