aboutsummaryrefslogtreecommitdiff
path: root/runtime/src/patio/exceptions.c
blob: 23685d8c1ee6e28e27331d510e1bba492b62c45c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#ifndef __wasm__

#include <setjmp.h>
#include <stdint.h>
#include <stdlib.h>

#include "./patio.h"

PatioInt patio__runtime__exceptions_exception_value;
jmp_buf* patio__runtime__exceptions_exception_handler = 0;

void patio__runtime__exceptions_throw(uint32_t exception_tag, PatioInt 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