Parcourir la source

Clean up optimisations to be applied in main.ml to be more flexible.

Luca Deltodesco il y a 12 ans
Parent
commit
a14a26e6d3
1 fichiers modifiés avec 11 ajouts et 5 suppressions
  1. 11 5
      main.ml

+ 11 - 5
main.ml

@@ -1214,14 +1214,20 @@ try
 		com.main <- main;
 		com.types <- types;
 		com.modules <- modules;
-		let platform_optimize = (match com.platform with
-			| Js -> Genjs.optimize
-			| _ -> fun ctx e -> e
-		) in
+		let foldMap = List.fold_left (fun f g x -> g (f x)) (fun x -> x) in
 		let filters = [
 			Codegen.Abstract.handle_abstract_casts tctx;
 			Codegen.promote_complex_rhs com;
-			if com.foptimize then (fun e -> Optimizer.reduce_expression tctx (platform_optimize tctx (Optimizer.inline_constructors tctx e))) else Optimizer.sanitize tctx;
+			if com.foptimize then foldMap (
+				let reduce_expression = Optimizer.reduce_expression tctx in
+				let inline_constructors = Optimizer.inline_constructors tctx in
+				match com.platform with
+					| Js -> [inline_constructors;
+							 Genjs.optimize tctx;
+							 reduce_expression]
+					| _ -> [inline_constructors;
+							reduce_expression]
+			) else Optimizer.sanitize tctx;
 			Codegen.check_local_vars_init;
 			Codegen.captured_vars com;
 			Codegen.rename_local_vars com;