Skip to content

Commit

Permalink
javascript: lift out node backend
Browse files Browse the repository at this point in the history
  • Loading branch information
raichoo committed Aug 22, 2014
1 parent 31de6be commit f905a79
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
42 changes: 42 additions & 0 deletions codegen/idris-node/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module Main where

import Idris.Core.TT
import Idris.AbsSyntax
import Idris.ElabDecls
import Idris.REPL

import IRTS.Compiler
import IRTS.CodegenJavaScript

import System.Environment
import System.Exit

import Paths_idris

data Opts = Opts { inputs :: [FilePath]
, output :: FilePath
}

showUsage = do putStrLn "Usage: idris-node <ibc-files> [-o <output-file>]"
exitWith ExitSuccess

getOpts :: IO Opts
getOpts = do xs <- getArgs
return $ process (Opts [] "main.js") xs
where
process opts ("-o":o:xs) = process (opts { output = o }) xs
process opts (x:xs) = process (opts { inputs = x:inputs opts }) xs
process opts [] = opts

jsMain :: Opts -> Idris ()
jsMain opts = do elabPrims
loadInputs (inputs opts) Nothing
mainProg <- elabMain
ir <- compile (Via "node") (output opts) mainProg
runIO $ codegenNode ir

main :: IO ()
main = do opts <- getOpts
if (null (inputs opts))
then showUsage
else runMain (jsMain opts)
13 changes: 13 additions & 0 deletions idris.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -778,3 +778,16 @@ Executable idris-javascript

ghc-prof-options: -auto-all -caf-all
ghc-options: -threaded -rtsopts -funbox-strict-fields

Executable idris-node
Main-is: Main.hs
hs-source-dirs: codegen/idris-node

Build-depends: idris
, base
, filepath
, haskeline >= 0.7
, transformers

ghc-prof-options: -auto-all -caf-all
ghc-options: -threaded -rtsopts -funbox-strict-fields
1 change: 0 additions & 1 deletion src/IRTS/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ generate codegen mainmod ir
-- Built-in code generators (FIXME: lift these out!)
Via "c" -> codegenC ir
Via "java" -> codegenJava ir
Via "node" -> codegenNode ir
Via "llvm" -> codegenLLVM ir
-- Any external code generator
Via cg -> do let cmd = "idris-" ++ cg ++ " " ++ mainmod ++
Expand Down

0 comments on commit f905a79

Please sign in to comment.