lib/utils/pyexec: Introduce MICROPY_REPL_INFO, wrap debug prints in it.
For the 3 ports that already make use of this feature (stm32, nrf and teensy) this doesn't make any difference, it just allows to disable it from now on. For other ports that use pyexec, this decreases code size because the debug printing code is dead (it can't be enabled) but the compiler can't deduce that, so code is still emitted.
This commit is contained in:
parent
aca8873bb8
commit
61d2b40ad5
lib/utils
ports
py
|
@ -45,7 +45,10 @@
|
|||
|
||||
pyexec_mode_kind_t pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL;
|
||||
int pyexec_system_exit = 0;
|
||||
|
||||
#if MICROPY_REPL_INFO
|
||||
STATIC bool repl_display_debugging_info = 0;
|
||||
#endif
|
||||
|
||||
#define EXEC_FLAG_PRINT_EOF (1)
|
||||
#define EXEC_FLAG_ALLOW_DEBUGGING (2)
|
||||
|
@ -61,7 +64,9 @@ STATIC bool repl_display_debugging_info = 0;
|
|||
// EXEC_FLAG_IS_REPL is used for REPL inputs (flag passed on to mp_compile)
|
||||
STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input_kind, int exec_flags) {
|
||||
int ret = 0;
|
||||
#if MICROPY_REPL_INFO
|
||||
uint32_t start = 0;
|
||||
#endif
|
||||
|
||||
// by default a SystemExit exception returns 0
|
||||
pyexec_system_exit = 0;
|
||||
|
@ -97,7 +102,9 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
|
|||
|
||||
// execute code
|
||||
mp_hal_set_interrupt_char(CHAR_CTRL_C); // allow ctrl-C to interrupt us
|
||||
#if MICROPY_REPL_INFO
|
||||
start = mp_hal_ticks_ms();
|
||||
#endif
|
||||
mp_call_function_0(module_fun);
|
||||
mp_hal_set_interrupt_char(-1); // disable interrupt
|
||||
nlr_pop();
|
||||
|
@ -123,6 +130,7 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
|
|||
}
|
||||
}
|
||||
|
||||
#if MICROPY_REPL_INFO
|
||||
// display debugging info if wanted
|
||||
if ((exec_flags & EXEC_FLAG_ALLOW_DEBUGGING) && repl_display_debugging_info) {
|
||||
mp_uint_t ticks = mp_hal_ticks_ms() - start; // TODO implement a function that does this properly
|
||||
|
@ -142,6 +150,7 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
|
|||
gc_dump_info();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
if (exec_flags & EXEC_FLAG_PRINT_EOF) {
|
||||
mp_hal_stdout_tx_strn("\x04", 1);
|
||||
|
@ -576,9 +585,10 @@ int pyexec_frozen_module(const char *name) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if MICROPY_REPL_INFO
|
||||
mp_obj_t pyb_set_repl_info(mp_obj_t o_value) {
|
||||
repl_display_debugging_info = mp_obj_get_int(o_value);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(pyb_set_repl_info_obj, pyb_set_repl_info);
|
||||
#endif
|
||||
|
|
|
@ -51,8 +51,10 @@ int pyexec_frozen_module(const char *name);
|
|||
void pyexec_event_repl_init(void);
|
||||
int pyexec_event_repl_process_char(int c);
|
||||
extern uint8_t pyexec_repl_active;
|
||||
mp_obj_t pyb_set_repl_info(mp_obj_t o_value);
|
||||
|
||||
#if MICROPY_REPL_INFO
|
||||
mp_obj_t pyb_set_repl_info(mp_obj_t o_value);
|
||||
MP_DECLARE_CONST_FUN_OBJ_1(pyb_set_repl_info_obj);
|
||||
#endif
|
||||
|
||||
#endif // MICROPY_INCLUDED_LIB_UTILS_PYEXEC_H
|
||||
|
|
|
@ -40,7 +40,9 @@
|
|||
|
||||
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_board) },
|
||||
#if MICROPY_REPL_INFO
|
||||
{ MP_ROM_QSTR(MP_QSTR_repl_info), MP_ROM_PTR(&pyb_set_repl_info_obj) },
|
||||
#endif
|
||||
PYB_LED_MODULE
|
||||
};
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#define MICROPY_ENABLE_FINALISER (1)
|
||||
#define MICROPY_STACK_CHECK (1)
|
||||
#define MICROPY_HELPER_REPL (1)
|
||||
#define MICROPY_REPL_INFO (1)
|
||||
#define MICROPY_REPL_EMACS_KEYS (0)
|
||||
#define MICROPY_REPL_AUTO_INDENT (1)
|
||||
#define MICROPY_KBD_EXCEPTION (1)
|
||||
|
|
|
@ -142,7 +142,9 @@ STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) },
|
||||
#endif
|
||||
#if MICROPY_REPL_INFO
|
||||
{ MP_ROM_QSTR(MP_QSTR_repl_info), MP_ROM_PTR(&pyb_set_repl_info_obj) },
|
||||
#endif
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_wfi), MP_ROM_PTR(&pyb_wfi_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&pyb_disable_irq_obj) },
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0)
|
||||
#define MICROPY_KBD_EXCEPTION (1)
|
||||
#define MICROPY_HELPER_REPL (1)
|
||||
#define MICROPY_REPL_INFO (1)
|
||||
#define MICROPY_REPL_EMACS_KEYS (1)
|
||||
#define MICROPY_REPL_AUTO_INDENT (1)
|
||||
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
|
||||
|
|
|
@ -283,7 +283,9 @@ STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
|
|||
{ MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&pyb_info_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&pyb_unique_id_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&pyb_freq_obj) },
|
||||
#if MICROPY_REPL_INFO
|
||||
{ MP_ROM_QSTR(MP_QSTR_repl_info), MP_ROM_PTR(&pyb_set_repl_info_obj) },
|
||||
#endif
|
||||
|
||||
{ MP_ROM_QSTR(MP_QSTR_wfi), MP_ROM_PTR(&pyb_wfi_obj) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&pyb_disable_irq_obj) },
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#define MICROPY_ENABLE_FINALISER (1)
|
||||
#define MICROPY_STACK_CHECK (1)
|
||||
#define MICROPY_HELPER_REPL (1)
|
||||
#define MICROPY_REPL_INFO (1)
|
||||
#define MICROPY_ENABLE_SOURCE_LINE (1)
|
||||
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)
|
||||
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT)
|
||||
|
|
|
@ -560,6 +560,11 @@
|
|||
#define MICROPY_HELPER_REPL (0)
|
||||
#endif
|
||||
|
||||
// Allow enabling debug prints after each REPL line
|
||||
#ifndef MICROPY_REPL_INFO
|
||||
#define MICROPY_REPL_INFO (0)
|
||||
#endif
|
||||
|
||||
// Whether to include emacs-style readline behavior in REPL
|
||||
#ifndef MICROPY_REPL_EMACS_KEYS
|
||||
#define MICROPY_REPL_EMACS_KEYS (0)
|
||||
|
|
Loading…
Reference in New Issue