Browse Source

[java] Added java.Int64

Cauê Waneck 11 years ago
parent
commit
6daa143877
4 changed files with 59 additions and 25 deletions
  1. 1 0
      gencs.ml
  2. 13 12
      genjava.ml
  3. 33 0
      std/java/StdTypes.hx
  4. 12 13
      std/java/_std/haxe/Int64.hx

+ 1 - 0
gencs.ml

@@ -2484,6 +2484,7 @@ let configure gen =
 				| TEnum({ e_path = ([], "Bool") }, [])
 				| TAbstract ({ a_path = ([], "Bool") },[]) -> Some t
 				| TAbstract _ when like_float t -> Some t
+				| t when is_cs_basic_type t -> Some t
 				| _ -> None )
 		| _ -> None
 	in

+ 13 - 12
genjava.ml

@@ -780,7 +780,7 @@ let configure gen =
 
 	(*let string_ref = get_cl ( get_type gen (["haxe";"lang"], "StringRefl")) in*)
 
-	let ti64 = match ( get_type gen (["haxe";"_Int64"], "NativeInt64") ) with | TTypeDecl t -> TType(t,[]) | _ -> assert false in
+	let ti64 = match ( get_type gen (["java"], "Int64") ) with | TAbstractDecl a -> TAbstract(a,[]) | _ -> assert false in
 
 	let has_tdynamic params =
 		List.exists (fun e -> match run_follow gen e with | TDynamic _ -> true | _ -> false) params
@@ -810,8 +810,8 @@ let configure gen =
 									| TInst ({ cl_path = ["haxe"],"Int64" },[])
 									| TInst ({ cl_path = ([],"Int") },[])
 									| TAbstract ({ a_path = ([],"Int") },[])
-									| TType ({ t_path = ["haxe";"_Int64"], "NativeInt64" },[])
-									| TAbstract ({ a_path = ["haxe";"_Int64"], "NativeInt64" },[])
+									| TType ({ t_path = ["java"], "Int64" },[])
+									| TAbstract ({ a_path = ["java"], "Int64" },[])
 									| TType ({ t_path = ["java"],"Int8" },[])
 									| TAbstract ({ a_path = ["java"],"Int8" },[])
 									| TType ({ t_path = ["java"],"Int16" },[])
@@ -855,8 +855,8 @@ let configure gen =
 			| TAbstract ({ a_path = ([],"Int") },[])
 			| TInst( { cl_path = (["haxe"], "Int32") }, [] )
 			| TInst( { cl_path = (["haxe"], "Int64") }, [] )
-			| TType ({ t_path = ["haxe";"_Int64"], "NativeInt64" },[])
-			| TAbstract ({ a_path = ["haxe";"_Int64"], "NativeInt64" },[])
+			| TType ({ t_path = ["java"], "Int64" },[])
+			| TAbstract ({ a_path = ["java"], "Int64" },[])
 			| TType ({ t_path = ["java"],"Int8" },[])
 			| TAbstract ({ a_path = ["java"],"Int8" },[])
 			| TType ({ t_path = ["java"],"Int16" },[])
@@ -974,8 +974,8 @@ let configure gen =
 			| TAbstract ({ a_path = ([],"Float") },[]) -> "double"
 			| TInst ({ cl_path = ([],"Int") },[])
 			| TAbstract ({ a_path = ([],"Int") },[]) -> "int"
-			| TType ({ t_path = ["haxe";"_Int64"], "NativeInt64" },[])
-			| TAbstract ({ a_path = ["haxe";"_Int64"], "NativeInt64" },[]) -> "long"
+			| TType ({ t_path = ["java"], "Int64" },[])
+			| TAbstract ({ a_path = ["java"], "Int64" },[]) -> "long"
 			| TType ({ t_path = ["java"],"Int8" },[])
 			| TAbstract ({ a_path = ["java"],"Int8" },[]) -> "byte"
 			| TType ({ t_path = ["java"],"Int16" },[])
@@ -1038,8 +1038,8 @@ let configure gen =
 			| TInst ({ cl_path = ([],"Int") },[])
 			| TAbstract ({ a_path = ([],"Int") },[]) ->
 					path_s_import pos (["java";"lang"], "Integer")
-			| TType ({ t_path = ["haxe";"_Int64"], "NativeInt64" },[])
-			| TAbstract ({ a_path = ["haxe";"_Int64"], "NativeInt64" },[]) ->
+			| TType ({ t_path = ["java"], "Int64" },[])
+			| TAbstract ({ a_path = ["java"], "Int64" },[]) ->
 					path_s_import pos (["java";"lang"], "Long")
 			| TInst ({ cl_path = ["haxe"],"Int64" },[])
 			| TAbstract ({ a_path = ["haxe"],"Int64" },[]) ->
