Python Source -- PVM
- Linked list of
PyFrameObject-- x86 stack frame
ebpNamespace: mapping from name (string) to object (pointer)
f_localsActually, we already know the needed size of stack size when compiling
Another thing is that, the use of closure will also cause extra space in the
We can get access to the frame object at runtime through Python interface, which is basically a hack based on the exception mechanism of VM.
.py file is one module, which is the highest level of scope.
How to understand assignment in Python: Binding an object to name in specified scope. It can also be viewed as a "constraint".
Object also has its own namespace, in which the method names and attribute names are defined.
Priority in descending order:
- L: function / method - local
- G: module - global scope
- B: builtin scope
Considering closure, we have:
- E: Enclosing function
Force use the name in global scope
- Environment Initialization:
- main thread
PyThreadState. Imported modules are shared across the threads. Sync -- GIL, or Global Interpreter Lock.
The interaction between frame and thread:
When the evaluation starts, we will use
PyThreadState_GET() to get current active thread object, then set its frame. When we need to create new
PyFrameObject object, we will retrieve old frame from thread state, create new execution environment, link the new frame to old one.