Browse Source

[java] Fix some Java Int64 generation issues

Cauê Waneck 10 years ago
parent
commit
324e149a86
4 changed files with 31 additions and 7 deletions
  1. 2 0
      gencommon.ml
  2. 3 1
      genjava.ml
  3. 4 4
      std/java/_std/haxe/Int64.hx
  4. 22 2
      tests/unit/src/unit/TestInt64.hx

+ 2 - 0
gencommon.ml

@@ -84,8 +84,10 @@ let rec like_int t =
 let rec like_i64 t =
 	match follow t with
 		| TInst({ cl_path = (["cs"], "Int64") },[])
+		| TAbstract({ a_path = (["cs"], "Int64") },[])
 		| TInst({ cl_path = (["cs"], "UInt64") },[])
 		| TInst({ cl_path = (["java"], "Int64") },[])
+		| TAbstract({ a_path = (["java"], "Int64") },[])
 		| TInst({ cl_path = (["haxe"], "Int64") },[])
 		| TAbstract({ a_path = (["haxe"], "Int64") },[]) -> true
 		| TAbstract(a, _) -> List.exists (fun t -> like_i64 t) a.a_from || List.exists (fun t -> like_i64 t) a.a_to

+ 3 - 1
genjava.ml

@@ -84,7 +84,7 @@ let is_java_basic_type t =
 		| TInst( { cl_path = (["haxe"], "Int32") }, [] )
 		| TInst( { cl_path = (["haxe"], "Int64") }, [] )
 		| TAbstract( { a_path = ([], "Single") }, [] )
-		| TAbstract( { a_path = (["java"], ("Int8" | "Int16" | "Char16")) }, [] )
+		| TAbstract( { a_path = (["java"], ("Int8" | "Int16" | "Char16" | "Int64")) }, [] )
 		| TAbstract( { a_path =	([], "Int") }, [] )
 		| TAbstract( { a_path =	([], "Float") }, [] )
 		| TAbstract( { a_path =	([], "Bool") }, [] ) ->
@@ -234,6 +234,8 @@ struct
 							mk_is true obj i16_md
 						| TAbstractDecl{ a_path = (["java"], "Char16") } ->
 							mk_is true obj c16_md
+						| TAbstractDecl{ a_path = (["java"], "Int64") } ->
+							mk_is true obj i64_md
 						| TClassDecl{ cl_path = (["haxe"], "Int64") } ->
 							mk_is true obj i64_md
 						| TAbstractDecl{ a_path = ([], "Dynamic") }

+ 4 - 4
std/java/_std/haxe/Int64.hx

@@ -29,7 +29,7 @@ abstract Int64(__Int64) from __Int64 to __Int64
 {
 
 	public static inline function make( high : Int32, low : Int32 ) : Int64
-		return new Int64( (cast(high, __Int64) << 32) | (low & untyped __java__('0xffffffffL')) );
+		return new Int64( (cast(high, __Int64) << 32) | (cast(low, __Int64)& untyped __java__('0xffffffffL')) );
 
 	private inline function new(x : __Int64)
 		this = x;
@@ -76,13 +76,13 @@ abstract Int64(__Int64) from __Int64 to __Int64
 	}
 
 	public static inline function toStr( x : Int64 ) : String
-		return x.val + "";
+		return '${x.val}';
 
 	public static inline function divMod( dividend : Int64, divisor : Int64 ) : { quotient : Int64, modulus : Int64 }
-		return {quotient:0,modulus:0};//{ quotient: dividend / divisor, modulus: dividend % divisor };
+		return { quotient: dividend / divisor, modulus: dividend % divisor };
 
 	private inline function toString() : String
-		return this + "";
+		return '$this';
 
 	@:op(-A) public static function neg( x : Int64 ) : Int64
 		return -x.val;

+ 22 - 2
tests/unit/src/unit/TestInt64.hx

@@ -37,6 +37,26 @@ class TestInt64 extends Test {
 		exc( tryOverflow.bind(a) );	// Throws Overflow
 	}
 
+	// Some tests of how it generates Int64 when used as Null<Int64> or as type parameters
+	function testGen()
+	{
+		var arr:Array<Int64> = [];
+		arr.push(1);
+		arr.push(Int64.make(0xFFFFFFFF,0x80000000));
+		eq(arr[0].getHigh(), 0);
+		eq(arr[0].getLow(), 1);
+		eq(arr[1].getHigh(), 0xFFFFFFFF);
+		eq(arr[1].getLow(), 0x80000000);
+
+		var n:Null<Int64> = null;
+		eq(n, null);
+		var dyn:Dynamic = n;
+		eq(dyn, null);
+		n = Int64.make(0xf0f0f0f0, 0xefefefef);
+		eq(n.getHigh(), 0xf0f0f0f0);
+		eq(n.getLow(), 0xefefefef);
+	}
+
 	function tryOverflow( a : Int64 )
 	{
 		a.toInt();
@@ -296,7 +316,7 @@ class TestInt64 extends Test {
 		var a : Int64 = 32.ofInt();
 		var b : Int64 = (-4).ofInt();
 
-		t( a.eq(b) );
+		f( a.eq(b) );
 		t( a.neq(b) );
 		int64eq( a.add(b), 28 );
 		int64eq( a.sub(b), 36 );
@@ -442,4 +462,4 @@ class TestInt64 extends Test {
 		eq(Std.string(make(-2147483648, 1)), Std.string(neg(make(2147483647, -1)))); // -9223372036854775807 == neg(9223372036854775807)
 	}
 }
-*/
+*/