From c7195c4bc5a43f0aae731f3030961b60d1db4cac Mon Sep 17 00:00:00 2001 From: Thea Flowers Date: Tue, 29 Oct 2019 10:11:19 -0700 Subject: [PATCH] Allow boards to enable the `micropython.native` decorator Adds the `CIRCUITPY_ENABLE_MPY_NATIVE` for `mpconfigboard.mk` that enables the `micropython.native` decorator. --- .../boards/winterbloom_sol/mpconfigboard.mk | 3 +++ py/circuitpy_mpconfig.h | 4 ++-- py/circuitpy_mpconfig.mk | 7 +++++++ py/compile.c | 2 +- py/emitnative.c | 18 ++++++++++++++++++ py/objfun.c | 2 ++ 6 files changed, 33 insertions(+), 3 deletions(-) diff --git a/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk b/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk index 19917898b..aa94af6a4 100644 --- a/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk +++ b/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk @@ -25,3 +25,6 @@ CIRCUITPY_I2CSLAVE = 0 CIRCUITPY_NETWORK = 0 CIRCUITPY_TOUCHIO = 0 CIRCUITPY_PS2IO = 0 + +# Enable micropython.native +CIRCUITPY_ENABLE_MPY_NATIVE = 1 diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 2cb617819..b1e7bc05a 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -56,8 +56,8 @@ #define MICROPY_COMP_MODULE_CONST (1) #define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0) #define MICROPY_DEBUG_PRINTERS (0) -#define MICROPY_EMIT_INLINE_THUMB (0) -#define MICROPY_EMIT_THUMB (0) +#define MICROPY_EMIT_INLINE_THUMB (CIRCUITPY_ENABLE_MPY_NATIVE) +#define MICROPY_EMIT_THUMB (CIRCUITPY_ENABLE_MPY_NATIVE) #define MICROPY_EMIT_X64 (0) #define MICROPY_ENABLE_DOC_STRING (0) #define MICROPY_ENABLE_FINALISER (1) diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index ac79d32d0..c1199571b 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -294,3 +294,10 @@ ifndef CIRCUITPY_BITBANG_APA102 CIRCUITPY_BITBANG_APA102 = 0 endif CFLAGS += -DCIRCUITPY_BITBANG_APA102=$(CIRCUITPY_BITBANG_APA102) + + +# Enabled micropython.native decorator (experimental) +ifndef CIRCUITPY_ENABLE_MPY_NATIVE +CIRCUITPY_ENABLE_MPY_NATIVE = 0 +endif +CFLAGS += -DCIRCUITPY_ENABLE_MPY_NATIVE=$(CIRCUITPY_ENABLE_MPY_NATIVE) diff --git a/py/compile.c b/py/compile.c index 1218aa07e..8b17935bd 100644 --- a/py/compile.c +++ b/py/compile.c @@ -3207,7 +3207,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind } if (pass > MP_PASS_SCOPE) { mp_int_t bytesize = MP_PARSE_NODE_LEAF_SMALL_INT(pn_arg[0]); - for (uint j = 1; j < n_args; j++) { + for (int j = 1; j < n_args; j++) { if (!MP_PARSE_NODE_IS_SMALL_INT(pn_arg[j])) { compile_syntax_error(comp, nodes[i], translate("'data' requires integer arguments")); return; diff --git a/py/emitnative.c b/py/emitnative.c index 67b0025c6..6d23bf097 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -58,6 +58,22 @@ #define DEBUG_printf(...) (void)0 #endif +#ifndef N_X64 + #define N_X64 (0) +#endif +#ifndef N_X86 + #define N_X86 (0) +#endif +#ifndef N_THUMB + #define N_THUMB (0) +#endif +#ifndef N_ARM + #define N_ARM (0) +#endif +#ifndef N_XTENSA + #define N_XTENSA (0) +#endif + // wrapper around everything in this file #if N_X64 || N_X86 || N_THUMB || N_ARM || N_XTENSA @@ -443,10 +459,12 @@ STATIC void emit_native_end_pass(emit_t *emit) { type_sig |= (emit->local_vtype[i] & 0xf) << (i * 4 + 4); } + #pragma GCC diagnostic ignored "-Wcast-align" mp_emit_glue_assign_native(emit->scope->raw_code, emit->do_viper_types ? MP_CODE_NATIVE_VIPER : MP_CODE_NATIVE_PY, f, f_len, (mp_uint_t*)((byte*)f + emit->const_table_offset), emit->scope->num_pos_args, emit->scope->scope_flags, type_sig); + #pragma GCC diagnostic pop } } diff --git a/py/objfun.c b/py/objfun.c index b8364815b..fd55e532a 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -546,7 +546,9 @@ STATIC mp_uint_t convert_obj_for_inline_asm(mp_obj_t obj) { STATIC mp_obj_t fun_asm_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_obj_fun_asm_t *self = self_in; + #pragma GCC diagnostic ignored "-Wint-conversion" mp_arg_check_num(n_args, n_kw, self->n_args, self->n_args, false); + #pragma GCC diagnostic pop void *fun = MICROPY_MAKE_POINTER_CALLABLE(self->fun_data);