Browse Source

[cs] starting to implement cs.StdTypes.Int64

Cauê Waneck 11 years ago
parent
commit
3ac6967218
2 changed files with 79 additions and 13 deletions
  1. 62 1
      std/cs/StdTypes.hx
  2. 17 12
      std/cs/_std/haxe/Int64.hx

+ 62 - 1
std/cs/StdTypes.hx

@@ -26,4 +26,65 @@ package cs;
 @:notNull @:runtimeValue @:coreType abstract Char16 from Int {}
 @:notNull @:runtimeValue @:coreType abstract UInt8 to Int from Int {}
 @:notNull @:runtimeValue @:coreType abstract UInt16 to Int {}
-@:notNull abstract UInt64(haxe.Int64) from haxe.Int64 {}
+@:notNull @:runtimeValue @:coreType abstract Int64 from Int
+{
+	@:op(A+B) public static function addI(lhs:Int64, rhs:Int):Int64;
+	@:op(A+B) public static function add(lhs:Int64, rhs:Int64):Int64;
+	@:op(A*B) public static function mulI(lhs:Int64, rhs:Int):Int64;
+	@:op(A*B) public static function mul(lhs:Int64, rhs:Int64):Int64;
+	@:op(A%B) public static function modI(lhs:Int64, rhs:Int):Int64;
+	@:op(A%B) public static function mod(lhs:Int64, rhs:Int64):Int64;
+	@:op(A-B) public static function subI(lhs:Int64, rhs:Int):Int64;
+	@:op(A-B) public static function sub(lhs:Int64, rhs:Int64):Int64;
+	@:op(A/B) public static function divI(lhs:Int64, rhs:Int):Int64;
+	@:op(A/B) public static function div(lhs:Int64, rhs:Int64):Int64;
+	@:op(A|B) public static function orI(lhs:Int64, rhs:Int):Int64;
+	@:op(A|B) public static function or(lhs:Int64, rhs:Int64):Int64;
+	@:op(A^B) public static function xorI(lhs:Int64, rhs:Int):Int64;
+	@:op(A^B) public static function xor(lhs:Int64, rhs:Int64):Int64;
+	@:op(A&B) public static function andI(lhs:Int64, rhs:Int):Int64;
+	@:op(A&B) public static function and(lhs:Int64, rhs:Int64):Int64;
+	@:op(A<<B) public static function shlI(lhs:Int64, rhs:Int):Int64;
+	@:op(A<<B) public static function shl(lhs:Int64, rhs:Int64):Int64;
+	@:op(A>>B) public static function shrI(lhs:Int64, rhs:Int):Int64;
+	@:op(A>>B) public static function shr(lhs:Int64, rhs:Int64):Int64;
+
+	@:op(A>B) public static function gt(lhs:Int64, rhs:Int64):Bool;
+	@:op(A>=B) public static function gte(lhs:Int64, rhs:Int64):Bool;
+	@:op(A<B) public static function lt(lhs:Int64, rhs:Int64):Bool;
+	@:op(A<=B) public static function lte(lhs:Int64, rhs:Int64):Bool;
+
+	@:op(~A) public static function bneg(t:Int64):Int64;
+	@:op(-A) public static function neg(t:Int64):Int64;
+}
+@:notNull @:runtimeValue @:coreType abstract UInt64 from Int
+{
+	@:op(A+B) public static function addI(lhs:UInt64, rhs:Int):UInt64;
+	@:op(A+B) public static function add(lhs:UInt64, rhs:UInt64):UInt64;
+	@:op(A*B) public static function mulI(lhs:UInt64, rhs:Int):UInt64;
+	@:op(A*B) public static function mul(lhs:UInt64, rhs:UInt64):UInt64;
+	@:op(A%B) public static function modI(lhs:UInt64, rhs:Int):UInt64;
+	@:op(A%B) public static function mod(lhs:UInt64, rhs:UInt64):UInt64;
+	@:op(A-B) public static function subI(lhs:UInt64, rhs:Int):UInt64;
+	@:op(A-B) public static function sub(lhs:UInt64, rhs:UInt64):UInt64;
+	@:op(A/B) public static function divI(lhs:UInt64, rhs:Int):UInt64;
+	@:op(A/B) public static function div(lhs:UInt64, rhs:UInt64):UInt64;
+	@:op(A|B) public static function orI(lhs:UInt64, rhs:Int):UInt64;
+	@:op(A|B) public static function or(lhs:UInt64, rhs:UInt64):UInt64;
+	@:op(A^B) public static function xorI(lhs:UInt64, rhs:Int):UInt64;
+	@:op(A^B) public static function xor(lhs:UInt64, rhs:UInt64):UInt64;
+	@:op(A&B) public static function andI(lhs:UInt64, rhs:Int):UInt64;
+	@:op(A&B) public static function and(lhs:UInt64, rhs:UInt64):UInt64;
+	@:op(A<<B) public static function shlI(lhs:UInt64, rhs:Int):UInt64;
+	@:op(A<<B) public static function shl(lhs:UInt64, rhs:UInt64):UInt64;
+	@:op(A>>B) public static function shrI(lhs:UInt64, rhs:Int):UInt64;
+	@:op(A>>B) public static function shr(lhs:UInt64, rhs:UInt64):UInt64;
+
+	@:op(A>B) public static function gt(lhs:UInt64, rhs:UInt64):Bool;
+	@:op(A>=B) public static function gte(lhs:UInt64, rhs:UInt64):Bool;
+	@:op(A<B) public static function lt(lhs:UInt64, rhs:UInt64):Bool;
+	@:op(A<=B) public static function lte(lhs:UInt64, rhs:UInt64):Bool;
+
+	@:op(~A) public function bneg(t:UInt64):UInt64;
+	@:op(-A) public function neg(t:UInt64):UInt64;
+}

