ソースを参照

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

BIN
bin32/civas


BIN
bin32/civvm


+ 7 - 3
phases/assemble.ml

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

+ 2 - 4
phases/print.ml

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

+ 1 - 2
types.mli

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