nlr.h 931 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
// non-local return
// exception handling, basically a stack of setjmp/longjmp buffers

#include <limits.h>

typedef struct _nlr_buf_t nlr_buf_t;
struct _nlr_buf_t {
    // the entries here must all be machine word size
    nlr_buf_t *prev;
    void *ret_val;
11
#if defined(__i386__)
12
    void *regs[6];
13
#elif defined(__x86_64__)
14
15
16
  #if defined(__CYGWIN__)
    void *regs[12];
  #else
17
    void *regs[8];
18
  #endif
19
#elif defined(__thumb2__)
20
    void *regs[10];
21
22
#else
#error Unknown arch in nlr.h
23
24
25
26
#endif
};

unsigned int nlr_push(nlr_buf_t *);
27
void nlr_pop(void);
28
void nlr_jump(void *val) __attribute__((noreturn));
29
30
31
32
33
34
35
36
37
38
39
40
41

// use nlr_raise instead of nlr_jump so that debugging is easier
#ifndef DEBUG
#define nlr_raise(val) nlr_jump(val)
#else
#define nlr_raise(val) \
    do { \
        void *_val = val; \
        assert(_val != NULL); \
        assert(mp_obj_is_exception_instance(_val)); \
        nlr_jump(_val); \
    } while (0)
#endif