Skip to content

Commit

Permalink
Merge branch 'tvars_change' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Dec 8, 2013
2 parents f43123a + 1af911f commit 2fbf280
Show file tree
Hide file tree
Showing 23 changed files with 396 additions and 393 deletions.
1 change: 1 addition & 0 deletions ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ module Meta = struct
| Meta
| Macro
| MaybeUsed
| MergeBlock
| MultiType
| Native
| NativeGen
Expand Down
28 changes: 12 additions & 16 deletions codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -788,10 +788,8 @@ module PatternMatchConversion = struct
else
((v,Some e) :: vl), el
) ([],[e]) bl in
mk (TBlock
((mk (TVars (vl)) cctx.ctx.t.tvoid e.epos)
:: el)
) e.etype e.epos
let el_v = List.map (fun (v,eo) -> mk (TVar (v,eo)) cctx.ctx.t.tvoid e.epos) vl in
mk (TBlock (el_v @ el)) e.etype e.epos
| DTGoto i ->
convert_dt cctx (cctx.dt_lookup.(i))
| DTExpr e ->
Expand Down Expand Up @@ -819,10 +817,8 @@ module PatternMatchConversion = struct
if dt.dt_var_init = [] then
e
else begin
mk (TBlock [
mk (TVars dt.dt_var_init) t_dynamic e.epos;
e;
]) dt.dt_type e.epos
let el_v = List.map (fun (v,eo) -> mk (TVar (v,eo)) cctx.ctx.t.tvoid p) dt.dt_var_init in
mk (TBlock (el_v @ [e])) dt.dt_type e.epos
end
end

