@@ -36,12 +36,6 @@ typedef enum {
3636#define EMIT_INLINE_ASM (fun ) (comp->emit_inline_asm_method_table->fun(comp->emit_inline_asm))
3737#define EMIT_INLINE_ASM_ARG (fun , ...) (comp->emit_inline_asm_method_table->fun(comp->emit_inline_asm, __VA_ARGS__))
3838
39- #define EMIT_OPT_NONE (0)
40- #define EMIT_OPT_BYTE_CODE (1)
41- #define EMIT_OPT_NATIVE_PYTHON (2)
42- #define EMIT_OPT_VIPER (3)
43- #define EMIT_OPT_ASM_THUMB (4)
44-
4539typedef struct _compiler_t {
4640 qstr source_file ;
4741 bool is_repl ;
@@ -1000,16 +994,16 @@ STATIC bool compile_built_in_decorator(compiler_t *comp, int name_len, mp_parse_
1000994
1001995 qstr attr = MP_PARSE_NODE_LEAF_ARG (name_nodes [1 ]);
1002996 if (attr == MP_QSTR_byte_code ) {
1003- * emit_options = EMIT_OPT_BYTE_CODE ;
997+ * emit_options = MP_EMIT_OPT_BYTE_CODE ;
1004998#if MICROPY_EMIT_NATIVE
1005999 } else if (attr == MP_QSTR_native ) {
1006- * emit_options = EMIT_OPT_NATIVE_PYTHON ;
1000+ * emit_options = MP_EMIT_OPT_NATIVE_PYTHON ;
10071001 } else if (attr == MP_QSTR_viper ) {
1008- * emit_options = EMIT_OPT_VIPER ;
1002+ * emit_options = MP_EMIT_OPT_VIPER ;
10091003#endif
10101004#if MICROPY_EMIT_INLINE_THUMB
10111005 } else if (attr == MP_QSTR_asm_thumb ) {
1012- * emit_options = EMIT_OPT_ASM_THUMB ;
1006+ * emit_options = MP_EMIT_OPT_ASM_THUMB ;
10131007#endif
10141008 } else {
10151009 compile_syntax_error (comp , "invalid micropython decorator" );
@@ -1601,7 +1595,7 @@ void compile_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
16011595 // this bit optimises: for <x> in range(...), turning it into an explicitly incremented variable
16021596 // this is actually slower, but uses no heap memory
16031597 // for viper it will be much, much faster
1604- if (/*comp->scope_cur->emit_options == EMIT_OPT_VIPER &&*/ MP_PARSE_NODE_IS_ID (pns -> nodes [0 ]) && MP_PARSE_NODE_IS_STRUCT_KIND (pns -> nodes [1 ], PN_power )) {
1598+ if (/*comp->scope_cur->emit_options == MP_EMIT_OPT_VIPER &&*/ MP_PARSE_NODE_IS_ID (pns -> nodes [0 ]) && MP_PARSE_NODE_IS_STRUCT_KIND (pns -> nodes [1 ], PN_power )) {
16051599 mp_parse_node_struct_t * pns_it = (mp_parse_node_struct_t * )pns -> nodes [1 ];
16061600 if (MP_PARSE_NODE_IS_ID (pns_it -> nodes [0 ])
16071601 && MP_PARSE_NODE_LEAF_ARG (pns_it -> nodes [0 ]) == MP_QSTR_range
@@ -3187,7 +3181,7 @@ void compile_scope_compute_things(compiler_t *comp, scope_t *scope) {
31873181 }
31883182}
31893183
3190- mp_obj_t mp_compile (mp_parse_node_t pn , qstr source_file , bool is_repl ) {
3184+ mp_obj_t mp_compile (mp_parse_node_t pn , qstr source_file , uint emit_opt , bool is_repl ) {
31913185 compiler_t * comp = m_new (compiler_t , 1 );
31923186
31933187 comp -> source_file = source_file ;
@@ -3208,7 +3202,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, bool is_repl) {
32083202 pn = fold_constants (pn );
32093203
32103204 // set the outer scope
3211- scope_t * module_scope = scope_new_and_link (comp , SCOPE_MODULE , pn , EMIT_OPT_NONE );
3205+ scope_t * module_scope = scope_new_and_link (comp , SCOPE_MODULE , pn , emit_opt );
32123206
32133207 // compile pass 1
32143208 comp -> emit = emit_pass1_new ();
@@ -3219,7 +3213,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, bool is_repl) {
32193213 for (scope_t * s = comp -> scope_head ; s != NULL && !comp -> had_error ; s = s -> next ) {
32203214 if (false) {
32213215#if MICROPY_EMIT_INLINE_THUMB
3222- } else if (s -> emit_options == EMIT_OPT_ASM_THUMB ) {
3216+ } else if (s -> emit_options == MP_EMIT_OPT_ASM_THUMB ) {
32233217 compile_scope_inline_asm (comp , s , PASS_1 );
32243218#endif
32253219 } else {
@@ -3255,7 +3249,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, bool is_repl) {
32553249 // dummy
32563250
32573251#if MICROPY_EMIT_INLINE_THUMB
3258- } else if (s -> emit_options == EMIT_OPT_ASM_THUMB ) {
3252+ } else if (s -> emit_options == MP_EMIT_OPT_ASM_THUMB ) {
32593253 // inline assembly for thumb
32603254 if (emit_inline_thumb == NULL ) {
32613255 emit_inline_thumb = emit_inline_thumb_new (max_num_labels );
@@ -3279,8 +3273,8 @@ mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, bool is_repl) {
32793273 switch (s -> emit_options ) {
32803274
32813275#if MICROPY_EMIT_NATIVE
3282- case EMIT_OPT_NATIVE_PYTHON :
3283- case EMIT_OPT_VIPER :
3276+ case MP_EMIT_OPT_NATIVE_PYTHON :
3277+ case MP_EMIT_OPT_VIPER :
32843278#if MICROPY_EMIT_X64
32853279 if (emit_native == NULL ) {
32863280 emit_native = emit_native_x64_new (max_num_labels );
@@ -3293,7 +3287,7 @@ mp_obj_t mp_compile(mp_parse_node_t pn, qstr source_file, bool is_repl) {
32933287 comp -> emit_method_table = & emit_native_thumb_method_table ;
32943288#endif
32953289 comp -> emit = emit_native ;
3296- comp -> emit_method_table -> set_native_types (comp -> emit , s -> emit_options == EMIT_OPT_VIPER );
3290+ comp -> emit_method_table -> set_native_types (comp -> emit , s -> emit_options == MP_EMIT_OPT_VIPER );
32973291 break ;
32983292#endif // MICROPY_EMIT_NATIVE
32993293
0 commit comments