Precompute more

This commit is contained in:
Niels G. W. Serup 2024-10-05 15:35:52 +02:00
parent 556ded64a8
commit 7e23b55513
No known key found for this signature in database
GPG Key ID: 38EEEBCE67324F19
3 changed files with 29 additions and 7 deletions

View File

@ -32,6 +32,7 @@ library
Evaluation.FunctionIO
DependencyRunner
SiteGenerator
Precomputer
build-depends:
base >=4.14 && <4.20
, mtl

View File

@ -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"

18
byg/src/Precomputer.hs Normal file
View File

@ -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 ||]