Преглед изворни кода

Updated compiler to fit the new one-dimensional array instruction interface

Taddeus Kroes пре 12 година
родитељ
комит
66ab431a00
5 измењених фајлова са 10 додато и 9 уклоњено
  1. BIN
      bin32/civas
  2. BIN
      bin32/civvm
  3. 7 3
      phases/assemble.ml
  4. 2 4
      phases/print.ml
  5. 1 2
      types.mli


+ 7 - 3
phases/assemble.ml

@@ -217,16 +217,20 @@ let assemble program =
       [InlineComment (Label (endlabel), node2str node)]
       [InlineComment (Label (endlabel), node2str node)]
 
 
     (* Arrays *)
     (* Arrays *)
-    | Allocate (dec, dims, _) ->
+    | Allocate (dec, [dim], _) ->
       let store = match (depthof dec, depthof node) with
       let store = match (depthof dec, depthof node) with
       | (0, _)            -> Store (typeof dec, Glob,    indexof dec)
       | (0, _)            -> Store (typeof dec, Glob,    indexof dec)
       | (a, b) when a = b -> Store (typeof dec, Current, indexof dec)
       | (a, b) when a = b -> Store (typeof dec, Current, indexof dec)
       | _                 -> raise InvalidNode
       | _                 -> raise InvalidNode
       in
       in
-      trav_all dims @
-      [NewArray (basetypeof dec, List.length dims);
+      trav dim @
+      [NewArray (basetypeof dec);
        InlineComment (store, node2str node)]
        InlineComment (store, node2str node)]
 
 
+    | Allocate _ ->
+      raise (FatalError (NodeMsg (node, "invalid number of array dimensions \
+                                         (should be one-dimensional)")))
+
     | VarUse (dec, Some dims, _) ->
     | VarUse (dec, Some dims, _) ->
       let load = match (depthof dec, depthof node) with
       let load = match (depthof dec, depthof node) with
       | (0, _)            -> Load (typeof dec, Glob,        indexof dec)
       | (0, _)            -> Load (typeof dec, Glob,        indexof dec)

+ 2 - 4
phases/print.ml

@@ -117,10 +117,8 @@ let rec instr2str = function
     tab ^ prefix ctype ^ "pop"
     tab ^ prefix ctype ^ "pop"
 
 
   (* Arrays *)
   (* Arrays *)
-  | NewArray (basetype, ndims) ->
-    tab ^ prefix basetype ^ "newa " ^ si ndims
-  | ArraySize index ->
-    tab ^ "asize " ^ si index
+  | NewArray basetype ->
+    tab ^ prefix basetype ^ "newa"
   | LoadArray basetype ->
   | LoadArray basetype ->
     tab ^ prefix basetype ^ "loada"
     tab ^ prefix basetype ^ "loada"
   | StoreArray basetype ->
   | StoreArray basetype ->

+ 1 - 2
types.mli

@@ -193,8 +193,7 @@ type instr =
   | Pop of ctype                        (** [[ifb]pop] *)
   | Pop of ctype                        (** [[ifb]pop] *)
 
 
   (* Arrays *)
   (* Arrays *)
-  | NewArray of ctype * int             (** [[ifb]newa D] *)
-  | ArraySize of int                    (** [asize D] *)
+  | NewArray of ctype                   (** [[ifb]newa] *)
   | LoadArray of ctype                  (** [[ifb]loada] *)
   | LoadArray of ctype                  (** [[ifb]loada] *)
   | StoreArray of ctype                 (** [[ifb]storea] *)
   | StoreArray of ctype                 (** [[ifb]storea] *)