Browse Source

completed flash10 support

Nicolas Cannasse 17 years ago
parent
commit
9a6ee33d15
7 changed files with 72 additions and 21 deletions
  1. 1 0
      doc/CHANGES.txt
  2. 12 12
      genswf.ml
  3. 24 5
      genswf9.ml
  4. 2 2
      main.ml
  5. 24 2
      std/flash9/Vector.hx
  6. 8 0
      std/flash9/events/SampleDataEvent.hx
  7. 1 0
      std/haxe/ImportAll.hx

+ 1 - 0
doc/CHANGES.txt

@@ -42,6 +42,7 @@
 	fixed compiler bug with inline + optional arguments
 	fixed Type.createInstance and createEmptyInstance with Array for flash6-8
 	added "c".code for compiletime UTF8 charcodes
+	completed flash10 support
 
 2008-07-28: 2.0
 	fixed current package bug in inherited constructor type

+ 12 - 12
genswf.ml

@@ -157,7 +157,7 @@ let add_as3_clips ctx cl =
 	ctx.f9clips <- List.filter (fun c -> c.f9_cid <> None) cl @ ctx.f9clips
 
 let generate com swf_header swf_lib =
-	let ver = com.flash_version in
+	let isf9 = com.flash_version >= 9 in
 	let t = Common.timer "generate swf" in
 	let file , codeclip = (try let f , c = ExtString.String.split com.file "@" in f, Some c with _ -> com.file , None) in
 	let ctx = {
@@ -168,7 +168,7 @@ let generate com swf_header swf_lib =
 		code = [];
 		genmethod = (fun() -> assert false);
 	} in
