on c79fb21 help sign in
Idris-dev/main/Main.hs
90 lines 2.8 kB history raw
1module Main where
3import System.Console.Haskeline
4import System.IO
5import System.Environment
6import System.Exit
7import System.FilePath ((</>), addTrailingPathSeparator)
9import Data.Maybe
10import Data.Version
11import Control.Monad.Trans.Error ( ErrorT(..) )
12import Control.Monad.Trans.State.Strict ( execStateT, get, put )
13import Control.Monad ( when )
15import Idris.Core.TT
16import Idris.Core.Typecheck
17import Idris.Core.Evaluate
18import Idris.Core.Constraints
20import Idris.AbsSyntax
21import Idris.Parser
22import Idris.REPL
23import Idris.ElabDecls
24import Idris.Primitives
25import Idris.Imports
26import Idris.Error
27import Idris.CmdOptions
29import IRTS.System ( getLibFlags, getIdrisLibDir, getIncFlags )
31import Util.DynamicLinker
33import Pkg.Package
35import Paths_idris
37-- Main program reads command line options, parses the main program, and gets
38-- on with the REPL.
40main = do opts <- runArgParser
41 result <- runErrorT $ execStateT (runIdris opts) idrisInit
42 case result of
43 Left err -> putStrLn $ "Uncaught error: " ++ show err
44 Right _ -> return ()
46runIdris :: [Opt] -> Idris ()
47runIdris [Client c] = do setVerbose False
48 setQuiet True
49 runIO $ runClient c
50runIdris opts = do
51 when (ShowIncs `elem` opts) $ runIO showIncs
52 when (ShowLibs `elem` opts) $ runIO showLibs
53 when (ShowLibdir `elem` opts) $ runIO showLibdir
54 case opt getPkgCheck opts of
55 [] -> return ()
56 fs -> do runIO $ mapM_ (checkPkg (WarnOnly `elem` opts) True) fs
57 runIO $ exitWith ExitSuccess
58 case opt getPkgClean opts of
59 [] -> return ()
60 fs -> do runIO $ mapM_ cleanPkg fs
61 runIO $ exitWith ExitSuccess
62 case opt getPkgMkDoc opts of -- IdrisDoc
63 [] -> return ()
64 fs -> do runIO $ mapM_ documentPkg fs
65 runIO $ exitWith ExitSuccess
66 case opt getPkgTest opts of
67 [] -> return ()
68 fs -> do runIO $ mapM_ testPkg fs
69 runIO $ exitWith ExitSuccess
70 case opt getPkg opts of
71 [] -> case opt getPkgREPL opts of
72 [] -> idrisMain opts
73 [f] -> replPkg f
74 _ -> ifail "Too many packages"
75 fs -> runIO $ mapM_ (buildPkg (WarnOnly `elem` opts)) fs
77showver = do putStrLn $ "Idris version " ++ ver
78 exitWith ExitSuccess
80showLibs = do libFlags <- getLibFlags
81 putStrLn libFlags
82 exitWith ExitSuccess
84showLibdir = do dir <- getIdrisLibDir
85 putStrLn dir
86 exitWith ExitSuccess
88showIncs = do incFlags <- getIncFlags
89 putStrLn incFlags
90 exitWith ExitSuccess