summaryrefslogtreecommitdiff
path: root/py/runtime.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-12-15 13:00:19 +1100
committerDamien George <damien.p.george@gmail.com>2016-12-15 13:00:19 +1100
commit7f1da0a03b1559080ca4d054bd38f104bde168e6 (patch)
tree1450845231e9bda2a481a67140cb09d6ad7ba71c /py/runtime.c
parent979ab4e126dacca4d7fbbd0e71c849365ef2c947 (diff)
py: Add MICROPY_KBD_EXCEPTION config option to provide mp_kbd_exception.
Defining and initialising mp_kbd_exception is boiler-plate code and so the core runtime can provide it, instead of each port needing to do it themselves. The exception object is placed in the VM state rather than on the heap.
Diffstat (limited to 'py/runtime.c')
-rw-r--r--py/runtime.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/py/runtime.c b/py/runtime.c
index e7e35a081..8b4420926 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -68,6 +68,15 @@ void mp_init(void) {
mp_init_emergency_exception_buf();
#endif
+ #if MICROPY_KBD_EXCEPTION
+ // initialise the exception object for raising KeyboardInterrupt
+ MP_STATE_VM(mp_kbd_exception).base.type = &mp_type_KeyboardInterrupt;
+ MP_STATE_VM(mp_kbd_exception).traceback_alloc = 0;
+ MP_STATE_VM(mp_kbd_exception).traceback_len = 0;
+ MP_STATE_VM(mp_kbd_exception).traceback_data = NULL;
+ MP_STATE_VM(mp_kbd_exception).args = mp_const_empty_tuple;
+ #endif
+
// call port specific initialization if any
#ifdef MICROPY_PORT_INIT_FUNC
MICROPY_PORT_INIT_FUNC;