-	if ver = 9 then begin
+	if isf9 then begin
 		let code, boot, m = Genswf9.generate com in
 		ctx.hx9code <- (match code with
 			| [i] when Array.length i.hls_fields = 0 ->
@@ -185,18 +185,18 @@ let generate com swf_header swf_lib =
 		ctx.f8clips <- List.map Ast.s_type_path clips;
 	end;
 	let build_swf content =
-		let sandbox = (if ver >= 8 then
+		let sandbox = (if com.flash_version >= 8 then
 				let net = Common.defined com "network-sandbox" in
-				[tag (TSandbox (match ver, net with
-					| 9, true -> SBUnknown 9
-					| 9, false -> SBUnknown 8
+				[tag (TSandbox (match isf9, net with
+					| true, true -> SBUnknown 9
+					| true, false -> SBUnknown 8
 					| _, true -> SBNetwork
 					| _, false -> SBLocal
 				))]
 			else
 				[]
 		) in
-		let debug = (if ver = 9 && Common.defined com "fdb" then [tag (TEnableDebugger2 (0,""))] else []) in
+		let debug = (if isf9 && Common.defined com "fdb" then [tag (TEnableDebugger2 (0,""))] else []) in
 		let base_id = ref 0x5000 in
 		let clips = List.fold_left (fun acc m ->
 			incr base_id;
@@ -224,7 +224,7 @@ let generate com swf_header swf_lib =
 				ctx.as3code <- build_movieclip ctx path :: ctx.as3code;
 		) ctx.f9clips;
 		let as3code = (match ctx.as3code @ ctx.hx9code with [] -> [] | l -> [tag (TActionScript3 (None,As3hlparse.flatten l))]) in
-		let clips9 = (if ver = 9 then [tag (TF9Classes ctx.f9clips)] else []) in
+		let clips9 = (if isf9 then [tag (TF9Classes ctx.f9clips)] else []) in
 		sandbox @ debug @ content @ clips @ code @ as3code @ clips9
 	in
 	let swf = (match swf_lib with
@@ -239,7 +239,7 @@ let generate com swf_header swf_lib =
 			let h, swf = (try Swf.parse ch with _ -> failwith ("The input swf " ^ file ^ " is corrupted")) in
 			let header , tagbg = (match swf_header with
 				| None ->
-					{ h with h_version = ver }, None
+					{ h with h_version = com.flash_version }, None
 				| Some h ->
 					let h , bg = convert_header com h in
 					let tagbg = tag (TSetBgColor { cr = bg lsr 16; cg = (bg lsr 8) land 0xFF; cb = bg land 0xFF }) in
@@ -265,7 +265,7 @@ let generate com swf_header swf_lib =
 				| TShowFrame ->
 					build_swf (List.rev acc) @ t :: l
 				| TExport el ->
-					if ver = 9 then begin
+					if isf9 then begin
 						List.iter (fun e ->
 							ctx.f9clips <- { f9_cid = Some e.exp_id; f9_classname = e.exp_name } :: ctx.f9clips
 						) el;
@@ -281,10 +281,10 @@ let generate com swf_header swf_lib =
 				| TSandbox _ ->
 					loop acc l
 				| TF9Classes cl ->
-					if ver = 9 then add_as3_clips ctx cl;
+					if isf9 then add_as3_clips ctx cl;
 					loop acc l
 				| TActionScript3 (_,data) ->
-					if ver = 9 then add_as3_code ctx data com.types;
+					if isf9 then add_as3_code ctx data com.types;
 					loop acc l
 				| _ ->
 					loop (t :: acc) l

+ 24 - 5
genswf9.ml

@@ -165,6 +165,7 @@ let type_path ctx path =
 		| ["flash"] , "FlashXml__" -> [] , "Xml"
 		| ["flash"] , "Boot" -> [] , ctx.boot
 		| ["flash"] , "Error" -> [], "Error"
+		| ["flash"] , "Vector" -> ["__AS3__";"vec"], "Vector"
 		| _ -> path
 	) in
 	HMPath (pack,name)
@@ -198,6 +199,8 @@ let rec type_id ctx t =
 		type_path ctx path
 	| TInst ({ cl_path = ["haxe"],"Int32" },_) ->
 		type_path ctx ([],"Int")
+	| TInst ({ cl_path = ["flash"],"Vector" } as c,pl) ->
+		HMParams (type_path ctx c.cl_path,List.map (type_id ctx) pl)
 	| TInst (c,_) ->
 		(match c.cl_kind with
 		| KTypeParameter ->
@@ -807,11 +810,27 @@ let rec gen_expr_content ctx retval e =
 	| TNew ({ cl_path = [],"Array" },_,[]) ->
 		(* it seems that [] is 4 time faster than new Array() *)
 		write ctx (HArray 0)
-	| TNew (c,_,pl) ->
-		let id = type_path ctx c.cl_path in
-		write ctx (HFindPropStrict id);
-		List.iter (gen_expr ctx true) pl;
-		write ctx (HConstructProperty (id,List.length pl))
+	| TNew (c,tl,pl) ->
+		let id = type_id ctx (TInst (c,tl)) in
+		(match id with 
+		| HMParams (t,tl) ->
+			let rec get_type t =
+				match t with
+				| HMParams (t,tl) ->
+					write ctx (HGetLex t);
+					List.iter get_type tl;
+					write ctx (HApplyType (List.length tl));
+				| _ ->
+					write ctx (HGetLex t)
+			in
+			get_type id;
+			List.iter (gen_expr ctx true) pl;
+			write ctx (HConstruct (List.length pl))
+		| _ ->
+			write ctx (HFindPropStrict id);
+			List.iter (gen_expr ctx true) pl;
+			write ctx (HConstructProperty (id,List.length pl))
+		);
 	| TFunction f ->
 		write ctx (HFunction (generate_function ctx f true))
 	| TIf (e0,e1,e2) ->

+ 2 - 2
main.ml

@@ -230,7 +230,7 @@ try
 		("-js",Arg.String (set_platform Js "js"),"<file> : compile code to JavaScript file");
 		("-as3",Arg.String (fun dir ->
 			set_platform Flash "flash" dir;
-			com.flash_version <- 9;
+			if com.flash_version < 9 then com.flash_version <- 9;
 			gen_as3 := true;
 			Common.define com "as3gen";
 			Common.define com "no_inline";
@@ -238,7 +238,7 @@ try
 		("-swf",Arg.String (set_platform Flash "flash"),"<file> : compile code to Flash SWF file");
 		("-swf9",Arg.String (fun file ->
 			set_platform Flash "flash" file;
-			com.flash_version <- 9;
+			if com.flash_version < 9 then com.flash_version <- 9;
 		),"<file> : compile code to Flash9 SWF file");
 		("-swf-version",Arg.Int (fun v ->			
 			com.flash_version <- v;

+ 24 - 2
std/flash9/Vector.hx

@@ -1,4 +1,26 @@
 package flash;
 
-class Vector<T> {
-}
+/**
+	The Vector class is very similar to Array but is only supported by the Flash Player 10+
+**/
+extern class Vector<T> implements ArrayAccess<T> {
+
+	var length : UInt;
+	var fixed : Bool;
+
+	function new( ?length : UInt, ?fixed : Bool ) : Void;
+	function concat( a : Vector<T> ) : Vector<T>;
+	function join( sep : String ) : String;
+	function pop() : Null<T>;
+	function push(x : T) : Int;
+	function reverse() : Void;
+	function shift() : Null<T>;
+	function unshift( x : T ) : Void;
+	function slice( pos : Int, ?end : Int ) : Vector<T>;
+	function sort( f : T -> T -> Int ) : Void;
+	function splice( pos : Int, len : Int ) : Vector<T>;
+	function toString() : String;
+
+	function iterator() : Iterator<T>;
+
+}

+ 8 - 0
std/flash9/events/SampleDataEvent.hx

@@ -0,0 +1,8 @@
+package flash.events;
+
+extern class SampleDataEvent extends Event {
+	var position : Float;
+	var data : flash.utils.ByteArray;
+    function new( ?type : String, ?bubbles : Bool, ?cancelable : Bool, ?position : Float, ?data : flash.utils.ByteArray ) : Void;
+    static var SAMPLE_DATA : String;
+}

+ 1 - 0
std/haxe/ImportAll.hx

@@ -457,6 +457,7 @@ import tools.hxinst.Main;
 
 import flash.Vector;
 
+import flash.events.SampleDataEvent;
 import flash.events.SamplesCallbackEvent;
 import flash.events.ShaderEvent;