aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-10-13 13:19:52 +0100
committergingerBill <bill@gingerbill.org>2018-10-13 13:19:52 +0100
commit42b42db67544f6037cfb3aac2d486161bc0e2147 (patch)
tree5b7bc7e04d2e59d9ca1beb7f8e774336cb4a0eb3
parent73e9dbbf8c4a68dc6c512eb2de568d59df046494 (diff)
Add `unimplemented` and `unreachable` procedures; make `os.exit` a diverging procedure
-rw-r--r--core/os/os_linux.odin4
-rw-r--r--core/os/os_osx.odin2
-rw-r--r--core/os/os_windows.odin2
-rw-r--r--core/runtime/core.odin22
-rw-r--r--src/ir.cpp9
5 files changed, 31 insertions, 8 deletions
diff --git a/core/os/os_linux.odin b/core/os/os_linux.odin
index 284b1e89a..4f6375701 100644
--- a/core/os/os_linux.odin
+++ b/core/os/os_linux.odin
@@ -139,7 +139,7 @@ foreign libc {
@(link_name="calloc") _unix_calloc :: proc(num, size: int) -> rawptr ---;
@(link_name="free") _unix_free :: proc(ptr: rawptr) ---;
@(link_name="realloc") _unix_realloc :: proc(ptr: rawptr, size: int) -> rawptr ---;
- @(link_name="getenv") _unix_getenv :: proc(cstring) -> cstring ---;
+ @(link_name="getenv") _unix_getenv :: proc(cstring) -> cstring --- -> !;
@(link_name="exit") _unix_exit :: proc(status: int) ---;
}
@@ -241,7 +241,7 @@ getenv :: proc(name: string) -> (string, bool) {
return string(cstr), true;
}
-exit :: proc(code: int) {
+exit :: proc(code: int) -> ! {
_unix_exit(code);
}
diff --git a/core/os/os_osx.odin b/core/os/os_osx.odin
index ae777db85..c4c78cb3c 100644
--- a/core/os/os_osx.odin
+++ b/core/os/os_osx.odin
@@ -255,7 +255,7 @@ getenv :: proc(name: string) -> (string, bool) {
return string(cstr), true;
}
-exit :: inline proc(code: int) {
+exit :: inline proc(code: int) -> ! {
_unix_exit(code);
}
diff --git a/core/os/os_windows.odin b/core/os/os_windows.odin
index 1ffb2206a..57a864395 100644
--- a/core/os/os_windows.odin
+++ b/core/os/os_windows.odin
@@ -245,7 +245,7 @@ heap_free :: proc(ptr: rawptr) {
}
-exit :: proc(code: int) {
+exit :: proc(code: int) -> ! {
win32.exit_process(u32(code));
}
diff --git a/core/runtime/core.odin b/core/runtime/core.odin
index fff510dfb..3b88a0412 100644
--- a/core/runtime/core.odin
+++ b/core/runtime/core.odin
@@ -590,6 +590,28 @@ panic :: proc "contextless" (message: string, loc := #caller_location) -> ! {
p("Panic", message, loc);
}
+@(builtin)
+unimplemented :: proc "contextless" (message := "", loc := #caller_location) -> ! {
+ p := context.assertion_failure_proc;
+ if p == nil {
+ p = default_assertion_failure_proc;
+ }
+ p("not yet implemented", message, loc);
+}
+
+@(builtin)
+unreachable :: proc "contextless" (message := "", loc := #caller_location) -> ! {
+ p := context.assertion_failure_proc;
+ if p == nil {
+ p = default_assertion_failure_proc;
+ }
+ if message != "" {
+ p("internal error", message, loc);
+ } else {
+ p("internal error", "entered unreachable code", loc);
+ }
+}
+
// Dynamic Array
diff --git a/src/ir.cpp b/src/ir.cpp
index b51b9c184..7ceda6c10 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -1645,6 +1645,10 @@ irValue *ir_emit_bitcast(irProcedure *proc, irValue *data, Type *type) {
return ir_emit(proc, ir_instr_conv(proc, irConv_bitcast, data, ir_type(data), type));
}
+void ir_emit_unreachable(irProcedure *proc) {
+ ir_emit(proc, ir_instr_unreachable(proc));
+}
+
irValue *ir_emit_transmute(irProcedure *proc, irValue *value, Type *t);
irValue *ir_address_from_load_or_generate_local(irProcedure *proc, irValue *val);
irValue *ir_emit_struct_ep(irProcedure *proc, irValue *s, i32 index);
@@ -1749,6 +1753,7 @@ irValue *ir_emit_call(irProcedure *p, irValue *value, Array<irValue *> args, Pro
if (abi_rt != results) {
result = ir_emit_transmute(p, result, rt);
}
+
return result;
}
@@ -1838,10 +1843,6 @@ void ir_close_scope(irProcedure *proc, irDeferExitKind kind, irBlock *block) {
-void ir_emit_unreachable(irProcedure *proc) {
- ir_emit(proc, ir_instr_unreachable(proc));
-}
-
void ir_emit_return(irProcedure *proc, irValue *v) {
ir_emit_defer_stmts(proc, irDeferExit_Return, nullptr);