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