Browse Source

added FEnumParameter

Simon Krajewski 12 years ago
parent
commit
73d9102e3d
10 changed files with 31 additions and 20 deletions
  1. 3 7
      codegen.ml
  2. 3 0
      genas3.ml
  3. 6 2
      gencpp.ml
  4. 1 1
      genjs.ml
  5. 2 0
      genneko.ml
  6. 3 0
      genphp.ml
  7. 5 0
      genswf9.ml
  8. 2 6
      matcher.ml
  9. 5 3
      type.ml
  10. 1 1
      typer.ml

+ 3 - 7
codegen.ml

@@ -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
@@ -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

+ 3 - 0
genas3.ml

@@ -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)

+ 6 - 2
gencpp.ml

@@ -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
@@ -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
 

+ 1 - 1
genjs.ml

@@ -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 ->

+ 2 - 0
genneko.ml

@@ -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 ->

+ 3 - 0
genphp.ml

@@ -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 ->

+ 5 - 0
genswf9.ml

@@ -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

+ 2 - 6
matcher.ml

@@ -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
@@ -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

+ 5 - 3
type.ml

@@ -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;
@@ -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
 
@@ -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
@@ -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)
@@ -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 ->

+ 1 - 1
typer.ml

@@ -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())