@@ -1155,7 +1155,7 @@ let configure gen =
 						| TInt i32 ->
 							print w "%ld" i32;
 							(match real_type e.etype with
-								| TType( { t_path = (["haxe";"_Int64"], "NativeInt64") }, [] ) -> write w "L";
+								| TType( { t_path = (["java"], "Int64") }, [] ) -> write w "L";
 								| _ -> ()
 							)
 						| TFloat s ->
@@ -1170,7 +1170,7 @@ let configure gen =
 						| TBool b -> write w (if b then "true" else "false")
 						| TNull ->
 							(match real_type e.etype with
-								| TType( { t_path = (["haxe";"_Int64"], "NativeInt64") }, [] )
+								| TAbstract( { a_path = (["java"], "Int64") }, [] )
 								| TInst( { cl_path = (["haxe"], "Int64") }, [] ) -> write w "0L"
 								| TInst( { cl_path = (["haxe"], "Int32") }, [] )
 								| TInst({ cl_path = ([], "Int") },[])
@@ -1183,7 +1183,7 @@ let configure gen =
 									expr_s w { e with eexpr = TConst(TInt Int32.zero) }
 								| TAbstract _ when like_float e.etype ->
 									expr_s w { e with eexpr = TConst(TFloat "0.0") }
-								| _ -> write w "null")
+								| t -> write w ("null /*" ^ debug_type t ^ "*/") )
 						| TThis -> write w "this"
 						| TSuper -> write w "super")
 				| TLocal { v_name = "__fallback__" } -> ()
@@ -2040,6 +2040,7 @@ let configure gen =
 				| TAbstract ({ a_path = ([], "Int") },[])
 				| TEnum({ e_path = ([], "Bool") }, [])
 				| TAbstract ({ a_path = ([], "Bool") },[]) -> Some t
+				| t when is_java_basic_type t -> Some t
 				| _ -> None )
 		| _ -> None
 	in

+ 33 - 0
std/java/StdTypes.hx

@@ -24,3 +24,36 @@ package java;
 @:notNull @:runtimeValue @:coreType abstract Int8 from Int {}
 @:notNull @:runtimeValue @:coreType abstract Int16 from Int {}
 @:notNull @:runtimeValue @:coreType abstract Char16 from Int {}
+@:notNull @:runtimeValue @:coreType abstract Int64 from Int from Float from haxe.Int64
+{
+	@: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 ushrI(lhs:Int64, rhs:Int):Int64;
+	@:op(A>>>B) public static function ushr(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;
+}

+ 12 - 13
std/java/_std/haxe/Int64.hx

@@ -21,14 +21,14 @@
  */
 package haxe;
 using haxe.Int64;
-private typedef NativeInt64 = Int;
+import java.StdTypes.Int64 in NativeInt64;
 
 @: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 mkNative(i:Int):NativeInt64 return cast i;
 
 	public static inline function make( high : Int, low : Int ) : Int64
 	{
@@ -37,12 +37,11 @@ private typedef NativeInt64 = Int;
 
 	public static inline function getLow( x : Int64 ) : Int
 	{
-		return cast (x.asNative() & untyped __java__("0xFFFFFFFFL"), Int);
+		return cast (x.asNative() & (untyped __java__("0xFFFFFFFFL")), Int);
 	}
 
-	public static inline function getHigh( x : Int64 ) : Int
-	{
-		return cast(cast(x,NativeInt64) >>> cast(32,NativeInt64), Int);
+	public static inline function getHigh( x : Int64 ) : Int {
+		return cast(cast(x,NativeInt64) >>> 32, Int);
 	}
 
 	public static inline function ofInt( x : Int ) : Int64 {
@@ -70,17 +69,17 @@ private typedef NativeInt64 = Int;
 
 	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 +91,7 @@ private typedef NativeInt64 = Int;
 	}
 
 	public static inline function ushr( a : Int64, b : Int ) : Int64 {
-		return (a.asNative() >>> b).ofNative();
+		return ( a.asNative() >>> b).ofNative();
 	}
 
 	public static inline function and( a : Int64, b : Int64 ) : Int64
@@ -112,7 +111,7 @@ private typedef NativeInt64 = Int;
 
 	public static inline function neg( a : Int64 ) : Int64
 	{
-		return (~a.asNative()).ofNative();
+		return (~(a.asNative())).ofNative();
 	}
 
 	public static inline function isNeg( a : Int64 ) : Bool
@@ -133,7 +132,7 @@ private typedef NativeInt64 = Int;
 	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()) ? compare( (~(a.asNative())).ofNative(), (~(b.asNative())).ofNative()) : 1;
 		return (b.asNative() < 0.mkNative()) ? -1 : compare(a, b);
 	}