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.
This commit is contained in:
Jeremy Hylton 2001-04-12 21:54:41 +00:00
parent 13d70944cb
commit bb0bae6da2
2 changed files with 8 additions and 8 deletions

View File

@ -326,7 +326,7 @@ class CodeGenerator:
self.nextBlock(loop) self.nextBlock(loop)
self.loops.push(loop) self.loops.push(loop)
self.set_lineno(node) self.set_lineno(node, force=1)
self.visit(node.test) self.visit(node.test)
self.emit('JUMP_IF_FALSE', else_ or after) 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.startBlock(else_) # or just the POPs if not else clause
self.emit('POP_TOP') self.emit('POP_TOP')
self.emit('POP_BLOCK') self.emit('POP_BLOCK')
self.loops.pop()
if node.else_: if node.else_:
self.visit(node.else_) self.visit(node.else_)
self.loops.pop()
self.nextBlock(after) self.nextBlock(after)
def visitFor(self, node): def visitFor(self, node):
@ -354,7 +354,7 @@ class CodeGenerator:
self.visit(node.list) self.visit(node.list)
self.visit(ast.Const(0)) self.visit(ast.Const(0))
self.nextBlock(start) self.nextBlock(start)
self.set_lineno(node) self.set_lineno(node, force=1)
self.emit('FOR_LOOP', anchor) self.emit('FOR_LOOP', anchor)
self.nextBlock() self.nextBlock()
self.visit(node.assign) self.visit(node.assign)
@ -362,9 +362,9 @@ class CodeGenerator:
self.emit('JUMP_ABSOLUTE', start) self.emit('JUMP_ABSOLUTE', start)
self.startBlock(anchor) self.startBlock(anchor)
self.emit('POP_BLOCK') self.emit('POP_BLOCK')
self.loops.pop()
if node.else_: if node.else_:
self.visit(node.else_) self.visit(node.else_)
self.loops.pop()
self.nextBlock(after) self.nextBlock(after)
def visitBreak(self, node): def visitBreak(self, node):

View File

@ -326,7 +326,7 @@ class CodeGenerator:
self.nextBlock(loop) self.nextBlock(loop)
self.loops.push(loop) self.loops.push(loop)
self.set_lineno(node) self.set_lineno(node, force=1)
self.visit(node.test) self.visit(node.test)
self.emit('JUMP_IF_FALSE', else_ or after) 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.startBlock(else_) # or just the POPs if not else clause
self.emit('POP_TOP') self.emit('POP_TOP')
self.emit('POP_BLOCK') self.emit('POP_BLOCK')
self.loops.pop()
if node.else_: if node.else_:
self.visit(node.else_) self.visit(node.else_)
self.loops.pop()
self.nextBlock(after) self.nextBlock(after)
def visitFor(self, node): def visitFor(self, node):
@ -354,7 +354,7 @@ class CodeGenerator:
self.visit(node.list) self.visit(node.list)
self.visit(ast.Const(0)) self.visit(ast.Const(0))
self.nextBlock(start) self.nextBlock(start)
self.set_lineno(node) self.set_lineno(node, force=1)
self.emit('FOR_LOOP', anchor) self.emit('FOR_LOOP', anchor)
self.nextBlock() self.nextBlock()
self.visit(node.assign) self.visit(node.assign)
@ -362,9 +362,9 @@ class CodeGenerator:
self.emit('JUMP_ABSOLUTE', start) self.emit('JUMP_ABSOLUTE', start)
self.startBlock(anchor) self.startBlock(anchor)
self.emit('POP_BLOCK') self.emit('POP_BLOCK')
self.loops.pop()
if node.else_: if node.else_:
self.visit(node.else_) self.visit(node.else_)
self.loops.pop()
self.nextBlock(after) self.nextBlock(after)
def visitBreak(self, node): def visitBreak(self, node):