py: Add mp_pending_exception global variable, for VM soft interrupt.
This allows to implement KeyboardInterrupt on unix, and a much safer
ctrl-C in stmhal port. First ctrl-C is a soft one, with hope that VM
will notice it; second ctrl-C is a hard one that kills anything (for
both unix and stmhal).
One needs to check for a pending exception in the VM only for jump
opcodes. Others can't produce an infinite loop (infinite recursion is
caught by stack check).
diff --git a/py/runtime.c b/py/runtime.c
index 6cb5c7e..f6f34be 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -62,6 +62,9 @@
#define DEBUG_OP_printf(...) (void)0
#endif
+// pending exception object (MP_OBJ_NULL if not pending)
+mp_obj_t mp_pending_exception;
+
// locals and globals need to be pointers because they can be the same in outer module scope
STATIC mp_obj_dict_t *dict_locals;
STATIC mp_obj_dict_t *dict_globals;
@@ -79,6 +82,9 @@
qstr_init();
mp_stack_ctrl_init();
+ // no pending exceptions to start with
+ mp_pending_exception = MP_OBJ_NULL;
+
#if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF
mp_init_emergency_exception_buf();
#endif