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
Boxiang Sun
cython
Commits
3bad2267
Commit
3bad2267
authored
Jan 30, 2009
by
Magnus Lie Hetland
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for #196
parent
1fdb965c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
3 deletions
+57
-3
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+12
-2
Cython/Compiler/Optimize.py
Cython/Compiler/Optimize.py
+2
-1
tests/run/for_decrement.pyx
tests/run/for_decrement.pyx
+43
-0
No files found.
Cython/Compiler/Nodes.py
View file @
3bad2267
...
...
@@ -3904,9 +3904,15 @@ class ForFromStatNode(LoopNode, StatNode):
self
.
bound1
.
generate_evaluation_code
(
code
)
self
.
bound2
.
generate_evaluation_code
(
code
)
offset
,
incop
=
self
.
relation_table
[
self
.
relation1
]
if
incop
==
"++"
:
decop
=
"--"
else
:
decop
=
"++"
if
self
.
step
is
not
None
:
self
.
step
.
generate_evaluation_code
(
code
)
incop
=
"%s=%s"
%
(
incop
[
0
],
self
.
step
.
result
())
step
=
self
.
step
.
result
()
incop
=
"%s=%s"
%
(
incop
[
0
],
step
)
decop
=
"%s=%s"
%
(
decop
[
0
],
step
)
loopvar_name
=
self
.
loopvar_node
.
result
()
code
.
putln
(
"for (%s = %s%s; %s %s %s; %s%s) {"
%
(
...
...
@@ -3919,7 +3925,11 @@ class ForFromStatNode(LoopNode, StatNode):
self
.
target
.
generate_assignment_code
(
self
.
py_loopvar_node
,
code
)
self
.
body
.
generate_execution_code
(
code
)
code
.
put_label
(
code
.
continue_label
)
code
.
putln
(
"}"
)
if
getattr
(
self
,
"from_range"
,
False
):
# Undo last increment to maintain Python semantics:
code
.
putln
(
"} %s%s;"
%
(
loopvar_name
,
decop
))
else
:
code
.
putln
(
"}"
)
break_label
=
code
.
break_label
code
.
set_loop_labels
(
old_loop_labels
)
if
self
.
else_clause
:
...
...
Cython/Compiler/Optimize.py
View file @
3bad2267
...
...
@@ -144,7 +144,8 @@ class IterationTransform(Visitor.VisitorTransform):
relation2
=
relation2
,
bound2
=
bound2
,
step
=
step
,
body
=
node
.
body
,
else_clause
=
node
.
else_clause
,
loopvar_node
=
node
.
target
)
loopvar_node
=
node
.
target
,
from_range
=
True
)
return
for_node
def
_transform_dict_iteration
(
self
,
node
,
dict_obj
,
keys
,
values
):
...
...
tests/run/for_decrement.pyx
0 → 100644
View file @
3bad2267
"""
>>> range_loop_indices()
** Calculating step **
(9, 9, 8, 1, 2)
>>> from_loop_indices()
** Calculating step **
** Calculating step **
** Calculating step **
** Calculating step **
** Calculating step **
(10, 10, 0)
"""
cdef
int
get_step
():
"""
This should only be called once, when used in range().
"""
print
"** Calculating step **"
return
2
def
range_loop_indices
():
"""
Optimized integer for loops using range() should follow Python behavior,
and leave the index variable with the last value of the range.
"""
cdef
int
i
,
j
,
k
,
l
,
m
for
i
in
range
(
10
):
pass
for
j
in
range
(
2
,
10
):
pass
for
k
in
range
(
0
,
10
,
get_step
()):
pass
for
l
in
range
(
10
,
0
,
-
1
):
pass
for
m
in
range
(
10
,
0
,
-
2
):
pass
return
i
,
j
,
k
,
l
,
m
def
from_loop_indices
():
"""
for-from-loops should follow C behavior, and leave the index variable
incremented one step after the last iteration.
"""
cdef
int
i
,
j
,
k
for
i
from
0
<=
i
<
10
by
get_step
():
pass
for
j
from
0
<=
j
<
10
:
pass
for
k
from
10
>
k
>
0
:
pass
return
i
,
j
,
k
\ No newline at end of file
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