1616
1717// TODO need to mangle __attr names
1818
19+ #define MICROPY_EMIT_NATIVE (MICROPY_EMIT_X64 || MICROPY_EMIT_THUMB)
20+
1921typedef enum {
2022 PN_none = 0 ,
2123#define DEF_RULE(rule, comp, kind, arg...) PN_##rule,
@@ -853,16 +855,19 @@ static bool compile_built_in_decorator(compiler_t *comp, int name_len, py_parse_
853855 }
854856
855857 qstr attr = PY_PARSE_NODE_LEAF_ARG (name_nodes [1 ]);
856- if (attr == comp -> qstr_native ) {
858+ if (0 ) {
859+ #if MICROPY_EMIT_NATIVE
860+ } else if (attr == comp -> qstr_native ) {
857861 * emit_options = EMIT_OPT_NATIVE_PYTHON ;
858862 } else if (attr == comp -> qstr_viper ) {
859863 * emit_options = EMIT_OPT_VIPER ;
864+ #endif
860865#if MICROPY_EMIT_INLINE_THUMB
861866 } else if (attr == comp -> qstr_asm_thumb ) {
862867 * emit_options = EMIT_OPT_ASM_THUMB ;
863868#endif
864869 } else {
865- printf ("SyntaxError: invalid micropython decorator\n" );
870+ printf ("SyntaxError: invalid micropython decorator '%s' \n" , qstr_str ( attr ) );
866871 }
867872
868873 return true;
@@ -1302,37 +1307,44 @@ void compile_while_stmt(compiler_t *comp, py_parse_node_struct_t *pns) {
13021307 int old_break_label = comp -> break_label ;
13031308 int old_continue_label = comp -> continue_label ;
13041309
1305- int done_label = comp_next_label (comp );
1306- int end_label = comp_next_label (comp );
13071310 int break_label = comp_next_label (comp );
13081311 int continue_label = comp_next_label (comp );
13091312
13101313 comp -> break_label = break_label ;
13111314 comp -> continue_label = continue_label ;
13121315
1313- EMIT (setup_loop , end_label );
1316+ // compared to CPython, we have an optimised version of while loops
1317+ #if MICROPY_EMIT_CPYTHON
1318+ int done_label = comp_next_label (comp );
1319+ EMIT (setup_loop , break_label );
13141320 EMIT (label_assign , continue_label );
13151321 c_if_cond (comp , pns -> nodes [0 ], false, done_label ); // condition
13161322 compile_node (comp , pns -> nodes [1 ]); // body
13171323 if (!EMIT (last_emit_was_return_value )) {
13181324 EMIT (jump , continue_label );
13191325 }
13201326 EMIT (label_assign , done_label );
1321-
1322- // break/continue apply to outer loop (if any) in the else block
1323- comp -> break_label = old_break_label ;
1324- comp -> continue_label = old_continue_label ;
1325-
13261327 // CPython does not emit POP_BLOCK if the condition was a constant; don't undertand why
13271328 // this is a small hack to agree with CPython
13281329 if (!node_is_const_true (pns -> nodes [0 ])) {
13291330 EMIT (pop_block );
13301331 }
1332+ #else
1333+ int top_label = comp_next_label (comp );
1334+ EMIT (jump , continue_label );
1335+ EMIT (label_assign , top_label );
1336+ compile_node (comp , pns -> nodes [1 ]); // body
1337+ EMIT (label_assign , continue_label );
1338+ c_if_cond (comp , pns -> nodes [0 ], true, top_label ); // condition
1339+ #endif
1340+
1341+ // break/continue apply to outer loop (if any) in the else block
1342+ comp -> break_label = old_break_label ;
1343+ comp -> continue_label = old_continue_label ;
13311344
13321345 compile_node (comp , pns -> nodes [2 ]); // else
13331346
13341347 EMIT (label_assign , break_label );
1335- EMIT (label_assign , end_label );
13361348}
13371349
13381350void compile_for_stmt (compiler_t * comp , py_parse_node_struct_t * pns ) {
@@ -1348,7 +1360,11 @@ void compile_for_stmt(compiler_t *comp, py_parse_node_struct_t *pns) {
13481360 comp -> continue_label = for_label ;
13491361 comp -> break_label = break_label ;
13501362
1363+ // I don't think our implementation needs SETUP_LOOP/POP_BLOCK for for-statements
1364+ #if MICROPY_EMIT_CPYTHON
13511365 EMIT (setup_loop , end_label );
1366+ #endif
1367+
13521368 compile_node (comp , pns -> nodes [1 ]); // iterator
13531369 EMIT (get_iter );
13541370 EMIT (label_assign , for_label );
@@ -1365,7 +1381,9 @@ void compile_for_stmt(compiler_t *comp, py_parse_node_struct_t *pns) {
13651381 comp -> break_label = old_break_label ;
13661382 comp -> continue_label = old_continue_label ;
13671383
1384+ #if MICROPY_EMIT_CPYTHON
13681385 EMIT (pop_block );
1386+ #endif
13691387
13701388 compile_node (comp , pns -> nodes [3 ]); // else (not tested)
13711389
0 commit comments