Pārlūkot izejas kodu

[cs] Added StdTypes.Int64

Cauê Waneck 11 gadi atpakaļ
vecāks
revīzija
40c3d39416
7 mainītis faili ar 32 papildinājumiem un 31 dzēšanām
  1. 8 3
      codegen.ml
  2. 2 2
      gencommon.ml
  3. 13 17
      gencs.ml
  4. 2 2
      genjava.ml
  5. 2 2
      std/cs/StdTypes.hx
  6. 1 5
      std/cs/_std/haxe/Int64.hx
  7. 4 0
      std/cs/types/Int64.hx

+ 8 - 3
codegen.ml

@@ -1426,11 +1426,16 @@ let default_cast ?(vtmp="$t") com e texpr t p =
 module Overloads =
 struct
 	let rec simplify_t t = match t with
-		| TInst _ | TEnum _ | TAbstract({ a_impl = None }, _) ->
+		| TAbstract(a,_) when Meta.has Meta.CoreType a.a_meta ->
+			t
+		| TInst _ | TEnum _ ->
 			t
 		| TAbstract(a,tl) -> simplify_t (Abstract.get_underlying_type a tl)
 		| TType(({ t_path = [],"Null" } as t), [t2]) -> (match simplify_t t2 with
-			| (TAbstract({ a_impl = None }, _) | TEnum _ as t2) -> TType(t, [simplify_t t2])
+			| (TAbstract(a,_) as t2) when Meta.has Meta.CoreType a.a_meta ->
+				TType(t, [simplify_t t2])
+			| (TEnum _ as t2) ->
+				TType(t, [simplify_t t2])
 			| t2 -> t2)
 		| TType(t, tl) ->
 			simplify_t (apply_params t.t_types tl t.t_type)
@@ -1488,7 +1493,7 @@ struct
 			(cacc, 0)
 		| TDynamic _, _ ->
 			(max_int, 0) (* a function with dynamic will always be worst of all *)
-		| TAbstract({ a_impl = None }, _), TDynamic _ ->
+		| TAbstract(a, _), TDynamic _ when Meta.has Meta.CoreType a.a_meta ->
 			(cacc + 2, 0) (* a dynamic to a basic type will have an "unboxing" penalty *)
 		| _, TDynamic _ ->
 			(cacc + 1, 0)

+ 2 - 2
gencommon.ml

@@ -3004,7 +3004,7 @@ struct
 				List.fold_left get_type_params acc ( tret :: List.map (fun (_,_,t) -> t) params )
 			| TDynamic t ->
 				(match t with | TDynamic _ -> acc | _ -> get_type_params acc t)
-			| TAbstract ({ a_impl = Some _ } as a, pl) ->
+			| TAbstract (a, pl) when not (Meta.has Meta.CoreType a.a_meta) ->
 					get_type_params acc ( Codegen.Abstract.get_underlying_type a pl)
 			| TAnon a ->
 				PMap.fold (fun cf acc -> get_type_params acc cf.cf_type) a.a_fields acc
@@ -6318,7 +6318,7 @@ struct
 				| TArray(arr, idx) ->
 					let arr_etype = match follow arr.etype with
 					| (TInst _ as t) -> t
-					| TAbstract ({ a_impl = Some _ } as a, pl) ->
+					| TAbstract (a, pl) when not (Meta.has Meta.CoreType a.a_meta) ->
 						follow (Codegen.Abstract.get_underlying_type a pl)
 					| t -> t in
 					let idx = match gen.greal_type idx.etype with

+ 13 - 17
gencs.ml

@@ -48,7 +48,7 @@ let rec is_cs_basic_type t =
 			true
 		| TAbstract _ when like_float t ->
 			true
-		| TAbstract({ a_impl = Some _ } as a,pl) ->
+		| TAbstract(a,pl) when not (Meta.has Meta.CoreType a.a_meta) ->
 			is_cs_basic_type (Codegen.Abstract.get_underlying_type a pl)
 		| TEnum(e, _) when not (Meta.has Meta.Class e.e_meta) -> true
 		| TInst(cl, _) when Meta.has Meta.Struct cl.cl_meta -> true
@@ -159,9 +159,9 @@ let is_string t =
 		| TInst( { cl_path = ([], "String") }, [] ) -> true
 		| _ -> false
 
