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 Evaluation.FunctionIO
DependencyRunner DependencyRunner
SiteGenerator SiteGenerator
Precomputer
build-depends: build-depends:
base >=4.14 && <4.20 base >=4.14 && <4.20
, mtl , mtl

View File

@ -1,25 +1,28 @@
{-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TemplateHaskell #-}
module Main where module Main where
import Types.Dependency (Dependency, formatDependencyTrees)
import DependencyGenerator (evalDepGenM) import DependencyGenerator (evalDepGenM)
import SiteGenerator (generateSite) import SiteGenerator (generateSite)
import DependencyRunner (runDeps, runDepRunMIO) import qualified Precomputer
import System.Environment (getArgs) import System.Environment (getArgs)
import Data.Text (Text)
import qualified Data.Text.IO as T import qualified Data.Text.IO as T
import Language.Haskell.TH.Syntax (lift) import Language.Haskell.TH.Syntax
dependencies :: [Dependency] formatDependencyTrees :: Text
dependencies = $(lift (evalDepGenM generateSite)) formatDependencyTrees = $$(Precomputer.formatDependencyTrees $(lift (evalDepGenM generateSite)))
runDeps :: IO ()
runDeps = $$(Precomputer.runDeps $(lift (evalDepGenM generateSite)))
main :: IO () main :: IO ()
main = do main = do
args <- getArgs args <- getArgs
case args of case args of
["run"] -> ["run"] ->
runDepRunMIO $ runDeps dependencies runDeps
["tree"] -> ["tree"] ->
T.putStr $ formatDependencyTrees dependencies T.putStr formatDependencyTrees
_ -> _ ->
error "unexpected arguments" 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 ||]