فهرست منبع

[cpp] Use native-statics for Int64 externs

hughsando 9 سال پیش
والد
کامیت
54e50cddd8
1فایلهای تغییر یافته به همراه152 افزوده شده و 54 حذف شده
  1. 152 54
      std/cpp/_std/haxe/Int64.hx

+ 152 - 54
std/cpp/_std/haxe/Int64.hx

@@ -25,8 +25,115 @@ import haxe.Int64Helper;
 
 @:notNull
 
+
+@:include("cpp/Int64.h")
 @:native("cpp::Int64Struct")
-private extern class ___Int64 { public function get():cpp.Int64; }
+private extern class ___Int64 {
+   public function get():cpp.Int64;
+
+   @:native("_hx_int64_make")
+   public static function make(high:Int32, low:Int32): __Int64 return null;
+
+   @:native(" ::cpp::Int64Struct")
+   public static function ofInt(value:Int): __Int64 return null;
+
+   @:native(" ::cpp::Int64Struct::is")
+   public static function is(d:Dynamic):Bool return false;
+
+   @:native("_hx_int64_is_neg")
+   public static function isNeg(a:__Int64):Bool return false;
+
+   @:native("_hx_int64_is_zero")
+   public static function isZero(a:__Int64):Bool return false;
+
+   @:native("_hx_int64_compare")
+   public static function compare(a:__Int64, b:__Int64):Int return 0;
+
+   @:native("_hx_int64_ucompare")
+   public static function ucompare(a:__Int64, b:__Int64):Int return 0;
+
+   @:native("_hx_int64_to_string")
+   public static function toString(a:__Int64):String return null;
+
+   @:native("_hx_int64_neg")
+   public static function neg(a:__Int64): __Int64 return null;
+
+   @:native("_hx_int64_pre_increment")
+   public static function preIncrement(a:__Int64): __Int64 return null;
+
+   @:native("_hx_int64_post_increment")
+   public static function postIncrement(a:__Int64): __Int64 return null;
+
+   @:native("_hx_int64_pre_decrement")
+   public static function preDecrement(a:__Int64): __Int64 return null;
+
+   @:native("_hx_int64_post_decrement")
+   public static function postDecrement(a:__Int64): __Int64 return null;
+
+   @:native("_hx_int64_add")
+   public static function add(a:__Int64, b:__Int64): __Int64 return null;
+
+   @:native("_hx_int64_add")
+   public static function addInt(a:__Int64, b:Int): __Int64 return null;
+
+   @:native("_hx_int64_sub")
+   public static function sub(a:__Int64, b:__Int64): __Int64 return null;
+
+   @:native("_hx_int64_sub")
+   public static function subInt(a:__Int64, b:Int): __Int64 return null;
+
+   @:native("_hx_int64_sub")
+   public static function intSub(a:Int, b:__Int64): __Int64 return null;
+
+   @:native("_hx_int64_mul")
+   public static function mul(a:__Int64, b:__Int64): __Int64 return null;
+
+   @:native("_hx_int64_div")
+   public static function div(a:__Int64, b:__Int64): __Int64 return null;
+
+   @:native("_hx_int64_mod")
+   public static function mod(a:__Int64, b:__Int64): __Int64 return null;
+
+   @:native("_hx_int64_eq")
+   public static function eq(a:__Int64, b:__Int64): Bool return null;
+
+   @:native("_hx_int64_eq")
+   public static function eqInt(a:__Int64, b:Int): Bool return null;
+
+   @:native("_hx_int64_neq")
+   public static function neq(a:__Int64, b:__Int64): Bool return null;
+
+   @:native("_hx_int64_neq")
+   public static function neqInt(a:__Int64, b:Int): Bool return null;
+
+   @:native("_hx_int64_complement")
+   public static function complement(a:__Int64): __Int64 return null;
+
+   @:native("_hx_int64_and")
+   public static function bitAnd(a:__Int64, b:__Int64): __Int64 return null;
+
+   @:native("_hx_int64_or")
+   public static function bitOr(a:__Int64, b:__Int64): __Int64 return null;
+
+   @:native("_hx_int64_xor")
+   public static function bitXor(a:__Int64, b:__Int64): __Int64 return null;
+
+   @:native("_hx_int64_shl")
+   public static function shl(a:__Int64, b:Int): __Int64 return null;
+
+   @:native("_hx_int64_shr")
+   public static function shr(a:__Int64, b:Int): __Int64 return null;
+
+   @:native("_hx_int64_ushr")
+   public static function ushr(a:__Int64, b:Int): __Int64 return null;
+
+   @:native("_hx_int64_high")
+   public static function high(a:__Int64):Int32 return 0;
+
+   @:native("_hx_int64_low")
+   public static function low(a:__Int64):Int32 return 0;
+
+}
 
 private typedef __Int64 = ___Int64;
 
