@@ -56,11 +56,13 @@ getName = do i <- get;
5656 put (i { idris_name = idx + 1 })
5757 return idx
5858
59−checkUndefined :: Name -> Idris ()
60−checkUndefined n = do i <- getContext
61− case lookupCtxt n i of
62− Just _ -> fail $ show n ++ " already defined"
63− _ -> return ()
59+checkUndefined :: FC -> Name -> Idris ()
60+checkUndefined fc n
61+ = do i <- getContext
62+ case lookupCtxt n i of
63+ Just _ -> fail $ show fc ++ ":" ++
64+ show n ++ " already defined"
65+ _ -> return ()
6466
6567setContext :: Context -> Idris ()
6668setContext ctxt = do i <- get; put (i { tt_ctxt = ctxt } )
@@ -130,12 +132,12 @@ instance Ord FixDecl where
130132
131133data Plicity = Imp | Exp deriving Show
132134
133−data PDecl' t = PFix Fixity [String] -- fixity declaration
134− | PTy Name t -- type declaration
135− | PClauses Name [PClause' t] -- pattern clause
136− | PData (PData' t) -- data declaration
137− | PParams [(Name, PTerm)] [PDecl' t] -- params block
138− | PSyntax Syntax
135+data PDecl' t = PFix FC Fixity [String] -- fixity declaration
136+ | PTy FC Name t -- type declaration
137+ | PClauses FC Name [PClause' t] -- pattern clause
138+ | PData FC (PData' t) -- data declaration
139+ | PParams FC [(Name, PTerm)] [PDecl' t] -- params block
140+ | PSyntax FC Syntax
139141 deriving Functor
140142
141143data PClause' t = PClause Name t t [PDecl]
@@ -143,7 +145,7 @@ data PClause' t = PClause Name t t [PDecl]
143145
144146data PData' t = PDatadecl { d_name :: Name,
145147 d_tcon :: t,
146− d_cons :: [(Name, t)] }
148+ d_cons :: [(Name, t, FC)] }
147149 deriving Functor
148150
149151-- Handy to get a free function for applying PTerm -> PTerm functions
@@ -156,11 +158,12 @@ type PClause = PClause' PTerm
156158-- get all the names declared in a decl
157159
158160declared :: PDecl -> [Name]
159−declared (PFix _ _) = []
160−declared (PTy n t) = [n]
161−declared (PClauses n _) = [] -- not a declaration
162−declared (PData (PDatadecl n _ ts)) = n : map fst ts
163−declared (PParams _ ds) = concatMap declared ds
161+declared (PFix _ _ _) = []
162+declared (PTy _ n t) = [n]
163+declared (PClauses _ n _) = [] -- not a declaration
164+declared (PData _ (PDatadecl n _ ts)) = n : map fstt ts
165+ where fstt (a, _, _) = a
166+declared (PParams _ _ ds) = concatMap declared ds
164167-- declared (PImport _) = []
165168
166169-- High level language terms
@@ -222,10 +225,10 @@ instance Show PTerm where
222225 show tm = showImp False tm
223226
224227instance Show PDecl where
225− show (PFix f ops) = show f ++ " " ++ showSep ", " ops
226− show (PTy n ty) = show n ++ " : " ++ show ty
227− show (PClauses n c) = showSep "\n" (map show c)
228− show (PData d) = show d
228+ show (PFix _ f ops) = show f ++ " " ++ showSep ", " ops
229+ show (PTy _ n ty) = show n ++ " : " ++ show ty
230+ show (PClauses _ n c) = showSep "\n" (map show c)
231+ show (PData _ d) = show d
229232
230233instance Show PClause where
231234 show c = showCImp False c
@@ -240,7 +243,7 @@ showDImp :: Bool -> PData -> String
240243showDImp impl (PDatadecl n ty cons)
241244 = "data " ++ show n ++ " : " ++ showImp impl ty ++ " where\n\t"
242245 ++ showSep "\n\t| "
243− (map (\ (n, t) -> show n ++ " : " ++ showImp impl t) cons)
246+ (map (\ (n, t, _) -> show n ++ " : " ++ showImp impl t) cons)
244247
245248getImps :: [PArg] -> [(Name, PTerm)]
246249getImps [] = []
@@ -323,13 +326,15 @@ namesIn ist tm = nub $ ni [] tm
323326
324327-- For inferring types of things
325328
329+bi = FC "builtin" 0
330+
326331inferTy = MN 0 "__Infer"
327332inferCon = MN 0 "__infer"
328333inferDecl = PDatadecl inferTy
329334 PSet
330335 [(inferCon, PPi Imp (MN 0 "A") PSet (
331336 PPi Exp (MN 0 "a") (PRef (MN 0 "A"))
332− (PRef inferTy)))]
337+ (PRef inferTy)), bi)]
333338
334339infTerm t = PApp (PRef inferCon) [PImp (MN 0 "A") Placeholder, PExp t]
335340infP = P (TCon 0) inferTy (Set 0)
@@ -344,10 +349,11 @@ getInferType (App (App _ ty) _) = ty
344349
345350-- Handy primitives: Unit, False, Pair, MkPair, mkForeign
346351
352+
347353unitTy = MN 0 "__Unit"
348354unitCon = MN 0 "__II"
349355unitDecl = PDatadecl unitTy PSet
350− [(unitCon, PRef unitTy)]
356+ [(unitCon, PRef unitTy, bi)]
351357
352358falseTy = MN 0 "__False"
353359falseDecl = PDatadecl falseTy PSet []
@@ -360,7 +366,7 @@ pairDecl = PDatadecl pairTy (piBind [(n "A", PSet), (n "B", PSet)] PSet)
360366 PPi Exp (n "a") (PRef (n "A")) (
361367 PPi Exp (n "c") (PRef (n "B"))
362368 (PApp (PRef pairTy) [PExp (PRef (n "A")),
363− PExp (PRef (n "B"))])))))]
369+ PExp (PRef (n "B"))])))), bi)]
364370 where n a = MN 0 a
365371
366372piBind :: [(Name, PTerm)] -> PTerm -> PTerm
@@ -467,11 +473,11 @@ dumpDecls :: [PDecl] -> String
467473dumpDecls [] = ""
468474dumpDecls (d:ds) = dumpDecl d ++ "\n" ++ dumpDecls ds
469475
470−dumpDecl (PFix f ops) = show f ++ " " ++ showSep ", " ops
471−dumpDecl (PTy n t) = "tydecl " ++ show n ++ " : " ++ showImp True t
472−dumpDecl (PClauses n cs) = "pat\t" ++ showSep "\n\t" (map (showCImp True) cs)
473−dumpDecl (PData d) = showDImp True d
474−dumpDecl (PParams ns ps) = "params {" ++ show ns ++ "\n" ++ dumpDecls ps ++ "}\n"
475−dumpDecl (PSyntax syn) = "syntax " ++ show syn
476+dumpDecl (PFix _ f ops) = show f ++ " " ++ showSep ", " ops
477+dumpDecl (PTy _ n t) = "tydecl " ++ show n ++ " : " ++ showImp True t
478+dumpDecl (PClauses _ n cs) = "pat\t" ++ showSep "\n\t" (map (showCImp True) cs)
479+dumpDecl (PData _ d) = showDImp True d
480+dumpDecl (PParams _ ns ps) = "params {" ++ show ns ++ "\n" ++ dumpDecls ps ++ "}\n"
481+dumpDecl (PSyntax _ syn) = "syntax " ++ show syn
476482-- dumpDecl (PImport i) = "import " ++ i
477483