diff options
| author | gingerBill <bill@gingerbill.org> | 2018-05-12 18:40:49 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-05-12 18:40:49 +0100 |
| commit | 2ef22e86e0742d6dcf0e8c4796f126134e808086 (patch) | |
| tree | 04e93cb32d73adaa3826bb46a33231219902b59f /core/_preload.odin | |
| parent | 830f4f540fdbe30b22e93540249e61c1d1521f9b (diff) | |
Make `any` use `typeid` rather than `^Type_Info`
Diffstat (limited to 'core/_preload.odin')
| -rw-r--r-- | core/_preload.odin | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/core/_preload.odin b/core/_preload.odin index a1d729649..cec6a59b4 100644 --- a/core/_preload.odin +++ b/core/_preload.odin @@ -239,10 +239,28 @@ type_info_base_without_enum :: proc(info: ^Type_Info) -> ^Type_Info { return base; } + +typeid_from_type_info :: proc(ti: ^Type_Info) -> typeid { + id: uintptr = 0; + if ti != nil { + id = (uintptr(ti) - uintptr(&__type_table[0]))/size_of(Type_Info); + } + return transmute(typeid)id; +} type_info_from_typeid :: proc(t: typeid) -> ^Type_Info { index := transmute(uintptr)t; return &__type_table[index]; } +typeid_base :: proc(id: typeid) -> typeid { + ti := type_info_from_typeid(id); + ti = type_info_base(ti); + return typeid_from_type_info(ti); +} +typeid_base_without_enum :: proc(id: typeid) -> typeid { + ti := type_info_from_typeid(id); + ti = type_info_base_without_enum(ti); + return typeid_from_type_info(ti); +} @@ -649,7 +667,10 @@ __print_caller_location :: proc(fd: os.Handle, using loc: Source_Code_Location) __print_u64(fd, u64(column)); os.write_byte(fd, ')'); } - +__print_typeid :: proc(fd: os.Handle, id: typeid) { + ti := type_info_from_typeid(id); + __print_type(fd, ti); +} __print_type :: proc(fd: os.Handle, ti: ^Type_Info) { if ti == nil { os.write_string(fd, "nil"); @@ -660,7 +681,7 @@ __print_type :: proc(fd: os.Handle, ti: ^Type_Info) { case Type_Info_Named: os.write_string(fd, info.name); case Type_Info_Integer: - a := any{type_info = ti}; + a := any{typeid = typeid_from_type_info(ti)}; switch _ in a { case int: os.write_string(fd, "int"); case uint: os.write_string(fd, "uint"); @@ -680,7 +701,7 @@ __print_type :: proc(fd: os.Handle, ti: ^Type_Info) { case Type_Info_String: os.write_string(fd, "string"); case Type_Info_Boolean: - a := any{type_info = ti}; + a := any{typeid = typeid_from_type_info(ti)}; switch _ in a { case bool: os.write_string(fd, "bool"); case: @@ -689,6 +710,8 @@ __print_type :: proc(fd: os.Handle, ti: ^Type_Info) { } case Type_Info_Any: os.write_string(fd, "any"); + case Type_Info_Type_Id: + os.write_string(fd, "typeid"); case Type_Info_Pointer: if info.elem == nil { @@ -941,15 +964,15 @@ __dynamic_array_expr_error :: proc "contextless" (file: string, line, column: in __debug_trap(); } -__type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: int, from, to: ^Type_Info) { +__type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: int, from, to: typeid) { if ok do return; fd := os.stderr; __print_caller_location(fd, Source_Code_Location{file, line, column, ""}); os.write_string(fd, " Invalid type assertion from"); - __print_type(fd, from); + __print_typeid(fd, from); os.write_string(fd, " to "); - __print_type(fd, to); + __print_typeid(fd, to); os.write_byte(fd, '\n'); __debug_trap(); } |