mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Move PrintExpr to IntristicFunction1 (#6324)
This commit is contained in:
1 parent
59f422de66
commit
f49c18578a
3 files changed
+24
-20
No files matched your search
@@ -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)?;
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -551,7 +551,7 @@ op_arg_enum!(
|
||||
#[repr(u8)]
|
||||
pub enum IntrinsicFunction1 {
|
||||
// Invalid = 0,
|
||||
// Print = 1,
|
||||
Print = 1,
|
||||
/// Import * operation
|
||||
ImportStar = 2,
|
||||
// StopIterationError = 3,
|
||||
@@ -793,7 +793,6 @@ pub enum Instruction {
|
||||
PopJumpIfTrue {
|
||||
target: Arg<Label>,
|
||||
},
|
||||
PrintExpr,
|
||||
Raise {
|
||||
kind: Arg<RaiseKind>,
|
||||
},
|
||||
@@ -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 } => {
|
||||
@@ -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),
|
||||
|
||||
+7
-14
@@ -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
|
||||
@@ -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| {
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user