Browse Source

[python] [php] fix some bitoperators for int32 (closes #5938), add so… (#6361)

* [python] [php] fix some bitoperators for int32 (closes #5938), add some tests for this to Int32.unit
frabbit 8 years ago
parent
commit
4223ed5ecf
2 changed files with 35 additions and 11 deletions
  1. 16 11
      std/haxe/Int32.hx
  2. 19 0
      tests/unit/src/unitstd/haxe/Int32.unit.hx

+ 16 - 11
std/haxe/Int32.hx

@@ -144,9 +144,13 @@ abstract Int32(Int) from Int to Int {
 	@:op(A >= B) private static function gteFloat(a:Int32, b:Float):Bool;
 	@:op(A >= B) private static function floatGte(a:Float, b:Int32):Bool;
 
-	#if lua
+	#if (lua || python || php)
 	@:op(~A) private static inline function complement( a : Int32 ) : Int32
+		#if lua
 		return lua.Boot.clamp(~a);
+		#else
+		return clamp(~a);
+		#end
 	#else
 	@:op(~A) private function complement():Int32;
 	#end
@@ -154,20 +158,20 @@ abstract Int32(Int) from Int to Int {
 	@:op(A & B) private static function and(a:Int32, b:Int32):Int32;
 	@:op(A & B) @:commutative private static function andInt(a:Int32, b:Int):Int32;
 
-	#if lua
-	@:op(A | B) private static function or(a:Int32, b:Int32):Int32
+	#if (lua || python || php)
+	@:op(A | B) private static #if (python || php) inline #end function or(a:Int32, b:Int32):Int32
 		return clamp((a:Int) | (b:Int));
-	@:op(A | B) @:commutative private static function orInt(a:Int32, b:Int):Int32
+	@:op(A | B) @:commutative private #if (python || php) inline #end static function orInt(a:Int32, b:Int):Int32
 		return clamp((a:Int) | b);
 	#else
 	@:op(A | B) private static function or(a:Int32, b:Int32):Int32;
 	@:op(A | B) @:commutative private static function orInt(a:Int32, b:Int):Int32;
 	#end
 
-	#if lua
-	@:op(A ^ B) private static function xor(a:Int32, b:Int32):Int32
+	#if (lua || python || php)
+	@:op(A ^ B) private static #if (python || php) inline #end function xor(a:Int32, b:Int32):Int32
 		return clamp((a:Int) ^ (b:Int));
-	@:op(A ^ B) @:commutative private static function xorInt(a:Int32, b:Int):Int32
+	@:op(A ^ B) @:commutative private static #if (python || php) inline #end function xorInt(a:Int32, b:Int):Int32
 		return clamp((a:Int) ^ b);
 	#else
 	@:op(A ^ B) private static function xor(a:Int32, b:Int32):Int32;
@@ -175,12 +179,12 @@ abstract Int32(Int) from Int to Int {
 	#end
 
 
-#if lua
-	@:op(A >> B) private static function shr(a:Int32, b:Int32):Int32
+#if (lua || python || php)
+	@:op(A >> B) private static #if (python || php) inline #end function shr(a:Int32, b:Int32):Int32
 		return clamp((a:Int) >> (b:Int));
-	@:op(A >> B) private static function shrInt(a:Int32, b:Int):Int32
+	@:op(A >> B) private static #if (python || php) inline #end function shrInt(a:Int32, b:Int):Int32
 		return clamp((a:Int) >> b);
-	@:op(A >> B) private static function intShr(a:Int, b:Int32):Int32
+	@:op(A >> B) private static #if (python || php) inline #end function intShr(a:Int, b:Int32):Int32
 		return clamp(a >> (b:Int));
 #else
 	@:op(A >> B) private static function shr(a:Int32, b:Int32):Int32;
@@ -229,6 +233,7 @@ abstract Int32(Int) from Int to Int {
 	static var extraBits : Int = untyped __php__("PHP_INT_SIZE") * 8 - 32;
 	#end
 
+
 #if !lua inline #end
 	static function clamp( x : Int ) : Int {
 		// force to-int conversion on platforms that require it

+ 19 - 0
tests/unit/src/unitstd/haxe/Int32.unit.hx

@@ -23,3 +23,22 @@ max*2 == -2;
 min << 1 == 0;
 min >> 1 == 0xc0000000;
 min >>> 1 == 0x40000000;
+
+var a = [1];
+var next = 0;
+
+var i32:haxe.Int32 = max - 1;
+i32 |= ((a[next] << 32) | 1 );
+i32 == max;
+
+var i32:haxe.Int32 = ((a[next] << 33) | 3);
+i32 >>= 1;
+i32 == 1;
+
+var i32:haxe.Int32 = 2;
+i32 ^= ( (a[next] << 32) | 1);
+i32 == 3;
+
+var i32:haxe.Int32 = 2;
+var c = ~(((a[next] << 32) | 1):haxe.Int32);
+c == 0xfffffffe;