8000 py/nlr: Clean up selection and config of NLR implementation. · neverhover/micropython@5bf8e85 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5bf8e85

Browse files
committed
py/nlr: Clean up selection and config of NLR implementation.
If MICROPY_NLR_SETJMP is not enabled and the machine is auto-detected then nlr.h now defines some convenience macros for the individual NLR implementations to use (eg MICROPY_NLR_THUMB). This keeps nlr.h and the implementation in sync, and also makes the nlr_buf_t struct easier to read.
1 parent 97cc485 commit 5bf8e85

File tree

5 files changed

+35
-25
lines changed

5 files changed

+35
-25
lines changed

py/nlr.h

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,39 +30,50 @@
3030
// exception handling, basically a stack of setjmp/longjmp buffers
3131

3232
#include <limits.h>
33-
#include <setjmp.h>
3433
#include <assert.h>
3534

3635
#include "py/mpconfig.h"
3736

38-
typedef struct _nlr_buf_t nlr_buf_t;
39-
struct _nlr_buf_t {
40-
// the entries here must all be machine word size
41-
nlr_buf_t *prev;
42-
void *ret_val; // always a concrete object (an exception instance)
43-
#if !defined(MICROPY_NLR_SETJMP) || !MICROPY_NLR_SETJMP
37+
// If MICROPY_NLR_SETJMP is not enabled then auto-detect the machine arch
38+
#if !MICROPY_NLR_SETJMP
4439
#if defined(__i386__)
45-
void *regs[6];
40+
#define MICROPY_NLR_X86 (1)
41+
#define MICROPY_NLR_NUM_REGS (6)
4642
#elif defined(__x86_64__)
47-
#if defined(__CYGWIN__)
48-
void *regs[12];
49-
#else
50-
void *regs[8];
51-
#endif
43+
#define MICROPY_NLR_X64 (1)
44+
#if defined(__CYGWIN__)
45+
#define MICROPY_NLR_NUM_REGS (12)
46+
#else
47+
#define MICROPY_NLR_NUM_REGS (8)
48+
#endif
5249
#elif defined(__thumb2__) || defined(__thumb__) || defined(__arm__)
53-
void *regs[10];
50+
#define MICROPY_NLR_THUMB (1)
51+
#define MICROPY_NLR_NUM_REGS (10)
5452
#elif defined(__xtensa__)
55-
void *regs[10];
53+
#define MICROPY_NLR_XTENSA (1)
54+
#define MICROPY_NLR_NUM_REGS (10)
5655
#else
5756
#define MICROPY_NLR_SETJMP (1)
5857
//#warning "No native NLR support for this arch, using setjmp implementation"
5958
#endif
6059
#endif
6160

6261
#if MICROPY_NLR_SETJMP
63-
jmp_buf jmpbuf;
62+
#include <setjmp.h>
6463
#endif
6564

65+
typedef struct _nlr_buf_t nlr_buf_t;
66+
struct _nlr_buf_t {
67+
// the entries here must all be machine word size
68+
nlr_buf_t *prev;
69+
void *ret_val; // always a concrete object (an exception instance)
70+
71+
#if MICROPY_NLR_SETJMP
72+
jmp_buf jmpbuf;
73+
#else
74+
void *regs[MICROPY_NLR_NUM_REGS];
75+
#endif
76+
6677
#if MICROPY_ENABLE_PYSTACK
6778
void *pystack;
6879
#endif
@@ -123,7 +134,6 @@ NORETURN void nlr_jump_fail(void *val);
123134
/*
124135
#define nlr_push(val) \
125136
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)
126-
#endif
127137
*/
128138
#endif
129139

py/nlrthumb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include "py/mpstate.h"
2828

29-
#if (!defined(MICROPY_NLR_SETJMP) || !MICROPY_NLR_SETJMP) && (defined(__thumb2__) || defined(__thumb__) || defined(__arm__))
29+
#if MICROPY_NLR_THUMB
3030

3131
#undef nlr_push
3232

@@ -148,4 +148,4 @@ NORETURN void nlr_jump(void *val) {
148148
#endif
149149
}
150150

151-
#endif // (!defined(MICROPY_NLR_SETJMP) || !MICROPY_NLR_SETJMP) && (defined(__thumb2__) || defined(__thumb__) || defined(__arm__))
151+
#endif // MICROPY_NLR_THUMB

py/nlrx64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include "py/mpstate.h"
2828

29-
#if !MICROPY_NLR_SETJMP && defined(__x86_64__)
29+
#if MICROPY_NLR_X64
3030

3131
#undef nlr_push
3232

@@ -138,4 +138,4 @@ NORETURN void nlr_jump(void *val) {
138138
for (;;); // needed to silence compiler warning
139139
}
140140

141-
#endif // !MICROPY_NLR_SETJMP && defined(__x86_64__)
141+
#endif // MICROPY_NLR_X64

py/nlrx86.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include "py/mpstate.h"
2828

29-
#if !MICROPY_NLR_SETJMP && defined(__i386__)
29+
#if MICROPY_NLR_X86
3030

3131
#undef nlr_push
3232

@@ -114,4 +114,4 @@ NORETURN void nlr_jump(void *val) {
114114
for (;;); // needed to silence compiler warning
115115
}
116116

117-
#endif // !MICROPY_NLR_SETJMP && defined(__i386__)
117+
#endif // MICROPY_NLR_X86

py/nlrxtensa.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
#include "py/mpstate.h"
2828

29-
#if !MICROPY_NLR_SETJMP && defined(__xtensa__)
29+
#if MICROPY_NLR_XTENSA
3030

3131
#undef nlr_push
3232

@@ -101,4 +101,4 @@ NORETURN void nlr_jump(void *val) {
101101
for (;;); // needed to silence compiler warning
102102
}
103103

104-
#endif // !MICROPY_NLR_SETJMP && defined(__xtensa__)
104+
#endif // MICROPY_NLR_XTENSA

0 commit comments

Comments
 (0)
0