diff options
author | Adam NAILI | 2018-04-19 15:16:11 +0200 |
---|---|---|
committer | Adam NAILI | 2018-04-19 15:16:11 +0200 |
commit | 35b808e5a3ba0a70f72b67c5690af78f86fe0c29 (patch) | |
tree | 705da8f9819aa13decc1b9b10076225c16d2695e | |
parent | fe155b6f7bb8df70bb9823a5f35736ac6f7eddff (diff) | |
download | urm-35b808e5a3ba0a70f72b67c5690af78f86fe0c29.tar.gz |
Implementing some functions. Urm not working. Need reg manipulation func
-rw-r--r-- | projet.ml | 61 |
1 files changed, 53 insertions, 8 deletions
@@ -42,19 +42,64 @@ let program_of_string str = | |||
42 | in List.iter (fun s -> print_string s; print_newline ()) lex; program_of_lex lex | 42 | in List.iter (fun s -> print_string s; print_newline ()) lex; program_of_lex lex |
43 | 43 | ||
44 | let instptr_mk urmcmd_list = | 44 | let instptr_mk urmcmd_list = |
45 | let rec aux urmcmd_list count acc = | 45 | let rec aux urmcmd_list count acc = |
46 | match urmcmd_list with | 46 | match urmcmd_list with |
47 | | [] -> acc | 47 | | [] -> acc |
48 | | instruction::reste -> aux reste (count + 1) ((count,instruction)::acc) | 48 | | instruction::reste -> aux reste (count + 1) ((count,instruction)::acc) |
49 | in InstPtr([],rev (aux urmcmd_list 0 [])) | 49 | in InstPtr([],rev (aux urmcmd_list 0 [])) |
50 | 50 | ||
51 | let instptr_move_up = function | 51 | let instptr_move_up = function |
52 | | InstPtr([],list2)-> InstPtr([],list2) | ||
53 | | InstPtr(instr::list1,list2) -> InstPtr(list1, instr::list2) | ||
54 | |||
55 | let instptr_move_down = function | ||
52 | | InstPtr(list1,[])-> InstPtr(list1,[]) | 56 | | InstPtr(list1,[])-> InstPtr(list1,[]) |
53 | | InstPtr(list1,instr::list2) -> InstPtr(instr::list1, list2) | 57 | | InstPtr(list1,instr::list2) -> InstPtr(instr::list1, list2) |
54 | 58 | ||
55 | let instptr_get = function | 59 | let instptr_get = function |
56 | | _,Zero(_) -> Zero(_) | 60 | | InstPtr(list1,(l,Zero(a))::tail)-> (l,Zero(a)) |
57 | | _,Succ(_) -> Succ(_) | 61 | | InstPtr(list1,(l,Succ(a))::tail) -> (l,Succ(a)) |
58 | | _,Copy(_,_) -> Copy(_,_) | 62 | | InstPtr(list1,(l,Copy(a,b))::tail) -> (l,Copy(a,b)) |
59 | | _,Jump(_,_,_) -> Jump(_,_,_) | 63 | | InstPtr(list1,(l,Jump(a,b,c))::tail) -> (l,Jump(a,b,c)) |
60 | | _ -> raise Syntax_error \ No newline at end of file | 64 | | InstPtr(_,[])-> failwith "No instruction left" |
65 | |||
66 | let instptr_string instptr = | ||
67 | let aux = function | ||
68 | | l,Zero(a) -> (string_of_int l)^": Zero "^(string_of_int a) | ||
69 | | l,Succ(a) -> (string_of_int l)^": Succ "^(string_of_int a) | ||
70 | | l,Copy(a,b) -> (string_of_int l)^": Copy "^(string_of_int a)^" "^(string_of_int b) | ||
71 | | l,Jump(a,b,c) -> (string_of_int l)^": Jump "^(string_of_int a)^" "^(string_of_int b)^" "^(string_of_int c) | ||
72 | in try aux (instptr_get instptr) with | ||
73 | | _ -> "null" | ||
74 | |||
75 | |||
76 | let reg_idx = function | ||
77 | | Reg(a,b) -> a | ||
78 | |||
79 | let reg_val = function | ||
80 | | Reg(a,b) -> b | ||
81 | |||
82 | let reg_compar reg1 reg2 = (reg_val reg1) - (reg_val reg2) | ||
83 | |||
84 | let regs_get reglist idx = | ||
85 | let rec aux = function | ||
86 | | [] -> failwith "Register not found" | ||
87 | | Reg(i,v)::tail when i = idx -> v | ||
88 | | Reg(_,_)::tail -> aux tail | ||
89 | in aux reglist | ||
90 | |||
91 | let regs_exists regs idx = List.exists (fun (Reg(x,_)) -> x = idx) regs | ||
92 | |||
93 | (*TODO: Function of register manipulation: create a register or modify an existent register (remove + create?)*) | ||
94 | |||
95 | |||
96 | let urm_apply urm = | ||
97 | let aux = function | ||
98 | | _,Zero(a) -> urm.regs | ||
99 | in aux (instptr_get urm.instptr) | ||
100 | |||
101 | let urm_run urm = | ||
102 | match urm with | ||
103 | | {instptr = InstPtr(_,[]); regs = reg_list } -> reg_list | ||
104 | |||
105 | let urm_mk cmd_list reg_list = {instptr = (instptr_mk cmd_list) ; regs = reg_list} | ||