Skip to content

Commit

Permalink
added FEnumParameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Jun 1, 2013
1 parent 4725d2b commit 73d9102
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 20 deletions.
10 changes: 3 additions & 7 deletions codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1563,12 +1563,7 @@ module PatternMatchConversion = struct
mk (TField(e,fa)) st.st_type st.st_pos
| SArray (sts,i) -> mk (TArray(convert_st cctx sts,mk_const cctx.ctx st.st_pos (TInt (Int32.of_int i)))) st.st_type st.st_pos
| STuple (st,_,_) -> convert_st cctx st
| SEnum(sts,_,i) ->
let cf = PMap.find "enumParameters" cctx.ttype.cl_statics in
let ec = mk (TTypeExpr (TClassDecl cctx.ttype)) t_dynamic st.st_pos in
let ef = mk (TField(ec, FStatic(cctx.ttype,cf))) (tfun [sts.st_type] (cctx.ctx.t.tarray t_dynamic)) st.st_pos in
let ec = mk (TCall (ef,[convert_st cctx sts])) t_dynamic st.st_pos in
mk (TArray (ec,mk (TConst(TInt (Int32.of_int i))) cctx.ctx.t.tint st.st_pos)) st.st_type st.st_pos
| SEnum(sts,ef,i) -> mk (TField(convert_st cctx sts, FEnumParameter(ef,i))) st.st_type st.st_pos

let convert_con cctx con = match con.c_def with
| CConst c -> mk_const cctx.ctx con.c_pos c
Expand Down Expand Up @@ -1638,8 +1633,9 @@ module PatternMatchConversion = struct
let e_subject,exh = match follow st.st_type with
| TEnum(_) ->
let cf = PMap.find "enumIndex" cctx.ttype.cl_statics in
let ec = mk (TTypeExpr (TClassDecl cctx.ttype)) t_dynamic p in
let ec = (!type_module_type_ref) cctx.ctx (TClassDecl cctx.ttype) None p in
let ef = mk (TField(ec, FStatic(cctx.ttype,cf))) (tfun [t_dynamic] cctx.ctx.t.tint) p in
(* make_call cctx.ctx ef [e_st] cctx.ctx.t.tint p,true *)
mk (TCall (ef,[e_st])) cctx.ctx.t.tint p,true
| TInst({cl_path = [],"Array"},_) as t ->
mk (TField (e_st,quick_field t "length")) cctx.ctx.t.tint p,false
Expand Down
3 changes: 3 additions & 0 deletions genas3.ml
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,9 @@ and gen_expr ctx e =
gen_expr ctx e1;
spr ctx ")";
gen_field_access ctx e1.etype (field_name s)
| TField (e,FEnumParameter(_,i)) ->
gen_value ctx e;
print ctx ".params[%i]" i;
| TField (e,s) ->
gen_value ctx e;
gen_field_access ctx e.etype (field_name s)
Expand Down
8 changes: 6 additions & 2 deletions gencpp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,7 @@ and gen_expression ctx retval expression =
check_array_cast (Codegen.Abstract.get_underlying_type abs pl)
| _ -> ()
in

let rec gen_tfield field_object field =
let member = (field_name field) in
let remap_name = keyword_remap member in
Expand Down Expand Up @@ -1734,7 +1734,11 @@ and gen_expression ctx retval expression =
(* Get precidence matching haxe ? *)
| TBinop (op,expr1,expr2) -> gen_bin_op op expr1 expr2
| TField (expr,name) when (is_null expr) -> output "Dynamic()"

| TField (expr,FEnumParameter(ef,i)) ->
let enum = match follow expr.etype with TEnum(enum,_) -> enum | _ -> assert false in
output ( "(::" ^ (join_class_path_remap enum.e_path "::") ^ "(");
gen_expression ctx true expr;
output ( "))->__Param(" ^ (string_of_int i) ^ ")")
| TField (field_object,field) ->
gen_tfield field_object field

