From ee3ddc3961d81059863cc1ea8245306ecb381dce Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sun, 29 Nov 2020 12:51:57 -0800 Subject: 7302 - tile: at long last, division Also square roots. But there's a bug in rendering floats without precision. --- apps/tile/environment.mu | 2 +- apps/tile/rpn.mu | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'apps/tile') diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu index 4ebd41d2..6d6b91ec 100644 --- a/apps/tile/environment.mu +++ b/apps/tile/environment.mu @@ -1517,7 +1517,7 @@ fn render-primitives screen: (addr screen), bottom-margin-row: int, right-col: i row <- subtract 1 var col/edx: int <- copy 1 move-cursor screen, row, col - row, col <- render-primitive-group screen, row, col, right-col, "numbers: ", "+ - * " + row, col <- render-primitive-group screen, row, col, right-col, "numbers: ", "+ - * / sqrt " row, col <- render-primitive-group screen, row, col, right-col, "arrays: ", "len " row, col <- render-primitive-group screen, row, col, right-col, "files: ", "open read slurp lines " row, col <- render-primitive-group screen, row, col, right-col, "misc: ", "dup swap " # hack: keep these at the right of the bottom row diff --git a/apps/tile/rpn.mu b/apps/tile/rpn.mu index 193bd2c9..219e9b09 100644 --- a/apps/tile/rpn.mu +++ b/apps/tile/rpn.mu @@ -50,6 +50,26 @@ fn evaluate functions: (addr handle function), bindings: (addr table), scratch: push-number-to-value-stack out, a break $evaluate:process-word } + { + var is-div?/eax: boolean <- stream-data-equal? curr-stream, "/" + compare is-div?, 0 + break-if-= + var _b/xmm0: float <- pop-number-from-value-stack out + var b/xmm1: float <- copy _b + var a/xmm0: float <- pop-number-from-value-stack out + a <- divide b + push-number-to-value-stack out, a + break $evaluate:process-word + } + { + var is-sqrt?/eax: boolean <- stream-data-equal? curr-stream, "sqrt" + compare is-sqrt?, 0 + break-if-= + var a/xmm0: float <- pop-number-from-value-stack out + a <- square-root a + push-number-to-value-stack out, a + break $evaluate:process-word + } ## strings/arrays { var is-len?/eax: boolean <- stream-data-equal? curr-stream, "len" -- cgit 1.4.1-2-gfad0