Repository: RustPython/RustPython
File: crates/compiler-core/src/bytecode/instruction.rs (Rust)

Code before:
    // So we assign random IDs to these opcodes.
    Break {
        target: Arg<Label>,
    } = 119,
    BuildListFromTuples {
        size: Arg<u32>,
    } = 120,
    BuildMapForCall {
        size: Arg<u32>,
    } = 121,
    BuildSetFromTuples {
        size: Arg<u32>,
    } = 122,
    BuildTupleFromIter = 123,
    BuildTupleFromTuples {
        size: Arg<u32>,
    } = 124,
    Continue {
        target: Arg<Label>,
    } = 128,
    JumpIfFalseOrPop {
        target: Arg<Label>,
    } = 129,
    JumpIfTrueOrPop {
        target: Arg<Label>,
    } = 130,
    JumpIfNotExcMatch(Arg<Label>) = 131,
    SetExcInfo = 134,
    Subscript = 135,
    // Pseudos (needs to be moved to `PseudoInstruction` enum.
    LoadClosure(Arg<NameIdx>) = 253, // TODO: Move to pseudos
}

const _: () = assert!(mem::size_of::<Instruction>() == 1);

impl From<Instruction> for u8 {
    #[inline]
    fn from(ins: Instruction) -> Self {
        // SAFETY: there's no padding bits
        unsafe { mem::transmute::<Instruction, Self>(ins) }
    }
}

impl TryFrom<u8> for Instruction {
    type Error = MarshalError;

    #[inline]
    fn try_from(value: u8) -> Result<Self, MarshalError> {
        // CPython-compatible opcodes (0-118)
        let cpython_start = u8::from(Self::Cache);
        let cpython_end = u8::from(Self::YieldValue { arg: Arg::marker() });

Review comment (suggestion):
The bytecode already has to be purged because `LoadClosure` is no longer 253. So I've moved these as well

Code after:
    } = 119,
    BuildListFromTuples {
        size: Arg<u32>,
    } = 120,
    BuildMapForCall {
        size: Arg<u32>,
    } = 121,
    BuildSetFromTuples {
        size: Arg<u32>,
    } = 122,
    BuildTupleFromIter = 123,
    BuildTupleFromTuples {
        size: Arg<u32>,
    } = 124,
    Continue {
        target: Arg<Label>,
    } = 128,
    JumpIfFalseOrPop {
        target: Arg<Label>,
    } = 129,
    JumpIfTrueOrPop {
        target: Arg<Label>,
    } = 130,
    JumpIfNotExcMatch(Arg<Label>) = 131,
    SetExcInfo = 132,
    Subscript = 133,
    // End of custom instructions
    Resume {
        arg: Arg<u32>,
    } = 149,
    BinaryOpAddFloat = 150,                     // Placeholder
    BinaryOpAddInt = 151,                       // Placeholder
    BinaryOpAddUnicode = 152,                   // Placeholder
    BinaryOpMultiplyFloat = 153,                // Placeholder
    BinaryOpMultiplyInt = 154,                  // Placeholder
    BinaryOpSubtractFloat = 155,                // Placeholder
    BinaryOpSubtractInt = 156,                  // Placeholder
    BinarySubscrDict = 157,                     // Placeholder
    BinarySubscrGetitem = 158,                  // Placeholder
    BinarySubscrListInt = 159,                  // Placeholder
    BinarySubscrStrInt = 160,                   // Placeholder
    BinarySubscrTupleInt = 161,                 // Placeholder
    CallAllocAndEnterInit = 162,                // Placeholder
    CallBoundMethodExactArgs = 163,             // Placeholder
    CallBoundMethodGeneral = 164,               // Placeholder
    CallBuiltinClass = 165,                     // Placeholder
    CallBuiltinFast = 166,                      // Placeholder
    CallBuiltinFastWithKeywords = 167,          // Placeholder
    CallBuiltinO = 168,                         // Placeholder
    CallIsinstance = 169,                       // Placeholder
    CallLen = 170,                              // Placeholder