@@ -21,6 +21,11 @@ import Control.Monad (forM)
21import System.Exit (exitSuccess, exitFailure)
21import System.Exit (exitSuccess, exitFailure)
22import qualified System.IO.UTF8 as U
22import qualified System.IO.UTF8 as U
23import Text.Parsec (ParseError)
23import Text.Parsec (ParseError)
24+import qualified Paths_purescript as Paths
25+import Data.Version (showVersion)
27+preludeFilename :: IO FilePath
28+preludeFilename = Paths.getDataFileName "libraries/prelude/prelude.purs"
25readInput :: Maybe [FilePath] -> IO (Either ParseError [P.Module])
30readInput :: Maybe [FilePath] -> IO (Either ParseError [P.Module])
26readInput Nothing = getContents >>= return . P.runIndentParser P.parseModules
31readInput Nothing = getContents >>= return . P.runIndentParser P.parseModules
@@ -73,24 +78,31 @@ performRuntimeTypeChecks :: Term Bool
73performRuntimeTypeChecks = value $ flag $ (optInfo [ "runtime-type-checks" ])
78performRuntimeTypeChecks = value $ flag $ (optInfo [ "runtime-type-checks" ])
74 { optDoc = "Generate runtime type checks" }
79 { optDoc = "Generate runtime type checks" }
81+noPrelude :: Term Bool
82+noPrelude = value $ flag $ (optInfo [ "no-prelude" ])
83+ { optDoc = "Omit the Prelude" }
76options :: Term P.Options
85options :: Term P.Options
77options = P.Options <$> tco <*> performRuntimeTypeChecks
86options = P.Options <$> tco <*> performRuntimeTypeChecks
79−stdInOrInputFiles :: Term (Maybe [FilePath])
88+stdInOrInputFiles :: FilePath -> Term (Maybe [FilePath])
80−stdInOrInputFiles = combine <$> useStdIn <*> inputFiles
89+stdInOrInputFiles prelude = combine <$> useStdIn <*> (not <$> noPrelude) <*> inputFiles
82− combine False input = Just input
91+ combine False True input = Just (prelude : input)
92+ combine False False input = Just input
83− combine True _ = Nothing
93+ combine True _ _ = Nothing
85−term :: Term (IO ())
95+term :: FilePath -> Term (IO ())
86−term = compile <$> options <*> stdInOrInputFiles <*> outputFile <*> externsFile
96+term prelude = compile <$> options <*> stdInOrInputFiles prelude <*> outputFile <*> externsFile
88termInfo :: TermInfo
98termInfo :: TermInfo
89termInfo = defTI
99termInfo = defTI
90 { termName = "psc"
100 { termName = "psc"
91− , version = "1.0"
101+ , version = showVersion $ Paths.version
92 , termDoc = "Compiles PureScript to Javascript"
102 , termDoc = "Compiles PureScript to Javascript"
95main :: IO ()
105main :: IO ()
107+ prelude <- preludeFilename
96−main = run (term, termInfo)
108+ run (term prelude, termInfo)