astrorafael wrote: ↑Wed Feb 17, 2021 12:52 pm
I was examining the machine_pin.c file. and have seen tons of references in the code the MP_STATE_PORT(x) macro which seems to be associated with "irq objects". i.e.:
I think in all cases, MP_STATE_PORT(x) is an alias for MP_STATE_VM(x)
So really the question is, what is MP_STATE_VM.
The answer to that is that it's a convenient way of accessing the members of the global mp_state_vm_t struct (which is the entire VM state).
Essentially, MicroPython has a global variable "mp_state_ctx" (defined in py/mpstate.c) which contains the mp_state_vm_t instance.
So you will see this all through the codebase to access various objects that are part of the VM state.
But in this particular case, another thing that's part of the VM state is any "root pointers" that are defined by the port (defined in MICROPY_PORT_ROOT_POINTERS). These are important because the port may have additional objects that need to be tracked by the garbage collector.
So typically, MP_STATE_PORT is used to access port-specific root pointers (i.e. things that are both global state, but also GC root pointers).
In this case, the irq objects need to be root pointers because they contain pointers to python functions.