diff --git a/crates/codegen/src/compile.rs b/crates/codegen/src/compile.rs index ea2711cd33..b0cbbf501f 100644 --- a/crates/codegen/src/compile.rs +++ b/crates/codegen/src/compile.rs @@ -6881,9 +6881,9 @@ impl Compiler { self, Instruction::Resume { context: if is_await { - u32::from(bytecode::ResumeType::AfterAwait) + bytecode::ResumeType::AfterAwait } else { - u32::from(bytecode::ResumeType::AfterYieldFrom) + bytecode::ResumeType::AfterYieldFrom } } ); @@ -7055,7 +7055,7 @@ impl Compiler { emit!( self, Instruction::Resume { - context: u32::from(bytecode::ResumeType::AfterYield) + context: bytecode::ResumeType::AfterYield } ); } @@ -7277,7 +7277,7 @@ impl Compiler { emit!( compiler, Instruction::Resume { - context: u32::from(bytecode::ResumeType::AfterYield) + context: bytecode::ResumeType::AfterYield } ); emit!(compiler, Instruction::PopTop); diff --git a/crates/compiler-core/src/bytecode/instruction.rs b/crates/compiler-core/src/bytecode/instruction.rs index 9d4856851e..cd85e2458d 100644 --- a/crates/compiler-core/src/bytecode/instruction.rs +++ b/crates/compiler-core/src/bytecode/instruction.rs @@ -304,7 +304,7 @@ pub enum Instruction { } = 120, // CPython 3.14 RESUME (128) Resume { - context: Arg, + context: Arg, } = 128, // CPython 3.14 specialized opcodes (129-211) BinaryOpAddFloat = 129, // Placeholder diff --git a/crates/compiler-core/src/bytecode/oparg.rs b/crates/compiler-core/src/bytecode/oparg.rs index 2fa40ce227..4b274408ad 100644 --- a/crates/compiler-core/src/bytecode/oparg.rs +++ b/crates/compiler-core/src/bytecode/oparg.rs @@ -276,16 +276,47 @@ impl fmt::Display for ConvertValueOparg { } } -oparg_enum!( - /// Resume type for the RESUME instruction - #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] - pub enum ResumeType { - AtFuncStart = 0, - AfterYield = 1, - AfterYieldFrom = 2, - AfterAwait = 3, +/// Resume type for the RESUME instruction +#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] +pub enum ResumeType { + AtFuncStart, + AfterYield, + AfterYieldFrom, + AfterAwait, + Other(u32), +} + +impl From for ResumeType { + fn from(value: u32) -> Self { + match value { + 0 => Self::AtFuncStart, + 1 => Self::AfterYield, + 2 => Self::AfterYieldFrom, + 3 => Self::AfterAwait, + _ => Self::Other(value), + } } -); +} + +impl From for u32 { + fn from(typ: ResumeType) -> Self { + match typ { + ResumeType::AtFuncStart => 0, + ResumeType::AfterYield => 1, + ResumeType::AfterYieldFrom => 2, + ResumeType::AfterAwait => 3, + ResumeType::Other(v) => v, + } + } +} + +impl core::fmt::Display for ResumeType { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + u32::from(*self).fmt(f) + } +} + +impl OpArgType for ResumeType {} pub type NameIdx = u32; @@ -714,6 +745,7 @@ macro_rules! newtype_oparg { self.0.fmt(f) } } + impl OpArgType for $name {} } }