py/compile: Add mp_compile_to_raw_code() to return raw code object.
This can then be passed to mp_raw_code_save_file to save a .mpy file.
This commit is contained in:
parent
f5c554dfe3
commit
d4dba88236
14
py/compile.c
14
py/compile.c
|
@ -3090,7 +3090,10 @@ STATIC void scope_compute_things(scope_t *scope) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t mp_compile(mp_parse_tree_t *parse_tree, qstr source_file, uint emit_opt, bool is_repl) {
|
#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) {
|
||||||
// put compiler state on the stack, it's relatively small
|
// put compiler state on the stack, it's relatively small
|
||||||
compiler_t comp_state = {0};
|
compiler_t comp_state = {0};
|
||||||
compiler_t *comp = &comp_state;
|
compiler_t *comp = &comp_state;
|
||||||
|
@ -3263,7 +3266,12 @@ mp_obj_t mp_compile(mp_parse_tree_t *parse_tree, qstr source_file, uint emit_opt
|
||||||
if (comp->compile_error != MP_OBJ_NULL) {
|
if (comp->compile_error != MP_OBJ_NULL) {
|
||||||
nlr_raise(comp->compile_error);
|
nlr_raise(comp->compile_error);
|
||||||
} else {
|
} else {
|
||||||
// return function that executes the outer module
|
return outer_raw_code;
|
||||||
return mp_make_function_from_raw_code(outer_raw_code, MP_OBJ_NULL, MP_OBJ_NULL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
// return function that executes the outer module
|
||||||
|
return mp_make_function_from_raw_code(rc, MP_OBJ_NULL, MP_OBJ_NULL);
|
||||||
|
}
|
||||||
|
|
|
@ -43,6 +43,11 @@ enum {
|
||||||
// the compiler will clear the parse tree before it returns
|
// the compiler will clear the parse tree before it returns
|
||||||
mp_obj_t mp_compile(mp_parse_tree_t *parse_tree, qstr source_file, uint emit_opt, bool is_repl);
|
mp_obj_t mp_compile(mp_parse_tree_t *parse_tree, qstr source_file, uint emit_opt, bool is_repl);
|
||||||
|
|
||||||
|
#if MICROPY_PERSISTENT_CODE_SAVE
|
||||||
|
// this has the same semantics as mp_compile
|
||||||
|
mp_raw_code_t *mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_file, uint emit_opt, bool is_repl);
|
||||||
|
#endif
|
||||||
|
|
||||||
// this is implemented in runtime.c
|
// this is implemented in runtime.c
|
||||||
mp_obj_t mp_parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t parse_input_kind, mp_obj_dict_t *globals, mp_obj_dict_t *locals);
|
mp_obj_t mp_parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t parse_input_kind, mp_obj_dict_t *globals, mp_obj_dict_t *locals);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue