[Python-checkins] python/dist/src/Lib/test test_peepholer.py, 1.11, 1.12

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Sun Feb 20 13:46:56 CET 2005


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3491
Modified Files:
	test_peepholer.py 
Log Message:
Teach the peepholer to fold unary operations on constants.
Afterwards, -0.5 loads in a single step and no longer requires a runtime 
UNARY_NEGATIVE operation.
Index: test_peepholer.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_peepholer.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- test_peepholer.py	10 Feb 2005 20:40:29 -0000	1.11
+++ test_peepholer.py	20 Feb 2005 12:46:54 -0000	1.12
@@ -133,6 +133,25 @@
 asm = dis_single('a="x"*1000')
 self.assert_('(1000)' in asm)
 
+ def test_folding_of_unaryops_on_constants(self):
+ for line, elem in (
+ ('`1`', "('1')"), # unary convert
+ ('-0.5', '(-0.5)'), # unary negative
+ ('~-2', '(1)'), # unary invert
+ ):
+ asm = dis_single(line)
+ self.assert_(elem in asm, asm)
+ self.assert_('UNARY_' not in asm)
+
+ # Verify that unfoldables are skipped
+ for line, elem in (
+ ('-"abc"', "('abc')"), # unary negative
+ ('~"abc"', "('abc')"), # unary invert
+ ):
+ asm = dis_single(line)
+ self.assert_(elem in asm, asm)
+ self.assert_('UNARY_' in asm)
+
 def test_elim_extra_return(self):
 # RETURN LOAD_CONST None RETURN --> RETURN
 def f(x):


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /