about summary refs log tree commit diff stats
path: root/apps/arith.mu
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-06-15 23:23:09 -0700
committerKartik Agaram <vc@akkartik.com>2020-06-15 23:23:09 -0700
commit525c3986368b3609c964b2bcfc69c246477cd46c (patch)
tree5ccef8e529e0fff99f9c16c54bbf16c5d74da5dd /apps/arith.mu
parent99a8ea89e2954f011e1795955f8832bffad84df3 (diff)
downloadmu-525c3986368b3609c964b2bcfc69c246477cd46c.tar.gz
6540 - arith: mul
I forgot that Mu doesn't have div yet.
Diffstat (limited to 'apps/arith.mu')
-rw-r--r--apps/arith.mu52
1 files changed, 52 insertions, 0 deletions
diff --git a/apps/arith.mu b/apps/arith.mu
index 6821efcf..743480de 100644
--- a/apps/arith.mu
+++ b/apps/arith.mu
@@ -63,7 +63,59 @@ fn simplify -> result/eax: int, look/esi: byte {
 
 fn term _look: byte -> result/eax: int, look/esi: byte {
   look <- copy _look  # should be a no-op
+  look <- skip-spaces look
   result, look <- num look
+  $term:loop: {
+    # operator
+    var op/ecx: byte <- copy 0
+    look <- skip-spaces look
+    compare look, 0
+    break-if-=
+    compare look, 0xa
+    break-if-=
+    {
+      var continue?/eax: boolean <- is-mul-or-div? look
+      compare continue?, 0  # false
+      break-if-= $term:loop
+    }
+    op, look <- operator look
+    # second arg
+    var second/edx: int <- copy 0
+    look <- skip-spaces look
+    {
+      var tmp/eax: int <- copy 0
+      tmp, look <- num look
+      second <- copy tmp
+    }
+    # perform op
+    $term:perform-op: {
+      {
+        compare op, 0x2a  # '*'
+        break-if-!=
+        result <- multiply second
+        break $term:perform-op
+      }
+#?       {
+#?         compare op, 0x2f  # '/'
+#?         break-if-!=
+#?         result <- divide second  # not in Mu yet
+#?         break $term:perform-op
+#?       }
+    }
+    loop
+  }
+}
+
+fn is-mul-or-div? c: byte -> result/eax: bool {
+$is-mul-or-div?:body: {
+  compare c, 0x2a
+  {
+    break-if-!=
+    result <- copy 1  # true
+    break $is-mul-or-div?:body
+  }
+  result <- copy 0  # false
+}  # $is-mul-or-div?:body
 }
 
 fn operator _look: byte -> op/ecx: byte, look/esi: byte {