mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Resume opcode to hold ResumeType (#7465)
This commit is contained in:
1 parent
25b55d01e3
commit
33b024b70e
3 files changed
+46
-14
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -714,6 +745,7 @@ macro_rules! newtype_oparg {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl OpArgType for $name {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user