diff options
author | Damien George <damien.p.george@gmail.com> | 2015-12-18 12:35:44 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-12-18 12:35:44 +0000 |
commit | dd5353a4054024a411aa343a22ffcd16195a16ad (patch) | |
tree | faa3f91ab3a37f1b2f3469e01a9228e83853dc7b /py/builtinimport.c | |
parent | ab8012bd8098e155e38ef6dead62bca8a200e613 (diff) |
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.
Diffstat (limited to 'py/builtinimport.c')
-rw-r--r-- | py/builtinimport.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/py/builtinimport.c b/py/builtinimport.c index a8d5f0696..2560ec156 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -120,6 +120,7 @@ STATIC mp_import_stat_t find_file(const char *file_str, uint file_len, vstr_t *d #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 @@ STATIC void do_load_from_lexer(mp_obj_t module_obj, mp_lexer_t *lex, const char 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_execute_raw_code(mp_obj_t module_obj, mp_raw_code_t *raw_code) { 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) { |