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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
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
Show 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,15 +894,26 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
...
@@ -894,15 +894,26 @@ 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
isinstance
(
node
.
operand1
,
ExprNodes
.
ConstNode
)
and
\
isinstance
(
node
.
operand1
,
ExprNodes
.
ConstNode
):
if
type1
is
type2
:
if
type1
is
type2
:
new_node
=
node
.
operand1
new_node
=
node
.
operand1
else
:
else
:
...
@@ -919,9 +930,7 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
...
@@ -919,9 +930,7 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
node
.
operand1
,
node
.
operand2
)
node
.
operand1
,
node
.
operand2
)
if
target_class
is
None
:
if
target_class
is
None
:
return
node
return
node
new_node
=
target_class
(
type
=
widest_type
)
new_node
=
target_class
(
pos
=
node
.
pos
,
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