summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-11-02 04:20:10 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-11-02 04:20:10 (GMT)
commit5dec096e6a62be5769904111a16d32ee86a9ef46 (patch)
treef697e85ad339cd1c2ff4ced57ad0cbbe6edc3912
parent7d112df94f97cec372bdb7f15eb265ded908da50 (diff)
downloadcpython-5dec096e6a62be5769904111a16d32ee86a9ef46.zip
cpython-5dec096e6a62be5769904111a16d32ee86a9ef46.tar.gz
cpython-5dec096e6a62be5769904111a16d32ee86a9ef46.tar.bz2
Maintain peepholer's cumlc invariant by updating the running total
everytime a LOAD_CONSTANT is encountered, created, or overwritten. Added two tests to cover cases affected by the patch.
-rw-r--r--Lib/test/test_peepholer.py8
-rw-r--r--Python/compile.c4
2 files changed, 9 insertions, 3 deletions
diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py
index 934b57c..f58fe03 100644
--- a/Lib/test/test_peepholer.py
+++ b/Lib/test/test_peepholer.py
@@ -75,9 +75,11 @@ class TestTranforms(unittest.TestCase):
def test_folding_of_tuples_of_constants(self):
for line, elem in (
- ('a = 1,2,3', '((1, 2, 3))',),
- ('("a","b","c")', "(('a', 'b', 'c'))",),
- ('a,b,c = 1,2,3', '((1, 2, 3))',),
+ ('a = 1,2,3', '((1, 2, 3))'),
+ ('("a","b","c")', "(('a', 'b', 'c'))"),
+ ('a,b,c = 1,2,3', '((1, 2, 3))'),
+ ('(None, 1, None)', '((None, 1, None))'),
+ ('((1, 2), 3, 4)', '(((1, 2), 3, 4))'),
):
asm = dis_single(line)
self.assert_(elem in asm)
diff --git a/Python/compile.c b/Python/compile.c
index d47f8d5..be81ba0 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -586,6 +586,7 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen
if (PyList_GET_ITEM(consts, j) == Py_None) {
codestr[i] = LOAD_CONST;
SETARG(codestr, i, j);
+ cumlc = lastlc + 1;
break;
}
}
@@ -601,6 +602,7 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen
!PyObject_IsTrue(PyList_GET_ITEM(consts, j)))
continue;
memset(codestr+i, NOP, 7);
+ cumlc = 0;
break;
/* Try to fold tuples of constants.
@@ -615,6 +617,8 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen
codestr[h] == LOAD_CONST &&
ISBASICBLOCK(blocks, h, 3*(j+1)) &&
tuple_of_constants(&codestr[h], j, consts)) {
+ assert(codestr[i] == LOAD_CONST);
+ cumlc = 1;
break;
}
/* Intentional fallthrough */