Expand Down Expand Up @@ -938,7 +934,7 @@ let stack_context_init com stack_var exc_var pos_var tmp_var use_add p =
let stack_return e =
let tmp = alloc_var tmp_var e.etype in
mk (TBlock [
mk (TVars [tmp, Some e]) t.tvoid e.epos;
mk (TVar (tmp, Some e)) t.tvoid e.epos;
stack_pop;
mk (TReturn (Some (mk (TLocal tmp) e.etype e.epos))) e.etype e.epos
]) e.etype e.epos
Expand All @@ -950,7 +946,7 @@ let stack_context_init com stack_var exc_var pos_var tmp_var use_add p =
stack_pos = p;
stack_expr = stack_e;
stack_pop = stack_pop;
stack_save_pos = mk (TVars [pos_var, Some (field stack_e "length" t.tint p)]) t.tvoid p;
stack_save_pos = mk (TVar (pos_var, Some (field stack_e "length" t.tint p))) t.tvoid p;
stack_push = stack_push;
stack_return = stack_return;
stack_restore = [
Expand Down Expand Up @@ -1062,10 +1058,10 @@ let fix_override com c f fd =
let e = fd.tf_expr in
let el = (match e.eexpr with TBlock el -> el | _ -> [e]) in
let p = (match el with [] -> e.epos | e :: _ -> e.epos) in
let v = mk (TVars (List.map (fun (v,v2) ->
(v,Some (mk (TCast (mk (TLocal v2) v2.v_type p,None)) v.v_type p))
) args)) com.basic.tvoid p in
{ e with eexpr = TBlock (v :: el) }
let el_v = List.map (fun (v,v2) ->
mk (TVar (v,Some (mk (TCast (mk (TLocal v2) v2.v_type p,None)) v.v_type p))) com.basic.tvoid p
) args in
{ e with eexpr = TBlock (el_v @ el) }
);
} in
(* as3 does not allow wider visibility, so the base method has to be made public *)
Expand Down Expand Up @@ -1161,7 +1157,7 @@ let rec constructor_side_effects e =
false
| TUnop _ | TArray _ | TField _ | TEnumParameter _ | TCall _ | TNew _ | TFor _ | TWhile _ | TSwitch _ | TPatMatch _ | TReturn _ | TThrow _ ->
true
| TBinop _ | TTry _ | TIf _ | TBlock _ | TVars _
| TBinop _ | TTry _ | TIf _ | TBlock _ | TVar _
| TFunction _ | TArrayDecl _ | TObjectDecl _
| TParenthesis _ | TTypeExpr _ | TLocal _ | TMeta _
| TConst _ | TContinue | TBreak | TCast _ ->
Expand Down Expand Up @@ -1269,7 +1265,7 @@ let default_cast ?(vtmp="$t") com e texpr t p =
| TTypeDecl _ -> assert false
in
let vtmp = alloc_var vtmp e.etype in
let var = mk (TVars [vtmp,Some e]) api.tvoid p in
let var = mk (TVar (vtmp,Some e)) api.tvoid p in
let vexpr = mk (TLocal vtmp) e.etype p in
let texpr = mk (TTypeExpr texpr) (mk_texpr texpr) p in
let std = (try List.find (fun t -> t_path t = ([],"Std")) com.types with Not_found -> assert false) in
Expand Down
1 change: 1 addition & 0 deletions common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ module MetaInfo = struct
| Meta -> ":meta",("Internally used to mark a class field as being the metadata field",[])
| Macro -> ":macro",("(deprecated)",[])
| MaybeUsed -> ":maybeUsed",("Internally used by DCE to mark fields that might be kept",[Internal])
| MergeBlock -> ":mergeBlock",("Internally used by typer to mark block that should be merged into the outer scope",[Internal])
| MultiType -> ":multiType",("Specifies that an abstract chooses its this-type from its @:to functions",[UsedOn TAbstract])
| Native -> ":native",("Rewrites the path of a class or enum during generation",[HasParam "Output type path";UsedOnEither [TClass;TEnum]])
| NativeGen -> ":nativeGen",("Annotates that a type should be treated as if it were an extern definition - platform native",[Platforms [Java;Cs]; UsedOnEither[TClass;TEnum]])
Expand Down
8 changes: 3 additions & 5 deletions dce.ml
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,9 @@ and expr dce e =
field dce c "new" false;
List.iter (expr dce) el;
List.iter (mark_t dce e.epos) pl;
| TVars vl ->
List.iter (fun (v,e1) ->
opt (expr dce) e1;
mark_t dce e.epos v.v_type;
) vl;
| TVar (v,e1) ->
opt (expr dce) e1;
mark_t dce e.epos v.v_type;
| TCast(e, Some mt) ->
check_feature dce "typed_cast";
mark_mt dce mt;
Expand Down
54 changes: 24 additions & 30 deletions filters.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let mk_block_context com gen_temp =
let push e = block_el := e :: !block_el in
let declare_temp t eo p =
let v = gen_temp t in
let e = mk (TVars [v,eo]) com.basic.tvoid p in
let e = mk (TVar (v,eo)) com.basic.tvoid p in
push e;
mk (TLocal v) t p
in
Expand Down Expand Up @@ -141,7 +141,6 @@ let handle_side_effects com gen_temp e =
in
List.map loop (loop2 [] (List.rev el))
in
let e = blockify_ast e in
let e = loop e in
match close_block() with
| [] ->
Expand Down Expand Up @@ -189,18 +188,16 @@ let promote_complex_rhs ctx e =
let r = ref [] in
List.iter (fun e ->
match e.eexpr with
| TVars(vl) ->
List.iter (fun (v,eo) ->
match eo with
| TVar(v,eo) ->
begin match eo with
| Some e when is_complex e ->
r := (loop (fun e -> mk (TBinop(OpAssign,mk (TLocal v) v.v_type e.epos,e)) v.v_type e.epos) e)
:: ((mk (TVars [v,None]) ctx.basic.tvoid e.epos))
:: ((mk (TVar (v,None)) ctx.basic.tvoid e.epos))
:: !r
| Some e ->
r := (mk (TVars [v,Some (find e)]) ctx.basic.tvoid e.epos) :: !r
| None -> r := (mk (TVars [v,None]) ctx.basic.tvoid e.epos) :: !r

) vl
r := (mk (TVar (v,Some (find e))) ctx.basic.tvoid e.epos) :: !r
| None -> r := (mk (TVar (v,None)) ctx.basic.tvoid e.epos) :: !r
end
| _ -> r := (find e) :: !r
) el;
List.rev !r
Expand Down Expand Up @@ -274,15 +271,15 @@ let check_local_vars_init e =
if v.v_name = "this" then error "Missing this = value" e.epos
else error ("Local variable " ^ v.v_name ^ " used without being initialized") e.epos
end
| TVars vl ->
List.iter (fun (v,eo) ->
| TVar (v,eo) ->
begin
match eo with
| None ->
declared := v.v_id :: !declared;
vars := PMap.add v.v_id false !vars
| Some e ->
loop vars e
) vl
end
| TBlock el ->
let old = !declared in
let old_vars = !vars in
Expand Down Expand Up @@ -412,11 +409,9 @@ let rec local_usage f e =
match e.eexpr with
| TLocal v ->
f (Use v)
| TVars l ->
List.iter (fun (v,e) ->
(match e with None -> () | Some e -> local_usage f e);
f (Declare v);
) l
| TVar (v,eo) ->
(match eo with None -> () | Some e -> local_usage f e);
f (Declare v);
| TFunction tf ->
let cc f =
List.iter (fun (v,_) -> f (Declare v)) tf.tf_args;
Expand Down Expand Up @@ -478,7 +473,7 @@ let captured_vars com e =
let t = com.basic in

