Browse Source

Changes to the Std library required for cpp target

Hugh Sanderson 16 năm trước cách đây
mục cha
commit
c1345f87f1
13 tập tin đã thay đổi với 776 bổ sung12 xóa
  1. 4 0
      std/Array.hx
  2. 107 0
      std/Date.hx
  3. 30 10
      std/EReg.hx
  4. 22 0
      std/Hash.hx
  5. 16 0
      std/IntHash.hx
  6. 18 1
      std/Reflect.hx
  7. 13 0
      std/Std.hx
  8. 4 0
      std/StringTools.hx
  9. 58 1
      std/Type.hx
  10. 79 0
      std/Xml.hx
  11. 369 0
      std/cpp/CppXml__.hx
  12. 54 0
      std/cpp/Lib.hx
  13. 2 0
      std/haxe/Log.hx

+ 4 - 0
std/Array.hx

@@ -38,7 +38,11 @@ extern class Array<T> {
 	/**
 		Creates a new Array.
 	**/
+	#if (cpp)
+	function new(length:Int = 0, fixed:Bool = false) : Void;
+	#else
 	function new() : Void;
+	#end
 
 	/**
 		Returns a new Array by appending [a] to [this].

+ 107 - 0
std/Date.hx

@@ -27,6 +27,8 @@
 	The Date class is used for date manipulation. There is some extra functions
 	available in the [DateTools] class.
 **/
+
+#if !cpp
 extern class Date
 {
 	/**
@@ -183,3 +185,108 @@ extern class Date
 	}
 #end
 }
+#else // cpp ....
+class Date
+{
+	var mSeconds:Float;
+
+	/**
+		Creates a new date object.
+	**/
+	public function new(year : Int, month : Int, day : Int, hour : Int, min : Int, sec : Int ) : Void {
+		mSeconds = untyped __global__.__hxcpp_new_date(year,month,day,hour,min,sec);
+	}
+
+	/**
+		Returns the timestamp of the date. It's the number of milliseconds
+		elapsed since 1st January 1970. It might only have a per-second precision
+		depending on the platforms.
+	**/
+	public function getTime() : Float {
+		return mSeconds;
+	}
+
+	/**
+		Returns the hours value of the date (0-23 range).
+	**/
+	public function getHours() : Int { return untyped __global__.__hxcpp_get_hours(mSeconds); }
+
+	/**
+		Returns the minutes value of the date (0-59 range).
+	**/
+	public function getMinutes() : Int { return untyped __global__.__hxcpp_get_minutes(mSeconds); }
+
+	/**
+		Returns the seconds of the date (0-59 range).
+	**/
+	public function getSeconds() : Int { return untyped __global__.__hxcpp_get_seconds(mSeconds); }
+
+	/**
+		Returns the full year of the date.
+	**/
+	public function getFullYear() : Int { return untyped __global__.__hxcpp_get_year(mSeconds); }
+
+	/**
+		Returns the month of the date (0-11 range).
+	**/
+	public function getMonth() : Int { return untyped __global__.__hxcpp_get_month(mSeconds); }
+
+	/**
+		Returns the day of the date (1-31 range).
+	**/
+	public function getDate() : Int { return untyped __global__.__hxcpp_get_date(mSeconds); }
+
+	/**
+		Returns the week day of the date (0-6 range).
+	**/
+	public function getDay() : Int { return untyped __global__.__hxcpp_get_day(mSeconds); }
+
+	/**
+		Returns a string representation for the Date, by using the
+		standard format [YYYY-MM-DD HH:MM:SS]. See [DateTools.format] for
+		other formating rules.
+	**/
+	public function toString():String { return untyped __global__.__hxcpp_to_string(mSeconds); }
+
+	/**
+		Returns a Date representing the current local time.
+	**/
+	public static function now() : Date { return fromTime( untyped __global__.__hxcpp_date_now()); }
+
+	/**
+		Returns a Date from a timestamp [t] which is the number of
+		milliseconds elapsed since 1st January 1970.
+	**/
+	public static function fromTime( t : Float ) : Date {
+		var result = new Date(0,0,0,0,0,0);
+		result.mSeconds = t;
+		return result;
+	}
+
+	/**
+		Returns a Date from a formated string of one of the following formats :
+		[YYYY-MM-DD hh:mm:ss] or [YYYY-MM-DD] or [hh:mm:ss]. The first two formats
+		are expressed in local time, the third in UTC Epoch.
+	**/
+	public static function fromString( s : String ) : Date {
+		switch( s.length ) {
+			case 8: // hh:mm:ss
+				var k = s.split(":");
+				var d : Date = new Date(0,0,0,Std.parseInt(k[0]),Std.parseInt(k[1]),Std.parseInt(k[2]));
+				return d;
+			case 10: // YYYY-MM-DD
+				var k = s.split("-");
+				return new Date(Std.parseInt(k[0]),Std.parseInt(k[1])-1,Std.parseInt(k[2]),0,0,0);
+			case 19: // YYYY-MM-DD hh:mm:ss
+				var k = s.split(" ");
+				var y = k[0].split("-");
+				var t = k[1].split(":");
+				return new Date(Std.parseInt(y[0]),Std.parseInt(y[1]) - 1,Std.parseInt(y[2]),
+					Std.parseInt(t[0]),Std.parseInt(t[1]),Std.parseInt(t[2]));
+			default:
+				throw "Invalid date format : " + s;
+		}
+		return null;
+	}
+}
+#end

+ 30 - 10
std/EReg.hx

@@ -34,7 +34,7 @@ class EReg {
 	#if flash9
 	var result : {> Array<String>, index : Int, input : String };
 	#end
-	#if (neko || php)
+	#if (neko || php || cpp)
 	var last : String;
 	var global : Bool;
 	#end
@@ -50,12 +50,16 @@ class EReg {
 		options [opt].
 	**/
 	public function new( r : String, opt : String ) {
-		#if neko
+		#if (neko||cpp)
 			var a = opt.split("g");
 			global = a.length > 1;
 			if( global )
 				opt = a.join("");
+         #if neko
 			this.r = regexp_new_options(untyped r.__s, untyped opt.__s);
+         #else
+			this.r = regexp_new_options(r, opt);
+         #end
 		#elseif js
 			opt = opt.split("u").join(""); // 'u' (utf8) depends on page encoding
 			this.r = untyped __new__("RegExp",r,opt);
@@ -79,8 +83,12 @@ class EReg {
 		Updates the internal state accordingly.
 	**/
 	public function match( s : String ) : Bool {
-		#if neko
-			var p = regexp_match(r,untyped s.__s,0,s.length);
+		#if (neko || cpp)
+			#if neko
+				var p = regexp_match(r,untyped s.__s,0,s.length);
+			#else
+				var p = regexp_match(r,s,0,s.length);
+			#end
 			if( p )
 				last = s;
 			else
@@ -118,6 +126,9 @@ class EReg {
 		#if neko
 			var m = regexp_matched(r,n);
 			return (m == null) ? null : new String(m);
+		#elseif cpp
+			var m = regexp_matched(r,n);
+			return m;
 		#elseif js
 			return untyped if( r.m != null && n >= 0 && n < r.m.length ) r.m[n] else throw "EReg::matched";
 		#elseif flash9
@@ -139,7 +150,7 @@ class EReg {
 		of the matched substring.
 	**/
 	public function matchedLeft() : String {
-		#if neko
+		#if (neko || cpp)
 			var p = regexp_matched_pos(r,0);
 			return last.substr(0,p.pos);
 		#elseif js
@@ -165,7 +176,7 @@ class EReg {
 		of the matched substring.
 	**/
 	public function matchedRight() : String {
-		#if neko
+		#if (neko||cpp)
 			var p = regexp_matched_pos(r,0);
 			var sz = p.pos+p.len;
 			return last.substr(sz,last.length-sz);
@@ -197,7 +208,7 @@ class EReg {
 		original matched string.
 	**/
 	public function matchedPos() : { pos : Int, len : Int } {
-		#if neko
+		#if (neko||cpp)
 			return regexp_matched_pos(r,0);
 		#elseif js
 			if( untyped r.m == null ) throw "No string matched";
@@ -217,13 +228,17 @@ class EReg {
 		the separators.
 	**/
 	public function split( s : String ) : Array<String> {
-		#if neko
+		#if (neko||cpp)
 			var pos = 0;
 			var len = s.length;
 			var a = new Array();
 			var first = true;
 			do {
-				if( !regexp_match(r,untyped s.__s,pos,len) )
+				#if neko
+					if( !regexp_match(r,untyped s.__s,pos,len) )
+				#else
+					if( !regexp_match(r,s,pos,len) )
+				#end
 					break;
 				var p = regexp_matched_pos(r,0);
 				if( p.len == 0 && !first ) {
@@ -256,7 +271,7 @@ class EReg {
 		while replacing. [$$] means the [$] character.
 	**/
 	public function replace( s : String, by : String ) : String {
-		#if neko
+		#if (neko||cpp)
 			var b = new StringBuf();
 			var pos = 0;
 			var len = s.length;
@@ -339,6 +354,11 @@ class EReg {
 	static var regexp_match = neko.Lib.load("regexp","regexp_match",4);
 	static var regexp_matched = neko.Lib.load("regexp","regexp_matched",2);
 	static var regexp_matched_pos : Dynamic -> Int -> { pos : Int, len : Int } = neko.Lib.load("regexp","regexp_matched_pos",2);
+#elseif cpp
+	static var regexp_new_options = cpp.Lib.load("regexp","regexp_new_options",2);
+	static var regexp_match = cpp.Lib.load("regexp","regexp_match",4);
+	static var regexp_matched = cpp.Lib.load("regexp","regexp_matched",2);
+	static var regexp_matched_pos : Dynamic -> Int -> { pos : Int, len : Int } = cpp.Lib.load("regexp","regexp_matched_pos",2);
 #end
 
 }

+ 22 - 0
std/Hash.hx

@@ -50,6 +50,8 @@ class Hash<T> {
 				__js__("delete")(h.__proto__);
 			}
 		}
+		#elseif cpp
+		h = {};
 		#elseif php
 		h = untyped __call__('array');
 		#end
@@ -65,6 +67,8 @@ class Hash<T> {
 		untyped h["$"+key] = value;
 		#elseif neko
 		untyped __dollar__hset(h,key.__s,value,null);
+		#elseif cpp
+		untyped h.__SetField(key,value);
 		#elseif php
 		untyped h[key] = value;
 		#end
@@ -80,6 +84,8 @@ class Hash<T> {
 		return untyped h["$"+key];
 		#elseif neko
 		return untyped __dollar__hget(h,key.__s,null);
+		#elseif cpp
+		return untyped h.__Field(key);
 		#elseif php
 		untyped __php__("if(!isset($this->h[$key])) return null");
 		return untyped h[key];
@@ -111,6 +117,8 @@ class Hash<T> {
 		}
 		#elseif neko
 		return untyped __dollar__hmem(h,key.__s,null);
+		#elseif cpp
+		return untyped h.__Field(key)!=null;
 		#elseif php
 		return untyped __call__("isset", h[key]);
 		#else
@@ -140,6 +148,8 @@ class Hash<T> {
 		return true;
 		#elseif neko
 		return untyped __dollar__hremove(h,key.__s,null);
+		#elseif cpp
+		return untyped __global__.__hx_anon_remove(h,key);
 		#elseif php
 		if(!untyped __call__("isset", h[key])) return false;
 		untyped __call__("unset", h[key]);
@@ -168,6 +178,10 @@ class Hash<T> {
 		var l = new List<String>();
 		untyped __dollar__hiter(h,function(k,_) { l.push(new String(k)); });
 		return l.iterator();
+		#elseif cpp
+		var a:Array<String> = [];
+		untyped h.__GetFields(a);
+		return a.iterator();
 		#elseif php
 		return untyped __call__("new _hx_array_iterator", __call__("array_keys", h));
 		#else
@@ -204,6 +218,14 @@ class Hash<T> {
 		var l = new List<T>();
 		untyped __dollar__hiter(h,function(_,v) { l.push(v); });
 		return l.iterator();
+		#elseif cpp
+		var a:Array<String> = [];
+		untyped h.__GetFields(a);
+		var it = a.iterator();
+		return untyped {
+			hasNext : function() { return it.hasNext(); },
+			next : function() { return  untyped h.__Field(it.next()); }
+		};
 		#elseif php
 		return untyped __call__("new _hx_array_iterator", __call__("array_values", h));
 		#else

+ 16 - 0
std/IntHash.hx

@@ -49,6 +49,8 @@ class IntHash<T> {
 		};
 		#elseif php
 		h = untyped __call__('array');
+		#elseif cpp
+		h = untyped __global__.CreateIntHash();
 		#end
 	}
 
@@ -62,6 +64,8 @@ class IntHash<T> {
 		untyped h[key] = value;
 		#elseif neko
 		untyped __dollar__hset(h,key,value,null);
+		#elseif cpp
+		untyped __global__.__int_hash_set(h,key,value);
 		#end
 	}
 
@@ -78,6 +82,8 @@ class IntHash<T> {
 		#elseif php
 		untyped __php__("if(!isset($this->h[$key])) return null");
 		return untyped h[key];
+		#elseif cpp
+		return untyped __global__.__int_hash_get(h,key);
 		#else
 		return null;
 		#end
@@ -99,6 +105,8 @@ class IntHash<T> {
 		return untyped __dollar__hmem(h,key,null);
 		#elseif php
 		return untyped __call__("isset", h[key]);
+		#elseif cpp
+		return untyped __global__.__int_hash_exists(h,key);
 		#else
 		return false;
 		#end
@@ -127,6 +135,8 @@ class IntHash<T> {
 		if(!untyped __call__("isset", h[key])) return false;
 		untyped __call__("unset", h[key]);
 		return true;
+		#elseif cpp
+		return untyped __global__.__int_hash_remove(h,key);
 		#else
 		return false;
 		#end
@@ -156,6 +166,9 @@ class IntHash<T> {
 		return l.iterator();
 		#elseif php
 		return untyped __call__("new _hx_array_iterator", __call__("array_keys", h));
+		#elseif cpp
+		var a:Array<Int> = untyped __global__.__int_hash_keys(h);
+		return a.iterator();
 		#else
 		return null;
 		#end
@@ -192,6 +205,9 @@ class IntHash<T> {
 		return l.iterator();
 		#elseif php
 		return untyped __call__("new _hx_array_iterator", __call__("array_values", h));
+		#elseif cpp
+		var a:Array<Dynamic> = untyped __global__.__int_hash_values(h);
+		return a.iterator();
 		#else
 		return null;
 		#end

+ 18 - 1
std/Reflect.hx

@@ -46,6 +46,8 @@ class Reflect {
 			return false;
 		#elseif neko
 			return __dollar__typeof(o) == __dollar__tobject && __dollar__objfield(o,__dollar__hash(field.__s));
+		#elseif cpp
+			return o!=null && o.__HasField(field);
 		#elseif php
 			return __call__("_hx_has_field", o, field);
 		#else
@@ -61,6 +63,8 @@ class Reflect {
 			return (o == null) ? null : o[field];
 		#elseif flash
 			return o[field];
+		#elseif cpp
+			return o.__Field(field);
 		#elseif js
 			var v = null;
 			try {
@@ -85,6 +89,8 @@ class Reflect {
 			o[field] = value;
 		#elseif js
 			o[field] = value;
+		#elseif cpp
+			o.__SetField(field,value);
 		#elseif neko
 			if( __dollar__typeof(o) == __dollar__tobject )
 				__dollar__objset(o,__dollar__hash(field.__s),value);
@@ -96,7 +102,7 @@ class Reflect {
 	/**
 		Call a method with the given object and arguments.
 	**/
-	public #if !php inline #end static function callMethod( o : Dynamic, func : Dynamic, args : Array<Dynamic> ) : Dynamic untyped {
+	public #if !(php||cpp) inline #end static function callMethod( o : Dynamic, func : Dynamic, args : Array<Dynamic> ) : Dynamic untyped {
 		#if flash9
 			return func.apply(o,args);
 		#elseif flash
@@ -112,6 +118,9 @@ class Reflect {
 				else return __call__("call_user_func", field(o, func), args[0], args[1]);
 			}
 			return __php__("call_user_func_array(is_callable($func) ? $func : array($o, $func) , $args == null ? array() : $args->__a)");
+		#elseif cpp
+         var s:String = func;
+         return untyped o.__Field(s).__Run(args);
 		#else
 			return null;
 		#end
@@ -164,6 +173,10 @@ class Reflect {
 					o.__proto__ = t;
 			}
 			return a;
+		#elseif cpp
+			var a : Array<String> = [];
+			o.__GetFields(a);
+			return a;
 		#elseif neko
 			if( __dollar__typeof(o) != __dollar__tobject )
 				return new Array<String>();
@@ -202,6 +215,8 @@ class Reflect {
 			return __dollar__typeof(f) == __dollar__tfunction;
 		#elseif php
 			return __php__("(is_array($f) && is_callable($f)) || _hx_is_lambda($f)") || (__php__("is_array($f)") && hasField(__php__("$f[0]"), __php__("$f[1]")) && __php__("$f[1]") != "length");
+		#elseif cpp
+			return f!=null && f.__GetType() ==  __global__.vtFunction;
 		#else
 			return false;
 		#end
@@ -243,6 +258,8 @@ class Reflect {
 			if(untyped __call__("is_string", f1) && untyped __call__("is_string", f2))
 				return f1 == f2;
 			return false;
+		#elseif cpp
+			return untyped __global__.__hxcpp_same_closure(f1,f2);
 		#else
 			return false;
 		#end

+ 13 - 0
std/Std.hx

@@ -41,6 +41,8 @@ class Std {
 		js.Boot.__instanceof(v,t);
 		#elseif php
 		untyped __call__("_hx_instanceof", v,t);
+		#elseif cpp
+		t!=null && (t==Dynamic) || (v!=null && v.__IsClass(t));
 		#else
 		false;
 		#end
@@ -59,6 +61,8 @@ class Std {
 		js.Boot.__string_rec(s,"");
 		#elseif php
 		__call__("_hx_string_rec", s, '');
+		#elseif cpp
+		s==null ? "null" : s.__ToString();
 		#else
 		"";
 		#end
@@ -110,6 +114,9 @@ class Std {
 		#elseif php
 		if(!__php__("is_numeric")(x)) return null;
 		return x.substr(0, 2).toLowerCase() == "0x" ? __php__("intval(substr($x, 2), 16)") : __php__("intval($x)");
+		#elseif cpp
+		if (x==null) return null;
+		return __global__.ParseInt(x);
 		#else
 		return 0;
 		#end
@@ -131,6 +138,8 @@ class Std {
 		__js__("parseFloat")(x);
 		#elseif php
 		__php__("is_numeric($x) ? floatval($x) : acos(1.01)");
+		#elseif cpp
+		__global__.ParseFloat(x.__s);
 		#else
 		0;
 		#end
@@ -151,6 +160,8 @@ class Std {
 		Math.floor(Math.random()*x);
 		#elseif php
 		__call__("rand", 0, x-1);
+		#elseif cpp
+		__global__.rand() % x;
 		#else
 		0;
 		#end
@@ -173,6 +184,8 @@ class Std {
 			Class = { __name__ : ["Class"] };
 			Enum = {};
 			Void = { __ename__ : ["Void"] };
+		#elseif cpp
+			null;
 		#elseif flash9
 			null;
 		#elseif flash

+ 4 - 0
std/StringTools.hx

@@ -46,6 +46,8 @@ class StringTools {
 			return encodeURIComponent(s);
 		#elseif php
 			return __call__("rawurlencode", s);
+		#elseif cpp
+			return s.__URLEncode();
 		#else
 			return null;
 		#end
@@ -65,6 +67,8 @@ class StringTools {
 			return decodeURIComponent(s.split("+").join(" "));
 		#elseif php
 			return __call__("urldecode", s);
+		#elseif cpp
+			return s.__URLDecode();
 		#else
 			return null;
 		#end

+ 58 - 1
std/Type.hx

@@ -66,6 +66,8 @@ class Type {
 				return null;
 			else
 				return __call__("_hx_ttype", c);
+		#elseif cpp
+			return untyped o.__GetClass();
 		#else
 			return null;
 		#end
@@ -101,6 +103,10 @@ class Type {
 				return null;
 			else
 				return __php__("_hx_ttype(get_class($o))");
+		#elseif cpp
+			if(!o.__IsEnum())
+				return null;
+			return o;
 		#else
 			return null;
 		#end
@@ -122,6 +128,8 @@ class Type {
 				return null;
 			else
 				return __call__("_hx_ttype", s);
+		#elseif cpp
+			return c.GetSuper();
 		#else
 			return c.__super__;
 		#end
@@ -145,6 +153,8 @@ class Type {
 			return str.split("::").join(".");
 		#elseif php
 			return untyped c.__qname__;
+		#elseif cpp
+			return untyped c.mName;
 		#else
 			var a : Array<String> = untyped c.__name__;
 			return a.join(".");
@@ -158,7 +168,9 @@ class Type {
 		#if flash9
 			return getClassName(cast e);
 		#elseif php
-		  return untyped e.__qname__;
+			return untyped e.__qname__;
+		#elseif (cpp)
+			return untyped e.__ToString();
 		#else
 			var a : Array<String> = untyped e.__ename__;
 			return a.join(".");
@@ -176,6 +188,8 @@ class Type {
 				return c;
 			else
 				return null;
+		#elseif cpp
+			return untyped Class.Resolve(name);
 		#else
 			var cl : Class<Dynamic>;
 		#if flash9
@@ -229,6 +243,8 @@ class Type {
 				return e;
 			else
 				return null;
+		#elseif cpp
+			return untyped Class.Resolve(name);
 		#else
 			var e : Dynamic;
 		#if flash9
@@ -303,6 +319,10 @@ class Type {
 			var c = cl.__rfl__();
 			if(c == null) return null;
 			return __php__("$inst = $c->getConstructor() ? $c->newInstanceArgs($args->__a) : $c->newInstanceArgs()");
+		#elseif cpp
+			if (cl!=null)
+				return cl.mConstructArgs(args);
+			return null;
 		#else
 			return null;
 		#end
@@ -358,6 +378,8 @@ class Type {
 				throw "Unable to instantiate " + Std.string(cl);
 			}
 			return null;
+		#elseif cpp
+			return cl.mConstructEmpty();
 		#else
 			return null;
 		#end
@@ -367,6 +389,11 @@ class Type {
 		Create an instance of an enum by using a constructor name and parameters.
 	**/
 	public static function createEnum( e : Enum, constr : String, ?params : Array<Dynamic> ) : Dynamic {
+		#if cpp
+		if (untyped e.mConstructEnum != null)
+			return untyped e.mConstructEnum(constr,params);
+		return null;
+		#else
 		var f = Reflect.field(e,constr);
 		if( f == null ) throw "No such constructor "+constr;
 		if( Reflect.isFunction(f) ) {
@@ -376,6 +403,7 @@ class Type {
 		if( params != null && params.length != 0 )
 			throw "Constructor "+constr+" does not need parameters";
 		return f;
+		#end
 	}
 
 	#if flash9
@@ -418,7 +446,10 @@ class Type {
 				if(!$p->isStatic()) $r[] = $p->getName();
 			");
 			return untyped __php__("new _hx_array(array_values(array_unique($r)))");
+		#elseif cpp
+			return untyped c.GetInstanceFields();
 		#else
+
 			var a = Reflect.fields(untyped c.prototype);
 			#if js
 				a.remove("__class__");
@@ -464,6 +495,8 @@ class Type {
 				if($p->isStatic()) $r[] = $p->getName();
 			");
 			return untyped __php__("new _hx_array($r)");
+		#elseif cpp
+			return untyped c.GetClassFields();
 		#else
 			var a = Reflect.fields(c);
 			a.remove(__unprotect__("__name__"));
@@ -495,6 +528,8 @@ class Type {
 			sps = rfl.getMethods();
 			__php__("foreach($sps as $m) { $n = $m->getName(); if($n != '__construct' && $n != '__toString') $r[] = $n; }");
 			return __php__("new _hx_array($r)");
+		#elseif cpp
+			return untyped e.GetClassFields();
 		#else
 			return untyped e.__constructs__;
 		#end
@@ -604,6 +639,20 @@ class Type {
 			if(__php__("$c instanceof _hx_enum"))  return TEnum(cast c);
 			if(__php__("$c instanceof _hx_class")) return TClass(cast c);
 			return TUnknown;
+		#elseif cpp
+			if (v==null) return TNull;
+			var t:Int = untyped v.__GetType();
+			switch(t)
+			{
+				case untyped __global__.vtBool : return TBool;
+				case untyped __global__.vtInt : return TInt;
+				case untyped __global__.vtFloat : return TFloat;
+				case untyped __global__.vtFunction : return TFunction;
+				case untyped __global__.vtObject : return TObject;
+				case untyped __global__.vtEnum : return TEnum(v.__GetClass());
+				default:
+					return untyped TClass(v.__GetClass());
+			}
 		#else
 			return TUnknown;
 		#end
@@ -651,6 +700,8 @@ class Type {
 			} catch( e : Dynamic ) {
 				return false;
 			}
+		#elseif cpp
+			return a==b;
 		#else
 			if( a[0] != b[0] )
 				return false;
@@ -672,6 +723,8 @@ class Type {
 			return new String(e.tag);
 		#elseif (flash9 || php)
 			return e.tag;
+		#elseif cpp
+			return e.__Tag();
 		#else
 			return e[0];
 		#end
@@ -685,6 +738,8 @@ class Type {
 			return if( e.args == null ) [] else untyped Array.new1(e.args,__dollar__asize(e.args));
 		#elseif flash9
 			return if( e.params == null ) [] else e.params;
+		#elseif cpp
+			return untyped e.__EnumParams();
 		#elseif php
 			if(e.params == null)
 				return [];
@@ -701,6 +756,8 @@ class Type {
 	public inline static function enumIndex( e : Dynamic ) : Int {
 		#if (neko || flash9 || php)
 			return e.index;
+		#elseif cpp
+			return e.__Index();
 		#else
 			return e[1];
 		#end

+ 79 - 0
std/Xml.hx

@@ -29,13 +29,20 @@
 	use [Std.string(t)] to get a string reprensation
 	of the type.
 **/
+#if !cpp
 enum XmlType {
 }
+#else
+typedef XmlType = String;
+#end
 
 /**
 	The standard Xml class and parsing.
 	More API to manipulate XML are available in the [haxe.xml] package.
 **/
+#if !cpp
+
+
 extern class Xml {
 
 	/**
@@ -249,3 +256,75 @@ extern class Xml {
 	}
 #end
 }
+
+#else
+class Xml {
+	public static var Element(default,null) : XmlType;
+	public static var PCData(default,null) : XmlType;
+	public static var CData(default,null) : XmlType;
+	public static var Comment(default,null) : XmlType;
+	public static var DocType(default,null) : XmlType;
+	public static var Prolog(default,null) : XmlType;
+	public static var Document(default,null) : XmlType;
+	public static function parse( s : String ) : Xml {
+		return cpp.CppXml__.parse(s);
+	}
+	public static function createElement( name : String ) : Xml {
+		return cpp.CppXml__.createElement(name);
+	}
+	public static function createPCData( data : String ) : Xml {
+		return cpp.CppXml__.createPCData(data);
+	}
+	public static function createCData( data : String ) : Xml {
+		return cpp.CppXml__.createCData(data);
+	}
+	public static function createComment( data : String ) : Xml {
+		return cpp.CppXml__.createComment(data);
+	}
+	public static function createDocType( data : String ) : Xml {
+		return cpp.CppXml__.createDocType(data);
+	}
+	public static function createProlog( data : String ) : Xml {
+		return cpp.CppXml__.createProlog(data);
+	}
+	public static function createDocument() : Xml { return null; }
+	public var nodeType(default,null) : XmlType;
+	public var nodeName(getNodeName,setNodeName) : String;
+	private function getNodeName() : String { return null; }
+	private function setNodeName( name : String ) : String { return null; }
+	public var nodeValue(getNodeValue,setNodeValue) : String;
+	private function getNodeValue() : String { return null; }
+	private function setNodeValue( name : String ) : String { return null; }
+	public function get( att : String ) : String { return null; }
+	public function set( att : String, value : String ) : Void { }
+	public function remove( att : String ) : Void { }
+	public function exists( att : String ) : Bool { return false; }
+	public function attributes() : Iterator<String> { return null; }
+	var parent(getParent,null) : Xml;
+	private function getParent() : Xml { return null; }
+	public function iterator() : Iterator<Xml> { return null; }
+	public function elements() : Iterator<Xml> { return null; }
+	public function elementsNamed( name : String ) : Iterator<Xml> { return null; }
+	public function firstChild() : Xml { return null; }
+	public function firstElement() : Xml { return null; }
+	public function addChild( x : Xml ) : Void { }
+	public function removeChild( x : Xml ) : Bool { return null; }
+	public function insertChild( x : Xml, pos : Int ) : Void { }
+	public function toString() : String { return null; }
+	
+	static function __init__() : Void untyped {
+		Xml.Element = "element";
+		Xml.PCData = "pcdata";
+		Xml.CData = "cdata";
+		Xml.Comment = "comment";
+		Xml.DocType = "doctype";
+		Xml.Prolog = "prolog";
+		Xml.Document = "document";
+	}
+}
+
+#end
+
+
+
+

+ 369 - 0
std/cpp/CppXml__.hx

@@ -0,0 +1,369 @@
+/*
+ * Copyright (c) 2005, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+package cpp;
+import Xml;
+
+class CppXml__ extends Xml {
+
+	static var __name__ = ["Xml"];
+
+	private var _nodeName : String;
+	private var _nodeValue : String;
+	private var _attributes : Dynamic<String>;
+	private var _children : Array<Dynamic>;
+	private var _parent : CppXml__;
+
+	private function new() {
+	}
+
+	private static var _parse = cpp.Lib.load("std","parse_xml",2);
+
+	public static function parse( xmlData : String ) : CppXml__ {
+		var x = new CppXml__();
+		x._children = new Array();
+		var parser = {
+			cur : x,
+			xml : function(name,att) {
+				var x : Dynamic = new CppXml__();
+				x._parent = untyped this.cur;
+				x.nodeType = Xml.Element;
+				x._nodeName = new String(name);
+				x._attributes = att;
+				x._children = new Array();
+				untyped {
+					var i = 0;
+					this.cur.addChild(x);
+					this.cur = x;
+				}
+			},
+			cdata : function(text) {
+				var x = new CppXml__();
+				x._parent = untyped this.cur;
+				x.nodeType = Xml.CData;
+				x._nodeValue = new String(text);
+				untyped this.cur.addChild(x);
+			},
+			pcdata : function(text) {
+				var x = new CppXml__();
+				x._parent = untyped this.cur;
+				x.nodeType = Xml.PCData;
+				x._nodeValue = new String(text);
+				untyped this.cur.addChild(x);
+			},
+			comment : function(text:String) {
+				var x = new CppXml__();
+				x._parent = untyped this.cur;
+				if( untyped text.cca(0) == 63 ) {
+					x.nodeType = Xml.Prolog;
+					text = "<"+new String(text)+">";
+				} else {
+					x.nodeType = Xml.Comment;
+					text = "<!--"+new String(text)+"-->";
+				}
+				x._nodeValue = text;
+				untyped this.cur.addChild(x);
+			},
+			doctype : function(text) {
+				var x = new CppXml__();
+				x._parent = untyped this.cur;
+				x.nodeType = Xml.DocType;
+				x._nodeValue = "<!DOCTYPE"+new String(text)+">";
+				untyped this.cur.addChild(x);
+			},
+			done : function() {
+				untyped this.cur = this.cur._parent;
+			}
+		};
+		untyped _parse(xmlData.__s,parser);
+		x.nodeType = Xml.Document;
+		return x;
+	}
+
+
+	public static function createElement( name : String ) : CppXml__ {
+		var r = new CppXml__();
+		r.nodeType = Xml.Element;
+		r._nodeName = name;
+		r._attributes = null;
+		r._children = new Array();
+		return r;
+	}
+
+	public static function createPCData( data : String ) : CppXml__ {
+		var r = new CppXml__();
+		r.nodeType = Xml.PCData;
+		r._nodeValue = data;
+		return r;
+	}
+
+	public static function createCData( data : String ) : CppXml__ {
+		var r = new CppXml__();
+		r.nodeType = Xml.CData;
+		r._nodeValue = data;
+		return r;
+	}
+
+	public static function createComment( data : String ) : CppXml__ {
+		var r = new CppXml__();
+		r.nodeType = Xml.Comment;
+		r._nodeValue = data;
+		return r;
+	}
+
+	public static function createDocType( data : String ) : CppXml__ {
+		var r = new CppXml__();
+		r.nodeType = Xml.DocType;
+		r._nodeValue = data;
+		return r;
+	}
+
+	public static function createProlog( data : String ) : CppXml__ {
+		var r = new CppXml__();
+		r.nodeType = Xml.Prolog;
+		r._nodeValue = data;
+		return r;
+	}
+
+	public static function createDocument() : CppXml__ {
+		var r = new CppXml__();
+		r.nodeType = Xml.Document;
+		r._children = new Array();
+		return r;
+	}
+
+	private override function getNodeName() : String {
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		return _nodeName;
+	}
+
+	private override function setNodeName( n : String ) : String {
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		return _nodeName = n;
+	}
+
+	private override function getNodeValue() : String {
+		if( nodeType == Xml.Element || nodeType == Xml.Document )
+			throw "bad nodeType";
+		return _nodeValue;
+	}
+
+	private override function setNodeValue( v : String ) : String {
+		if( nodeType == Xml.Element || nodeType == Xml.Document )
+			throw "bad nodeType";
+		return _nodeValue = v;
+	}
+
+	private override function getParent() : Xml {
+		return _parent;
+	}
+
+	public override function get( att : String ) : String {
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		return Reflect.field( _attributes, att );
+	}
+
+	public override function set( att : String, value : String ) : Void {
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		Reflect.setField (_attributes, att, value );
+	}
+
+	public override function remove( att : String ) : Void{
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		Reflect.deleteField( _attributes, att );
+	}
+
+	public override function exists( att : String ) : Bool {
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		return Reflect.hasField( _attributes, att );
+	}
+
+	public override function attributes() : Iterator<String> {
+		if( nodeType != Xml.Element )
+			throw "bad nodeType";
+		return Reflect.fields( _attributes ).iterator();
+	}
+
+	public override function iterator() : Iterator<Xml> {
+		if( _children == null )
+			throw "bad nodetype";
+      return untyped _children.iterator();
+	}
+
+
+	public override function elements() {
+		if( _children == null )
+			throw "bad nodetype";
+      var children = _children;
+		return untyped {
+			cur: 0,
+			hasNext : function() {
+				var k:Int = this.cur;
+				var l = children.length;
+				while( k < l ) {
+					if( children[k].nodeType == Xml.Element )
+						break;
+					k += 1;
+				}
+				this.cur = k;
+				return k < l;
+			},
+			next : function() {
+				var k = this.cur;
+				var l = children.length;
+				while( k < l ) {
+					var n = children[k];
+					k += 1;
+					if( n.nodeType == Xml.Element ) {
+						this.cur = k;
+						return n;
+					}
+				}
+				return null;
+			}
+		}
+	}
+
+	public override function elementsNamed( name : String ) {
+		if( _children == null )
+			throw "bad nodetype";
+      var children = _children;
+		return untyped {
+			cur: 0,
+			hasNext : function() {
+				var k = this.cur;
+				var l = children.length;
+				while( k < l ) {
+					var n = children[k];
+					if( n.nodeType == Xml.Element && n._nodeName == name )
+						break;
+					k++;
+				}
+				this.cur = k;
+				return k < l;
+			},
+			next : function() {
+				var k = this.cur;
+				var l = children.length;
+				while( k < l ) {
+					var n = children[k];
+					k++;
+					if( n.nodeType == Xml.Element && n._nodeName == name ) {
+						this.cur = k;
+						return n;
+					}
+				}
+				return null;
+			}
+		}
+	}
+
+	public override function firstChild() : Xml {
+		if( _children == null )
+			throw "bad nodetype";
+		return _children[0];
+	}
+
+	public override function firstElement() : Xml {
+		if( _children == null )
+			throw "bad nodetype";
+		for( cur in 0..._children.length ) {
+			var n:CppXml__ = _children[cur];
+			if( n.nodeType == Xml.Element )
+				return n;
+		}
+		return null;
+	}
+
+   public override function addChild( x_ : Xml ) : Void {
+      var x:CppXml__ = cast x_;
+		if( _children == null )
+			throw "bad nodetype";
+		if( x._parent != null ) x._parent._children.remove(x);
+		x._parent = this;
+		_children.push( x );
+	}
+
+   override function removeChild( x_ : Xml ) : Bool {
+      var x:CppXml__ = cast x_;
+		if( _children == null )
+			throw "bad nodetype";
+		var b = _children.remove( x );
+		if( b ) x._parent = null;
+		return b;
+	}
+
+	public override function insertChild( x_ : Xml, pos : Int ) : Void {
+      var x:CppXml__ = cast x_;
+		if( _children == null )
+			throw "bad nodetype";
+		if( x._parent != null ) x._parent._children.remove(x);
+		x._parent = this;
+		_children.insert( pos, x );
+	}
+
+	public override function toString() {
+		if( nodeType == Xml.PCData )
+			return _nodeValue;
+		if( nodeType == Xml.CData )
+			return "<![CDATA["+_nodeValue+"]]>";
+		if( nodeType == Xml.Comment || nodeType == Xml.DocType || nodeType == Xml.Prolog )
+			return _nodeValue;
+
+		var s = new StringBuf();
+
+		if( nodeType == Xml.Element ) {
+			s.add("<");
+			s.add(_nodeName);
+			for( k in Reflect.fields(_attributes) ) {
+				s.add(" ");
+				s.add(k);
+				s.add("=\"");
+				s.add(Reflect.field(_attributes,k));
+				s.add("\"");
+			}
+			if( _children.length == 0 ) {
+				s.add("/>");
+				return s.toString();
+			}
+			s.add(">");
+		}
+		for( x in iterator() )
+			s.add(x);
+		if( nodeType == Xml.Element ) {
+			s.add("</");
+			s.add(_nodeName);
+			s.add(">");
+		}
+		return s.toString();
+	}
+
+
+}

+ 54 - 0
std/cpp/Lib.hx

@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2005, The haXe Project Contributors
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   - Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   - Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ */
+package cpp;
+
+class Lib {
+
+	/**
+		Load and return a Cpp primitive from a DLL library.
+	**/
+	public static function load( lib : String, prim : String, nargs : Int ) : Dynamic {
+		return untyped __global__.__loadprim(lib,prim,nargs);
+	}
+
+	public static function rethrow(inExp:Dynamic) { throw inExp; }
+
+	public static function stringReference(inExp:Dynamic) { throw inExp; }
+
+/**
+		Print the specified value on the default output.
+	**/
+	public static function print( v : Dynamic ) : Void {
+		untyped __global__.__hxcpp_print(v);
+	}
+
+	/**
+		Print the specified value on the default output followed by a newline character.
+	**/
+	public static function println( v : Dynamic ) : Void {
+		untyped __global__.__hxcpp_println(v);
+	}
+
+}

+ 2 - 0
std/haxe/Log.hx

@@ -35,6 +35,8 @@ class Log {
 		untyped js.Boot.__trace(v,infos);
 		#elseif php
 		untyped __call__('_hx_trace', v,infos);
+		#elseif cpp
+		untyped __trace(v,infos);
 		#end
 	}