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
3b16dc63
Commit
3b16dc63
authored
Dec 03, 2010
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support lambda in class and cclass scope, ticket #605.
parent
eea8ce91
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
6 deletions
+44
-6
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+1
-3
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+7
-3
tests/run/lambda_class_T605.pyx
tests/run/lambda_class_T605.pyx
+36
-0
No files found.
Cython/Compiler/ModuleNode.py
View file @
3b16dc63
...
...
@@ -271,9 +271,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code
=
globalstate
[
'all_the_rest'
]
self
.
generate_cached_builtins_decls
(
env
,
code
)
# generate lambda function definitions
for
node
in
env
.
lambda_defs
:
node
.
generate_function_definitions
(
env
,
code
)
self
.
generate_lambda_definitions
(
env
,
code
)
# generate normal function definitions
self
.
body
.
generate_function_definitions
(
env
,
code
)
code
.
mark_pos
(
None
)
...
...
Cython/Compiler/Nodes.py
View file @
3b16dc63
...
...
@@ -321,7 +321,10 @@ class BlockNode(object):
for
entry
in
entries
:
code
.
globalstate
.
add_cached_builtin_decl
(
entry
)
del
entries
[:]
def
generate_lambda_definitions
(
self
,
env
,
code
):
for
node
in
env
.
lambda_defs
:
node
.
generate_function_definitions
(
env
,
code
)
class
StatListNode
(
Node
):
# stats a list of StatNode
...
...
@@ -1211,8 +1214,7 @@ class FuncDefNode(StatNode, BlockNode):
# Generate closure function definitions
self
.
body
.
generate_function_definitions
(
lenv
,
code
)
# generate lambda function definitions
for
node
in
lenv
.
lambda_defs
:
node
.
generate_function_definitions
(
lenv
,
code
)
self
.
generate_lambda_definitions
(
lenv
,
code
)
is_getbuffer_slot
=
(
self
.
entry
.
name
==
"__getbuffer__"
and
self
.
entry
.
scope
.
is_c_class_scope
)
...
...
@@ -3079,6 +3081,7 @@ class PyClassDefNode(ClassDefNode):
self
.
target
.
analyse_target_expression
(
env
,
self
.
classobj
)
def
generate_function_definitions
(
self
,
env
,
code
):
self
.
generate_lambda_definitions
(
self
.
scope
,
code
)
self
.
body
.
generate_function_definitions
(
self
.
scope
,
code
)
def
generate_execution_code
(
self
,
code
):
...
...
@@ -3241,6 +3244,7 @@ class CClassDefNode(ClassDefNode):
self
.
body
.
analyse_expressions
(
scope
)
def
generate_function_definitions
(
self
,
env
,
code
):
self
.
generate_lambda_definitions
(
self
.
scope
,
code
)
if
self
.
body
:
self
.
body
.
generate_function_definitions
(
self
.
entry
.
type
.
scope
,
code
)
...
...
tests/run/lambda_class_T605.pyx
0 → 100644
View file @
3b16dc63
cdef
int
cdef
_CONST
=
123
CONST
=
456
cdef
class
Foo
:
"""
>>> obj = Foo()
>>> obj.id(123)
123
>>> obj.cconst_mul(1)
123
>>> obj.const_mul(1)
456
>>> obj.foo[0](1)
1
"""
id
=
lambda
self
,
x
:
x
cconst_mul
=
lambda
self
,
x
:
x
*
cdef
_CONST
const_mul
=
lambda
self
,
x
:
x
*
CONST
foo
=
(
lambda
x
:
x
,)
class
Bar
:
"""
>>> obj = Bar()
>>> obj.id(123)
123
>>> obj.cconst_mul(1)
123
>>> obj.const_mul(1)
456
>>> obj.foo[0](1)
1
"""
id
=
lambda
self
,
x
:
x
cconst_mul
=
lambda
self
,
x
:
x
*
cdef
_CONST
const_mul
=
lambda
self
,
x
:
x
*
CONST
foo
=
(
lambda
x
:
x
,)
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