From 5dfefb477a18aaeb1c0ea3fafc5bc68238b3e4d6 Mon Sep 17 00:00:00 2001 From: Romain Goyet Date: Thu, 8 Nov 2018 13:29:49 +0100 Subject: [PATCH] [python] Rename micropython_port_should_interrupt to micropython_port_vm_hook_loop --- build/toolchain.emscripten.mak | 2 +- python/port/helpers.cpp | 14 +++++++++++--- python/port/helpers.h | 4 +--- python/port/mpconfigport.h | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/build/toolchain.emscripten.mak b/build/toolchain.emscripten.mak index baabdca9b..7048b6d02 100644 --- a/build/toolchain.emscripten.mak +++ b/build/toolchain.emscripten.mak @@ -63,7 +63,7 @@ _do_load_from_lexer \ _fun_bc_call \ _fun_builtin_var_call \ _main \ -_micropython_port_should_interrupt \ +_micropython_port_vm_hook_loop \ _mp_builtin___import__ \ _mp_builtin_input \ _mp_call_function_0 \ diff --git a/python/port/helpers.cpp b/python/port/helpers.cpp index cda2b53ca..ac0114b02 100644 --- a/python/port/helpers.cpp +++ b/python/port/helpers.cpp @@ -4,15 +4,23 @@ extern "C" { #include "mphalport.h" } -void micropython_port_should_interrupt() { +void micropython_port_vm_hook_loop() { + /* This function is called very frequently by the MicroPython engine. We grab + * this opportunity to interrupt execution and/or refresh the display on + * platforms that need it. */ + + /* Doing too many things here slows down Python execution quite a lot. So we + * only do things once in a while and return as soon as possible otherwise. */ static int c = 0; c++; - if (c%20000 != 0) { + if (c % 20000 != 0) { return; } c = 0; + + /* Check if the user asked for an interruption from the keyboard */ Ion::Keyboard::State scan = Ion::Keyboard::scan(); - if (scan.keyDown((Ion::Keyboard::Key)mp_interrupt_char)) { + if (scan.keyDown(static_cast(mp_interrupt_char))) { mp_keyboard_interrupt(); } } diff --git a/python/port/helpers.h b/python/port/helpers.h index b07c6de29..375256909 100644 --- a/python/port/helpers.h +++ b/python/port/helpers.h @@ -5,9 +5,7 @@ extern "C" { #endif -/* should_interrupt effectively does something once every 20000 calls. It checks - * if a key is down to raise an interruption flag. */ -void micropython_port_should_interrupt(); +void micropython_port_vm_hook_loop(); #ifdef __cplusplus } diff --git a/python/port/mpconfigport.h b/python/port/mpconfigport.h index 17794886b..109a0682c 100644 --- a/python/port/mpconfigport.h +++ b/python/port/mpconfigport.h @@ -90,7 +90,7 @@ // (This scheme won't work if we want to mix Thumb and normal ARM code.) #define MICROPY_MAKE_POINTER_CALLABLE(p) (p) -#define MICROPY_VM_HOOK_LOOP micropython_port_should_interrupt(); +#define MICROPY_VM_HOOK_LOOP micropython_port_vm_hook_loop(); typedef intptr_t mp_int_t; // must be pointer size typedef uintptr_t mp_uint_t; // must be pointer size