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
Gwenaël Samain
cython
Commits
cc65c48a
Commit
cc65c48a
authored
Apr 10, 2009
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
40f1624b
f3d13916
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
4 deletions
+33
-4
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+19
-3
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+1
-1
tests/run/range_optimisation_T203.pyx
tests/run/range_optimisation_T203.pyx
+13
-0
No files found.
Cython/Compiler/Nodes.py
View file @
cc65c48a
...
...
@@ -4002,12 +4002,28 @@ class ForFromStatNode(LoopNode, StatNode):
self
.
body
.
generate_execution_code
(
code
)
code
.
put_label
(
code
.
continue_label
)
if
self
.
py_loopvar_node
:
# Reassign py variable to loop var here.
# (For consistancy, should rarely come up in practice.)
# This mess is to make for..from loops with python targets behave
# exactly like those with C targets with regards to re-assignment
# of the loop variable.
import
ExprNodes
from_py_node
=
ExprNodes
.
CoerceFromPyTypeNode
(
self
.
loopvar_node
.
type
,
self
.
target
,
None
)
if
self
.
target
.
entry
.
is_pyglobal
:
# We know target is a NameNode, this is the only ugly case.
target_node
=
ExprNodes
.
PyTempNode
(
self
.
target
.
pos
,
None
)
target_node
.
result_code
=
code
.
funcstate
.
allocate_temp
(
py_object_type
,
False
)
code
.
putln
(
"%s = __Pyx_GetName(%s, %s); %s"
%
(
target_node
.
result_code
,
Naming
.
module_cname
,
self
.
target
.
entry
.
interned_cname
,
code
.
error_goto_if_null
(
target_node
.
result_code
,
self
.
target
.
pos
)))
code
.
put_gotref
(
target_node
.
result_code
)
else
:
target_node
=
self
.
target
from_py_node
=
ExprNodes
.
CoerceFromPyTypeNode
(
self
.
loopvar_node
.
type
,
target_node
,
None
)
from_py_node
.
temp_code
=
loopvar_name
from_py_node
.
generate_result_code
(
code
)
if
self
.
target
.
entry
.
is_pyglobal
:
code
.
put_decref_clear
(
target_node
.
result_code
,
py_object_type
)
code
.
funcstate
.
release_temp
(
target_node
.
result_code
)
code
.
putln
(
"}"
)
if
self
.
py_loopvar_node
:
# This is potentially wasteful, but we don't want the semantics to
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
cc65c48a
...
...
@@ -730,7 +730,7 @@ property NAME:
if
node
.
name
in
self
.
seen_vars_stack
[
-
1
]:
entry
=
self
.
env_stack
[
-
1
].
lookup
(
node
.
name
)
if
entry
is
None
or
entry
.
visibility
!=
'extern'
:
error
(
node
.
pos
,
"cdef variable '%s' declared after it is used"
%
node
.
name
)
warning
(
node
.
pos
,
"cdef variable '%s' declared after it is used"
%
node
.
name
,
2
)
self
.
visitchildren
(
node
)
return
node
...
...
tests/run/range_optimisation_T203.pyx
View file @
cc65c48a
...
...
@@ -46,6 +46,12 @@ at 1
at 3
at 7
15
>>> for_from_py_global_target_reassignment(10, 2)
at 0
at 1
at 3
at 7
15
>>> for_in_target_reassignment(10, 2)
at 0
at 1
...
...
@@ -112,6 +118,13 @@ def for_from_py_target_reassignment(int bound, int factor):
i
*=
factor
return
i
def
for_from_py_global_target_reassignment
(
int
bound
,
int
factor
):
global
g_var
for
g_var
from
0
<=
g_var
<
bound
:
print
"at"
,
g_var
g_var
*=
factor
return
g_var
def
for_in_target_reassignment
(
int
bound
,
int
factor
):
cdef
int
i
=
100
for
i
in
range
(
bound
):
...
...
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