diff options
-rw-r--r-- | reg.ml | 4 | ||||
-rw-r--r-- | urm.ml | 14 |
2 files changed, 12 insertions, 6 deletions
@@ -8,7 +8,7 @@ open Common | |||
8 | let reg_idx (Reg(idx, _)) = idx | 8 | let reg_idx (Reg(idx, _)) = idx |
9 | let reg_val (Reg(_, value)) = value | 9 | let reg_val (Reg(_, value)) = value |
10 | let reg_compar l r = (reg_val l) - (reg_val r) | 10 | let reg_compar l r = (reg_val l) - (reg_val r) |
11 | let reg_string (Reg (index, value)) = (string_of_int index) ^ ": " ^ (string_of_int value) | 11 | let reg_string (Reg (index, value)) = "(" ^ (string_of_int index) ^ "," ^ (string_of_int value) ^ ")" |
12 | 12 | ||
13 | let regs_get reglist index = | 13 | let regs_get reglist index = |
14 | List.find (fun (Reg(idx, _)) -> idx = index) reglist |> reg_val | 14 | List.find (fun (Reg(idx, _)) -> idx = index) reglist |> reg_val |
@@ -16,5 +16,5 @@ let regs_get reglist index = | |||
16 | let regs_set reglist index value = | 16 | let regs_set reglist index value = |
17 | Reg(index, value) :: List.filter (fun (Reg(idx, _)) -> idx != index) reglist | 17 | Reg(index, value) :: List.filter (fun (Reg(idx, _)) -> idx != index) reglist |
18 | 18 | ||
19 | let regs_string reglist = List.map (reg_string) reglist |> String.concat ", " | 19 | let regs_string reglist = List.map (reg_string) reglist |> String.concat "," |
20 | 20 | ||
@@ -23,12 +23,18 @@ let urm_apply urm = | |||
23 | | _, _ -> { instptr = urm.instptr ; regs = urm.regs } |> urm_move_down | 23 | | _, _ -> { instptr = urm.instptr ; regs = urm.regs } |> urm_move_down |
24 | in if instptr_end urm.instptr then urm else aux (instptr_get urm.instptr) | 24 | in if instptr_end urm.instptr then urm else aux (instptr_get urm.instptr) |
25 | 25 | ||
26 | (* Launches the URM *) | 26 | let rec urm_run_pre pre = function |
27 | let rec urm_run = function | ||
28 | | { instptr = InstPtr(_, []) ; regs = reg_list } -> reg_list | 27 | | { instptr = InstPtr(_, []) ; regs = reg_list } -> reg_list |
29 | | urm -> urm_apply urm |> urm_run | 28 | | urm -> pre urm; urm_apply urm |> urm_run_pre pre |
30 | 29 | ||
31 | let urm_run_trace = urm_run (* TODO *) | 30 | let urm_run = urm_run_pre (fun _ -> ()) |
31 | |||
32 | let urm_run_trace = | ||
33 | let print_func u = | ||
34 | print_endline (instptr_string u.instptr); | ||
35 | print_endline (regs_string u.regs); | ||
36 | print_newline () | ||
37 | in urm_run_pre (print_func) | ||
32 | 38 | ||
33 | (* Creates an URM from a command list and a register list *) | 39 | (* Creates an URM from a command list and a register list *) |
34 | let urm_mk cmd_list reg_list = { instptr = (instptr_mk cmd_list) ; regs = reg_list } | 40 | let urm_mk cmd_list reg_list = { instptr = (instptr_mk cmd_list) ; regs = reg_list } |