mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 06:38:47 +00:00
Move error handling for bounds checking into separate procedures (eliminate caching issues)
This commit is contained in:
@@ -268,9 +268,11 @@ complex128_eq :: inline proc "contextless" (a, b: complex128) -> bool { return r
|
|||||||
complex128_ne :: inline proc "contextless" (a, b: complex128) -> bool { return real(a) != real(b) || imag(a) != imag(b); }
|
complex128_ne :: inline proc "contextless" (a, b: complex128) -> bool { return real(a) != real(b) || imag(a) != imag(b); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bounds_check_error :: proc "contextless" (file: string, line, column: int, index, count: int) {
|
bounds_check_error :: proc "contextless" (file: string, line, column: int, index, count: int) {
|
||||||
if 0 <= index && index < count do return;
|
if 0 <= index && index < count do return;
|
||||||
|
handle_error :: proc "contextless" (file: string, line, column: int, index, count: int) {
|
||||||
fd := os.stderr;
|
fd := os.stderr;
|
||||||
print_caller_location(fd, Source_Code_Location{file, line, column, ""});
|
print_caller_location(fd, Source_Code_Location{file, line, column, ""});
|
||||||
os.write_string(fd, " Index ");
|
os.write_string(fd, " Index ");
|
||||||
@@ -280,10 +282,12 @@ bounds_check_error :: proc "contextless" (file: string, line, column: int, index
|
|||||||
os.write_byte(fd, '\n');
|
os.write_byte(fd, '\n');
|
||||||
debug_trap();
|
debug_trap();
|
||||||
}
|
}
|
||||||
|
handle_error(file, line, column, index, count);
|
||||||
|
}
|
||||||
|
|
||||||
slice_expr_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) {
|
slice_expr_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) {
|
||||||
if 0 <= lo && lo <= hi && hi <= len do return;
|
if 0 <= lo && lo <= hi && hi <= len do return;
|
||||||
|
handle_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) {
|
||||||
fd := os.stderr;
|
fd := os.stderr;
|
||||||
print_caller_location(fd, Source_Code_Location{file, line, column, ""});
|
print_caller_location(fd, Source_Code_Location{file, line, column, ""});
|
||||||
os.write_string(fd, " Invalid slice indices: ");
|
os.write_string(fd, " Invalid slice indices: ");
|
||||||
@@ -295,10 +299,12 @@ slice_expr_error :: proc "contextless" (file: string, line, column: int, lo, hi:
|
|||||||
os.write_byte(fd, '\n');
|
os.write_byte(fd, '\n');
|
||||||
debug_trap();
|
debug_trap();
|
||||||
}
|
}
|
||||||
|
handle_error(file, line, column, lo, hi, len);
|
||||||
|
}
|
||||||
|
|
||||||
dynamic_array_expr_error :: proc "contextless" (file: string, line, column: int, low, high, max: int) {
|
dynamic_array_expr_error :: proc "contextless" (file: string, line, column: int, low, high, max: int) {
|
||||||
if 0 <= low && low <= high && high <= max do return;
|
if 0 <= low && low <= high && high <= max do return;
|
||||||
|
handle_error :: proc "contextless" (file: string, line, column: int, low, high, max: int) {
|
||||||
fd := os.stderr;
|
fd := os.stderr;
|
||||||
print_caller_location(fd, Source_Code_Location{file, line, column, ""});
|
print_caller_location(fd, Source_Code_Location{file, line, column, ""});
|
||||||
os.write_string(fd, " Invalid dynamic array values: ");
|
os.write_string(fd, " Invalid dynamic array values: ");
|
||||||
@@ -310,11 +316,13 @@ dynamic_array_expr_error :: proc "contextless" (file: string, line, column: int,
|
|||||||
os.write_byte(fd, '\n');
|
os.write_byte(fd, '\n');
|
||||||
debug_trap();
|
debug_trap();
|
||||||
}
|
}
|
||||||
|
handle_error(file, line, column, low, high, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: int, from, to: typeid) {
|
type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: int, from, to: typeid) {
|
||||||
if ok do return;
|
if ok do return;
|
||||||
|
handle_error :: proc "contextless" (file: string, line, column: int, from, to: typeid) {
|
||||||
fd := os.stderr;
|
fd := os.stderr;
|
||||||
print_caller_location(fd, Source_Code_Location{file, line, column, ""});
|
print_caller_location(fd, Source_Code_Location{file, line, column, ""});
|
||||||
os.write_string(fd, " Invalid type assertion from ");
|
os.write_string(fd, " Invalid type assertion from ");
|
||||||
@@ -324,6 +332,8 @@ type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column
|
|||||||
os.write_byte(fd, '\n');
|
os.write_byte(fd, '\n');
|
||||||
debug_trap();
|
debug_trap();
|
||||||
}
|
}
|
||||||
|
handle_error(file, line, column, from, to);
|
||||||
|
}
|
||||||
|
|
||||||
string_decode_rune :: inline proc "contextless" (s: string) -> (rune, int) {
|
string_decode_rune :: inline proc "contextless" (s: string) -> (rune, int) {
|
||||||
return utf8.decode_rune_in_string(s);
|
return utf8.decode_rune_in_string(s);
|
||||||
@@ -342,9 +352,9 @@ dynamic_array_expr_error_loc :: inline proc "contextless" (using loc := #caller_
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
make_slice_error_loc :: inline proc "contextless" (using loc := #caller_location, len: int) {
|
make_slice_error_loc :: inline proc "contextless" (loc := #caller_location, len: int) {
|
||||||
if 0 <= len do return;
|
if 0 <= len do return;
|
||||||
|
handle_error :: proc "contextless" (loc: Source_Code_Location, len: int) {
|
||||||
fd := os.stderr;
|
fd := os.stderr;
|
||||||
print_caller_location(fd, loc);
|
print_caller_location(fd, loc);
|
||||||
os.write_string(fd, " Invalid slice length for make: ");
|
os.write_string(fd, " Invalid slice length for make: ");
|
||||||
@@ -352,10 +362,12 @@ make_slice_error_loc :: inline proc "contextless" (using loc := #caller_location
|
|||||||
os.write_byte(fd, '\n');
|
os.write_byte(fd, '\n');
|
||||||
debug_trap();
|
debug_trap();
|
||||||
}
|
}
|
||||||
|
handle_error(loc, len);
|
||||||
|
}
|
||||||
|
|
||||||
make_dynamic_array_error_loc :: inline proc "contextless" (using loc := #caller_location, len, cap: int) {
|
make_dynamic_array_error_loc :: inline proc "contextless" (using loc := #caller_location, len, cap: int) {
|
||||||
if 0 <= len && len <= cap do return;
|
if 0 <= len && len <= cap do return;
|
||||||
|
handle_error :: proc "contextless" (loc: Source_Code_Location, len, cap: int) {
|
||||||
fd := os.stderr;
|
fd := os.stderr;
|
||||||
print_caller_location(fd, loc);
|
print_caller_location(fd, loc);
|
||||||
os.write_string(fd, " Invalid dynamic array parameters for make: ");
|
os.write_string(fd, " Invalid dynamic array parameters for make: ");
|
||||||
@@ -365,10 +377,12 @@ make_dynamic_array_error_loc :: inline proc "contextless" (using loc := #caller_
|
|||||||
os.write_byte(fd, '\n');
|
os.write_byte(fd, '\n');
|
||||||
debug_trap();
|
debug_trap();
|
||||||
}
|
}
|
||||||
|
handle_error(loc, len, cap);
|
||||||
|
}
|
||||||
|
|
||||||
make_map_expr_error_loc :: inline proc "contextless" (using loc := #caller_location, cap: int) {
|
make_map_expr_error_loc :: inline proc "contextless" (loc := #caller_location, cap: int) {
|
||||||
if 0 <= cap do return;
|
if 0 <= cap do return;
|
||||||
|
handle_error :: proc "contextless" (loc: Source_Code_Location, cap: int) {
|
||||||
fd := os.stderr;
|
fd := os.stderr;
|
||||||
print_caller_location(fd, loc);
|
print_caller_location(fd, loc);
|
||||||
os.write_string(fd, " Invalid map capacity for make: ");
|
os.write_string(fd, " Invalid map capacity for make: ");
|
||||||
@@ -376,6 +390,8 @@ make_map_expr_error_loc :: inline proc "contextless" (using loc := #caller_locat
|
|||||||
os.write_byte(fd, '\n');
|
os.write_byte(fd, '\n');
|
||||||
debug_trap();
|
debug_trap();
|
||||||
}
|
}
|
||||||
|
handle_error(loc, cap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user