Skip to content

Commit cc00859

Browse files
authored
Merge pull request #2282 from theacodes/native-if-available
Make the @micropython.native decorator no-op if support isn't enabled
2 parents f7426e0 + 84e1d7f commit cc00859

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

py/compile.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,13 +775,22 @@ STATIC bool compile_built_in_decorator(compiler_t *comp, int name_len, mp_parse_
775775
qstr attr = MP_PARSE_NODE_LEAF_ARG(name_nodes[1]);
776776
if (attr == MP_QSTR_bytecode) {
777777
*emit_options = MP_EMIT_OPT_BYTECODE;
778-
#if MICROPY_EMIT_NATIVE
778+
// @micropython.native decorator.
779779
} else if (attr == MP_QSTR_native) {
780+
// Different from MicroPython: native doesn't raise SyntaxError if native support isn't
781+
// compiled, it just passes through the function unmodified.
782+
#if MICROPY_EMIT_NATIVE
780783
*emit_options = MP_EMIT_OPT_NATIVE_PYTHON;
784+
#else
785+
return true;
786+
#endif
787+
#if MICROPY_EMIT_NATIVE
788+
// @micropython.viper decorator.
781789
} else if (attr == MP_QSTR_viper) {
782790
*emit_options = MP_EMIT_OPT_VIPER;
783-
#endif
791+
#endif
784792
#if MICROPY_EMIT_INLINE_ASM
793+
// @micropython.asm_thumb decorator.
785794
} else if (attr == ASM_DECORATOR_QSTR) {
786795
*emit_options = MP_EMIT_OPT_ASM;
787796
#endif

0 commit comments

Comments
 (0)