summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--py/nlr.h44
-rw-r--r--py/nlrthumb.c4
-rw-r--r--py/nlrx64.c4
-rw-r--r--py/nlrx86.c4
-rw-r--r--py/nlrxtensa.c4
5 files changed, 35 insertions, 25 deletions
diff --git a/py/nlr.h b/py/nlr.h
index 1235f1460..bd9fcc884 100644
--- a/py/nlr.h
+++ b/py/nlr.h
@@ -30,29 +30,28 @@
// exception handling, basically a stack of setjmp/longjmp buffers
#include <limits.h>
-#include <setjmp.h>
#include <assert.h>
#include "py/mpconfig.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; // always a concrete object (an exception instance)
-#if !defined(MICROPY_NLR_SETJMP) || !MICROPY_NLR_SETJMP
+// If MICROPY_NLR_SETJMP is not enabled then auto-detect the machine arch
+#if !MICROPY_NLR_SETJMP
#if defined(__i386__)
- void *regs[6];
+ #define MICROPY_NLR_X86 (1)
+ #define MICROPY_NLR_NUM_REGS (6)
#elif defined(__x86_64__)
- #if defined(__CYGWIN__)
- void *regs[12];
- #else
- void *regs[8];
- #endif
+ #define MICROPY_NLR_X64 (1)
+ #if defined(__CYGWIN__)
+ #define MICROPY_NLR_NUM_REGS (12)
+ #else
+ #define MICROPY_NLR_NUM_REGS (8)
+ #endif
#elif defined(__thumb2__) || defined(__thumb__) || defined(__arm__)
- void *regs[10];
+ #define MICROPY_NLR_THUMB (1)
+ #define MICROPY_NLR_NUM_REGS (10)
#elif defined(__xtensa__)
- void *regs[10];
+ #define MICROPY_NLR_XTENSA (1)
+ #define MICROPY_NLR_NUM_REGS (10)
#else
#define MICROPY_NLR_SETJMP (1)
//#warning "No native NLR support for this arch, using setjmp implementation"
@@ -60,9 +59,21 @@ struct _nlr_buf_t {
#endif
#if MICROPY_NLR_SETJMP
- jmp_buf jmpbuf;
+#include <setjmp.h>
#endif
+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; // always a concrete object (an exception instance)
+
+ #if MICROPY_NLR_SETJMP
+ jmp_buf jmpbuf;
+ #else
+ void *regs[MICROPY_NLR_NUM_REGS];
+ #endif
+
#if MICROPY_ENABLE_PYSTACK
void *pystack;
#endif
@@ -123,7 +134,6 @@ NORETURN void nlr_jump_fail(void *val);
/*
#define nlr_push(val) \
printf("nlr_push: before: nlr_top=%p, val=%p\n", MP_STATE_THREAD(nlr_top), val),assert(MP_STATE_THREAD(nlr_top) != val),nlr_push(val)
-#endif
*/
#endif
diff --git a/py/nlrthumb.c b/py/nlrthumb.c
index 18d31eb70..cc081e3ff 100644
--- a/py/nlrthumb.c
+++ b/py/nlrthumb.c
@@ -26,7 +26,7 @@
#include "py/mpstate.h"
-#if (!defined(MICROPY_NLR_SETJMP) || !MICROPY_NLR_SETJMP) && (defined(__thumb2__) || defined(__thumb__) || defined(__arm__))
+#if MICROPY_NLR_THUMB
#undef nlr_push
@@ -148,4 +148,4 @@ NORETURN void nlr_jump(void *val) {
#endif
}
-#endif // (!defined(MICROPY_NLR_SETJMP) || !MICROPY_NLR_SETJMP) && (defined(__thumb2__) || defined(__thumb__) || defined(__arm__))
+#endif // MICROPY_NLR_THUMB
diff --git a/py/nlrx64.c b/py/nlrx64.c
index ddcd76166..927b21591 100644
--- a/py/nlrx64.c
+++ b/py/nlrx64.c
@@ -26,7 +26,7 @@
#include "py/mpstate.h"
-#if !MICROPY_NLR_SETJMP && defined(__x86_64__)
+#if MICROPY_NLR_X64
#undef nlr_push
@@ -138,4 +138,4 @@ NORETURN void nlr_jump(void *val) {
for (;;); // needed to silence compiler warning
}
-#endif // !MICROPY_NLR_SETJMP && defined(__x86_64__)
+#endif // MICROPY_NLR_X64
diff --git a/py/nlrx86.c b/py/nlrx86.c
index 3a27460eb..0e03eef6f 100644
--- a/py/nlrx86.c
+++ b/py/nlrx86.c
@@ -26,7 +26,7 @@
#include "py/mpstate.h"
-#if !MICROPY_NLR_SETJMP && defined(__i386__)
+#if MICROPY_NLR_X86
#undef nlr_push
@@ -114,4 +114,4 @@ NORETURN void nlr_jump(void *val) {
for (;;); // needed to silence compiler warning
}
-#endif // !MICROPY_NLR_SETJMP && defined(__i386__)
+#endif // MICROPY_NLR_X86
diff --git a/py/nlrxtensa.c b/py/nlrxtensa.c
index 5a969fc87..73f14385d 100644
--- a/py/nlrxtensa.c
+++ b/py/nlrxtensa.c
@@ -26,7 +26,7 @@
#include "py/mpstate.h"
-#if !MICROPY_NLR_SETJMP && defined(__xtensa__)
+#if MICROPY_NLR_XTENSA
#undef nlr_push
@@ -101,4 +101,4 @@ NORETURN void nlr_jump(void *val) {
for (;;); // needed to silence compiler warning
}
-#endif // !MICROPY_NLR_SETJMP && defined(__xtensa__)
+#endif // MICROPY_NLR_XTENSA