Skip to content

Commit a1c3416

Browse files
committed
bricks/_common/micropython: Include REPL starter only when needed.
This saves 70 more bytes on Move Hub.
1 parent 4775a08 commit a1c3416

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

bricks/_common/micropython.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ static void mp_vfs_map_minimal_new_reader(mp_reader_t *reader, mp_vfs_map_minima
9696
reader->close = mp_vfs_map_minimal_close;
9797
}
9898

99+
#if PYBRICKS_OPT_COMPILER
99100
static void run_repl() {
100-
#if MICROPY_ENABLE_COMPILER
101101
// Reset REPL history.
102102
readline_init0();
103103
nlr_buf_t nlr;
@@ -111,10 +111,8 @@ static void run_repl() {
111111
// Print which exception triggered this.
112112
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
113113
}
114-
#else
115-
mp_hal_stdout_tx_str("REPL not supported!\r\n");
116-
#endif
117114
}
115+
#endif
118116

119117
// From micropython/py/builtinimport.c, but copied because it is static.
120118
static void do_execute_raw_code(mp_module_context_t *context, const mp_raw_code_t *rc, const mp_module_context_t *mc) {
@@ -233,6 +231,7 @@ static void run_user_program(void) {
233231
// Print which exception triggered this.
234232
mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val);
235233

234+
#if PYBRICKS_OPT_COMPILER
236235
// On KeyboardInterrupt, drop to REPL for debugging.
237236
if (mp_obj_exception_match((mp_obj_t)nlr.ret_val, &mp_type_KeyboardInterrupt)) {
238237

@@ -244,6 +243,7 @@ static void run_user_program(void) {
244243
// Enter REPL.
245244
run_repl();
246245
}
246+
#endif
247247
}
248248
}
249249

@@ -271,18 +271,21 @@ void pbsys_main_run_program(pbsys_main_program_t *program) {
271271
// Initialize MicroPython.
272272
mp_init();
273273

274-
// For MicroPython, the builtin program is the REPL.
275-
if (program->run_builtin) {
276-
// Init Pybricks package and auto-import everything.
277-
pb_package_pybricks_init(true);
278-
279-
// Start the REPL.
280-
run_repl();
281-
} else {
274+
// Check for run type.
275+
if (!program->run_builtin) {
282276
// Init Pybricks package without auto-import.
283277
pb_package_pybricks_init(false);
278+
// Run loaded program.
284279
run_user_program();
285280
}
281+
#if PYBRICKS_OPT_COMPILER
282+
else {
283+
// For MicroPython, the builtin program is the REPL.
284+
// Run it with everything auto-imported.
285+
pb_package_pybricks_init(true);
286+
run_repl();
287+
}
288+
#endif // PYBRICKS_OPT_COMPILER
286289

287290
// Clean up non-MicroPython resources used by the pybricks package.
288291
pb_package_pybricks_deinit();

0 commit comments

Comments
 (0)