Commit 86fafebc authored by Dylan Trotter's avatar Dylan Trotter

Implement lambdas.

parent 32dfd73b
......@@ -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
......@@ -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])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment