@@ -50,22 +50,33 @@ STATIC bool repl_display_debugging_info = 0;
5050#define EXEC_FLAG_PRINT_EOF (1)
5151#define EXEC_FLAG_ALLOW_DEBUGGING (2)
5252#define EXEC_FLAG_IS_REPL (4)
53+ #define EXEC_FLAG_SOURCE_IS_RAW_CODE (8)
5354
5455// parses, compiles and executes the code in the lexer
5556// frees the lexer before returning
5657// EXEC_FLAG_PRINT_EOF prints 2 EOF chars: 1 after normal output, 1 after exception output
5758// EXEC_FLAG_ALLOW_DEBUGGING allows debugging info to be printed after executing the code
5859// EXEC_FLAG_IS_REPL is used for REPL inputs (flag passed on to mp_compile)
59- STATIC int parse_compile_execute (mp_lexer_t * lex , mp_parse_input_kind_t input_kind , int exec_flags ) {
60+ STATIC int parse_compile_execute (void * source , mp_parse_input_kind_t input_kind , int exec_flags ) {
6061 int ret = 0 ;
6162 uint32_t start = 0 ;
6263
6364 nlr_buf_t nlr ;
6465 if (nlr_push (& nlr ) == 0 ) {
65- // parse and compile the script
66- qstr source_name = lex -> source_name ;
67- mp_parse_tree_t parse_tree = mp_parse (lex , input_kind );
68- mp_obj_t module_fun = mp_compile (& parse_tree , source_name , MP_EMIT_OPT_NONE , exec_flags & EXEC_FLAG_IS_REPL );
66+ mp_obj_t module_fun ;
67+ #if MICROPY_MODULE_FROZEN_MPY
68+ if (exec_flags & EXEC_FLAG_SOURCE_IS_RAW_CODE ) {
69+ // source is a raw_code object, create the function
70+ module_fun = mp_make_function_from_raw_code (source , MP_OBJ_NULL , MP_OBJ_NULL );
71+ } else
72+ #endif
73+ {
74+ // source is a lexer, parse and compile the script
75+ mp_lexer_t * lex = source ;
76+ qstr source_name = lex -> source_name ;
77+ mp_parse_tree_t parse_tree = mp_parse (lex , input_kind );
78+ module_fun = mp_compile (& parse_tree , source_name , MP_EMIT_OPT_NONE , exec_flags & EXEC_FLAG_IS_REPL );
79+ }
6980
7081 // execute code
7182 mp_hal_set_interrupt_char (CHAR_CTRL_C ); // allow ctrl-C to interrupt us
@@ -488,14 +499,24 @@ int pyexec_file(const char *filename) {
488499
489500#if MICROPY_MODULE_FROZEN
490501int pyexec_frozen_module (const char * name ) {
491- mp_lexer_t * lex = mp_find_frozen_module (name , strlen (name ));
502+ void * frozen_data ;
503+ int frozen_type = mp_find_frozen_module (name , strlen (name ), & frozen_data );
492504
493- if (lex == NULL ) {
494- printf ("could not find module '%s'\n" , name );
495- return false;
496- }
505+ switch (frozen_type ) {
506+ #if MICROPY_MODULE_FROZEN_STR
507+ case MP_FROZEN_STR :
508+ return parse_compile_execute (frozen_data , MP_PARSE_FILE_INPUT , 0 );
509+ #endif
497510
498- return parse_compile_execute (lex , MP_PARSE_FILE_INPUT , 0 );
511+ #if MICROPY_MODULE_FROZEN_MPY
512+ case MP_FROZEN_MPY :
513+ return parse_compile_execute (frozen_data , MP_PARSE_FILE_INPUT , EXEC_FLAG_SOURCE_IS_RAW_CODE );
514+ #endif
515+
516+ default :
517+ printf ("could not find module '%s'\n" , name );
518+ return false;
519+ }
499520}
500521#endif
501522
0 commit comments