let rec mk_init av v pos =
mk (TVars [av,Some (mk (TArrayDecl [mk (TLocal v) v.v_type pos]) av.v_type pos)]) t.tvoid pos
mk (TVar (av,Some (mk (TArrayDecl [mk (TLocal v) v.v_type pos]) av.v_type pos))) t.tvoid pos

and mk_var v used =
let v2 = alloc_var v.v_name (PMap.find v.v_id used) in
Expand All @@ -487,14 +482,14 @@ let captured_vars com e =

and wrap used e =
match e.eexpr with
| TVars vl ->
let vl = List.map (fun (v,ve) ->
| TVar (v,ve) ->
let v,ve =
if PMap.mem v.v_id used then
v, Some (mk (TArrayDecl (match ve with None -> [] | Some e -> [wrap used e])) v.v_type e.epos)
else
v, (match ve with None -> None | Some e -> Some (wrap used e))
) vl in
{ e with eexpr = TVars vl }
in
{ e with eexpr = TVar (v,ve) }
| TLocal v when PMap.mem v.v_id used ->
mk (TArray ({ e with etype = v.v_type },mk (TConst (TInt 0l)) t.tint e.epos)) e.etype e.epos
| TFor (v,it,expr) when PMap.mem v.v_id used ->
Expand Down Expand Up @@ -735,12 +730,10 @@ let rename_local_vars com e =
in
let rec loop e =
match e.eexpr with
| TVars l ->
List.iter (fun (v,eo) ->
if not cfg.pf_locals_scope then declare v e.epos;
(match eo with None -> () | Some e -> loop e);
if cfg.pf_locals_scope then declare v e.epos;
) l
| TVar (v,eo) ->
if not cfg.pf_locals_scope then declare v e.epos;
(match eo with None -> () | Some e -> loop e);
if cfg.pf_locals_scope then declare v e.epos;
| TFunction tf ->
let old = save() in
List.iter (fun (v,_) -> declare v e.epos) tf.tf_args;
Expand Down Expand Up @@ -976,7 +969,7 @@ let add_field_inits ctx t =
end else
eassign;
) inits in
let el = if !need_this then (mk (TVars([v, Some ethis])) ethis.etype ethis.epos) :: el else el in
let el = if !need_this then (mk (TVar((v, Some ethis))) ethis.etype ethis.epos) :: el else el in
match c.cl_constructor with
| None ->
let ct = TFun([],ctx.com.basic.tvoid) in
Expand Down Expand Up @@ -1079,6 +1072,7 @@ let run com tctx main =
(* PASS 1: general expression filters *)
let filters = [
Codegen.Abstract.handle_abstract_casts tctx;
blockify_ast;
(match com.platform with
| Cpp -> (fun e ->
let save = save_locals tctx in
Expand Down
21 changes: 9 additions & 12 deletions genas3.ml
Original file line number Diff line number Diff line change
Expand Up @@ -648,18 +648,15 @@ and gen_expr ctx e =
| TThrow e ->
spr ctx "throw ";
gen_value ctx e;
| TVars [] ->
()
| TVars vl ->
| TVar (v,eo) ->
spr ctx "var ";
concat ctx ", " (fun (v,eo) ->
print ctx "%s : %s" (s_ident v.v_name) (type_str ctx v.v_type e.epos);
match eo with
| None -> ()
| Some e ->
spr ctx " = ";
gen_value ctx e
) vl;
print ctx "%s : %s" (s_ident v.v_name) (type_str ctx v.v_type e.epos);
begin match eo with
| None -> ()
| Some e ->
spr ctx " = ";
gen_value ctx e
end
| TNew (c,params,el) ->
(match c.cl_path, params with
| (["flash"],"Vector"), [pt] -> print ctx "new Vector.<%s>(" (type_str ctx pt e.epos)
Expand Down Expand Up @@ -852,7 +849,7 @@ and gen_value ctx e =
| TBreak
| TContinue ->
unsupported e.epos
| TVars _
| TVar _
| TFor _
| TWhile _
| TThrow _ ->
Expand Down
Loading

0 comments on commit 2fbf280

Please sign in to comment.