Browse Source

Typing done

Typer and compiler updated.

To be tested :/
Phyks (Lucas Verney) 5 years ago
parent
commit
88f047c89d
12 changed files with 16357 additions and 1794 deletions
  1. 12842
    253
      compiler.annot
  2. BIN
      compiler.cmi
  3. BIN
      compiler.cmo
  4. 12
    12
      compiler.ml
  5. 1367
    0
      main.annot
  6. BIN
      main.cmi
  7. BIN
      main.cmo
  8. BIN
      minic++
  9. 2129
    1523
      typer.annot
  10. BIN
      typer.cmi
  11. BIN
      typer.cmo
  12. 7
    6
      typer.ml

+ 12842
- 253
compiler.annot
File diff suppressed because it is too large
View File


BIN
compiler.cmi View File


BIN
compiler.cmo View File


+ 12
- 12
compiler.ml View File

@@ -95,7 +95,7 @@ let rec mips_expr locals = function
95 95
         | ATIdent ident ->
96 96
                 if local then
97 97
                     begin
98
-                        match Hashtbl.find locals (ATVIdent ident) with
98
+                        match snd (Hashtbl.find locals (ATVIdent ident)) with
99 99
                         | Pos pos ->
100 100
                             {
101 101
                                 text = lw a0 areg (-pos, fp);
@@ -125,7 +125,7 @@ let rec mips_expr locals = function
125 125
 
126 126
             let object_desc = Hashtbl.find objects (ATVIdent object_id) in
127 127
 
128
-            let ofs = Hashtbl.find object_desc.fields (ATVIdent ident) in
128
+            let ofs = snd (Hashtbl.find object_desc.fields (ATVIdent ident)) in
129 129
             {
130 130
                 text = la a0 alab ("object_"^(object_id))
131 131
                     ++ lw a0 areg (ofs, a0);
@@ -137,7 +137,7 @@ let rec mips_expr locals = function
137 137
             
138 138
             if local then
139 139
                 begin
140
-                    match Hashtbl.find locals (ATVIdent i) with
140
+                    match snd(Hashtbl.find locals (ATVIdent i)) with
141 141
                     | Pos pos ->
142 142
                         {
143 143
                             text = mips_for_e2.text
@@ -168,7 +168,7 @@ let rec mips_expr locals = function
168 168
             let mips_for_e2 = mips_expr locals e2 in
169 169
             if local then
170 170
                 begin
171
-                    match Hashtbl.find locals (ATVIdent i) with
171
+                    match snd(Hashtbl.find locals (ATVIdent i)) with
172 172
                     | Pos pos ->
173 173
                         {
174 174
                             text = mips_for_e2.text
@@ -202,7 +202,7 @@ let rec mips_expr locals = function
202 202
     | ATAssign (ATDot(ATEQident (ATIdent qid, _), id), e2) ->
203 203
             let object_desc = Hashtbl.find objects (ATVIdent qid) in
204 204
 
205
-            let ofs = Hashtbl.find object_desc.fields (ATVIdent id) in
205
+            let ofs = snd(Hashtbl.find object_desc.fields (ATVIdent id)) in
206 206
 
207 207
             let mips_for_e2 = mips_expr locals e2 in
208 208
             {
@@ -235,7 +235,7 @@ let rec mips_expr locals = function
235 235
         let load reg =
236 236
             if local then
237 237
                 begin
238
-                    match Hashtbl.find locals (ATVIdent i) with
238
+                    match snd(Hashtbl.find locals (ATVIdent i)) with
239 239
                     | Pos pos ->
240 240
                         lw reg areg(-pos, fp)
241 241
                     | Global_var_ref id ->
@@ -248,7 +248,7 @@ let rec mips_expr locals = function
248 248
         in
249 249
         let store reg = 
250 250
             if local then
251
-                begin match Hashtbl.find locals (ATVIdent i) with 
251
+                begin match snd(Hashtbl.find locals (ATVIdent i)) with 
252 252
                     | Pos pos ->
253 253
                         sw reg areg(-pos, fp)
254 254
                     | Global_var_ref id ->
@@ -299,7 +299,7 @@ let rec mips_expr locals = function
299 299
             | ATEQident (ATIdent ident, local) ->
300 300
                 let generated_mips = if local then (
301 301
                         begin
302
-                            match Hashtbl.find locals (ATVIdent ident) with
302
+                            match snd(Hashtbl.find locals (ATVIdent ident)) with
303 303
                             | Pos pos ->
304 304
                                 if pos = -1 then (* Object on the heap *)
305 305
                                     {
@@ -342,7 +342,7 @@ let rec mips_expr locals = function
342 342
             | ATEQident (ATIdent ident, local) ->
343 343
                 let generated_mips = if local then (
344 344
                         begin
345
-                            match Hashtbl.find locals (ATVIdent ident) with
345
+                            match snd(Hashtbl.find locals (ATVIdent ident)) with
346 346
                             | Pos pos ->
347 347
                                 {
348 348
                                     text = lw a0 areg (-pos,fp)
@@ -471,7 +471,7 @@ let rec mips_instruction locals x y = match y with
471 471
         in
472 472
 
473 473
         begin
474
-            match Hashtbl.find locals (find_ident var) with
474
+            match snd(Hashtbl.find locals (find_ident var)) with
475 475
             | Pos pos -> 
476 476
                 {
477 477
                     text = x.text
@@ -675,11 +675,11 @@ let mips_decl x y = match y with
675 675
 
676 676
                 {
677 677
                     text = x.text;
678
-                    data = x.data ++ label (etiquette var) ++ dword [0];
678
+                    data = x.data ++ label (etiquette (fst var)) ++ dword [0];
679 679
                 }
680 680
             in
681 681
 
682
-            let mips_global_var = List.fold_left (global_var) empty_mips var.at_var in
682
+            let mips_global_var = List.fold_left (global_var) empty_mips var in
683 683
             {
684 684
                 text = x.text ++ mips_global_var.text;
685 685
                 data = x.data ++ mips_global_var.data;

+ 1367
- 0
main.annot
File diff suppressed because it is too large
View File


BIN
main.cmi View File


BIN
main.cmo View File


BIN
minic++ View File


+ 2129
- 1523
typer.annot
File diff suppressed because it is too large
View File


BIN
typer.cmi View File


BIN
typer.cmo View File


+ 7
- 6
typer.ml View File

@@ -193,8 +193,9 @@ let rec type_expr pos locals = function
193 193
     | ETrue -> ATEInt 1, ATInt
194 194
     | EFalse -> ATEInt 0, ATInt
195 195
     | ENull -> ATEInt 0, ATNull
196
-    | Apply (e, le) -> assert false; (*begin (* TODO typing *)
197
-        match type_expr pos locals e with
196
+    | Apply (e, le) -> begin
197
+        let tmp = type_expr pos locals e in
198
+        match fst tmp with
198 199
         | ATEQident (ATIdent id, _) ->
199 200
             let decl_fonction_tmp = Hashtbl.find decl_fonction id in
200 201
             let i = ref (-1) in
@@ -204,15 +205,15 @@ let rec type_expr pos locals = function
204 205
                     i:=!i+1;
205 206
                     let tmp = type_expr pos locals x in
206 207
                     if snd(List.nth decl_fonction_tmp !i) then
207
-                        ATUOp (ATEComm, tmp), true
208
+                        ATUOp (ATEComm, fst tmp), true
208 209
                     else
209
-                        tmp, false
210
+                        fst tmp, false
210 211
                 in
211
-                ATApply (id, List.map (type_expr_ref) le)
212
+                ATApply (id, List.map (type_expr_ref) le), snd tmp
212 213
             else
213 214
                 raise (Error ("Wrong number of arguments for function "^id^".", pos))
214 215
         | _ -> raise (Error ("Expression cannot be used as a function.", pos))
215
-    end*)
216
+    end
216 217
     | Dot (e, id) -> begin
217 218
         let tmp = type_expr pos locals e in
218 219
         begin match snd tmp with