Taddeus Kroes 12 лет назад
Родитель
Сommit
6a1d84d5f9
3 измененных файлов с 24 добавлено и 19 удалено
  1. 21 16
      phases/assemble.ml
  2. 2 2
      phases/desug.mli
  3. 1 1
      phases/peephole.ml

+ 21 - 16
phases/assemble.ml

@@ -26,6 +26,7 @@ let assemble program =
     in
     match node with
     (* Global *)
+
     | Program (decls, _) ->
       trav_all decls
 
@@ -39,10 +40,12 @@ let assemble program =
 
     | FunDef (export, ret_type, name, params, body, _) ->
       let label = labelof node in
-      (if export then
+      begin
+        if export then
           let param_types = List.map typeof params in
           [Export (name, ret_type, param_types, label)]
-      else []) @
+        else []
+      end @
       [Comment (sprintf "fun \"%s\" with %d local vars" label (indexof node));
        Label label;
        RtnEnter (indexof node)] @
@@ -59,6 +62,7 @@ let assemble program =
     | Block body | VarDecs body -> trav_all body
 
     (* Statements *)
+
     | VarLet (dec, None, value, _) ->
       let store = match (depthof dec, depthof node) with
       | (0, _)            -> Store (typeof dec, Glob,        indexof dec)
@@ -74,7 +78,7 @@ let assemble program =
       let endlabel = genlabel "end" in
       (trav cond) @
       [Branch (false, endlabel);
-      comline ("if (" ^ (node2str cond) ^ ") {")] @
+       comline ("if (" ^ (node2str cond) ^ ") {")] @
       (trav body) @
       [comline "}";
        Label endlabel]
@@ -84,10 +88,10 @@ let assemble program =
       let endlabel = genlabel "end" in
       (trav cond) @
       [Branch (false, elselabel);
-      comline ("if (" ^ (node2str cond) ^ ") {")] @
+       comline ("if (" ^ (node2str cond) ^ ") {")] @
       (trav true_body) @
       [Jump endlabel;
-      comline "} else {";
+       comline "} else {";
        Label elselabel] @
       (trav false_body) @
       [comline "}";
@@ -103,7 +107,7 @@ let assemble program =
       (trav body) @
       [Jump startlabel;
        Label endlabel;
-      comline "}"]
+       comline "}"]
 
     | DoWhile (cond, body, _) ->
       let startlabel = genlabel "dowhile" in
@@ -115,19 +119,20 @@ let assemble program =
       [InlineComment (Branch (true, startlabel), com)]
 
     (* Expression statement pops the disregarded expression value from the
-    * stack, if any *)
+     * stack, if any *)
     | Expr value ->
       let pop = match typeof value with
-          | Void -> [comline (node2str node)]
-          | ctype -> [InlineComment (Pop ctype, node2str node)]
+      | Void -> [comline (node2str node)]
+      | ctype -> [InlineComment (Pop ctype, node2str node)]
       in
-      (trav value) @ pop
+      trav value @ pop
 
     (* Expressions *)
-    (* Immediate values are handled here, and not in the peephole optimizer,
-    * for convenience: the indices in the constant table would be altered,
-    * so entries cannot be removed. By this early detection (also during
-    * index analysis), they are not added in the first place *)
+
+    (* Immediate values are handled here, and not in the peephole optimizer, for
+     * convenience: the indices in the constant table would be altered, so
+     * entries cannot be removed. By this early detection (also during index
+     * analysis), they are not added in the first place *)
     | Const (value, _) when is_immediate_const value ->
       [InlineComment (LoadImm value, node2str node)]
 
@@ -243,8 +248,8 @@ let assemble program =
    * cumbersome right now... *)
   let pairs = ref [] in
   let add_pair value index =
-  let com = sprintf "index %d" index in
-  pairs := (InlineComment (ConstDef value, com), index) :: !pairs;
+    let com = sprintf "index %d" index in
+    pairs := (InlineComment (ConstDef value, com), index) :: !pairs
   in
   Hashtbl.iter add_pair consts;
   let cmp (_, i) (_, j) = compare i j in

+ 2 - 2
phases/desug.mli

@@ -80,8 +80,8 @@ void foo() \{
     [two()] must be evaluated exactly three times in order to preserve correct
     behaviour. However, [a[1, 1]] will at a later stage be transformed into
     [a[(1 * two()) + 1]], thus incorrectly evaluating [two()] an additional
-    time. Assigning a scalar value to an array create the same problem, since
-    this is trwnsformed into a for-loop, where the scalar expression is
+    time. Assigning a scalar value to an array creates the same problem, since
+    this is transformed into a for-loop, where the scalar expression is
     evaluated during each iteration. The problem is solved by creating new
     so-called "constant variables" for all of these values, and initializing hem
     to the original expressions. The expressions are then replaced with usages

+ 1 - 1
phases/peephole.ml

@@ -83,7 +83,7 @@ let count_instrs instrs =
   in trav 0 instrs
 
 let phase = function
-  | Assembly instrs as input ->
+  | Assembly instrs ->
     let oldcount = count_instrs instrs in
     let instrs = peephole (strip_comments instrs) in
     let newcount = count_instrs instrs in