1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-25 00:21:41 +03:00
juvix/app/Commands/Dev/Core/Read/Options.hs
Łukasz Czajka 98b1daec7d
Print JuvixCore correctly (#1875)
Print JuvixCore InfoTable in such a way that it can be parsed back by
the JuvixCore parser.

* Depends on PR #1832 
* Depends on PR #1862 
* Closes #1841 
* Adds "JuvixCore print" tests which read the files from
Core/positive/*.jvc, print them, read them back and check if the
evaluation results are preserved.

---------

Co-authored-by: Jan Mas Rovira <janmasrovira@gmail.com>
2023-03-15 16:41:39 +01:00

65 lines
2.0 KiB
Haskell

module Commands.Dev.Core.Read.Options where
import Commands.Dev.Core.Eval.Options qualified as Eval
import CommonOptions
import Evaluator qualified
import Juvix.Compiler.Core.Data.TransformationId
import Juvix.Compiler.Core.Pretty.Options qualified as Core
data CoreReadOptions = CoreReadOptions
{ _coreReadTransformations :: [TransformationId],
_coreReadShowDeBruijn :: Bool,
_coreReadShowIdentIds :: Bool,
_coreReadNoDisambiguate :: Bool,
_coreReadEval :: Bool,
_coreReadNoPrint :: Bool,
_coreReadInputFile :: AppPath File
}
deriving stock (Data)
makeLenses ''CoreReadOptions
instance CanonicalProjection CoreReadOptions Core.Options where
project c =
Core.defaultOptions
{ Core._optShowDeBruijnIndices = c ^. coreReadShowDeBruijn,
Core._optShowIdentIds = c ^. coreReadShowIdentIds
}
instance CanonicalProjection CoreReadOptions Eval.CoreEvalOptions where
project c =
Eval.CoreEvalOptions
{ _coreEvalNoIO = False,
_coreEvalInputFile = c ^. coreReadInputFile,
_coreEvalShowDeBruijn = c ^. coreReadShowDeBruijn,
_coreEvalShowIdentIds = c ^. coreReadShowIdentIds,
_coreEvalNoDisambiguate = c ^. coreReadNoDisambiguate
}
instance CanonicalProjection CoreReadOptions Evaluator.EvalOptions where
project x =
Evaluator.EvalOptions
{ _evalNoIO = False,
_evalNoDisambiguate = x ^. coreReadNoDisambiguate,
_evalInputFile = x ^. coreReadInputFile
}
parseCoreReadOptions :: Parser CoreReadOptions
parseCoreReadOptions = do
_coreReadShowDeBruijn <- optDeBruijn
_coreReadShowIdentIds <- optIdentIds
_coreReadNoDisambiguate <- optNoDisambiguate
_coreReadNoPrint <-
switch
( long "no-print"
<> help "do not print the transformed code"
)
_coreReadEval <-
switch
( long "eval"
<> help "evaluate after the transformation"
)
_coreReadTransformations <- optTransformationIds
_coreReadInputFile <- parseInputJuvixCoreFile
pure CoreReadOptions {..}