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