mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 04:38:16 +00:00
Optional ok for union_cast (similar to map indices)
This commit is contained in:
+14
-11
@@ -315,7 +315,11 @@ __assert :: proc(file: string, line, column: int, msg: string) #inline {
|
||||
file, line, column, msg);
|
||||
__debug_trap();
|
||||
}
|
||||
|
||||
__panic :: proc(file: string, line, column: int, msg: string) #inline {
|
||||
fmt.fprintf(os.stderr, "%s(%d:%d) Panic: %s\n",
|
||||
file, line, column, msg);
|
||||
__debug_trap();
|
||||
}
|
||||
__bounds_check_error :: proc(file: string, line, column: int, index, count: int) {
|
||||
if 0 <= index && index < count {
|
||||
return;
|
||||
@@ -341,6 +345,13 @@ __substring_expr_error :: proc(file: string, line, column: int, low, high: int)
|
||||
file, line, column, low, high);
|
||||
__debug_trap();
|
||||
}
|
||||
__union_cast_check :: proc(ok: bool, file: string, line, column: int, from, to: ^Type_Info) {
|
||||
if !ok {
|
||||
fmt.fprintf(os.stderr, "%s(%d:%d) Invalid `union_cast` from %T to %T\n",
|
||||
file, line, column, from, to);
|
||||
__debug_trap();
|
||||
}
|
||||
}
|
||||
|
||||
__string_decode_rune :: proc(s: string) -> (rune, int) #inline {
|
||||
return utf8.decode_rune(s);
|
||||
@@ -449,6 +460,8 @@ __dynamic_array_append_nothing :: proc(array_: rawptr, elem_size, elem_align: in
|
||||
}
|
||||
|
||||
|
||||
// Map stuff
|
||||
|
||||
__default_hash :: proc(data: []byte) -> u64 {
|
||||
return hash.fnv64a(data);
|
||||
}
|
||||
@@ -650,13 +663,3 @@ __dynamic_map_erase :: proc(using h: __Map_Header, fr: __Map_Find_Result) {
|
||||
m.hashes[last.hash_index] = fr.entry_index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
__print_ti_ptr :: proc(ti: ^Type_Info) {
|
||||
fmt.println(ti);
|
||||
match e in ti {
|
||||
case Type_Info.Enum:
|
||||
fmt.println(e.names);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -790,10 +790,10 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
|
||||
buffer_write_string(fi.buf, "map[");
|
||||
defer buffer_write_byte(fi.buf, ']');
|
||||
entries := ^(cast(^Raw_Dynamic_Map)v.data).entries;
|
||||
gs, gs_ok := union_cast(^Struct)type_info_base(info.generated_struct); assert(gs_ok);
|
||||
ed, ed_ok := union_cast(^Dynamic_Array)type_info_base(gs.types[1]); assert(ed_ok);
|
||||
gs := union_cast(^Struct)type_info_base(info.generated_struct);
|
||||
ed := union_cast(^Dynamic_Array)type_info_base(gs.types[1]);
|
||||
|
||||
entry_type, et_ok := union_cast(^Struct)ed.elem; assert(et_ok);
|
||||
entry_type := union_cast(^Struct)ed.elem;
|
||||
entry_size := ed.elem_size;
|
||||
for i in 0..<entries.count {
|
||||
if i > 0 {
|
||||
|
||||
Reference in New Issue
Block a user