FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Bytecode oparg optimization by ShaharNaveh · Pull Request #7032 · RustPython/RustPython · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .lock  (1) .rs  (4) .toml  (1) All 3 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions crates/codegen/src/compile.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,7 @@ impl Compiler {
arg: OpArgMarker::marker(),
}
.into(),
arg: OpArg(bytecode::ResumeType::AtFuncStart as u32),
arg: OpArg(u32::from(bytecode::ResumeType::AtFuncStart)),
target: BlockIdx::NULL,
location,
end_location,
Expand Down Expand Up @@ -1267,16 +1267,19 @@ impl Compiler {
/// Emit format parameter validation for annotation scope
/// if format > VALUE_WITH_FAKE_GLOBALS (2): raise NotImplementedError
fn emit_format_validation(&mut self) -> CompileResult<()> {
use bytecode::ComparisonOperator::Greater;

// Load format parameter (first local variable, index 0)
emit!(self, Instruction::LoadFast(0));

// Load VALUE_WITH_FAKE_GLOBALS constant (2)
self.emit_load_const(ConstantData::Integer { value: 2.into() });

// Compare: format > 2
emit!(self, Instruction::CompareOp { op: Greater });
emit!(
self,
Instruction::CompareOp {
op: ComparisonOperator::Greater
}
);

// Jump to body if format <= 2 (comparison is false)
let body_block = self.new_block();
Expand Down Expand Up @@ -6545,9 +6548,9 @@ impl Compiler {
self,
Instruction::Resume {
arg: if is_await {
bytecode::ResumeType::AfterAwait as u32
u32::from(bytecode::ResumeType::AfterAwait)
} else {
bytecode::ResumeType::AfterYieldFrom as u32
u32::from(bytecode::ResumeType::AfterYieldFrom)
}
}
);
Expand Down Expand Up @@ -6702,7 +6705,7 @@ impl Compiler {
emit!(
self,
Instruction::Resume {
arg: bytecode::ResumeType::AfterYield as u32
arg: u32::from(bytecode::ResumeType::AfterYield)
}
);
}
Expand Down Expand Up @@ -6924,7 +6927,7 @@ impl Compiler {
emit!(
compiler,
Instruction::Resume {
arg: bytecode::ResumeType::AfterYield as u32
arg: u32::from(bytecode::ResumeType::AfterYield)
}
);
emit!(compiler, Instruction::PopTop);
Expand Down Expand Up @@ -8412,7 +8415,7 @@ impl Compiler {

// Emit BUILD_INTERPOLATION
// oparg encoding: (conversion << 2) | has_format_spec
let oparg = (conversion << 2) | (has_format_spec as u32);
let oparg = (conversion << 2) | u32::from(has_format_spec);
emit!(self, Instruction::BuildInterpolation { oparg });

*interp_count += 1;
Expand Down
1 change: 0 additions & 1 deletion crates/compiler-core/Cargo.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ bitflags = { workspace = true }
itertools = { workspace = true }
malachite-bigint = { workspace = true }
num-complex = { workspace = true }
num_enum = { workspace = true }

lz4_flex = "0.12"

Expand Down
4 changes: 2 additions & 2 deletions crates/compiler-core/src/bytecode.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ bitflags! {
}
}

#[derive(Copy, Clone)]
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct CodeUnit {
pub op: Instruction,
pub arg: OpArgByte,
Expand All @@ -330,7 +330,7 @@ impl TryFrom<&[u8]> for CodeUnit {
}
}

#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct CodeUnits(Box<[CodeUnit]>);

impl TryFrom<&[u8]> for CodeUnits {
Expand Down
Loading
Loading

Back | FazBrowse Home | New Git URL