@@ -11,6 +11,7 @@ import Idris.Imports
1111import Idris.ElabTerm
1212import Idris.Coverage
1313import Idris.DataOpts
14+import Idris.Providers
1415import Paths_idris
1516
1617import Core.TT
@@ -38,6 +39,7 @@ checkDef fc ns = do ctxt <- getContext
3839 mapM (\(n, t) -> do (t', _) <- recheckC fc [] t
3940 return (n, t')) ns
4041
42+-- | Elaborate a top-level type declaration - for example, "foo : Int -> Int".
4143elabType :: ElabInfo -> SyntaxInfo -> String ->
4244 FC -> FnOpts -> Name -> PTerm -> Idris ()
4345elabType info syn doc fc opts n ty' = {- let ty' = piBind (params info) ty_in
@@ -185,6 +187,23 @@ elabData info syn doc fc codata (PDatadecl n t_in dcons)
185187 = (mn, False) : updateParamsA ns args (p : all)
186188 updateParamsA ps args all = ps
187189
190+-- | Elaborate a type provider
191+elabProvider :: ElabInfo -> SyntaxInfo -> FC -> Name -> PTerm -> PTerm -> Idris ()
192+elabProvider info syn fc n ty tm
193+ = do let expected = providerTy fc ty
194+ logLvl 1 $ "** Providing " ++
195+ show n ++ " : " ++ show expected ++
196+ " as " ++ show tm
197+ i <- getIState
198+ (e', et) <- elabVal toplevel False tm
199+ ctxt <- getContext
200+ let e'' = normaliseAll ctxt [] e'
201+ let et' = normaliseAll ctxt [] et
202+ elabType info syn "" fc [] n ty
203+ elabClauses info fc [] n [PClause fc n (PRef fc $ n) [] (unProv fc tm) []]
204+ logLvl 1 $ "** Elaborated: " ++ show e' ++ " :as: " ++ show et
205+ logLvl 1 $ "** Evaluated: " ++ show e'' ++ " :as: " ++ show et'
206+
188207elabRecord :: ElabInfo -> SyntaxInfo -> String -> FC -> Name ->
189208 PTerm -> String -> Name -> PTerm -> Idris ()
190209elabRecord info syn doc fc tyn ty cdoc cn cty
@@ -329,6 +348,8 @@ elabCon info syn tn codata (doc, n, t_in, fc)
329348 mkLazy (PPi pl n ty sc) = PPi (pl { plazy = True }) n ty (mkLazy sc)
330349 mkLazy t = t
331350
351+-- | Elaborate a collection of left-hand and right-hand pairs - that is, a
352+-- top-level definition.
332353elabClauses :: ElabInfo -> FC -> FnOpts -> Name -> [PClause] -> Idris ()
333354elabClauses info fc opts n_in cs = let n = liftname info n_in in
334355 do ctxt <- getContext
@@ -1263,6 +1284,10 @@ elabDecl' _ info (PDSL n dsl)
12631284 addIBC (IBCDSL n)
12641285elabDecl' what info (PDirective i)
12651286 | what /= EDefns = i
1287+elabDecl' what info (PProvider syn fc n tp tm)
1288+ | what /= EDefns
1289+ = do iLOG $ "Elaborating type provider " ++ show n
1290+ elabProvider info syn fc n tp tm
12661291elabDecl' _ _ _ = return () -- skipped this time
12671292
12681293elabCaseBlock info d@(PClauses f o n ps)