code
object. A code
object describes
the layout of a PyFrame
, and is a factory for frames of
matching type.
In this implementation, while there is only one Python type
code
, we allow alternative implementations of it. In
particular, we provide for a code object that is the result of
compiling to JVM byte code, in addition to the expected support
for Python byte code.
The abstract base PyCode
has a need to store fewer
attributes than the concrete CPython code
object, where
the only realisation holds a block of byte code with broadly
similar needs from one version to the next. We provide
get-methods matching all those of CPython, and each concrete
class can override them where meaningful.
Modifier and Type | Class and Description |
---|---|
pack-priv static interface | PyCode.Layout
Interface on a store of information about the variables required by a code object and where they will be stored in the frame it creates. |
pack-priv static enum | PyCode.Trait
Characteristics of a |
pack-priv static enum | PyCode.VariableTrait
Traits characterising local variables of the frame this code object will produce. |
Modifier and Type | Field and Description |
---|---|
pack-priv final int | argcount
Number of positional parameters (not counting |
public static final int | CO_ASYNC_GENERATOR
The code object is an asynchronous generator function. |
public static final int | CO_COROUTINE
The code is for a coroutine function (defined with
|
public static final int | CO_GENERATOR
The code is for a generator function, i.e. a generator object is returned when the code object is executed.. |
public static final int | CO_ITERABLE_COROUTINE
The flag is used to transform generators into generator-based coroutines. |
public static final int | CO_NESTED
The code is for a nested function. |
public static final int | CO_NEWLOCALS
A new |
public static final int | CO_OPTIMIZED
The code uses fast local local variables, not a map. |
public static final int | CO_VARARGS
The function has a collector for excess positional arguments |
private static final int | |
public static final int | CO_VARKEYWORDS
The function has a collector for excess keyword arguments |
private static final int | |
pack-priv final Object[] | consts
Constant objects needed by the code. |
protected static final String[] | EMPTY_STRING_ARRAY
Empty (zero-length) array of |
pack-priv final String | filename
Source file from which compiled. |
pack-priv final int | firstlineno
First source line number of this code. |
pack-priv final int | flags
|
pack-priv final int | kwonlyargcount
Number of keyword-only parameters. |
pack-priv final String | name
Name of function etc. |
private static final String | |
pack-priv final String[] | names
Names referenced in the code. |
pack-priv final int | posonlyargcount
Number of positional-only parameters. |
pack-priv final String | qualname
Fully qualified name of function etc. |
pack-priv final EnumSet | traits
Characteristics of this |
public static final PyType | TYPE
The Python type |
Access | Constructor and Description |
---|---|
public | PyCode(String
co_filename co_name co_qualname co_flags a bitmap of traitsco_firstlineno co_consts co_names co_argcount the number of positional
parameters (including positional-only arguments and arguments
with default values)co_posonlyargcount the number of
positional-only arguments (including arguments with default
values)co_kwonlyargcount the number of
keyword-only arguments (including arguments with default
values)Full constructor. |
Modifier and Type | Method and Description |
---|---|
private Object | |
private Object | |
protected static PyBytes | |
protected static String | Returns: v to check and cast/convert v, String the name of the argument (for error production) argName)Cast a Python |
protected static PyTuple | |
pack-priv PyTuple | |
pack-priv PyBytes | |
pack-priv PyTuple | |
pack-priv PyTuple | |
pack-priv PyBytes | |
pack-priv PyTuple | |
pack-priv int | |
pack-priv PyTuple | |
pack-priv abstract PyFunction | Returns: the function from this codeproviding the module context interpreter, PyDict name space to treat as global variables globals, Object[] default positional argument values or
defaults, PyDict null default keyword argument values or kwdefaults, Object null type annotations ( annotations, PyCell[] dict , null
or maybe tuple )variables referenced but not defined here, must be
size expected by code or closure)null if empty.Create a |
pack-priv PyFunction | Returns: the functionproviding the module context interpreter, PyDict name space to treat as global variables globals)Create a |
public PyType | |
pack-priv abstract PyCode. | |
protected static String[] | |
public String | |
pack-priv int | Returns: total space in frame for argumentsReturn the total space in a frame of a code object, that must be reserved for arguments. |
pack-priv static int | Returns: total space in frame for argumentsargument count excluding collector parameters. argcount, int bit map of code traits flags)From the values of |
private static EnumSet |
argcount | back to summary |
---|---|
pack-priv final int argcount Number of positional parameters (not counting
|
CO_ASYNC_GENERATOR | back to summary |
---|---|
public static final int CO_ASYNC_GENERATOR The code object is an asynchronous generator function. When the code object is executed it returns an asynchronous generator object. See PEP 525 for more details. |
CO_COROUTINE | back to summary |
---|---|
public static final int CO_COROUTINE The code is for a coroutine function (defined with
|
CO_GENERATOR | back to summary |
---|---|
public static final int CO_GENERATOR The code is for a generator function, i.e. a generator object is returned when the code object is executed.. |
CO_ITERABLE_COROUTINE | back to summary |
---|---|
public static final int CO_ITERABLE_COROUTINE The flag is used to transform generators into generator-based
coroutines. Generator objects with this flag can be used in
|
CO_NESTED | back to summary |
---|---|
public static final int CO_NESTED The code is for a nested function. |
CO_NEWLOCALS | back to summary |
---|---|
public static final int CO_NEWLOCALS A new |
CO_OPTIMIZED | back to summary |
---|---|
public static final int CO_OPTIMIZED The code uses fast local local variables, not a map. |
CO_VARARGS | back to summary |
---|---|
public static final int CO_VARARGS The function has a collector for excess positional arguments |
CO_VARARGS_SHIFT | back to summary |
---|---|
private static final int CO_VARARGS_SHIFT |
CO_VARKEYWORDS | back to summary |
---|---|
public static final int CO_VARKEYWORDS The function has a collector for excess keyword arguments |
CO_VARKEYWORDS_SHIFT | back to summary |
---|---|
private static final int CO_VARKEYWORDS_SHIFT |
consts | back to summary |
---|---|
pack-priv final Object[] consts Constant objects needed by the code. Not |
EMPTY_STRING_ARRAY | back to summary |
---|---|
protected static final String[] EMPTY_STRING_ARRAY Empty (zero-length) array of |
filename | back to summary |
---|---|
pack-priv final String filename Source file from which compiled.
|
firstlineno | back to summary |
---|---|
pack-priv final int firstlineno First source line number of this code. |
flags | back to summary |
---|---|
pack-priv final int flags
|
kwonlyargcount | back to summary |
---|---|
pack-priv final int kwonlyargcount Number of keyword-only parameters.
|
name | back to summary |
---|---|
pack-priv final String name Name of function etc.
|
NAME_TUPLES_STRING | back to summary |
---|---|
private static final String NAME_TUPLES_STRING |
names | back to summary |
---|---|
pack-priv final String[] names Names referenced in the code. Not |
posonlyargcount | back to summary |
---|---|
pack-priv final int posonlyargcount Number of positional-only parameters.
|
qualname | back to summary |
---|---|
pack-priv final String qualname Fully qualified name of function etc.
|
traits | back to summary |
---|---|
pack-priv final EnumSet<PyCode. Characteristics of this |
TYPE | back to summary |
---|---|
public static final PyType TYPE The Python type |
PyCode | back to summary |
---|---|
public PyCode(String filename, String name, String qualname, int flags, int firstlineno, Object[] consts, String[] names, int argcount, int posonlyargcount, int kwonlyargcount) Full constructor. The
Where the parameters map directly to an attribute of the code
object, that is the best way to explain them. Note that this
factory method is tuned to the needs of
|
__repr__ | back to summary |
---|---|
private Object __repr__()
|
__str__ | back to summary |
---|---|
private Object __str__()
|
castBytes | back to summary |
---|---|
protected static PyBytes castBytes(Object v, String arg) throws TypeError |
castString | back to summary |
---|---|
protected static String castString(Object v, String argName) Cast a Python |
castTuple | back to summary |
---|---|
protected static PyTuple castTuple(Object v, String arg) |
co_cellvars | back to summary |
---|---|
pack-priv PyTuple co_cellvars() Get |
co_code | back to summary |
---|---|
pack-priv PyBytes co_code()
|
co_consts | back to summary |
---|---|
pack-priv PyTuple co_consts() Get |
co_freevars | back to summary |
---|---|
pack-priv PyTuple co_freevars() Get |
co_lnotab | back to summary |
---|---|
pack-priv PyBytes co_lnotab()
|
co_names | back to summary |
---|---|
pack-priv PyTuple co_names() Get |
co_stacksize | back to summary |
---|---|
pack-priv int co_stacksize()
|
co_varnames | back to summary |
---|---|
pack-priv PyTuple co_varnames() Get |
createFunction | back to summary |
---|---|
pack-priv abstract PyFunction Create a
|
createFunction | back to summary |
---|---|
pack-priv PyFunction Create a
|
getType | back to summary |
---|---|
public PyType getType() Implements org. Doc from org. The Python |
layout | back to summary |
---|---|
pack-priv abstract PyCode. Describe the layout of the frame local variables (at least the
arguments), cell and free variables. |
names | back to summary |
---|---|
protected static String[] names(Object v, String tupleName) Check that all the argument is a tuple and that all objects in it
are |
toString | back to summary |
---|---|
public String toString() Overrides java. Doc from java. Returns a string representation of the object. |
totalargs | back to summary |
---|---|
pack-priv int totalargs() Return the total space in a frame of a code object, that must be reserved for arguments. This is also the size of the layout array appearing as an argument to constructors.
|
totalargs | back to summary |
---|---|
pack-priv static int totalargs(int argcount, int flags) From the values of
|
traitsFrom | back to summary |
---|---|
private static EnumSet |
Modifier and Type | Method and Description |
---|---|
public Stream | Returns: names of cell variables (may be parameters).Return a stream of the names of variables to include in
|
public Stream | Returns: names of free variables.Return a stream of the names of variables to include in
|
public Stream | Returns: names of all local variables.Return a stream of the names of all the local variables These are
the parameters and then the other plain, cell and free variables,
but occurring only once each (whereas |
public String | |
public default int | |
public default int | |
public default int | |
public default int | |
public EnumSet | Returns: traits of the local variableof variable index)Return the |
public Stream | Returns: names of non-cell and parameters variables.Return a stream of the names of variables to include in
|
cellvars | back to summary |
---|---|
public Stream Return a stream of the names of variables to include in
|
freevars | back to summary |
---|---|
public Stream Return a stream of the names of variables to include in
|
localnames | back to summary |
---|---|
public Stream Return a stream of the names of all the local variables These are
the parameters and then the other plain, cell and free variables,
but occurring only once each (whereas |
name | back to summary |
---|---|
public String name(int index) Return name of one local frame variable.
|
ncellvars | back to summary |
---|---|
public default int ncellvars()
|
nfreevars | back to summary |
---|---|
public default int nfreevars()
|
nvarnames | back to summary |
---|---|
public default int nvarnames()
|
size | back to summary |
---|---|
public default int size()
|
traits | back to summary |
---|---|
public EnumSet Return the
|
varnames | back to summary |
---|---|
public Stream Return a stream of the names of variables to include in
|
PyCode
(as CPython co_flags). These
are not all relevant to all code types.
Modifier and Type | Field and Description |
---|---|
public static final PyCode. | |
public static final PyCode. | |
public static final PyCode. | |
public static final PyCode. | |
public static final PyCode. | |
public static final PyCode. | |
public static final PyCode. | |
public static final PyCode. | |
public static final PyCode. |
Access | Constructor and Description |
---|---|
private |
Modifier and Type | Method and Description |
---|---|
public static PyCode. | |
public static PyCode. |
ASYNC_GENERATOR | back to summary |
---|---|
public static final PyCode. |
COROUTINE | back to summary |
---|---|
public static final PyCode. |
GENERATOR | back to summary |
---|---|
public static final PyCode. |
ITERABLE_COROUTINE | back to summary |
---|---|
public static final PyCode. |
NESTED | back to summary |
---|---|
public static final PyCode. |
NEWLOCALS | back to summary |
---|---|
public static final PyCode. |
OPTIMIZED | back to summary |
---|---|
public static final PyCode. |
VARARGS | back to summary |
---|---|
public static final PyCode. |
VARKEYWORDS | back to summary |
---|---|
public static final PyCode. |
Trait | back to summary |
---|---|
private Trait() |
valueOf | back to summary |
---|---|
public static PyCode. |
values | back to summary |
---|---|
public static PyCode. |
Modifier and Type | Field and Description |
---|---|
public static final PyCode. | CELL
Belongs in |
public static final PyCode. | FREE
Belongs in |
public static final PyCode. | PLAIN
Belongs in |
Access | Constructor and Description |
---|---|
private |
Modifier and Type | Method and Description |
---|---|
public static PyCode. | |
public static PyCode. |
CELL | back to summary |
---|---|
public static final PyCode. Belongs in |
FREE | back to summary |
---|---|
public static final PyCode. Belongs in |
PLAIN | back to summary |
---|---|
public static final PyCode. Belongs in |
VariableTrait | back to summary |
---|---|
private VariableTrait() |
valueOf | back to summary |
---|---|
public static PyCode. |
values | back to summary |
---|---|
public static PyCode. |