16 - conditional and unconditional jumps
This commit is contained in:
parent
77f8e6cd25
commit
b83c85c8a4
11
mu.arc
11
mu.arc
|
@ -3,6 +3,7 @@
|
|||
(def clear ()
|
||||
(= types* (obj
|
||||
integer (obj size 1)
|
||||
location (obj size 1)
|
||||
address (obj size 1)))
|
||||
(= memory* (table))
|
||||
(= function* (table)))
|
||||
|
@ -19,7 +20,9 @@
|
|||
|
||||
(def run (instrs (o fn-args))
|
||||
(ret result nil
|
||||
;? (prn instrs)
|
||||
(for pc 0 (< pc len.instrs) (++ pc)
|
||||
;? (prn pc)
|
||||
(let instr instrs.pc
|
||||
;? (prn instr)
|
||||
;? (prn memory*)
|
||||
|
@ -53,6 +56,14 @@
|
|||
(= (memory* oarg.0.1)
|
||||
; hardcoded channel for now
|
||||
(memory* pop.fn-args.1))
|
||||
jmp
|
||||
(do (= pc arg.0.1)
|
||||
;? (prn "jumping to " pc)
|
||||
(continue))
|
||||
jifz
|
||||
(when (is 0 (memory* arg.0.1))
|
||||
(= pc arg.1.1)
|
||||
(continue))
|
||||
reply
|
||||
(do (= result arg)
|
||||
(break))
|
||||
|
|
36
mu.arc.t
36
mu.arc.t
|
@ -151,3 +151,39 @@
|
|||
;? (prn memory*)
|
||||
(if (~iso memory* (obj 1 8))
|
||||
(prn "F - jmp works"))
|
||||
|
||||
(clear)
|
||||
(add-fns
|
||||
'((main
|
||||
((integer 1) <- loadi 8)
|
||||
(jmp (location 3))
|
||||
((integer 2) <- loadi 3)
|
||||
(reply))))
|
||||
(run function*!main)
|
||||
;? (prn memory*)
|
||||
(if (~iso memory* (obj 1 8))
|
||||
(prn "F - jmp works"))
|
||||
|
||||
(clear)
|
||||
(add-fns
|
||||
'((main
|
||||
((integer 1) <- loadi 0)
|
||||
(jifz (integer 1) (location 3))
|
||||
((integer 2) <- loadi 3)
|
||||
(reply))))
|
||||
(run function*!main)
|
||||
;? (prn memory*)
|
||||
(if (~iso memory* (obj 1 0))
|
||||
(prn "F - jifz works"))
|
||||
|
||||
(clear)
|
||||
(add-fns
|
||||
'((main
|
||||
((integer 1) <- loadi 1)
|
||||
(jifz (integer 1) (location 3))
|
||||
((integer 2) <- loadi 3)
|
||||
(reply))))
|
||||
(run function*!main)
|
||||
;? (prn memory*)
|
||||
(if (~iso memory* (obj 1 1 2 3))
|
||||
(prn "F - jifz works - 2"))
|
||||
|
|
Loading…
Reference in New Issue