Browse Source

[hl] added guid type

Nicolas Cannasse 5 months ago
parent
commit
5812a01550
6 changed files with 48 additions and 6 deletions
  1. 3 0
      src/generators/genhl.ml
  2. 6 4
      src/generators/hl2c.ml
  3. 5 1
      src/generators/hlcode.ml
  4. 2 1
      src/generators/hlinterp.ml
  5. 7 0
      std/hl/Api.hx
  6. 25 0
      std/hl/GUID.hx

+ 3 - 0
src/generators/genhl.ml

@@ -473,6 +473,7 @@ let rec to_type ?tref ctx t =
 			| ["hl"], "UI16" -> HUI16
 			| ["hl"], "UI16" -> HUI16
 			| ["hl"], "UI8" -> HUI8
 			| ["hl"], "UI8" -> HUI8
 			| ["hl"], "I64" -> HI64
 			| ["hl"], "I64" -> HI64
+			| ["hl"], "GUID" -> HGUID
 			| ["hl"], "NativeArray" -> HArray (to_type ctx (List.hd pl))
 			| ["hl"], "NativeArray" -> HArray (to_type ctx (List.hd pl))
 			| ["haxe";"macro"], "Position" -> HAbstract ("macro_pos", alloc_string ctx "macro_pos")
 			| ["haxe";"macro"], "Position" -> HAbstract ("macro_pos", alloc_string ctx "macro_pos")
 			| _ -> failwith ("Unknown core type " ^ s_type_path a.a_path))
 			| _ -> failwith ("Unknown core type " ^ s_type_path a.a_path))
@@ -4027,6 +4028,8 @@ let write_code ch code debug =
 		| HPacked t ->
 		| HPacked t ->
 			byte 22;
 			byte 22;
 			write_type t
 			write_type t
+		| HGUID ->
+			byte 23
 	) all_types;
 	) all_types;
 
 
 	let write_debug_infos debug =
 	let write_debug_infos debug =

+ 6 - 4
src/generators/hl2c.ml

@@ -124,11 +124,11 @@ let tname str =
 	ident n
 	ident n
 
 
 let is_gc_ptr = function
 let is_gc_ptr = function
-	| HVoid | HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64 | HBool | HType | HRef _ | HMethod _ | HPacked _ -> false
+	| HVoid | HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64 | HBool | HType | HRef _ | HMethod _ | HPacked _ | HGUID -> false
 	| HBytes | HDyn | HFun _ | HObj _ | HArray _ | HVirtual _ | HDynObj | HAbstract _ | HEnum _ | HNull _ | HStruct _ -> true
 	| HBytes | HDyn | HFun _ | HObj _ | HArray _ | HVirtual _ | HDynObj | HAbstract _ | HEnum _ | HNull _ | HStruct _ -> true
 
 
 let is_ptr = function
 let is_ptr = function
-	| HVoid | HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64 | HBool -> false
+	| HVoid | HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64 | HBool | HGUID -> false
 	| _ -> true
 	| _ -> true
 
 
 let rec ctype_no_ptr = function
 let rec ctype_no_ptr = function
@@ -156,6 +156,7 @@ let rec ctype_no_ptr = function
 	| HPacked t ->
 	| HPacked t ->
 		let name,v = ctype_no_ptr t in
 		let name,v = ctype_no_ptr t in
 		"struct _" ^ name, v
 		"struct _" ^ name, v
+	| HGUID -> "int64", 0
 
 
 let ctype t =
 let ctype t =
 	let t, nptr = ctype_no_ptr t in
 	let t, nptr = ctype_no_ptr t in
@@ -203,6 +204,7 @@ let type_id t =
 	| HMethod _ -> "HMETHOD"
 	| HMethod _ -> "HMETHOD"
 	| HStruct _  -> "HSTRUCT"
 	| HStruct _  -> "HSTRUCT"
 	| HPacked _ -> "HPACKED"
 	| HPacked _ -> "HPACKED"
+	| HGUID -> "HGUID"
 
 
 let var_type n t =
 let var_type n t =
 	ctype t ^ " " ^ ident n
 	ctype t ^ " " ^ ident n
@@ -237,7 +239,7 @@ let define ctx s =
 
 
 let rec define_type ctx t =
 let rec define_type ctx t =
 	match t with
 	match t with
-	| HVoid | HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64 | HBool | HBytes | HDyn | HArray _ | HType | HDynObj | HNull _ | HRef _ -> ()
+	| HVoid | HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64 | HBool | HBytes | HDyn | HArray _ | HType | HDynObj | HNull _ | HRef _ | HGUID -> ()
 	| HAbstract _ ->
 	| HAbstract _ ->
 		define ctx "#include <hl/natives.h>";
 		define ctx "#include <hl/natives.h>";
 	| HFun (args,ret) | HMethod (args,ret) ->
 	| HFun (args,ret) | HMethod (args,ret) ->
@@ -1138,7 +1140,7 @@ let make_types_idents htypes =
 	let types_descs = ref PMap.empty in
 	let types_descs = ref PMap.empty in
 	let rec make_desc t =
 	let rec make_desc t =
 		match t with
 		match t with
