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)
102 | Declare : List Decl -> Elab ()
105 | ReadFile : LookupDir -> (path : String) -> Elab $
Maybe String
107 | WriteFile : LookupDir -> (path : String) -> (contents : String) -> Elab ()
109 | IdrisDir : LookupDir -> Elab String
116 | Applicative Elab where
121 | Alternative Elab where
122 | empty = Fail EmptyFC ""
134 | interface Monad m => Elaboration m where
137 | failAt : FC -> String -> m a
140 | warnAt : FC -> String -> m ()
144 | try : Elab a -> Elab a -> m a
147 | logMsg : String -> Nat -> String -> m ()
150 | logTerm : String -> Nat -> String -> TTImp -> m ()
153 | logSugaredTerm : String -> Nat -> String -> TTImp -> m ()
156 | resugarTerm : (maxLineWidth : Maybe Nat) -> TTImp -> m String
160 | check : TTImp -> m expected
163 | quote : (0 _ : val) -> m TTImp
166 | lambda : (0 x : Type) ->
167 | {0 ty : x -> Type} ->
168 | ((val : x) -> Elab (ty val)) -> m ((val : x) -> (ty val))
175 | goal : m (Maybe TTImp)
178 | localVars : m (List Name)
181 | genSym : String -> m Name
184 | inCurrentNS : Name -> m Name
187 | getType : Name -> m (List (Name, TTImp))
190 | getInfo : Name -> m (List (Name, NameInfo))
193 | getVis : Name -> m (List (Name, Visibility))
196 | getLocalType : Name -> m TTImp
199 | getCons : Name -> m (List Name)
202 | getReferredFns : Name -> m (List Name)
205 | getCurrentFn : m (SnocList Name)
211 | declare : List Decl -> m ()
214 | readFile : LookupDir -> (path : String) -> m $
Maybe String
217 | writeFile : LookupDir -> (path : String) -> (contents : String) -> m ()
220 | idrisDir : LookupDir -> m String
224 | fail : Elaboration m => String -> m a
225 | fail = failAt EmptyFC
229 | warn : Elaboration m => String -> m ()
230 | warn = warnAt EmptyFC
234 | logGoal : Elaboration m => String -> Nat -> String -> m ()
235 | logGoal str n msg = whenJust !goal $
logTerm str n msg
238 | Elaboration Elab where
244 | logSugaredTerm = LogSugaredTerm
245 | resugarTerm = ResugarTerm
250 | localVars = LocalVars
252 | inCurrentNS = InCurrentNS
256 | getLocalType = GetLocalType
258 | getReferredFns = GetReferredFns
259 | getCurrentFn = GetCurrentFn
262 | readFile = ReadFile
263 | writeFile = WriteFile
264 | idrisDir = IdrisDir
267 | Elaboration m => MonadTrans t => Monad (t m) => Elaboration (t m) where
268 | failAt = lift .: failAt
269 | warnAt = lift .: warnAt
271 | logMsg s = lift .: logMsg s
272 | logTerm s n = lift .: logTerm s n
273 | logSugaredTerm s n = lift .: logSugaredTerm s n
274 | resugarTerm = lift .: resugarTerm
275 | check = lift . check
276 | quote v = lift $
quote v
277 | lambda x = lift . lambda x
279 | localVars = lift localVars
280 | genSym = lift . genSym
281 | inCurrentNS = lift . inCurrentNS
282 | getType = lift . getType
283 | getInfo = lift . getInfo
284 | getVis = lift . getVis
285 | getLocalType = lift . getLocalType
286 | getCons = lift . getCons
287 | getReferredFns = lift . getReferredFns
288 | getCurrentFn = lift getCurrentFn
290 | declare = lift . declare
291 | readFile = lift .: readFile
292 | writeFile d = lift .: writeFile d
293 | idrisDir = lift . idrisDir
297 | catch : Elaboration m => Elab a -> m (Maybe a)
298 | catch elab = try (Just <$> elab) (pure Nothing)
303 | search : Elaboration m => (0 ty : Type) -> m (Maybe ty)
304 | search ty = catch $
check {expected = ty} `(%search)