1
1
mirror of https://github.com/anoma/juvix.git synced 2025-01-05 22:46:08 +03:00

Print values in juvix eval (#2179)

* Closes #2177
This commit is contained in:
Łukasz Czajka 2023-06-06 12:35:01 +02:00 committed by GitHub
parent 108ccf7dcf
commit 5d85cb44f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 25 deletions

View File

@ -29,7 +29,8 @@ instance CanonicalProjection CoreEvalOptions Eval.EvalOptions where
Eval.EvalOptions
{ _evalInputFile = c ^. coreEvalInputFile,
_evalNoIO = c ^. coreEvalNoIO,
_evalNoDisambiguate = c ^. coreEvalNoDisambiguate
_evalNoDisambiguate = c ^. coreEvalNoDisambiguate,
_evalPrintValues = False
}
parseCoreEvalOptions :: Parser CoreEvalOptions

View File

@ -35,7 +35,8 @@ instance CanonicalProjection CoreFromConcreteOptions Eval.EvalOptions where
Eval.EvalOptions
{ _evalInputFile = c ^. coreFromConcreteInputFile,
_evalNoIO = c ^. coreFromConcreteNoIO,
_evalNoDisambiguate = c ^. coreFromConcreteNoDisambiguate
_evalNoDisambiguate = c ^. coreFromConcreteNoDisambiguate,
_evalPrintValues = False
}
parseCoreFromConcreteOptions :: Parser CoreFromConcreteOptions

View File

@ -28,7 +28,8 @@ instance CanonicalProjection CoreNormalizeOptions Eval.EvalOptions where
Eval.EvalOptions
{ _evalInputFile = c ^. coreNormalizeInputFile,
_evalNoIO = True,
_evalNoDisambiguate = c ^. coreNormalizeNoDisambiguate
_evalNoDisambiguate = c ^. coreNormalizeNoDisambiguate,
_evalPrintValues = False
}
parseCoreNormalizeOptions :: Parser CoreNormalizeOptions

View File

@ -45,7 +45,8 @@ instance CanonicalProjection CoreReadOptions Evaluator.EvalOptions where
Evaluator.EvalOptions
{ _evalNoIO = False,
_evalNoDisambiguate = x ^. coreReadNoDisambiguate,
_evalInputFile = x ^. coreReadInputFile
_evalInputFile = x ^. coreReadInputFile,
_evalPrintValues = False
}
parseCoreReadOptions :: Parser CoreReadOptions

View File

@ -5,9 +5,7 @@ import Evaluator qualified as Eval
import Juvix.Compiler.Core.Pretty.Options qualified as Core
data EvalOptions = EvalOptions
{ _evalShowDeBruijn :: Bool,
_evalNoIO :: Bool,
_evalInputFile :: AppPath File,
{ _evalInputFile :: AppPath File,
_evalSymbolName :: Maybe Text
}
deriving stock (Data)
@ -15,31 +13,22 @@ data EvalOptions = EvalOptions
makeLenses ''EvalOptions
instance CanonicalProjection EvalOptions Core.Options where
project c =
project _ =
Core.defaultOptions
{ Core._optShowDeBruijnIndices = c ^. evalShowDeBruijn
{ Core._optShowDeBruijnIndices = False
}
instance CanonicalProjection EvalOptions Eval.EvalOptions where
project c =
Eval.EvalOptions
{ _evalInputFile = c ^. evalInputFile,
_evalNoIO = c ^. evalNoIO,
_evalNoDisambiguate = False
_evalNoIO = False,
_evalNoDisambiguate = False,
_evalPrintValues = True
}
parseEvalOptions :: Parser EvalOptions
parseEvalOptions = do
_evalShowDeBruijn <-
switch
( long "show-de-bruijn"
<> help "Show variable de Bruijn indices"
)
_evalNoIO <-
switch
( long "no-io"
<> help "Don't interpret the IO effects"
)
_evalInputFile <- parseInputJuvixFile
_evalSymbolName <-
optional $

View File

@ -6,6 +6,7 @@ import Juvix.Compiler.Core.Data.InfoTable qualified as Core
import Juvix.Compiler.Core.Error qualified as Core
import Juvix.Compiler.Core.Evaluator qualified as Core
import Juvix.Compiler.Core.Extra.Base qualified as Core
import Juvix.Compiler.Core.Extra.Value qualified as Core
import Juvix.Compiler.Core.Info qualified as Info
import Juvix.Compiler.Core.Info.NoDisplayInfo qualified as Info
import Juvix.Compiler.Core.Language qualified as Core
@ -16,7 +17,8 @@ import Juvix.Compiler.Core.Transformation.DisambiguateNames qualified as Core
data EvalOptions = EvalOptions
{ _evalInputFile :: AppPath File,
_evalNoIO :: Bool,
_evalNoDisambiguate :: Bool
_evalNoDisambiguate :: Bool,
_evalPrintValues :: Bool
}
makeLenses ''EvalOptions
@ -56,9 +58,13 @@ evalAndPrint opts tab node = do
Right node'
| Info.member Info.kNoDisplayInfo (Core.getInfo node') ->
return ()
Right node' -> do
renderStdOut (Core.ppOut opts node'')
embed (putStrLn "")
Right node'
| project opts ^. evalPrintValues -> do
renderStdOut (Core.ppOut opts (Core.toValue tab node'))
newline
| otherwise -> do
renderStdOut (Core.ppOut opts node'')
newline
where
node'' = if project opts ^. evalNoDisambiguate then node' else Core.disambiguateNodeNames tab node'
where