8000 Add 3.12 typing features to the compiler by dchiquito · Pull Request #5302 · RustPython/RustPython · GitHub
[go: up one dir, main page]

Skip to content

Add 3.12 typing features to the compiler #5302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 10, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add TypeVar bytecodes
  • Loading branch information
8000
dchiquito committed May 7, 2024
commit bfa18d25779bea858a8f40554085a2e1c28dee81
17 changes: 16 additions & 1 deletion compiler/core/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,13 @@ pub enum Instruction {
GetANext,
EndAsyncFor,
ExtendedArg,
TypeVar,
TypeVarWithBound,
TypeVarWithConstraint,
TypeAlias,
}
// This must be kept up to date to avoid marshaling errors
const LAST_INSTRUCTION: Instruction = Instruction::TypeAlias;
const _: () = assert!(mem::size_of::<Instruction>() == 1);

impl From<Instruction> for u8 {
Expand All @@ -604,7 +610,7 @@ impl TryFrom<u8> for Instruction {

#[inline]
fn try_from(value: u8) -> Result<Self, crate::marshal::MarshalError> {
if value <= u8::from(Instruction::ExtendedArg) {
if value <= u8::from(LAST_INSTRUCTION) {
Ok(unsafe { std::mem::transmute::<u8, Instruction>(value) })
} else {
Err(crate::marshal::MarshalError::InvalidBytecode)
Expand Down Expand Up @@ -636,6 +642,7 @@ bitflags! {
const ANNOTATIONS = 0x02;
const KW_ONLY_DEFAULTS = 0x04;
const DEFAULTS = 0x08;
const TYPE_PARAMS = 0x10;
}
}
impl OpArgType for MakeFunctionFlags {
Expand Down Expand Up @@ -1270,6 +1277,10 @@ impl Instruction {
GetANext => 1,
EndAsyncFor => -2,
ExtendedArg => 0,
TypeVar => 0,
TypeVarWithBound => -1,
TypeVarWithConstraint => -1,
TypeAlias => -2,
}
}

Expand Down Expand Up @@ -1431,6 +1442,10 @@ impl Instruction {
GetANext => w!(GetANext),
EndAsyncFor => w!(EndAsyncFor),
ExtendedArg => w!(ExtendedArg, Arg::<u32>::marker()),
TypeVar => w!(TypeVar),
TypeVarWithBound => w!(TypeVarWithBound),
TypeVarWithConstraint => w!(TypeVarWithConstraint),
TypeAlias => w!(TypeAlias),
}
}
}
Expand Down
0