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
56304494
Commit
56304494
authored
Jan 21, 2015
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle for-from ranges with unsigned targets and near-zero endpoints.
parent
122904c4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
6 deletions
+54
-6
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+18
-6
tests/run/reversed_iteration.pyx
tests/run/reversed_iteration.pyx
+36
-0
No files found.
Cython/Compiler/Nodes.py
View file @
56304494
...
...
@@ -6201,12 +6201,24 @@ class ForFromStatNode(LoopNode, StatNode):
loopvar_name
=
code
.
funcstate
.
allocate_temp
(
self
.
target
.
type
,
False
)
else
:
loopvar_name
=
self
.
loopvar_node
.
result
()
code
.
putln
(
"for (%s = %s%s; %s %s %s; %s%s) {"
%
(
loopvar_name
,
self
.
bound1
.
result
(),
offset
,
loopvar_name
,
self
.
relation2
,
self
.
bound2
.
result
(),
loopvar_name
,
incop
))
if
self
.
target
.
type
.
is_int
and
not
self
.
target
.
type
.
signed
and
self
.
relation2
[
0
]
==
'>'
:
# Handle the case where the endpoint of an unsigned int iteration
# is within step of 0.
if
not
self
.
step
:
step
=
1
code
.
putln
(
"for (%s = %s%s + %s; %s %s %s + %s; ) { %s%s;"
%
(
loopvar_name
,
self
.
bound1
.
result
(),
offset
,
step
,
loopvar_name
,
self
.
relation2
,
self
.
bound2
.
result
(),
step
,
loopvar_name
,
incop
))
else
:
code
.
putln
(
"for (%s = %s%s; %s %s %s; %s%s) {"
%
(
loopvar_name
,
self
.
bound1
.
result
(),
offset
,
loopvar_name
,
self
.
relation2
,
self
.
bound2
.
result
(),
loopvar_name
,
incop
))
if
self
.
py_loopvar_node
:
self
.
py_loopvar_node
.
generate_evaluation_code
(
code
)
self
.
target
.
generate_assignment_code
(
self
.
py_loopvar_node
,
code
)
...
...
tests/run/reversed_iteration.pyx
View file @
56304494
...
...
@@ -759,3 +759,39 @@ def reversed_bytes_slice_step_only(bytes s):
for
c
in
reversed
(
s
[::
-
1
]):
result
.
append
(
c
)
return
result
@
cython
.
test_assert_path_exists
(
'//ForFromStatNode'
)
def
reversed_unsigned
(
int
a
,
int
b
):
"""
>>> reversed_unsigned(0, 5)
[4, 3, 2, 1, 0]
>>> reversed_unsigned(1, 5)
[4, 3, 2, 1]
>>> reversed_unsigned(1, 1)
[]
"""
cdef
unsigned
int
i
return
[
i
for
i
in
reversed
(
range
(
a
,
b
))]
@
cython
.
test_assert_path_exists
(
'//ForFromStatNode'
)
def
reversed_unsigned_by_3
(
int
a
,
int
b
):
"""
>>> reversed_unsigned_by_3(0, 5)
[3, 0]
>>> reversed_unsigned_by_3(0, 7)
[6, 3, 0]
"""
cdef
unsigned
int
i
return
[
i
for
i
in
reversed
(
range
(
a
,
b
,
3
))]
@
cython
.
test_assert_path_exists
(
'//ForFromStatNode'
)
def
range_unsigned_by_neg_3
(
int
a
,
int
b
):
"""
>>> range_unsigned_by_neg_3(-1, 6)
[6, 3, 0]
>>> range_unsigned_by_neg_3(0, 7)
[7, 4, 1]
"""
cdef
unsigned
int
i
return
[
i
for
i
in
range
(
b
,
a
,
-
3
)]
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