|
@@ -29,43 +29,6 @@ let get_native_name = Native.get_native_name
|
|
|
|
|
|
(* PASS 1 begin *)
|
|
|
|
|
|
-(* Adds final returns to functions as required by some platforms *)
|
|
|
-let rec add_final_return e =
|
|
|
- let rec loop e t =
|
|
|
- let def_return p =
|
|
|
- let c = (match follow t with
|
|
|
- | TAbstract ({ a_path = [],"Int" },_) -> TInt 0l
|
|
|
- | TAbstract ({ a_path = [],"Float" },_) -> TFloat "0."
|
|
|
- | TAbstract ({ a_path = [],"Bool" },_) -> TBool false
|
|
|
- | _ -> TNull
|
|
|
- ) in
|
|
|
- { eexpr = TReturn (Some { eexpr = TConst c; epos = p; etype = t }); etype = t_dynamic; epos = p }
|
|
|
- in
|
|
|
- match e.eexpr with
|
|
|
- | TBlock el ->
|
|
|
- (match List.rev el with
|
|
|
- | [] -> e
|
|
|
- | elast :: el ->
|
|
|
- match loop elast t with
|
|
|
- | { eexpr = TBlock el2 } -> { e with eexpr = TBlock ((List.rev el) @ el2) }
|
|
|
- | elast -> { e with eexpr = TBlock (List.rev (elast :: el)) })
|
|
|
- | TReturn _ ->
|
|
|
- e
|
|
|
- | _ ->
|
|
|
- { e with eexpr = TBlock [e;def_return e.epos] }
|
|
|
- in
|
|
|
-
|
|
|
- let e = Type.map_expr add_final_return e in
|
|
|
-
|
|
|
- match e.eexpr with
|
|
|
- | TFunction f ->
|
|
|
- let f = (match follow f.tf_type with
|
|
|
- | TAbstract ({ a_path = [],"Void" },[]) -> f
|
|
|
- | _ -> { f with tf_expr = loop f.tf_expr f.tf_type }
|
|
|
- ) in
|
|
|
- { e with eexpr = TFunction f }
|
|
|
- | _ -> e
|
|
|
-
|
|
|
(* -------------------------------------------------------------------------- *)
|
|
|
(* CHECK LOCAL VARS INIT *)
|
|
|
|
|
@@ -721,7 +684,7 @@ let run tctx ectx main before_destruction =
|
|
|
let locals = RenameVars.init com in
|
|
|
let filters = [
|
|
|
"sanitize",(fun _ e -> Optimizer.sanitize com e);
|
|
|
- "add_final_return",(fun _ -> if com.config.pf_add_final_return then add_final_return else (fun e -> e));
|
|
|
+ "add_final_return",(fun _ -> if com.config.pf_add_final_return then AddFinalReturn.add_final_return else (fun e -> e));
|
|
|
"RenameVars",(match com.platform with
|
|
|
| Eval -> (fun _ e -> e)
|
|
|
| Jvm -> (fun _ e -> e)
|