~jojo/Carth

ref: ae1d242d7d48292779dcbd953e5864bb4211e1ca Carth/src/Conf.hs -rw-r--r-- 1.3 KiB
ae1d242dJoJo Update stackage release & use default-extensions in cabal file 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module Conf where

import Control.Monad

data Conf
    = CompileConf CompileConfig
    | RunConf RunConfig

data CompileConfig = CompileConfig
    { cInfile :: FilePath
    , cOutfile :: FilePath
    -- | Path to C compiler to use for linking and compiling ".c" files
    , cCompiler :: FilePath
    , cDebug :: Bool
    , cVerbose :: Bool
    }

data RunConfig = RunConfig
    { rInfile :: FilePath
    , rDebug :: Bool
    , rVerbose :: Bool
    }

class Config cfg where
    getDebug :: cfg -> Bool
    getVerbose :: cfg -> Bool
instance Config CompileConfig where
    getDebug = cDebug
    getVerbose = cVerbose
instance Config RunConfig where
    getDebug = rDebug
    getVerbose = rVerbose

defaultCompileConfig :: FilePath -> FilePath -> CompileConfig
defaultCompileConfig inf outf = CompileConfig { cInfile = inf
                                              , cOutfile = outf
                                              , cCompiler = "cc"
                                              , cDebug = False
                                              , cVerbose = False
                                              }

defaultRunConfig :: FilePath -> RunConfig
defaultRunConfig inf = RunConfig { rInfile = inf, rDebug = False, rVerbose = False }

verbose :: Config cfg => cfg -> String -> IO ()
verbose cfg msg = when (getVerbose cfg) $ putStrLn msg