5 - compound functions now take args
This commit is contained in:
parent
52cbb73992
commit
4363daba1f
8
mu.arc
8
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")
|
||||
)
|
||||
|
|
19
mu.arc.t
19
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"))
|
||||
|
|
Loading…
Reference in New Issue