aboutsummaryrefslogtreecommitdiff
path: root/urm.ml
diff options
context:
space:
mode:
Diffstat (limited to 'urm.ml')
-rw-r--r--urm.ml34
1 files changed, 34 insertions, 0 deletions
diff --git a/urm.ml b/urm.ml
new file mode 100644
index 0000000..49e970b
--- /dev/null
+++ b/urm.ml
@@ -0,0 +1,34 @@
1(*
2 * UPEM / L3 / Functional programming / Project: URM
3 * Pacien TRAN-GIRARD, Adam NAILI
4 *)
5
6open Common
7open Instptr
8open Reg
9
10(* Gives a new urm by moving down its instruction pointer *)
11let urm_move_down urm = { instptr = instptr_move_down urm.instptr ; regs = urm.regs }
12
13(* TODO: Verifier pour JUMP que a et b sont deux registres initialisés *)
14
15(* Applies the current instruction pointed by the pointer of instruction. Modifies the pointer of instruction for every instruction *)
16let urm_apply urm =
17 let aux = function
18 | _, Zero(a) -> { instptr = urm.instptr ; regs = regs_set (urm.regs) a 0 } |> urm_move_down
19 | _, Copy(a, b) when a != b -> { instptr = urm.instptr ; regs = regs_set urm.regs a (regs_get urm.regs b) } |> urm_move_down
20 | _, Copy(a, b) -> failwith "Copy from one register to itself"
21 | _, Succ(a) -> { instptr = urm.instptr ; regs = regs_set urm.regs a ((regs_get urm.regs a) + 1) } |> urm_move_down
22 | _, Jump(a, b, c) when (regs_get urm.regs a) = (regs_get urm.regs b) -> { instptr = (instptr_jump urm.instptr (fst (instptr_get urm.instptr) - c)) ; regs = urm.regs }
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)
25
26(* Launches the URM *)
27let rec urm_run = function
28 | { instptr = InstPtr(_, []) ; regs = reg_list } -> reg_list
29 | urm -> urm_apply urm |> urm_run
30
31let urm_run_trace = urm_run (* TODO *)
32
33(* 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 }