on ceff983 help sign in
43 lines 1.2 kB history raw
1module Main where
3import Idris.Core.TT
4import Idris.AbsSyntax
5import Idris.ElabDecls
6import Idris.REPL
8import IRTS.Compiler
9import IRTS.CodegenJavaScript
11import System.Environment
12import System.Exit
14import Paths_idris
16data Opts = Opts { inputs :: [FilePath]
17 , output :: FilePath
18 }
20showUsage = do putStrLn "A code generator which is intended to be called by the compiler, not by a user."
21 putStrLn "Usage: idris-codegen-node <ibc-files> [-o <output-file>]"
22 exitWith ExitSuccess
24getOpts :: IO Opts
25getOpts = do xs <- getArgs
26 return $ process (Opts [] "main.js") xs
27 where
28 process opts ("-o":o:xs) = process (opts { output = o }) xs
29 process opts (x:xs) = process (opts { inputs = x:inputs opts }) xs
30 process opts [] = opts
32jsMain :: Opts -> Idris ()
33jsMain opts = do elabPrims
34 loadInputs (inputs opts) Nothing
35 mainProg <- elabMain
36 ir <- compile (Via "node") (output opts) (Just mainProg)
37 runIO $ codegenNode ir
39main :: IO ()
40main = do opts <- getOpts
41 if (null (inputs opts))
42 then showUsage
43 else runMain (jsMain opts)