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
67 | Quote : (0 _ : val) -> Elab TTImp
70 | Lambda : (0 x : Type) ->
71 | {0 ty : x -> Type} ->
72 | ((val : x) -> Elab (ty val)) -> Elab ((val : x) -> (ty val))
76 | Goal : Elab (Maybe TTImp)
78 | LocalVars : Elab (List Name)
80 | GenSym : String -> Elab Name
82 | InCurrentNS : Name -> Elab Name
86 | GetType : Name -> Elab (List (Name, TTImp))
88 | GetInfo : Name -> Elab (List (Name, NameInfo))
90 | GetVis : Name -> Elab (List (Name, Visibility))
92 | GetLocalType : Name -> Elab TTImp
94 | GetCons : Name -> Elab (List Name)
96 | GetReferredFns : Name -> Elab (List Name)
98 | GetCurrentFn : Elab (SnocList Name)
100 | Declare : List Decl -> Elab ()
103 | ReadFile : LookupDir -> (path : String) -> Elab $
Maybe String
105 | WriteFile : LookupDir -> (path : String) -> (contents : String) -> Elab ()
107 | IdrisDir : LookupDir -> Elab String
114 | Applicative Elab where
119 | Alternative Elab where
120 | empty = Fail EmptyFC ""
132 | interface Monad m => Elaboration m where
135 | failAt : FC -> String -> m a
138 | warnAt : FC -> String -> m ()
142 | try : Elab a -> Elab a -> m a
145 | logMsg : String -> Nat -> String -> m ()
148 | logTerm : String -> Nat -> String -> TTImp -> m ()
151 | logSugaredTerm : String -> Nat -> String -> TTImp -> m ()
154 | resugarTerm : (maxLineWidth : Maybe Nat) -> TTImp -> m String
158 | check : TTImp -> m expected
161 | quote : (0 _ : val) -> m TTImp
164 | lambda : (0 x : Type) ->
165 | {0 ty : x -> Type} ->
166 | ((val : x) -> Elab (ty val)) -> m ((val : x) -> (ty val))
173 | goal : m (Maybe TTImp)
176 | localVars : m (List Name)
179 | genSym : String -> m Name
182 | inCurrentNS : Name -> m Name
185 | getType : Name -> m (List (Name, TTImp))
188 | getInfo : Name -> m (List (Name, NameInfo))
191 | getVis : Name -> m (List (Name, Visibility))
194 | getLocalType : Name -> m TTImp
197 | getCons : Name -> m (List Name)
200 | getReferredFns : Name -> m (List Name)
203 | getCurrentFn : m (SnocList Name)
206 | declare : List Decl -> m ()
209 | readFile : LookupDir -> (path : String) -> m $
Maybe String
212 | writeFile : LookupDir -> (path : String) -> (contents : String) -> m ()
215 | idrisDir : LookupDir -> m String
219 | fail : Elaboration m => String -> m a
220 | fail = failAt EmptyFC
224 | warn : Elaboration m => String -> m ()
225 | warn = warnAt EmptyFC
229 | logGoal : Elaboration m => String -> Nat -> String -> m ()
230 | logGoal str n msg = whenJust !goal $
logTerm str n msg
233 | Elaboration Elab where
239 | logSugaredTerm = LogSugaredTerm
240 | resugarTerm = ResugarTerm
245 | localVars = LocalVars
247 | inCurrentNS = InCurrentNS
251 | getLocalType = GetLocalType
253 | getReferredFns = GetReferredFns
254 | getCurrentFn = GetCurrentFn
256 | readFile = ReadFile
257 | writeFile = WriteFile
258 | idrisDir = IdrisDir
261 | Elaboration m => MonadTrans t => Monad (t m) => Elaboration (t m) where
262 | failAt = lift .: failAt
263 | warnAt = lift .: warnAt
265 | logMsg s = lift .: logMsg s
266 | logTerm s n = lift .: logTerm s n
267 | logSugaredTerm s n = lift .: logSugaredTerm s n
268 | resugarTerm = lift .: resugarTerm
269 | check = lift . check
270 | quote v = lift $
quote v
271 | lambda x = lift . lambda x
273 | localVars = lift localVars
274 | genSym = lift . genSym
275 | inCurrentNS = lift . inCurrentNS
276 | getType = lift . getType
277 | getInfo = lift . getInfo
278 | getVis = lift . getVis
279 | getLocalType = lift . getLocalType
280 | getCons = lift . getCons
281 | getReferredFns = lift . getReferredFns
282 | getCurrentFn = lift getCurrentFn
283 | declare = lift . declare
284 | readFile = lift .: readFile
285 | writeFile d = lift .: writeFile d
286 | idrisDir = lift . idrisDir
290 | catch : Elaboration m => Elab a -> m (Maybe a)
291 | catch elab = try (Just <$> elab) (pure Nothing)
296 | search : Elaboration m => (0 ty : Type) -> m (Maybe ty)
297 | search ty = catch $
check {expected = ty} `(%search)