diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-11-28 19:44:36 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-11-28 21:53:27 +0000 |
| commit | 53079bcb98247079ebf03c83b491b17fc2e46eba (patch) | |
| tree | b2e9f4824e45ca3c0203d24c5d2c5a30d3bd37e5 /runtime/src | |
| parent | 0020edc8158445d408a8ed198e1e3fdd78b6454b (diff) | |
Support simple try/throw in LLVM backend
Diffstat (limited to 'runtime/src')
| -rw-r--r-- | runtime/src/exceptions.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/runtime/src/exceptions.c b/runtime/src/exceptions.c new file mode 100644 index 00000000..deaaa25b --- /dev/null +++ b/runtime/src/exceptions.c @@ -0,0 +1,25 @@ +#ifndef __WASM__ + +#include <setjmp.h> +#include <stdint.h> +#include <stdlib.h> + +uint32_t patio__runtime__exceptions_exception_value; +jmp_buf* patio__runtime__exceptions_exception_handler = 0; + +void patio__runtime__exceptions_throw(uint32_t exception_tag, uint64_t value) { + if (patio__runtime__exceptions_exception_handler == 0) { + exit(1); + } + patio__runtime__exceptions_exception_value = value; + _longjmp(*patio__runtime__exceptions_exception_handler, exception_tag); +} + +void patio__runtime__exceptions_rethrow(uint32_t exception_tag) { + if (patio__runtime__exceptions_exception_handler == 0) { + exit(1); + } + _longjmp(*patio__runtime__exceptions_exception_handler, exception_tag); +} + +#endif |
