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