summaryrefslogtreecommitdiffstats
path: root/Lib/compiler
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2004-08-07 19:21:56 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2004-08-07 19:21:56 (GMT)
commit2876f5ad212d56819cb2d87c73bd6f4dfaa985bc (patch)
tree7888098d78bb3fb51c5ff3636d6f88305c57eef2 /Lib/compiler
parent4c989ddc9c8bd38ab14c9f42511eb567ed219604 (diff)
downloadcpython-2876f5ad212d56819cb2d87c73bd6f4dfaa985bc.zip
cpython-2876f5ad212d56819cb2d87c73bd6f4dfaa985bc.tar.gz
cpython-2876f5ad212d56819cb2d87c73bd6f4dfaa985bc.tar.bz2
SF patch 836879.
Don't generate code for asserts in -O mode.
Diffstat (limited to 'Lib/compiler')
-rw-r--r--Lib/compiler/pycodegen.py40
1 files changed, 19 insertions, 21 deletions
diff --git a/Lib/compiler/pycodegen.py b/Lib/compiler/pycodegen.py
index e33551a..e5d1ff1 100644
--- a/Lib/compiler/pycodegen.py
+++ b/Lib/compiler/pycodegen.py
@@ -707,27 +707,25 @@ class CodeGenerator:
def visitAssert(self, node):
# XXX would be interesting to implement this via a
# transformation of the AST before this stage
- end = self.newBlock()
- self.set_lineno(node)
- # XXX __debug__ and AssertionError appear to be special cases
- # -- they are always loaded as globals even if there are local
- # names. I guess this is a sort of renaming op.
- self.emit('LOAD_GLOBAL', '__debug__')
- self.emit('JUMP_IF_FALSE', end)
- self.nextBlock()
- self.emit('POP_TOP')
- self.visit(node.test)
- self.emit('JUMP_IF_TRUE', end)
- self.nextBlock()
- self.emit('POP_TOP')
- self.emit('LOAD_GLOBAL', 'AssertionError')
- if node.fail:
- self.visit(node.fail)
- self.emit('RAISE_VARARGS', 2)
- else:
- self.emit('RAISE_VARARGS', 1)
- self.nextBlock(end)
- self.emit('POP_TOP')
+ if __debug__:
+ end = self.newBlock()
+ self.set_lineno(node)
+ # XXX AssertionError appears to be special case -- it is always
+ # loaded as a global even if there is a local name. I guess this
+ # is a sort of renaming op.
+ self.nextBlock()
+ self.visit(node.test)
+ self.emit('JUMP_IF_TRUE', end)
+ self.nextBlock()
+ self.emit('POP_TOP')
+ self.emit('LOAD_GLOBAL', 'AssertionError')
+ if node.fail:
+ self.visit(node.fail)
+ self.emit('RAISE_VARARGS', 2)
+ else:
+ self.emit('RAISE_VARARGS', 1)
+ self.nextBlock(end)
+ self.emit('POP_TOP')
def visitRaise(self, node):
self.set_lineno(node)