@@ -5,6 +5,8 @@ module Idris.ElabDecls where
5import Idris.AbsSyntax
5import Idris.AbsSyntax
6import Idris.Error
6import Idris.Error
7import Idris.Delaborate
7import Idris.Delaborate
9import Core.TT
11import Core.TT
10import Core.Elaborate
12import Core.Elaborate
@@ -13,6 +15,7 @@ import Core.Typecheck
13import Core.CaseTree
15import Core.CaseTree
15import Control.Monad
17import Control.Monad
18+import Control.Monad.State
16import Debug.Trace
19import Debug.Trace
18-- Data to pass to recursively called elaborators; e.g. for where blocks,
21-- Data to pass to recursively called elaborators; e.g. for where blocks,
@@ -47,9 +50,9 @@ elabData info (PDatadecl n t dcons)
47elabCon :: ElabInfo -> (Name, PTerm) -> Idris (Name, Type)
50elabCon :: ElabInfo -> (Name, PTerm) -> Idris (Name, Type)
48elabCon info (n, t)
51elabCon info (n, t)
49 = do ctxt <- getContext
52 = do ctxt <- getContext
50− iLOG $ "Constructor " ++ show n ++ " : " ++ showImp True t
53+ logLvl 2 $ "Constructor " ++ show n ++ " : " ++ showImp True t
51 (t', log) <- tclift $ elaborate ctxt n (Set 0) (build info False t)
54 (t', log) <- tclift $ elaborate ctxt n (Set 0) (build info False t)
52−-- iLOG $ "Rechecking " ++ show t'
55+-- logLvl 2 $ "Rechecking " ++ show t'
53 (cty, _) <- tclift $ recheck ctxt [] t'
56 (cty, _) <- tclift $ recheck ctxt [] t'
54 logLvl 2 $ "---> " ++ show n ++ " : " ++ show cty
57 logLvl 2 $ "---> " ++ show n ++ " : " ++ show cty
55 return (n, cty)
58 return (n, cty)
@@ -79,7 +82,7 @@ elabVal info tm
79 (build info True (infTerm tm))
82 (build info True (infTerm tm))
80 logLvl 3 ("Value: " ++ show tm')
83 logLvl 3 ("Value: " ++ show tm')
81 let vtm = getInferTerm tm'
84 let vtm = getInferTerm tm'
82− iLOG (show vtm)
85+ logLvl 2 (show vtm)
83 tclift $ recheck ctxt [] vtm
86 tclift $ recheck ctxt [] vtm
85elabClause :: ElabInfo -> PClause -> Idris (Term, Term)
88elabClause :: ElabInfo -> PClause -> Idris (Term, Term)
@@ -99,7 +102,7 @@ elabClause info (PClause fname lhs rhs whereblock)
99 let winfo = pinfo (pvars ist lhs_tm) whereblock windex
102 let winfo = pinfo (pvars ist lhs_tm) whereblock windex
100 mapM_ (elabDecl' winfo) whereblock
103 mapM_ (elabDecl' winfo) whereblock
101 -- Now build the RHS, using the type of the LHS as the goal.
104 -- Now build the RHS, using the type of the LHS as the goal.
102− iLOG (showImp True rhs)
105+ logLvl 2 (showImp True rhs)
103 ctxt <- getContext -- new context with where block added
106 ctxt <- getContext -- new context with where block added
104 (rhs', _) <- tclift $ elaborate ctxt (MN 0 "patRHS") clhsty
107 (rhs', _) <- tclift $ elaborate ctxt (MN 0 "patRHS") clhsty
105 (do pbinds lhs_tm
108 (do pbinds lhs_tm
@@ -133,18 +136,19 @@ elabClause info (PClause fname lhs rhs whereblock)
133 _ -> MN i (show n)) . l
136 _ -> MN i (show n)) . l
139+-- TODO: Also build a 'binary' version of each declaration for fast reloading
136elabDecl :: ElabInfo -> PDecl -> Idris ()
141elabDecl :: ElabInfo -> PDecl -> Idris ()
137elabDecl info d = idrisCatch (elabDecl' info d) (\e -> iputStrLn (report e))
142elabDecl info d = idrisCatch (elabDecl' info d) (\e -> iputStrLn (report e))
139elabDecl' info (PFix _ _) = return () -- nothing to elaborate
144elabDecl' info (PFix _ _) = return () -- nothing to elaborate
140elabDecl' info (PTy n ty) = do iLOG $ "Elaborating type decl " ++ show n
145elabDecl' info (PTy n ty) = do iLOG $ "Elaborating type decl " ++ show n
141 elabType info n ty
146 elabType info n ty
142−elabDecl' info (PData d) = do iLOG $ "Elaborating " ++ show d
147+elabDecl' info (PData d) = do iLOG $ "Elaborating " ++ show (d_name d)
143 elabData info d
148 elabData info d
144elabDecl' info d@(PClauses n ps) = do iLOG $ "Elaborating clause " ++ show n
149elabDecl' info d@(PClauses n ps) = do iLOG $ "Elaborating clause " ++ show n
145 elabClauses info n ps
150 elabClauses info n ps
146−elabDecl' info (PParams ns ps) = do iLOG $ "Params block " ++ show ns
147− mapM_ (elabDecl' pinfo) ps
151+elabDecl' info (PParams ns ps) = mapM_ (elabDecl' pinfo) ps
149 pinfo = let ds = concatMap declared ps
153 pinfo = let ds = concatMap declared ps
150 newps = params info ++ ns
154 newps = params info ++ ns
@@ -152,6 +156,8 @@ elabDecl' info (PParams ns ps) = do iLOG $ "Params block " ++ show ns
152 newb = addAlist dsParams (inblock info) in
156 newb = addAlist dsParams (inblock info) in
153 info { params = newps,
157 info { params = newps,
154 inblock = newb }
158 inblock = newb }
159+-- elabDecl' info (PImport i) = loadModule i
156-- Using the elaborator, convert a term in raw syntax to a fully
162-- Using the elaborator, convert a term in raw syntax to a fully
157-- elaborated, typechecked term.
163-- elaborated, typechecked term.