aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--reg.ml12
-rw-r--r--reg.mli4
-rw-r--r--urm_test.ml7
3 files changed, 10 insertions, 13 deletions
diff --git a/reg.ml b/reg.ml
index d065838..56c4ae6 100644
--- a/reg.ml
+++ b/reg.ml
@@ -10,11 +10,7 @@ let 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 = List.find (fun (Reg(idx, _)) -> idx = index) reglist |> reg_val
14 List.find (fun (Reg(idx, _)) -> idx = index) reglist |> reg_val 14let regs_set reglist index value = Reg(index, value) :: List.filter (fun (Reg(idx, _)) -> idx != index) reglist
15 15let regs_sort = List.sort (fun (Reg(l, _)) (Reg(r, _)) -> compare l r)
16let regs_set reglist index value = 16let regs_string reglist = regs_sort reglist |> List.map (reg_string) |> String.concat ","
17 Reg(index, value) :: List.filter (fun (Reg(idx, _)) -> idx != index) reglist
18
19let regs_string reglist = List.map (reg_string) reglist |> String.concat ","
20
diff --git a/reg.mli b/reg.mli
index f5e41a0..6e81259 100644
--- a/reg.mli
+++ b/reg.mli
@@ -22,6 +22,8 @@ val regs_get : reg list -> regidx -> regval
22 * or creates it to the value specified if it does not exist *) 22 * or creates it to the value specified if it does not exist *)
23val regs_set : reg list -> regidx -> regval -> reg list 23val regs_set : reg list -> regidx -> regval -> reg list
24 24
25(* Sorts a list of registers in ascending index order *)
26val regs_sort : reg list -> reg list
27
25(* Returns the string representation of a register list. *) 28(* Returns the string representation of a register list. *)
26val regs_string : reg list -> string 29val regs_string : reg list -> string
27
diff --git a/urm_test.ml b/urm_test.ml
index bc3a0b8..f223bf6 100644
--- a/urm_test.ml
+++ b/urm_test.ml
@@ -6,10 +6,9 @@
6open Common 6open Common
7open Instptr 7open Instptr
8open Urm 8open Urm
9open Reg
9open Kaputt.Abbreviations 10open Kaputt.Abbreviations
10 11
11let sort_regs = List.sort (fun (Reg(l, _)) (Reg(r, _)) -> compare l r)
12
13let () = 12let () =
14 Test.add_simple_test 13 Test.add_simple_test
15 ~title:"example_urm_add_program" 14 ~title:"example_urm_add_program"
@@ -54,7 +53,7 @@ let () =
54 in let output_regs = urm_run output_prgm 53 in let output_regs = urm_run output_prgm
55 in 54 in
56 Assert.is_true (output_prgm = expected_urm); 55 Assert.is_true (output_prgm = expected_urm);
57 Assert.is_true ((sort_regs output_regs) = expected_output)) 56 Assert.is_true ((regs_sort output_regs) = expected_output))
58 57
59let () = 58let () =
60 Test.add_simple_test 59 Test.add_simple_test
@@ -146,7 +145,7 @@ let () =
146 in let output_regs = urm_run output_prgm 145 in let output_regs = urm_run output_prgm
147 in 146 in
148 Assert.is_true (output_prgm = expected_urm); 147 Assert.is_true (output_prgm = expected_urm);
149 Assert.is_true ((sort_regs output_regs) = expected_output)) 148 Assert.is_true ((regs_sort output_regs) = expected_output))
150 149
151let () = if Array.mem "run-tests" Sys.argv then Test.launch_tests () 150let () = if Array.mem "run-tests" Sys.argv then Test.launch_tests ()
152 151