about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-07-06 02:19:32 -0700
committerKartik K. Agaram <vc@akkartik.com>2014-07-06 02:20:14 -0700
commit4363daba1f60032a117ffd1d0c34d31120e578ac (patch)
tree17e11a7afe8de7792974a6458731e5233a6508ee
parent52cbb739921116ece71bbcde1a02bed8cae9c1db (diff)
downloadmu-4363daba1f60032a117ffd1d0c34d31120e578ac.tar.gz
5 - compound functions now take args
-rw-r--r--mu.arc8
-rw-r--r--mu.arc.t19
2 files changed, 25 insertions, 2 deletions
diff --git a/mu.arc b/mu.arc
index 27b5fd9f..f8807296 100644
--- a/mu.arc
+++ b/mu.arc
@@ -8,7 +8,7 @@
   (each (name . body) fns
     (= function*.name body)))
 
-(def run (instrs (o returned))
+(def run (instrs (o fn-args) (o returned))
   (each instr instrs
     (unless returned
 ;?       (prn instr)
@@ -23,10 +23,14 @@
             add
               (= (memory* oarg.0)
                  (+ (memory* arg.0) (memory* arg.1)))
+            read
+              (= (memory* oarg.0)
+                 ; hardcoded channel for now
+                 (memory* pop.fn-args))
             return
               (set returned)
             ; else user-defined function
-              (run function*.op)
+              (run function*.op arg)
             )))))
 ;?   (prn "return")
   )
diff --git a/mu.arc.t b/mu.arc.t
index fd9c0946..6f51cda9 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -36,3 +36,22 @@
 ;? (prn memory*)
 (if (~iso memory* (obj 1 1  2 3  3 4))
   (prn "F - early return works"))
+
+(clear)
+(add-fns
+  '((add-fn
+      (4 <- read)
+      (5 <- read)
+      (3 <- add 4 5)
+      (return)
+      (4 <- loadi 34))
+    (main
+      (1 <- loadi 1)
+      (2 <- loadi 3)
+      (add-fn 1 2))))
+(run function*!main)
+;? (prn memory*)
+(if (~iso memory* (obj 1 1  2 3  3 4
+                       ; add-fn's temporaries
+                       4 1  5 3))
+  (prn "F - parameterized compound fn"))