summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-01-10 18:51:35 (GMT)
committerGuido van Rossum <guido@python.org>2007-01-10 18:51:35 (GMT)
commit16be03e4a206c24b00dc1d2d3c740dffbbfc4ac9 (patch)
tree459a125a265abb16399baeea398ab116b7bf4f9b /Lib
parentb940e113bf90ff71b0ef57414ea2beea9d2a4bc0 (diff)
downloadcpython-16be03e4a206c24b00dc1d2d3c740dffbbfc4ac9.zip
cpython-16be03e4a206c24b00dc1d2d3c740dffbbfc4ac9.tar.gz
cpython-16be03e4a206c24b00dc1d2d3c740dffbbfc4ac9.tar.bz2
Some more changes related to the new except syntax and semantics,
by Collin Winter.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/compiler/pycodegen.py28
-rw-r--r--Lib/compiler/transformer.py12
2 files changed, 31 insertions, 9 deletions
diff --git a/Lib/compiler/pycodegen.py b/Lib/compiler/pycodegen.py
index 55d2617..92eff6c 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)
diff --git a/Lib/compiler/transformer.py b/Lib/compiler/transformer.py
index 4a8e623..e111b61 100644
--- a/Lib/compiler/transformer.py
+++ b/Lib/compiler/transformer.py
@@ -988,16 +988,16 @@ class Transformer:
for i in range(3, len(nodelist), 3):
node = nodelist[i]
if node[0] == symbol.except_clause:
- # except_clause: 'except' [expr [',' expr]] */
+ # except_clause: 'except' [expr ['as' NAME]] */
if len(node) > 2:
- expr1 = self.com_node(node[2])
+ expr = self.com_node(node[2])
if len(node) > 4:
- expr2 = self.com_assign(node[4], OP_ASSIGN)
+ expr_name = node[4]
else:
- expr2 = None
+ expr_name = None
else:
- expr1 = expr2 = None
- clauses.append((expr1, expr2, self.com_node(nodelist[i+2])))
+ expr = expr_name = None
+ clauses.append((expr, expr_name, self.com_node(nodelist[i+2])))
if node[0] == token.NAME:
if node[1] == 'else':