diff --git a/codegen/src/compile.rs b/codegen/src/compile.rs index ebfd454..bdad5f7 100644 --- a/codegen/src/compile.rs +++ b/codegen/src/compile.rs @@ -342,7 +342,7 @@ impl Compiler { self.emit(Instruction::StoreGlobal(doc)) } - if self.find_ann(statements) { + if Self::find_ann(statements) { self.emit(Instruction::SetupAnnotation); } @@ -1229,22 +1229,22 @@ impl Compiler { } // Python/compile.c find_ann - fn find_ann(&self, body: &[ast::Stmt]) -> bool { + fn find_ann(body: &[ast::Stmt]) -> bool { use ast::StmtKind::*; for statement in body { let res = match &statement.node { AnnAssign { .. } => true, - For { body, orelse, .. } => self.find_ann(body) || self.find_ann(orelse), - If { body, orelse, .. } => self.find_ann(body) || self.find_ann(orelse), - While { body, orelse, .. } => self.find_ann(body) || self.find_ann(orelse), - With { body, .. } => self.find_ann(body), + For { body, orelse, .. } => Self::find_ann(body) || Self::find_ann(orelse), + If { body, orelse, .. } => Self::find_ann(body) || Self::find_ann(orelse), + While { body, orelse, .. } => Self::find_ann(body) || Self::find_ann(orelse), + With { body, .. } => Self::find_ann(body), Try { body, orelse, finalbody, .. - } => self.find_ann(body) || self.find_ann(orelse) || self.find_ann(finalbody), + } => Self::find_ann(body) || Self::find_ann(orelse) || Self::find_ann(finalbody), _ => false, }; if res { @@ -1295,7 +1295,7 @@ impl Compiler { let doc = self.name("__doc__"); self.emit(Instruction::StoreLocal(doc)); // setup annotations - if self.find_ann(body) { + if Self::find_ann(body) { self.emit(Instruction::SetupAnnotation); } self.compile_statements(body)?; diff --git a/core/src/bytecode.rs b/core/src/bytecode.rs index ae28f6e..9c3751c 100644 --- a/core/src/bytecode.rs +++ b/core/src/bytecode.rs @@ -996,20 +996,8 @@ impl Instruction { | SetupFinally { .. } | EnterFinally | EndFinally => 0, - SetupExcept { .. } => { - if jump { - 1 - } else { - 0 - } - } - SetupWith { .. } => { - if jump { - 0 - } else { - 1 - } - } + SetupExcept { .. } => jump as i32, + SetupWith { .. } => (!jump) as i32, WithCleanupStart => 0, WithCleanupFinish => -1, PopBlock => 0,