diff options
Diffstat (limited to 'urm.ml')
-rw-r--r-- | urm.ml | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -0,0 +1,34 @@ | |||
1 | (* | ||
2 | * UPEM / L3 / Functional programming / Project: URM | ||
3 | * Pacien TRAN-GIRARD, Adam NAILI | ||
4 | *) | ||
5 | |||
6 | open Common | ||
7 | open Instptr | ||
8 | open Reg | ||
9 | |||
10 | (* Gives a new urm by moving down its instruction pointer *) | ||
11 | let 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 *) | ||
16 | let 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 *) | ||
27 | let rec urm_run = function | ||
28 | | { instptr = InstPtr(_, []) ; regs = reg_list } -> reg_list | ||
29 | | urm -> urm_apply urm |> urm_run | ||
30 | |||
31 | let urm_run_trace = urm_run (* TODO *) | ||
32 | |||
33 | (* Creates an URM from a command list and a register list *) | ||
34 | let urm_mk cmd_list reg_list = { instptr = (instptr_mk cmd_list) ; regs = reg_list } | ||