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
e76ea8ef
Commit
e76ea8ef
authored
Jul 05, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix constant folding: calculate float values but do not aggregate them into ConstNodes
parent
6328f1a2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
21 deletions
+30
-21
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+30
-21
No files found.
Cython/Compiler/Optimize.py
View file @
e76ea8ef
...
@@ -894,34 +894,43 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
...
@@ -894,34 +894,43 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
self
.
_calculate_const
(
node
)
self
.
_calculate_const
(
node
)
if
node
.
constant_result
is
ExprNodes
.
not_a_constant
:
if
node
.
constant_result
is
ExprNodes
.
not_a_constant
:
return
node
return
node
if
isinstance
(
node
.
constant_result
,
float
):
# We calculate float constants to make them available to
# the compiler, but we do not aggregate them into a
# constant node to prevent any loss of precision.
return
node
if
not
isinstance
(
node
.
operand1
,
ExprNodes
.
ConstNode
)
or
\
not
isinstance
(
node
.
operand1
,
ExprNodes
.
ConstNode
):
# 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
# now inject a new constant node with the calculated value
try
:
try
:
if
node
.
operand1
.
type
is
None
or
node
.
operand2
.
type
is
None
:
type1
,
type2
=
node
.
operand1
.
type
,
node
.
operand2
.
type
if
type1
is
None
or
type2
is
None
:
return
node
return
node
except
AttributeError
:
except
AttributeError
:
return
node
return
node
type1
,
type2
=
node
.
operand1
.
type
,
node
.
operand2
.
type
if
type1
is
type2
:
if
isinstance
(
node
.
operand1
,
ExprNodes
.
ConstNode
)
and
\
new_node
=
node
.
operand1
isinstance
(
node
.
operand1
,
ExprNodes
.
ConstNode
):
else
:
if
type1
is
type2
:
widest_type
=
PyrexTypes
.
widest_numeric_type
(
type1
,
type2
)
if
type
(
node
.
operand1
)
is
type
(
node
.
operand2
):
new_node
=
node
.
operand1
new_node
.
type
=
widest_type
elif
type1
is
widest_type
:
new_node
=
node
.
operand1
new_node
=
node
.
operand1
elif
type2
is
widest_type
:
new_node
=
node
.
operand2
else
:
else
:
widest_type
=
PyrexTypes
.
widest_numeric_type
(
type1
,
type2
)
target_class
=
self
.
_widest_node_class
(
if
type
(
node
.
operand1
)
is
type
(
node
.
operand2
):
node
.
operand1
,
node
.
operand2
)
new_node
=
node
.
operand1
if
target_class
is
None
:
new_node
.
type
=
widest_type
return
node
elif
type1
is
widest_type
:
new_node
=
target_class
(
pos
=
node
.
pos
,
type
=
widest_type
)
new_node
=
node
.
operand1
elif
type2
is
widest_type
:
new_node
=
node
.
operand2
else
:
target_class
=
self
.
_widest_node_class
(
node
.
operand1
,
node
.
operand2
)
if
target_class
is
None
:
return
node
new_node
=
target_class
(
type
=
widest_type
)
else
:
return
node
new_node
.
constant_result
=
node
.
constant_result
new_node
.
constant_result
=
node
.
constant_result
new_node
.
value
=
str
(
node
.
constant_result
)
new_node
.
value
=
str
(
node
.
constant_result
)
...
...
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