pub enum Instruction {
Show 89 variants
ImportName {
idx: NameIdx,
},
ImportNameless,
ImportStar,
ImportFrom {
idx: NameIdx,
},
LoadFast(NameIdx),
LoadNameAny(NameIdx),
LoadGlobal(NameIdx),
LoadDeref(NameIdx),
LoadClassDeref(NameIdx),
StoreFast(NameIdx),
StoreLocal(NameIdx),
StoreGlobal(NameIdx),
StoreDeref(NameIdx),
DeleteFast(NameIdx),
DeleteLocal(NameIdx),
DeleteGlobal(NameIdx),
DeleteDeref(NameIdx),
LoadClosure(NameIdx),
Subscript,
StoreSubscript,
DeleteSubscript,
StoreAttr {
idx: NameIdx,
},
DeleteAttr {
idx: NameIdx,
},
LoadConst {
idx: u32,
},
UnaryOperation {
op: UnaryOperator,
},
BinaryOperation {
op: BinaryOperator,
},
BinaryOperationInplace {
op: BinaryOperator,
},
LoadAttr {
idx: NameIdx,
},
TestOperation {
op: TestOperator,
},
CompareOperation {
op: ComparisonOperator,
},
Pop,
Rotate2,
Rotate3,
Duplicate,
Duplicate2,
GetIter,
Continue {
target: Label,
},
Break {
target: Label,
},
Jump {
target: Label,
},
JumpIfTrue {
target: Label,
},
JumpIfFalse {
target: Label,
},
JumpIfTrueOrPop {
target: Label,
},
JumpIfFalseOrPop {
target: Label,
},
MakeFunction(MakeFunctionFlags),
CallFunctionPositional {
nargs: u32,
},
CallFunctionKeyword {
nargs: u32,
},
CallFunctionEx {
has_kwargs: bool,
},
LoadMethod {
idx: NameIdx,
},
CallMethodPositional {
nargs: u32,
},
CallMethodKeyword {
nargs: u32,
},
CallMethodEx {
has_kwargs: bool,
},
ForIter {
target: Label,
},
ReturnValue,
YieldValue,
YieldFrom,
SetupAnnotation,
SetupLoop {
break_target: Label,
},
SetupFinally {
handler: Label,
},
EnterFinally,
EndFinally,
SetupExcept {
handler: Label,
},
SetupWith {
end: Label,
},
WithCleanupStart,
WithCleanupFinish,
PopBlock,
Raise {
kind: RaiseKind,
},
BuildString {
size: u32,
},
BuildTuple {
unpack: bool,
size: u32,
},
BuildList {
unpack: bool,
size: u32,
},
BuildSet {
unpack: bool,
size: u32,
},
BuildMap {
unpack: bool,
for_call: bool,
size: u32,
},
DictUpdate,
BuildSlice {
step: bool,
},
ListAppend {
i: u32,
},
SetAdd {
i: u32,
},
MapAdd {
i: u32,
},
PrintExpr,
LoadBuildClass,
UnpackSequence {
size: u32,
},
UnpackEx {
before: u8,
after: u8,
},
FormatValue {
conversion: ConversionFlag,
},
PopException,
Reverse {
amount: u32,
},
GetAwaitable,
BeforeAsyncWith,
SetupAsyncWith {
end: Label,
},
GetAIter,
GetANext,
EndAsyncFor,
}
Expand description
A Single bytecode instruction.
Variants§
ImportName
Importing by name
ImportNameless
Importing without name
ImportStar
Import *
ImportFrom
from … import …
LoadFast(NameIdx)
LoadNameAny(NameIdx)
LoadGlobal(NameIdx)
LoadDeref(NameIdx)
LoadClassDeref(NameIdx)
StoreFast(NameIdx)
StoreLocal(NameIdx)
StoreGlobal(NameIdx)
StoreDeref(NameIdx)
DeleteFast(NameIdx)
DeleteLocal(NameIdx)
DeleteGlobal(NameIdx)
DeleteDeref(NameIdx)
LoadClosure(NameIdx)
Subscript
StoreSubscript
DeleteSubscript
StoreAttr
DeleteAttr
LoadConst
UnaryOperation
Fields
op: UnaryOperator
BinaryOperation
Fields
op: BinaryOperator
BinaryOperationInplace
Fields
op: BinaryOperator
LoadAttr
TestOperation
Fields
op: TestOperator
CompareOperation
Fields
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(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
BuildList
BuildSet
BuildMap
DictUpdate
BuildSlice
ListAppend
SetAdd
MapAdd
PrintExpr
LoadBuildClass
UnpackSequence
UnpackEx
FormatValue
Fields
conversion: ConversionFlag
PopException
Reverse
GetAwaitable
BeforeAsyncWith
SetupAsyncWith
GetAIter
GetANext
EndAsyncFor
Implementations§
source§impl Instruction
impl Instruction
sourcepub fn label_arg(&self) -> Option<&Label>
pub fn label_arg(&self) -> Option<&Label>
Gets the label stored inside this instruction, if it exists
sourcepub fn label_arg_mut(&mut self) -> Option<&mut Label>
pub fn label_arg_mut(&mut self) -> Option<&mut Label>
Gets a mutable reference to 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::{Instruction, Label};
let label = Label(0xF);
let jump_inst = Instruction::Jump {target: label};
assert!(jump_inst.unconditional_branch())
sourcepub fn stack_effect(&self, jump: bool) -> i32
pub fn stack_effect(&self, jump: bool) -> i32
What effect this instruction has on the stack
Examples
use rustpython_compiler_core::{Instruction, Label, UnaryOperator};
let jump_instruction = Instruction::Jump {target: Label(0xF)};
let invert_instruction = Instruction::UnaryOperation {op: UnaryOperator::Invert};
assert_eq!(jump_instruction.stack_effect(true), 0);
assert_eq!(invert_instruction.stack_effect(false), 0);
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<'de> Deserialize<'de> for Instruction
impl<'de> Deserialize<'de> for Instruction
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl PartialEq<Instruction> for Instruction
impl PartialEq<Instruction> 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 ==
.