|
@@ -21,6 +21,7 @@ bounds_check_error :: proc "contextless" (file: string, line, column: i32, index
|
|
|
if 0 <= index && index < count {
|
|
|
return
|
|
|
}
|
|
|
+ @(cold)
|
|
|
handle_error :: proc "contextless" (file: string, line, column: i32, index, count: int) {
|
|
|
print_caller_location(Source_Code_Location{file, line, column, ""})
|
|
|
print_string(" Index ")
|
|
@@ -81,6 +82,7 @@ dynamic_array_expr_error :: proc "contextless" (file: string, line, column: i32,
|
|
|
if 0 <= low && low <= high && high <= max {
|
|
|
return
|
|
|
}
|
|
|
+ @(cold)
|
|
|
handle_error :: proc "contextless" (file: string, line, column: i32, low, high, max: int) {
|
|
|
print_caller_location(Source_Code_Location{file, line, column, ""})
|
|
|
print_string(" Invalid dynamic array indices ")
|
|
@@ -97,10 +99,11 @@ dynamic_array_expr_error :: proc "contextless" (file: string, line, column: i32,
|
|
|
|
|
|
|
|
|
matrix_bounds_check_error :: proc "contextless" (file: string, line, column: i32, row_index, column_index, row_count, column_count: int) {
|
|
|
- if 0 <= row_index && row_index < row_count &&
|
|
|
+ if 0 <= row_index && row_index < row_count &&
|
|
|
0 <= column_index && column_index < column_count {
|
|
|
return
|
|
|
}
|
|
|
+ @(cold)
|
|
|
handle_error :: proc "contextless" (file: string, line, column: i32, row_index, column_index, row_count, column_count: int) {
|
|
|
print_caller_location(Source_Code_Location{file, line, column, ""})
|
|
|
print_string(" Matrix indices [")
|
|
@@ -119,71 +122,101 @@ matrix_bounds_check_error :: proc "contextless" (file: string, line, column: i32
|
|
|
}
|
|
|
|
|
|
|
|
|
-type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: i32, from, to: typeid) {
|
|
|
- if ok {
|
|
|
- return
|
|
|
- }
|
|
|
- handle_error :: proc "contextless" (file: string, line, column: i32, from, to: typeid) {
|
|
|
- print_caller_location(Source_Code_Location{file, line, column, ""})
|
|
|
- print_string(" Invalid type assertion from ")
|
|
|
- print_typeid(from)
|
|
|
- print_string(" to ")
|
|
|
- print_typeid(to)
|
|
|
- print_byte('\n')
|
|
|
- type_assertion_trap()
|
|
|
+when ODIN_DISALLOW_RTTI {
|
|
|
+ type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: i32) {
|
|
|
+ if ok {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ @(cold)
|
|
|
+ handle_error :: proc "contextless" (file: string, line, column: i32) {
|
|
|
+ print_caller_location(Source_Code_Location{file, line, column, ""})
|
|
|
+ print_string(" Invalid type assertion\n")
|
|
|
+ type_assertion_trap()
|
|
|
+ }
|
|
|
+ handle_error(file, line, column)
|
|
|
}
|
|
|
- handle_error(file, line, column, from, to)
|
|
|
-}
|
|
|
|
|
|
-type_assertion_check2 :: proc "contextless" (ok: bool, file: string, line, column: i32, from, to: typeid, from_data: rawptr) {
|
|
|
- if ok {
|
|
|
- return
|
|
|
+ type_assertion_check2 :: proc "contextless" (ok: bool, file: string, line, column: i32) {
|
|
|
+ if ok {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ @(cold)
|
|
|
+ handle_error :: proc "contextless" (file: string, line, column: i32) {
|
|
|
+ print_caller_location(Source_Code_Location{file, line, column, ""})
|
|
|
+ print_string(" Invalid type assertion\n")
|
|
|
+ type_assertion_trap()
|
|
|
+ }
|
|
|
+ handle_error(file, line, column)
|
|
|
+ }
|
|
|
+} else {
|
|
|
+ type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: i32, from, to: typeid) {
|
|
|
+ if ok {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ @(cold)
|
|
|
+ handle_error :: proc "contextless" (file: string, line, column: i32, from, to: typeid) {
|
|
|
+ print_caller_location(Source_Code_Location{file, line, column, ""})
|
|
|
+ print_string(" Invalid type assertion from ")
|
|
|
+ print_typeid(from)
|
|
|
+ print_string(" to ")
|
|
|
+ print_typeid(to)
|
|
|
+ print_byte('\n')
|
|
|
+ type_assertion_trap()
|
|
|
+ }
|
|
|
+ handle_error(file, line, column, from, to)
|
|
|
}
|
|
|
|
|
|
- variant_type :: proc "contextless" (id: typeid, data: rawptr) -> typeid {
|
|
|
- if id == nil || data == nil {
|
|
|
- return id
|
|
|
+ type_assertion_check2 :: proc "contextless" (ok: bool, file: string, line, column: i32, from, to: typeid, from_data: rawptr) {
|
|
|
+ if ok {
|
|
|
+ return
|
|
|
}
|
|
|
- ti := type_info_base(type_info_of(id))
|
|
|
- #partial switch v in ti.variant {
|
|
|
- case Type_Info_Any:
|
|
|
- return (^any)(data).id
|
|
|
- case Type_Info_Union:
|
|
|
- tag_ptr := uintptr(data) + v.tag_offset
|
|
|
- idx := 0
|
|
|
- switch v.tag_type.size {
|
|
|
- case 1: idx = int((^u8)(tag_ptr)^) - 1
|
|
|
- case 2: idx = int((^u16)(tag_ptr)^) - 1
|
|
|
- case 4: idx = int((^u32)(tag_ptr)^) - 1
|
|
|
- case 8: idx = int((^u64)(tag_ptr)^) - 1
|
|
|
- case 16: idx = int((^u128)(tag_ptr)^) - 1
|
|
|
+
|
|
|
+ variant_type :: proc "contextless" (id: typeid, data: rawptr) -> typeid {
|
|
|
+ if id == nil || data == nil {
|
|
|
+ return id
|
|
|
}
|
|
|
- if idx < 0 {
|
|
|
- return nil
|
|
|
- } else if idx < len(v.variants) {
|
|
|
- return v.variants[idx].id
|
|
|
+ ti := type_info_base(type_info_of(id))
|
|
|
+ #partial switch v in ti.variant {
|
|
|
+ case Type_Info_Any:
|
|
|
+ return (^any)(data).id
|
|
|
+ case Type_Info_Union:
|
|
|
+ tag_ptr := uintptr(data) + v.tag_offset
|
|
|
+ idx := 0
|
|
|
+ switch v.tag_type.size {
|
|
|
+ case 1: idx = int((^u8)(tag_ptr)^) - 1
|
|
|
+ case 2: idx = int((^u16)(tag_ptr)^) - 1
|
|
|
+ case 4: idx = int((^u32)(tag_ptr)^) - 1
|
|
|
+ case 8: idx = int((^u64)(tag_ptr)^) - 1
|
|
|
+ case 16: idx = int((^u128)(tag_ptr)^) - 1
|
|
|
+ }
|
|
|
+ if idx < 0 {
|
|
|
+ return nil
|
|
|
+ } else if idx < len(v.variants) {
|
|
|
+ return v.variants[idx].id
|
|
|
+ }
|
|
|
}
|
|
|
+ return id
|
|
|
}
|
|
|
- return id
|
|
|
- }
|
|
|
|
|
|
- handle_error :: proc "contextless" (file: string, line, column: i32, from, to: typeid, from_data: rawptr) {
|
|
|
+ @(cold)
|
|
|
+ handle_error :: proc "contextless" (file: string, line, column: i32, from, to: typeid, from_data: rawptr) {
|
|
|
|
|
|
- actual := variant_type(from, from_data)
|
|
|
+ actual := variant_type(from, from_data)
|
|
|
|
|
|
- print_caller_location(Source_Code_Location{file, line, column, ""})
|
|
|
- print_string(" Invalid type assertion from ")
|
|
|
- print_typeid(from)
|
|
|
- print_string(" to ")
|
|
|
- print_typeid(to)
|
|
|
- if actual != from {
|
|
|
- print_string(", actual type: ")
|
|
|
- print_typeid(actual)
|
|
|
+ print_caller_location(Source_Code_Location{file, line, column, ""})
|
|
|
+ print_string(" Invalid type assertion from ")
|
|
|
+ print_typeid(from)
|
|
|
+ print_string(" to ")
|
|
|
+ print_typeid(to)
|
|
|
+ if actual != from {
|
|
|
+ print_string(", actual type: ")
|
|
|
+ print_typeid(actual)
|
|
|
+ }
|
|
|
+ print_byte('\n')
|
|
|
+ type_assertion_trap()
|
|
|
}
|
|
|
- print_byte('\n')
|
|
|
- type_assertion_trap()
|
|
|
+ handle_error(file, line, column, from, to, from_data)
|
|
|
}
|
|
|
- handle_error(file, line, column, from, to, from_data)
|
|
|
}
|
|
|
|
|
|
|
|
@@ -191,6 +224,7 @@ make_slice_error_loc :: #force_inline proc "contextless" (loc := #caller_locatio
|
|
|
if 0 <= len {
|
|
|
return
|
|
|
}
|
|
|
+ @(cold)
|
|
|
handle_error :: proc "contextless" (loc: Source_Code_Location, len: int) {
|
|
|
print_caller_location(loc)
|
|
|
print_string(" Invalid slice length for make: ")
|
|
@@ -205,6 +239,7 @@ make_dynamic_array_error_loc :: #force_inline proc "contextless" (using loc := #
|
|
|
if 0 <= len && len <= cap {
|
|
|
return
|
|
|
}
|
|
|
+ @(cold)
|
|
|
handle_error :: proc "contextless" (loc: Source_Code_Location, len, cap: int) {
|
|
|
print_caller_location(loc)
|
|
|
print_string(" Invalid dynamic array parameters for make: ")
|
|
@@ -221,6 +256,7 @@ make_map_expr_error_loc :: #force_inline proc "contextless" (loc := #caller_loca
|
|
|
if 0 <= cap {
|
|
|
return
|
|
|
}
|
|
|
+ @(cold)
|
|
|
handle_error :: proc "contextless" (loc: Source_Code_Location, cap: int) {
|
|
|
print_caller_location(loc)
|
|
|
print_string(" Invalid map capacity for make: ")
|