Expand description
Implement python as a virtual machine with bytecode. This module implements bytecode structure.
Modules§
Structs§
- Arg
- Arguments
- Argument structure
- Basic
Bag - Code
Flags - Code
Object - Primary container of a single code object. Each python function has a code object. Also a module has a code object.
- Code
Unit - Code
Units - Constants
- Exception
Table Entry - Exception table entry for zero-cost exception handling Format: (start, size, target, depth<<1|lasti)
- Label
- Load
Attr - Load
Super Attr - Make
Function Flags - OpArg
- Full 32-bit op_arg, including any possible ExtendedArg extension.
- OpArg
Byte - Opcode argument that may be extended by a prior ExtendedArg.
- OpArg
State - Stack
Effect - What effect the instruction has on the stack.
- Unpack
ExArgs
Enums§
- AnyInstruction
- Binary
Operator - The possible Binary operators
- Borrowed
Constant - A borrowed Constant
- Build
Slice ArgCount - Specifies if a slice is built with either 2 or 3 arguments.
- Common
Constant - Common constants for LOAD_COMMON_CONSTANT opcode. pycore_opcode_utils.h CONSTANT_*
- Comparison
Operator COMPARE_OParg is(cmp_index << 5) | mask. Only the upper 3 bits identify the comparison; the lower 5 bits are an inline cache mask for adaptive specialization.- Constant
Data - A Constant (which usually encapsulates data within it)
- Convert
Value Oparg - Oparg values for
Instruction::ConvertValue. - Instruction
- A Single bytecode instruction that are executed by the VM.
- Intrinsic
Function1 - Intrinsic function for CALL_INTRINSIC_1
- Intrinsic
Function2 - Intrinsic function for CALL_INTRINSIC_2
- Invert
- Whether or not to invert the operation.
- Make
Function Flag SET_FUNCTION_ATTRIBUTEflags. Bitmask: Defaults=0x01, KwOnly=0x02, Annotations=0x04, Closure=0x08, TypeParams=0x10, Annotate=0x20. Stored as bit position (0-5) bybitflag!macro.- Pseudo
Instruction - Instructions used by the compiler. They are not executed by the VM.
- PyCode
Location Info Kind - CPython 3.11+ linetable location info codes
- Raise
Kind - The kind of Raise that occurred.
- Special
Method - Special method for LOAD_SPECIAL opcode (context managers).
Constants§
- ADAPTIVE_
COOLDOWN_ VALUE - Adaptive specialization: cooldown counter after a successful specialization.
- ADAPTIVE_
WARMUP_ VALUE - Adaptive specialization: number of executions before attempting specialization.
- CO_
FAST_ CELL - CO_
FAST_ FREE - CO_
FAST_ HIDDEN - Per-slot kind flags for localsplus (co_localspluskinds).
- CO_
FAST_ LOCAL - JUMP_
BACKWARD_ INITIAL_ VALUE - Initial JUMP_BACKWARD counter bits (value/backoff = 4095/12).
Traits§
Functions§
- adaptive_
counter_ backoff - Reset adaptive counter with exponential backoff.
- adaptive_
counter_ bits - Encode an adaptive counter as
(value << 4) | backoff. - adaptive_
counter_ triggers - True when the adaptive counter should trigger specialization.
- advance_
adaptive_ counter - Decrement adaptive counter by one countdown step.
- build_
no_ location_ mask - Parse linetable to build a boolean mask indicating which code units
have NO_LOCATION (line == -1). Returns a Vec
of length num_units. - decode_
exception_ table - Decode all exception table entries.
- encode_
exception_ table - Encode exception table entries. Uses 6-bit varint encoding with start marker (MSB) and continuation bit.
- find_
exception_ handler - Find exception handler for given instruction offset.