@@ -36,17 +143,15 @@ abstract Int64( __Int64 ) from __Int64 to __Int64
    /**
 		Makes a copy of `this` Int64.
 	**/
-	public #if !cppua inline #end function copy():Int64 return this;
+	public #if !cppia inline #end function copy():Int64 return this;
 
 
 	public static #if !cppia inline #end function make( high : Int32, low : Int32 ) : Int64 {
-      var tmpHigh = high;
-      var tmpLow = low;
-      return untyped __cpp__("cpp::Int64Struct(( ( (cpp::Int64)((unsigned int){0}) ) << 32 ) | ((unsigned int){1}))",tmpHigh, tmpLow);
+      return __Int64.make(high,low);
 	}
 
-	@:from public static function ofInt( x : Int ) : Int64 {
-		return untyped __cpp__("((cpp::Int64)({0}))", x);
+	@:from public static #if !cppia inline #end function ofInt( x : Int ) : Int64 {
+      return __Int64.ofInt(x);
 	}
 
 
@@ -85,31 +190,29 @@ abstract Int64( __Int64 ) from __Int64 to __Int64
 		Returns `true` if `x` is less than zero.
 	**/
 	public static #if !cppia inline #end function isNeg( x : Int64) : Bool
-		return untyped __cpp__("(({0}.get()) < 0)", x);
+      return __Int64.isNeg(x);
 
 	/**
 		Returns `true` if `x` is exactly zero.
 	**/
 	public static #if !cppia inline #end function isZero( x : Int64 ) : Bool
-		return untyped __cpp__("(({0}.get()) == 0)", x);
+      return __Int64.isZero(x);
 
 	/**
 		Compares `a` and `b` in signed mode.
 		Returns a negative value if `a < b`, positive if `a > b`,
 		or 0 if `a == b`.
 	**/
-	public static #if !cppia inline #end function compare( a : Int64, b : Int64 ) : Int {
-		return untyped __cpp__("( ({0}.get()) < ({1}.get()) ? -1 : ({0})==({1}) ? 0 : 1)", a, b, a, b);
-	}
+	public static #if !cppia inline #end function compare( a : Int64, b : Int64 ) : Int
+      return __Int64.compare(a,b);
 
 	/**
 		Compares `a` and `b` in unsigned mode.
 		Returns a negative value if `a < b`, positive if `a > b`,
 		or 0 if `a == b`.
 	**/
-	public static #if !cppia inline #end function ucompare( a : Int64, b : Int64 ) : Int {
-		return untyped __cpp__("( (cpp::UInt64)({0}.get()) < (cpp::UInt64)({1}.get()) ? -1 : ({0}.get())==({1}.get()) ? 0 : 1)", a, b, a, b);
-	}
+	public static #if !cppia inline #end function ucompare( a : Int64, b : Int64 ) : Int
+      return __Int64.ucompare(a,b);
 
 	/**
 		Returns a signed decimal `String` representation of `x`.
@@ -117,10 +220,8 @@ abstract Int64( __Int64 ) from __Int64 to __Int64
 	public static #if !cppia inline #end function toStr(x:Int64) : String
 		return x.toString();
 
-	private function toString() : String
-	{
-		return untyped __cpp__("String( ({0}).get() )", this);
-	}
+	private #if !cppia inline #end function toString() : String
+      return __Int64.toString(this);
 
 	public static function parseString( sParam : String ) : Int64 {
 		return Int64Helper.parseString( sParam );
@@ -149,16 +250,15 @@ abstract Int64( __Int64 ) from __Int64 to __Int64
 	/**
 		Returns the negative of `x`.
 	**/
