From f5d0f2d60451e6f073e4130195cf602374c4f73f Mon Sep 17 00:00:00 2001 From: Andreas Abel Date: Wed, 25 Oct 2023 00:21:58 +0200 Subject: [PATCH] [ lab2, agda ] use `Setup.hs` to call `agda --ghc` --- cabal.project | 2 ++ laborations/lab2/agda/Main.hs | 3 +++ laborations/lab2/agda/Setup.hs | 36 ++++++++++++++++++++++++++++++ laborations/lab2/agda/package.yaml | 16 ++++++++----- 4 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 laborations/lab2/agda/Main.hs create mode 100644 laborations/lab2/agda/Setup.hs diff --git a/cabal.project b/cabal.project index 14c61cd..9e1d3b6 100644 --- a/cabal.project +++ b/cabal.project @@ -9,3 +9,5 @@ packages: laborations/lab2/haskell laborations/lab3/haskell laborations/lab4/haskell + + laborations/lab2/agda diff --git a/laborations/lab2/agda/Main.hs b/laborations/lab2/agda/Main.hs new file mode 100644 index 0000000..7243325 --- /dev/null +++ b/laborations/lab2/agda/Main.hs @@ -0,0 +1,3 @@ +module Main (module X) where + +import MAlonzo.Code.Qlab2 as X (main) diff --git a/laborations/lab2/agda/Setup.hs b/laborations/lab2/agda/Setup.hs new file mode 100644 index 0000000..d5b2c51 --- /dev/null +++ b/laborations/lab2/agda/Setup.hs @@ -0,0 +1,36 @@ +-- Programming Language Technology (Chalmers DAT151 / GU DIT231). +-- (C) Andreas Abel 2023 +-- All rights reserved. + +-- | Hook BNFC into the cabal build process to generate AST, lexer, parser, and printer definitions. + +import Distribution.Simple (defaultMainWithHooks, simpleUserHooks, buildHook) +import Distribution.Simple.BuildPaths (autogenPackageModulesDir) +import System.Process (callProcess) + +main :: IO () +main = defaultMainWithHooks simpleUserHooks + { buildHook = \ packageDescription localBuildInfo userHooks buildFlags -> do + -- For simplicity, generate files in build/global-autogen; + -- there they are available to all components of the package. + let dir = autogenPackageModulesDir localBuildInfo + callProcess "bnfc" + [ "-o", dir + , "-d" + , "CMM.cf" + ] + callProcess "agda" + [ "--ghc", "--ghc-dont-call-ghc" + , "src/lab2.agda" + ] + callProcess "rm" + [ "-rf" + , dir ++ "/MAlonzo" + ] + callProcess "mv" + [ "src/MAlonzo" + , dir ++ "/" + ] + -- Run the build process. + buildHook simpleUserHooks packageDescription localBuildInfo userHooks buildFlags + } diff --git a/laborations/lab2/agda/package.yaml b/laborations/lab2/agda/package.yaml index 6a453a4..09f621d 100644 --- a/laborations/lab2/agda/package.yaml +++ b/laborations/lab2/agda/package.yaml @@ -25,8 +25,11 @@ tested-with: - GHC == 8.6.5 - GHC == 8.4.4 -dependencies: - - base >= 4.9 && < 5 +custom-setup: + dependencies: + - Cabal >= 2.0 && < 4 + - base >= 4.11 && < 5 + - process executables: lab2: @@ -34,13 +37,16 @@ executables: # files in CMM are qualified modules source-dirs: - . - - src - main: MAlonzo.Code.Qlab2 + # - src + main: Main + generated-other-modules: + - MAlonzo.Code.Qlab2 dependencies: + - base >= 4.11 && < 5 - array - - text - filepath - process + - text # exclude some modules when: