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

Commit b6a9fae

Browse files
committed
Call.
1 parent dcf7d40 commit b6a9fae

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

  • semantic-analysis/src/Analysis/Syntax

semantic-analysis/src/Analysis/Syntax/Python.hs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{-# LANGUAGE KindSignatures #-}
55
{-# LANGUAGE LambdaCase #-}
66
{-# LANGUAGE PatternSynonyms #-}
7+
{-# LANGUAGE ViewPatterns #-}
78
-- | This belongs in @semantic-python@ instead of @semantic-analysis@, but for the sake of expedience…
89
module Analysis.Syntax.Python
910
( -- * Syntax
@@ -17,6 +18,7 @@ module Analysis.Syntax.Python
1718
, pattern Throw''
1819
, pattern Import''
1920
, pattern Function''
21+
, pattern Call''
2022
-- * Abstract interpretation
2123
, eval0
2224
, eval
@@ -108,6 +110,25 @@ pattern Import'' i = Import' i T.:$: T.Nil
108110
pattern Function'' :: Name -> [Name] -> T.Term Python v -> T.Term Python v
109111
pattern Function'' n as b = Function' n as T.:$: T.Cons b T.Nil
110112

113+
pattern Call''
114+
:: T.Term Python v
115+
-> [T.Term Python v]
116+
-> T.Term Python v
117+
pattern Call'' f as <- Call' T.:$: T.Cons f (T.Cons (fromArgs -> as) T.Nil)
118+
where Call'' f as = Call' T.:$: T.Cons f (T.Cons (foldr ACons'' ANil'' as) T.Nil)
119+
120+
fromArgs :: T.Term Python v -> [T.Term Python v]
121+
fromArgs = \case
122+
ANil'' -> []
123+
ACons'' a as -> a:fromArgs as
124+
_ -> fail "unexpected constructor in spine of argument list"
125+
126+
pattern ANil'' :: T.Term Python v
127+
pattern ANil'' = ANil' T.:$: T.Nil
128+
129+
pattern ACons'' :: T.Term Python v -> T.Term Python v -> T.Term Python v
130+
pattern ACons'' a as = ACons' T.:$: T.Cons a (T.Cons as T.Nil)
131+
111132

112133
-- Abstract interpretation
113134

0 commit comments

Comments
 (0)