From 53079bcb98247079ebf03c83b491b17fc2e46eba Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 28 Nov 2023 19:44:36 +0000 Subject: Support simple try/throw in LLVM backend --- runtime/meson.build | 1 + runtime/src/exceptions.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 runtime/src/exceptions.c (limited to 'runtime') diff --git a/runtime/meson.build b/runtime/meson.build index 489aea7b..41b9382b 100644 --- a/runtime/meson.build +++ b/runtime/meson.build @@ -2,6 +2,7 @@ project('shed-runtime', 'c', default_options : ['warning_level=1']) static_library( 'shed', 'src/effects.c', + 'src/exceptions.c', 'src/shed.c', 'src/strings.c', 'src/namespaces/Shed/Builtins.c', 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 +#include +#include + +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 -- cgit v1.2.3