summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2001-04-12 21:54:41 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2001-04-12 21:54:41 (GMT)
commitbb0bae6da2c322971041d7943d1096d0590a9d3f (patch)
tree7044acf8685c10b07560abbc6c3c475928ff9bac
parent13d70944cba10f6f9b39aa94cb9c5df442523dda (diff)
downloadcpython-bb0bae6da2c322971041d7943d1096d0590a9d3f.zip
cpython-bb0bae6da2c322971041d7943d1096d0590a9d3f.tar.gz
cpython-bb0bae6da2c322971041d7943d1096d0590a9d3f.tar.bz2
Pop loop off the loop stack before handling the loop's else clause.
Otherwise, continue/break will attempt to affect the wrong loop. A few more fiddles to get the SET_LINENOs consistent across compilers.
-rw-r--r--Lib/compiler/pycodegen.py8
-rw-r--r--Tools/compiler/compiler/pycodegen.py8
2 files changed, 8 insertions, 8 deletions
diff --git a/Lib/compiler/pycodegen.py b/Lib/compiler/pycodegen.py
index dc2be32..9f58067 100644
--- a/Lib/compiler/pycodegen.py
+++ b/Lib/compiler/pycodegen.py
@@ -326,7 +326,7 @@ class CodeGenerator:
self.nextBlock(loop)
self.loops.push(loop)
- self.set_lineno(node)
+ self.set_lineno(node, force=1)
self.visit(node.test)
self.emit('JUMP_IF_FALSE', else_ or after)
@@ -338,9 +338,9 @@ class CodeGenerator:
self.startBlock(else_) # or just the POPs if not else clause
self.emit('POP_TOP')
self.emit('POP_BLOCK')
+ self.loops.pop()
if node.else_:
self.visit(node.else_)
- self.loops.pop()
self.nextBlock(after)
def visitFor(self, node):
@@ -354,7 +354,7 @@ class CodeGenerator:
self.visit(node.list)
self.visit(ast.Const(0))
self.nextBlock(start)
- self.set_lineno(node)
+ self.set_lineno(node, force=1)
self.emit('FOR_LOOP', anchor)
self.nextBlock()
self.visit(node.assign)
@@ -362,9 +362,9 @@ class CodeGenerator:
self.emit('JUMP_ABSOLUTE', start)
self.startBlock(anchor)
self.emit('POP_BLOCK')
+ self.loops.pop()
if node.else_:
self.visit(node.else_)
- self.loops.pop()
self.nextBlock(after)
def visitBreak(self, node):
diff --git a/Tools/compiler/compiler/pycodegen.py b/Tools/compiler/compiler/pycodegen.py
index dc2be32..9f58067 100644
--- a/Tools/compiler/compiler/pycodegen.py
+++ b/Tools/compiler/compiler/pycodegen.py
@@ -326,7 +326,7 @@ class CodeGenerator:
self.nextBlock(loop)
self.loops.push(loop)
- self.set_lineno(node)
+ self.set_lineno(node, force=1)
self.visit(node.test)
self.emit('JUMP_IF_FALSE', else_ or after)
@@ -338,9 +338,9 @@ class CodeGenerator:
self.startBlock(else_) # or just the POPs if not else clause
self.emit('POP_TOP')
self.emit('POP_BLOCK')
+ self.loops.pop()
if node.else_:
self.visit(node.else_)
- self.loops.pop()
self.nextBlock(after)
def visitFor(self, node):
@@ -354,7 +354,7 @@ class CodeGenerator:
self.visit(node.list)
self.visit(ast.Const(0))
self.nextBlock(start)
- self.set_lineno(node)
+ self.set_lineno(node, force=1)
self.emit('FOR_LOOP', anchor)
self.nextBlock()
self.visit(node.assign)
@@ -362,9 +362,9 @@ class CodeGenerator:
self.emit('JUMP_ABSOLUTE', start)
self.startBlock(anchor)
self.emit('POP_BLOCK')
+ self.loops.pop()
if node.else_:
self.visit(node.else_)
- self.loops.pop()
self.nextBlock(after)
def visitBreak(self, node):