summaryrefslogtreecommitdiffstatshomepage
path: root/lib/utils
diff options
context:
space:
mode:
authorYonatan Goldschmidt <yon.goldschmidt@gmail.com>2019-12-25 09:27:38 +0200
committerDamien George <damien.p.george@gmail.com>2019-12-28 00:05:39 +1100
commit61d2b40ad56243585ac2bebef67aff10d4c5583c (patch)
treea845f6cd81f4734aeeae62c79aa20397d917b942 /lib/utils
parentaca8873bb841860c0b62d36afe42501eb4505199 (diff)
downloadmicropython-61d2b40ad56243585ac2bebef67aff10d4c5583c.tar.gz
micropython-61d2b40ad56243585ac2bebef67aff10d4c5583c.zip
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.
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/pyexec.c12
-rw-r--r--lib/utils/pyexec.h4
2 files changed, 14 insertions, 2 deletions
diff --git a/lib/utils/pyexec.c b/lib/utils/pyexec.c
index 851b026b6f..747097f157 100644
--- a/lib/utils/pyexec.c
+++ b/lib/utils/pyexec.c
@@ -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
diff --git a/lib/utils/pyexec.h b/lib/utils/pyexec.h
index 9eb490be54..573cb6d452 100644
--- a/lib/utils/pyexec.h
+++ b/lib/utils/pyexec.h
@@ -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