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
175f08eb
Commit
175f08eb
authored
Nov 27, 2010
by
Vitja Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support lambda in module scope #603
parent
8dca292a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
5 deletions
+31
-5
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+2
-0
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+1
-4
Cython/Compiler/Symtab.py
Cython/Compiler/Symtab.py
+3
-1
tests/run/lambda_module.pyx
tests/run/lambda_module.pyx
+25
-0
No files found.
Cython/Compiler/Nodes.py
View file @
175f08eb
...
...
@@ -2215,6 +2215,8 @@ class DefNode(FuncDefNode):
def
needs_assignment_synthesis
(
self
,
env
,
code
=
None
):
# Should enable for module level as well, that will require more testing...
if
self
.
entry
.
is_lambda
:
return
True
if
env
.
is_module_scope
:
if
code
is
None
:
return
env
.
directives
[
'binding'
]
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
175f08eb
...
...
@@ -181,9 +181,6 @@ class PostParse(ScopeTrackingTransform):
def
visit_LambdaNode
(
self
,
node
):
# unpack a lambda expression into the corresponding DefNode
if
self
.
scope_type
!=
'function'
:
error
(
node
.
pos
,
"lambda functions are currently only supported in functions"
)
lambda_id
=
self
.
lambda_counter
self
.
lambda_counter
+=
1
node
.
lambda_name
=
EncodedString
(
u'lambda%d'
%
lambda_id
)
...
...
@@ -1366,7 +1363,7 @@ class CreateClosureClasses(CythonTransform):
while
cscope
.
is_py_class_scope
or
cscope
.
is_c_class_scope
:
cscope
=
cscope
.
outer_scope
if
not
from_closure
and
self
.
path
:
if
not
from_closure
and
(
self
.
path
or
inner_node
)
:
if
not
inner_node
:
if
not
node
.
assmt
:
raise
InternalError
,
"DefNode does not have assignment node"
...
...
Cython/Compiler/Symtab.py
View file @
175f08eb
...
...
@@ -75,6 +75,7 @@ class Entry(object):
# is_cfunction boolean Is a C function
# is_cmethod boolean Is a C method of an extension type
# is_unbound_cmethod boolean Is an unbound C method of an extension type
# is_lambda boolean Is a lambda function
# is_type boolean Is a type definition
# is_cclass boolean Is an extension class
# is_cpp_class boolean Is a C++ class
...
...
@@ -137,6 +138,7 @@ class Entry(object):
is_cfunction = 0
is_cmethod = 0
is_unbound_cmethod = 0
is_lambda = 0
is_type = 0
is_cclass = 0
is_cpp_class = 0
...
...
@@ -530,7 +532,7 @@ class Scope(object):
entry.name = EncodedString(func_cname)
entry.func_cname = func_cname
entry.signature = pyfunction_signature
self.pyfunc_entries.append(entry)
entry.is_lambda = True
return entry
def add_lambda_def(self, def_node):
...
...
tests/run/lambda_module.pyx
0 → 100644
View file @
175f08eb
# Module scope lambda functions
__doc__
=
"""
>>> pow2(16)
256
>>> with_closure(0)
0
>>> typed_lambda(1)(2)
3
>>> typed_lambda(1.5)(1.5)
2
>>> cdef_const_lambda()
123
>>> const_lambda()
321
"""
pow2
=
lambda
x
:
x
*
x
with_closure
=
lambda
x
:(
lambda
:
x
)()
typed_lambda
=
lambda
int
x
:
(
lambda
int
y
:
x
+
y
)
cdef
int
xxx
=
123
cdef
_const_lambda
=
lambda
:
xxx
yyy
=
321
const_lambda
=
lambda
:
yyy
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