Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
af7adad5
Commit
af7adad5
authored
Oct 22, 2009
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Peephole constant folding had missed UNARY_POSITIVE.
parent
42ead48d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
0 deletions
+7
-0
Lib/test/test_peepholer.py
Lib/test/test_peepholer.py
+1
-0
Misc/NEWS
Misc/NEWS
+2
-0
Python/peephole.c
Python/peephole.c
+4
-0
No files found.
Lib/test/test_peepholer.py
View file @
af7adad5
...
...
@@ -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
)
...
...
Misc/NEWS
View file @
af7adad5
...
...
@@ -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.
...
...
Python/peephole.c
View file @
af7adad5
...
...
@@ -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
))
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment