change RET instruction to take an argument
This commit is contained in:
parent
44406a233e
commit
d7bf73a17c
|
@ -25,7 +25,7 @@ type ins =
|
|||
| CON of reg * vtable
|
||||
| CAL of reg * reg * reg * reg list
|
||||
(* control flow *)
|
||||
| RET
|
||||
| RET of reg
|
||||
| JMP of block
|
||||
| CBR of reg * block * block
|
||||
|
||||
|
@ -58,7 +58,7 @@ let frame_size t =
|
|||
in
|
||||
let meas (R i) fs = max fs (i + 1) in
|
||||
let meas_ins fs = function
|
||||
| RET -> fs
|
||||
| RET r
|
||||
| LDI (r, _)
|
||||
| CON (r, _)
|
||||
-> meas r fs
|
||||
|
@ -128,7 +128,7 @@ let pp_ins ~label ppf = function
|
|||
Fmt.pf ppf "cal %a, %a[%a](" pp_reg a pp_reg b pp_reg c;
|
||||
List.iteri (fun i d -> if i > 0 then Fmt.pf ppf ","; pp_reg ppf d) ds;
|
||||
Fmt.pf ppf ")"
|
||||
| RET -> Fmt.pf ppf "ret"
|
||||
| RET a -> Fmt.pf ppf "ret %a" pp_reg a
|
||||
| JMP b -> Fmt.pf ppf "jmp %s" (label b)
|
||||
| CBR (a, b1, b2) ->
|
||||
let l1 = label b1 in
|
||||
|
|
|
@ -60,6 +60,7 @@ end
|
|||
type frame = {
|
||||
r : Value.t array;
|
||||
mutable pc : Code.ins list;
|
||||
mutable rv : Value.t;
|
||||
}
|
||||
|
||||
let jmp fr b = fr.pc <- Code.instructions b
|
||||
|
@ -85,7 +86,8 @@ let rec exec ({ r; _ } as fr) = function
|
|||
| Code.JMP b -> jmp fr b
|
||||
| Code.CBR (R a, b1, b2) ->
|
||||
jmp fr (if Value.truthy r.(a) then b1 else b2)
|
||||
| Code.RET ->
|
||||
| Code.RET (R a) ->
|
||||
fr.rv <- r.(a);
|
||||
fr.pc <- []
|
||||
|
||||
and call mthd self args =
|
||||
|
@ -108,9 +110,9 @@ and step fr =
|
|||
|
||||
and run prog self (* args *) =
|
||||
let r = Array.make (Code.frame_size prog) Value.Nil in
|
||||
let fr = { r; pc = [] } in
|
||||
let fr = { r; pc = []; rv = Nil } in
|
||||
r.(0) <- self;
|
||||
jmp fr prog.entry;
|
||||
step fr;
|
||||
r.(0)
|
||||
fr.rv
|
||||
|
||||
|
|
Loading…
Reference in New Issue