Taddeus Kroes il y a 11 ans
Parent
commit
0a4c9499c1
1 fichiers modifiés avec 15 ajouts et 13 suppressions
  1. 15 13
      phases/desug.ml

+ 15 - 13
phases/desug.ml

@@ -163,7 +163,7 @@ let rec split_inits = function
 
 
   | node -> traverse_unit split_inits node
   | node -> traverse_unit split_inits node
 
 
-(* Add <allocate> statements after array declarations *)
+(* Add __allocate statements after array declarations *)
 let rec add_allocs node =
 let rec add_allocs node =
   let create_dimvar = function
   let create_dimvar = function
     | Dim (name, _) -> Var (name, None, [])
     | Dim (name, _) -> Var (name, None, [])
@@ -332,17 +332,19 @@ let rec array_init = function
 
 
 let phase = function
 let phase = function
   | Ast node ->
   | Ast node ->
-    (* Move array dimensions and scalar initialisations into new variables as
-     * initialisations, so that they are evaluated exactly once, and so that
-     * dimension names are consistent with the array name *)
-    let node = move_scalars (array_dims node) in
-
-    (* Split variable initialisations into declarations and assignments, and
-     * move the assignments to the function body *)
-    let node = move_inits (add_allocs (split_inits node)) in
-
-    (* Transform ArrayConst assignment to assignments in for-loops, and
-     * transform all for-loops to while-loops afterwards *)
-    Ast (for_to_while (array_init node))
+    Ast begin
+      (* Move array dimensions and scalar initialisations into new variables as
+       * initialisations, so that they are evaluated exactly once, and so that
+       * dimension names are consistent with the array name *)
+      array_dims node |> move_scalars
+
+      (* Split variable initialisations into declarations and assignments, and
+       * move the assignments to the function body *)
+      |> split_inits |> add_allocs |> move_inits
+
+      (* Transform ArrayConst assignment to assignments in for-loops, and
+       * transform all for-loops to while-loops afterwards *)
+      |> array_init |> for_to_while
+    end
 
 
   | _ -> raise InvalidInput
   | _ -> raise InvalidInput