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

Fields

§idx: NameIdx

Importing by name

§

ImportNameless

Importing without name

§

ImportStar

Import *

§

ImportFrom

Fields

§idx: NameIdx

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

Fields

§idx: NameIdx
§

DeleteAttr

Fields

§idx: NameIdx
§

LoadConst

Fields

§idx: u32

index into constants vec

§

UnaryOperation

Fields

§

BinaryOperation

Fields

§

BinaryOperationInplace

Fields

§

LoadAttr

Fields

§idx: NameIdx
§

TestOperation

Fields

§

CompareOperation

§

Pop

§

Rotate2

§

Rotate3

§

Duplicate

§

Duplicate2

§

GetIter

§

Continue

Fields

§target: Label
§

Break

Fields

§target: Label
§

Jump

Fields

§target: Label
§

JumpIfTrue

Fields

§target: Label

Pop the top of the stack, and jump if this value is true.

§

JumpIfFalse

Fields

§target: Label

Pop the top of the stack, and jump if this value is false.

§

JumpIfTrueOrPop

Fields

§target: Label

Peek at the top of the stack, and jump if this value is true. Otherwise, pop top of stack.

§

JumpIfFalseOrPop

Fields

§target: Label

Peek at the top of the stack, and jump if this value is false. Otherwise, pop top of stack.

§

MakeFunction(MakeFunctionFlags)

§

CallFunctionPositional

Fields

§nargs: u32
§

CallFunctionKeyword

Fields

§nargs: u32
§

CallFunctionEx

Fields

§has_kwargs: bool
§

LoadMethod

Fields

§idx: NameIdx
§

CallMethodPositional

Fields

§nargs: u32
§

CallMethodKeyword

Fields

§nargs: u32
§

CallMethodEx

Fields

§has_kwargs: bool
§

ForIter

Fields

§target: Label
§

ReturnValue

§

YieldValue

§

YieldFrom

§

SetupAnnotation

§

SetupLoop

Fields

§break_target: Label
§

SetupFinally

Fields

§handler: Label

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

Fields

§handler: Label
§

SetupWith

Fields

§end: Label
§

WithCleanupStart

§

WithCleanupFinish

§

PopBlock

§

Raise

Fields

§

BuildString

Fields

§size: u32
§

BuildTuple

Fields

§unpack: bool
§size: u32
§

BuildList

Fields

§unpack: bool
§size: u32
§

BuildSet

Fields

§unpack: bool
§size: u32
§

BuildMap

Fields

§unpack: bool
§for_call: bool
§size: u32
§

DictUpdate

§

BuildSlice

Fields

§step: bool

whether build a slice with a third step argument

§

ListAppend

Fields

§i: u32
§

SetAdd

Fields

§i: u32
§

MapAdd

Fields

§i: u32
§

PrintExpr

§

LoadBuildClass

§

UnpackSequence

Fields

§size: u32
§

UnpackEx

Fields

§before: u8
§after: u8
§

FormatValue

Fields

§conversion: ConversionFlag
§

PopException

§

Reverse

Fields

§amount: u32
§

GetAwaitable

§

BeforeAsyncWith

§

SetupAsyncWith

Fields

§end: Label
§

GetAIter

§

GetANext

§

EndAsyncFor

Implementations§

Gets the label stored inside this instruction, if it exists

Gets a mutable reference to the label stored inside this instruction, if it exists

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())

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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.