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
1a1261a1
Commit
1a1261a1
authored
Nov 28, 2014
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
merge 0.21.x branch into master
parents
0a9cecf7
31d5d476
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
8 deletions
+32
-8
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+17
-8
tests/run/cascaded_typed_assignments_T466.pyx
tests/run/cascaded_typed_assignments_T466.pyx
+15
-0
No files found.
Cython/Compiler/Nodes.py
View file @
1a1261a1
...
@@ -4984,10 +4984,11 @@ class CascadedAssignmentNode(AssignmentNode):
...
@@ -4984,10 +4984,11 @@ class CascadedAssignmentNode(AssignmentNode):
#
#
# Used internally:
# Used internally:
#
#
# coerced_rhs_list [ExprNode] RHS coerced to type of each LHS
# coerced_values [ExprNode] RHS coerced to all distinct LHS types
# cloned_values [ExprNode] cloned RHS value for each LHS
child_attrs
=
[
"lhs_list"
,
"rhs"
,
"coerced_values"
,
"c
oerced_rhs_list
"
]
child_attrs
=
[
"lhs_list"
,
"rhs"
,
"coerced_values"
,
"c
loned_values
"
]
c
oerced_rhs_list
=
None
c
loned_values
=
None
coerced_values
=
None
coerced_values
=
None
def
analyse_declarations
(
self
,
env
):
def
analyse_declarations
(
self
,
env
):
...
@@ -4997,6 +4998,7 @@ class CascadedAssignmentNode(AssignmentNode):
...
@@ -4997,6 +4998,7 @@ class CascadedAssignmentNode(AssignmentNode):
def
analyse_types
(
self
,
env
,
use_temp
=
0
):
def
analyse_types
(
self
,
env
,
use_temp
=
0
):
from
.ExprNodes
import
CloneNode
,
ProxyNode
from
.ExprNodes
import
CloneNode
,
ProxyNode
# collect distinct types used on the LHS
lhs_types
=
set
()
lhs_types
=
set
()
for
lhs
in
self
.
lhs_list
:
for
lhs
in
self
.
lhs_list
:
lhs
.
analyse_target_types
(
env
)
lhs
.
analyse_target_types
(
env
)
...
@@ -5015,6 +5017,7 @@ class CascadedAssignmentNode(AssignmentNode):
...
@@ -5015,6 +5017,7 @@ class CascadedAssignmentNode(AssignmentNode):
rhs
=
rhs
.
coerce_to_simple
(
env
)
rhs
=
rhs
.
coerce_to_simple
(
env
)
self
.
rhs
=
ProxyNode
(
rhs
)
if
rhs
.
is_temp
else
rhs
self
.
rhs
=
ProxyNode
(
rhs
)
if
rhs
.
is_temp
else
rhs
# clone RHS and coerce it to all distinct LHS types
self
.
coerced_values
=
[]
self
.
coerced_values
=
[]
coerced_values
=
{}
coerced_values
=
{}
for
lhs
in
self
.
lhs_list
:
for
lhs
in
self
.
lhs_list
:
...
@@ -5023,22 +5026,28 @@ class CascadedAssignmentNode(AssignmentNode):
...
@@ -5023,22 +5026,28 @@ class CascadedAssignmentNode(AssignmentNode):
self
.
coerced_values
.
append
(
rhs
)
self
.
coerced_values
.
append
(
rhs
)
coerced_values
[
lhs
.
type
]
=
rhs
coerced_values
[
lhs
.
type
]
=
rhs
self
.
coerced_rhs_list
=
[]
# clone coerced values for all LHS assignments
self
.
cloned_values
=
[]
for
lhs
in
self
.
lhs_list
:
for
lhs
in
self
.
lhs_list
:
rhs
=
coerced_values
.
get
(
lhs
.
type
,
self
.
rhs
)
rhs
=
coerced_values
.
get
(
lhs
.
type
,
self
.
rhs
)
self
.
c
oerced_rhs_list
.
append
(
CloneNode
(
rhs
))
self
.
c
loned_values
.
append
(
CloneNode
(
rhs
))
return
self
return
self
def
generate_rhs_evaluation_code
(
self
,
code
):
def
generate_rhs_evaluation_code
(
self
,
code
):
self
.
rhs
.
generate_evaluation_code
(
code
)
self
.
rhs
.
generate_evaluation_code
(
code
)
def
generate_assignment_code
(
self
,
code
):
def
generate_assignment_code
(
self
,
code
):
# prepare all coercions
for
rhs
in
self
.
coerced_values
:
for
rhs
in
self
.
coerced_values
:
rhs
.
generate_evaluation_code
(
code
)
rhs
.
generate_evaluation_code
(
code
)
for
lhs
,
rhs
in
zip
(
self
.
lhs_list
,
self
.
coerced_rhs_list
):
# assign clones to LHS
for
lhs
,
rhs
in
zip
(
self
.
lhs_list
,
self
.
cloned_values
):
rhs
.
generate_evaluation_code
(
code
)
rhs
.
generate_evaluation_code
(
code
)
lhs
.
generate_assignment_code
(
rhs
,
code
)
lhs
.
generate_assignment_code
(
rhs
,
code
)
# Assignment has disposed of the cloned RHS
# dispose of coerced values and original RHS
for
rhs_value
in
self
.
coerced_values
:
rhs_value
.
generate_disposal_code
(
code
)
rhs_value
.
free_temps
(
code
)
self
.
rhs
.
generate_disposal_code
(
code
)
self
.
rhs
.
generate_disposal_code
(
code
)
self
.
rhs
.
free_temps
(
code
)
self
.
rhs
.
free_temps
(
code
)
...
@@ -5048,7 +5057,7 @@ class CascadedAssignmentNode(AssignmentNode):
...
@@ -5048,7 +5057,7 @@ class CascadedAssignmentNode(AssignmentNode):
def
annotate
(
self
,
code
):
def
annotate
(
self
,
code
):
for
rhs
in
self
.
coerced_values
:
for
rhs
in
self
.
coerced_values
:
rhs
.
annotate
(
code
)
rhs
.
annotate
(
code
)
for
lhs
,
rhs
in
zip
(
self
.
lhs_list
,
self
.
c
oerced_rhs_list
):
for
lhs
,
rhs
in
zip
(
self
.
lhs_list
,
self
.
c
loned_values
):
lhs
.
annotate
(
code
)
lhs
.
annotate
(
code
)
rhs
.
annotate
(
code
)
rhs
.
annotate
(
code
)
self
.
rhs
.
annotate
(
code
)
self
.
rhs
.
annotate
(
code
)
...
...
tests/run/cascaded_typed_assignments_T466.pyx
View file @
1a1261a1
...
@@ -101,3 +101,18 @@ def assign_carray():
...
@@ -101,3 +101,18 @@ def assign_carray():
assert
b
[
0
]
==
2
assert
b
[
0
]
==
2
assert
c
[
1
]
==
3
assert
c
[
1
]
==
3
return
a
[
0
],
b
[
0
],
c
[
1
]
return
a
[
0
],
b
[
0
],
c
[
1
]
def
pyobject_from_cvalue
(
table
,
key
):
"""
>>> table = {'X':0, 'Y':1}
>>> pyobject_from_cvalue(table, 'Z')
2
>>> pyobject_from_cvalue(table, 'X')
0
"""
cdef
int
num
num
=
table
.
get
(
key
,
-
1
)
if
num
<
0
:
num
=
table
[
key
]
=
len
(
table
)
return
num
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