@@ -137,7 +137,14 @@ STATIC mp_obj_t eval_exec_helper(mp_uint_t n_args, const mp_obj_t *args, mp_pars
137137 const char * str = mp_obj_str_get_data (args [0 ], & str_len );
138138
139139 // create the lexer
140- mp_lexer_t * lex = mp_lexer_new_from_str_len (MP_QSTR__lt_string_gt_ , str , str_len , 0 );
140+ // MP_PARSE_SINGLE_INPUT is used to indicate a file input
141+ mp_lexer_t * lex ;
142+ if (MICROPY_PY_BUILTINS_EXECFILE && parse_input_kind == MP_PARSE_SINGLE_INPUT ) {
143+ lex = mp_lexer_new_from_file (str );
144+ parse_input_kind = MP_PARSE_FILE_INPUT ;
145+ } else {
146+ lex = mp_lexer_new_from_str_len (MP_QSTR__lt_string_gt_ , str , str_len , 0 );
147+ }
141148
142149 return mp_parse_compile_execute (lex , parse_input_kind , globals , locals );
143150}
@@ -151,3 +158,11 @@ STATIC mp_obj_t mp_builtin_exec(mp_uint_t n_args, const mp_obj_t *args) {
151158 return eval_exec_helper (n_args , args , MP_PARSE_FILE_INPUT );
152159}
153160MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (mp_builtin_exec_obj , 1 , 3 , mp_builtin_exec );
161+
162+ #if MICROPY_PY_BUILTINS_EXECFILE
163+ STATIC mp_obj_t mp_builtin_execfile (mp_uint_t n_args , const mp_obj_t * args ) {
164+ // MP_PARSE_SINGLE_INPUT is used to indicate a file input
165+ return eval_exec_helper (n_args , args , MP_PARSE_SINGLE_INPUT );
166+ }
167+ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (mp_builtin_execfile_obj , 1 , 3 , mp_builtin_execfile );
168+ #endif
0 commit comments