on d1663cc help sign in
Idris-dev/src/Main.hs
114 lines 4.4 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 Core.CoreParser
16import Core.ShellParser
17import Core.TT
18import Core.Typecheck
19import Core.ProofShell
20import Core.Evaluate
21import Core.Constraints
23import Idris.AbsSyntax
24import Idris.Parser
25import Idris.REPL
26import Idris.ElabDecls
27import Idris.Primitives
28import Idris.Imports
29import Idris.Error
31import Util.System ( getLibFlags, getIdrisLibDir, getIncFlags )
32import Util.DynamicLinker
34import Pkg.Package
36import Paths_idris
38-- Main program reads command line options, parses the main program, and gets
39-- on with the REPL.
41main = do xs <- getArgs
42 let opts = parseArgs xs
43 result <- runErrorT $ execStateT (runIdris opts) idrisInit
44 case result of
45 Left err -> putStrLn $ "Uncaught error: " ++ show err
46 Right _ -> return ()
48runIdris :: [Opt] -> Idris ()
49runIdris [Client c] = do setVerbose False
50 setQuiet True
51 runIO $ runClient c
52runIdris opts = do
53 when (Ver `elem` opts) $ runIO showver
54 when (Usage `elem` opts) $ runIO usage
55 when (ShowIncs `elem` opts) $ runIO showIncs
56 when (ShowLibs `elem` opts) $ runIO showLibs
57 when (ShowLibdir `elem` opts) $ runIO showLibdir
58 case opt getPkgClean opts of
59 [] -> return ()
60 fs -> do runIO $ mapM_ cleanPkg fs
61 runIO $ exitWith ExitSuccess
62 case opt getPkg opts of
63 [] -> idrisMain opts -- in Idris.REPL
64 fs -> runIO $ mapM_ (buildPkg (WarnOnly `elem` opts)) fs
66usage = do putStrLn usagemsg
67 exitWith ExitSuccess
69showver = do putStrLn $ "Idris version " ++ ver
70 exitWith ExitSuccess
72showLibs = do libFlags <- getLibFlags
73 putStrLn libFlags
74 exitWith ExitSuccess
76showLibdir = do dir <- getIdrisLibDir
77 putStrLn dir
78 exitWith ExitSuccess
80showIncs = do incFlags <- getIncFlags
81 putStrLn incFlags
82 exitWith ExitSuccess
84usagemsg = "Idris version " ++ ver ++ "\n" ++
85 "--------------" ++ map (\x -> '-') ver ++ "\n" ++
86 "Usage: idris [input file] [options]\n" ++
87 "Options:\n" ++
88 "\t--quiet Quiet mode (for editors)\n" ++
89 "\t--[no]colour Control REPL colour highlighting\n" ++
90 "\t--check Type check only\n" ++
91 "\t-o [file] Specify output filename\n" ++
92 "\t-i [dir] Add directory to the list of import paths\n" ++
93 "\t--ibcsubdir [dir] Write IBC files into sub directory\n" ++
94 "\t--noprelude Don't import the prelude\n" ++
95 "\t--total Require functions to be total by default\n" ++
96 "\t--warnpartial Warn about undeclared partial functions\n" ++
97 "\t--typeintype Disable universe checking\n" ++
98 "\t--log [level] Type debugging log level\n" ++
99 "\t-S Do no further compilation of code generator output\n" ++
100 "\t-c Compile to object files rather than an executable\n" ++
101 "\t--mvn Create a maven project (for Java codegen)\n" ++
102 "\t--exec [expr] Execute the expression expr in the interpreter,\n" ++
103 "\t defaulting to Main.main if none provided, and exit.\n" ++
104 "\t--ideslave Ideslave mode (for editors; in/ouput wrapped in \n" ++
105 "\t s-expressions)\n" ++
106 "\t--libdir Show library install directory and exit\n" ++
107 "\t--link Show C library directories and exit (for C linking)\n" ++
108 "\t--include Show C include directories and exit (for C linking)\n" ++
109 "\t--codegen [cg] Select code generator: C, Java, bytecode, javascript,\n" ++
110 "\t node or llvm\n" ++
111 "\t--target [triple] Select target triple (for LLVM codegen)\n" ++
112 "\t--cpu [cpu] Select target CPU (e.g. corei7 or cortex-m3) (for LLVM codegen)\n"