diff options
author | Damien George <damien.p.george@gmail.com> | 2015-12-26 12:32:33 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-12-26 12:32:33 +0000 |
commit | 84b245f187f9711357b1fd46bebc67266bd028e5 (patch) | |
tree | 1df85f4a6a32cd2742ec0ff1690ff4afa919f7d9 /lib/utils/pyexec.c | |
parent | 7203b58e876cffe9bb7246e17c206e7b4280f701 (diff) |
lib/utils: Add pyexec_frozen_module to load and execute frozen module.
This is a convenience function similar to pyexec_file. It should be used
instead of raw mp_parse_compile_execute because the latter does not catch
and report exceptions.
Diffstat (limited to 'lib/utils/pyexec.c')
-rw-r--r-- | lib/utils/pyexec.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/utils/pyexec.c b/lib/utils/pyexec.c index 295d05943..5e90b77d4 100644 --- a/lib/utils/pyexec.c +++ b/lib/utils/pyexec.c @@ -27,12 +27,14 @@ #include <stdlib.h> #include <stdio.h> #include <stdint.h> +#include <string.h> #include "py/nlr.h" #include "py/compile.h" #include "py/runtime.h" #include "py/repl.h" #include "py/gc.h" +#include "py/frozenmod.h" #include "py/mphal.h" #if defined(USE_DEVICE_MODE) #include "irq.h" @@ -476,6 +478,19 @@ int pyexec_file(const char *filename) { return parse_compile_execute(lex, MP_PARSE_FILE_INPUT, 0); } +#if MICROPY_MODULE_FROZEN +int pyexec_frozen_module(const char *name) { + mp_lexer_t *lex = mp_find_frozen_module(name, strlen(name)); + + if (lex == NULL) { + printf("could not find module '%s'\n", name); + return false; + } + + return parse_compile_execute(lex, MP_PARSE_FILE_INPUT, 0); +} +#endif + mp_obj_t pyb_set_repl_info(mp_obj_t o_value) { repl_display_debugging_info = mp_obj_get_int(o_value); return mp_const_none; |