Skip to content
Snippets Groups Projects
Select Git revision
  • dualcore
  • ch3/leds
  • wip-bootstrap default
  • ch3/time
  • master
5 results

vm.c

  • Damien George's avatar
    40d8430e
    py/vm: Add macros to hook into various points in the VM. · 40d8430e
    Damien George authored
    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
    40d8430e
    History
    py/vm: Add macros to hook into various points in the VM.
    Damien George authored
    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