From 40418ad4043eb254d9f2bf3c2307444babae95ae Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 31 Oct 2014 15:21:07 -0700 Subject: 185 - make sure functions call by value This becomes important in the presence of scopes. --- mu.arc | 18 ++++++++++-------- mu.arc.t | 14 ++++++++++++++ 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) -- cgit 1.4.1-2-gfad0 ef7702b3c4'>pwned.go
blob: 57a1727c5f5783c06e6c15672b1ae99d0a2a3b91 (plain) (tree)