-let change_md = function
-	| TAbstractDecl( { a_impl = Some impl } as a) when Meta.has Meta.Delegate a.a_meta ->
-		TClassDecl impl
+let rec change_md = function
+	| TAbstractDecl(a) when Meta.has Meta.Delegate a.a_meta && not (Meta.has Meta.CoreType a.a_meta) ->
+		change_md (t_to_md a.a_this)
 	| TClassDecl( { cl_kind = KAbstractImpl ({ a_this = TInst(impl,_) } as a) }) when Meta.has Meta.Delegate a.a_meta ->
 		TClassDecl impl
 	| md -> md
@@ -438,7 +438,7 @@ struct
 						etype = basic.tbool;
 						epos = e.epos
 					}
-				| TCast(expr, _) when is_int_float e.etype && not (is_int_float expr.etype) && not (is_null e.etype) ->
+				| TCast(expr, _) when is_int_float e.etype && not (is_cs_basic_type expr.etype) && not (is_null e.etype) ->
 					let needs_cast = match gen.gfollow#run_f e.etype with
 						| TInst _ -> false
 						| _ -> true
@@ -708,10 +708,8 @@ let configure gen =
 			| TAbstract ({ a_path = ([],"Int") },[])
 			| TType ({ t_path = [],"UInt" },[])
 			| TAbstract ({ a_path = [],"UInt" },[])
-			| TType ({ t_path = ["haxe";"_Int64"], "NativeInt64" },[])
-			| TAbstract ({ a_path = ["haxe";"_Int64"], "NativeInt64" },[])
-			| TType ({ t_path = ["haxe";"_Int64"], "NativeUInt64" },[])
-			| TAbstract ({ a_path = ["haxe";"_Int64"], "NativeUInt64" },[])
+			| TType ({ t_path = ["cs"], "Int64" },[])
+			| TAbstract ({ a_path = ["cs"], "Int64" },[])
 			| TType ({ t_path = ["cs"],"UInt64" },[])
 			| TAbstract ({ a_path = ["cs"],"UInt64" },[])
 			| TType ({ t_path = ["cs"],"UInt8" },[])
@@ -731,7 +729,7 @@ let configure gen =
 			| TType ({ t_path = [],"Single" },[])
 			| TAbstract ({ a_path = [],"Single" },[]) -> Some t
 			| TType ({ t_path = [],"Null" },[_]) -> Some t
-			| TAbstract ({ a_impl = Some _ } as a, pl) ->
+			| TAbstract (a, pl) when not (Meta.has Meta.CoreType a.a_meta) ->
 					Some (gen.gfollow#run_f ( Codegen.Abstract.get_underlying_type a pl) )
 			| TAbstract( { a_path = ([], "EnumValue") }, _	)
 			| TInst( { cl_path = ([], "EnumValue") }, _  ) -> Some t_dynamic
@@ -748,7 +746,7 @@ let configure gen =
 
 	let ifaces = Hashtbl.create 1 in
 
-	let ti64 = match ( get_type gen (["haxe";"_Int64"], "NativeInt64") ) with | TTypeDecl t -> TType(t,[]) | TAbstractDecl a -> TAbstract(a,[]) | _ -> assert false in
+	let ti64 = match ( get_type gen (["cs"], "Int64") ) with | TTypeDecl t -> TType(t,[]) | TAbstractDecl a -> TAbstract(a,[]) | _ -> assert false in
 
 	let ttype = get_cl ( get_type gen (["System"], "Type") ) in
 
@@ -762,7 +760,7 @@ let configure gen =
 	let rec real_type t =
 		let t = gen.gfollow#run_f t in
 		let ret = match t with
-			| TAbstract ({ a_impl = Some _ } as a, pl) ->
+			| TAbstract (a, pl) when not (Meta.has Meta.CoreType a.a_meta) ->
 				real_type (Codegen.Abstract.get_underlying_type a pl)
 			| TInst( { cl_path = (["haxe"], "Int32") }, [] ) -> gen.gcon.basic.tint
 			| TInst( { cl_path = (["haxe"], "Int64") }, [] ) -> ti64
@@ -864,10 +862,8 @@ let configure gen =
 			| TAbstract ({ a_path = ([],"Int") },[]) -> "int"
 			| TType ({ t_path = [],"UInt" },[])
 			| TAbstract ({ a_path = [],"UInt" },[]) -> "uint"
-			| TType ({ t_path = ["haxe";"_Int64"], "NativeInt64" },[])
-			| TAbstract ({ a_path = ["haxe";"_Int64"], "NativeInt64" },[]) -> "long"
-			| TType ({ t_path = ["haxe";"_Int64"], "NativeUInt64" },[])
-			| TAbstract ({ a_path = ["haxe";"_Int64"], "NativeUInt64" },[]) -> "ulong"
+			| TType ({ t_path = ["cs"], "Int64" },[])
+			| TAbstract ({ a_path = ["cs"], "Int64" },[]) -> "long"
 			| TType ({ t_path = ["cs"],"UInt64" },[])
 			| TAbstract ({ a_path = ["cs"],"UInt64" },[]) -> "ulong"
 			| TType ({ t_path = ["cs"],"UInt8" },[])
@@ -917,7 +913,7 @@ let configure gen =
 					| Statics _ | EnumStatics _ -> "System.Type"
 					| _ -> "object")
 			| TDynamic _ -> "object"
