Browse Source

added flash9 resources

Nicolas Cannasse 18 years ago
parent
commit
ac99c662a9
4 changed files with 27 additions and 5 deletions
  1. 1 0
      doc/CHANGES.txt
  2. 24 4
      genswf9.ml
  3. 1 1
      std/Std.hx
  4. 1 0
      std/flash9/Boot.hx

+ 1 - 0
doc/CHANGES.txt

@@ -17,6 +17,7 @@
 	new faster neko binary AST
 	new faster neko binary AST
 	added haxe.remoting.NekoSocketConnection and SocketProtocol
 	added haxe.remoting.NekoSocketConnection and SocketProtocol
 	don't allow for...in iteration with Dynamic or Unknown
 	don't allow for...in iteration with Dynamic or Unknown
+	added flash9 resources
 
 
 2007-05-18: 1.13
 2007-05-18: 1.13
 	fixed bug with local variable masking package in catch type
 	fixed bug with local variable masking package in catch type

+ 24 - 4
genswf9.ml

@@ -1463,7 +1463,24 @@ let generate_type ctx t =
 	| TTypeDecl _ -> ()
 	| TTypeDecl _ -> ()
 	| TEnumDecl e -> if not e.e_extern then generate_enum ctx e
 	| TEnumDecl e -> if not e.e_extern then generate_enum ctx e
 
 
-let generate_inits ctx types =
+let generate_resources ctx hres =
+	write ctx A3GetGlobalScope;
+	write ctx (A3GetProp (type_path ctx ([],ctx.boot)));
+	let id = type_path ctx (["flash";"utils"],"Dictionary") in
+	write ctx (A3FindPropStrict id);	
+	write ctx (A3ConstructProperty (id,0));
+	let r = alloc_reg ctx (KType id) in
+	set_reg ctx r;
+	Hashtbl.iter (fun name data ->
+		write ctx (A3Reg r.rid);
+		write ctx (A3String (lookup name ctx.strings));
+		write ctx (A3String (lookup data ctx.strings));
+		setvar ctx VArray false;
+	) hres;
+	write ctx (A3Reg r.rid);
+	write ctx (A3InitProp (ident ctx "__res"))
+
+let generate_inits ctx types hres =
 	let f = begin_fun ctx [] t_void [] false in
 	let f = begin_fun ctx [] t_void [] false in
 	let slot = ref 0 in
 	let slot = ref 0 in
 	let classes = List.fold_left (fun acc t ->
 	let classes = List.fold_left (fun acc t ->
@@ -1510,6 +1527,10 @@ let generate_inits ctx types =
 	write ctx A3RetVoid;
 	write ctx A3RetVoid;
 	write ctx (A3Function (finit()));
 	write ctx (A3Function (finit()));
 	write ctx (A3InitProp (ident ctx "init"));
 	write ctx (A3InitProp (ident ctx "init"));
+
+	(* generate resources *)
+	generate_resources ctx hres;
+
 	write ctx A3RetVoid;
 	write ctx A3RetVoid;
 	{
 	{
 		st3_method = f();
 		st3_method = f();
@@ -1549,9 +1570,8 @@ let generate types hres =
 		last_line = -1;
 		last_line = -1;
 		try_scope_reg = None;
 		try_scope_reg = None;
 	} in
 	} in
-	List.iter (generate_type ctx) types;
-	Hashtbl.iter (fun _ _ -> failwith "Resources are not yet supported in Flash9") hres;
-	let init = generate_inits ctx types in
+	List.iter (generate_type ctx) types;	
+	let init = generate_inits ctx types hres in
 	let a = {
 	let a = {
 		as3_ints = lookup_array ctx.ints;
 		as3_ints = lookup_array ctx.ints;
 		as3_uints = [||];
 		as3_uints = [||];

+ 1 - 1
std/Std.hx

@@ -183,7 +183,7 @@ class Std {
 	public static function resource( name : String ) : String {
 	public static function resource( name : String ) : String {
 		return untyped
 		return untyped
 		#if flash9
 		#if flash9
-		null;
+		flash.Boot.__res[name];
 		#else flash
 		#else flash
 		flash.Boot.__res[name];
 		flash.Boot.__res[name];
 		#else neko
 		#else neko

+ 1 - 0
std/flash9/Boot.hx

@@ -7,6 +7,7 @@ class Boot extends flash.display.MovieClip {
 	static var init : Void -> Void;
 	static var init : Void -> Void;
 	static var tf : flash.text.TextField;
 	static var tf : flash.text.TextField;
 	static var lines : Array<String>;
 	static var lines : Array<String>;
+	static var __res : flash.utils.Dictionary;
 	public static var skip_constructor = false;
 	public static var skip_constructor = false;
 
 
 	public function new(?mc:flash.display.MovieClip) {
 	public function new(?mc:flash.display.MovieClip) {