Browse Source

added __foreach__

Nicolas Cannasse 16 years ago
parent
commit
3c23b89265
4 changed files with 18 additions and 3 deletions
  1. 1 0
      doc/CHANGES.txt
  2. 10 0
      genas3.ml
  3. 5 1
      genswf9.ml
  4. 2 2
      std/flash9/sampler/Api.hx

+ 1 - 0
doc/CHANGES.txt

@@ -19,6 +19,7 @@ TODO :
 	added SWC output support
 	fixed issues with unset of values in for loops and executing blocks that return functions (haXe/PHP)
 	"throw" type is now Unknown instead of Dynamic (prevent type-hole in "if A else if B else throw")
+	added __foreach__ for flash9/as3
 
 2008-11-23: 2.02
 	Std.is(MyInterface, Class) now returns true (haXe/PHP)

+ 10 - 0
genas3.ml

@@ -340,6 +340,16 @@ let rec gen_call ctx e el r =
 		gen_value ctx e;
 		print ctx ") %s.push(%s.substr(1))" ret tmp;
 		b();
+	| TLocal "__foreach__", [e] ->
+		let ret = (match ctx.in_value with None -> assert false | Some r -> r) in
+		print ctx "%s = new Array()" ret;
+		newline ctx;
+		let b = save_locals ctx in
+		let tmp = define_local ctx "$k" in
+		print ctx "for each(var %s : * in " tmp;
+		gen_value ctx e;
+		print ctx ") %s.push(%s)" ret tmp;
+		b();
 	| TLocal "__new__", e :: args ->
 		spr ctx "new ";
 		gen_value ctx e;

+ 5 - 1
genswf9.ml

@@ -1198,6 +1198,7 @@ and gen_call ctx retval e el r =
 		gen_expr ctx true e;
 		write ctx HToNumber
 	| TLocal "__hkeys__" , [e2]
+	| TLocal "__foreach__", [e2]
 	| TLocal "__keys__" , [e2] ->
 		let racc = alloc_reg ctx (KType (type_path ctx ([],"Array"))) in
 		let rcounter = alloc_reg ctx KInt in
@@ -1213,7 +1214,10 @@ and gen_call ctx retval e el r =
 		write ctx (HReg racc.rid);
 		write ctx (HReg rtmp.rid);
 		write ctx (HReg rcounter.rid);
-		write ctx HForIn;
+		if e.eexpr = TLocal "__foreach__" then
+			write ctx HForEach
+		else
+			write ctx HForIn;
 		if e.eexpr = TLocal "__hkeys__" then begin
 			write ctx (HSmallInt 1);
 			write ctx (HCallProperty (as3 "substr",1));

+ 2 - 2
std/flash9/sampler/Api.hx

@@ -26,8 +26,8 @@ class Api {
 		return untyped __global__["flash.sampler.getSampleCount"]();
 	}
 
-	public static function getSamples() : Dynamic<flash.sampler.Sample> {
-		return untyped __global__["flash.sampler.getSamples"]();
+	public static function getSamples() : Array<flash.sampler.Sample> {
+		return untyped __foreach__(__global__["flash.sampler.getSamples"]());
 	}
 
 	public static function getSize( obj : Dynamic ) : Float {