88#include "py/repl.h"
99#include "py/runtime.h"
1010#include "py/stackctrl.h"
11+ #include "py/frozenmod.h"
1112#include "lib/utils/pyexec.h"
1213#include "gccollect.h"
1314#include "machine.h"
@@ -36,9 +37,18 @@ void do_str(const char *src, mp_parse_input_kind_t input_kind) {
3637 }
3738}
3839
40+ void do_frozen (const char * name ) {
41+ void * frozen_data ;
42+ int frozen_type = mp_find_frozen_module (name , strlen (name ), & frozen_data );
43+ if (frozen_type != MP_FROZEN_MPY )
44+ __fatal_error ("frozen_type != MP_FROZEN_MPY" );
45+
46+ mp_obj_t module_fun = mp_make_function_from_raw_code (frozen_data , MP_OBJ_NULL , MP_OBJ_NULL );
47+ mp_call_function_0 (module_fun );
48+ }
49+
3950int main (int argc , char * * argv ) {
4051 nlr_buf_t nlr ;
41- int code ;
4252
4353 if (nlr_push (& nlr ) == 0 ) {
4454 mp_stack_set_top ((uint8_t * ) & _estack );
@@ -57,28 +67,42 @@ int main(int argc, char **argv) {
5767 mp_obj_list_append (mp_sys_path , MP_OBJ_NEW_QSTR (MP_QSTR_ ));
5868 mp_obj_list_init (mp_sys_argv , 0 );
5969
60- code = pyexec_frozen_module ("bios.py" );
61- if (code != 1 ) {
62- // error or SystemExit
63- return 1 ;
64- } else {
65- // done, give interpreter for now
66- for (;;) {
67- if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL ) {
68- if (pyexec_raw_repl () != 0 ) {
69- break ;
70- }
71- } else {
72- if (pyexec_friendly_repl () != 0 ) {
73- break ;
74- }
70+ do_frozen ("bios.py" );
71+
72+ for (;;) {
73+ if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL ) {
74+ if (pyexec_raw_repl () != 0 ) {
75+ break ;
76+ }
77+ } else {
78+ if (pyexec_friendly_repl () != 0 ) {
79+ break ;
7580 }
7681 }
7782 }
7883
7984 nlr_pop ();
8085 } else {
81- mp_obj_print_exception (& debug_print , (mp_obj_t ) nlr .ret_val );
86+ nlr_buf_t nlr2 ;
87+ if (nlr_push (& nlr2 ) == 0 ) {
88+ vstr_t vstr ;
89+ mp_print_t print ;
90+ vstr_init_print (& vstr , 256 , & print );
91+
92+ mp_obj_print_exception (& print , (mp_obj_t ) nlr .ret_val );
93+ char * message = vstr_null_terminated_str (& vstr );
94+ __fatal_error (message );
95+ nlr_pop ();
96+ } else {
97+ vstr_t vstr ;
98+ mp_print_t print ;
99+ vstr_init_print (& vstr , 256 , & print );
100+
101+ mp_obj_print_helper (& print , (mp_obj_t ) nlr .ret_val , PRINT_EXC );
102+ char * message = vstr_null_terminated_str (& vstr );
103+ __fatal_error (message );
104+ }
105+
82106 mp_deinit ();
83107 }
84108
0 commit comments