@@ -5,8 +5,9 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
8−{-# LANGUAGE DeriveFunctor, FlexibleInstances, MultiParamTypeClasses,
9+{-# LANGUAGE DeriveFunctor #-}
9− PatternGuards, TypeSynonymInstances #-}
10+{-# LANGUAGE PatternGuards #-}
11module Idris.AbsSyntax(
12module Idris.AbsSyntax(
12 module Idris.AbsSyntax
13 module Idris.AbsSyntax
@@ -15,37 +16,32 @@ module Idris.AbsSyntax(
16import Idris.AbsSyntaxTree
17import Idris.AbsSyntaxTree
17import Idris.Colours
18import Idris.Colours
18−import Idris.Core.Elaborate hiding (Tactic(..))
19import Idris.Core.Evaluate
19import Idris.Core.Evaluate
20import Idris.Core.TT
20import Idris.Core.TT
21−import Idris.Core.Typecheck
22import Idris.Docstrings
21import Idris.Docstrings
23import Idris.IdeMode hiding (Opt(..))
22import Idris.IdeMode hiding (Opt(..))
24import IRTS.CodegenCommon
23import IRTS.CodegenCommon
26−import Util.DynamicLinker
25+import System.Directory (canonicalizePath, doesFileExist)
28−import Util.ScreenSize
29−import Util.System
26+import System.IO
31import Control.Applicative
28import Control.Applicative
32−import Control.Monad (liftM3)
33import Control.Monad.State
29import Control.Monad.State
34−import Data.Char
30+import Prelude hiding (Applicative, Foldable, Traversable, (<$>))
35import Data.Either
32import Data.Either
36−import Data.Generics.Uniplate.Data (descend, descendM)
37import Data.List hiding (insert, union)
33import Data.List hiding (insert, union)
38import qualified Data.Map as M
34import qualified Data.Map as M
39import Data.Maybe
35import Data.Maybe
40import qualified Data.Set as S
36import qualified Data.Set as S
41import qualified Data.Text as T
37import qualified Data.Text as T
42−import Data.Word (Word)
44−import Network (PortID(PortNumber))
45−import System.Console.Haskeline
46−import System.Directory (canonicalizePath, doesFileExist)
48−import System.IO.Error (ioeGetErrorString, isUserError, tryIOError)
38+import System.IO.Error (tryIOError)
40+import Data.Generics.Uniplate.Data (descend, descendM)
42+import Util.DynamicLinker
50getContext :: Idris Context
46getContext :: Idris Context
51getContext = do i <- getIState; return (tt_ctxt i)
47getContext = do i <- getIState; return (tt_ctxt i)
@@ -91,9 +87,9 @@ addDyLib libs = do i <- getIState
91 Just x -> do putIState $ i { idris_dynamic_libs = x:ls }
87 Just x -> do putIState $ i { idris_dynamic_libs = x:ls }
92 return (Left x)
88 return (Left x)
93 where findDyLib :: [DynamicLib] -> String -> Maybe DynamicLib
89 where findDyLib :: [DynamicLib] -> String -> Maybe DynamicLib
94− findDyLib [] l = Nothing
90+ findDyLib [] _ = Nothing
95− findDyLib (lib:libs) l | l == lib_name lib = Just lib
91+ findDyLib (lib:libs') l | l == lib_name lib = Just lib
96− | otherwise = findDyLib libs l
92+ | otherwise = findDyLib libs' l
98getAutoImports :: Idris [FilePath]
94getAutoImports :: Idris [FilePath]
99getAutoImports = do i <- getIState
95getAutoImports = do i <- getIState
@@ -102,7 +98,6 @@ getAutoImports = do i <- getIState
102addAutoImport :: FilePath -> Idris ()
98addAutoImport :: FilePath -> Idris ()
103addAutoImport fp = do i <- getIState
99addAutoImport fp = do i <- getIState
104 let opts = idris_options i
100 let opts = idris_options i
105− let autoimps = opt_autoImport opts
106 put (i { idris_options = opts { opt_autoImport =
101 put (i { idris_options = opts { opt_autoImport =
107 fp : opt_autoImport opts } } )
102 fp : opt_autoImport opts } } )
@@ -250,7 +245,7 @@ getCoercionsTo i ty =
250 let cs = idris_coercions i
245 let cs = idris_coercions i
251 (fn,_) = unApply (getRetTy ty) in
246 (fn,_) = unApply (getRetTy ty) in
252 findCoercions fn cs
247 findCoercions fn cs
253− where findCoercions t [] = []
248+ where findCoercions _ [] = []
254 findCoercions t (n : ns) =
249 findCoercions t (n : ns) =
255 let ps = case lookupTy n (tt_ctxt i) of
250 let ps = case lookupTy n (tt_ctxt i) of
256 [ty'] -> case unApply (getRetTy (normalise (tt_ctxt i) [] ty')) of
251 [ty'] -> case unApply (getRetTy (normalise (tt_ctxt i) [] ty')) of
@@ -322,10 +317,10 @@ addTyInfConstraints fc ts = do logLvl 2 $ "TI missing: " ++ show ts
322 do let (fx, _) = unApply x
317 do let (fx, _) = unApply x
323 let (fy, _) = unApply y
318 let (fy, _) = unApply y
324 case (fx, fy) of
319 case (fx, fy) of
325− (P (TCon _ _) n _, P (TCon _ _) n' _) -> errWhen (n/=n)
320+ (P (TCon _ _) n _, P (TCon _ _) n' _) -> errWhen (n/=n) -- XXX: n' is unused. Should this be errWhen (n /= n')?
326 (P (TCon _ _) n _, Constant _) -> errWhen True
321 (P (TCon _ _) n _, Constant _) -> errWhen True
327 (Constant _, P (TCon _ _) n' _) -> errWhen True
322 (Constant _, P (TCon _ _) n' _) -> errWhen True
328− (P (DCon _ _ _) n _, P (DCon _ _ _) n' _) -> errWhen (n/=n)
323+ (P (DCon _ _ _) n _, P (DCon _ _ _) n' _) -> errWhen (n/=n) -- XXX: n' is unused. Should this be errWhen (n /= n')?
329 _ -> return ()
324 _ -> return ()
331 where errWhen True
326 where errWhen True
@@ -353,12 +348,6 @@ addFunctionErrorHandlers f arg hs =
353 -- will always be one of those two, thus no extra case
348 -- will always be one of those two, thus no extra case
354 putIState $ i { idris_function_errorhandlers = newHandlers }
349 putIState $ i { idris_function_errorhandlers = newHandlers }
356−getFunctionErrorHandlers :: Name -> Name -> Idris [Name]
357−getFunctionErrorHandlers f arg = do i <- getIState
358− return . maybe [] S.toList $
359− undefined --lookup arg =<< lookupCtxtExact f (idris_function_errorhandlers i)
362-- | Trace all the names in a call graph starting at the given name
351-- | Trace all the names in a call graph starting at the given name
363getAllNames :: Name -> Idris [Name]
352getAllNames :: Name -> Idris [Name]
364getAllNames n = do i <- getIState
353getAllNames n = do i <- getIState
@@ -414,7 +403,7 @@ addNameHint ty n
414 putIState $ i { idris_namehints = addDef ty' ns' (idris_namehints i) }
403 putIState $ i { idris_namehints = addDef ty' ns' (idris_namehints i) }
416getNameHints :: IState -> Name -> [Name]
405getNameHints :: IState -> Name -> [Name]
417−getNameHints i (UN arr) | arr == txt "->" = [sUN "f",sUN "g"]
406+getNameHints _ (UN arr) | arr == txt "->" = [sUN "f",sUN "g"]
418getNameHints i n =
407getNameHints i n =
419 case lookupCtxt n (idris_namehints i) of
408 case lookupCtxt n (idris_namehints i) of
420 [ns] -> ns
409 [ns] -> ns
@@ -430,7 +419,6 @@ getDeprecated n = do
430 i <- getIState
419 i <- getIState
431 return $ lookupCtxtExact n (idris_deprecated i)
420 return $ lookupCtxtExact n (idris_deprecated i)
434addFragile :: Name -> String -> Idris ()
422addFragile :: Name -> String -> Idris ()
435addFragile n reason = do
423addFragile n reason = do
436 i <- getIState
424 i <- getIState
@@ -442,15 +430,15 @@ getFragile n = do
442 return $ lookupCtxtExact n (idris_fragile i)
430 return $ lookupCtxtExact n (idris_fragile i)
444push_estack :: Name -> Bool -> Idris ()
432push_estack :: Name -> Bool -> Idris ()
445−push_estack n impl
433+push_estack n implementation
446 = do i <- getIState
434 = do i <- getIState
447− putIState (i { elab_stack = (n, impl) : elab_stack i })
435+ putIState (i { elab_stack = (n, implementation) : elab_stack i })
449pop_estack :: Idris ()
437pop_estack :: Idris ()
450pop_estack = do i <- getIState
438pop_estack = do i <- getIState
451 putIState (i { elab_stack = ptail (elab_stack i) })
439 putIState (i { elab_stack = ptail (elab_stack i) })
452 where ptail [] = []
440 where ptail [] = []
453− ptail (x : xs) = xs
441+ ptail (_ : xs) = xs
455-- | Add an interface implementation function.
443-- | Add an interface implementation function.
@@ -546,7 +534,7 @@ addIBC ibc@(IBCDef n)
546 when (notDef (ibc_write i)) $
534 when (notDef (ibc_write i)) $
547 putIState $ i { ibc_write = ibc : ibc_write i }
535 putIState $ i { ibc_write = ibc : ibc_write i }
548 where notDef [] = True
536 where notDef [] = True
549− notDef (IBCDef n': is) | n == n' = False
537+ notDef (IBCDef n': _) | n == n' = False
550 notDef (_ : is) = notDef is
538 notDef (_ : is) = notDef is
551addIBC ibc = do i <- getIState; putIState $ i { ibc_write = ibc : ibc_write i }
539addIBC ibc = do i <- getIState; putIState $ i { ibc_write = ibc : ibc_write i }
@@ -683,7 +671,7 @@ clearPTypes :: Idris ()
683clearPTypes = do i <- get
671clearPTypes = do i <- get
684 let ctxt = tt_ctxt i
672 let ctxt = tt_ctxt i
685 put (i { tt_ctxt = mapDefCtxt pErase ctxt })
673 put (i { tt_ctxt = mapDefCtxt pErase ctxt })
686− where pErase (CaseOp c t tys orig tot cds)
674+ where pErase (CaseOp c t tys orig _ cds)
687 = CaseOp c t tys orig [] (pErase' cds)
675 = CaseOp c t tys orig [] (pErase' cds)
688 pErase x = x
676 pErase x = x
689 pErase' (CaseDefs (cs, c) rs)
677 pErase' (CaseDefs (cs, c) rs)
@@ -699,7 +687,7 @@ checkUndefined fc n
699 _ -> return ()
687 _ -> return ()
701isUndefined :: FC -> Name -> Idris Bool
689isUndefined :: FC -> Name -> Idris Bool
702−isUndefined fc n
690+isUndefined _ n
703 = do i <- getContext
691 = do i <- getContext
704 case lookupTyExact n i of
692 case lookupTyExact n i of
705 Just _ -> return False
693 Just _ -> return False
@@ -756,7 +744,7 @@ addDeferred' nt ns
756 tidyNames used (Bind n b sc)
744 tidyNames used (Bind n b sc)
757 = let n' = uniqueNameSet n used in
745 = let n' = uniqueNameSet n used in
758 Bind n' b $ tidyNames (S.insert n' used) sc
746 Bind n' b $ tidyNames (S.insert n' used) sc
759− tidyNames used b = b
747+ tidyNames _ b = b
761solveDeferred :: FC -> Name -> Idris ()
749solveDeferred :: FC -> Name -> Idris ()
762solveDeferred fc n
750solveDeferred fc n
@@ -1144,7 +1132,6 @@ setColour ct c = do i <- getIState
1144 setColour' PromptColour c t = t { promptColour = c }
1132 setColour' PromptColour c t = t { promptColour = c }
1145 setColour' PostulateColour c t = t { postulateColour = c }
1133 setColour' PostulateColour c t = t { postulateColour = c }
1148logLvl :: Int -> String -> Idris ()
1135logLvl :: Int -> String -> Idris ()
1149logLvl = logLvlCats []
1136logLvl = logLvlCats []
@@ -1178,7 +1165,7 @@ logLvlCats :: [LogCat] -- ^ The categories that the message should appear under.
1178 -> Int -- ^ The Logging level the message should appear.
1165 -> Int -- ^ The Logging level the message should appear.
1179 -> String -- ^ The message to show the developer.
1166 -> String -- ^ The message to show the developer.
1180 -> Idris ()
1167 -> Idris ()
1181−logLvlCats cs l str = do
1168+logLvlCats cs l msg = do
1182 i <- getIState
1169 i <- getIState
1183 let lvl = opt_logLevel (idris_options i)
1170 let lvl = opt_logLevel (idris_options i)
1184 let cats = opt_logcats (idris_options i)
1171 let cats = opt_logcats (idris_options i)
@@ -1186,9 +1173,9 @@ logLvlCats cs l str = do
1186 when (inCat cs cats || null cats) $
1173 when (inCat cs cats || null cats) $
1187 case idris_outputmode i of
1174 case idris_outputmode i of
1188 RawOutput h -> do
1175 RawOutput h -> do
1189− runIO $ hPutStrLn h str
1176+ runIO $ hPutStrLn h msg
1190 IdeMode n h -> do
1177 IdeMode n h -> do
1191− let good = SexpList [IntegerAtom (toInteger l), toSExp str]
1178+ let good = SexpList [IntegerAtom (toInteger l), toSExp msg]
1192 runIO . hPutStrLn h $ convSExp "log" good n
1179 runIO . hPutStrLn h $ convSExp "log" good n
1194 inCat :: [LogCat] -> [LogCat] -> Bool
1181 inCat :: [LogCat] -> [LogCat] -> Bool
@@ -1210,6 +1197,29 @@ setTypeCase t = do i <- getIState
1210 let opt' = opts { opt_typecase = t }
1197 let opt' = opts { opt_typecase = t }
1211 putIState $ i { idris_options = opt' }
1198 putIState $ i { idris_options = opt' }
1200+getIndentWith :: Idris Int
1203+ return $ interactiveOpts_indentWith (idris_interactiveOpts i)
1205+setIndentWith :: Int -> Idris ()
1206+setIndentWith indentWith = do
1208+ let opts = idris_interactiveOpts i
1209+ let opts' = opts { interactiveOpts_indentWith = indentWith }
1210+ putIState $ i { idris_interactiveOpts = opts' }
1212+getIndentClause :: Idris Int
1213+getIndentClause = do
1215+ return $ interactiveOpts_indentClause (idris_interactiveOpts i)
1217+setIndentClause :: Int -> Idris ()
1218+setIndentClause indentClause = do
1220+ let opts = idris_interactiveOpts i
1221+ let opts' = opts { interactiveOpts_indentClause = indentClause }
1222+ putIState $ i { idris_interactiveOpts = opts' }
1214-- Dealing with parameters
1224-- Dealing with parameters
@@ -2226,9 +2236,10 @@ instance Applicative (EitherErr a) where
2226instance Monad (EitherErr a) where
2236instance Monad (EitherErr a) where
2227 return = RightOK
2237 return = RightOK
2229− (LeftErr e) >>= k = LeftErr e
2239+ (LeftErr e) >>= _ = LeftErr e
2230 RightOK v >>= k = k v
2240 RightOK v >>= k = k v
2242+toEither :: EitherErr a b -> Either a b
2232toEither (LeftErr e) = Left e
2243toEither (LeftErr e) = Left e
2233toEither (RightOK ho) = Right ho
2244toEither (RightOK ho) = Right ho
@@ -2439,7 +2450,7 @@ mkUniqueNames env shadows tm
2439 -- looking for too long...)
2450 -- looking for too long...)
2440 initN (UN n) l = UN $ txt (str n ++ show l)
2451 initN (UN n) l = UN $ txt (str n ++ show l)
2441 initN (MN i s) l = MN (i+l) s
2452 initN (MN i s) l = MN (i+l) s
2442− initN n l = n
2453+ initN n _ = n
2444 -- FIXME: Probably ought to do this for completeness! It's fine as
2455 -- FIXME: Probably ought to do this for completeness! It's fine as
2445 -- long as there are no bindings inside tactics though.
2456 -- long as there are no bindings inside tactics though.
@@ -2547,50 +2558,49 @@ mkUniqueNames env shadows tm
2548 mkUniq ql nmap tm = descendM (mkUniq ql nmap) tm
2559 mkUniq ql nmap tm = descendM (mkUniq ql nmap) tm
2551getFile :: Opt -> Maybe String
2561getFile :: Opt -> Maybe String
2552−getFile (Filename str) = Just str
2562+getFile (Filename s) = Just s
2553getFile _ = Nothing
2563getFile _ = Nothing
2555getBC :: Opt -> Maybe String
2565getBC :: Opt -> Maybe String
2556−getBC (BCAsm str) = Just str
2566+getBC (BCAsm s) = Just s
2557getBC _ = Nothing
2567getBC _ = Nothing
2559getOutput :: Opt -> Maybe String
2569getOutput :: Opt -> Maybe String
2560−getOutput (Output str) = Just str
2570+getOutput (Output s) = Just s
2561getOutput _ = Nothing
2571getOutput _ = Nothing
2563getIBCSubDir :: Opt -> Maybe String
2573getIBCSubDir :: Opt -> Maybe String
2564−getIBCSubDir (IBCSubDir str) = Just str
2574+getIBCSubDir (IBCSubDir s) = Just s
2565getIBCSubDir _ = Nothing
2575getIBCSubDir _ = Nothing
2567getImportDir :: Opt -> Maybe String
2577getImportDir :: Opt -> Maybe String
2568−getImportDir (ImportDir str) = Just str
2578+getImportDir (ImportDir s) = Just s
2569getImportDir _ = Nothing
2579getImportDir _ = Nothing
2571getSourceDir :: Opt -> Maybe String
2581getSourceDir :: Opt -> Maybe String
2572−getSourceDir (SourceDir str) = Just str
2582+getSourceDir (SourceDir s) = Just s
2573getSourceDir _ = Nothing
2583getSourceDir _ = Nothing
2575getPkgDir :: Opt -> Maybe String
2585getPkgDir :: Opt -> Maybe String
2576−getPkgDir (Pkg str) = Just str
2586+getPkgDir (Pkg s) = Just s
2577getPkgDir _ = Nothing
2587getPkgDir _ = Nothing
2579getPkg :: Opt -> Maybe (Bool, String)
2589getPkg :: Opt -> Maybe (Bool, String)
2580−getPkg (PkgBuild str) = Just (False, str)
2590+getPkg (PkgBuild s) = Just (False, s)
2581−getPkg (PkgInstall str) = Just (True, str)
2591+getPkg (PkgInstall s) = Just (True, s)
2582getPkg _ = Nothing
2592getPkg _ = Nothing
2584getPkgClean :: Opt -> Maybe String
2594getPkgClean :: Opt -> Maybe String
2585−getPkgClean (PkgClean str) = Just str
2595+getPkgClean (PkgClean s) = Just s
2586getPkgClean _ = Nothing
2596getPkgClean _ = Nothing
2588getPkgREPL :: Opt -> Maybe String
2598getPkgREPL :: Opt -> Maybe String
2589−getPkgREPL (PkgREPL str) = Just str
2599+getPkgREPL (PkgREPL s) = Just s
2590getPkgREPL _ = Nothing
2600getPkgREPL _ = Nothing
2592getPkgCheck :: Opt -> Maybe String
2602getPkgCheck :: Opt -> Maybe String
2593−getPkgCheck (PkgCheck str) = Just str
2603+getPkgCheck (PkgCheck s) = Just s
2594getPkgCheck _ = Nothing
2604getPkgCheck _ = Nothing
2596-- | Returns None if given an Opt which is not PkgMkDoc
2606-- | Returns None if given an Opt which is not PkgMkDoc
@@ -2618,7 +2628,6 @@ getConsoleWidth :: Opt -> Maybe ConsoleWidth
2618getConsoleWidth (UseConsoleWidth x) = Just x
2628getConsoleWidth (UseConsoleWidth x) = Just x
2619getConsoleWidth _ = Nothing
2629getConsoleWidth _ = Nothing
2622getExecScript :: Opt -> Maybe String
2631getExecScript :: Opt -> Maybe String
2623getExecScript (InterpretScript expr) = Just expr
2632getExecScript (InterpretScript expr) = Just expr
2624getExecScript _ = Nothing
2633getExecScript _ = Nothing
@@ -2667,7 +2676,7 @@ getClient _ = Nothing
2667-- Get the first valid port
2676-- Get the first valid port
2668getPort :: [Opt] -> Maybe REPLPort
2677getPort :: [Opt] -> Maybe REPLPort
2669getPort [] = Nothing
2678getPort [] = Nothing
2670−getPort (Port p : xs) = Just p
2679+getPort (Port p : _ ) = Just p
2671getPort (_ : xs) = getPort xs
2680getPort (_ : xs) = getPort xs
2673opt :: (Opt -> Maybe a) -> [Opt] -> [a]
2682opt :: (Opt -> Maybe a) -> [Opt] -> [a]