Skip to content

Commit

Permalink
Merge 6e473ed into 2e0559b
Browse files Browse the repository at this point in the history
  • Loading branch information
paf31 committed Aug 25, 2014
2 parents 2e0559b + 6e473ed commit 2021b43
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
17 changes: 7 additions & 10 deletions psc-make/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ instance P.MonadMake Make where
liftError = either throwError return
progress = makeIO . U.putStrLn

compile :: FilePath -> P.Options -> [FilePath] -> IO ()
compile outputDir opts input = do
modules <- readInput input
compile :: FilePath -> [FilePath] -> FilePath -> P.Options -> IO ()
compile prelude input outputDir opts = do
modules <- readInput allInputFiles
case modules of
Left err -> do
U.print err
Expand All @@ -81,6 +81,9 @@ compile outputDir opts input = do
exitFailure
Right _ -> do
exitSuccess
where
allInputFiles | P.optionsNoPrelude opts = input
| otherwise = prelude : input

mkdirp :: FilePath -> IO ()
mkdirp = createDirectoryIfMissing True . takeDirectory
Expand Down Expand Up @@ -120,14 +123,8 @@ verboseErrors = value $ flag $ (optInfo [ "v", "verbose-errors" ])
options :: Term P.Options
options = P.Options <$> noPrelude <*> noTco <*> performRuntimeTypeChecks <*> noMagicDo <*> pure Nothing <*> noOpts <*> pure Nothing <*> pure [] <*> pure [] <*> verboseErrors

inputFilesAndPrelude :: FilePath -> Term [FilePath]
inputFilesAndPrelude prelude = combine <$> (not <$> noPrelude) <*> inputFiles
where
combine True input = prelude : input
combine False input = input

term :: FilePath -> Term (IO ())
term prelude = compile <$> outputDirectory <*> options <*> inputFilesAndPrelude prelude
term prelude = compile prelude <$> inputFiles <*> outputDirectory <*> options

termInfo :: TermInfo
termInfo = defTI
Expand Down
20 changes: 9 additions & 11 deletions psc/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ readInput (Just input) = fmap collect $ forM input $ \inputFile -> do
collect :: [(FilePath, Either ParseError [P.Module])] -> Either ParseError [(FilePath, P.Module)]
collect = fmap concat . sequence . map (\(fp, e) -> fmap (map ((,) fp)) e)

compile :: P.Options -> Maybe [FilePath] -> Maybe FilePath -> Maybe FilePath -> IO ()
compile opts input output externs = do
modules <- readInput input
compile :: FilePath -> P.Options -> Bool -> [FilePath] -> Maybe FilePath -> Maybe FilePath -> IO ()
compile prelude opts stdin input output externs = do
modules <- readInput stdInOrInputFiles
case modules of
Left err -> do
U.hPutStr stderr $ show err
Expand All @@ -64,6 +64,11 @@ compile opts input output externs = do
Just path -> mkdirp path >> U.writeFile path exts
Nothing -> return ()
exitSuccess
where
stdInOrInputFiles :: Maybe [FilePath]
stdInOrInputFiles | stdin = Nothing
| P.optionsNoPrelude opts = Just input
| otherwise = Just $ prelude : input

mkdirp :: FilePath -> IO ()
mkdirp = createDirectoryIfMissing True . takeDirectory
Expand Down Expand Up @@ -127,15 +132,8 @@ verboseErrors = value $ flag $ (optInfo [ "v", "verbose-errors" ])
options :: Term P.Options
options = P.Options <$> noPrelude <*> noTco <*> performRuntimeTypeChecks <*> noMagicDo <*> runMain <*> noOpts <*> (Just <$> browserNamespace) <*> dceModules <*> codeGenModules <*> verboseErrors

stdInOrInputFiles :: FilePath -> Term (Maybe [FilePath])
stdInOrInputFiles prelude = combine <$> useStdIn <*> (not <$> noPrelude) <*> inputFiles
where
combine False True input = Just (prelude : input)
combine False False input = Just input
combine True _ _ = Nothing

term :: FilePath -> Term (IO ())
term prelude = compile <$> options <*> stdInOrInputFiles prelude <*> outputFile <*> externsFile
term prelude = compile prelude <$> options <*> useStdIn <*> inputFiles <*> outputFile <*> externsFile

termInfo :: TermInfo
termInfo = defTI
Expand Down

0 comments on commit 2021b43

Please sign in to comment.