Expand Down
2 changes: 1 addition & 1 deletion genjs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ and gen_expr ctx e =
| TField (x,f) ->
gen_value ctx x;
let name = field_name f in
spr ctx (match f with FStatic _ | FEnum _ -> static_field name | FInstance _ | FAnon _ | FDynamic _ | FClosure _ -> field name)
spr ctx (match f with FStatic _ | FEnum _ -> static_field name | FInstance _ | FAnon _ | FDynamic _ | FClosure _ -> field name | FEnumParameter(f,i) -> "[" ^ (string_of_int (i + 2)) ^ "]")
| TTypeExpr t ->
spr ctx (ctx.type_accessor t)
| TParenthesis e ->
Expand Down
2 changes: 2 additions & 0 deletions genneko.ml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ and gen_expr ctx e =
call p (ident p ("@closure" ^ string_of_int n)) [tmp;ident p "@fun"]
] , p
| _ -> assert false)
| TField (e,FEnumParameter(_,i)) ->
EArray (field p (gen_expr ctx e) "args",int p i),p
| TField (e,f) ->
field p (gen_expr ctx e) (field_name f)
| TTypeExpr t ->
Expand Down
3 changes: 3 additions & 0 deletions genphp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,9 @@ and gen_expr ctx e =
print ctx " %s " (Ast.s_binop op);
gen_value_op ctx e2;
));
| TField (e1,FEnumParameter(_,i)) ->
gen_value ctx e1;
print ctx "->params[%d]" i;
| TField (e1,s) ->
gen_tfield ctx e e1 (field_name s)
| TTypeExpr t ->
Expand Down
5 changes: 5 additions & 0 deletions genswf9.ml
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,11 @@ let rec gen_access ctx e (forset : 'a) : 'a access =
let id, _, _ = property ctx f e1.etype in
write ctx HThis;
VSuper id
| TField (e1,FEnumParameter(ef,i)) ->
gen_expr ctx true e1;
write ctx (HGetProp (ident "params"));
write ctx (HSmallInt i);
VArray
| TField (e1,f) ->
let f = field_name f in
let id, k, closure = property ctx f e1.etype in
Expand Down
8 changes: 2 additions & 6 deletions matcher.ml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ let mk_subs st con =
begin match apply_params en.e_types pl (monomorphs ef.ef_params ef.ef_type) with
| TFun(args,r) ->
ExtList.List.mapi (fun i (_,_,t) ->
mk_st (SEnum(st,ef.ef_name,i)) t st.st_pos
mk_st (SEnum(st,ef,i)) t st.st_pos
) args
| _ ->
assert false
Expand Down Expand Up @@ -1004,11 +1004,7 @@ let match_expr ctx e cases def with_type p =
s_st_r false true st (Printf.sprintf "[%i]%s" i (if top then " = " ^ v else v))
| SField(st,f) ->
s_st_r false true st (Printf.sprintf ".%s%s" f (if top then " = " ^ v else v))
| SEnum(st,n,i) ->
let ef = match follow st.st_type with
| TEnum(en,_) -> PMap.find n en.e_constrs
| _ -> raise Not_found
in
| SEnum(st,ef,i) ->
let len = match follow ef.ef_type with TFun(args,_) -> List.length args | _ -> 0 in
s_st_r false false st (Printf.sprintf "%s(%s)" ef.ef_name (st_args i (len - 1 - i) v))
in
Expand Down
8 changes: 5 additions & 3 deletions type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ and tfield_access =
| FDynamic of string
| FClosure of tclass option * tclass_field (* None class = TAnon *)
| FEnum of tenum * tenum_field
| FEnumParameter of tenum_field * int

and texpr = {
eexpr : texpr_expr;
Expand Down Expand Up @@ -309,7 +310,7 @@ and con = {
and st_def =
| SVar of tvar
| SField of st * string
| SEnum of st * string * int
| SEnum of st * tenum_field * int
| SArray of st * int
| STuple of st * int * int

Expand Down Expand Up @@ -361,7 +362,7 @@ let fun_args l = List.map (fun (a,c,t) -> a, c <> None, t) l
let field_name f =
match f with
| FAnon f | FInstance (_,f) | FStatic (_,f) | FClosure (_,f) -> f.cf_name
| FEnum (_,f) -> f.ef_name
| FEnum (_,f) | FEnumParameter (f,_) -> f.ef_name
| FDynamic n -> n

let extract_field = function
Expand Down Expand Up @@ -1578,7 +1579,7 @@ and s_dt tabs tree =
let rec s_st st =
(match st.st_def with
| SVar v -> v.v_name
| SEnum (st,n,i) -> s_st st ^ "." ^ n ^ "." ^ (string_of_int i)
| SEnum (st,ef,i) -> s_st st ^ "." ^ ef.ef_name ^ "." ^ (string_of_int i)
| SArray (st,i) -> s_st st ^ "[" ^ (string_of_int i) ^ "]"
| STuple (st,i,a) -> "(" ^ (st_args i (a - i - 1) (s_st st)) ^ ")"
| SField (st,n) -> s_st st ^ "." ^ n)
Expand Down Expand Up @@ -1618,6 +1619,7 @@ and s_expr s_type e =
| FAnon f -> "anon(" ^ f.cf_name ^ ")"
| FEnum (en,f) -> "enum(" ^ s_type_path en.e_path ^ "." ^ f.ef_name ^ ")"
| FDynamic f -> "dynamic(" ^ f ^ ")"
| FEnumParameter (f,i) -> "enumParam(" ^ f.ef_name ^ "," ^ (string_of_int i) ^ ")"
) in
sprintf "%s.%s" (loop e) fstr
| TTypeExpr m ->
Expand Down
2 changes: 1 addition & 1 deletion typer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ let field_access ctx mode f fmode t e p =
| FInstance (c,cf) -> FClosure (Some c,cf)
| FStatic _ | FEnum _ -> fmode
| FAnon f -> FClosure (None, f)
| FDynamic _ | FClosure _ -> assert false
| FDynamic _ | FClosure _ | FEnumParameter _ -> assert false
) in
AKExpr (mk (TField (e,cmode)) t p)
| _ -> normal())
Expand Down

0 comments on commit 73d9102

Please sign in to comment.