Browse Source

[eval] eval.integers.Int64.toHxInt64

Aleksandr Kuzmenko 4 years ago
parent
commit
41065ae733
3 changed files with 23 additions and 13 deletions
  1. 16 0
      src/macro/eval/evalIntegers.ml
  2. 2 13
      src/macro/eval/evalStdLib.ml
  3. 5 0
      std/eval/integers/Int64.hx

+ 16 - 0
src/macro/eval/evalIntegers.ml

@@ -12,6 +12,17 @@ open EvalMisc
 open Unsigned
 open Unsigned
 open Signed
 open Signed
 
 
+let encode_haxe_i64 low high =
+	let vi = create_instance key_haxe__Int64____Int64 in
+	set_instance_field vi key_high (vint32 high);
+	set_instance_field vi key_low (vint32 low);
+	vinstance vi
+
+let encode_haxe_i64_direct i64 =
+	let low = GInt64.to_int32 i64 in
+	let high = GInt64.to_int32 (Int64.shift_right_logical i64 32) in
+	encode_haxe_i64 low high
+
 let decode_u64 v =
 let decode_u64 v =
 	match v with
 	match v with
 	| VUInt64 u -> u
 	| VUInt64 u -> u
@@ -138,6 +149,7 @@ let uint64_fields = [
 
 
 let int64_fields = [
 let int64_fields = [
 	"MAX", VInt64 Int64.max_int;
 	"MAX", VInt64 Int64.max_int;
+	"MIN", VInt64 Int64.min_int;
 	"ZERO", VInt64 Int64.zero;
 	"ZERO", VInt64 Int64.zero;
 	"ONE", VInt64 Int64.one;
 	"ONE", VInt64 Int64.one;
 	"ofInt", vfun1 (fun v ->
 	"ofInt", vfun1 (fun v ->
@@ -172,6 +184,10 @@ let int64_fields = [
 		let i = decode_i64 v in
 		let i = decode_i64 v in
 		VUInt64 (UInt64.of_int64 i)
 		VUInt64 (UInt64.of_int64 i)
 	);
 	);
+	"toHxInt64", vfun1 (fun v ->
+		let i = decode_i64 v in
+		encode_haxe_i64_direct i
+	);
 	"toString", vfun1 (fun v ->
 	"toString", vfun1 (fun v ->
 		let i = decode_i64 v in
 		let i = decode_i64 v in
 		EvalString.vstring (EvalString.create_ascii (Int64.to_string i))
 		EvalString.vstring (EvalString.create_ascii (Int64.to_string i))

+ 2 - 13
src/macro/eval/evalStdLib.ml

@@ -42,17 +42,6 @@ let ptmap_keys h =
 let hashtbl_keys h =
 let hashtbl_keys h =
 	Hashtbl.fold (fun k _ acc -> k :: acc) h []
 	Hashtbl.fold (fun k _ acc -> k :: acc) h []
 
 
-let encode_i64 low high =
-	let vi = create_instance key_haxe__Int64____Int64 in
-	set_instance_field vi key_high (vint32 high);
-	set_instance_field vi key_low (vint32 low);
-	vinstance vi
-
-let encode_i64_direct i64 =
-	let low = Int64.to_int32 i64 in
-	let high = Int64.to_int32 (Int64.shift_right_logical i64 32) in
-	encode_i64 low high
-
 module StdEvalVector = struct
 module StdEvalVector = struct
 	let this this = match this with
 	let this this = match this with
 		| VVector vv -> vv
 		| VVector vv -> vv
@@ -344,7 +333,7 @@ module StdBytes = struct
 		try
 		try
 			let low = read_i32 this pos in
 			let low = read_i32 this pos in
 			let high = read_i32 this (pos + 4) in
 			let high = read_i32 this (pos + 4) in
-			encode_i64 low high;
+			EvalIntegers.encode_haxe_i64 low high;
 		with _ ->
 		with _ ->
 			outside_bounds()
 			outside_bounds()
 	)
 	)
@@ -1157,7 +1146,7 @@ module StdFPHelper = struct
 	let doubleToI64 = vfun1 (fun v ->
 	let doubleToI64 = vfun1 (fun v ->
 		let f = num v in
 		let f = num v in
 		let i64 = Int64.bits_of_float f in
 		let i64 = Int64.bits_of_float f in
-		encode_i64_direct i64
+		EvalIntegers.encode_haxe_i64_direct i64
 	)
 	)
 
 
 	let floatToI32 = vfun1 (fun f ->
 	let floatToI32 = vfun1 (fun f ->

+ 5 - 0
std/eval/integers/Int64.hx

@@ -54,6 +54,11 @@ package eval.integers;
 	**/
 	**/
 	public function toUInt64():UInt64;
 	public function toUInt64():UInt64;
 
 
+	/**
+		Convert to `haxe.Int64`.
+	**/
+	@:to public function toHxInt64():haxe.Int64;
+
 	/**
 	/**
 		Return the string representation of this value.
 		Return the string representation of this value.
 	**/
 	**/