aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/eurm.ml10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/eurm.ml b/src/eurm.ml
index b462775..cb5a9cd 100644
--- a/src/eurm.ml
+++ b/src/eurm.ml
@@ -45,12 +45,12 @@ let add_reg_label state new_regs new_labels = {
45let rec apply_transform transform_func state = function 45let rec apply_transform transform_func state = function
46 | [] -> [], state 46 | [] -> [], state
47 | cmd :: tail -> 47 | cmd :: tail ->
48 let substitution, new_state = transform_func cmd 48 let substitution, new_state = transform_func state cmd
49 in let prgm_tail, end_state = apply_transform transform_func new_state tail 49 in let prgm_tail, end_state = apply_transform transform_func new_state tail
50 in substitution @ prgm_tail, end_state 50 in substitution @ prgm_tail, end_state
51 51
52let compile_stage1 eurmcmds state = 52let compile_stage1 eurmcmds state =
53 let transform = function 53 let transform state = function
54 | Dec(r) -> 54 | Dec(r) ->
55 let new_reg = state.max_reg + 1 55 let new_reg = state.max_reg + 1
56 in [ Zero(new_reg); Inc(new_reg); Sub(r, new_reg) ], 56 in [ Zero(new_reg); Inc(new_reg); Sub(r, new_reg) ],
@@ -84,7 +84,7 @@ let compile_stage1 eurmcmds state =
84 in apply_transform (transform) state eurmcmds 84 in apply_transform (transform) state eurmcmds
85 85
86let compile_stage2 eurmcmds state = 86let compile_stage2 eurmcmds state =
87 let transform = function 87 let transform state = function
88 | Add(r1, r2) -> 88 | Add(r1, r2) ->
89 let ctr_reg = state.max_reg + 1 89 let ctr_reg = state.max_reg + 1
90 and start_label = string_of_int (state.label_count + 1) and end_label = string_of_int (state.label_count + 2) 90 and start_label = string_of_int (state.label_count + 1) and end_label = string_of_int (state.label_count + 2)
@@ -115,7 +115,7 @@ let compile_stage2 eurmcmds state =
115 in apply_transform (transform) state eurmcmds 115 in apply_transform (transform) state eurmcmds
116 116
117let compile_stage3 eurmcmds state = 117let compile_stage3 eurmcmds state =
118 let transform = function 118 let transform state = function
119 | Goto(lbl) -> 119 | Goto(lbl) ->
120 let dummy_reg = state.max_reg + 1 120 let dummy_reg = state.max_reg + 1
121 in [ Zero(dummy_reg); EqPredicate(dummy_reg, dummy_reg, lbl) ], 121 in [ Zero(dummy_reg); EqPredicate(dummy_reg, dummy_reg, lbl) ],
@@ -128,7 +128,7 @@ let compile_stage4 eurmcmds state =
128 let label_table = Hashtbl.create 100 128 let label_table = Hashtbl.create 100
129 in let build_label_table = 129 in let build_label_table =
130 List.iteri (fun lineo cmd -> match cmd with | Label(lbl) -> Hashtbl.add label_table lbl lineo | _ -> ()) 130 List.iteri (fun lineo cmd -> match cmd with | Label(lbl) -> Hashtbl.add label_table lbl lineo | _ -> ())
131 in let transform = function 131 in let transform state = function
132 | Inc(r) -> [ URMSucc(r) ], state 132 | Inc(r) -> [ URMSucc(r) ], state
133 | Zero(r) -> [ URMZero(r) ], state 133 | Zero(r) -> [ URMZero(r) ], state
134 | Copy(r1, r2) -> [ URMCopy(r1, r2) ], state 134 | Copy(r1, r2) -> [ URMCopy(r1, r2) ], state