Skip to main content

Module bytecode

Module bytecode 

Source
Expand description

Implement python as a virtual machine with bytecode. This module implements bytecode structure.

Re-exports§

pub use crate::bytecode::instruction::AnyInstruction;
pub use crate::bytecode::instruction::AnyOpcode;
pub use crate::bytecode::instruction::Arg;
pub use crate::bytecode::instruction::Instruction;
pub use crate::bytecode::instruction::Opcode;
pub use crate::bytecode::instruction::PseudoInstruction;
pub use crate::bytecode::instruction::PseudoOpcode;
pub use crate::bytecode::instruction::StackEffect;
pub use crate::bytecode::oparg::BinaryOperator;
pub use crate::bytecode::oparg::BuildSliceArgCount;
pub use crate::bytecode::oparg::CommonConstant;
pub use crate::bytecode::oparg::ComparisonOperator;
pub use crate::bytecode::oparg::ConvertValueOparg;
pub use crate::bytecode::oparg::IntrinsicFunction1;
pub use crate::bytecode::oparg::IntrinsicFunction2;
pub use crate::bytecode::oparg::Invert;
pub use crate::bytecode::oparg::Label;
pub use crate::bytecode::oparg::LoadAttr;
pub use crate::bytecode::oparg::LoadSuperAttr;
pub use crate::bytecode::oparg::MakeFunctionFlag;
pub use crate::bytecode::oparg::MakeFunctionFlags;
pub use crate::bytecode::oparg::NameIdx;
pub use crate::bytecode::oparg::OpArg;
pub use crate::bytecode::oparg::OpArgByte;
pub use crate::bytecode::oparg::OpArgState;
pub use crate::bytecode::oparg::OpArgType;
pub use crate::bytecode::oparg::RaiseKind;
pub use crate::bytecode::oparg::SpecialMethod;
pub use crate::bytecode::oparg::UnpackExArgs;

Modules§

oparg

Structs§

Arg
Arguments
Argument structure
BasicBag
CoFastFlags
CodeFlags
CodeObject
Primary container of a single code object. Each python function has a code object. Also a module has a code object.
CodeUnit
align(2) so that the whole unit can be read with one aligned AtomicU16 access (see CodeUnits::read_unit) without relying on the allocator to happen to align the instruction array.
CodeUnits
Constants
ExceptionTableEntry
Exception table entry for zero-cost exception handling Format: (start, size, target, depth<<1|lasti)
StackEffect
What effect the instruction has on the stack.

Enums§

AnyInstruction
AnyOpcode
BorrowedConstant
A borrowed Constant
CoFastFlag
Per-slot kind flags for localsplus (co_localspluskinds). Values are bit positions (Local is bit 5 → mask 0x20).
ConstantData
A Constant (which usually encapsulates data within it)
Instruction
Opcode
PseudoInstruction
PseudoOpcode
PyCodeLocationInfoKind
CPython 3.11+ linetable location info codes

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_ARG
CO_FAST_ARG_KW
CO_FAST_ARG_POS
CO_FAST_ARG_VAR
CO_FAST_CELL
CO_FAST_FREE
CO_FAST_HIDDEN
CO_FAST_LOCAL
JUMP_BACKWARD_INITIAL_VALUE
Initial JUMP_BACKWARD counter bits (value/backoff = 4095/12).

Traits§

AsBag
Constant
ConstantBag
A Constant Bag
InstrDisplayContext

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.