瀏覽代碼

always coerce after TCall

Nicolas Cannasse 17 年之前
父節點
當前提交
87e044a02a
共有 3 個文件被更改,包括 18 次插入35 次删除
  1. 1 0
      doc/CHANGES.txt
  2. 15 33
      genswf9.ml
  3. 2 2
      std/flash9/filters/ConvolutionFilter.hx

+ 1 - 0
doc/CHANGES.txt

@@ -13,6 +13,7 @@ TODO inlining : substitute class+function type parameters in order to have fully
 	haxe/PHP integeration
 	renamed NekoSocketConnection to SyncSocketConnection (php support)
 	fixes in genAs3
+	fix for flash9 : always coerce call return type
 
 2008-07-17: 2.0-RC1
 	genneko : remove big array error (fixed in neko 1.7.1)

+ 15 - 33
genswf9.ml

@@ -798,8 +798,8 @@ let rec gen_expr_content ctx retval e =
 		coerce ctx (classify ctx e.etype)
 	| TBinop (op,e1,e2) ->
 		gen_binop ctx retval op e1 e2 e.etype
-	| TCall (e,el) ->
-		gen_call ctx retval e el
+	| TCall (f,el) ->
+		gen_call ctx retval f el e.etype
 	| TNew ({ cl_path = [],"Array" },_,[]) ->
 		(* it seems that [] is 4 time faster than new Array() *)
 		write ctx (HArray 0)
@@ -1080,7 +1080,7 @@ let rec gen_expr_content ctx retval e =
 		List.iter (fun j -> j()) jends;
 		free_reg ctx rparams
 
-and gen_call ctx retval e el =
+and gen_call ctx retval e el r =
 	match e.eexpr , el with
 	| TLocal "__is__" , [e;t] ->
 		gen_expr ctx true e;
@@ -1171,11 +1171,16 @@ and gen_call ctx retval e el =
 		write ctx (HFindPropStrict id);
 		List.iter (gen_expr ctx true) el;
 		write ctx (HCallSuper (id,List.length el));
+		coerce ctx (classify ctx r);
 	| TField ({ eexpr = TConst TThis },f) , _ when not ctx.in_static ->
 		let id = ident f in
 		write ctx (HFindPropStrict id);
 		List.iter (gen_expr ctx true) el;
-		write ctx (if retval then HCallProperty (id,List.length el) else HCallPropVoid (id,List.length el));
+		if retval then begin
+			write ctx (HCallProperty (id,List.length el));
+			coerce ctx (classify ctx r);
+		end else
+			write ctx (HCallPropVoid (id,List.length el))
 	| TField (e1,f) , _ ->
 		let old = ctx.for_call in
 		ctx.for_call <- true;
@@ -1183,35 +1188,11 @@ and gen_call ctx retval e el =
 		ctx.for_call <- old;
 		List.iter (gen_expr ctx true) el;
 		let id , _, _ = property f e1.etype in
-		if not retval then
-			write ctx (HCallPropVoid (id,List.length el))
-		else
-			let coerce() =
-				match follow e.etype with
-				| TFun (_,r) -> coerce ctx (classify ctx r)
-				| _ -> ()
-			in
+		if retval then begin
 			write ctx (HCallProperty (id,List.length el));
-			(match follow e1.etype with
-			| TInst ({ cl_path = [],"Array" },_) ->
-				(match f with
-				| "copy" | "remove" -> coerce()
-				| _ -> ())
-			| TInst ({ cl_path = [],"Date" },_) ->
-				coerce() (* all date methods are typed as Number in AS3 and Int in haXe *)
-			| TAnon a ->
-				(match !(a.a_status) with
-				| Statics { cl_path = ([],"Date") } ->
-					(match f with
-					| "now" | "fromString" | "fromTime"  -> coerce()
-					| _ -> ())
-				| Statics { cl_path = ([],"Math") } ->
-					(match f with
-					| "isFinite" | "isNaN" -> coerce()
-					| "floor" | "ceil" | "round" -> coerce() (* AS3 state Number, while Int in haXe *)
-					| _ -> ())
-				| _ -> ())
-			| _ -> ())
+			coerce ctx (classify ctx r);
+		end else
+			write ctx (HCallPropVoid (id,List.length el))
 	| TEnumField (e,f) , _ ->
 		let id = type_path ctx e.e_path in
 		write ctx (HGetLex id);
@@ -1221,7 +1202,8 @@ and gen_call ctx retval e el =
 		gen_expr ctx true e;
 		write ctx HGetGlobalScope;
 		List.iter (gen_expr ctx true) el;
-		write ctx (HCallStack (List.length el))
+		write ctx (HCallStack (List.length el));
+		coerce ctx (classify ctx r)
 
 and gen_unop ctx retval op flag e =
 	let k = classify ctx e.etype in

+ 2 - 2
std/flash9/filters/ConvolutionFilter.hx

@@ -7,8 +7,8 @@ extern class ConvolutionFilter extends BitmapFilter {
 	var color : UInt;
 	var divisor : Float;
 	var matrix : Array<Dynamic>;
-	var matrixX : Float;
-	var matrixY : Float;
+	var matrixX : Int;
+	var matrixY : Int;
 	var preserveAlpha : Bool;
 	function new(?matrixX : Float, ?matrixY : Float, ?matrix : Array<Dynamic>, ?divisor : Float, ?bias : Float, ?preserveAlpha : Bool, ?clamp : Bool, ?color : UInt, ?alpha : Float) : Void;
 }