Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
grumpy
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
grumpy
Commits
86fafebc
Commit
86fafebc
authored
Jan 03, 2017
by
Dylan Trotter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement lambdas.
parent
32dfd73b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
1 deletion
+12
-1
compiler/expr_visitor.py
compiler/expr_visitor.py
+6
-1
compiler/expr_visitor_test.py
compiler/expr_visitor_test.py
+6
-0
No files found.
compiler/expr_visitor.py
View file @
86fafebc
...
...
@@ -239,6 +239,12 @@ class ExprVisitor(ast.NodeVisitor):
self
.
writer
.
write
(
'{} = {}'
.
format
(
result
.
name
,
v
.
expr
))
return
result
def
visit_Lambda
(
self
,
node
):
ret
=
ast
.
Return
(
node
.
body
,
lineno
=
node
.
lineno
)
func_node
=
ast
.
FunctionDef
(
name
=
'<lambda>'
,
args
=
node
.
args
,
body
=
[
ret
])
return
self
.
visit_function_inline
(
func_node
)
def
visit_List
(
self
,
node
):
with
self
.
_visit_seq_elts
(
node
.
elts
)
as
elems
:
result
=
self
.
block
.
alloc_temp
()
...
...
@@ -451,5 +457,4 @@ class ExprVisitor(ast.NodeVisitor):
msg
=
'node not yet implemented: '
+
type
(
node
).
__name__
raise
util
.
ParseError
(
node
,
msg
)
visit_Lambda
=
_node_not_implemented
visit_SetComp
=
_node_not_implemented
compiler/expr_visitor_test.py
View file @
86fafebc
...
...
@@ -151,6 +151,12 @@ class ExprVisitorTest(unittest.TestCase):
testIfExprNested
=
_MakeExprTest
(
'"foo" if "" else "bar" if 0 else "baz"'
)
testLambda
=
_MakeExprTest
(
'(lambda: 123)()'
)
testLambda
=
_MakeExprTest
(
'(lambda a, b: (a, b))("foo", "bar")'
)
testLambda
=
_MakeExprTest
(
'(lambda a, b=3: (a, b))("foo")'
)
testLambda
=
_MakeExprTest
(
'(lambda *args: args)(1, 2, 3)'
)
testLambda
=
_MakeExprTest
(
'(lambda **kwargs: kwargs)(x="foo", y="bar")'
)
testListEmpty
=
_MakeLiteralTest
([])
testListNonEmpty
=
_MakeLiteralTest
([
1
,
2
])
...
...
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