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.
This commit is contained in:
Damien George 2017-12-28 16:18:39 +11:00
parent 97cc485538
commit 5bf8e85fc8
5 changed files with 35 additions and 25 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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