@@ -56,11 +56,13 @@ getName = do i <- get;
56 put (i { idris_name = idx + 1 })
56 put (i { idris_name = idx + 1 })
57 return idx
57 return idx
59−checkUndefined :: Name -> Idris ()
59+checkUndefined :: FC -> Name -> Idris ()
60−checkUndefined n = do i <- getContext
60+checkUndefined fc n
61− case lookupCtxt n i of
62+ case lookupCtxt n i of
63+ Just _ -> fail $ show fc ++ ":" ++
62− Just _ -> fail $ show n ++ " already defined"
64+ show n ++ " already defined"
63− _ -> return ()
65+ _ -> return ()
65setContext :: Context -> Idris ()
67setContext :: Context -> Idris ()
66setContext ctxt = do i <- get; put (i { tt_ctxt = ctxt } )
68setContext ctxt = do i <- get; put (i { tt_ctxt = ctxt } )
@@ -130,12 +132,12 @@ instance Ord FixDecl where
131data Plicity = Imp | Exp deriving Show
133data Plicity = Imp | Exp deriving Show
133−data PDecl' t = PFix Fixity [String] -- fixity declaration
135+data PDecl' t = PFix FC Fixity [String] -- fixity declaration
134− | PTy Name t -- type declaration
136+ | PTy FC Name t -- type declaration
135− | PClauses Name [PClause' t] -- pattern clause
137+ | PClauses FC Name [PClause' t] -- pattern clause
136− | PData (PData' t) -- data declaration
138+ | PData FC (PData' t) -- data declaration
137− | PParams [(Name, PTerm)] [PDecl' t] -- params block
139+ | PParams FC [(Name, PTerm)] [PDecl' t] -- params block
138− | PSyntax Syntax
140+ | PSyntax FC Syntax
139 deriving Functor
141 deriving Functor
141data PClause' t = PClause Name t t [PDecl]
143data PClause' t = PClause Name t t [PDecl]
@@ -143,7 +145,7 @@ data PClause' t = PClause Name t t [PDecl]
144data PData' t = PDatadecl { d_name :: Name,
146data PData' t = PDatadecl { d_name :: Name,
145 d_tcon :: t,
147 d_tcon :: t,
146− d_cons :: [(Name, t)] }
148+ d_cons :: [(Name, t, FC)] }
147 deriving Functor
149 deriving Functor
149-- Handy to get a free function for applying PTerm -> PTerm functions
151-- Handy to get a free function for applying PTerm -> PTerm functions
@@ -156,11 +158,12 @@ type PClause = PClause' PTerm
156-- get all the names declared in a decl
158-- get all the names declared in a decl
158declared :: PDecl -> [Name]
160declared :: PDecl -> [Name]
159−declared (PFix _ _) = []
161+declared (PFix _ _ _) = []
160−declared (PTy n t) = [n]
162+declared (PTy _ n t) = [n]
161−declared (PClauses n _) = [] -- not a declaration
163+declared (PClauses _ n _) = [] -- not a declaration
162−declared (PData (PDatadecl n _ ts)) = n : map fst ts
164+declared (PData _ (PDatadecl n _ ts)) = n : map fstt ts
165+ where fstt (a, _, _) = a
163−declared (PParams _ ds) = concatMap declared ds
166+declared (PParams _ _ ds) = concatMap declared ds
164-- declared (PImport _) = []
167-- declared (PImport _) = []
166-- High level language terms
169-- High level language terms
@@ -222,10 +225,10 @@ instance Show PTerm where
222 show tm = showImp False tm
225 show tm = showImp False tm
224instance Show PDecl where
227instance Show PDecl where
225− show (PFix f ops) = show f ++ " " ++ showSep ", " ops
228+ show (PFix _ f ops) = show f ++ " " ++ showSep ", " ops
226− show (PTy n ty) = show n ++ " : " ++ show ty
229+ show (PTy _ n ty) = show n ++ " : " ++ show ty
227− show (PClauses n c) = showSep "\n" (map show c)
230+ show (PClauses _ n c) = showSep "\n" (map show c)
228− show (PData d) = show d
231+ show (PData _ d) = show d
230instance Show PClause where
233instance Show PClause where
231 show c = showCImp False c
234 show c = showCImp False c
@@ -240,7 +243,7 @@ showDImp :: Bool -> PData -> String
240showDImp impl (PDatadecl n ty cons)
243showDImp impl (PDatadecl n ty cons)
241 = "data " ++ show n ++ " : " ++ showImp impl ty ++ " where\n\t"
244 = "data " ++ show n ++ " : " ++ showImp impl ty ++ " where\n\t"
242 ++ showSep "\n\t| "
245 ++ showSep "\n\t| "
243− (map (\ (n, t) -> show n ++ " : " ++ showImp impl t) cons)
246+ (map (\ (n, t, _) -> show n ++ " : " ++ showImp impl t) cons)
245getImps :: [PArg] -> [(Name, PTerm)]
248getImps :: [PArg] -> [(Name, PTerm)]
246getImps [] = []
249getImps [] = []
@@ -323,13 +326,15 @@ namesIn ist tm = nub $ ni [] tm
324-- For inferring types of things
327-- For inferring types of things
326inferTy = MN 0 "__Infer"
331inferTy = MN 0 "__Infer"
327inferCon = MN 0 "__infer"
332inferCon = MN 0 "__infer"
328inferDecl = PDatadecl inferTy
333inferDecl = PDatadecl inferTy
330 [(inferCon, PPi Imp (MN 0 "A") PSet (
335 [(inferCon, PPi Imp (MN 0 "A") PSet (
331 PPi Exp (MN 0 "a") (PRef (MN 0 "A"))
336 PPi Exp (MN 0 "a") (PRef (MN 0 "A"))
332− (PRef inferTy)))]
337+ (PRef inferTy)), bi)]
334infTerm t = PApp (PRef inferCon) [PImp (MN 0 "A") Placeholder, PExp t]
339infTerm t = PApp (PRef inferCon) [PImp (MN 0 "A") Placeholder, PExp t]
335infP = P (TCon 0) inferTy (Set 0)
340infP = P (TCon 0) inferTy (Set 0)
@@ -344,10 +349,11 @@ getInferType (App (App _ ty) _) = ty
345-- Handy primitives: Unit, False, Pair, MkPair, mkForeign
350-- Handy primitives: Unit, False, Pair, MkPair, mkForeign
347unitTy = MN 0 "__Unit"
353unitTy = MN 0 "__Unit"
348unitCon = MN 0 "__II"
354unitCon = MN 0 "__II"
349unitDecl = PDatadecl unitTy PSet
355unitDecl = PDatadecl unitTy PSet
350− [(unitCon, PRef unitTy)]
356+ [(unitCon, PRef unitTy, bi)]
352falseTy = MN 0 "__False"
358falseTy = MN 0 "__False"
353falseDecl = PDatadecl falseTy PSet []
359falseDecl = PDatadecl falseTy PSet []
@@ -360,7 +366,7 @@ pairDecl = PDatadecl pairTy (piBind [(n "A", PSet), (n "B", PSet)] PSet)
360 PPi Exp (n "a") (PRef (n "A")) (
366 PPi Exp (n "a") (PRef (n "A")) (
361 PPi Exp (n "c") (PRef (n "B"))
367 PPi Exp (n "c") (PRef (n "B"))
362 (PApp (PRef pairTy) [PExp (PRef (n "A")),
368 (PApp (PRef pairTy) [PExp (PRef (n "A")),
363− PExp (PRef (n "B"))])))))]
369+ PExp (PRef (n "B"))])))), bi)]
364 where n a = MN 0 a
370 where n a = MN 0 a
366piBind :: [(Name, PTerm)] -> PTerm -> PTerm
372piBind :: [(Name, PTerm)] -> PTerm -> PTerm
@@ -467,11 +473,11 @@ dumpDecls :: [PDecl] -> String
467dumpDecls [] = ""
473dumpDecls [] = ""
468dumpDecls (d:ds) = dumpDecl d ++ "\n" ++ dumpDecls ds
474dumpDecls (d:ds) = dumpDecl d ++ "\n" ++ dumpDecls ds
470−dumpDecl (PFix f ops) = show f ++ " " ++ showSep ", " ops
476+dumpDecl (PFix _ f ops) = show f ++ " " ++ showSep ", " ops
471−dumpDecl (PTy n t) = "tydecl " ++ show n ++ " : " ++ showImp True t
477+dumpDecl (PTy _ n t) = "tydecl " ++ show n ++ " : " ++ showImp True t
472−dumpDecl (PClauses n cs) = "pat\t" ++ showSep "\n\t" (map (showCImp True) cs)
478+dumpDecl (PClauses _ n cs) = "pat\t" ++ showSep "\n\t" (map (showCImp True) cs)
473−dumpDecl (PData d) = showDImp True d
479+dumpDecl (PData _ d) = showDImp True d
474−dumpDecl (PParams ns ps) = "params {" ++ show ns ++ "\n" ++ dumpDecls ps ++ "}\n"
480+dumpDecl (PParams _ ns ps) = "params {" ++ show ns ++ "\n" ++ dumpDecls ps ++ "}\n"
475−dumpDecl (PSyntax syn) = "syntax " ++ show syn
481+dumpDecl (PSyntax _ syn) = "syntax " ++ show syn
476-- dumpDecl (PImport i) = "import " ++ i
482-- dumpDecl (PImport i) = "import " ++ i