py: Implement compile builtin, enabled only on unix port.

This should be pretty compliant with CPython, except perhaps for some
corner cases to do with globals/locals context.

Addresses issue #879.
This commit is contained in:
Damien George
2014-10-25 21:59:14 +01:00
parent e5a3759ff5
commit c9fc620723
7 changed files with 106 additions and 3 deletions

View File

@@ -1189,6 +1189,13 @@ mp_obj_t mp_parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t parse_i
nlr_raise(module_fun);
}
// for compile only
if (MICROPY_PY_BUILTINS_COMPILE && globals == NULL) {
mp_globals_set(old_globals);
mp_locals_set(old_locals);
return module_fun;
}
// complied successfully, execute it
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {