Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 1164c87

Browse files
robrixpatrickt
andcommitted
Compile function definitions.
Co-Authored-By: Patrick Thomson <patrickt@users.noreply.github.com>
1 parent d64e12d commit 1164c87

File tree

1 file changed

+23
-1
lines changed
  • semantic-python/src/Language/Python

1 file changed

+23
-1
lines changed

semantic-python/src/Language/Python/Core.hs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,29 @@ instance Compile Py.False where compile _ = pure (Bool False)
5252

5353
instance Compile Py.Float
5454
instance Compile Py.ForStatement
55-
instance Compile Py.FunctionDefinition
55+
56+
instance Compile Py.FunctionDefinition where
57+
compile Py.FunctionDefinition
58+
{ name = Py.Identifier name
59+
, parameters = Py.Parameters parameters
60+
, ..
61+
} = do
62+
parameters' <- params
63+
body' <- compile body
64+
pure (Let (User name) := lams parameters' body')
65+
where params = case parameters of
66+
Nothing -> pure []
67+
Just p -> traverse param [p] -- FIXME: this is wrong in node-types.json, @p@ should already be a list
68+
param (Left Py.AnonymousComma{}) = fail "lol what"
69+
param (Right (Left Py.DefaultParameter{..})) = fail "lol what"
70+
param (Right (Right (Left Py.DictionarySplat{..}))) = fail "lol what"
71+
param (Right (Right (Right (Left (Py.Identifier name))))) = pure (User name)
72+
param (Right (Right (Right (Right (Left Py.KeywordIdentifier{..}))))) = fail "lol what"
73+
param (Right (Right (Right (Right (Right (Left Py.ListSplat{..})))))) = fail "lol what"
74+
param (Right (Right (Right (Right (Right (Right (Left Py.Tuple{..}))))))) = fail "lol what"
75+
param (Right (Right (Right (Right (Right (Right (Right (Left Py.TypedDefaultParameter{..})))))))) = fail "lol what"
76+
param (Right (Right (Right (Right (Right (Right (Right (Right Py.TypedParameter{..})))))))) = fail "lol what"
77+
5678
instance Compile Py.FutureImportStatement
5779
instance Compile Py.GeneratorExpression
5880
instance Compile Py.GlobalStatement

0 commit comments

Comments
 (0)