Skip to content

Commit 9115667

Browse files
authored
Merge pull request #2271 from theacodes/enable-micropython-native
Allow boards to enable the `micropython.native` decorator
2 parents 147a1bb + 3439c36 commit 9115667

File tree

6 files changed

+32
-4
lines changed

6 files changed

+32
-4
lines changed

ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ CIRCUITPY_I2CSLAVE = 0
2525
CIRCUITPY_NETWORK = 0
2626
CIRCUITPY_TOUCHIO = 0
2727
CIRCUITPY_PS2IO = 0
28+
29+
# Enable micropython.native
30+
CIRCUITPY_ENABLE_MPY_NATIVE = 1

py/circuitpy_mpconfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
#define MICROPY_COMP_MODULE_CONST (1)
5757
#define MICROPY_COMP_TRIPLE_TUPLE_ASSIGN (0)
5858
#define MICROPY_DEBUG_PRINTERS (0)
59-
#define MICROPY_EMIT_INLINE_THUMB (0)
60-
#define MICROPY_EMIT_THUMB (0)
59+
#define MICROPY_EMIT_INLINE_THUMB (CIRCUITPY_ENABLE_MPY_NATIVE)
60+
#define MICROPY_EMIT_THUMB (CIRCUITPY_ENABLE_MPY_NATIVE)
6161
#define MICROPY_EMIT_X64 (0)
6262
#define MICROPY_ENABLE_DOC_STRING (0)
6363
#define MICROPY_ENABLE_FINALISER (1)

py/circuitpy_mpconfig.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,10 @@ ifndef CIRCUITPY_BITBANG_APA102
294294
CIRCUITPY_BITBANG_APA102 = 0
295295
endif
296296
CFLAGS += -DCIRCUITPY_BITBANG_APA102=$(CIRCUITPY_BITBANG_APA102)
297+
298+
299+
# Enabled micropython.native decorator (experimental)
300+
ifndef CIRCUITPY_ENABLE_MPY_NATIVE
301+
CIRCUITPY_ENABLE_MPY_NATIVE = 0
302+
endif
303+
CFLAGS += -DCIRCUITPY_ENABLE_MPY_NATIVE=$(CIRCUITPY_ENABLE_MPY_NATIVE)

py/compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3207,7 +3207,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind
32073207
}
32083208
if (pass > MP_PASS_SCOPE) {
32093209
mp_int_t bytesize = MP_PARSE_NODE_LEAF_SMALL_INT(pn_arg[0]);
3210-
for (uint j = 1; j < n_args; j++) {
3210+
for (int j = 1; j < n_args; j++) {
32113211
if (!MP_PARSE_NODE_IS_SMALL_INT(pn_arg[j])) {
32123212
compile_syntax_error(comp, nodes[i], translate("'data' requires integer arguments"));
32133213
return;

py/emitnative.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@
5858
#define DEBUG_printf(...) (void)0
5959
#endif
6060

61+
#ifndef N_X64
62+
#define N_X64 (0)
63+
#endif
64+
#ifndef N_X86
65+
#define N_X86 (0)
66+
#endif
67+
#ifndef N_THUMB
68+
#define N_THUMB (0)
69+
#endif
70+
#ifndef N_ARM
71+
#define N_ARM (0)
72+
#endif
73+
#ifndef N_XTENSA
74+
#define N_XTENSA (0)
75+
#endif
76+
6177
// wrapper around everything in this file
6278
#if N_X64 || N_X86 || N_THUMB || N_ARM || N_XTENSA
6379

@@ -443,10 +459,12 @@ STATIC void emit_native_end_pass(emit_t *emit) {
443459
type_sig |= (emit->local_vtype[i] & 0xf) << (i * 4 + 4);
444460
}
445461

462+
#pragma GCC diagnostic ignored "-Wcast-align"
446463
mp_emit_glue_assign_native(emit->scope->raw_code,
447464
emit->do_viper_types ? MP_CODE_NATIVE_VIPER : MP_CODE_NATIVE_PY,
448465
f, f_len, (mp_uint_t*)((byte*)f + emit->const_table_offset),
449466
emit->scope->num_pos_args, emit->scope->scope_flags, type_sig);
467+
#pragma GCC diagnostic pop
450468
}
451469
}
452470

py/objfun.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ STATIC mp_uint_t convert_obj_for_inline_asm(mp_obj_t obj) {
546546
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) {
547547
mp_obj_fun_asm_t *self = self_in;
548548

549-
mp_arg_check_num(n_args, n_kw, self->n_args, self->n_args, false);
549+
mp_arg_check_num_kw_array(n_args, n_kw, self->n_args, self->n_args, false);
550550

551551
void *fun = MICROPY_MAKE_POINTER_CALLABLE(self->fun_data);
552552

0 commit comments

Comments
 (0)