-			| TAbstract(a,pl) when a.a_impl <> None ->
+			| TAbstract(a,pl) when not (Meta.has Meta.CoreType a.a_meta) ->
 				t_s (Codegen.Abstract.get_underlying_type a pl)
 			(* No Lazy type nor Function type made. That's because function types will be at this point be converted into other types *)
 			| _ -> if !strict_mode then begin trace ("[ !TypeError " ^ (Type.s_type (Type.print_context()) t) ^ " ]"); assert false end else "[ !TypeError " ^ (Type.s_type (Type.print_context()) t) ^ " ]"

+ 2 - 2
genjava.ml

@@ -866,7 +866,7 @@ let configure gen =
 			| TType ({ t_path = [],"Single" },[])
 			| TAbstract ({ a_path = [],"Single" },[])
 			| TType ({ t_path = [],"Null" },[_]) -> Some t
-			| TAbstract ({ a_impl = Some _ } as a, pl) ->
+			| TAbstract (a, pl) when not (Meta.has Meta.CoreType a.a_meta) ->
 					Some (gen.gfollow#run_f ( Codegen.Abstract.get_underlying_type a pl) )
 			| TAbstract( { a_path = ([], "EnumValue") }, _ )
 			| TInst( { cl_path = ([], "EnumValue") }, _  ) -> Some t_dynamic
@@ -883,7 +883,7 @@ let configure gen =
 	let rec real_type t =
 		let t = gen.gfollow#run_f t in
 		match t with
-			| TAbstract ({ a_impl = Some _ } as a, pl) ->
+			| TAbstract (a, pl) when not (Meta.has Meta.CoreType a.a_meta) ->
 				real_type (Codegen.Abstract.get_underlying_type a pl)
 			| TInst( { cl_path = (["haxe"], "Int32") }, [] ) -> gen.gcon.basic.tint
 			| TInst( { cl_path = (["haxe"], "Int64") }, [] ) -> ti64

+ 2 - 2
std/cs/StdTypes.hx

@@ -26,7 +26,7 @@ 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 @:runtimeValue @:coreType abstract Int64 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;
@@ -57,7 +57,7 @@ package cs;
 	@: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
+@:notNull @:runtimeValue @:coreType abstract UInt64 from Int from Int64 from Float from haxe.Int64
 {
 	@:op(A+B) public static function addI(lhs:UInt64, rhs:Int):UInt64;
 	@:op(A+B) public static function add(lhs:UInt64, rhs:UInt64):UInt64;

+ 1 - 5
std/cs/_std/haxe/Int64.hx

@@ -113,11 +113,7 @@ import cs.StdTypes.UInt64 in NativeUInt64;
 
 	public static inline function neg( a : Int64 ) : Int64
 	{
-		var a2:NativeInt64 = a.asNative();
-		// var a3 = NativeInt64.bneg(a2);
-		var a3 = ~a;
-		return a;
-		// return (~(a.asNative())).ofNative();
+		return (~(a.asNative())).ofNative();
 	}
 
 	public static inline function isNeg( a : Int64 ) : Bool

+ 4 - 0
std/cs/types/Int64.hx

@@ -0,0 +1,4 @@
+package cs.types;
+
+typedef Int64 = cs.StdTypes.Int64;
+