Skip to content
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'upstream/main' into bytecode-oparg-num-…
…enum
  • Loading branch information
ShaharNaveh committed Feb 5, 2026
commit b0e9e5ecccb8352c8e0b49dc7a9c06757ad405d2
84 changes: 84 additions & 0 deletions crates/compiler-core/src/bytecode/oparg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,90 @@ impl fmt::Display for UnpackExArgs {
}
}

#[derive(Clone, Copy)]
pub struct LoadSuperAttr(u32);

impl LoadSuperAttr {
#[must_use]
pub const fn new(value: u32) -> Self {
Self(value)
}

#[must_use]
pub fn builder() -> LoadSuperAttrBuilder {
LoadSuperAttrBuilder::default()
}

#[must_use]
pub const fn name_idx(self) -> u32 {
self.0 >> 2
}

#[must_use]
pub const fn is_load_method(self) -> bool {
(self.0 & 1) == 1
}

#[must_use]
pub const fn has_class(self) -> bool {
(self.0 & 2) == 2
}
}

impl OpArgType for LoadSuperAttr {}

impl From<u32> for LoadSuperAttr {
fn from(value: u32) -> Self {
Self::new(value)
}
}

impl From<LoadSuperAttr> for u32 {
fn from(value: LoadSuperAttr) -> Self {
value.0
}
}

#[derive(Clone, Copy, Default)]
pub struct LoadSuperAttrBuilder {
name_idx: u32,
is_load_method: bool,
has_class: bool,
}

impl LoadSuperAttrBuilder {
#[must_use]
pub const fn build(self) -> LoadSuperAttr {
let value =
(self.name_idx << 2) | ((self.has_class as u32) << 1) | (self.is_load_method as u32);
LoadSuperAttr::new(value)
}

#[must_use]
pub const fn name_idx(mut self, value: u32) -> Self {
self.name_idx = value;
self
}

#[must_use]
pub const fn is_load_method(mut self, value: bool) -> Self {
self.is_load_method = value;
self
}

#[must_use]
pub const fn has_class(mut self, value: bool) -> Self {
self.has_class = value;
self
}
}

impl From<LoadSuperAttrBuilder> for LoadSuperAttr {
fn from(builder: LoadSuperAttrBuilder) -> Self {
builder.build()
}
}

/// Helper function for `num_enum` derive macro.
///
/// # Examples
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.