From 2ffd995524ef5dc7fee86136b3fa0cb8247fb6b7 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 11 Feb 2021 22:03:09 -0800 Subject: 7727 - baremetal/shell: 1+1 --- baremetal/shell/eval.mu | 25 +++++++++++++++++++++++++ baremetal/shell/line.mu | 7 +++++++ baremetal/shell/value-stack.mu | 3 +++ 3 files changed, 35 insertions(+) (limited to 'baremetal/shell') diff --git a/baremetal/shell/eval.mu b/baremetal/shell/eval.mu index 2fc32a93..4352b540 100644 --- a/baremetal/shell/eval.mu +++ b/baremetal/shell/eval.mu @@ -236,3 +236,28 @@ fn evaluate _in: (addr line), end: (addr word), out: (addr value-stack) { loop } } + +fn test-eval-arithmetic { + # in + var in-storage: line + var in/esi: (addr line) <- address in-storage + parse-line "1 1 +", in + # end + var w-ah/eax: (addr handle word) <- get in, data + var end-h: (handle word) + var end-ah/ecx: (addr handle word) <- address end-h + final-word w-ah, end-ah + var end/eax: (addr word) <- lookup *end-ah + # out + var out-storage: value-stack + var out/edi: (addr value-stack) <- address out-storage + initialize-value-stack out, 8 + # + evaluate in, end, out + # + var len/eax: int <- value-stack-length out + check-ints-equal len, 1, "F - test-eval-arithmetic stack size" + var n/xmm0: float <- pop-number-from-value-stack out + var n2/eax: int <- convert n + check-ints-equal n2, 2, "F - test-eval-arithmetic result" +} diff --git a/baremetal/shell/line.mu b/baremetal/shell/line.mu index 70b0184c..f3d8d261 100644 --- a/baremetal/shell/line.mu +++ b/baremetal/shell/line.mu @@ -61,6 +61,13 @@ fn render-line screen: (addr screen), _line: (addr line), x: int, y: int, render return result } +fn parse-line in: (addr array byte), _out: (addr line) { + var out/edi: (addr line) <- copy _out + initialize-line out + var dest/eax: (addr handle word) <- get out, data + parse-words in, dest +} + #? fn main { #? # line = [aaa, bbb, ccc, ddd] #? var line-storage: line diff --git a/baremetal/shell/value-stack.mu b/baremetal/shell/value-stack.mu index c456f2e5..1ea4180f 100644 --- a/baremetal/shell/value-stack.mu +++ b/baremetal/shell/value-stack.mu @@ -1,3 +1,6 @@ +# value stacks encode the result of a program at a single point in time +# they are typically rendered vertically + type value-stack { data: (handle array value) top: int -- cgit 1.4.1-2-gfad0