mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-14 08:35:21 +00:00
Add missing codes for empty statement body
Fix #3704 Compared to previous version of `compile_program_single`, below two codes are skipped when an empty body is given. ```rust self.emit_constant(ConstantData::None); self.emit(Instruction::ReturnValue); ``` Signed-off-by: snowapril <sinjihng@gmail.com>
This commit is contained in:
parent
be43bfaa80
commit
dc1d6616ca
1 changed files with 15 additions and 17 deletions
|
@ -344,31 +344,29 @@ impl Compiler {
|
||||||
) -> CompileResult<()> {
|
) -> CompileResult<()> {
|
||||||
self.symbol_table_stack.push(symbol_table);
|
self.symbol_table_stack.push(symbol_table);
|
||||||
|
|
||||||
let (last, body) = if let Some(splited) = body.split_last() {
|
if let Some((last, body)) = body.split_last() {
|
||||||
splited
|
for statement in body {
|
||||||
} else {
|
if let ast::StmtKind::Expr { value } = &statement.node {
|
||||||
return Ok(());
|
self.compile_expression(value)?;
|
||||||
};
|
self.emit(Instruction::PrintExpr);
|
||||||
|
} else {
|
||||||
|
self.compile_statement(statement)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for statement in body {
|
if let ast::StmtKind::Expr { value } = &last.node {
|
||||||
if let ast::StmtKind::Expr { value } = &statement.node {
|
|
||||||
self.compile_expression(value)?;
|
self.compile_expression(value)?;
|
||||||
|
self.emit(Instruction::Duplicate);
|
||||||
self.emit(Instruction::PrintExpr);
|
self.emit(Instruction::PrintExpr);
|
||||||
} else {
|
} else {
|
||||||
self.compile_statement(statement)?;
|
self.compile_statement(last)?;
|
||||||
|
self.emit_constant(ConstantData::None);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if let ast::StmtKind::Expr { value } = &last.node {
|
|
||||||
self.compile_expression(value)?;
|
|
||||||
self.emit(Instruction::Duplicate);
|
|
||||||
self.emit(Instruction::PrintExpr);
|
|
||||||
} else {
|
} else {
|
||||||
self.compile_statement(last)?;
|
|
||||||
self.emit_constant(ConstantData::None);
|
self.emit_constant(ConstantData::None);
|
||||||
}
|
};
|
||||||
self.emit(Instruction::ReturnValue);
|
|
||||||
|
|
||||||
|
self.emit(Instruction::ReturnValue);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue