@@ -63,7 +63,7 @@ bool mp_obj_is_package(mp_obj_t module) {
6363// Stat either frozen or normal module by a given path
6464// (whatever is available, if at all).
6565STATIC mp_import_stat_t mp_import_stat_any (const char * path ) {
66- #if MICROPY_MODULE_FROZEN_STR
66+ #if MICROPY_MODULE_FROZEN
6767 mp_import_stat_t st = mp_frozen_stat (path );
6868 if (st != MP_IMPORT_STAT_NO_EXIST ) {
6969 return st ;
@@ -194,10 +194,37 @@ STATIC void do_execute_raw_code(mp_obj_t module_obj, mp_raw_code_t *raw_code) {
194194#endif
195195
196196STATIC void do_load (mp_obj_t module_obj , vstr_t * file ) {
197- #if MICROPY_PERSISTENT_CODE_LOAD || MICROPY_ENABLE_COMPILER
197+ #if MICROPY_MODULE_FROZEN || MICROPY_PERSISTENT_CODE_LOAD || MICROPY_ENABLE_COMPILER
198198 char * file_str = vstr_null_terminated_str (file );
199199 #endif
200200
201+ // If we support frozen modules (either as str or mpy) then try to find the
202+ // requested filename in the list of frozen module filenames.
203+ #if MICROPY_MODULE_FROZEN
204+ void * modref ;
205+ int frozen_type = mp_find_frozen_module (file_str , file -> len , & modref );
206+ #endif
207+
208+ // If we support frozen str modules and the compiler is enabled, and we
209+ // found the filename in the list of frozen files, then load and execute it.
210+ #if MICROPY_MODULE_FROZEN_STR
211+ if (frozen_type == MP_FROZEN_STR ) {
212+ do_load_from_lexer (module_obj , modref , file_str );
213+ return ;
214+ }
215+ #endif
216+
217+ // If we support frozen mpy modules and we found a corresponding file (and
218+ // its data) in the list of frozen files, execute it.
219+ #if MICROPY_MODULE_FROZEN_MPY
220+ if (frozen_type == MP_FROZEN_MPY ) {
221+ do_execute_raw_code (module_obj , modref );
222+ return ;
223+ }
224+ #endif
225+
226+ // If we support loading .mpy files then check if the file extension is of
227+ // the correct format and, if so, load and execute the file.
201228 #if MICROPY_PERSISTENT_CODE_LOAD
202229 if (file_str [file -> len - 3 ] == 'm' ) {
203230 mp_raw_code_t * raw_code = mp_raw_code_load_file (file_str );
@@ -206,29 +233,18 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
206233 }
207234 #endif
208235
236+ // If we can compile scripts then load the file and compile and execute it.
209237 #if MICROPY_ENABLE_COMPILER
210238 {
211- void * modref ;
212- #if MICROPY_MODULE_FROZEN
213- int frozen_type = mp_find_frozen_module (file_str , file -> len , & modref );
214- #else
215- int frozen_type = MP_FROZEN_NONE ;
216- #endif
217- #if MICROPY_PERSISTENT_CODE_LOAD || MICROPY_MODULE_FROZEN_MPY
218- if (frozen_type == MP_FROZEN_MPY ) {
219- do_execute_raw_code (module_obj , modref );
220- return ;
221- }
222- #endif
223- if (frozen_type == MP_FROZEN_NONE ) {
224- modref = mp_lexer_new_from_file (file_str );
225- }
226- do_load_from_lexer (module_obj , modref , file_str );
239+ mp_lexer_t * lex = mp_lexer_new_from_file (file_str );
240+ do_load_from_lexer (module_obj , lex , file_str );
241+ return ;
227242 }
228- #else
243+ #endif
244+
245+ // If we get here then the file was not frozen and we can't compile scripts.
229246 nlr_raise (mp_obj_new_exception_msg_varg (& mp_type_ImportError ,
230247 "script compilation not supported" ));
231- #endif
232248}
233249
234250STATIC void chop_component (const char * start , const char * * end ) {
0 commit comments