-		| HVoid | HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64 | HBool | HBytes | HDyn | HArray _ | HType | HRef _ | HDynObj | HNull _ ->
+		| HVoid | HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64 | HBool | HBytes | HDyn | HArray _ | HType | HRef _ | HDynObj | HNull _ | HGUID ->
 			DSimple t
 			DSimple t
 		| HFun (tl,t) ->
 		| HFun (tl,t) ->
 			DFun (List.map make_desc tl, make_desc t, true)
 			DFun (List.map make_desc tl, make_desc t, true)

+ 5 - 1
src/generators/hlcode.ml

@@ -49,6 +49,7 @@ type ttype =
 	| HMethod of ttype list * ttype
 	| HMethod of ttype list * ttype
 	| HStruct of class_proto
 	| HStruct of class_proto
 	| HPacked of ttype
 	| HPacked of ttype
+	| HGUID
 
 
 and class_proto = {
 and class_proto = {
 	pname : string;
 	pname : string;
@@ -259,7 +260,7 @@ let list_mapi f l =
 let is_nullable t =
 let is_nullable t =
 	match t with
 	match t with
 	| HBytes | HDyn | HFun _ | HObj _ | HArray _ | HVirtual _ | HDynObj | HAbstract _ | HEnum _ | HNull _ | HRef _ | HType | HMethod _ | HStruct _ -> true
 	| HBytes | HDyn | HFun _ | HObj _ | HArray _ | HVirtual _ | HDynObj | HAbstract _ | HEnum _ | HNull _ | HRef _ | HType | HMethod _ | HStruct _ -> true
-	| HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64 | HBool | HVoid | HPacked _ -> false
+	| HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64 | HBool | HVoid | HPacked _ | HGUID -> false
 
 
 let is_struct = function
 let is_struct = function
 	| HStruct _ | HPacked _ -> true
 	| HStruct _ | HPacked _ -> true
@@ -358,6 +359,8 @@ let rec safe_cast t1 t2 =
 		List.for_all2 (fun t1 t2 -> safe_cast t2 t1 || (t1 = HDyn && is_dynamic t2)) args1 args2 && safe_cast t1 t2
 		List.for_all2 (fun t1 t2 -> safe_cast t2 t1 || (t1 = HDyn && is_dynamic t2)) args1 args2 && safe_cast t1 t2
 	| HArray t1,HArray t2 ->
 	| HArray t1,HArray t2 ->
 		compatible_element_types t1 t2
 		compatible_element_types t1 t2
+	| (HI64|HGUID), (HI64|HGUID) ->
+		true
 	| _ ->
 	| _ ->
 		tsame t1 t2
 		tsame t1 t2
 
 
@@ -490,6 +493,7 @@ let rec tstr ?(stack=[]) ?(detailed=false) t =
 		"enum(" ^ e.ename ^ ")"
 		"enum(" ^ e.ename ^ ")"
 	| HNull t -> "null(" ^ tstr t ^ ")"
 	| HNull t -> "null(" ^ tstr t ^ ")"
 	| HPacked t -> "packed(" ^ tstr t ^ ")"
 	| HPacked t -> "packed(" ^ tstr t ^ ")"
+	| HGUID -> "guid"
 
 
 let ostr fstr o =
 let ostr fstr o =
 	match o with
 	match o with

+ 2 - 1
src/generators/hlinterp.ml

@@ -1083,7 +1083,8 @@ let interp ctx f args =
 					| HNull _ -> 19
 					| HNull _ -> 19
 					| HMethod _ -> 20
 					| HMethod _ -> 20
 					| HStruct _ -> 21
 					| HStruct _ -> 21
-					| HPacked _ -> 22)))
+					| HPacked _ -> 22
+					| HGUID -> 23)))
 				| _ -> Globals.die "" __LOC__);
 				| _ -> Globals.die "" __LOC__);
 		| ORef (r,v) ->
 		| ORef (r,v) ->
 			set r (VRef (RStack (v + spos),rtype v))
 			set r (VRef (RStack (v + spos),rtype v))

+ 7 - 0
std/hl/Api.hx

@@ -52,4 +52,11 @@ extern class Api {
 	#if (hl_ver >= version("1.13.0"))
 	#if (hl_ver >= version("1.13.0"))
 	@:hlNative("?std", "sys_has_debugger") static function hasDebugger() : Bool;
 	@:hlNative("?std", "sys_has_debugger") static function hasDebugger() : Bool;
 	#end
 	#end
+	#if (hl_ver >= version("1.15.0"))	
+	@:hlNative("?std", "register_guid_name") private static function _registerGUIDName( guid : hl.I64, bytes : hl.Bytes ) : Void;
+	static inline function registerGUIDName( guid : GUID, name : String ) {
+		return _registerGUIDName(guid,@:privateAccess name.bytes);
+	}
+	#end
+	
 }
 }

+ 25 - 0
std/hl/GUID.hx

@@ -0,0 +1,25 @@
+/*
+ * Copyright (C)2005-2019 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+package hl;
+
+@:coreType @:notNull @:runtimeValue abstract GUID to I64 from I64 {}