module Hhp.Boot where

import GHC (Ghc)
import GHC.Utils.Monad (liftIO)

import Hhp.Browse
import Hhp.Flag
import Hhp.GHCApi
import Hhp.Lang
import Hhp.List
import Hhp.Types

-- | Printing necessary information for front-end booting.
bootInfo :: Options -> Cradle -> IO String
bootInfo :: Options -> Cradle -> IO String
bootInfo Options
opt Cradle
cradle = forall a. Ghc a -> IO a
withGHC' forall a b. (a -> b) -> a -> b
$ do
    Options -> Cradle -> Ghc ()
initializeFlagsWithCradle Options
opt Cradle
cradle
    Options -> Ghc String
boot Options
opt

-- | Printing necessary information for front-end booting.
boot :: Options -> Ghc String
boot :: Options -> Ghc String
boot Options
opt = do
    String
mods  <- Options -> Ghc String
modules Options
opt
    String
langs <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ Options -> IO String
listLanguages Options
opt
    String
flags <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ Options -> IO String
listFlags Options
opt
    String
pre   <- forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Options -> String -> Ghc String
browse Options
opt) [String]
preBrowsedModules
    forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ String
mods forall a. [a] -> [a] -> [a]
++ String
langs forall a. [a] -> [a] -> [a]
++ String
flags forall a. [a] -> [a] -> [a]
++ String
pre

preBrowsedModules :: [String]
preBrowsedModules :: [String]
preBrowsedModules = [
    String
"Prelude"
  , String
"Control.Applicative"
  , String
"Control.Exception"
  , String
"Control.Monad"
  , String
"Data.Char"
  , String
"Data.List"
  , String
"Data.Maybe"
  , String
"System.IO"
  ]