Move all os specific stuff for the runtime to one file

This commit is contained in:
gingerBill
2020-09-15 12:19:56 +01:00
parent 17b3c2ed4c
commit 9d91c46cb4
5 changed files with 272 additions and 151 deletions
+28 -31
View File
@@ -1,8 +1,5 @@
package runtime
import "core:os"
bounds_trap :: proc "contextless" () -> ! {
when ODIN_OS == "windows" {
windows_trap_array_bounds();
@@ -24,13 +21,13 @@ bounds_check_error :: proc "contextless" (file: string, line, column: int, index
if 0 <= index && index < count do return;
handle_error :: proc "contextless" (file: string, line, column: int, index, count: int) {
context = default_context();
fd := os.stderr;
fd := os_stderr();
print_caller_location(fd, Source_Code_Location{file, line, column, "", 0});
os.write_string(fd, " Index ");
print_string(fd, " Index ");
print_i64(fd, i64(index));
os.write_string(fd, " is out of bounds range 0:");
print_string(fd, " is out of bounds range 0:");
print_i64(fd, i64(count));
os.write_byte(fd, '\n');
print_byte(fd, '\n');
bounds_trap();
}
handle_error(file, line, column, index, count);
@@ -38,15 +35,15 @@ bounds_check_error :: proc "contextless" (file: string, line, column: int, index
slice_handle_error :: proc "contextless" (file: string, line, column: int, lo, hi: int, len: int) {
context = default_context();
fd := os.stderr;
fd := os_stderr();
print_caller_location(fd, Source_Code_Location{file, line, column, "", 0});
os.write_string(fd, " Invalid slice indices: ");
print_string(fd, " Invalid slice indices: ");
print_i64(fd, i64(lo));
os.write_string(fd, ":");
print_string(fd, ":");
print_i64(fd, i64(hi));
os.write_string(fd, ":");
print_string(fd, ":");
print_i64(fd, i64(len));
os.write_byte(fd, '\n');
print_byte(fd, '\n');
bounds_trap();
}
@@ -64,15 +61,15 @@ dynamic_array_expr_error :: proc "contextless" (file: string, line, column: int,
if 0 <= low && low <= high && high <= max do return;
handle_error :: proc "contextless" (file: string, line, column: int, low, high, max: int) {
context = default_context();
fd := os.stderr;
fd := os_stderr();
print_caller_location(fd, Source_Code_Location{file, line, column, "", 0});
os.write_string(fd, " Invalid dynamic array values: ");
print_string(fd, " Invalid dynamic array values: ");
print_i64(fd, i64(low));
os.write_string(fd, ":");
print_string(fd, ":");
print_i64(fd, i64(high));
os.write_string(fd, ":");
print_string(fd, ":");
print_i64(fd, i64(max));
os.write_byte(fd, '\n');
print_byte(fd, '\n');
bounds_trap();
}
handle_error(file, line, column, low, high, max);
@@ -83,13 +80,13 @@ type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column
if ok do return;
handle_error :: proc "contextless" (file: string, line, column: int, from, to: typeid) {
context = default_context();
fd := os.stderr;
fd := os_stderr();
print_caller_location(fd, Source_Code_Location{file, line, column, "", 0});
os.write_string(fd, " Invalid type assertion from ");
print_string(fd, " Invalid type assertion from ");
print_typeid(fd, from);
os.write_string(fd, " to ");
print_string(fd, " to ");
print_typeid(fd, to);
os.write_byte(fd, '\n');
print_byte(fd, '\n');
type_assertion_trap();
}
handle_error(file, line, column, from, to);
@@ -99,11 +96,11 @@ make_slice_error_loc :: inline proc "contextless" (loc := #caller_location, len:
if 0 <= len do return;
handle_error :: proc "contextless" (loc: Source_Code_Location, len: int) {
context = default_context();
fd := os.stderr;
fd := os_stderr();
print_caller_location(fd, loc);
os.write_string(fd, " Invalid slice length for make: ");
print_string(fd, " Invalid slice length for make: ");
print_i64(fd, i64(len));
os.write_byte(fd, '\n');
print_byte(fd, '\n');
bounds_trap();
}
handle_error(loc, len);
@@ -113,13 +110,13 @@ make_dynamic_array_error_loc :: inline proc "contextless" (using loc := #caller_
if 0 <= len && len <= cap do return;
handle_error :: proc "contextless" (loc: Source_Code_Location, len, cap: int) {
context = default_context();
fd := os.stderr;
fd := os_stderr();
print_caller_location(fd, loc);
os.write_string(fd, " Invalid dynamic array parameters for make: ");
print_string(fd, " Invalid dynamic array parameters for make: ");
print_i64(fd, i64(len));
os.write_byte(fd, ':');
print_byte(fd, ':');
print_i64(fd, i64(cap));
os.write_byte(fd, '\n');
print_byte(fd, '\n');
bounds_trap();
}
handle_error(loc, len, cap);
@@ -129,11 +126,11 @@ make_map_expr_error_loc :: inline proc "contextless" (loc := #caller_location, c
if 0 <= cap do return;
handle_error :: proc "contextless" (loc: Source_Code_Location, cap: int) {
context = default_context();
fd := os.stderr;
fd := os_stderr();
print_caller_location(fd, loc);
os.write_string(fd, " Invalid map capacity for make: ");
print_string(fd, " Invalid map capacity for make: ");
print_i64(fd, i64(cap));
os.write_byte(fd, '\n');
print_byte(fd, '\n');
bounds_trap();
}
handle_error(loc, cap);