11{-# LANGUAGE NamedFieldPuns, DerivingVia, GeneralizedNewtypeDeriving #-}
22module Agda2Lambox.Compile.Term
3- ( C
4- , runC
5- , withMutuals
6- , compileTerm
3+ ( compileTerm
74 ) where
85
96import Control.Monad ( mapM )
@@ -74,8 +71,16 @@ withMutuals ms = local \e -> e { mutuals = reverse ms }
7471-- * Term conversion
7572
7673-- | Convert a treeless term to its λ□ equivalent.
77- compileTerm :: TTerm -> C LBox. Term
78- compileTerm = \ case
74+ compileTerm
75+ :: [QName ]
76+ -- ^ Local fixpoints.
77+ -> TTerm
78+ -> TCM LBox. Term
79+ compileTerm ms = runC . withMutuals ms . compileTermC
80+
81+ -- | Convert a treeless term to its λ□ equivalent.
82+ compileTermC :: TTerm -> C LBox. Term
83+ compileTermC = \ case
7984 TVar n -> pure $ LRel n
8085 TPrim p -> fail " primitives not supported"
8186
@@ -86,20 +91,20 @@ compileTerm = \case
8691 Just i -> LRel $ i + boundVars
8792
8893 TCon q -> liftTCM $ toConApp q []
89- TApp (TCon q) args -> liftTCM . toConApp q =<< mapM compileTerm args
94+ TApp (TCon q) args -> liftTCM . toConApp q =<< mapM compileTermC args
9095 -- ^ For dealing with fully-applied constructors
9196
9297 TApp u es -> do
93- cu <- compileTerm u
94- ces <- mapM compileTerm es
98+ cu <- compileTermC u
99+ ces <- mapM compileTermC es
95100 pure $ foldl' LApp cu ces
96101
97- TLam t -> underBinder $ LLam <$> compileTerm t
102+ TLam t -> underBinder $ LLam <$> compileTermC t
98103
99104 TLit l -> fail " literals not supported"
100105
101- TLet u v -> LLet <$> compileTerm u
102- <*> underBinder (compileTerm v)
106+ TLet u v -> LLet <$> compileTermC u
107+ <*> underBinder (compileTermC v)
103108
104109 TCase n CaseInfo {.. } dt talts ->
105110 case caseErased of
@@ -125,6 +130,6 @@ compileCaseType = \case
125130compileAlt :: TAlt -> C ([LBox. Name ], LBox. Term )
126131compileAlt = \ case
127132 TACon {.. } -> let names = take aArity $ repeat LBox. Anon
128- in (names,) <$> underBinders aArity (compileTerm aBody)
133+ in (names,) <$> underBinders aArity (compileTermC aBody)
129134 TALit {.. } -> fail " literal patterns not supported"
130135 TAGuard {.. } -> fail " case guards not supported"
0 commit comments