]> granicus.if.org Git - python/commitdiff
Peephole constant folding had missed UNARY_POSITIVE.
authorRaymond Hettinger <python@rcn.com>
Thu, 22 Oct 2009 11:22:50 +0000 (11:22 +0000)
committerRaymond Hettinger <python@rcn.com>
Thu, 22 Oct 2009 11:22:50 +0000 (11:22 +0000)
Lib/test/test_peepholer.py
Misc/NEWS
Python/peephole.c

index 569650035c64dd5cd2ec7a029c17fd951cf1c85d..9e8bb69f67a6f14c52085230028e9dcd170e7cb8 100644 (file)
@@ -150,6 +150,7 @@ class TestTranforms(unittest.TestCase):
         for line, elem in (
             ('-0.5', '(-0.5)'),                     # unary negative
             ('~-2', '(1)'),                         # unary invert
+            ('+1', '(1)'),                          # unary positive
         ):
             asm = dis_single(line)
             self.assertTrue(elem in asm, asm)
index 96ee2ac611c574dd53303a3b5455e3bdf87c8bc8..8830b7d9b6e589df556507f85f1417723ee88bf3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 3.2 Alpha 1?
 Core and Builtins
 -----------------
 
+- Peephole constant folding had missed UNARY_POSITIVE.
+
 - Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
   fixes the problem of some exceptions being thrown at shutdown when the
   interpreter is killed. Patch by Adam Olsen.
index 916309127257e152d97502a69f7cd15ec6eb46bf..104db8cb978cbe4aa67f301e3f151bd2c828a7c2 100644 (file)
@@ -197,6 +197,9 @@ fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts)
                case UNARY_INVERT:
                        newconst = PyNumber_Invert(v);
                        break;
+               case UNARY_POSITIVE:
+                       newconst = PyNumber_Positive(v);
+                       break;
                default:
                        /* Called with an unknown opcode */
                        PyErr_Format(PyExc_SystemError,
@@ -500,6 +503,7 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
                                   LOAD_CONST c1  UNARY_OP -->  LOAD_CONST unary_op(c) */
                        case UNARY_NEGATIVE:
                        case UNARY_INVERT:
+                       case UNARY_POSITIVE:
                                if (lastlc >= 1  &&
                                    ISBASICBLOCK(blocks, i-3, 4)  &&
                                    fold_unaryops_on_constants(&codestr[i-3], consts))  {