From 96a21119db27bd42dc87fdb7b99b5e62ed16716e Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Wed, 21 Jan 2026 17:01:00 +0900 Subject: [PATCH 1/6] align psuedo ops --- Lib/_opcode_metadata.py | 40 ++++---- crates/codegen/src/ir.rs | 8 +- .../compiler-core/src/bytecode/instruction.rs | 92 +++++++++++-------- 3 files changed, 79 insertions(+), 61 deletions(-) diff --git a/Lib/_opcode_metadata.py b/Lib/_opcode_metadata.py index 6f426d452c..790104fd65 100644 --- a/Lib/_opcode_metadata.py +++ b/Lib/_opcode_metadata.py @@ -135,12 +135,12 @@ 'BINARY_OP_EXTEND': 132, 'BINARY_OP_MULTIPLY_FLOAT': 133, 'BINARY_OP_MULTIPLY_INT': 134, - 'BINARY_SUBSCR_DICT': 135, - 'BINARY_SUBSCR_GETITEM': 136, - 'BINARY_SUBSCR_LIST_INT': 137, - 'BINARY_SUBSCR_LIST_SLICE': 138, - 'BINARY_SUBSCR_STR_INT': 139, - 'BINARY_SUBSCR_TUPLE_INT': 140, + 'BINARY_OP_SUBSCR_DICT': 135, + 'BINARY_OP_SUBSCR_GETITEM': 136, + 'BINARY_OP_SUBSCR_LIST_INT': 137, + 'BINARY_OP_SUBSCR_LIST_SLICE': 138, + 'BINARY_OP_SUBSCR_STR_INT': 139, + 'BINARY_OP_SUBSCR_TUPLE_INT': 140, 'BINARY_OP_SUBTRACT_FLOAT': 141, 'BINARY_OP_SUBTRACT_INT': 142, 'CALL_ALLOC_AND_ENTER_INIT': 143, @@ -234,19 +234,21 @@ 'INSTRUMENTED_JUMP_BACKWARD': 253, 'INSTRUMENTED_LINE': 254, 'ENTER_EXECUTOR': 255, - 'JUMP': 256, - 'JUMP_NO_INTERRUPT': 257, - 'RESERVED_258': 258, - 'LOAD_ATTR_METHOD': 259, - 'LOAD_SUPER_METHOD': 260, - 'LOAD_ZERO_SUPER_ATTR': 261, - 'LOAD_ZERO_SUPER_METHOD': 262, - 'POP_BLOCK': 263, - 'SETUP_CLEANUP': 264, - 'SETUP_FINALLY': 265, - 'SETUP_WITH': 266, - 'STORE_FAST_MAYBE_NULL': 267, - 'LOAD_CLOSURE': 268, + 'ANNOTATIONS_PLACEHOLDER': 256, + 'JUMP': 257, + 'JUMP_IF_FALSE': 258, + 'JUMP_IF_TRUE': 259, + 'JUMP_NO_INTERRUPT': 260, + 'LOAD_CLOSURE': 261, + 'POP_BLOCK': 262, + 'SETUP_CLEANUP': 263, + 'SETUP_FINALLY': 264, + 'SETUP_WITH': 265, + 'STORE_FAST_MAYBE_NULL': 266, + 'LOAD_ATTR_METHOD': 267, + 'LOAD_SUPER_METHOD': 268, + 'LOAD_ZERO_SUPER_ATTR': 269, + 'LOAD_ZERO_SUPER_METHOD': 270, } # CPython 3.13 compatible: opcodes < 44 have no argument diff --git a/crates/codegen/src/ir.rs b/crates/codegen/src/ir.rs index 8d0d1f7f73..46b6898505 100644 --- a/crates/codegen/src/ir.rs +++ b/crates/codegen/src/ir.rs @@ -273,12 +273,14 @@ impl CodeInfo { PseudoInstruction::Jump { .. } => { // PseudoInstruction::Jump instructions are handled later } - PseudoInstruction::JumpNoInterrupt { .. } - | PseudoInstruction::Reserved258 + PseudoInstruction::AnnotationsPlaceholder + | PseudoInstruction::JumpIfFalse { .. } + | PseudoInstruction::JumpIfTrue { .. } + | PseudoInstruction::JumpNoInterrupt { .. } | PseudoInstruction::SetupCleanup | PseudoInstruction::SetupFinally | PseudoInstruction::SetupWith - | PseudoInstruction::StoreFastMaybeNull => { + | PseudoInstruction::StoreFastMaybeNull(_) => { unimplemented!("Got a placeholder pseudo instruction ({instr:?})") } } diff --git a/crates/compiler-core/src/bytecode/instruction.rs b/crates/compiler-core/src/bytecode/instruction.rs index 41619702b8..2d6d45b174 100644 --- a/crates/compiler-core/src/bytecode/instruction.rs +++ b/crates/compiler-core/src/bytecode/instruction.rs @@ -269,12 +269,12 @@ pub enum Instruction { BinaryOpExtend = 132, // Placeholder BinaryOpMultiplyFloat = 133, // Placeholder BinaryOpMultiplyInt = 134, // Placeholder - BinarySubscrDict = 135, // Placeholder - BinarySubscrGetitem = 136, // Placeholder - BinarySubscrListInt = 137, // Placeholder - BinarySubscrListSlice = 138, // Placeholder - BinarySubscrStrInt = 139, // Placeholder - BinarySubscrTupleInt = 140, // Placeholder + BinaryOpSubscrDict = 135, // Placeholder + BinaryOpSubscrGetitem = 136, // Placeholder + BinaryOpSubscrListInt = 137, // Placeholder + BinaryOpSubscrListSlice = 138, // Placeholder + BinaryOpSubscrStrInt = 139, // Placeholder + BinaryOpSubscrTupleInt = 140, // Placeholder BinaryOpSubtractFloat = 141, // Placeholder BinaryOpSubtractInt = 142, // Placeholder CallAllocAndEnterInit = 143, // Placeholder @@ -571,7 +571,7 @@ impl InstructionMetadata for Instruction { let UnpackExArgs { before, after } = args.get(arg); -1 + before as i32 + 1 + after as i32 } - Self::PopExcept => 0, + Self::PopExcept => -1, Self::PopIter => -1, Self::GetAwaitable => 0, Self::GetAIter => 0, @@ -624,12 +624,12 @@ impl InstructionMetadata for Instruction { Self::BinaryOpMultiplyInt => 0, Self::BinaryOpSubtractFloat => 0, Self::BinaryOpSubtractInt => 0, - Self::BinarySubscrDict => 0, - Self::BinarySubscrGetitem => 0, - Self::BinarySubscrListInt => 0, - Self::BinarySubscrListSlice => 0, - Self::BinarySubscrStrInt => 0, - Self::BinarySubscrTupleInt => 0, + Self::BinaryOpSubscrDict => 0, + Self::BinaryOpSubscrGetitem => 0, + Self::BinaryOpSubscrListInt => 0, + Self::BinaryOpSubscrListSlice => 0, + Self::BinaryOpSubscrStrInt => 0, + Self::BinaryOpSubscrTupleInt => 0, Self::CallAllocAndEnterInit => 0, Self::CallBoundMethodExactArgs => 0, Self::CallBoundMethodGeneral => 0, @@ -917,37 +917,48 @@ impl InstructionMetadata for Instruction { } /// Instructions used by the compiler. They are not executed by the VM. +/// +/// CPython 3.14.2 aligned (256-266), RustPython-specific variants start at 267. #[derive(Clone, Copy, Debug)] #[repr(u16)] pub enum PseudoInstruction { + // CPython 3.14.2 pseudo instructions (256-266) + AnnotationsPlaceholder = 256, Jump { target: Arg