Nicolas Cannasse 18 лет назад
Родитель
Сommit
d2a87d3eca
15 измененных файлов с 104 добавлено и 74 удалено
  1. 3 3
      std/Array.hx
  2. 1 1
      std/Hash.hx
  3. 1 1
      std/IntHash.hx
  4. 3 3
      std/Std.hx
  5. 8 0
      std/StdTypes.hx
  6. 1 1
      std/String.hx
  7. 1 1
      std/StringBuf.hx
  8. 2 2
      std/StringTools.hx
  9. 16 9
      std/Type.hx
  10. 27 23
      std/Xml.hx
  11. 22 16
      std/flash9/Boot.hx
  12. 15 7
      std/flash9/FlashXml__.hx
  13. 1 1
      std/flash9/Lib.hx
  14. 2 1
      std/haxe/Serializer.hx
  15. 1 5
      std/haxe/Unserializer.hx

+ 3 - 3
std/Array.hx

@@ -53,7 +53,7 @@ extern class Array<T> {
 	/**
 		Removes the last element of the array and returns it.
 	**/
-	function pop() : T;
+	function pop() : Null<T>;
 
 	/**
 		Adds the element [x] at the end of the array.
@@ -68,7 +68,7 @@ extern class Array<T> {
 	/**
 		Removes the first element and returns it.
 	**/
-	function shift() : T;
+	function shift() : Null<T>;
 
 	/**
 		Copies the range of the array starting at [pos] up to,
@@ -122,6 +122,6 @@ extern class Array<T> {
 	/**
 		Returns an iterator of the Array values.
 	**/
-	function iterator() : Iterator<T>;
+	function iterator() : Iterator<Null<T>>;
 
 }

+ 1 - 1
std/Hash.hx

