aboutsummaryrefslogtreecommitdiff
path: root/py/compile.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-08-23 11:20:50 +1000
committerDamien George <damien.p.george@gmail.com>2019-08-28 12:47:58 +1000
commitaf20c2ead3e9bb397fdf89e316aa78b56f165013 (patch)
tree99cc8c752d6347dc9f0d6dccb6e11384626bd278 /py/compile.c
parent8e3e05761e1143a2502c7eca07c1b22bac192c84 (diff)
py: Add global default_emit_opt variable to make emit kind persistent.
mp_compile no longer takes an emit_opt argument, rather this setting is now provided by the global default_emit_opt variable. Now, when -X emit=native is passed as a command-line option, the emitter will be set for all compiled modules (included imports), not just the top-level script. In the future there could be a way to also set this variable from a script. Fixes issue #4267.
Diffstat (limited to 'py/compile.c')
-rw-r--r--py/compile.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/py/compile.c b/py/compile.c
index c0ae3de11..829472c0d 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -3437,7 +3437,7 @@ STATIC void scope_compute_things(scope_t *scope) {
#if !MICROPY_PERSISTENT_CODE_SAVE
STATIC
#endif
-mp_raw_code_t *mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_file, uint emit_opt, bool is_repl) {
+mp_raw_code_t *mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_file, bool is_repl) {
// put compiler state on the stack, it's relatively small
compiler_t comp_state = {0};
compiler_t *comp = &comp_state;
@@ -3448,6 +3448,11 @@ mp_raw_code_t *mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_f
comp->continue_label = INVALID_LABEL;
// create the module scope
+ #if MICROPY_EMIT_NATIVE
+ const uint emit_opt = MP_STATE_VM(default_emit_opt);
+ #else
+ const uint emit_opt = MP_EMIT_OPT_NONE;
+ #endif
scope_t *module_scope = scope_new_and_link(comp, SCOPE_MODULE, parse_tree->root, emit_opt);
// create standard emitter; it's used at least for MP_PASS_SCOPE
@@ -3602,8 +3607,8 @@ mp_raw_code_t *mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_f
}
}
-mp_obj_t mp_compile(mp_parse_tree_t *parse_tree, qstr source_file, uint emit_opt, bool is_repl) {
- mp_raw_code_t *rc = mp_compile_to_raw_code(parse_tree, source_file, emit_opt, is_repl);
+mp_obj_t mp_compile(mp_parse_tree_t *parse_tree, qstr source_file, bool is_repl) {
+ mp_raw_code_t *rc = mp_compile_to_raw_code(parse_tree, source_file, is_repl);
// return function that executes the outer module
return mp_make_function_from_raw_code(rc, MP_OBJ_NULL, MP_OBJ_NULL);
}