Top Description Fields Constructors Methods
org.python.core

pack-priv Class CPython311Frame

extends PyFrame<CPython311Code>
Class Inheritance
Imports
java.lang.invoke.MethodHandle, java.util.EnumSet, .Map, org.python.base.InterpreterError, org.python.core.PyCode.Layout, .PyCode.Trait, .PyDict.MergeMode

A PyFrame for executing CPython 3.11 byte code.

Field Summary

Modifier and TypeField and Description
private final Map<Object, Object>
builtins

The built-in objects from func, wrapped (if necessary) to make it a Map.

private static final Object[]
pack-priv final Object[]
fastlocals

All local variables, named in code.

private static final String
pack-priv Object
returnValue

Assigned eventually by return statement (or stays None).

pack-priv int
stacktop

Index of first empty space on the value stack.

private static final String
pack-priv final Object[]
valuestack

Value stack.

Inherited from org.python.core.PyFrame:
backcodefunclocalsTYPE

Constructor Summary

AccessConstructor and Description
protected
CPython311Frame(CPython311Function
that this frame executes
func
,
Object
local name space (may be null)
locals
)

Create a CPython38Frame, which is a PyFrame with the storage and mechanism to execute a module or isolated code object (compiled to a CPython311Code.

Method Summary

Modifier and TypeMethod and Description
pack-priv Object
eval()

Implements abstract org.python.core.PyFrame.eval.

Execute the code in this frame.
private void
getMethod(Object
of which the callable is an attribute
obj
,
String
of callable attribute
name
,
int
in stack at which to place results
offset
)

A specialised version of object.__getattribute__ specifically to support the LOAD_METHOD and CALL_METHOD opcode pair generated by the CPython byte code compiler.

private static TypeError

Returns:

an exception to throw
kwargsKeyError
(KeyError.Duplicate
the duplicate key error
ke
,
Object
providing a function name for context
func
)

Create a TypeError to throw when a duplicate key turns up while merging keyword arguments to a function call.

private static TypeError

Returns:

an exception to throw
kwargsTypeError
(Object
providing a function name for context
func
,
Object
the alleged mapping
kwargs
)

Create a TypeError to throw when keyword arguments appear not to be a mapping.

private static SystemError
noLocals(String
"loading", "storing" or "deleting"
action
,
String
variable name
name
)

Generate error to throw when we cannot access locals.

Inherited from org.python.core.PyFrame:
getInterpreterlocalsMapOrNulltoString

Field Detail

builtinsback to summary
private final Map<Object, Object> builtins

The built-in objects from func, wrapped (if necessary) to make it a Map. Inside the wrapper it will be accessed using the Python mapping protocol.

EMPTY_OBJECT_ARRAYback to summary
private static final Object[] EMPTY_OBJECT_ARRAY
fastlocalsback to summary
pack-priv final Object[] fastlocals

All local variables, named in code.layout.localnames.

NAME_ERROR_MSGback to summary
private static final String NAME_ERROR_MSG
returnValueback to summary
pack-priv Object returnValue

Assigned eventually by return statement (or stays None).

stacktopback to summary
pack-priv int stacktop

Index of first empty space on the value stack.

VALUE_AFTER_STARback to summary
private static final String VALUE_AFTER_STAR
valuestackback to summary
pack-priv final Object[] valuestack

Value stack.

Constructor Detail

CPython311Frameback to summary
protected CPython311Frame(CPython311Function func, Object locals)

Create a CPython38Frame, which is a PyFrame with the storage and mechanism to execute a module or isolated code object (compiled to a CPython311Code.

This will set the func and (sometimes) locals fields of the frame. The globals and builtins properties, exposed to Python as f_globals and f_builtins, are determined by func.

The func argument also locates the code object for the frame, the properties of which determine many characteristics of the frame.

  • If the code argument has the Trait#NEWLOCALS the locals argument is ignored.
    • If the code does not additionally have the trait Trait#OPTIMIZED, a new empty dict will be provided as locals.
    • Otherwise, the code has the trait OPTIMIZED, and locals will be null until possibly set later.
  • Otherwise, code does not have the trait NEWLOCALS and expects an object with the map protocol to act as PyFrame#locals.
    • If the argument locals is not null it specifies locals.
    • Otherwise, the argument locals is null and locals will be the same as #globals.
Parameters
func:CPython311Function

that this frame executes

locals:Object

local name space (may be null)

Method Detail

evalback to summary
pack-priv Object eval()

Implements abstract org.python.core.PyFrame.eval.

Doc from org.python.core.PyFrame.eval.

Execute the code in this frame.

Returns:Object

return value of the frame

Annotations
@Override
getMethodback to summary
private void getMethod(Object obj, String name, int offset) throws AttributeError, Throwable

A specialised version of object.__getattribute__ specifically to support the LOAD_METHOD and CALL_METHOD opcode pair generated by the CPython byte code compiler. This method will place two entries in the stack at the offset given that are either:

  1. an unbound method and the object passed (obj), or
  2. null and a bound method object.

The normal behaviour of object.__getattribute__ is represented by case 2.

Case 1 supports an optimisation that is possible when the type of the self object obj has not overridden __getattribute__, and the name resolves to a regular method in it. CALL_METHOD will detect and use this optimised form if the first element is not null.

Parameters
obj:Object

of which the callable is an attribute

name:String

of callable attribute

offset:int

in stack at which to place results

Exceptions
AttributeError:
if the named attribute does not exist
Throwable:
from other errors
kwargsKeyErrorback to summary
private static TypeError kwargsKeyError(KeyError.Duplicate ke, Object func)

Create a TypeError to throw when a duplicate key turns up while merging keyword arguments to a function call.

Parameters
ke:KeyError.Duplicate

the duplicate key error

func:Object

providing a function name for context

Returns:TypeError

an exception to throw

kwargsTypeErrorback to summary
private static TypeError kwargsTypeError(Object func, Object kwargs)

Create a TypeError to throw when keyword arguments appear not to be a mapping. dict.merge raises AttributeError (percolated from an attempt to get 'keys' attribute) if its second argument is not a mapping, which we convert to a TypeError.

Parameters
func:Object

providing a function name for context

kwargs:Object

the alleged mapping

Returns:TypeError

an exception to throw

noLocalsback to summary
private static SystemError noLocals(String action, String name)

Generate error to throw when we cannot access locals.

Parameters
action:String

"loading", "storing" or "deleting"

name:String

variable name