X Tutup
Skip to content

Commit cfbf6d6

Browse files
ShaharNavehCopilot
authored andcommitted
Resume opcode to hold ResumeType (#7465)
1 parent 60edcd9 commit cfbf6d6

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

crates/codegen/src/compile.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6881,9 +6881,9 @@ impl Compiler {
68816881
self,
68826882
Instruction::Resume {
68836883
context: if is_await {
6884-
u32::from(bytecode::ResumeType::AfterAwait)
6884+
bytecode::ResumeType::AfterAwait
68856885
} else {
6886-
u32::from(bytecode::ResumeType::AfterYieldFrom)
6886+
bytecode::ResumeType::AfterYieldFrom
68876887
}
68886888
}
68896889
);
@@ -7055,7 +7055,7 @@ impl Compiler {
70557055
emit!(
70567056
self,
70577057
Instruction::Resume {
7058-
context: u32::from(bytecode::ResumeType::AfterYield)
7058+
context: bytecode::ResumeType::AfterYield
70597059
}
70607060
);
70617061
}
@@ -7277,7 +7277,7 @@ impl Compiler {
72777277
emit!(
72787278
compiler,
72797279
Instruction::Resume {
7280-
context: u32::from(bytecode::ResumeType::AfterYield)
7280+
context: bytecode::ResumeType::AfterYield
72817281
}
72827282
);
72837283
emit!(compiler, Instruction::PopTop);

crates/compiler-core/src/bytecode/instruction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ pub enum Instruction {
304304
} = 120,
305305
// CPython 3.14 RESUME (128)
306306
Resume {
307-
context: Arg<u32>,
307+
context: Arg<oparg::ResumeType>,
308308
} = 128,
309309
// CPython 3.14 specialized opcodes (129-211)
310310
BinaryOpAddFloat = 129, // Placeholder

crates/compiler-core/src/bytecode/oparg.rs

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,47 @@ impl fmt::Display for ConvertValueOparg {
276276
}
277277
}
278278

279-
oparg_enum!(
280-
/// Resume type for the RESUME instruction
281-
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
282-
pub enum ResumeType {
283-
AtFuncStart = 0,
284-
AfterYield = 1,
285-
AfterYieldFrom = 2,
286-
AfterAwait = 3,
279+
/// Resume type for the RESUME instruction
280+
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
281+
pub enum ResumeType {
282+
AtFuncStart,
283+
AfterYield,
284+
AfterYieldFrom,
285+
AfterAwait,
286+
Other(u32),
287+
}
288+
289+
impl From<u32> for ResumeType {
290+
fn from(value: u32) -> Self {
291+
match value {
292+
0 => Self::AtFuncStart,
293+
1 => Self::AfterYield,
294+
2 => Self::AfterYieldFrom,
295+
3 => Self::AfterAwait,
296+
_ => Self::Other(value),
297+
}
287298
}
288-
);
299+
}
300+
301+
impl From<ResumeType> for u32 {
302+
fn from(typ: ResumeType) -> Self {
303+
match typ {
304+
ResumeType::AtFuncStart => 0,
305+
ResumeType::AfterYield => 1,
306+
ResumeType::AfterYieldFrom => 2,
307+
ResumeType::AfterAwait => 3,
308+
ResumeType::Other(v) => v,
309+
}
310+
}
311+
}
312+
313+
impl core::fmt::Display for ResumeType {
314+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
315+
u32::from(*self).fmt(f)
316+
}
317+
}
318+
319+
impl OpArgType for ResumeType {}
289320

290321
pub type NameIdx = u32;
291322

@@ -714,6 +745,7 @@ macro_rules! newtype_oparg {
714745
self.0.fmt(f)
715746
}
716747
}
748+
717749
impl OpArgType for $name {}
718750
}
719751
}

0 commit comments

Comments
 (0)
X Tutup