mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-19 11:05:45 +00:00
Refactor block stack unwinding to enable finally execution.
This commit is contained in:
parent
39c095d12c
commit
e8db01a09a
1 changed files with 12 additions and 3 deletions
|
@ -708,12 +708,20 @@ impl<O: OutputStream> Compiler<O> {
|
|||
&mut self,
|
||||
body: &[ast::Statement],
|
||||
handlers: &[ast::ExceptHandler],
|
||||
orelse: &Option<Vec<ast::Statement>>,
|
||||
finalbody: &Option<Vec<ast::Statement>>,
|
||||
orelse: &Option<ast::Suite>,
|
||||
finalbody: &Option<ast::Suite>,
|
||||
) -> Result<(), CompileError> {
|
||||
let mut handler_label = self.new_label();
|
||||
let finally_label = self.new_label();
|
||||
let else_label = self.new_label();
|
||||
|
||||
// Setup a finally block if we have a finally statement.
|
||||
if finalbody.is_some() {
|
||||
self.emit(Instruction::SetupFinally {
|
||||
handler: finally_label,
|
||||
});
|
||||
}
|
||||
|
||||
// try:
|
||||
self.emit(Instruction::SetupExcept {
|
||||
handler: handler_label,
|
||||
|
@ -798,8 +806,9 @@ impl<O: OutputStream> Compiler<O> {
|
|||
self.set_label(finally_label);
|
||||
if let Some(statements) = finalbody {
|
||||
self.compile_statements(statements)?;
|
||||
self.emit(Instruction::EndFinally);
|
||||
}
|
||||
// unimplemented!();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue