diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2014-07-11 21:53:44 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2014-07-11 21:55:26 -0700 |
commit | aa0ce16f8b1dc69912f43c9cc49d2e7302406aef (patch) | |
tree | 7c883f0d79f5353fc7714064ae393eca179ec745 | |
parent | b83c85c8a41dd0e6042e2e3a07e8550cd2eca59b (diff) | |
download | mu-aa0ce16f8b1dc69912f43c9cc49d2e7302406aef.tar.gz |
17
-rw-r--r-- | mu.arc | 22 | ||||
-rw-r--r-- | mu.arc.t | 34 |
2 files changed, 44 insertions, 12 deletions
diff --git a/mu.arc b/mu.arc index a4bf4e2d..934d480c 100644 --- a/mu.arc +++ b/mu.arc @@ -18,8 +18,9 @@ (each (name . body) fns (= function*.name body))) -(def run (instrs (o fn-args)) +(def run (instrs (o fn-args) (o otypes)) (ret result nil + (let fn-arg-idx 0 ;? (prn instrs) (for pc 0 (< pc len.instrs) (++ pc) ;? (prn pc) @@ -52,10 +53,19 @@ (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 - (memory* pop.fn-args.1)) + arg +;? (do (prn "arg " arg " fn-arg " fn-arg-idx) + (if arg +;? (do (prn "arg " arg) + (= (memory* oarg.0.1) + (memory* ((fn-args arg.0) 1))) +;? ) +;? (do (prn "no arg; using " fn-arg-idx " " fn-args.fn-arg-idx) + (= (memory* oarg.0.1) + (memory* fn-args.fn-arg-idx.1)) + (++ fn-arg-idx)) +;? ) +;? ) jmp (do (= pc arg.0.1) ;? (prn "jumping to " pc) @@ -76,7 +86,7 @@ (= (memory* o.1) (memory* pop.results.1))))) ))))) ;? (prn "return " result) - )) + ))) (awhen cdr.argv (each file it diff --git a/mu.arc.t b/mu.arc.t index 3825c4b9..5bca40b5 100644 --- a/mu.arc.t +++ b/mu.arc.t @@ -41,8 +41,8 @@ (clear) (add-fns '((add-fn - ((integer 4) <- read) - ((integer 5) <- read) + ((integer 4) <- arg) + ((integer 5) <- arg) ((integer 3) <- add (integer 4) (integer 5)) (reply) ((integer 4) <- loadi 34)) @@ -57,12 +57,34 @@ ; add-fn's temporaries 4 1 5 3)) (prn "F - parameterized compound fn")) +;? (quit) + +(clear) +(add-fns + '((add-fn + ((integer 5) <- arg 1) + ((integer 4) <- arg 0) + ((integer 3) <- add (integer 4) (integer 5)) + (reply) + ((integer 4) <- loadi 34)) + (main + ((integer 1) <- loadi 1) + ((integer 2) <- loadi 3) + (add-fn (integer 1) (integer 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 - arg with index")) +;? (quit) (clear) (add-fns '((add-fn - ((integer 4) <- read) - ((integer 5) <- read) + ((integer 4) <- arg) + ((integer 5) <- arg) ((integer 6) <- add (integer 4) (integer 5)) (reply (integer 6)) ((integer 4) <- loadi 34)) @@ -80,8 +102,8 @@ (clear) (add-fns '((add-fn - ((integer 4) <- read) - ((integer 5) <- read) + ((integer 4) <- arg) + ((integer 5) <- arg) ((integer 6) <- add (integer 4) (integer 5)) (reply (integer 6) (integer 5)) ((integer 4) <- loadi 34)) |