Răsfoiți Sursa

finalized TAbstract support, now pass unit tests

Nicolas Cannasse 13 ani în urmă
părinte
comite
f51c06e2a0
7 a modificat fișierele cu 24 adăugiri și 5 ștergeri
  1. 4 1
      dce.ml
  2. 6 0
      gencpp.ml
  3. 5 1
      genswf9.ml
  4. 3 0
      haxe.vcproj
  5. 2 1
      interp.ml
  6. 3 1
      optimizer.ml
  7. 1 1
      typeload.ml

+ 4 - 1
dce.ml

@@ -105,7 +105,8 @@ let rec mark_t dce t = match follow t with
 	| TInst(c,pl) -> mark_class dce c; List.iter (mark_t dce) pl
 	| TFun(args,ret) -> List.iter (fun (_,_,t) -> mark_t dce t) args; mark_t dce ret
 	| TEnum(e,pl) -> if not (has_meta ":used" e.e_meta) then e.e_meta <- (":used",[],e.e_pos) :: e.e_meta; List.iter (mark_t dce) pl
-	| _ -> ()
+	| TAbstract(a,pl) -> if not (has_meta ":used" a.a_meta) then a.a_meta <- (":used",[],a.a_pos) :: a.a_meta; List.iter (mark_t dce) pl
+	| TLazy _ | TDynamic _ | TAnon _ | TType _ | TMono _ -> ()
 
 (* find all dependent fields by checking implementing/subclassing types *)
 let rec mark_dependent_fields dce csup n stat =
@@ -190,6 +191,8 @@ and expr dce e =
 		) vl;
 	| TTypeExpr (TClassDecl c) ->
 		mark_class dce c;
+	| TTypeExpr (TAbstractDecl a) ->
+		mark_t dce (TAbstract (a,[]))
 	| TCast(e, Some (TEnumDecl en)) ->
 		mark_t dce (TEnum(en,[]));
 		expr dce e;

+ 6 - 0
gencpp.ml

@@ -352,6 +352,9 @@ let rec class_string klass suffix params =
 	|  ([],"Null") -> (match params with
 			| [t] ->
 				(match follow t with
+				| TAbstract ({ a_path = [],"Int" },_)
+				| TAbstract ({ a_path = [],"Float" },_)
+				| TAbstract ({ a_path = [],"Bool" },_)
 				| TInst ({ cl_path = [],"Int" },_)
 				| TInst ({ cl_path = [],"Float" },_)
 				| TEnum ({ e_path = [],"Bool" },_) -> "Dynamic"
@@ -381,6 +384,9 @@ and type_string_suff suffix haxe_type =
 			(match params with
 			| [t] ->
 				(match follow t with
+				| TAbstract ({ a_path = [],"Int" },_)
+				| TAbstract ({ a_path = [],"Float" },_)
+				| TAbstract ({ a_path = [],"Bool" },_)
 				| TInst ({ cl_path = [],"Int" },_)
 				| TInst ({ cl_path = [],"Float" },_)
 				| TEnum ({ e_path = [],"Bool" },_) -> "Dynamic" ^ suffix

+ 5 - 1
genswf9.ml

@@ -217,6 +217,8 @@ let rec type_id ctx t =
 			type_id ctx (TInst (c,params))
 		| _ ->
 			type_path ctx c.cl_path)
+	| TAbstract (a,_) ->
+		type_path ctx a.a_path
 	| TFun _ | TType ({ t_path = ["flash";"utils"],"Function" },[]) ->
 		type_path ctx ([],"Function")
 	| TType ({ t_path = ([],"UInt") as path },_) ->
@@ -2277,7 +2279,7 @@ let generate_enum ctx e meta =
 		} :: constrs);
 	}
 
-let generate_type ctx t =
+let rec generate_type ctx t =
 	match t with
 	| TClassDecl c ->
 		if c.cl_path = (["flash";"_Boot"],"RealBoot") then c.cl_path <- ctx.boot;
@@ -2311,6 +2313,8 @@ let generate_type ctx t =
 				hlf_kind = HFClass hlc;
 				hlf_metas = extract_meta e.e_meta;
 			})
+	| TAbstractDecl ({ a_path = [],"Dynamic" } as a) ->
+		generate_type ctx (TClassDecl (mk_class a.a_module a.a_path a.a_pos))
 	| TTypeDecl _ | TAbstractDecl _ ->
 		None
 

+ 3 - 0
haxe.vcproj

@@ -113,6 +113,9 @@
 		<File
 			RelativePath=".\common.ml">
 		</File>
+		<File
+			RelativePath=".\dce.ml">
+		</File>
 		<File
 			RelativePath=".\interp.ml">
 		</File>

+ 2 - 1
interp.ml

@@ -4045,7 +4045,7 @@ and encode_type t =
 		| TLazy f ->
 			loop (!f())
 		| TAbstract (a, pl) ->
-			7, [encode_ref a encode_tabstract (fun() -> s_type_path a.a_path); encode_tparams pl]
+			8, [encode_ref a encode_tabstract (fun() -> s_type_path a.a_path); encode_tparams pl]
 	in
 	let tag, pl = loop t in
 	enc_enum IType tag pl
@@ -4074,6 +4074,7 @@ and decode_type t =
 	| 6, [VNull] -> t_dynamic
 	| 6, [t] -> TDynamic (decode_type t)
 	| 7, [VAbstract (ALazyType f)] -> TLazy f
+	| 8, [a; pl] -> TAbstract (decode_ref a, List.map decode_type (dec_array pl))
 	| _ -> raise Invalid_expr
 
 and encode_texpr e =

+ 3 - 1
optimizer.ml

@@ -426,7 +426,7 @@ let optimize_for_loop ctx i e1 e2 p =
 			force locals to be of Int type (to prevent Int/UInt issues)
 		*)
 		let i2 = match i2.etype with
-			| TInst({ cl_path = ([],"Int") }, []) -> i2
+			| TInst({ cl_path = ([],"Int") }, []) | TAbstract ({ a_path = ([],"Int") }, []) -> i2
 			| _ -> { i2 with eexpr = TCast(i2, None); etype = t_int }
 		in
 		(match max with
@@ -710,11 +710,13 @@ let rec sanitize ctx e =
 let rec reduce_loop ctx e =
 	let is_float t =
 		match follow t with
+		| TAbstract({ a_path = [],"Float" },_) -> true
 		| TInst ({ cl_path = ([],"Float") },_) -> true
 		| _ -> false
 	in
 	let is_numeric t =
 		match follow t with
+		| TAbstract({ a_path = [],("Float"|"Int") },_) -> true
 		| TInst ({ cl_path = ([],("Float" | "Int")) },_) -> true
 		| _ -> false
 	in

+ 1 - 1
typeload.ml

@@ -49,7 +49,7 @@ let type_var_field ctx t e stat p =
 	let e = type_expr_with_type ctx e (Some t) false in
 	unify ctx e.etype t p;
 	match t with
-	| TType ({ t_path = ([],"UInt") },[]) when stat -> { e with etype = t }
+	| TType ({ t_path = ([],"UInt") },[]) | TAbstract ({ a_path = ([],"UInt") },[]) when stat -> { e with etype = t }
 	| _ -> e
 
 let apply_macro ctx mode path el p =