[Patches] [ python-Patches-431422 ] "print" not emitting POP_TOP
noreply@sourceforge.net
noreply@sourceforge.net
Mon, 27 Aug 2001 14:58:37 -0700
Patches item #431422, was opened at 2001-06-08 08:54
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=431422&group_id=5470
Category: Parser/Compiler
Group: None
>Status: Closed
Resolution: Accepted
Priority: 5
Submitted By: Shane Hathaway (hathawsh)
Assigned to: Jeremy Hylton (jhylton)
>Summary: "print" not emitting POP_TOP
Initial Comment:
The Python-based compiler module (in Tools) has a bug
in the visitPrint() method of
pycodegen.CodeGenerator. It does not emit a trailing
POP_TOP instruction, which AFAICT it should emit only
when outputting to a stream and there is a trailing
comma (indicating no newline). I've attached the
patch applied to Zope's RestrictedPython module; if
there is anything incorrect about it please tell me
right away. Otherwise please apply the patch to
Tools/compiler/pycodgen.py.
----------------------------------------------------------------------
Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2001-07-03 22:41
Message:
Logged In: YES
user_id=3066
Assigned to Jeremy since the compiler package is his.
----------------------------------------------------------------------
Comment By: Shane Hathaway (hathawsh)
Date: 2001-06-22 11:41
Message:
Logged In: YES
user_id=16701
Oops, it turns out the patch is incorrect! POP_TOP should
only be added to the *last* print node. Here are the
revised visitPrint() and visitPrintnl() methods. This is
what is being used in Zope now.
def visitPrint(self, node, newline=0):
self.set_lineno(node)
if node.dest:
self.visit(node.dest)
for child in node.nodes:
if node.dest:
self.emit('DUP_TOP')
self.visit(child)
if node.dest:
self.emit('ROT_TWO')
self.emit('PRINT_ITEM_TO')
else:
self.emit('PRINT_ITEM')
if node.dest and not newline:
self.emit('POP_TOP')
def visitPrintnl(self, node):
self.visitPrint(node, 1)
if node.dest:
self.emit('PRINT_NEWLINE_TO')
else:
self.emit('PRINT_NEWLINE')
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=431422&group_id=5470