Browse Source

fixed + operator with Dynamic/Null operands

Nicolas Cannasse 18 years ago
parent
commit
9c2008a449
2 changed files with 13 additions and 5 deletions
  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
 	fixed some F9 issues with haXe-specific Array, Date and Math methods
 	used AS3 namespace for F9 Array and String instance methods
 	used AS3 namespace for F9 Array and String instance methods
 	fixed F9 with uninitialized integer registers
 	fixed F9 with uninitialized integer registers
+	fixed F9 + operator with Dynamic/Null operands
 
 
 2007-07-25: 1.14
 2007-07-25: 1.14
 	fixed no error when invalid "catch" expression
 	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);
 		getvar ctx (gen_access ctx e Read);
 		coerce ctx (classify ctx e.etype)
 		coerce ctx (classify ctx e.etype)
 	| TBinop (op,e1,e2) ->
 	| TBinop (op,e1,e2) ->
-		gen_binop ctx retval op e1 e2
+		gen_binop ctx retval op e1 e2 e.etype
 	| TCall (e,el) ->
 	| TCall (e,el) ->
 		gen_call ctx e el
 		gen_call ctx e el
 	| TNew (c,_,pl) ->
 	| TNew (c,_,pl) ->
@@ -1118,13 +1118,20 @@ and gen_unop ctx retval op flag e =
 			write ctx (A3Op (if incr then A3OIncr else A3ODecr));
 			write ctx (A3Op (if incr then A3OIncr else A3ODecr));
 			setvar ctx acc retval
 			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 =
 	let gen_op ?iop o =
 		gen_expr ctx true e1;
 		gen_expr ctx true e1;
 		gen_expr ctx true e2;
 		gen_expr ctx true e2;
 		match iop with
 		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)
 			write ctx (A3Op o)
 	in
 	in
@@ -1151,7 +1158,7 @@ and gen_binop ctx retval op e1 e2 =
 		j();
 		j();
 	| OpAssignOp op ->
 	| OpAssignOp op ->
 		let acc = gen_access ctx e1 Write in
 		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
 		setvar ctx acc retval
 	| OpAdd ->
 	| OpAdd ->
 		gen_op ~iop:A3OIAdd A3OAdd
 		gen_op ~iop:A3OIAdd A3OAdd