2022-05-30 14:40:52 +03:00
|
|
|
module GlobalOptions
|
|
|
|
( module GlobalOptions,
|
2023-12-06 20:24:59 +03:00
|
|
|
module Juvix.Data.Effect.TaggedLock,
|
2022-05-30 14:40:52 +03:00
|
|
|
)
|
|
|
|
where
|
2022-05-18 18:10:10 +03:00
|
|
|
|
2022-12-20 15:05:40 +03:00
|
|
|
import CommonOptions
|
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
|
2023-12-30 22:15:35 +03:00
|
|
|
import Juvix.Compiler.Pipeline.Root
|
2023-12-06 20:24:59 +03:00
|
|
|
import Juvix.Data.Effect.TaggedLock
|
2022-09-01 14:22:32 +03:00
|
|
|
import Juvix.Data.Error.GenericError qualified as E
|
2024-02-27 16:54:43 +03:00
|
|
|
import Juvix.Data.Field
|
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-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,
|
2023-09-05 18:11:17 +03:00
|
|
|
_globalUnrollLimit :: Int,
|
2024-02-27 16:54:43 +03:00
|
|
|
_globalFieldSize :: Maybe Natural,
|
2023-12-01 18:50:37 +03:00
|
|
|
_globalOffline :: Bool
|
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 =
|
2023-06-20 12:02:37 +03:00
|
|
|
Internal.defaultOptions
|
2022-09-12 11:44:00 +03:00
|
|
|
{ Internal._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
|
2023-05-24 11:46:18 +03:00
|
|
|
{ E._showNameIds = _globalShowNameIds
|
2022-10-18 18:38:31 +03:00
|
|
|
}
|
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,
|
2024-02-27 16:54:43 +03:00
|
|
|
Core._optFieldSize = fromMaybe defaultFieldSize _globalFieldSize,
|
2023-05-15 18:27:05 +03:00
|
|
|
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,
|
|
|
|
_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,
|
2023-09-05 18:11:17 +03:00
|
|
|
_globalUnrollLimit = defaultUnrollLimit,
|
2024-02-27 16:54:43 +03:00
|
|
|
_globalFieldSize = Nothing,
|
2023-12-01 18:50:37 +03:00
|
|
|
_globalOffline = False
|
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
|
|
|
)
|
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-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"
|
|
|
|
)
|
2024-02-27 16:54:43 +03:00
|
|
|
_globalFieldSize <-
|
|
|
|
option
|
|
|
|
fieldSizeOpt
|
|
|
|
( long "field-size"
|
|
|
|
<> value Nothing
|
|
|
|
<> help "Field type size [cairo,small,11] (default: small)"
|
|
|
|
)
|
2023-03-28 12:41:05 +03:00
|
|
|
_globalUnrollLimit <-
|
|
|
|
option
|
|
|
|
(fromIntegral <$> naturalNumberOpt)
|
|
|
|
( long "unroll"
|
|
|
|
<> value defaultUnrollLimit
|
|
|
|
<> help ("Recursion unrolling limit (default: " <> show defaultUnrollLimit <> ")")
|
|
|
|
)
|
2023-09-05 18:11:17 +03:00
|
|
|
_globalOffline <-
|
|
|
|
switch
|
|
|
|
( long "offline"
|
|
|
|
<> help "Disable access to network resources"
|
|
|
|
)
|
2023-11-12 18:23:33 +03:00
|
|
|
_globalShowNameIds <-
|
|
|
|
switch
|
|
|
|
( long "show-name-ids"
|
|
|
|
<> help "[DEV] Show the unique number of each identifier when pretty printing"
|
|
|
|
)
|
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
|
|
|
|
2024-02-13 21:00:01 +03:00
|
|
|
entryPointFromGlobalOptionsPre :: (Members '[TaggedLock, EmbedIO] r) => Root -> Prepath File -> GlobalOptions -> Sem r EntryPoint
|
2023-10-30 16:05:52 +03:00
|
|
|
entryPointFromGlobalOptionsPre root premainFile opts = do
|
2023-12-06 20:24:59 +03:00
|
|
|
mainFile <- liftIO (prepathToAbsFile (root ^. rootInvokeDir) premainFile)
|
2023-10-30 16:05:52 +03:00
|
|
|
entryPointFromGlobalOptions root mainFile opts
|
2023-04-19 17:56:48 +03:00
|
|
|
|
2024-02-13 21:00:01 +03:00
|
|
|
entryPointFromGlobalOptions :: (Members '[TaggedLock, EmbedIO] r) => Root -> Path Abs File -> GlobalOptions -> Sem r EntryPoint
|
2023-10-30 16:05:52 +03:00
|
|
|
entryPointFromGlobalOptions root mainFile opts = do
|
2023-12-06 20:24:59 +03:00
|
|
|
mabsBuildDir :: Maybe (Path Abs Dir) <- liftIO (mapM (prepathToAbsDir cwd) optBuildDir)
|
|
|
|
pkg <- readPackageRootIO root
|
2023-04-19 17:56:48 +03:00
|
|
|
let def :: EntryPoint
|
2023-12-06 20:24:59 +03:00
|
|
|
def = defaultEntryPoint pkg root mainFile
|
2023-04-19 17:56:48 +03:00
|
|
|
return
|
|
|
|
def
|
|
|
|
{ _entryPointNoTermination = opts ^. globalNoTermination,
|
|
|
|
_entryPointNoPositivity = opts ^. globalNoPositivity,
|
|
|
|
_entryPointNoCoverage = opts ^. globalNoCoverage,
|
|
|
|
_entryPointNoStdlib = opts ^. globalNoStdlib,
|
|
|
|
_entryPointUnrollLimit = opts ^. globalUnrollLimit,
|
|
|
|
_entryPointGenericOptions = project opts,
|
2023-11-07 21:11:02 +03:00
|
|
|
_entryPointBuildDir = maybe (def ^. entryPointBuildDir) (CustomBuildDir . Abs) mabsBuildDir,
|
2024-02-27 16:54:43 +03:00
|
|
|
_entryPointOffline = opts ^. globalOffline,
|
|
|
|
_entryPointFieldSize = fromMaybe defaultFieldSize $ opts ^. globalFieldSize
|
2023-04-19 17:56:48 +03:00
|
|
|
}
|
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-10-30 16:05:52 +03:00
|
|
|
cwd = root ^. rootInvokeDir
|
2023-04-27 18:33:08 +03:00
|
|
|
|
2024-02-13 21:00:01 +03:00
|
|
|
entryPointFromGlobalOptionsNoFile :: (Members '[EmbedIO, TaggedLock] r, MonadIO (Sem r)) => Root -> GlobalOptions -> Sem r EntryPoint
|
2023-10-30 16:05:52 +03:00
|
|
|
entryPointFromGlobalOptionsNoFile root opts = do
|
2023-04-27 18:33:08 +03:00
|
|
|
mabsBuildDir :: Maybe (Path Abs Dir) <- mapM (prepathToAbsDir cwd) optBuildDir
|
2023-12-06 20:24:59 +03:00
|
|
|
pkg <- readPackageRootIO root
|
2023-04-27 18:33:08 +03:00
|
|
|
let def :: EntryPoint
|
2023-12-06 20:24:59 +03:00
|
|
|
def = defaultEntryPointNoFile pkg root
|
2023-04-27 18:33:08 +03:00
|
|
|
return
|
|
|
|
def
|
|
|
|
{ _entryPointNoTermination = opts ^. globalNoTermination,
|
|
|
|
_entryPointNoPositivity = opts ^. globalNoPositivity,
|
|
|
|
_entryPointNoCoverage = opts ^. globalNoCoverage,
|
|
|
|
_entryPointNoStdlib = opts ^. globalNoStdlib,
|
|
|
|
_entryPointUnrollLimit = opts ^. globalUnrollLimit,
|
|
|
|
_entryPointGenericOptions = project opts,
|
2023-11-07 21:11:02 +03:00
|
|
|
_entryPointBuildDir = maybe (def ^. entryPointBuildDir) (CustomBuildDir . Abs) mabsBuildDir,
|
2024-02-27 16:54:43 +03:00
|
|
|
_entryPointOffline = opts ^. globalOffline,
|
|
|
|
_entryPointFieldSize = fromMaybe defaultFieldSize $ opts ^. globalFieldSize
|
2023-04-27 18:33:08 +03:00
|
|
|
}
|
|
|
|
where
|
|
|
|
optBuildDir :: Maybe (Prepath Dir)
|
|
|
|
optBuildDir = fmap (^. pathPath) (opts ^. globalBuildDir)
|
2023-10-30 16:05:52 +03:00
|
|
|
cwd = root ^. rootInvokeDir
|