+ 17 - 12
std/cs/_std/haxe/Int64.hx

@@ -21,15 +21,16 @@
  */
 package haxe;
 using haxe.Int64;
-@:coreType @:notNull @:runtimeValue private abstract NativeInt64 from Int to Int {}
-@:coreType @:notNull @:runtimeValue private abstract NativeUInt64 from Int to Int {}
+import cs.StdTypes.Int64 in NativeInt64;
+import cs.StdTypes.UInt64 in NativeUInt64;
 
 @:coreApi
 @:nativeGen class Int64
 {
 	@:extern private static inline function asNative(i:Int64):NativeInt64 return untyped i;
 	@:extern private static inline function ofNative(i:NativeInt64):Int64 return untyped i;
-	@:extern private static inline function mkNative(i:Dynamic):NativeInt64 return i;
+	@:extern private static inline function ofUNative(i:NativeUInt64):Int64 return untyped i;
+	@:extern private static inline function mkNative(i:Int):NativeInt64 return cast i;
 
 	public static inline function make( high : Int, low : Int ) : Int64
 	{
@@ -70,17 +71,17 @@ using haxe.Int64;
 
 	static function divMod( modulus : Int64, divisor : Int64 ) : { quotient : Int64, modulus : Int64 }
 	{
-		var q:Int64 = (modulus.asNative() / divisor.asNative()).mkNative().ofNative();
-		var m:Int64 = (modulus.asNative() % divisor.asNative()).mkNative().ofNative();
+		var q:Int64 = (modulus.asNative() / divisor.asNative()).ofNative();
+		var m:Int64 = (modulus.asNative() % divisor.asNative()).ofNative();
 		return { quotient : q, modulus : m };
 	}
 
 	public static inline function div( a : Int64, b : Int64 ) : Int64 {
-		return (a.asNative() / b.asNative()).mkNative().ofNative();
+		return (a.asNative() / b.asNative()).ofNative();
 	}
 
 	public static inline function mod( a : Int64, b : Int64 ) : Int64 {
-		return (a.asNative() % b.asNative()).mkNative().ofNative();
+		return (a.asNative() % b.asNative()).ofNative();
 	}
 
 	public static inline function shl( a : Int64, b : Int ) : Int64 {
@@ -92,7 +93,7 @@ using haxe.Int64;
 	}
 
 	public static inline function ushr( a : Int64, b : Int ) : Int64 {
-		return ( cast(a, NativeUInt64) >> b).ofNative();
+		return ( cast(a, NativeUInt64) >> b).ofUNative();
 	}
 
 	public static inline function and( a : Int64, b : Int64 ) : Int64
@@ -112,7 +113,11 @@ using haxe.Int64;
 
 	public static inline function neg( a : Int64 ) : Int64
 	{
-		return (~a.asNative()).ofNative();
+		var a2:NativeInt64 = a.asNative();
+		// var a3 = NativeInt64.bneg(a2);
+		var a3 = ~a;
+		return a;
+		// return (~(a.asNative())).ofNative();
 	}
 
 	public static inline function isNeg( a : Int64 ) : Bool
@@ -132,9 +137,9 @@ using haxe.Int64;
 
 	public static function ucompare( a : Int64, b : Int64 ) : Int
 	{
-		if (a.asNative() < 0.mkNative())
-			return (b.asNative() < 0.mkNative()) ? compare( (~a.asNative()).ofNative(), (~b.asNative()).ofNative()) : 1;
-		return (b.asNative() < 0.mkNative()) ? -1 : compare(a, b);
+		var a:NativeUInt64 = cast a,
+				b:NativeUInt64 = cast b;
+		return (a < b) ? -1 : (a > b) ? 1 : 0;
 	}
 
 	public static inline function toStr( a : Int64 ) : String {