diff options
| author | Michael Williamson <mike@zwobble.org> | 2025-01-17 23:32:18 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2025-01-17 23:32:18 +0000 |
| commit | 436f43fa2667c77ef8a7d05bb5b8001c17c7822b (patch) | |
| tree | 364fece3c5f4833713b1fd7d6e9f1a99dc8dd0a0 /runtime | |
| parent | 7c5489a16401738969f87bd1a5d89d0e1e736f99 (diff) | |
Add support for native functions
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/src/shed/ints.h | 8 | ||||
| -rw-r--r-- | runtime/src/shed/namespaces/Shed/Builtins.c | 24 | ||||
| -rw-r--r-- | runtime/src/shed/shed.h | 1 |
3 files changed, 33 insertions, 0 deletions
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 <stdlib.h> + 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" |
