aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--reg.ml4
-rw-r--r--urm.ml14
2 files changed, 12 insertions, 6 deletions
diff --git a/reg.ml b/reg.ml
index 133ef21..d065838 100644
--- a/reg.ml
+++ b/reg.ml
@@ -8,7 +8,7 @@ open Common
8let reg_idx (Reg(idx, _)) = idx 8let reg_idx (Reg(idx, _)) = idx
9let reg_val (Reg(_, value)) = value 9let reg_val (Reg(_, value)) = value
10let reg_compar l r = (reg_val l) - (reg_val r) 10let reg_compar l r = (reg_val l) - (reg_val r)
11let reg_string (Reg (index, value)) = (string_of_int index) ^ ": " ^ (string_of_int value) 11let reg_string (Reg (index, value)) = "(" ^ (string_of_int index) ^ "," ^ (string_of_int value) ^ ")"
12 12
13let regs_get reglist index = 13let 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 =
16let regs_set reglist index value = 16let 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
19let regs_string reglist = List.map (reg_string) reglist |> String.concat ", " 19let regs_string reglist = List.map (reg_string) reglist |> String.concat ","
20 20
diff --git a/urm.ml b/urm.ml
index be9f7e4..3b7068b 100644
--- a/urm.ml
+++ b/urm.ml
@@ -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 *) 26let rec urm_run_pre pre = function
27let 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
31let urm_run_trace = urm_run (* TODO *) 30let urm_run = urm_run_pre (fun _ -> ())
31
32let 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 *)
34let urm_mk cmd_list reg_list = { instptr = (instptr_mk cmd_list) ; regs = reg_list } 40let urm_mk cmd_list reg_list = { instptr = (instptr_mk cmd_list) ; regs = reg_list }