From 6264ac68cfc8de631a69b5c8e12af3024f81f6a6 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 11 Jul 2014 21:04:38 -0700 Subject: 12 - more arithmetic ops --- mu.arc | 14 ++++++++++++++ mu.arc.t | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) 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")) -- cgit 1.4.1-2-gfad0