From 35c868e9fbe91f62e7bcd3e34a5d14a1503a1f12 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sat, 11 Dec 2021 22:54:29 -0600 Subject: [PATCH] added os.exit --- core/os/os.onyx | 3 +++ core/runtime/onyx_run.onyx | 2 +- modules/onyx_runtime/onyx_runtime.c | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/os/os.onyx b/core/os/os.onyx index 5aac907a..23c77f80 100644 --- a/core/os/os.onyx +++ b/core/os/os.onyx @@ -41,3 +41,6 @@ list_directory :: (path: str) -> Iterator(DirectoryEntry) { return .{ c, next, close }; } +exit :: (exitcode: i32) { + runtime.__exit(exitcode); +} \ No newline at end of file diff --git a/core/runtime/onyx_run.onyx b/core/runtime/onyx_run.onyx index 43530fb3..1b2c6d84 100644 --- a/core/runtime/onyx_run.onyx +++ b/core/runtime/onyx_run.onyx @@ -14,7 +14,7 @@ __output_string :: (s: str) -> u32 { return wrote; } -__exit :: (status: i32) --- +__exit :: (status: i32) -> void #foreign "onyx_runtime" "__exit" --- __read_from_input :: (buffer: [] u8) -> i32 { err, read := io.stream_read(^__stdin, buffer); diff --git a/modules/onyx_runtime/onyx_runtime.c b/modules/onyx_runtime/onyx_runtime.c index 906c4c75..1be097d6 100644 --- a/modules/onyx_runtime/onyx_runtime.c +++ b/modules/onyx_runtime/onyx_runtime.c @@ -754,6 +754,11 @@ ONYX_DEF(__process_destroy, (WASM_I64), ()) { return NULL; } +ONYX_DEF(__exit, (WASM_I32), ()) { + exit(params->data[0].of.i32); + return NULL; +} + ONYX_LIBRARY { ONYX_FUNC(__file_open_impl) ONYX_FUNC(__file_close) @@ -780,5 +785,6 @@ ONYX_LIBRARY { ONYX_FUNC(__process_wait) ONYX_FUNC(__process_destroy) + ONYX_FUNC(__exit) NULL }; \ No newline at end of file -- 2.25.1