2022-05-30 14:40:52 +03:00
|
|
|
module GlobalOptions
|
|
|
|
( module GlobalOptions,
|
|
|
|
)
|
|
|
|
where
|
2022-05-18 18:10:10 +03:00
|
|
|
|
2022-12-20 15:05:40 +03:00
|
|
|
import CommonOptions
|
2022-09-12 11:44:00 +03:00
|
|
|
import Juvix.Compiler.Abstract.Pretty.Options qualified as Abstract
|
2023-03-27 11:42:27 +03:00
|
|
|
import Juvix.Compiler.Core.Options qualified as Core
|
2022-09-12 11:44:00 +03:00
|
|
|
import Juvix.Compiler.Internal.Pretty.Options qualified as Internal
|
2023-04-13 12:27:39 +03:00
|
|
|
import Juvix.Compiler.Pipeline
|
2022-09-01 14:22:32 +03:00
|
|
|
import Juvix.Data.Error.GenericError qualified as E
|
2022-05-18 18:10:10 +03:00
|
|
|
|
|
|
|
data GlobalOptions = GlobalOptions
|
|
|
|
{ _globalNoColors :: Bool,
|
|
|
|
_globalShowNameIds :: Bool,
|
2023-01-06 19:54:13 +03:00
|
|
|
_globalBuildDir :: Maybe (AppPath Dir),
|
2022-05-30 14:40:52 +03:00
|
|
|
_globalOnlyErrors :: Bool,
|
2022-10-18 18:38:31 +03:00
|
|
|
_globalNoApe :: Bool,
|
2022-08-19 17:57:07 +03:00
|
|
|
_globalStdin :: Bool,
|
2022-06-09 17:36:07 +03:00
|
|
|
_globalNoTermination :: Bool,
|
2022-07-23 10:27:12 +03:00
|
|
|
_globalNoPositivity :: Bool,
|
2023-03-27 11:42:27 +03:00
|
|
|
_globalNoCoverage :: Bool,
|
2023-03-28 12:41:05 +03:00
|
|
|
_globalNoStdlib :: Bool,
|
|
|
|
_globalUnrollLimit :: Int
|
2022-05-18 18:10:10 +03:00
|
|
|
}
|
2022-12-20 15:05:40 +03:00
|
|
|
deriving stock (Eq, Show)
|
2022-05-18 18:10:10 +03:00
|
|
|
|
|
|
|
makeLenses ''GlobalOptions
|
|
|
|
|
2022-09-12 11:44:00 +03:00
|
|
|
instance CanonicalProjection GlobalOptions Internal.Options where
|
|
|
|
project g =
|
|
|
|
Internal.Options
|
|
|
|
{ Internal._optShowNameIds = g ^. globalShowNameIds
|
|
|
|
}
|
|
|
|
|
|
|
|
instance CanonicalProjection GlobalOptions Abstract.Options where
|
|
|
|
project g =
|
|
|
|
Abstract.defaultOptions
|
|
|
|
{ Abstract._optShowNameIds = g ^. globalShowNameIds
|
|
|
|
}
|
|
|
|
|
2022-09-14 17:16:15 +03:00
|
|
|
instance CanonicalProjection GlobalOptions E.GenericOptions where
|
2022-10-18 18:38:31 +03:00
|
|
|
project GlobalOptions {..} =
|
|
|
|
E.GenericOptions
|
|
|
|
{ E._showNameIds = _globalShowNameIds,
|
|
|
|
E._genericNoApe = _globalNoApe
|
|
|
|
}
|
2022-09-14 17:16:15 +03:00
|
|
|
|
2023-03-27 11:42:27 +03:00
|
|
|
instance CanonicalProjection GlobalOptions Core.CoreOptions where
|
|
|
|
project GlobalOptions {..} =
|
|
|
|
Core.CoreOptions
|
2023-03-28 12:41:05 +03:00
|
|
|
{ Core._optCheckCoverage = not _globalNoCoverage,
|
2023-05-15 18:27:05 +03:00
|
|
|
Core._optUnrollLimit = _globalUnrollLimit,
|
|
|
|
Core._optOptimizationLevel = defaultOptimizationLevel,
|
|
|
|
Core._optInliningDepth = defaultInliningDepth
|
2023-03-27 11:42:27 +03:00
|
|
|
}
|
|
|
|
|
2022-06-09 17:36:07 +03:00
|
|
|
defaultGlobalOptions :: GlobalOptions
|
|
|
|
defaultGlobalOptions =
|
|
|
|
GlobalOptions
|
|
|
|
{ _globalNoColors = False,
|
|
|
|
_globalShowNameIds = False,
|
|
|
|
_globalOnlyErrors = False,
|
2022-10-18 18:38:31 +03:00
|
|
|
_globalNoApe = False,
|
2022-06-09 17:36:07 +03:00
|
|
|
_globalNoTermination = False,
|
2023-01-06 19:54:13 +03:00
|
|
|
_globalBuildDir = Nothing,
|
2022-08-19 17:57:07 +03:00
|
|
|
_globalStdin = False,
|
2022-07-23 10:27:12 +03:00
|
|
|
_globalNoPositivity = False,
|
2023-03-27 11:42:27 +03:00
|
|
|
_globalNoCoverage = False,
|
2023-03-28 12:41:05 +03:00
|
|
|
_globalNoStdlib = False,
|
|
|
|
_globalUnrollLimit = defaultUnrollLimit
|
2022-06-09 17:36:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
-- | Get a parser for global flags which can be hidden or not depending on
|
|
|
|
-- the input boolean
|
2022-09-14 17:16:15 +03:00
|
|
|
parseGlobalFlags :: Parser GlobalOptions
|
|
|
|
parseGlobalFlags = do
|
2022-05-18 18:10:10 +03:00
|
|
|
_globalNoColors <-
|
|
|
|
switch
|
|
|
|
( long "no-colors"
|
2022-06-09 17:36:07 +03:00
|
|
|
<> help "Disable ANSI formatting"
|
2022-05-18 18:10:10 +03:00
|
|
|
)
|
|
|
|
_globalShowNameIds <-
|
|
|
|
switch
|
|
|
|
( long "show-name-ids"
|
|
|
|
<> help "Show the unique number of each identifier when pretty printing"
|
|
|
|
)
|
2023-01-06 19:54:13 +03:00
|
|
|
_globalBuildDir <-
|
|
|
|
optional
|
2023-01-09 17:09:02 +03:00
|
|
|
( parseBuildDir
|
|
|
|
( long "internal-build-dir"
|
|
|
|
<> help "Directory for compiler internal output"
|
2023-01-06 19:54:13 +03:00
|
|
|
)
|
|
|
|
)
|
2022-10-18 18:38:31 +03:00
|
|
|
_globalNoApe <-
|
|
|
|
switch
|
|
|
|
( long "no-format"
|
2023-01-09 17:09:02 +03:00
|
|
|
<> help "Disable the new pretty printing algorithm"
|
2022-10-18 18:38:31 +03:00
|
|
|
)
|
2022-08-19 17:57:07 +03:00
|
|
|
_globalStdin <-
|
|
|
|
switch
|
|
|
|
( long "stdin"
|
|
|
|
<> help "Read from Stdin"
|
|
|
|
)
|
2022-05-18 18:10:10 +03:00
|
|
|
_globalOnlyErrors <-
|
|
|
|
switch
|
|
|
|
( long "only-errors"
|
2022-07-08 14:59:45 +03:00
|
|
|
<> help "Only print errors in a uniform format (used by juvix-mode)"
|
2022-05-18 18:10:10 +03:00
|
|
|
)
|
2022-05-30 14:40:52 +03:00
|
|
|
_globalNoTermination <-
|
|
|
|
switch
|
|
|
|
( long "no-termination"
|
2022-06-09 17:36:07 +03:00
|
|
|
<> help "Disable termination checking"
|
2022-05-30 14:40:52 +03:00
|
|
|
)
|
2022-07-23 10:27:12 +03:00
|
|
|
_globalNoPositivity <-
|
|
|
|
switch
|
|
|
|
( long "no-positivity"
|
|
|
|
<> help "Disable positivity checking for inductive types"
|
|
|
|
)
|
2023-03-27 11:42:27 +03:00
|
|
|
_globalNoCoverage <-
|
|
|
|
switch
|
|
|
|
( long "no-coverage"
|
|
|
|
<> help "Disable coverage checking for patterns"
|
|
|
|
)
|
2022-06-30 12:31:08 +03:00
|
|
|
_globalNoStdlib <-
|
|
|
|
switch
|
|
|
|
( long "no-stdlib"
|
|
|
|
<> help "Do not use the standard library"
|
|
|
|
)
|
2023-03-28 12:41:05 +03:00
|
|
|
_globalUnrollLimit <-
|
|
|
|
option
|
|
|
|
(fromIntegral <$> naturalNumberOpt)
|
|
|
|
( long "unroll"
|
|
|
|
<> value defaultUnrollLimit
|
|
|
|
<> help ("Recursion unrolling limit (default: " <> show defaultUnrollLimit <> ")")
|
|
|
|
)
|
2022-09-14 17:16:15 +03:00
|
|
|
return GlobalOptions {..}
|
2023-01-09 17:09:02 +03:00
|
|
|
|
2023-04-19 17:56:48 +03:00
|
|
|
parseBuildDir :: Mod OptionFields (Prepath Dir) -> Parser (AppPath Dir)
|
2023-01-09 17:09:02 +03:00
|
|
|
parseBuildDir m = do
|
|
|
|
_pathPath <-
|
|
|
|
option
|
2023-04-19 17:56:48 +03:00
|
|
|
somePreDirOpt
|
2023-04-13 12:27:39 +03:00
|
|
|
( metavar "BUILD_DIR"
|
2023-01-09 17:09:02 +03:00
|
|
|
<> action "directory"
|
|
|
|
<> m
|
|
|
|
)
|
|
|
|
pure AppPath {_pathIsInput = False, ..}
|
2023-03-28 12:41:05 +03:00
|
|
|
|
2023-04-19 17:56:48 +03:00
|
|
|
entryPointFromGlobalOptionsPre :: Roots -> Prepath File -> GlobalOptions -> IO EntryPoint
|
|
|
|
entryPointFromGlobalOptionsPre roots premainFile opts = do
|
|
|
|
mainFile <- prepathToAbsFile (roots ^. rootsInvokeDir) premainFile
|
|
|
|
entryPointFromGlobalOptions roots mainFile opts
|
|
|
|
|
|
|
|
entryPointFromGlobalOptions :: Roots -> Path Abs File -> GlobalOptions -> IO EntryPoint
|
|
|
|
entryPointFromGlobalOptions roots mainFile opts = do
|
|
|
|
mabsBuildDir :: Maybe (Path Abs Dir) <- mapM (prepathToAbsDir cwd) optBuildDir
|
|
|
|
let def :: EntryPoint
|
|
|
|
def = defaultEntryPoint roots mainFile
|
|
|
|
return
|
|
|
|
def
|
|
|
|
{ _entryPointNoTermination = opts ^. globalNoTermination,
|
|
|
|
_entryPointNoPositivity = opts ^. globalNoPositivity,
|
|
|
|
_entryPointNoCoverage = opts ^. globalNoCoverage,
|
|
|
|
_entryPointNoStdlib = opts ^. globalNoStdlib,
|
|
|
|
_entryPointUnrollLimit = opts ^. globalUnrollLimit,
|
|
|
|
_entryPointGenericOptions = project opts,
|
|
|
|
_entryPointBuildDir = maybe (def ^. entryPointBuildDir) Abs mabsBuildDir
|
|
|
|
}
|
2023-04-13 12:27:39 +03:00
|
|
|
where
|
2023-04-19 17:56:48 +03:00
|
|
|
optBuildDir :: Maybe (Prepath Dir)
|
2023-04-13 12:27:39 +03:00
|
|
|
optBuildDir = fmap (^. pathPath) (opts ^. globalBuildDir)
|
2023-04-19 17:56:48 +03:00
|
|
|
cwd = roots ^. rootsInvokeDir
|
2023-04-27 18:33:08 +03:00
|
|
|
|
|
|
|
entryPointFromGlobalOptionsNoFile :: Roots -> GlobalOptions -> IO EntryPoint
|
|
|
|
entryPointFromGlobalOptionsNoFile roots opts = do
|
|
|
|
mabsBuildDir :: Maybe (Path Abs Dir) <- mapM (prepathToAbsDir cwd) optBuildDir
|
|
|
|
let def :: EntryPoint
|
|
|
|
def = defaultEntryPointNoFile roots
|
|
|
|
return
|
|
|
|
def
|
|
|
|
{ _entryPointNoTermination = opts ^. globalNoTermination,
|
|
|
|
_entryPointNoPositivity = opts ^. globalNoPositivity,
|
|
|
|
_entryPointNoCoverage = opts ^. globalNoCoverage,
|
|
|
|
_entryPointNoStdlib = opts ^. globalNoStdlib,
|
|
|
|
_entryPointUnrollLimit = opts ^. globalUnrollLimit,
|
|
|
|
_entryPointGenericOptions = project opts,
|
|
|
|
_entryPointBuildDir = maybe (def ^. entryPointBuildDir) Abs mabsBuildDir
|
|
|
|
}
|
|
|
|
where
|
|
|
|
optBuildDir :: Maybe (Prepath Dir)
|
|
|
|
optBuildDir = fmap (^. pathPath) (opts ^. globalBuildDir)
|
|
|
|
cwd = roots ^. rootsInvokeDir
|