py/objcode: Factor code object out into its own file.
The `mp_obj_code_t` and `mp_type_code` code object was defined internally in both `py/builtinevex.c` and `py/profile.c`, with completely different implementations (the former very minimal, the latter quite complete). This commit factors these implementations into a new, separate source file, and allows the code object to have four different modes, selected at compile-time: - MICROPY_PY_BUILTINS_CODE_NONE: code object not included in the build. - MICROPY_PY_BUILTINS_CODE_MINIMUM: very simple code object that just holds a reference to the function that it represents. This level is used when MICROPY_PY_BUILTINS_COMPILE is enabled. - MICROPY_PY_BUILTINS_CODE_BASIC: simple code object that holds a reference to the proto-function and its constants. - MICROPY_PY_BUILTINS_CODE_FULL: almost complete implementation of the code object. This level is used when MICROPY_PY_SYS_SETTRACE is enabled. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -30,6 +30,9 @@
|
||||
#include "py/parse.h"
|
||||
#include "py/emitglue.h"
|
||||
|
||||
// Whether mp_compile_to_raw_code is exposed as a public function.
|
||||
#define MICROPY_EXPOSE_MP_COMPILE_TO_RAW_CODE (MICROPY_PY_BUILTINS_CODE >= MICROPY_PY_BUILTINS_CODE_BASIC || MICROPY_PERSISTENT_CODE_SAVE)
|
||||
|
||||
#if MICROPY_COMP_ALLOW_TOP_LEVEL_AWAIT
|
||||
// set to `true` to allow top-level await expressions
|
||||
extern bool mp_compile_allow_top_level_await;
|
||||
@@ -40,7 +43,7 @@ extern bool mp_compile_allow_top_level_await;
|
||||
// mp_globals_get() will be used for the context
|
||||
mp_obj_t mp_compile(mp_parse_tree_t *parse_tree, qstr source_file, bool is_repl);
|
||||
|
||||
#if MICROPY_PERSISTENT_CODE_SAVE
|
||||
#if MICROPY_EXPOSE_MP_COMPILE_TO_RAW_CODE
|
||||
// this has the same semantics as mp_compile
|
||||
void mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_file, bool is_repl, mp_compiled_module_t *cm);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user