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

Move `PrintExpr` to `IntristicFunction1` by ShaharNaveh · Pull Request #6324 · RustPython/RustPython · GitHub

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

Filter by extension

Filter by extension .rs  (3) All 1 file type selected
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
18 changes: 16 additions & 2 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 @@ -1057,7 +1057,14 @@ impl Compiler {
for statement in body {
if let Stmt::Expr(StmtExpr { value, .. }) = &statement {
self.compile_expression(value)?;
emit!(self, Instruction::PrintExpr);
emit!(
self,
Instruction::CallIntrinsic1 {
func: bytecode::IntrinsicFunction1::Print
}
);

emit!(self, Instruction::Pop);
} else {
self.compile_statement(statement)?;
}
Expand All @@ -1066,7 +1073,14 @@ impl Compiler {
if let Stmt::Expr(StmtExpr { value, .. }) = &last {
self.compile_expression(value)?;
emit!(self, Instruction::CopyItem { index: 1_u32 });
emit!(self, Instruction::PrintExpr);
emit!(
self,
Instruction::CallIntrinsic1 {
func: bytecode::IntrinsicFunction1::Print
}
);

emit!(self, Instruction::Pop);
} else {
self.compile_statement(last)?;
self.emit_load_const(ConstantData::None);
Expand Down
5 changes: 1 addition & 4 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 @@ -551,7 +551,7 @@ op_arg_enum!(
#[repr(u8)]
pub enum IntrinsicFunction1 {
// Invalid = 0,
// Print = 1,
Print = 1,
/// Import * operation
ImportStar = 2,
// StopIterationError = 3,
Expand Down Expand Up @@ -793,7 +793,6 @@ pub enum Instruction {
PopJumpIfTrue {
target: Arg<Label>,
},
PrintExpr,
Raise {
kind: Arg<RaiseKind>,
},
Expand Down Expand Up @@ -1767,7 +1766,6 @@ impl Instruction {
}
ListAppend { .. } | SetAdd { .. } => -1,
MapAdd { .. } => -2,
PrintExpr => -1,
LoadBuildClass => 1,
UnpackSequence { size } => -1 + size.get(arg) as i32,
UnpackEx { args } => {
Expand Down Expand Up @@ -1939,7 +1937,6 @@ impl Instruction {
PopException => w!(PopException),
PopJumpIfFalse { target } => w!(PopJumpIfFalse, target),
PopJumpIfTrue { target } => w!(PopJumpIfTrue, target),
PrintExpr => w!(PrintExpr),
Raise { kind } => w!(Raise, ?kind),
Resume { arg } => w!(Resume, arg),
ReturnConst { idx } => fmt_const("ReturnConst", arg, f, idx),
Expand Down
21 changes: 7 additions & 14 deletions crates/vm/src/frame.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 @@ -1351,8 +1351,6 @@ impl ExecutingFrame<'_> {
bytecode::Instruction::PopJumpIfTrue { target } => {
self.pop_jump_if(vm, target.get(arg), true)
}
bytecode::Instruction::PrintExpr => self.print_expr(vm),

bytecode::Instruction::Raise { kind } => self.execute_raise(vm, kind.get(arg)),
bytecode::Instruction::Resume { arg: resume_arg } => {
// Resume execution after yield, await, or at function start
Expand Down Expand Up @@ -2208,18 +2206,6 @@ impl ExecutingFrame<'_> {
Ok(None)
}

fn print_expr(&mut self, vm: &VirtualMachine) -> FrameResult {
let expr = self.pop_value();

let displayhook = vm
.sys_module
.get_attr("displayhook", vm)
.map_err(|_| vm.new_runtime_error("lost sys.displayhook"))?;
displayhook.call((expr,), vm)?;

Ok(None)
}

fn unpack_sequence(&mut self, size: u32, vm: &VirtualMachine) -> FrameResult {
let value = self.pop_value();
let elements: Vec<_> = value.try_to_value(vm).map_err(|e| {
Expand Down Expand Up @@ -2390,6 +2376,13 @@ impl ExecutingFrame<'_> {
vm: &VirtualMachine,
) -> PyResult {
match func {
bytecode::IntrinsicFunction1::Print => {
let displayhook = vm
.sys_module
.get_attr("displayhook", vm)
.map_err(|_| vm.new_runtime_error("lost sys.displayhook"))?;
displayhook.call((arg,), vm)
}
bytecode::IntrinsicFunction1::ImportStar => {
// arg is the module object
self.push_value(arg); // Push module back on stack for import_star
Expand Down
Loading

Back | FazBrowse Home | New Git URL