Top Description Fields Constructors Methods
org.python.core

public abstract Class PyFrame<C extends org.python.core.PyCode>

extends Object
Class Inheritance
Known Direct Subclasses
org.python.core.CPython311Frame
Type Parameters
<C>
The type of code that this frame executes
Imports
java.lang.invoke.MethodHandles, java.util.Map

A PyFrame is the context for the execution of code. Different concrete sub-classes of PyFrame exist to execute different compiled representations of Python code. For example, there is one for CPython 3.11 byte code and (we expect) another for Java byte code. The type of code object supported is the parameter C to the class.

In order that argument processing may be uinform irrespective of concrete type, a PyFrame presents an abstraction that has arguments laid out in an array. For example, the function definition:

def func(a, b, c=3, d=4, /, e=5, f=6, *aa, g=7, h, i=9, **kk):
    v, w, x = b, c, d, e
    return u
the layout of the local variables in a frame would be as below
A Python frame
frame a b c d e f g h i aa kk u v w x
code argcount kwonlyargcount * **
posonlyargcount
function defaults kwdefaults

In the last row of the table, the properties are supplied by the function object during each call. defaults apply in the position show, in order, while kwdefaults (in a map) apply to keywords wherever the name matches. The names in the frame are those in the PyCode#varnames field of the associated code object

The frame presents an abstraction of an array of named local variables, and two more of cell and free variables, while concrete subclasses are free to implement these in whatever manner they choose.

Field Summary

Modifier and TypeField and Description
pack-priv PyFrame<? extends PyCode>
back

Frames form a stack by chaining through the back pointer.

pack-priv final C
code

Code this frame is to execute, exposed as immutable f_code.

pack-priv final PyFunction<? extends C>
func

Function of which this is a frame.

pack-priv Object
locals

Local context (name space) of execution.

public static final PyType
TYPE

The Python type frame.

Constructor Summary

AccessConstructor and Description
protected
PyFrame(PyFunction<? extends C>
defining the code and globals
func
)

Foundation constructor on which subclass constructors rely.

Method Summary

Modifier and TypeMethod and Description
pack-priv abstract Object

Returns:

return value of the frame
eval
()

Execute the code in this frame.

pack-priv Interpreter

Returns:

Interpreter that defines the import context.
getInterpreter
()

Get the interpreter that defines the import context when executing code.

protected Map<Object, Object>

Returns:

as a Java Map
localsMapOrNull
()

Provide locals as a Java Map.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

backback to summary
pack-priv PyFrame<? extends PyCode> back

Frames form a stack by chaining through the back pointer.

codeback to summary
pack-priv final C code

Code this frame is to execute, exposed as immutable f_code. We have our own final copy because it is possible to change the code object that defines func but the frame should continue to reference the code that created it.

funcback to summary
pack-priv final PyFunction<? extends C> func

Function of which this is a frame.

localsback to summary
pack-priv Object locals

Local context (name space) of execution. (Assign if needed.) This is allowed to be any type, but if it is ever actually used, the interpreter will expect it to support the mapping protocol.

TYPEback to summary
public static final PyType TYPE

The Python type frame.

Constructor Detail

PyFrameback to summary
protected PyFrame(PyFunction<? extends C> func)

Foundation constructor on which subclass constructors rely. This provides a "loose" frame that is not yet part of any stack until explicitly pushed (with ThreadState#push(PyFrame)). In particular, the back pointer is null in the newly-created frame.

A frame always belongs to an Interpreter via its function, but it does not necessarily belong to a particular ThreadState.

Parameters
func:PyFunction<? extends C>

defining the code and globals

Method Detail

evalback to summary
pack-priv abstract Object eval()

Execute the code in this frame.

Returns:Object

return value of the frame

getInterpreterback to summary
pack-priv Interpreter getInterpreter()

Get the interpreter that defines the import context when executing code.

Returns:Interpreter

Interpreter that defines the import context.

localsMapOrNullback to summary
protected Map<Object, Object> localsMapOrNull()

Provide locals as a Java Map. This does not re-compute locals as a dictionary in the way of fastToLocals(), but only dresses an existing value as a Java Map (if it is not null).

Returns:Map<Object, Object>

as a Java Map

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override