mirror of https://github.com/python/cpython
Peephole constant folding had missed UNARY_POSITIVE.
This commit is contained in:
parent
42ead48dc1
commit
af7adad51d
|
@ -150,6 +150,7 @@ class TestTranforms(unittest.TestCase):
|
||||||
for line, elem in (
|
for line, elem in (
|
||||||
('-0.5', '(-0.5)'), # unary negative
|
('-0.5', '(-0.5)'), # unary negative
|
||||||
('~-2', '(1)'), # unary invert
|
('~-2', '(1)'), # unary invert
|
||||||
|
('+1', '(1)'), # unary positive
|
||||||
):
|
):
|
||||||
asm = dis_single(line)
|
asm = dis_single(line)
|
||||||
self.assertTrue(elem in asm, asm)
|
self.assertTrue(elem in asm, asm)
|
||||||
|
|
|
@ -12,6 +12,8 @@ What's New in Python 3.2 Alpha 1?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Peephole constant folding had missed UNARY_POSITIVE.
|
||||||
|
|
||||||
- Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
|
- Issue #1722344: threading._shutdown() is now called in Py_Finalize(), which
|
||||||
fixes the problem of some exceptions being thrown at shutdown when the
|
fixes the problem of some exceptions being thrown at shutdown when the
|
||||||
interpreter is killed. Patch by Adam Olsen.
|
interpreter is killed. Patch by Adam Olsen.
|
||||||
|
|
|
@ -197,6 +197,9 @@ fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts)
|
||||||
case UNARY_INVERT:
|
case UNARY_INVERT:
|
||||||
newconst = PyNumber_Invert(v);
|
newconst = PyNumber_Invert(v);
|
||||||
break;
|
break;
|
||||||
|
case UNARY_POSITIVE:
|
||||||
|
newconst = PyNumber_Positive(v);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
/* Called with an unknown opcode */
|
/* Called with an unknown opcode */
|
||||||
PyErr_Format(PyExc_SystemError,
|
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) */
|
LOAD_CONST c1 UNARY_OP --> LOAD_CONST unary_op(c) */
|
||||||
case UNARY_NEGATIVE:
|
case UNARY_NEGATIVE:
|
||||||
case UNARY_INVERT:
|
case UNARY_INVERT:
|
||||||
|
case UNARY_POSITIVE:
|
||||||
if (lastlc >= 1 &&
|
if (lastlc >= 1 &&
|
||||||
ISBASICBLOCK(blocks, i-3, 4) &&
|
ISBASICBLOCK(blocks, i-3, 4) &&
|
||||||
fold_unaryops_on_constants(&codestr[i-3], consts)) {
|
fold_unaryops_on_constants(&codestr[i-3], consts)) {
|
||||||
|
|
Loading…
Reference in New Issue