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
e994a8b7
Commit
e994a8b7
authored
Jul 19, 2008
by
Dag Sverre Seljebotn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Assignments on cdef variables are transformed into singleassignments
parent
e4792365
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
12 deletions
+35
-12
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+3
-7
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+20
-1
tests/run/bufaccess.pyx
tests/run/bufaccess.pyx
+12
-4
No files found.
Cython/Compiler/Nodes.py
View file @
e994a8b7
...
@@ -388,13 +388,9 @@ class CNameDeclaratorNode(CDeclaratorNode):
...
@@ -388,13 +388,9 @@ class CNameDeclaratorNode(CDeclaratorNode):
self
.
default
.
release_temp
(
env
)
self
.
default
.
release_temp
(
env
)
def
generate_execution_code
(
self
,
code
):
def
generate_execution_code
(
self
,
code
):
if
self
.
default
is
not
None
:
assert
self
.
default
is
None
self
.
default
.
generate_evaluation_code
(
code
)
# PostParse creates assignment statements for any
if
self
.
type
.
is_pyobject
:
# default values
self
.
default
.
make_owned_reference
(
code
)
code
.
putln
(
'%s = %s;'
%
(
self
.
entry
.
cname
,
self
.
default
.
result_as
(
self
.
entry
.
type
)))
self
.
default
.
generate_post_assignment_code
(
code
)
code
.
putln
()
class
CPtrDeclaratorNode
(
CDeclaratorNode
):
class
CPtrDeclaratorNode
(
CDeclaratorNode
):
# base CDeclaratorNode
# base CDeclaratorNode
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
e994a8b7
...
@@ -91,6 +91,8 @@ class PostParse(CythonTransform):
...
@@ -91,6 +91,8 @@ class PostParse(CythonTransform):
as such).
as such).
Specifically:
Specifically:
- Default values to cdef assignments are turned into single
assignments following the declaration.
- CBufferAccessTypeNode has its options interpreted:
- CBufferAccessTypeNode has its options interpreted:
Any first positional argument goes into the "dtype" attribute,
Any first positional argument goes into the "dtype" attribute,
any "ndim" keyword argument goes into the "ndim" attribute and
any "ndim" keyword argument goes into the "ndim" attribute and
...
@@ -101,6 +103,23 @@ class PostParse(CythonTransform):
...
@@ -101,6 +103,23 @@ class PostParse(CythonTransform):
if a more pure Abstract Syntax Tree is wanted.
if a more pure Abstract Syntax Tree is wanted.
"""
"""
def
visit_CVarDefNode
(
self
,
node
):
# This assumes only plain names and pointers are assignable on
# declaration.
self
.
visitchildren
(
node
)
stats
=
[
node
]
for
decl
in
node
.
declarators
:
while
isinstance
(
decl
,
CPtrDeclaratorNode
):
decl
=
decl
.
base
if
isinstance
(
decl
,
CNameDeclaratorNode
):
if
decl
.
default
is
not
None
:
stats
.
append
(
SingleAssignmentNode
(
node
.
pos
,
lhs
=
NameNode
(
node
.
pos
,
name
=
decl
.
name
),
rhs
=
decl
.
default
))
decl
.
default
=
None
return
stats
buffer_options
=
(
"dtype"
,
"ndim"
)
# ordered!
buffer_options
=
(
"dtype"
,
"ndim"
)
# ordered!
def
visit_CBufferAccessTypeNode
(
self
,
node
):
def
visit_CBufferAccessTypeNode
(
self
,
node
):
options
=
{}
options
=
{}
...
...
tests/run/bufaccess.pyx
View file @
e994a8b7
...
@@ -34,6 +34,12 @@ __doc__ = u"""
...
@@ -34,6 +34,12 @@ __doc__ = u"""
acquired
acquired
0 1 2 3 4 5
0 1 2 3 4 5
released
released
>>> cdef_assignment(A, 6)
acquired A
0 1 2 3 4 5
released A
>>> printbuf_float(MockBuffer("f", [1.0, 1.25, 0.75, 1.0]), (4,))
>>> printbuf_float(MockBuffer("f", [1.0, 1.25, 0.75, 1.0]), (4,))
acquired
acquired
1.0 1.25 0.75 1.0
1.0 1.25 0.75 1.0
...
@@ -86,10 +92,12 @@ def as_argument_defval(object[int] bufarg=MockBuffer('i', range(6)), int n=6):
...
@@ -86,10 +92,12 @@ def as_argument_defval(object[int] bufarg=MockBuffer('i', range(6)), int n=6):
print
bufarg
[
i
],
print
bufarg
[
i
],
print
print
def
cdef_assignment
(
obj
,
n
):
cdef
object
[
int
]
buf
=
obj
# default values
cdef
int
i
#
for
i
in
range
(
n
):
print
buf
[
i
],
print
def
printbuf_float
(
o
,
shape
):
def
printbuf_float
(
o
,
shape
):
# should make shape builtin
# should make shape builtin
...
...
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