Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
);
Expand Down Expand Up @@ -7055,7 +7055,7 @@ impl Compiler {
emit!(
self,
Instruction::Resume {
context: u32::from(bytecode::ResumeType::AfterYield)
context: bytecode::ResumeType::AfterYield
}
);
}
Expand Down Expand Up @@ -7277,7 +7277,7 @@ impl Compiler {
emit!(
compiler,
Instruction::Resume {
context: u32::from(bytecode::ResumeType::AfterYield)
context: bytecode::ResumeType::AfterYield
}
);
emit!(compiler, Instruction::PopTop);
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler-core/src/bytecode/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ pub enum Instruction {
} = 120,
// CPython 3.14 RESUME (128)
Resume {
context: Arg<u32>,
context: Arg<oparg::ResumeType>,
} = 128,
// CPython 3.14 specialized opcodes (129-211)
BinaryOpAddFloat = 129, // Placeholder
Expand Down
50 changes: 41 additions & 9 deletions crates/compiler-core/src/bytecode/oparg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> 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<ResumeType> 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;

Expand Down Expand Up @@ -714,6 +745,7 @@ macro_rules! newtype_oparg {
self.0.fmt(f)
}
}

impl OpArgType for $name {}
}
}
Expand Down
Loading