From 16be03e4a206c24b00dc1d2d3c740dffbbfc4ac9 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 10 Jan 2007 18:51:35 +0000 Subject: Some more changes related to the new except syntax and semantics, by Collin Winter. --- Lib/compiler/pycodegen.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'Lib/compiler/pycodegen.py') diff --git a/Lib/compiler/pycodegen.py b/Lib/compiler/pycodegen.py index 55d2617923..92eff6cc68 100644 --- a/Lib/compiler/pycodegen.py +++ b/Lib/compiler/pycodegen.py @@ -825,11 +825,33 @@ class CodeGenerator: self.emit('POP_TOP') self.emit('POP_TOP') if target: - self.visit(target) + cleanup_body = self.newBlock() + cleanup_final = self.newBlock() + target_name = target[1] + + self.storeName(target_name) + self.emit('POP_TOP') + self.emit('SETUP_FINALLY', cleanup_final) + self.nextBlock(cleanup_body) + self.setups.push((TRY_FINALLY, cleanup_body)) + self.visit(body) + self.emit('POP_BLOCK') + self.setups.pop() + self.emit('LOAD_CONST', None) + self.nextBlock(cleanup_final) + self.setups.push((END_FINALLY, cleanup_final)) + + + self.emit('LOAD_CONST', None) + self.storeName(target_name) + self._implicitNameOp('DELETE', target_name) + + self.emit('END_FINALLY') + self.setups.pop() else: self.emit('POP_TOP') - self.emit('POP_TOP') - self.visit(body) + self.emit('POP_TOP') + self.visit(body) self.emit('JUMP_FORWARD', end) if expr: self.nextBlock(next) -- cgit v1.2.1