0 | module Language.Reflection
2 | import public Language.Reflection.TT
3 | import public Language.Reflection.TTImp
5 | import public Control.Monad.Trans
34 | data Elab : Type -> Type where
36 | Map : (a -> b) -> Elab a -> Elab b
37 | Ap : Elab (a -> b) -> Elab a -> Elab b
38 | Bind : Elab a -> (a -> Elab b) -> Elab b
39 | Fail : FC -> String -> Elab a
40 | Warn : FC -> String -> Elab ()
42 | Try : Elab a -> Elab a -> Elab a
48 | LogMsg : String -> Nat -> String -> Elab ()
54 | LogTerm : String -> Nat -> String -> TTImp -> Elab ()
60 | LogSugaredTerm : String -> Nat -> String -> TTImp -> Elab ()
62 | ResugarTerm : (maxLineWidth : Maybe Nat) -> TTImp -> Elab String
65 | Check : TTImp -> Elab expected
68 | GetDecEqConPairs : a -> Elab (List Nat, List (String, String))
71 | Quote : (0 _ : val) -> Elab TTImp
74 | Lambda : (0 x : Type) ->
75 | {0 ty : x -> Type} ->
76 | ((val : x) -> Elab (ty val)) -> Elab ((val : x) -> (ty val))
80 | Goal : Elab (Maybe TTImp)
82 | LocalVars : Elab (List Name)
84 | GenSym : String -> Elab Name
86 | InCurrentNS : Name -> Elab Name
90 | GetType : Name -> Elab (List (Name, TTImp))
92 | GetInfo : Name -> Elab (List (Name, NameInfo))
94 | GetVis : Name -> Elab (List (Name, Visibility))
96 | GetLocalType : Name -> Elab TTImp
98 | GetCons : Name -> Elab (List Name)
100 | GetReferredFns : Name -> Elab (List Name)
102 | GetCurrentFn : Elab (SnocList Name)
106 | Declare : List Decl -> Elab ()
108 | ReadFile : LookupDir -> (path : String) -> Elab $
Maybe String
110 | WriteFile : LookupDir -> (path : String) -> (contents : String) -> Elab ()
112 | IdrisDir : LookupDir -> Elab String
119 | Applicative Elab where
124 | Alternative Elab where
125 | empty = Fail EmptyFC ""
137 | interface Monad m => Elaboration m where
140 | failAt : FC -> String -> m a
143 | warnAt : FC -> String -> m ()
147 | try : Elab a -> Elab a -> m a
150 | logMsg : String -> Nat -> String -> m ()
153 | logTerm : String -> Nat -> String -> TTImp -> m ()
156 | logSugaredTerm : String -> Nat -> String -> TTImp -> m ()
159 | resugarTerm : (maxLineWidth : Maybe Nat) -> TTImp -> m String
163 | check : TTImp -> m expected
168 | getDecEqConPairs : a -> m (List Nat, List (String, String))
170 | quote : (0 _ : val) -> m TTImp
173 | lambda : (0 x : Type) ->
174 | {0 ty : x -> Type} ->
175 | ((val : x) -> Elab (ty val)) -> m ((val : x) -> (ty val))
182 | goal : m (Maybe TTImp)
185 | localVars : m (List Name)
188 | genSym : String -> m Name
191 | inCurrentNS : Name -> m Name
194 | getType : Name -> m (List (Name, TTImp))
197 | getInfo : Name -> m (List (Name, NameInfo))
200 | getVis : Name -> m (List (Name, Visibility))
203 | getLocalType : Name -> m TTImp
206 | getCons : Name -> m (List Name)
209 | getReferredFns : Name -> m (List Name)
212 | getCurrentFn : m (SnocList Name)
218 | declare : List Decl -> m ()
221 | readFile : LookupDir -> (path : String) -> m $
Maybe String
224 | writeFile : LookupDir -> (path : String) -> (contents : String) -> m ()
227 | idrisDir : LookupDir -> m String
231 | fail : Elaboration m => String -> m a
232 | fail = failAt EmptyFC
236 | warn : Elaboration m => String -> m ()
237 | warn = warnAt EmptyFC
241 | logGoal : Elaboration m => String -> Nat -> String -> m ()
242 | logGoal str n msg = whenJust !goal $
logTerm str n msg
245 | Elaboration Elab where
251 | logSugaredTerm = LogSugaredTerm
252 | resugarTerm = ResugarTerm
254 | getDecEqConPairs = GetDecEqConPairs
258 | localVars = LocalVars
260 | inCurrentNS = InCurrentNS
264 | getLocalType = GetLocalType
266 | getReferredFns = GetReferredFns
267 | getCurrentFn = GetCurrentFn
270 | readFile = ReadFile
271 | writeFile = WriteFile
272 | idrisDir = IdrisDir
275 | Elaboration m => MonadTrans t => Monad (t m) => Elaboration (t m) where
276 | failAt = lift .: failAt
277 | warnAt = lift .: warnAt
279 | logMsg s = lift .: logMsg s
280 | logTerm s n = lift .: logTerm s n
281 | logSugaredTerm s n = lift .: logSugaredTerm s n
282 | resugarTerm = lift .: resugarTerm
283 | check = lift . check
284 | getDecEqConPairs = lift . getDecEqConPairs
285 | quote v = lift $
quote v
286 | lambda x = lift . lambda x
288 | localVars = lift localVars
289 | genSym = lift . genSym
290 | inCurrentNS = lift . inCurrentNS
291 | getType = lift . getType
292 | getInfo = lift . getInfo
293 | getVis = lift . getVis
294 | getLocalType = lift . getLocalType
295 | getCons = lift . getCons
296 | getReferredFns = lift . getReferredFns
297 | getCurrentFn = lift getCurrentFn
299 | declare = lift . declare
300 | readFile = lift .: readFile
301 | writeFile d = lift .: writeFile d
302 | idrisDir = lift . idrisDir
306 | catch : Elaboration m => Elab a -> m (Maybe a)
307 | catch elab = try (Just <$> elab) (pure Nothing)
312 | search : Elaboration m => (0 ty : Type) -> m (Maybe ty)
313 | search ty = catch $
check {expected = ty} `(%search)
316 | isPublic : Elaboration m => Name -> m Bool
317 | isPublic n = pure $
case !(getVis n) of
318 | [(_, Public)] => True