-	@:op(-A) public static #if !cppia inline #end function neg( x : Int64 ) : Int64 {
-		return untyped __cpp__("(-({0}.get()))",x);
-	}
+	@:op(-A) public static #if !cppia inline #end function neg( x : Int64 ) : Int64
+      return __Int64.neg(x);
 
 	@:op(++A) private inline  function preIncrement() : Int64 {
       #if cppia
       this = this + make(0,1);
       return this;
       #else
-		return untyped __cpp__("(++({0}.get()))",this);
+		return __Int64.preIncrement(this);
       #end
 	}
 
@@ -168,7 +268,7 @@ abstract Int64( __Int64 ) from __Int64 to __Int64
       this = this + make(0,1);
       return result;
       #else
-		return untyped __cpp__("(({0}.get())++)",this);
+		return __Int64.postIncrement(this);
       #end
 	}
 
@@ -177,7 +277,7 @@ abstract Int64( __Int64 ) from __Int64 to __Int64
       untyped this = this - make(0,1);
       return this;
       #else
-		return untyped __cpp__("(--({0}.get()))",this);
+		return __Int64.preDecrement(this);
       #end
 	}
 
@@ -187,39 +287,37 @@ abstract Int64( __Int64 ) from __Int64 to __Int64
       this = this - make(0,1);
       return result;
       #else
-		return untyped __cpp__("(({0}.get())--)",this);
+		return __Int64.postDecrement(this);
       #end
 	}
 
 	/**
 		Returns the sum of `a` and `b`.
 	**/
-	@:op(A + B) public static #if !cppia inline #end function add( a : Int64, b : Int64 ) : Int64 {
-		return untyped __cpp__("(({0}.get()) + ({1}.get()))", a, b);
-	}
+	@:op(A + B) public static #if !cppia inline #end function add( a : Int64, b : Int64 ) : Int64
+      return __Int64.add(a,b);
 
 	@:op(A + B) @:commutative private static #if !cppia inline #end function addInt( a : Int64, b : Int ) : Int64
-		return add( a, b );
+      return __Int64.addInt(a,b);
 
 	/**
 		Returns `a` minus `b`.
 	**/
 	@:op(A - B) public static #if !cppia inline #end function sub( a : Int64, b : Int64 ) : Int64 {
-		return untyped __cpp__("(({0}.get()) - ({1}.get()))", a, b);
+      return __Int64.sub(a,b);
 	}
 
 	@:op(A - B) private static #if !cppia inline #end function subInt( a : Int64, b : Int ) : Int64
-		return sub( a, b );
+		return __Int64.subInt( a, b );
 
 	@:op(A - B) private static #if !cppia inline #end function intSub( a : Int, b : Int64 ) : Int64
-		return sub( a, b );
+		return __Int64.intSub( a, b );
 
 	/**
 		Returns the product of `a` and `b`.
 	**/
-	@:op(A * B) public static #if !cppia inline #end function mul( a : Int64, b : Int64 ) : Int64 {
-		return untyped __cpp__("(({0}.get()) * ({1}.get()))", a, b);
-	}
+	@:op(A * B) public static #if !cppia inline #end function mul( a : Int64, b : Int64 ) : Int64
+		return __Int64.mul( a, b );
 
 	@:op(A * B) @:commutative private static #if !cppia inline #end function mulInt( a : Int64, b : Int ) : Int64
 		return mul( a, b );
@@ -227,10 +325,10 @@ abstract Int64( __Int64 ) from __Int64 to __Int64
 	/**
 		Returns the quotient of `a` divided by `b`.
 	**/
-	@:op(A / B) public static function div( a : Int64, b : Int64 ) : Int64 {
-		if (untyped __cpp__("(({0}.get()) == 0)",b) )
+	@:op(A / B) public static #if !cppia inline #end function div( a : Int64, b : Int64 ) : Int64 {
+		if (__Int64.isZero(a))
 			throw "divide by zero";
-		return untyped __cpp__("(({0}.get()) / ({1}.get()))", a, b);
+		return __Int64.div(a,b);
 	}
 
 
@@ -245,9 +343,9 @@ abstract Int64( __Int64 ) from __Int64 to __Int64
 	**/
 	@:op(A % B) public static #if !cppia inline #end function mod( a : Int64, b : Int64 ) : Int64
    {
-		if (untyped __cpp__("(({0}.get()) == 0)",b) )
+		if (__Int64.isZero(a))
 			throw "divide by zero";
-		return untyped __cpp__("(({0}.get()) % ({1}.get()))", a, b);
+		return __Int64.mod(a, b);
    }
 
 	@:op(A % B) private static #if !cppia inline #end function modInt( a : Int64, b : Int ) : Int64
