Explorar o código

fixed + operator with Dynamic/Null operands

Nicolas Cannasse %!s(int64=18) %!d(string=hai) anos
pai
achega
9c2008a449
Modificáronse 2 ficheiros con 13 adicións e 5 borrados
  1. 1 0
      doc/CHANGES.txt
  2. 12 5
      genswf9.ml

+ 1 - 0
doc/CHANGES.txt

@@ -14,6 +14,7 @@
 	fixed some F9 issues with haXe-specific Array, Date and Math methods
 	used AS3 namespace for F9 Array and String instance methods
 	fixed F9 with uninitialized integer registers
+	fixed F9 + operator with Dynamic/Null operands
 
 2007-07-25: 1.14
 	fixed no error when invalid "catch" expression

+ 12 - 5
genswf9.ml

@@ -735,7 +735,7 @@ let rec gen_expr_content ctx retval e =
 		getvar ctx (gen_access ctx e Read);
 		coerce ctx (classify ctx e.etype)
 	| TBinop (op,e1,e2) ->
-		gen_binop ctx retval op e1 e2
+		gen_binop ctx retval op e1 e2 e.etype
 	| TCall (e,el) ->
 		gen_call ctx e el
 	| TNew (c,_,pl) ->
@@ -1118,13 +1118,20 @@ and gen_unop ctx retval op flag e =
 			write ctx (A3Op (if incr then A3OIncr else A3ODecr));
 			setvar ctx acc retval
 
-and gen_binop ctx retval op e1 e2 =
+and gen_binop ctx retval op e1 e2 t =
 	let gen_op ?iop o =
 		gen_expr ctx true e1;
 		gen_expr ctx true e2;
 		match iop with
-		| Some iop when classify ctx e1.etype = KInt && classify ctx e2.etype = KInt ->
-			write ctx (A3Op iop)
+		| Some iop -> 
+			let k1 = classify ctx e1.etype in
+			let k2 = classify ctx e2.etype in
+			if k1 = KInt && k2 = KInt then
+				write ctx (A3Op iop)
+			else begin
+				write ctx (A3Op o);
+				if o = A3OAdd then coerce ctx (classify ctx t);
+			end;
 		| _ ->
 			write ctx (A3Op o)
 	in
@@ -1151,7 +1158,7 @@ and gen_binop ctx retval op e1 e2 =
 		j();
 	| OpAssignOp op ->
 		let acc = gen_access ctx e1 Write in
-		gen_binop ctx true op e1 e2;
+		gen_binop ctx true op e1 e2 t;
 		setvar ctx acc retval
 	| OpAdd ->
 		gen_op ~iop:A3OIAdd A3OAdd