mirror of
https://github.com/github/semantic.git
synced 2024-11-24 08:54:07 +03:00
Compile Python lambdas.
Lambdas are so hilariously crippled in Python that they're significantly easier to compile than functions. Indeed, the resulting core looks much like a function definition, without a `rec` binding.
This commit is contained in:
parent
4ff4e5d776
commit
e137f4c68b
@ -311,7 +311,18 @@ instance Compile Py.ImportFromStatement
|
||||
instance Compile Py.ImportStatement
|
||||
instance Compile Py.Integer
|
||||
|
||||
instance Compile Py.Lambda
|
||||
instance Compile Py.Lambda where
|
||||
compile it@Py.Lambda
|
||||
{ body
|
||||
, parameters
|
||||
} cc next = do
|
||||
let unparams (Py.LambdaParameters _ ps) = toList ps
|
||||
unparam (Py.Parameter (Prj (Py.Identifier _pann pname))) = Just . named' . Name $ pname
|
||||
unparam _ = Nothing
|
||||
body' <- compile body cc next
|
||||
let params = maybe [] unparams parameters
|
||||
pure . locate it. . lams (catMaybes (fmap unparam params)) $ body'
|
||||
|
||||
instance Compile Py.List
|
||||
instance Compile Py.ListComprehension
|
||||
instance Compile Py.ListSplat
|
||||
|
4
semantic-python/test/fixtures/4-01-lambda-literals.py
vendored
Normal file
4
semantic-python/test/fixtures/4-01-lambda-literals.py
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
# CHECK-TREE: { const <- \x -> \y -> x; y <- const #true #true; z <- const #false #false; #record { const: const, y : y, z: z, }}
|
||||
const = lambda x, y: x
|
||||
y = const(True, True)
|
||||
z = const(False, False)
|
Loading…
Reference in New Issue
Block a user