#[repr(u8)]pub enum Instruction {
Show 99 variants
ImportName {
idx: Arg<u32>,
},
ImportNameless,
ImportStar,
ImportFrom {
idx: Arg<u32>,
},
LoadFast(Arg<u32>),
LoadNameAny(Arg<u32>),
LoadGlobal(Arg<u32>),
LoadDeref(Arg<u32>),
LoadClassDeref(Arg<u32>),
StoreFast(Arg<u32>),
StoreLocal(Arg<u32>),
StoreGlobal(Arg<u32>),
StoreDeref(Arg<u32>),
DeleteFast(Arg<u32>),
DeleteLocal(Arg<u32>),
DeleteGlobal(Arg<u32>),
DeleteDeref(Arg<u32>),
LoadClosure(Arg<u32>),
Subscript,
StoreSubscript,
DeleteSubscript,
StoreAttr {
idx: Arg<u32>,
},
DeleteAttr {
idx: Arg<u32>,
},
LoadConst {
idx: Arg<u32>,
},
UnaryOperation {
op: Arg<UnaryOperator>,
},
BinaryOperation {
op: Arg<BinaryOperator>,
},
BinaryOperationInplace {
op: Arg<BinaryOperator>,
},
LoadAttr {
idx: Arg<u32>,
},
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<u32>,
},
CallMethodPositional {
nargs: Arg<u32>,
},
CallMethodKeyword {
nargs: Arg<u32>,
},
CallMethodEx {
has_kwargs: Arg<bool>,
},
ForIter {
target: Arg<Label>,
},
ReturnValue,
ReturnConst {
idx: Arg<u32>,
},
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,
TypeVar,
TypeVarWithBound,
TypeVarWithConstraint,
TypeAlias,
}
Expand description
A Single bytecode instruction.
Variants§
ImportName
Importing by name
ImportNameless
Importing without name
ImportStar
Import *
ImportFrom
from … import …
LoadFast(Arg<u32>)
LoadNameAny(Arg<u32>)
LoadGlobal(Arg<u32>)
LoadDeref(Arg<u32>)
LoadClassDeref(Arg<u32>)
StoreFast(Arg<u32>)
StoreLocal(Arg<u32>)
StoreGlobal(Arg<u32>)
StoreDeref(Arg<u32>)
DeleteFast(Arg<u32>)
DeleteLocal(Arg<u32>)
DeleteGlobal(Arg<u32>)
DeleteDeref(Arg<u32>)
LoadClosure(Arg<u32>)
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
ReturnConst
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
TypeVar
TypeVarWithBound
TypeVarWithConstraint
TypeAlias
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 PartialEq for Instruction
impl PartialEq for Instruction
Source§impl TryFrom<u8> for Instruction
impl TryFrom<u8> for Instruction
Source§type Error = MarshalError
type Error = MarshalError
Source§fn try_from(value: u8) -> Result<Instruction, MarshalError>
fn try_from(value: u8) -> Result<Instruction, MarshalError>
impl Copy for Instruction
impl Eq for Instruction
impl StructuralPartialEq for Instruction
Auto Trait Implementations§
impl Freeze for Instruction
impl RefUnwindSafe for Instruction
impl Send for Instruction
impl Sync for Instruction
impl Unpin for Instruction
impl UnwindSafe for Instruction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more