Procházet zdrojové kódy

fixed block_vars (take into account "for" variable)

Nicolas Cannasse před 18 roky
rodič
revize
74628ad9b2
3 změnil soubory, kde provedl 14 přidání a 7 odebrání
  1. 1 0
      doc/CHANGES.txt
  2. 9 6
      genswf9.ml
  3. 4 1
      transform.ml

+ 1 - 0
doc/CHANGES.txt

@@ -8,6 +8,7 @@
 	add uniqueness check for switch constants
 	js : HtmlCollection and MetaDom.childNodes are not true Arrays
 	allowed semicolon after typedef declaration
+	fixed in-loop closure usage of "for" variable for Flash and JS
 
 2007-03-06: 1.12
 	added flash lite support with -D flash_lite

+ 9 - 6
genswf9.ml

@@ -1036,6 +1036,9 @@ and generate_function ctx fdata stat =
 	write ctx A3RetVoid;
 	f()
 
+let generate_method ctx fdata stat =
+	generate_function ctx { fdata with tf_expr = Transform.block_vars fdata.tf_expr } stat
+
 let generate_construct ctx fdata cfields =
 	let args = List.map (fun (name,opt,_) -> name,opt) fdata.tf_args in
 	let f = begin_fun ctx args [fdata.tf_expr] false in
@@ -1050,11 +1053,11 @@ let generate_construct ctx fdata cfields =
 		| Some { eexpr = TFunction fdata } when f.cf_set = NormalAccess ->
 			let id = ident ctx f.cf_name in
 			write ctx (A3SetInf id);
-			write ctx (A3Function (generate_function ctx fdata false));
+			write ctx (A3Function (generate_method ctx fdata false));
 			write ctx (A3Set id);
 		| _ -> ()
 	) cfields;
-	gen_expr ctx false fdata.tf_expr;
+	gen_expr ctx false (Transform.block_vars fdata.tf_expr);
 	write ctx A3RetVoid;
 	f() , List.length args
 
@@ -1100,7 +1103,7 @@ let generate_class_init ctx c slot =
 		match f.cf_expr with
 		| Some { eexpr = TFunction fdata } when f.cf_set = NormalAccess ->
 			write ctx A3Dup;
-			write ctx (A3Function (generate_function ctx fdata true));
+			write ctx (A3Function (generate_method ctx fdata true));
 			write ctx (A3Set (ident ctx f.cf_name));
 		| _ -> ()
 	) c.cl_ordered_statics;
@@ -1123,7 +1126,7 @@ let generate_class_statics ctx c =
 				first := false;
 			end;
 			write ctx (A3Reg r);
-			gen_expr ctx true e;
+			gen_expr ctx true (Transform.block_vars e);
 			write ctx (A3SetSlot !nslot);
 	) c.cl_ordered_statics;
 	free_reg ctx r
@@ -1173,7 +1176,7 @@ let generate_field_kind ctx f c stat =
 			})	
 		else
 			Some (A3FMethod {
-				m3_type = generate_function ctx fdata stat;
+				m3_type = generate_method ctx fdata stat;
 				m3_final = false;
 				m3_override = not stat && loop c;
 				m3_kind = MK3Normal;
@@ -1391,7 +1394,7 @@ let generate_inits ctx types =
 		| TClassDecl c ->
 			(match c.cl_init with
 			| None -> ()
-			| Some e -> gen_expr ctx false e);
+			| Some e -> gen_expr ctx false (Transform.block_vars e));
 		| _ -> ()
 	) types;
 	List.iter (fun t ->

+ 4 - 1
transform.ml

@@ -150,6 +150,9 @@ let block_vars e =
 				add_var vars v;
 				v, t, e
 			) l) }
+		| TFor (v,t,i,e) ->
+			let new_vars = PMap.add v () (!vars) in
+			{ e with eexpr = TFor (v,t,in_loop vars i,in_loop (ref new_vars) e) }
 		| TTry (e,cases) ->
 			let e = in_loop vars e in
 			let cases = List.map (fun (v,t,e) ->
@@ -189,7 +192,7 @@ let block_vars e =
 	and out_loop e =
 		match e.eexpr with
 		| TFor _ | TWhile _ ->
-			map (in_loop (ref PMap.empty)) e
+			in_loop (ref PMap.empty) e
 		| _ ->
 			map out_loop e
 	in