Add intrinsics.type_convert_variants_to_pointers and reflect.get_union_as_ptr_variants

This commit is contained in:
gingerBill
2022-09-08 16:52:51 +01:00
parent 81e3b64ecd
commit f77709e67e
4 changed files with 55 additions and 0 deletions
+2
View File
@@ -188,6 +188,8 @@ type_field_index_of :: proc($T: typeid, $name: string) -> uintptr ---
type_equal_proc :: proc($T: typeid) -> (equal: proc "contextless" (rawptr, rawptr) -> bool) where type_is_comparable(T) ---
type_hasher_proc :: proc($T: typeid) -> (hasher: proc "contextless" (data: rawptr, seed: uintptr) -> uintptr) where type_is_comparable(T) ---
type_convert_variants_to_pointers :: proc($T: typeid) -> typeid where type_is_union(T) ---
constant_utf16_cstring :: proc($literal: string) -> [^]u16 ---
// SIMD related
+10
View File
@@ -2,6 +2,7 @@ package reflect
import "core:runtime"
import "core:intrinsics"
import "core:mem"
_ :: intrinsics
Type_Info :: runtime.Type_Info
@@ -739,6 +740,15 @@ get_union_variant :: proc(a: any) -> any {
return any{a.data, id}
}
get_union_as_ptr_variants :: proc(val: ^$T) -> (res: intrinsics.type_convert_variants_to_pointers(T)) where intrinsics.type_is_union(T) {
ptr := rawptr(val)
tag := get_union_variant_raw_tag(val^)
mem.copy(&res, &ptr, size_of(ptr))
set_union_variant_raw_tag(res, tag)
return
}
set_union_variant_raw_tag :: proc(a: any, tag: i64) {
if a == nil { return }