about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2014-10-31 15:21:07 -0700
committerKartik K. Agaram <vc@akkartik.com>2014-10-31 15:21:07 -0700
commit40418ad4043eb254d9f2bf3c2307444babae95ae (patch)
tree972fdf01d1dc4a7af51e0a36df272cf1ea3a4670
parent7946c901c7903596b216472f9cdbe9ae381027c7 (diff)
downloadmu-40418ad4043eb254d9f2bf3c2307444babae95ae.tar.gz
185 - make sure functions call by value
This becomes important in the presence of scopes.
-rw-r--r--mu.arc18
-rw-r--r--mu.arc.t14
2 files changed, 24 insertions, 8 deletions
diff --git a/mu.arc b/mu.arc
index cbe6940d..344e08e4 100644
--- a/mu.arc
+++ b/mu.arc
@@ -262,13 +262,11 @@
           (cut instr (+ delim 2)))  ; args
     (list nil instr.0 cdr.instr)))
 
-(def caller-args (routine)  ; not assignable
-  (let (_ _ args)  (parse-instr ((body routine 1) (pc routine 1)))
-    args))
+(mac caller-args (routine)  ; assignable
+  `((((rep ,routine) 'call-stack) 0) 'args))
 
-(def caller-oargs (routine)  ; not assignable
-  (let (oargs _ _)  (parse-instr ((body routine 1) (pc routine 1)))
-    oargs))
+(mac caller-oargs (routine)  ; assignable
+  `((((rep ,routine) 'call-stack) 0) 'oargs))
 
 (on-init
   (= running-routines* (queue))
@@ -489,7 +487,7 @@
                                 (++ caller-arg-idx.routine*)))
                     (trace "arg" arg " " idx " " caller-args.routine*)
                     (if (len> caller-args.routine* idx)
-                      (list (m caller-args.routine*.idx) t)
+                      (list caller-args.routine*.idx t)
                       (list nil nil)))
                 reply
                   (do (pop-stack routine*)
@@ -507,7 +505,11 @@
                       (continue))
                 ; else try to call as a user-defined function
                   (do (if function*.op
-                        (push-stack routine* op)
+                        (do (push-stack routine* op)
+                            (= caller-args.routine*
+                               (accum yield
+                                 (each a arg
+                                   (yield (m a))))))
                         (err "no such op @op"))
                       (continue))
                 )
diff --git a/mu.arc.t b/mu.arc.t
index eb226398..a38ddc37 100644
--- a/mu.arc.t
+++ b/mu.arc.t
@@ -947,6 +947,20 @@
   (prn "F - function with optional second arg"))
 ;? (quit)
 
+(reset)
+(new-trace "new-fn-arg-by-value")
+(add-fns
+  '((test1
+      ((1 integer) <- copy (0 literal))
+      ((2 integer) <- arg))
+    (main
+      ((1 integer) <- copy (34 literal))
+      (test1 (1 integer)))))
+(run 'main)
+;? (prn memory*)
+(if (~iso memory* (obj 1 0  2 34))
+  (prn "F - 'arg' passes by value"))
+
 ; how should errors be handled? will be unclear until we support concurrency and routine trees.
 
 (reset)