From c23b891ac4cd937dd7749b8e2cfca6fff7253ad0 Mon Sep 17 00:00:00 2001 From: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Sat, 10 Jan 2026 15:23:32 +0200 Subject: [PATCH 1/7] Move `Instruction` to its own file --- crates/compiler-core/src/bytecode.rs | 771 +---------------- .../compiler-core/src/bytecode/instruction.rs | 814 ++++++++++++++++++ 2 files changed, 818 insertions(+), 767 deletions(-) create mode 100644 crates/compiler-core/src/bytecode/instruction.rs diff --git a/crates/compiler-core/src/bytecode.rs b/crates/compiler-core/src/bytecode.rs index 010e414cc89..61707b7757e 100644 --- a/crates/compiler-core/src/bytecode.rs +++ b/crates/compiler-core/src/bytecode.rs @@ -14,6 +14,10 @@ use malachite_bigint::BigInt; use num_complex::Complex64; use rustpython_wtf8::{Wtf8, Wtf8Buf}; +pub use crate::bytecode::instruction::Instruction; + +mod instruction; + /// Exception table entry for zero-cost exception handling /// Format: (start, size, target, depth<<1|lasti) #[derive(Clone, Debug, PartialEq, Eq)] @@ -670,356 +674,6 @@ op_arg_enum!( pub type NameIdx = u32; -/// A Single bytecode instruction. -/// Instructions are ordered to match CPython 3.13 opcode numbers exactly. -/// HAVE_ARGUMENT = 44: opcodes 0-43 have no argument, 44+ have arguments. -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -#[repr(u8)] -pub enum Instruction { - // ==================== No-argument instructions (opcode < 44) ==================== - Cache = 0, // Placeholder - BeforeAsyncWith = 1, - BeforeWith = 2, - BinaryOpInplaceAddUnicode = 3, // Placeholder - BinarySlice = 4, // Placeholder - BinarySubscr = 5, - CheckEgMatch = 6, - CheckExcMatch = 7, - CleanupThrow = 8, - DeleteSubscr = 9, - EndAsyncFor = 10, - EndFor = 11, // Placeholder - EndSend = 12, - ExitInitCheck = 13, // Placeholder - FormatSimple = 14, - FormatWithSpec = 15, - GetAIter = 16, - Reserved = 17, - GetANext = 18, - GetIter = 19, - GetLen = 20, - GetYieldFromIter = 21, - InterpreterExit = 22, // Placeholder - LoadAssertionError = 23, // Placeholder - LoadBuildClass = 24, - LoadLocals = 25, // Placeholder - MakeFunction = 26, - MatchKeys = 27, - MatchMapping = 28, - MatchSequence = 29, - Nop = 30, - PopExcept = 31, - PopTop = 32, - PushExcInfo = 33, - PushNull = 34, // Placeholder - ReturnGenerator = 35, // Placeholder - ReturnValue = 36, - SetupAnnotations = 37, - StoreSlice = 38, // Placeholder - StoreSubscr = 39, - ToBool = 40, - UnaryInvert = 41, - UnaryNegative = 42, - UnaryNot = 43, - WithExceptStart = 44, - // ==================== With-argument instructions (opcode > 44) ==================== - BinaryOp { - op: Arg, - } = 45, - BuildConstKeyMap { - size: Arg, - } = 46, // Placeholder - BuildList { - size: Arg, - } = 47, - BuildMap { - size: Arg, - } = 48, - BuildSet { - size: Arg, - } = 49, - BuildSlice { - argc: Arg, - } = 50, - BuildString { - size: Arg, - } = 51, - BuildTuple { - size: Arg, - } = 52, - Call { - nargs: Arg, - } = 53, - CallFunctionEx { - has_kwargs: Arg, - } = 54, - CallIntrinsic1 { - func: Arg, - } = 55, - CallIntrinsic2 { - func: Arg, - } = 56, - CallKw { - nargs: Arg, - } = 57, - CompareOp { - op: Arg, - } = 58, - ContainsOp(Arg) = 59, - ConvertValue { - oparg: Arg, - } = 60, - CopyItem { - index: Arg, - } = 61, - CopyFreeVars { - count: Arg, - } = 62, // Placeholder - DeleteAttr { - idx: Arg, - } = 63, - DeleteDeref(Arg) = 64, - DeleteFast(Arg) = 65, - DeleteGlobal(Arg) = 66, - DeleteName(Arg) = 67, - DictMerge { - index: Arg, - } = 68, // Placeholder - DictUpdate { - index: Arg, - } = 69, - EnterExecutor = 70, // Placeholder - ExtendedArg = 71, - ForIter { - target: Arg