Simon Krajewski 12 gadi atpakaļ
vecāks
revīzija
d63199d323
2 mainītis faili ar 8 papildinājumiem un 9 dzēšanām
  1. 7 8
      codegen.ml
  2. 1 1
      main.ml

+ 7 - 8
codegen.ml

@@ -1666,25 +1666,24 @@ module PatternMatchConversion = struct
 		end
 end
 
-let promote_complex_returns ctx e =
+let promote_complex_rhs ctx e =
 	let rec loop f e = match e.eexpr with
 		| TBlock(el) ->
 			begin match List.rev el with
-				| elast :: el -> {e with eexpr = TBlock(List.rev ((loop f elast) :: el))}
+				| elast :: el -> {e with eexpr = TBlock(List.rev ((loop f elast) :: (List.map find el)))}
 				| [] -> e
 			end
 		| TSwitch(es,cases,edef) ->
-			{e with eexpr = TSwitch(es,List.map (fun (el,e) -> el,loop f e) cases,match edef with None -> None | Some e -> Some (loop f e))}
+			{e with eexpr = TSwitch(es,List.map (fun (el,e) -> List.map find el,loop f e) cases,match edef with None -> None | Some e -> Some (loop f e))}
 		| TIf(eif,ethen,eelse) ->
-			{e with eexpr = TIf(eif, loop f ethen, match eelse with None -> None | Some e -> Some (loop f e))}
+			{e with eexpr = TIf(find eif, loop f ethen, match eelse with None -> None | Some e -> Some (loop f e))}
 		| TTry(e1,el) ->
 			{e with eexpr = TTry(loop f e1, List.map (fun (el,e) -> el,loop f e) el)}
 		| TReturn _ | TThrow _ ->
-			e
+			find e
 		| _ ->
-			f e
-	in
-	let rec find e = match e.eexpr with
+			f (find e)
+	and find e = match e.eexpr with
 		| TReturn (Some e1) -> loop (fun e -> {e with eexpr = TReturn (Some e)}) e1
 		| TBinop(OpAssign, ({eexpr = TLocal v} as e1), e2) -> loop (fun er -> {e with eexpr = TBinop(OpAssign, e1, er)}) e2
 		| _ -> Type.map_expr find e

+ 1 - 1
main.ml

@@ -1218,7 +1218,7 @@ try
 		) com.types;
 		let filters = [
 			Codegen.Abstract.handle_abstract_casts tctx;
-			Codegen.promote_complex_returns com;
+			Codegen.promote_complex_rhs com;
 			if com.foptimize then (fun e -> Optimizer.reduce_expression tctx (Optimizer.inline_constructors tctx e)) else Optimizer.sanitize tctx;
 			Codegen.check_local_vars_init;
 			Codegen.captured_vars com;