#[repr(u8)]pub enum Instruction {
Show 94 variants
ImportName {
idx: Arg<NameIdx>,
},
ImportNameless,
ImportStar,
ImportFrom {
idx: Arg<NameIdx>,
},
LoadFast(Arg<NameIdx>),
LoadNameAny(Arg<NameIdx>),
LoadGlobal(Arg<NameIdx>),
LoadDeref(Arg<NameIdx>),
LoadClassDeref(Arg<NameIdx>),
StoreFast(Arg<NameIdx>),
StoreLocal(Arg<NameIdx>),
StoreGlobal(Arg<NameIdx>),
StoreDeref(Arg<NameIdx>),
DeleteFast(Arg<NameIdx>),
DeleteLocal(Arg<NameIdx>),
DeleteGlobal(Arg<NameIdx>),
DeleteDeref(Arg<NameIdx>),
LoadClosure(Arg<NameIdx>),
Subscript,
StoreSubscript,
DeleteSubscript,
StoreAttr {
idx: Arg<NameIdx>,
},
DeleteAttr {
idx: Arg<NameIdx>,
},
LoadConst {
idx: Arg<u32>,
},
UnaryOperation {
op: Arg<UnaryOperator>,
},
BinaryOperation {
op: Arg<BinaryOperator>,
},
BinaryOperationInplace {
op: Arg<BinaryOperator>,
},
LoadAttr {
idx: Arg<NameIdx>,
},
TestOperation {
op: Arg<TestOperator>,
},
CompareOperation {
op: Arg<ComparisonOperator>,
},
Pop,
Rotate2,
Rotate3,
Duplicate,
Duplicate2,
GetIter,
Continue {
target: Arg<Label>,
},
Break {
target: Arg<Label>,
},
Jump {
target: Arg<Label>,
},
JumpIfTrue {
target: Arg<Label>,
},
JumpIfFalse {
target: Arg<Label>,
},
JumpIfTrueOrPop {
target: Arg<Label>,
},
JumpIfFalseOrPop {
target: Arg<Label>,
},
MakeFunction(Arg<MakeFunctionFlags>),
CallFunctionPositional {
nargs: Arg<u32>,
},
CallFunctionKeyword {
nargs: Arg<u32>,
},
CallFunctionEx {
has_kwargs: Arg<bool>,
},
LoadMethod {
idx: Arg<NameIdx>,
},
CallMethodPositional {
nargs: Arg<u32>,
},
CallMethodKeyword {
nargs: Arg<u32>,
},
CallMethodEx {
has_kwargs: Arg<bool>,
},
ForIter {
target: Arg<Label>,
},
ReturnValue,
YieldValue,
YieldFrom,
SetupAnnotation,
SetupLoop,
SetupFinally {
handler: Arg<Label>,
},
EnterFinally,
EndFinally,
SetupExcept {
handler: Arg<Label>,
},
SetupWith {
end: Arg<Label>,
},
WithCleanupStart,
WithCleanupFinish,
PopBlock,
Raise {
kind: Arg<RaiseKind>,
},
BuildString {
size: Arg<u32>,
},
BuildTuple {
size: Arg<u32>,
},
BuildTupleUnpack {
size: Arg<u32>,
},
BuildList {
size: Arg<u32>,
},
BuildListUnpack {
size: Arg<u32>,
},
BuildSet {
size: Arg<u32>,
},
BuildSetUnpack {
size: Arg<u32>,
},
BuildMap {
size: Arg<u32>,
},
BuildMapForCall {
size: Arg<u32>,
},
DictUpdate,
BuildSlice {
step: Arg<bool>,
},
ListAppend {
i: Arg<u32>,
},
SetAdd {
i: Arg<u32>,
},
MapAdd {
i: Arg<u32>,
},
PrintExpr,
LoadBuildClass,
UnpackSequence {
size: Arg<u32>,
},
UnpackEx {
args: Arg<UnpackExArgs>,
},
FormatValue {
conversion: Arg<ConversionFlag>,
},
PopException,
Reverse {
amount: Arg<u32>,
},
GetAwaitable,
BeforeAsyncWith,
SetupAsyncWith {
end: Arg<Label>,
},
GetAIter,
GetANext,
EndAsyncFor,
ExtendedArg,
}
Expand description
A Single bytecode instruction.
Variants§
ImportName
Importing by name
ImportNameless
Importing without name
ImportStar
Import *
ImportFrom
from … import …
LoadFast(Arg<NameIdx>)
LoadNameAny(Arg<NameIdx>)
LoadGlobal(Arg<NameIdx>)
LoadDeref(Arg<NameIdx>)
LoadClassDeref(Arg<NameIdx>)
StoreFast(Arg<NameIdx>)
StoreLocal(Arg<NameIdx>)
StoreGlobal(Arg<NameIdx>)
StoreDeref(Arg<NameIdx>)
DeleteFast(Arg<NameIdx>)
DeleteLocal(Arg<NameIdx>)
DeleteGlobal(Arg<NameIdx>)
DeleteDeref(Arg<NameIdx>)
LoadClosure(Arg<NameIdx>)
Subscript
StoreSubscript
DeleteSubscript
StoreAttr
DeleteAttr
LoadConst
UnaryOperation
Fields
op: Arg<UnaryOperator>
BinaryOperation
Fields
op: Arg<BinaryOperator>
BinaryOperationInplace
Fields
op: Arg<BinaryOperator>
LoadAttr
TestOperation
Fields
op: Arg<TestOperator>
CompareOperation
Fields
op: Arg<ComparisonOperator>
Pop
Rotate2
Rotate3
Duplicate
Duplicate2
GetIter
Continue
Break
Jump
JumpIfTrue
Pop the top of the stack, and jump if this value is true.
JumpIfFalse
Pop the top of the stack, and jump if this value is false.
JumpIfTrueOrPop
Peek at the top of the stack, and jump if this value is true. Otherwise, pop top of stack.
JumpIfFalseOrPop
Peek at the top of the stack, and jump if this value is false. Otherwise, pop top of stack.
MakeFunction(Arg<MakeFunctionFlags>)
CallFunctionPositional
CallFunctionKeyword
CallFunctionEx
LoadMethod
CallMethodPositional
CallMethodKeyword
CallMethodEx
ForIter
ReturnValue
YieldValue
YieldFrom
SetupAnnotation
SetupLoop
SetupFinally
Setup a finally handler, which will be called whenever one of this events occurs:
- the block is popped
- the function returns
- an exception is returned
EnterFinally
Enter a finally block, without returning, excepting, just because we are there.
EndFinally
Marker bytecode for the end of a finally sequence. When this bytecode is executed, the eval loop does one of those things:
- Continue at a certain bytecode position
- Propagate the exception
- Return from a function
- Do nothing at all, just continue
SetupExcept
SetupWith
WithCleanupStart
WithCleanupFinish
PopBlock
Raise
BuildString
BuildTuple
BuildTupleUnpack
BuildList
BuildListUnpack
BuildSet
BuildSetUnpack
BuildMap
BuildMapForCall
DictUpdate
BuildSlice
ListAppend
SetAdd
MapAdd
PrintExpr
LoadBuildClass
UnpackSequence
UnpackEx
Fields
args: Arg<UnpackExArgs>
FormatValue
Fields
conversion: Arg<ConversionFlag>
PopException
Reverse
GetAwaitable
BeforeAsyncWith
SetupAsyncWith
GetAIter
GetANext
EndAsyncFor
ExtendedArg
Implementations§
source§impl Instruction
impl Instruction
sourcepub fn label_arg(&self) -> Option<Arg<Label>>
pub fn label_arg(&self) -> Option<Arg<Label>>
Gets the label stored inside this instruction, if it exists
sourcepub fn unconditional_branch(&self) -> bool
pub fn unconditional_branch(&self) -> bool
Whether this is an unconditional branching
§Examples
use rustpython_compiler_core::bytecode::{Arg, Instruction};
let jump_inst = Instruction::Jump { target: Arg::marker() };
assert!(jump_inst.unconditional_branch())
sourcepub fn stack_effect(&self, arg: OpArg, jump: bool) -> i32
pub fn stack_effect(&self, arg: OpArg, jump: bool) -> i32
What effect this instruction has on the stack
§Examples
use rustpython_compiler_core::bytecode::{Arg, Instruction, Label, UnaryOperator};
let (target, jump_arg) = Arg::new(Label(0xF));
let jump_instruction = Instruction::Jump { target };
let (op, invert_arg) = Arg::new(UnaryOperator::Invert);
let invert_instruction = Instruction::UnaryOperation { op };
assert_eq!(jump_instruction.stack_effect(jump_arg, true), 0);
assert_eq!(invert_instruction.stack_effect(invert_arg, false), 0);
pub fn display<'a>( &'a self, arg: OpArg, ctx: &'a impl InstrDisplayContext ) -> impl Display + 'a
Trait Implementations§
source§impl Clone for Instruction
impl Clone for Instruction
source§fn clone(&self) -> Instruction
fn clone(&self) -> Instruction
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Instruction
impl Debug for Instruction
source§impl From<Instruction> for u8
impl From<Instruction> for u8
source§fn from(ins: Instruction) -> u8
fn from(ins: Instruction) -> u8
source§impl PartialEq for Instruction
impl PartialEq for Instruction
source§fn eq(&self, other: &Instruction) -> bool
fn eq(&self, other: &Instruction) -> bool
self
and other
values to be equal, and is used
by ==
.