@@ -11,6 +11,7 @@ import Idris.Imports
11import Idris.ElabTerm
11import Idris.ElabTerm
12import Idris.Coverage
12import Idris.Coverage
13import Idris.DataOpts
13import Idris.DataOpts
14+import Idris.Providers
14import Paths_idris
15import Paths_idris
16import Core.TT
17import Core.TT
@@ -38,6 +39,7 @@ checkDef fc ns = do ctxt <- getContext
38 mapM (\(n, t) -> do (t', _) <- recheckC fc [] t
39 mapM (\(n, t) -> do (t', _) <- recheckC fc [] t
39 return (n, t')) ns
40 return (n, t')) ns
42+-- | Elaborate a top-level type declaration - for example, "foo : Int -> Int".
41elabType :: ElabInfo -> SyntaxInfo -> String ->
43elabType :: ElabInfo -> SyntaxInfo -> String ->
42 FC -> FnOpts -> Name -> PTerm -> Idris ()
44 FC -> FnOpts -> Name -> PTerm -> Idris ()
43elabType info syn doc fc opts n ty' = {- let ty' = piBind (params info) ty_in
45elabType 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)
185 = (mn, False) : updateParamsA ns args (p : all)
187 = (mn, False) : updateParamsA ns args (p : all)
186 updateParamsA ps args all = ps
188 updateParamsA ps args all = ps
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 ++
198+ (e', et) <- elabVal toplevel False tm
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'
188elabRecord :: ElabInfo -> SyntaxInfo -> String -> FC -> Name ->
207elabRecord :: ElabInfo -> SyntaxInfo -> String -> FC -> Name ->
189 PTerm -> String -> Name -> PTerm -> Idris ()
208 PTerm -> String -> Name -> PTerm -> Idris ()
190elabRecord info syn doc fc tyn ty cdoc cn cty
209elabRecord info syn doc fc tyn ty cdoc cn cty
@@ -329,6 +348,8 @@ elabCon info syn tn codata (doc, n, t_in, fc)
329 mkLazy (PPi pl n ty sc) = PPi (pl { plazy = True }) n ty (mkLazy sc)
348 mkLazy (PPi pl n ty sc) = PPi (pl { plazy = True }) n ty (mkLazy sc)
330 mkLazy t = t
349 mkLazy t = t
351+-- | Elaborate a collection of left-hand and right-hand pairs - that is, a
352+-- top-level definition.
332elabClauses :: ElabInfo -> FC -> FnOpts -> Name -> [PClause] -> Idris ()
353elabClauses :: ElabInfo -> FC -> FnOpts -> Name -> [PClause] -> Idris ()
333elabClauses info fc opts n_in cs = let n = liftname info n_in in
354elabClauses info fc opts n_in cs = let n = liftname info n_in in
334 do ctxt <- getContext
355 do ctxt <- getContext
@@ -1263,6 +1284,10 @@ elabDecl' _ info (PDSL n dsl)
1263 addIBC (IBCDSL n)
1284 addIBC (IBCDSL n)
1264elabDecl' what info (PDirective i)
1285elabDecl' what info (PDirective i)
1265 | what /= EDefns = i
1286 | what /= EDefns = i
1287+elabDecl' what info (PProvider syn fc n tp tm)
1289+ = do iLOG $ "Elaborating type provider " ++ show n
1290+ elabProvider info syn fc n tp tm
1266elabDecl' _ _ _ = return () -- skipped this time
1291elabDecl' _ _ _ = return () -- skipped this time
1268elabCaseBlock info d@(PClauses f o n ps)
1293elabCaseBlock info d@(PClauses f o n ps)