diff options
author | Damien George <damien.p.george@gmail.com> | 2016-02-15 22:46:21 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-02-17 09:02:19 +0000 |
commit | 40d8430ee3f62d48482439c080f3a058bcc7fd64 (patch) | |
tree | 1fec14d455aa005392cf95e0f7e616b65be30cdb /py/mpconfig.h | |
parent | 69d9e7d27d62d54c0625d4181c80478b0313384d (diff) | |
download | micropython-40d8430ee3f62d48482439c080f3a058bcc7fd64.tar.gz micropython-40d8430ee3f62d48482439c080f3a058bcc7fd64.zip |
py/vm: Add macros to hook into various points in the VM.
These can be used to insert arbitrary checks, polling, etc into the VM.
They are left general because the VM is a highly tuned loop and it should
be up to a given port how that port wants to modify the VM internals.
One common use would be to insert a polling check, but only done after
a certain number of opcodes were executed, so as not to slow down the VM
too much. For example:
#define MICROPY_VM_HOOK_COUNT (30)
#define MICROPY_VM_HOOK_INIT static uint vm_hook_divisor = MICROPY_VM_HOOK_COUNT
#define MICROPY_VM_HOOK_POLL if (--vm_hook_divisor == 0) { \
vm_hook_divisor = MICROPY_VM_HOOK_COUNT;
extern void vm_hook_function(void);
vm_hook_function();
}
#define MICROPY_VM_HOOK_LOOP MICROPY_VM_HOOK_POLL
#define MICROPY_VM_HOOK_RETURN MICROPY_VM_HOOK_POLL
Diffstat (limited to 'py/mpconfig.h')
-rw-r--r-- | py/mpconfig.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/py/mpconfig.h b/py/mpconfig.h index 0c46bf3e5a..cd9380aa6e 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -351,6 +351,22 @@ /*****************************************************************************/ /* Python internal features */ +// Hook for the VM at the start of the opcode loop (can contain variable +// definitions usable by the other hook functions) +#ifndef MICROPY_VM_HOOK_INIT +#define MICROPY_VM_HOOK_INIT +#endif + +// Hook for the VM during the opcode loop (but only after jump opcodes) +#ifndef MICROPY_VM_HOOK_LOOP +#define MICROPY_VM_HOOK_LOOP +#endif + +// Hook for the VM just before return opcode is finished being interpreted +#ifndef MICROPY_VM_HOOK_RETURN +#define MICROPY_VM_HOOK_RETURN +#endif + // Whether to include the garbage collector #ifndef MICROPY_ENABLE_GC #define MICROPY_ENABLE_GC (0) |