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