Skip to content

Commit

Permalink
[hl] added guid type
Browse files Browse the repository at this point in the history
  • Loading branch information
ncannasse committed Feb 2, 2025
1 parent f0310db commit 5812a01
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/generators/genhl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ let rec to_type ?tref ctx t =
| ["hl"], "UI16" -> HUI16
| ["hl"], "UI8" -> HUI8
| ["hl"], "I64" -> HI64
| ["hl"], "GUID" -> HGUID
| ["hl"], "NativeArray" -> HArray (to_type ctx (List.hd pl))
| ["haxe";"macro"], "Position" -> HAbstract ("macro_pos", alloc_string ctx "macro_pos")
| _ -> failwith ("Unknown core type " ^ s_type_path a.a_path))
Expand Down Expand Up @@ -4027,6 +4028,8 @@ let write_code ch code debug =
| HPacked t ->
byte 22;
write_type t
| HGUID ->
byte 23
) all_types;

let write_debug_infos debug =
Expand Down
10 changes: 6 additions & 4 deletions src/generators/hl2c.ml
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ let tname str =
ident n

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

let is_ptr = function
| HVoid | HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64 | HBool -> false
| HVoid | HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64 | HBool | HGUID -> false
| _ -> true

let rec ctype_no_ptr = function
Expand Down Expand Up @@ -156,6 +156,7 @@ let rec ctype_no_ptr = function
| HPacked t ->
let name,v = ctype_no_ptr t in
"struct _" ^ name, v
| HGUID -> "int64", 0

let ctype t =
let t, nptr = ctype_no_ptr t in
Expand Down Expand Up @@ -203,6 +204,7 @@ let type_id t =
| HMethod _ -> "HMETHOD"
| HStruct _ -> "HSTRUCT"
| HPacked _ -> "HPACKED"
| HGUID -> "HGUID"

let var_type n t =
ctype t ^ " " ^ ident n
Expand Down Expand Up @@ -237,7 +239,7 @@ let define ctx s =

let rec define_type ctx t =
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 _ ->
define ctx "#include <hl/natives.h>";
| HFun (args,ret) | HMethod (args,ret) ->
Expand Down Expand Up @@ -1138,7 +1140,7 @@ let make_types_idents htypes =
let types_descs = ref PMap.empty in
let rec make_desc t =
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
| HFun (tl,t) ->
DFun (List.map make_desc tl, make_desc t, true)
Expand Down
6 changes: 5 additions & 1 deletion src/generators/hlcode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type ttype =
| HMethod of ttype list * ttype
| HStruct of class_proto
| HPacked of ttype
| HGUID

and class_proto = {
pname : string;
Expand Down Expand Up @@ -259,7 +260,7 @@ let list_mapi f l =
let is_nullable t =
match t with
| 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
| HStruct _ | HPacked _ -> true
Expand Down Expand Up @@ -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
| HArray t1,HArray t2 ->
compatible_element_types t1 t2
| (HI64|HGUID), (HI64|HGUID) ->
true
| _ ->
tsame t1 t2

Expand Down Expand Up @@ -490,6 +493,7 @@ let rec tstr ?(stack=[]) ?(detailed=false) t =
"enum(" ^ e.ename ^ ")"
| HNull t -> "null(" ^ tstr t ^ ")"
| HPacked t -> "packed(" ^ tstr t ^ ")"
| HGUID -> "guid"

let ostr fstr o =
match o with
Expand Down
3 changes: 2 additions & 1 deletion src/generators/hlinterp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,8 @@ let interp ctx f args =
| HNull _ -> 19
| HMethod _ -> 20
| HStruct _ -> 21
| HPacked _ -> 22)))
| HPacked _ -> 22
| HGUID -> 23)))
| _ -> Globals.die "" __LOC__);
| ORef (r,v) ->
set r (VRef (RStack (v + spos),rtype v))
Expand Down
7 changes: 7 additions & 0 deletions std/hl/Api.hx
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,11 @@ extern class Api {
#if (hl_ver >= version("1.13.0"))
@:hlNative("?std", "sys_has_debugger") static function hasDebugger() : Bool;
#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 changes: 25 additions & 0 deletions std/hl/GUID.hx
Original file line number Diff line number Diff line change
@@ -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 {}

0 comments on commit 5812a01

Please sign in to comment.