2022-09-14 17:16:15 +03:00
|
|
|
module Commands.Dev.Core.Read.Options where
|
|
|
|
|
2022-10-21 20:13:06 +03:00
|
|
|
import Commands.Dev.Core.Eval.Options qualified as Eval
|
2022-09-14 17:16:15 +03:00
|
|
|
import CommonOptions
|
2022-11-14 18:03:28 +03:00
|
|
|
import Evaluator qualified
|
2022-12-15 11:52:26 +03:00
|
|
|
import Juvix.Compiler.Core.Data.TransformationId
|
2022-09-14 17:16:15 +03:00
|
|
|
import Juvix.Compiler.Core.Pretty.Options qualified as Core
|
|
|
|
|
|
|
|
data CoreReadOptions = CoreReadOptions
|
|
|
|
{ _coreReadTransformations :: [TransformationId],
|
|
|
|
_coreReadShowDeBruijn :: Bool,
|
2023-03-15 18:41:39 +03:00
|
|
|
_coreReadShowIdentIds :: Bool,
|
2023-03-30 14:23:40 +03:00
|
|
|
_coreReadShowArgsNum :: Bool,
|
2023-03-15 18:41:39 +03:00
|
|
|
_coreReadNoDisambiguate :: Bool,
|
2022-10-21 20:13:06 +03:00
|
|
|
_coreReadEval :: Bool,
|
2023-05-15 19:01:40 +03:00
|
|
|
_coreReadNormalize :: Bool,
|
2022-10-21 20:13:06 +03:00
|
|
|
_coreReadNoPrint :: Bool,
|
2022-12-20 15:05:40 +03:00
|
|
|
_coreReadInputFile :: AppPath File
|
2022-09-14 17:16:15 +03:00
|
|
|
}
|
|
|
|
deriving stock (Data)
|
|
|
|
|
|
|
|
makeLenses ''CoreReadOptions
|
|
|
|
|
|
|
|
instance CanonicalProjection CoreReadOptions Core.Options where
|
|
|
|
project c =
|
|
|
|
Core.defaultOptions
|
2023-03-15 18:41:39 +03:00
|
|
|
{ Core._optShowDeBruijnIndices = c ^. coreReadShowDeBruijn,
|
2023-03-30 14:23:40 +03:00
|
|
|
Core._optShowIdentIds = c ^. coreReadShowIdentIds,
|
|
|
|
Core._optShowArgsNum = c ^. coreReadShowArgsNum
|
2022-09-14 17:16:15 +03:00
|
|
|
}
|
|
|
|
|
2022-10-21 20:13:06 +03:00
|
|
|
instance CanonicalProjection CoreReadOptions Eval.CoreEvalOptions where
|
|
|
|
project c =
|
|
|
|
Eval.CoreEvalOptions
|
|
|
|
{ _coreEvalNoIO = False,
|
|
|
|
_coreEvalInputFile = c ^. coreReadInputFile,
|
2023-03-15 18:41:39 +03:00
|
|
|
_coreEvalShowDeBruijn = c ^. coreReadShowDeBruijn,
|
|
|
|
_coreEvalShowIdentIds = c ^. coreReadShowIdentIds,
|
2023-03-30 14:23:40 +03:00
|
|
|
_coreEvalShowArgsNum = c ^. coreReadShowArgsNum,
|
2023-03-15 18:41:39 +03:00
|
|
|
_coreEvalNoDisambiguate = c ^. coreReadNoDisambiguate
|
2022-10-21 20:13:06 +03:00
|
|
|
}
|
|
|
|
|
2022-11-07 16:47:56 +03:00
|
|
|
instance CanonicalProjection CoreReadOptions Evaluator.EvalOptions where
|
|
|
|
project x =
|
|
|
|
Evaluator.EvalOptions
|
|
|
|
{ _evalNoIO = False,
|
2023-03-15 18:41:39 +03:00
|
|
|
_evalNoDisambiguate = x ^. coreReadNoDisambiguate,
|
2023-06-06 13:35:01 +03:00
|
|
|
_evalInputFile = x ^. coreReadInputFile,
|
|
|
|
_evalPrintValues = False
|
2022-11-07 16:47:56 +03:00
|
|
|
}
|
|
|
|
|
2022-09-14 17:16:15 +03:00
|
|
|
parseCoreReadOptions :: Parser CoreReadOptions
|
|
|
|
parseCoreReadOptions = do
|
|
|
|
_coreReadShowDeBruijn <- optDeBruijn
|
2023-03-15 18:41:39 +03:00
|
|
|
_coreReadShowIdentIds <- optIdentIds
|
2023-03-30 14:23:40 +03:00
|
|
|
_coreReadShowArgsNum <- optArgsNum
|
2023-03-15 18:41:39 +03:00
|
|
|
_coreReadNoDisambiguate <- optNoDisambiguate
|
2022-10-21 20:13:06 +03:00
|
|
|
_coreReadNoPrint <-
|
|
|
|
switch
|
|
|
|
( long "no-print"
|
|
|
|
<> help "do not print the transformed code"
|
|
|
|
)
|
|
|
|
_coreReadEval <-
|
|
|
|
switch
|
|
|
|
( long "eval"
|
|
|
|
<> help "evaluate after the transformation"
|
|
|
|
)
|
2023-05-15 19:01:40 +03:00
|
|
|
_coreReadNormalize <-
|
|
|
|
switch
|
|
|
|
( long "normalize"
|
|
|
|
<> help "normalize after the transformation"
|
|
|
|
)
|
2022-12-15 11:52:26 +03:00
|
|
|
_coreReadTransformations <- optTransformationIds
|
2023-10-25 13:02:12 +03:00
|
|
|
_coreReadInputFile <- parseInputFile FileExtJuvixCore
|
2022-09-14 17:16:15 +03:00
|
|
|
pure CoreReadOptions {..}
|