5252#include "extmod/modplatform.h"
5353#include "extmod/vfs.h"
5454#include "extmod/vfs_posix.h"
55+ #include "shared/runtime/pyexec.h"
5556#include "genhdr/mpversion.h"
5657#include "input.h"
5758
@@ -87,11 +88,10 @@ static void stderr_print_strn(void *env, const char *str, size_t len) {
8788
8889const mp_print_t mp_stderr_print = {NULL , stderr_print_strn };
8990
90- #define FORCED_EXIT (0x100)
9191// If exc is SystemExit, return value where FORCED_EXIT bit set,
9292// and lower 8 bits are SystemExit value. For all other exceptions,
9393// return 1.
94- static int handle_uncaught_exception (mp_obj_base_t * exc ) {
94+ int pyexec_handle_uncaught_exception (mp_obj_base_t * exc ) {
9595 // check for SystemExit
9696 if (mp_obj_is_subclass_fast (MP_OBJ_FROM_PTR (exc -> type ), MP_OBJ_FROM_PTR (& mp_type_SystemExit ))) {
9797 // None is an exit value of 0; an int is its value; anything else is 1
@@ -100,7 +100,7 @@ static int handle_uncaught_exception(mp_obj_base_t *exc) {
100100 if (exit_val != mp_const_none && !mp_obj_get_int_maybe (exit_val , & val )) {
101101 val = 1 ;
102102 }
103- return FORCED_EXIT | (val & 255 );
103+ return PYEXEC_FORCED_EXIT | (val & 255 );
104104 }
105105
106106 // Report all other exceptions
@@ -171,7 +171,7 @@ static int execute_from_lexer(int source_kind, const void *source, mp_parse_inpu
171171 // uncaught exception
172172 mp_hal_set_interrupt_char (-1 );
173173 mp_handle_pending (false);
174- return handle_uncaught_exception (nlr .ret_val );
174+ return pyexec_handle_uncaught_exception (nlr .ret_val );
175175 }
176176}
177177
@@ -271,7 +271,7 @@ static int do_repl(void) {
271271 mp_hal_stdio_mode_orig ();
272272
273273 ret = execute_from_lexer (LEX_SRC_VSTR , & line , parse_input_kind , true);
274- if (ret & FORCED_EXIT ) {
274+ if (ret & PYEXEC_FORCED_EXIT ) {
275275 return ret ;
276276 }
277277 }
@@ -299,7 +299,7 @@ static int do_repl(void) {
299299
300300 int ret = execute_from_lexer (LEX_SRC_STR , line , MP_PARSE_SINGLE_INPUT , true);
301301 free (line );
302- if (ret & FORCED_EXIT ) {
302+ if (ret & PYEXEC_FORCED_EXIT ) {
303303 return ret ;
304304 }
305305 }
@@ -684,7 +684,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
684684 nlr_pop ();
685685 } else {
686686 // uncaught exception
687- return handle_uncaught_exception (nlr .ret_val ) & 0xff ;
687+ return pyexec_handle_uncaught_exception (nlr .ret_val ) & 0xff ;
688688 }
689689
690690 // If this module is a package, see if it has a `__main__.py`.
0 commit comments