2
0
Эх сурвалжийг харах

optimized remaining nulls in blocks

Nicolas Cannasse 14 жил өмнө
parent
commit
9c1a5cc718
1 өөрчлөгдсөн 11 нэмэгдсэн , 5 устгасан
  1. 11 5
      optimizer.ml

+ 11 - 5
optimizer.ml

@@ -185,7 +185,7 @@ let rec type_inline ctx cf f ethis params tret p =
 			(try
 			(try
 				let _, ef = List.assoc (local s) inlined_vars in
 				let _, ef = List.assoc (local s) inlined_vars in
 				match ef.eexpr, follow ef.etype with
 				match ef.eexpr, follow ef.etype with
-				| TFunction func, TFun (_,rt) ->					
+				| TFunction func, TFun (_,rt) ->
 					let cf = mk_field "" ef.etype e.epos in
 					let cf = mk_field "" ef.etype e.epos in
 					let inl = (try type_inline ctx cf func ethis el rt e.epos with Error (Custom _,_) -> None) in
 					let inl = (try type_inline ctx cf func ethis el rt e.epos with Error (Custom _,_) -> None) in
 					(match inl with
 					(match inl with
@@ -444,7 +444,7 @@ let sanitize_expr e =
 			| TIf _ -> if left then not (swap (OpAssignOp OpAssign) op) else swap op (OpAssignOp OpAssign)
 			| TIf _ -> if left then not (swap (OpAssignOp OpAssign) op) else swap op (OpAssignOp OpAssign)
 			| TCast (e,None) -> loop e left
 			| TCast (e,None) -> loop e left
 			| _ -> false
 			| _ -> false
-		in		
+		in
 		let e1 = if loop e1 true then parent e1 else e1 in
 		let e1 = if loop e1 true then parent e1 else e1 in
 		let e2 = if loop e2 false then parent e2 else e2 in
 		let e2 = if loop e2 false then parent e2 else e2 in
 		{ e with eexpr = TBinop (op,e1,e2) }
 		{ e with eexpr = TBinop (op,e1,e2) }
@@ -472,7 +472,7 @@ let sanitize_expr e =
 		(match f.tf_expr.eexpr with
 		(match f.tf_expr.eexpr with
 		| TBlock _ -> e
 		| TBlock _ -> e
 		| _ -> { e with eexpr = TFunction { f with tf_expr = block f.tf_expr } })
 		| _ -> { e with eexpr = TFunction { f with tf_expr = block f.tf_expr } })
-	| TCall (e2,args) ->		
+	| TCall (e2,args) ->
 		if need_parent e2 then { e with eexpr = TCall(parent e2,args) } else e
 		if need_parent e2 then { e with eexpr = TCall(parent e2,args) } else e
 	| TField (e2,f) ->
 	| TField (e2,f) ->
 		if need_parent e2 then { e with eexpr = TField(parent e2,f) } else e
 		if need_parent e2 then { e with eexpr = TField(parent e2,f) } else e
@@ -501,8 +501,14 @@ let reduce_expr ctx e =
 			) cl
 			) cl
 		) cases;
 		) cases;
 		e
 		e
-	| TBlock [ec] ->
-		{ ec with epos = e.epos }
+	| TBlock l ->
+		(match List.rev l with
+		| [] -> e
+		| ec :: l ->
+			(* remove all no-ops : not-final constants in blocks *)
+			match List.filter (fun e -> match e.eexpr with TConst _ -> false | _ -> true) l with
+			| [] -> { ec with epos = e.epos }
+			| l -> { e with eexpr = TBlock (List.rev (ec :: l)) })
 	| TParenthesis ec ->
 	| TParenthesis ec ->
 		{ ec with epos = e.epos }
 		{ ec with epos = e.epos }
 	| _ ->
 	| _ ->