diff --git a/byg/byg.cabal b/byg/byg.cabal index 06bc348..7552d31 100644 --- a/byg/byg.cabal +++ b/byg/byg.cabal @@ -32,6 +32,7 @@ library Evaluation.FunctionIO DependencyRunner SiteGenerator + Precomputer build-depends: base >=4.14 && <4.20 , mtl diff --git a/byg/src/Main.hs b/byg/src/Main.hs index 6002d14..adfa47e 100644 --- a/byg/src/Main.hs +++ b/byg/src/Main.hs @@ -1,25 +1,28 @@ {-# LANGUAGE TemplateHaskell #-} module Main where -import Types.Dependency (Dependency, formatDependencyTrees) import DependencyGenerator (evalDepGenM) import SiteGenerator (generateSite) -import DependencyRunner (runDeps, runDepRunMIO) +import qualified Precomputer import System.Environment (getArgs) +import Data.Text (Text) import qualified Data.Text.IO as T -import Language.Haskell.TH.Syntax (lift) +import Language.Haskell.TH.Syntax -dependencies :: [Dependency] -dependencies = $(lift (evalDepGenM generateSite)) +formatDependencyTrees :: Text +formatDependencyTrees = $$(Precomputer.formatDependencyTrees $(lift (evalDepGenM generateSite))) + +runDeps :: IO () +runDeps = $$(Precomputer.runDeps $(lift (evalDepGenM generateSite))) main :: IO () main = do args <- getArgs case args of ["run"] -> - runDepRunMIO $ runDeps dependencies + runDeps ["tree"] -> - T.putStr $ formatDependencyTrees dependencies + T.putStr formatDependencyTrees _ -> error "unexpected arguments" diff --git a/byg/src/Precomputer.hs b/byg/src/Precomputer.hs new file mode 100644 index 0000000..74afe55 --- /dev/null +++ b/byg/src/Precomputer.hs @@ -0,0 +1,18 @@ +{-# LANGUAGE TemplateHaskell #-} +module Precomputer + ( runDeps + , formatDependencyTrees + ) where + +import Types.Dependency (Dependency) +import qualified DependencyRunner as DR +import qualified Types.Dependency as D + +import Data.Text (Text) +import Language.Haskell.TH.Syntax + +runDeps :: [Dependency] -> Code Q (IO ()) +runDeps deps = [|| DR.runDepRunMIO (DR.runDeps deps) ||] + +formatDependencyTrees :: [Dependency] -> Code Q Text +formatDependencyTrees deps = [|| D.formatDependencyTrees deps ||]