-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Pseudo ops #6678
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
Pseudo ops #6678
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,10 +4,6 @@ | |
|
|
||
| _specializations = {} | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| _specialized_opmap = {} | ||
|
|
||
| opmap = { | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,6 +84,20 @@ pub fn find_exception_handler(table: &[u8], offset: u32) -> Option<ExceptionTabl | |
| None | ||
| } | ||
|
|
||
| /// Encode LOAD_ATTR oparg: bit 0 = method flag, bits 1+ = name index. | ||
| #[inline] | ||
| pub const fn encode_load_attr_arg(name_idx: u32, is_method: bool) -> u32 { | ||
| (name_idx << 1) | (is_method as u32) | ||
| } | ||
|
|
||
| /// Decode LOAD_ATTR oparg: returns (name_idx, is_method). | ||
| #[inline] | ||
| pub const fn decode_load_attr_arg(oparg: u32) -> (u32, bool) { | ||
| let is_method = (oparg & 1) == 1; | ||
| let name_idx = oparg >> 1; | ||
| (name_idx, is_method) | ||
| } | ||
|
Comment on lines
+87
to
+99
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LOAD_ATTR oparg encoding needs an explicit size invariant (avoid silent truncation). Possible defensive tweak pub const fn encode_load_attr_arg(name_idx: u32, is_method: bool) -> u32 {
- (name_idx << 1) | (is_method as u32)
+ // name_idx uses bits 1..; bit0 is reserved for is_method.
+ debug_assert!(name_idx < (1 << 31));
+ (name_idx << 1) | (is_method as u32)
}🤖 Prompt for AI Agents |
||
|
|
||
| /// Oparg values for [`Instruction::ConvertValue`]. | ||
| /// | ||
| /// ## See also | ||
|
|
@@ -1740,6 +1754,9 @@ impl Instruction { | |
| pub const fn label_arg(&self) -> Option<Arg<Label>> { | ||
| match self { | ||
| Jump { target: l } | ||
| | JumpBackward { target: l } | ||
| | JumpBackwardNoInterrupt { target: l } | ||
| | JumpForward { target: l } | ||
| | JumpIfNotExcMatch(l) | ||
| | PopJumpIfTrue { target: l } | ||
| | PopJumpIfFalse { target: l } | ||
|
|
@@ -1766,6 +1783,9 @@ impl Instruction { | |
| matches!( | ||
| self, | ||
| Jump { .. } | ||
| | JumpForward { .. } | ||
| | JumpBackward { .. } | ||
| | JumpBackwardNoInterrupt { .. } | ||
| | Continue { .. } | ||
| | Break { .. } | ||
| | ReturnValue | ||
|
|
@@ -2060,11 +2080,27 @@ impl Instruction { | |
| ImportName { idx } => w!(IMPORT_NAME, name = idx), | ||
| IsOp(inv) => w!(IS_OP, ?inv), | ||
| Jump { target } => w!(JUMP, target), | ||
| JumpBackward { target } => w!(JUMP_BACKWARD, target), | ||
| JumpBackwardNoInterrupt { target } => w!(JUMP_BACKWARD_NO_INTERRUPT, target), | ||
| JumpForward { target } => w!(JUMP_FORWARD, target), | ||
| JumpIfFalseOrPop { target } => w!(JUMP_IF_FALSE_OR_POP, target), | ||
| JumpIfNotExcMatch(target) => w!(JUMP_IF_NOT_EXC_MATCH, target), | ||
| JumpIfTrueOrPop { target } => w!(JUMP_IF_TRUE_OR_POP, target), | ||
| ListAppend { i } => w!(LIST_APPEND, i), | ||
| LoadAttr { idx } => w!(LOAD_ATTR, name = idx), | ||
| LoadAttr { idx } => { | ||
| let encoded = idx.get(arg); | ||
| let (name_idx, is_method) = decode_load_attr_arg(encoded); | ||
| let attr_name = name(name_idx); | ||
| if is_method { | ||
| write!( | ||
| f, | ||
| "{:pad$}({}, {}, method=true)", | ||
| "LOAD_ATTR", encoded, attr_name | ||
| ) | ||
| } else { | ||
| write!(f, "{:pad$}({}, {})", "LOAD_ATTR", encoded, attr_name) | ||
| } | ||
| } | ||
| LoadAttrMethod { idx } => w!(LOAD_ATTR_METHOD, name = idx), | ||
| LoadBuildClass => w!(LOAD_BUILD_CLASS), | ||
| LoadClassDeref(idx) => w!(LOAD_CLASSDEREF, cell_name = idx), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.