From 436f43fa2667c77ef8a7d05bb5b8001c17c7822b Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 17 Jan 2025 23:32:18 +0000 Subject: Add support for native functions --- runtime/src/shed/namespaces/Shed/Builtins.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'runtime/src/shed/namespaces') diff --git a/runtime/src/shed/namespaces/Shed/Builtins.c b/runtime/src/shed/namespaces/Shed/Builtins.c index 142a1317..9efb4c62 100644 --- a/runtime/src/shed/namespaces/Shed/Builtins.c +++ b/runtime/src/shed/namespaces/Shed/Builtins.c @@ -24,8 +24,24 @@ ShedObject shed__runtime__print(ShedClosurePointer closurePointer, ShedString va return shed_unit; } +void wasi_proc_exit(uint32_t exitcode) + __attribute__(( + __import_module__("wasi_snapshot_preview1"), + __import_name__("proc_exit"), + )); + +ShedObject shed__runtime__namespace__Std__Process__exit( + ShedClosurePointer closurePointer, + ShedObject exitCode +) { + wasi_proc_exit(shed__runtime__int_value(exitCode)); + return shed_unit; +} + #else +#include + ShedObject shed__runtime__print(ShedClosurePointer closurePointer, ShedString value) { size_t total_bytes_written = 0; while (total_bytes_written < value->length) { @@ -38,6 +54,14 @@ ShedObject shed__runtime__print(ShedClosurePointer closurePointer, ShedString va return shed_unit; } +ShedObject shed__runtime__namespace__Std__Process__exit( + ShedClosurePointer closurePointer, + ShedObject exitCode +) { + exit(shed__runtime__int_value(exitCode)); + return shed_unit; +} + #endif ShedClosureStruct shed__runtime__print_closure = { -- cgit v1.2.3