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