on ef93607 help sign in
Idris-dev/src/Main.hs
106 lines 4.0 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.State.Strict ( execStateT, get, put )
12import Control.Monad.Trans ( liftIO )
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 execStateT (runIdris opts) idrisInit
45runIdris :: [Opt] -> Idris ()
46runIdris opts = do
47 when (Ver `elem` opts) $ liftIO showver
48 when (Usage `elem` opts) $ liftIO usage
49 when (ShowIncs `elem` opts) $ liftIO showIncs
50 when (ShowLibs `elem` opts) $ liftIO showLibs
51 when (ShowLibdir `elem` opts) $ liftIO showLibdir
52 case opt getPkgClean opts of
53 [] -> return ()
54 fs -> do liftIO $ mapM_ cleanPkg fs
55 liftIO $ exitWith ExitSuccess
56 case opt getPkg opts of
57 [] -> idrisMain opts -- in Idris.REPL
58 fs -> liftIO $ mapM_ (buildPkg (WarnOnly `elem` opts)) fs
60usage = do putStrLn usagemsg
61 exitWith ExitSuccess
63showver = do putStrLn $ "Idris version " ++ ver
64 exitWith ExitSuccess
66showLibs = do libFlags <- getLibFlags
67 putStrLn libFlags
68 exitWith ExitSuccess
70showLibdir = do dir <- getIdrisLibDir
71 putStrLn dir
72 exitWith ExitSuccess
74showIncs = do incFlags <- getIncFlags
75 putStrLn incFlags
76 exitWith ExitSuccess
78usagemsg = "Idris version " ++ ver ++ "\n" ++
79 "--------------" ++ map (\x -> '-') ver ++ "\n" ++
80 "Usage: idris [input file] [options]\n" ++
81 "Options:\n" ++
82 "\t--quiet Quiet mode (for editors)\n" ++
83 "\t--check Type check only\n" ++
84 "\t-o [file] Specify output filename\n" ++
85 "\t-i [dir] Add directory to the list of import paths\n" ++
86 "\t--ibcsubdir [dir] Write IBC files into sub directory\n" ++
87 "\t--noprelude Don't import the prelude\n" ++
88 "\t--total Require functions to be total by default\n" ++
89 "\t--warnpartial Warn about undeclared partial functions\n" ++
90 "\t--typeintype Disable universe checking\n" ++
91 "\t--log [level] Type debugging log level\n" ++
92 "\t-S Do no further compilation of code generator output\n" ++
93 "\t-c Compile to object files rather than an executable\n" ++
94 "\t--exec [expr] Execute the expression expr in the interpreter,\n" ++
95 "\t defaulting to Main.main if none provided, and exit.\n" ++
96 "\t--ideslave Ideslave mode (for editors; in/ouput wrapped in \n" ++
97 "\t s-expressions)\n" ++
98 "\t--libdir Show library install directory and exit\n" ++
99 "\t--link Show C library directories and exit (for C linking)\n" ++
100 "\t--include Show C include directories and exit (for C linking)\n" ++
101 "\t--codegen [cg] Select code generator: C, Java, bytecode, javascript,\n" ++
102 "\t node or llvm\n" ++
103 "\t--target [triple] Select target triple (for LLVM codegen)\n" ++
104 "\t--cpu [cpu] Select target CPU (e.g. corei7 or cortex-m3) (for LLVM codegen)\n"