diff --git a/crates/compiler-core/src/bytecode.rs b/crates/compiler-core/src/bytecode.rs index a17fe7945d..87349bfe6f 100644 --- a/crates/compiler-core/src/bytecode.rs +++ b/crates/compiler-core/src/bytecode.rs @@ -21,7 +21,8 @@ use rustpython_wtf8::{Wtf8, Wtf8Buf}; pub use crate::bytecode::{ instruction::{ - AnyInstruction, Arg, Instruction, InstructionMetadata, PseudoInstruction, StackEffect, + AnyInstruction, Arg, Instruction, InstructionMetadata, Opcode, PseudoInstruction, + PseudoOpcode, StackEffect, }, oparg::{ BinaryOperator, BuildSliceArgCount, CommonConstant, ComparisonOperator, ConvertValueOparg, diff --git a/crates/compiler-core/src/bytecode/instruction.rs b/crates/compiler-core/src/bytecode/instruction.rs index 76dc6a7938..d178c0d8d2 100644 --- a/crates/compiler-core/src/bytecode/instruction.rs +++ b/crates/compiler-core/src/bytecode/instruction.rs @@ -1,4 +1,4 @@ -use core::{fmt, marker::PhantomData, mem}; +use core::{fmt, marker::PhantomData}; use crate::{ bytecode::{ @@ -13,451 +13,486 @@ use crate::{ marshal::MarshalError, }; -/// A Single bytecode instruction that are executed by the VM. -/// -/// Currently aligned with CPython 3.14. -/// -/// ## See also -/// - [CPython opcode IDs](https://github.com/python/cpython/blob/v3.14.2/Include/opcode_ids.h) -#[derive(Clone, Copy, Debug)] -#[repr(u8)] -pub enum Instruction { - // No-argument instructions (opcode < HAVE_ARGUMENT=44) - Cache = 0, - BinarySlice = 1, - BuildTemplate = 2, - BinaryOpInplaceAddUnicode = 3, - CallFunctionEx = 4, - CheckEgMatch = 5, - CheckExcMatch = 6, - CleanupThrow = 7, - DeleteSubscr = 8, - EndFor = 9, - EndSend = 10, - ExitInitCheck = 11, // Placeholder - FormatSimple = 12, - FormatWithSpec = 13, - GetAIter = 14, - GetANext = 15, - GetIter = 16, - Reserved = 17, - GetLen = 18, - GetYieldFromIter = 19, - InterpreterExit = 20, // Placeholder - LoadBuildClass = 21, - LoadLocals = 22, - MakeFunction = 23, - MatchKeys = 24, - MatchMapping = 25, - MatchSequence = 26, - Nop = 27, - NotTaken = 28, - PopExcept = 29, - PopIter = 30, - PopTop = 31, - PushExcInfo = 32, - PushNull = 33, - ReturnGenerator = 34, - ReturnValue = 35, - SetupAnnotations = 36, - StoreSlice = 37, - StoreSubscr = 38, - ToBool = 39, - UnaryInvert = 40, - UnaryNegative = 41, - UnaryNot = 42, - WithExceptStart = 43, - // CPython 3.14 opcodes with arguments (44-120) - BinaryOp { - op: Arg, - } = 44, - /// Build an Interpolation from value, expression string, and optional format_spec on stack. - /// - /// oparg encoding: (conversion << 2) | has_format_spec - /// - has_format_spec (bit 0): if 1, format_spec is on stack - /// - conversion (bits 2+): 0=None, 1=Str, 2=Repr, 3=Ascii - /// - /// Stack: [value, expression_str, format_spec?] -> [interpolation] - BuildInterpolation { - format: Arg, - } = 45, - BuildList { - count: Arg, - } = 46, - BuildMap { - count: Arg, - } = 47, - BuildSet { - count: Arg, - } = 48, - BuildSlice { - argc: Arg, - } = 49, - BuildString { - count: Arg, - } = 50, - BuildTuple { - count: Arg, - } = 51, - Call { - argc: Arg, - } = 52, - CallIntrinsic1 { - func: Arg, - } = 53, - CallIntrinsic2 { - func: Arg, - } = 54, - CallKw { - argc: Arg, - } = 55, - CompareOp { - opname: Arg, - } = 56, - ContainsOp { - invert: Arg, - } = 57, - ConvertValue { - oparg: Arg, - } = 58, - Copy { - i: Arg, - } = 59, - CopyFreeVars { - n: Arg, - } = 60, - DeleteAttr { - namei: Arg, - } = 61, - DeleteDeref { - i: Arg, - } = 62, - DeleteFast { - var_num: Arg, - } = 63, - DeleteGlobal { - namei: Arg, - } = 64, - DeleteName { - namei: Arg, - } = 65, - DictMerge { - i: Arg, - } = 66, - DictUpdate { - i: Arg, - } = 67, - EndAsyncFor = 68, - ExtendedArg = 69, - ForIter { - delta: Arg