Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
68b24fae
Commit
68b24fae
authored
May 04, 2010
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
collapse BoolBinopNode during constant folding, small fix for BoolNode folding
parent
23668f32
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
1 deletion
+28
-1
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+22
-1
tests/run/bint_binop_T145.pyx
tests/run/bint_binop_T145.pyx
+6
-0
No files found.
Cython/Compiler/Optimize.py
View file @
68b24fae
...
...
@@ -2526,6 +2526,24 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
self
.
_calculate_const
(
node
)
return
node
def
visit_BoolBinopNode
(
self
,
node
):
self
.
_calculate_const
(
node
)
if
node
.
constant_result
is
ExprNodes
.
not_a_constant
:
return
node
if
not
node
.
operand1
.
is_literal
or
not
node
.
operand2
.
is_literal
:
# We calculate other constants to make them available to
# the compiler, but we only aggregate constant nodes
# recursively, so non-const nodes are straight out.
return
node
if
node
.
constant_result
==
node
.
operand1
.
constant_result
and
node
.
operand1
.
is_literal
:
return
node
.
operand1
elif
node
.
constant_result
==
node
.
operand2
.
constant_result
and
node
.
operand2
.
is_literal
:
return
node
.
operand2
else
:
# FIXME: we could do more ...
return
node
def
visit_BinopNode
(
self
,
node
):
self
.
_calculate_const
(
node
)
if
node
.
constant_result
is
ExprNodes
.
not_a_constant
:
...
...
@@ -2568,7 +2586,10 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
new_node
=
target_class
(
pos
=
node
.
pos
,
type
=
widest_type
)
new_node
.
constant_result
=
node
.
constant_result
new_node
.
value
=
str
(
node
.
constant_result
)
if
isinstance
(
node
,
ExprNodes
.
BoolNode
):
new_node
.
value
=
node
.
constant_result
else
:
new_node
.
value
=
str
(
node
.
constant_result
)
#new_node = new_node.coerce_to(node.type, self.current_scope)
return
new_node
...
...
tests/run/bint_binop_T145.pyx
View file @
68b24fae
cimport
cython
@
cython
.
test_fail_if_path_exists
(
'//BoolBinopNode'
)
def
or_literal_bint
():
"""
>>> True or 5
...
...
@@ -8,6 +11,7 @@ def or_literal_bint():
"""
return
True
or
5
@
cython
.
test_fail_if_path_exists
(
'//BoolBinopNode'
)
def
and_literal_bint
():
"""
>>> 5 and True
...
...
@@ -17,6 +21,7 @@ def and_literal_bint():
"""
return
5
and
True
@
cython
.
test_fail_if_path_exists
(
'//BoolBinopNode'
)
def
False_and_True_or_0
():
"""
>>> False and True or 0
...
...
@@ -26,6 +31,7 @@ def False_and_True_or_0():
"""
return
False
and
True
or
0
@
cython
.
test_fail_if_path_exists
(
'//BoolBinopNode'
)
def
True_and_True_or_0
():
"""
>>> True and True or 0
...
...
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