@@ -260,19 +358,19 @@ abstract Int64( __Int64 ) from __Int64 to __Int64
 		Returns `true` if `a` is equal to `b`.
 	**/
 	@:op(A == B) public static #if !cppia inline #end function eq( a : Int64, b : Int64 ) : Bool
-		return untyped __cpp__("(({0}.get()) == ({1}.get()))", a, b);
+      return __Int64.eq(a,b);
 
 	@:op(A == B) @:commutative private static #if !cppia inline #end function eqInt( a : Int64, b : Int ) : Bool
-		return eq( a, b );
+		return __Int64.eqInt( a, b );
 
 	/**
 		Returns `true` if `a` is not equal to `b`.
 	**/
 	@:op(A != B) public static #if !cppia inline #end function neq( a : Int64, b : Int64 ) : Bool
-		return untyped __cpp__("(({0}.get()) != ({1}.get()))", a, b);
+		return __Int64.neq( a, b );
 
 	@:op(A != B) @:commutative private static #if !cppia inline #end function neqInt( a : Int64, b : Int ) : Bool
-		return neq(a, b);
+		return neq( a, b );
 
 	@:op(A < B) private static #if !cppia inline #end function lt( a : Int64, b : Int64 ) : Bool
 		return compare(a, b) < 0;
@@ -314,53 +412,53 @@ abstract Int64( __Int64 ) from __Int64 to __Int64
 		Returns the bitwise NOT of `a`.
 	**/
 	@:op(~A) private static #if !cppia inline #end function complement( a : Int64 ) : Int64
-		return untyped __cpp__("(~({0}.get()))", a);
+      return __Int64.complement(a);
 
 	/**
 		Returns the bitwise AND of `a` and `b`.
 	**/
 	@:op(A & B) public static #if !cppia inline #end function and( a : Int64, b : Int64 ) : Int64
-		return untyped __cpp__("(({0}) & ({1}))", a, b);
+      return __Int64.bitAnd(a,b);
 
 	/**
 		Returns the bitwise OR of `a` and `b`.
 	**/
 	@:op(A | B) public static #if !cppia inline #end function or( a : Int64, b : Int64 ) : Int64
-		return untyped __cpp__("(({0}) | ({1}))", a, b);
+      return __Int64.bitOr(a,b);
 
 	/**
 		Returns the bitwise XOR of `a` and `b`.
 	**/
 	@:op(A ^ B) public static #if !cppia inline #end function xor( a : Int64, b : Int64 ) : Int64
-		return untyped __cpp__("(({0}) ^ ({1}))", a, b);
+      return __Int64.bitXor(a,b);
 
 	/**
 		Returns `a` left-shifted by `b` bits.
 	**/
 	@:op(A << B) public static #if !cppia inline #end function shl( a : Int64, b : Int ) : Int64
-		return untyped __cpp__("(({0}) << ({1}))", a, (b&63));
+      return __Int64.shl(a,b);
 
 	/**
 		Returns `a` right-shifted by `b` bits in signed mode.
 		`a` is sign-extended.
 	**/
 	@:op(A >> B) public static #if !cppia inline #end function shr( a : Int64, b : Int) : Int64
-		return untyped __cpp__("(({0}) >> ({1}))", a, (b&63));
+      return __Int64.shr(a,b);
 
 	/**
 		Returns `a` right-shifted by `b` bits in unsigned mode.
 		`a` is padded with zeroes.
 	**/
 	@:op(A >>> B) public static #if !cppia inline #end function ushr( a : Int64, b : Int ) : Int64
-		return untyped __cpp__("(((cpp::UInt64)({0})) >> ({1}))", a, (b&63));
+      return __Int64.ushr(a,b);
 
 	public var high(get, never) : Int32;
 	private #if !cppia inline #end function get_high() : Int32
-		return  untyped __cpp__("(int)(((cpp::Int64)({0}))>>32)",this);
+      return __Int64.high(this);
 
 	public var low(get, never) : Int32;
 	private #if !cppia inline #end function get_low() : Int32
-		return untyped __cpp__("(int)(({0})&0xffffffff)", this);
+      return __Int64.low(this);
 
 }