aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-02-14 16:37:24 +0000
committerGinger Bill <bill@gingerbill.org>2017-02-14 16:37:24 +0000
commit8b5e3428a1e569abf763e63e859754e767e107e7 (patch)
tree302a0cd18b18436feeac7bf50d0d430b0368251a /core
parentd1f65097c48afe6d869949cc5ede76a8b14401a9 (diff)
Optional ok for `union_cast` (similar to map indices)
Diffstat (limited to 'core')
-rw-r--r--core/_preload.odin25
-rw-r--r--core/fmt.odin6
2 files changed, 17 insertions, 14 deletions
diff --git a/core/_preload.odin b/core/_preload.odin
index 7ff3bc44f..5114e8ef2 100644
--- a/core/_preload.odin
+++ b/core/_preload.odin
@@ -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);
- }
-}
-
diff --git a/core/fmt.odin b/core/fmt.odin
index 542f951e9..937d15c8a 100644
--- a/core/fmt.odin
+++ b/core/fmt.odin
@@ -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 {