diff options
author | pacien | 2018-04-27 12:07:02 +0200 |
---|---|---|
committer | pacien | 2018-04-27 12:07:02 +0200 |
commit | 7d05d97c8e51e77f117fc14f060bb0c54b86a135 (patch) | |
tree | 5cb9de7b3eadfaa09bbcc4de1adc2ef51e8f391f | |
parent | 3e0c5de7c0434678218a6583887f7b849dc684f9 (diff) | |
download | urm-7d05d97c8e51e77f117fc14f060bb0c54b86a135.tar.gz |
Sort regs before printing
-rw-r--r-- | reg.ml | 12 | ||||
-rw-r--r-- | reg.mli | 4 | ||||
-rw-r--r-- | urm_test.ml | 7 |
3 files changed, 10 insertions, 13 deletions
@@ -10,11 +10,7 @@ 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 = List.find (fun (Reg(idx, _)) -> idx = index) reglist |> reg_val |
14 | List.find (fun (Reg(idx, _)) -> idx = index) reglist |> reg_val | 14 | let regs_set reglist index value = Reg(index, value) :: List.filter (fun (Reg(idx, _)) -> idx != index) reglist |
15 | 15 | let regs_sort = List.sort (fun (Reg(l, _)) (Reg(r, _)) -> compare l r) | |
16 | let regs_set reglist index value = | 16 | let 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 | |||
19 | let regs_string reglist = List.map (reg_string) reglist |> String.concat "," | ||
20 | |||
@@ -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 *) |
23 | val regs_set : reg list -> regidx -> regval -> reg list | 23 | val regs_set : reg list -> regidx -> regval -> reg list |
24 | 24 | ||
25 | (* Sorts a list of registers in ascending index order *) | ||
26 | val 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. *) |
26 | val regs_string : reg list -> string | 29 | val 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 @@ | |||
6 | open Common | 6 | open Common |
7 | open Instptr | 7 | open Instptr |
8 | open Urm | 8 | open Urm |
9 | open Reg | ||
9 | open Kaputt.Abbreviations | 10 | open Kaputt.Abbreviations |
10 | 11 | ||
11 | let sort_regs = List.sort (fun (Reg(l, _)) (Reg(r, _)) -> compare l r) | ||
12 | |||
13 | let () = | 12 | let () = |
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 | ||
59 | let () = | 58 | let () = |
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 | ||
151 | let () = if Array.mem "run-tests" Sys.argv then Test.launch_tests () | 150 | let () = if Array.mem "run-tests" Sys.argv then Test.launch_tests () |
152 | 151 | ||