about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-07-11 21:04:38 -0700
committerKartik K. Agaram <vc@akkartik.com>2014-07-11 21:04:38 -0700
commit6264ac68cfc8de631a69b5c8e12af3024f81f6a6 (patch)
treea7f1f6af12aa76eb0ef19c41b8583adbe0a2de86
parentf4bc8c31484c848881f9995a3b8333777fea8440 (diff)
downloadmu-6264ac68cfc8de631a69b5c8e12af3024f81f6a6.tar.gz
12 - more arithmetic ops
-rw-r--r--mu.arc14
-rw-r--r--mu.arc.t44
2 files changed, 58 insertions, 0 deletions
diff --git a/mu.arc b/mu.arc
index f87bc8d1..1f9b5318 100644
--- a/mu.arc
+++ b/mu.arc
@@ -29,6 +29,20 @@
             add
               (= (memory* oarg.0.1)
                  (+ (memory* arg.0.1) (memory* arg.1.1)))
+            sub
+              (= (memory* oarg.0.1)
+                 (- (memory* arg.0.1) (memory* arg.1.1)))
+            mul
+              (= (memory* oarg.0.1)
+                 (* (memory* arg.0.1) (memory* arg.1.1)))
+            div
+              (= (memory* oarg.0.1)
+                 (/ (real (memory* arg.0.1)) (memory* arg.1.1)))
+            idiv
+              (= (memory* oarg.0.1)
+                 (trunc:/ (memory* arg.0.1) (memory* arg.1.1))
+                 (memory* oarg.1.1)
+                 (mod (memory* arg.0.1) (memory* arg.1.1)))
             read
               (= (memory* oarg.0.1)
                  ; hardcoded channel for now
diff --git a/mu.arc.t b/mu.arc.t
index a36dad9a..c9808072 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -95,3 +95,47 @@
                          ; add-fn's temporaries
                          4 1  5 3  6 4))
   (prn "F - parameterized compound fn with multiple return values"))
+
+(clear)
+(add-fns
+  '((main
+      ((integer 1) <- loadi 1)
+      ((integer 2) <- loadi 3)
+      ((integer 3) <- sub (integer 1) (integer 2)))))
+(run function*!main)
+;? (prn memory*)
+(if (~iso memory* (obj 1 1  2 3  3 -2))
+  (prn "F - sub works"))
+
+(clear)
+(add-fns
+  '((main
+      ((integer 1) <- loadi 2)
+      ((integer 2) <- loadi 3)
+      ((integer 3) <- mul (integer 1) (integer 2)))))
+(run function*!main)
+;? (prn memory*)
+(if (~iso memory* (obj 1 2  2 3  3 6))
+  (prn "F - mul works"))
+
+(clear)
+(add-fns
+  '((main
+      ((integer 1) <- loadi 8)
+      ((integer 2) <- loadi 3)
+      ((integer 3) <- div (integer 1) (integer 2)))))
+(run function*!main)
+;? (prn memory*)
+(if (~iso memory* (obj 1 8  2 3  3 (/ real.8 3)))
+  (prn "F - div works"))
+
+(clear)
+(add-fns
+  '((main
+      ((integer 1) <- loadi 8)
+      ((integer 2) <- loadi 3)
+      ((integer 3) (integer 4) <- idiv (integer 1) (integer 2)))))
+(run function*!main)
+;? (prn memory*)
+(if (~iso memory* (obj 1 8  2 3  3 2  4 2))
+  (prn "F - idiv works"))