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/ints.h | 8 ++++++++ runtime/src/shed/namespaces/Shed/Builtins.c | 24 ++++++++++++++++++++++++ runtime/src/shed/shed.h | 1 + 3 files changed, 33 insertions(+) create mode 100644 runtime/src/shed/ints.h (limited to 'runtime') diff --git a/runtime/src/shed/ints.h b/runtime/src/shed/ints.h new file mode 100644 index 00000000..c99579d8 --- /dev/null +++ b/runtime/src/shed/ints.h @@ -0,0 +1,8 @@ +#ifndef SHED_INTS_H +#define SHED_INTS_H + +#include "./primitives.h" + +PatioInt shed__runtime__int_value(ShedObject object); + +#endif 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 = { diff --git a/runtime/src/shed/shed.h b/runtime/src/shed/shed.h index ff44cd9c..1730a79b 100644 --- a/runtime/src/shed/shed.h +++ b/runtime/src/shed/shed.h @@ -2,6 +2,7 @@ #define SHED_H #include "./closures.h" +#include "./ints.h" #include "./primitives.h" #include "./strings.h" -- cgit v1.2.3