py: Add MICROPY_ENABLE_COMPILER and MICROPY_PY_BUILTINS_EVAL_EXEC opts.
MICROPY_ENABLE_COMPILER can be used to enable/disable the entire compiler,
which is useful when only loading of pre-compiled bytecode is supported.
It is enabled by default.
MICROPY_PY_BUILTINS_EVAL_EXEC controls support of eval and exec builtin
functions. By default they are only included if MICROPY_ENABLE_COMPILER
is enabled.
Disabling both options saves about 40k of code size on 32-bit x86.
diff --git a/py/builtinimport.c b/py/builtinimport.c
index a8d5f06..2560ec1 100644
--- a/py/builtinimport.c
+++ b/py/builtinimport.c
@@ -120,6 +120,7 @@
#endif
}
+#if MICROPY_ENABLE_COMPILER
STATIC void do_load_from_lexer(mp_obj_t module_obj, mp_lexer_t *lex, const char *fname) {
if (lex == NULL) {
@@ -141,6 +142,7 @@
mp_obj_dict_t *mod_globals = mp_obj_module_get_globals(module_obj);
mp_parse_compile_execute(lex, MP_PARSE_FILE_INPUT, mod_globals, mod_globals);
}
+#endif
#if MICROPY_PERSISTENT_CODE_LOAD
STATIC void do_execute_raw_code(mp_obj_t module_obj, mp_raw_code_t *raw_code) {
@@ -182,16 +184,24 @@
STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
// create the lexer
char *file_str = vstr_null_terminated_str(file);
+
#if MICROPY_PERSISTENT_CODE_LOAD
if (file_str[file->len - 3] == 'm') {
mp_raw_code_t *raw_code = mp_raw_code_load_file(file_str);
do_execute_raw_code(module_obj, raw_code);
- } else
+ return;
+ }
#endif
+
+ #if MICROPY_ENABLE_COMPILER
{
mp_lexer_t *lex = mp_lexer_new_from_file(file_str);
do_load_from_lexer(module_obj, lex, file_str);
}
+ #else
+ nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ImportError,
+ "script compilation not supported"));
+ #endif
}
STATIC void chop_component(const char *start, const char **end) {