@@ -69,7 +69,7 @@ class Hash<T> {
 	/**
 		Get a value for the given key.
 	**/
-	public function get( key : String ) : T {
+	public function get( key : String ) : Null<T> {
 		#if flash
 		return untyped h[key];
 		#else js

+ 1 - 1
std/IntHash.hx

@@ -66,7 +66,7 @@ class IntHash<T> {
 	/**
 		Get a value for the given key.
 	**/
-	public function get( key : Int ) : T {
+	public function get( key : Int ) : Null<T> {
 		#if flash
 		return untyped h[key];
 		#else js

+ 3 - 3
std/Std.hx

@@ -79,11 +79,11 @@ class Std {
 	/**
 		Convert a String to an Int, parsing different possible representations. Returns [null] if could not be parsed.
 	**/
-	public static function parseInt( x : String ) : Int {
+	public static function parseInt( x : String ) : Null<Int> {
 		untyped {
 		#if flash9
 		var v = __global__["parseInt"](x);
-		if( Math.isNaN(v) )
+		if( __global__["isNaN"](v) )
 			return null;
 		return v;
 		#else flash
@@ -137,7 +137,7 @@ class Std {
 	/**
 		Return the character code of the first character of the String, or null if the String is empty.
 	**/
-	public static function ord( x : String ) : Int {
+	public static function ord( x : String ) : Null<Int> {
 		#if flash
 		if( x == "" )
 			return null;

+ 8 - 0
std/StdTypes.hx

@@ -48,6 +48,14 @@ extern class Int extends Float { }
 typedef UInt = Int
 #end
 
+/**
+	[Null] can be useful in two cases. In order to document some methods
+	that accepts or can return a [null] value, or for the Flash9 compiler and AS3
+	generator to distinguish between base values that can be null and others that
+	can't.
+**/
+typedef Null<T> = T
+
 /**
 	The standard Boolean type is represented as an enum with two choices.
 **/

+ 1 - 1
std/String.hx

@@ -58,7 +58,7 @@ extern class String {
 		Returns the character code at the given position.
 		Returns [null] if outside of String bounds.
 	**/
-	function charCodeAt( index : Int) : Int;
+	function charCodeAt( index : Int) : Null<Int>;
 
 	/**
 		Returns the index of first occurence of [value]

+ 1 - 1
std/StringBuf.hx

@@ -58,7 +58,7 @@ class StringBuf {
 	/**
 		Adds a part of a string to the string buffer.
 	**/
-	public function addSub( s : String, pos : Int, ?len : Int ) {
+	public function addSub( s : String, pos : Int, ?len : Null<Int> ) {
 		#if neko
 		__add_sub(b,untyped s.__s,pos,len);
 		#else flash9

+ 2 - 2
std/StringTools.hx

@@ -260,11 +260,11 @@ class StringTools {
 		return out.toString();
 		#end
 	}
-	
+
 	/**
 		Encode a number into a hexadecimal representation, with an optional number of zeros for left padding.
 	**/
-	public static function hex( n : Int, ?digits : Int ) {
+	public static function hex( n : Int, ?digits : Null<Int> ) {
 		var s = "";
 		var hexChars = "0123456789ABCDEF";
 		do {

+ 16 - 9
std/Type.hx

@@ -42,8 +42,8 @@ class Type {
 		#end
 			return t;
 		} catch( e : Dynamic ) {
-			return null;
 		}
+		return null;
 	}
 
 	/**
@@ -60,8 +60,8 @@ class Type {
 		#end
 			return t;
 		} catch( e : Dynamic ) {
-			return null;
 		}
+		return null;
 	}
 
 	/**
@@ -137,7 +137,7 @@ class Type {
 			var cname = __global__["flash.utils.getQualifiedSuperclassName"](c);
 			if( cname == "Object" )
 				return null;
-			return __global__["flash.utils.getDefinitionByName"](cname);
+			return __as__(__global__["flash.utils.getDefinitionByName"](cname),Class);
 		#else true
 			return c.__super__;
 		#end
@@ -151,10 +151,7 @@ class Type {
 		if( c == null )
 			return null;
 		#if flash9
-			var name = untyped __global__["flash.utils.getQualifiedClassName"](c);
-			if( name == "flash::FlashXml__" )
-				return "Xml";
-			return name;
+			return untyped __global__["flash.utils.getQualifiedClassName"](c);
 		#else true
 			var a : Array<String> = untyped c.__name__;
 			return a.join(".");
@@ -183,7 +180,7 @@ class Type {
 		untyped {
 		#if flash9
 			try {
-				cl = __global__["flash.utils.getDefinitionByName"](name);
+				cl = __as__(__global__["flash.utils.getDefinitionByName"](name),Class);
 				if( cl.__isenum )
 					return null;
 				return cl; // skip test below
@@ -282,7 +279,16 @@ class Type {
 	**/
 	public static function createEmptyInstance<T>( cl : Class<T> ) : T untyped {
 		#if flash9
-			return cl.__construct__.call(null,null);
+			try {
+				flash.Boot.skip_constructor = true;
+				var i = cl.__construct__.call(null,[]);
+				flash.Boot.skip_constructor = false;
+				return i;
+			} catch( e : Dynamic ) {
+				flash.Boot.skip_constructor = false;
+				throw e;
+			}
+			return null;
 		#else flash
 			var o : Dynamic = __new__(_global["Object"]);
 			o.__proto__ = cl.prototype;
@@ -425,6 +431,7 @@ class Type {
 				return if( c == null ) TFunction else TClass(c);
 			}
 		}
+		return null;
 		#else (flash || js)
 		switch( #if flash __typeof__ #else true __js__("typeof") #end(v) ) {
 		#if flash

+ 27 - 23
std/Xml.hx

@@ -80,37 +80,37 @@ extern class Xml {
 
 	/**
 		Creates a node of the given type.
-	**/	
+	**/
 	static function createElement( name : String ) : Xml;
 
 	/**
 		Creates a node of the given type.
-	**/	
+	**/
 	static function createPCData( data : String ) : Xml;
-	
+
 	/**
 		Creates a node of the given type.
-	**/	
+	**/
 	static function createCData( data : String ) : Xml;
 
 	/**
 		Creates a node of the given type.
-	**/	
+	**/
 	static function createComment( data : String ) : Xml;
 
 	/**
 		Creates a node of the given type.
-	**/	
+	**/
 	static function createDocType( data : String ) : Xml;
 
 	/**
 		Creates a node of the given type.
-	**/	
+	**/
 	static function createProlog( data : String ) : Xml;
 
 	/**
 		Creates a node of the given type.
-	**/	
+	**/
 	static function createDocument() : Xml;
 
 	/**
@@ -145,22 +145,22 @@ extern class Xml {
 		Attributes are case-sensitive.
 	**/
 	function set( att : String, value : String ) : Void;
-	
+
 	/**
 		Removes an attribute for an Element node.
 		Attributes are case-sensitive.
-	**/	
+	**/
 	function remove( att : String ) : Void;
-	
+
 	/**
 		Tells if the Element node has a given attribute.
 		Attributes are case-sensitive.
-	**/	
+	**/
 	function exists( att : String ) : Bool;
-	
+
 	/**
 		Returns an [Iterator] on all the attributes values.
-	**/	
+	**/
 	function attributes() : Iterator<String>;
 
 	/**
@@ -179,15 +179,15 @@ extern class Xml {
 	/**
 		Returns an iterator of all child nodes which are Elements.
 		Only works if the current node is an Element or a Document.
-	**/	
+	**/
 	function elements() : Iterator<Xml>;
-	
+
 	/**
 		Returns an iterator of all child nodes which are Elements with the given nodeName.
 		Only works if the current node is an Element or a Document.
-	**/		
+	**/
 	function elementsNamed( name : String ) : Iterator<Xml>;
-	
+
 	/**
 		Returns the first child node.
 	**/
@@ -195,22 +195,22 @@ extern class Xml {
 
 	/**
 		Returns the first child node which is an Element.
-	**/	
+	**/
 	function firstElement() : Xml;
 
-	
+
 	/**
 		Adds a child node to the Document or Element.
 		One node can only be inside one given node which is indicated by the [parent] property.
-	**/	
+	**/
 	function addChild( x : Xml ) : Void;
 
 	/**
 		Removes a child from the Document or Element.
 		Returns true if the child was successfuly removed.
-	**/	
+	**/
 	function removeChild( x : Xml ) : Bool;
-	
+
 	/**
 		Inserts a child at the given position among the other childs.
 	**/
@@ -227,12 +227,16 @@ extern class Xml {
 		neko.Boot.__classes.Xml = Xml;
 		#else js
 		Xml = js.JsXml__;
+		#else flash9
+		var ref = flash.FlashXml__;
 		#else flash
 		Xml = flash.FlashXml__;
 		#else error
 		#end
 
+		#if !flash9
 		Xml.__name__ = ["Xml"];
+		#end
 		Xml.Element = "element";
 		Xml.PCData = "pcdata";
 		Xml.CData = "cdata";

+ 22 - 16
std/flash9/Boot.hx

@@ -3,16 +3,19 @@ package flash;
 class Boot extends flash.display.MovieClip {
 
 	#if (!flash9doc)
-	
+
 	static var init : Void -> Void;
 	static var tf : flash.text.TextField;
 	static var lines : Array<String>;
+	public static var skip_constructor = false;
 
-	function new() {
+	public function new(?mc:flash.display.MovieClip) {
 		super();
 		untyped {
 			var aproto = Array.prototype;
-			aproto.copy = aproto.slice;
+			aproto.copy = function() {
+				return this.slice();
+			};
 			aproto.insert = function(i,x) {
 				this.splice(i,0,x);
 			};
@@ -36,10 +39,12 @@ class Boot extends flash.display.MovieClip {
 					}
 				}
 			};
+			#if !as3gen
 			Bool = __global__["Boolean"];
 			Int = __global__["int"];
 			Float = __global__["Number"];
 			Dynamic = { toString : function(){ return "Dynamic"; } };
+			#end
 			var cca = String.prototype.charCodeAt;
 			String.prototype.charCodeAt = function(i) {
 				var x = cca.call(this,i);
@@ -49,37 +54,38 @@ class Boot extends flash.display.MovieClip {
 			};
 		}
 		lines = new Array();
-		flash.Lib.current = this;
-		init();
+		flash.Lib.current = if( mc == null ) this else mc;
+		if( init != null )
+			init();
 	}
 
-	static function enum_to_string( e ) {
+	public static function enum_to_string( e ) {
 		if( e.params == null )
 			return e.tag;
 		return e.tag+"("+e.params.join(",")+")";
 	}
 
-	static function __instanceof( v : Dynamic, t : Dynamic ) {
+	public static function __instanceof( v : Dynamic, t : Dynamic ) {
 		try {
 			if( t === untyped __global__["Dynamic"] )
 				return true;
 			return untyped __is__(v,t);
 		} catch( e : Dynamic ) {
-			return false;
 		}
+		return false;
 	}
 
-	static function __clear_trace() {
+	public static function __clear_trace() {
 		flash.Lib.current.removeChild(tf);
 		tf = null;
 		lines = new Array();
 	}
-	
-	static function __set_trace_color(rgb) {
+
+	public static function __set_trace_color(rgb) {
 		getTrace().textColor = rgb;
 	}
-	
-	static function getTrace() {
+
+	public static function getTrace() {
 		var mc = flash.Lib.current;
 		if( tf == null ) {
 			tf = new flash.text.TextField();
@@ -91,7 +97,7 @@ class Boot extends flash.display.MovieClip {
 		return tf;
 	}
 
-	static function __trace( v : Dynamic, pos : haxe.PosInfos ) {
+	public static function __trace( v : Dynamic, pos : haxe.PosInfos ) {
 		var tf = getTrace();
 		var pstr = if( pos == null ) "(null)" else pos.fileName+":"+pos.lineNumber;
 		lines = lines.concat((pstr +": "+__string_rec(v,"")).split("\n"));
@@ -103,7 +109,7 @@ class Boot extends flash.display.MovieClip {
 		}
 	}
 
-	static function __string_rec( v : Dynamic, str : String ) {
+	public static function __string_rec( v : Dynamic, str : String ) {
 		var cname = untyped __global__["flash.utils.getQualifiedClassName"](v);
 		switch( cname ) {
 		case "Object":
@@ -141,7 +147,7 @@ class Boot extends flash.display.MovieClip {
 		}
 		return new String(v);
 	}
-	
+
 	#end
 
 }

+ 15 - 7
std/flash9/FlashXml__.hx

@@ -41,6 +41,14 @@ class FlashXml__ {
 	static var edoctype_elt = ~/[\[|\]>]/;
 	static var ecomment_end = ~/-->/;
 
+	public static var Element : String;
+	public static var PCData : String;
+	public static var CData : String;
+	public static var Comment : String;
+	public static var DocType : String;
+	public static var Prolog : String;
+	public static var Document : String;
+
 	public var nodeType(default,null) : XmlType;
 	public var nodeName(getNodeName,setNodeName) : String;
 	public var nodeValue(getNodeValue,setNodeValue) : String;
@@ -152,7 +160,7 @@ class FlashXml__ {
 	private function new(){
 	}
 
-	static function createElement( name : String ) : FlashXml__ {
+	public static function createElement( name : String ) : FlashXml__ {
 		var r = new FlashXml__();
 		r.nodeType = Xml.Element;
 		r._children = new Array();
@@ -161,42 +169,42 @@ class FlashXml__ {
 		return r;
 	}
 
-	static function createPCData( data : String ) : FlashXml__ {
+	public static function createPCData( data : String ) : FlashXml__ {
 		var r = new FlashXml__();
 		r.nodeType = Xml.PCData;
 		r.setNodeValue( data );
 		return r;
 	}
 
-	static function createCData( data : String ) : FlashXml__ {
+	public static function createCData( data : String ) : FlashXml__ {
 		var r = new FlashXml__();
 		r.nodeType = Xml.CData;
 		r.setNodeValue( data );
 		return r;
 	}
 
-	static function createComment( data : String ) : FlashXml__ {
+	public static function createComment( data : String ) : FlashXml__ {
 		var r = new FlashXml__();
 		r.nodeType = Xml.Comment;
 		r.setNodeValue( data );
 		return r;
 	}
 
-	static function createDocType( data : String ) : FlashXml__ {
+	public static function createDocType( data : String ) : FlashXml__ {
 		var r = new FlashXml__();
 		r.nodeType = Xml.DocType;
 		r.setNodeValue( data );
 		return r;
 	}
 
-	static function createProlog( data : String ) : FlashXml__ {
+	public static function createProlog( data : String ) : FlashXml__ {
 		var r = new FlashXml__();
 		r.nodeType = Xml.Prolog;
 		r.setNodeValue( data );
 		return r;
 	}
 
-	static function createDocument() : FlashXml__ {
+	public static function createDocument() : FlashXml__ {
 		var r = new FlashXml__();
 		r.nodeType = Xml.Document;
 		r._children = new Array();

+ 1 - 1
std/flash9/Lib.hx

@@ -35,7 +35,7 @@ class Lib {
 	public static function eval( path : String ) : Dynamic {
 		var p = path.split(".");
 		var fields = new Array();
-		var o = null;
+		var o : Dynamic = null;
 		while( p.length > 0 ) {
 			try {
 				o = untyped __global__["flash.utils.getDefinitionByName"](p.join("."));

+ 2 - 1
std/haxe/Serializer.hx

@@ -218,8 +218,9 @@ class Serializer {
 					serialize(i);
 				buf.add("h");
 			case cast Date:
+				var d : Date = v;
 				buf.add("v");
-				buf.add(v.toString());
+				buf.add(d.toString());
 			case cast Hash:
 				buf.add("b");
 				for( k in v.keys() ) {

+ 1 - 5
std/haxe/Unserializer.hx

@@ -129,11 +129,7 @@ class Unserializer {
  				else
  					break;
  			}
- 			var s = buf.substr(p1,pos-p1);
- 			var f = Std.parseFloat(s);
- 			if( f == null )
- 				throw ("Invalid float "+s);
- 			return f;
+ 			return Std.parseFloat(buf.substr(p1,pos-p1));
 		case 121: // y
  			var len = readDigits();
  			if( buf.charAt(pos++) != ":" || length - pos < len )