5151#include "extmod/modplatform.h"
5252#include "extmod/vfs.h"
5353#include "extmod/vfs_posix.h"
54+ #include "shared/runtime/pyexec.h"
5455#include "genhdr/mpversion.h"
5556#include "input.h"
5657
@@ -86,11 +87,10 @@ static void stderr_print_strn(void *env, const char *str, size_t len) {
8687
8788const mp_print_t mp_stderr_print = {NULL , stderr_print_strn };
8889
89- #define FORCED_EXIT (0x100)
9090// If exc is SystemExit, return value where FORCED_EXIT bit set,
9191// and lower 8 bits are SystemExit value. For all other exceptions,
9292// return 1.
93- static int handle_uncaught_exception (mp_obj_base_t * exc ) {
93+ int pyexec_handle_uncaught_exception (mp_obj_base_t * exc ) {
9494 // check for SystemExit
9595 if (mp_obj_is_subclass_fast (MP_OBJ_FROM_PTR (exc -> type ), MP_OBJ_FROM_PTR (& mp_type_SystemExit ))) {
9696 // None is an exit value of 0; an int is its value; anything else is 1
@@ -99,7 +99,7 @@ static int handle_uncaught_exception(mp_obj_base_t *exc) {
9999 if (exit_val != mp_const_none && !mp_obj_get_int_maybe (exit_val , & val )) {
100100 val = 1 ;
101101 }
102- return FORCED_EXIT | (val & 255 );
102+ return PYEXEC_FORCED_EXIT | (val & 255 );
103103 }
104104
105105 // Report all other exceptions
@@ -170,7 +170,7 @@ static int execute_from_lexer(int source_kind, const void *source, mp_parse_inpu
170170 // uncaught exception
171171 mp_hal_set_interrupt_char (-1 );
172172 mp_handle_pending (false);
173- return handle_uncaught_exception (nlr .ret_val );
173+ return pyexec_handle_uncaught_exception (nlr .ret_val );
174174 }
175175}
176176
@@ -270,7 +270,7 @@ static int do_repl(void) {
270270 mp_hal_stdio_mode_orig ();
271271
272272 ret = execute_from_lexer (LEX_SRC_VSTR , & line , parse_input_kind , true);
273- if (ret & FORCED_EXIT ) {
273+ if (ret & PYEXEC_FORCED_EXIT ) {
274274 return ret ;
275275 }
276276 }
@@ -298,7 +298,7 @@ static int do_repl(void) {
298298
299299 int ret = execute_from_lexer (LEX_SRC_STR , line , MP_PARSE_SINGLE_INPUT , true);
300300 free (line );
301- if (ret & FORCED_EXIT ) {
301+ if (ret & PYEXEC_FORCED_EXIT ) {
302302 return ret ;
303303 }
304304 }
@@ -676,7 +676,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
676676 nlr_pop ();
677677 } else {
678678 // uncaught exception
679- return handle_uncaught_exception (nlr .ret_val ) & 0xff ;
679+ return pyexec_handle_uncaught_exception (nlr .ret_val ) & 0xff ;
680680 }
681681
682682 // If this module is a package, see if it has a `__main__.py`.
0 commit comments