Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option --show-args-num #1946

Merged
merged 2 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/Commands/Dev/Core/Eval/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data CoreEvalOptions = CoreEvalOptions
_coreEvalInputFile :: AppPath File,
_coreEvalShowDeBruijn :: Bool,
_coreEvalShowIdentIds :: Bool,
_coreEvalShowArgsNum :: Bool,
_coreEvalNoDisambiguate :: Bool
}
deriving stock (Data)
Expand All @@ -19,7 +20,8 @@ instance CanonicalProjection CoreEvalOptions Core.Options where
project c =
Core.defaultOptions
{ Core._optShowDeBruijnIndices = c ^. coreEvalShowDeBruijn,
Core._optShowIdentIds = c ^. coreEvalShowIdentIds
Core._optShowIdentIds = c ^. coreEvalShowIdentIds,
Core._optShowArgsNum = c ^. coreEvalShowArgsNum
}

instance CanonicalProjection CoreEvalOptions Eval.EvalOptions where
Expand All @@ -39,6 +41,7 @@ parseCoreEvalOptions = do
)
_coreEvalShowDeBruijn <- optDeBruijn
_coreEvalShowIdentIds <- optIdentIds
_coreEvalShowArgsNum <- optArgsNum
_coreEvalNoDisambiguate <- optNoDisambiguate
_coreEvalInputFile <- parseInputJuvixCoreFile
pure CoreEvalOptions {..}
5 changes: 4 additions & 1 deletion app/Commands/Dev/Core/FromConcrete/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data CoreFromConcreteOptions = CoreFromConcreteOptions
{ _coreFromConcreteTransformations :: [TransformationId],
_coreFromConcreteShowDeBruijn :: Bool,
_coreFromConcreteShowIdentIds :: Bool,
_coreFromConcreteShowArgsNum :: Bool,
_coreFromConcreteNoDisambiguate :: Bool,
_coreFromConcreteFilter :: Bool,
_coreFromConcreteNoIO :: Bool,
Expand All @@ -24,7 +25,8 @@ instance CanonicalProjection CoreFromConcreteOptions Core.Options where
project c =
Core.defaultOptions
{ Core._optShowDeBruijnIndices = c ^. coreFromConcreteShowDeBruijn,
Core._optShowIdentIds = c ^. coreFromConcreteShowIdentIds
Core._optShowIdentIds = c ^. coreFromConcreteShowIdentIds,
Core._optShowArgsNum = c ^. coreFromConcreteShowArgsNum
}

instance CanonicalProjection CoreFromConcreteOptions Eval.EvalOptions where
Expand All @@ -40,6 +42,7 @@ parseCoreFromConcreteOptions = do
_coreFromConcreteTransformations <- optTransformationIds
_coreFromConcreteShowDeBruijn <- optDeBruijn
_coreFromConcreteShowIdentIds <- optIdentIds
_coreFromConcreteShowArgsNum <- optArgsNum
_coreFromConcreteNoDisambiguate <- optNoDisambiguate
_coreFromConcreteFilter <-
switch
Expand Down
6 changes: 5 additions & 1 deletion app/Commands/Dev/Core/Read/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ data CoreReadOptions = CoreReadOptions
{ _coreReadTransformations :: [TransformationId],
_coreReadShowDeBruijn :: Bool,
_coreReadShowIdentIds :: Bool,
_coreReadShowArgsNum :: Bool,
_coreReadNoDisambiguate :: Bool,
_coreReadEval :: Bool,
_coreReadNoPrint :: Bool,
Expand All @@ -23,7 +24,8 @@ instance CanonicalProjection CoreReadOptions Core.Options where
project c =
Core.defaultOptions
{ Core._optShowDeBruijnIndices = c ^. coreReadShowDeBruijn,
Core._optShowIdentIds = c ^. coreReadShowIdentIds
Core._optShowIdentIds = c ^. coreReadShowIdentIds,
Core._optShowArgsNum = c ^. coreReadShowArgsNum
}

instance CanonicalProjection CoreReadOptions Eval.CoreEvalOptions where
Expand All @@ -33,6 +35,7 @@ instance CanonicalProjection CoreReadOptions Eval.CoreEvalOptions where
_coreEvalInputFile = c ^. coreReadInputFile,
_coreEvalShowDeBruijn = c ^. coreReadShowDeBruijn,
_coreEvalShowIdentIds = c ^. coreReadShowIdentIds,
_coreEvalShowArgsNum = c ^. coreReadShowArgsNum,
_coreEvalNoDisambiguate = c ^. coreReadNoDisambiguate
}

Expand All @@ -48,6 +51,7 @@ parseCoreReadOptions :: Parser CoreReadOptions
parseCoreReadOptions = do
_coreReadShowDeBruijn <- optDeBruijn
_coreReadShowIdentIds <- optIdentIds
_coreReadShowArgsNum <- optArgsNum
_coreReadNoDisambiguate <- optNoDisambiguate
_coreReadNoPrint <-
switch
Expand Down
7 changes: 5 additions & 2 deletions app/Commands/Dev/Core/Repl/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import Juvix.Compiler.Core.Pretty.Options qualified as Core

data CoreReplOptions = CoreReplOptions
{ _coreReplShowDeBruijn :: Bool,
_coreReplShowIdentIds :: Bool
_coreReplShowIdentIds :: Bool,
_coreReplShowArgsNum :: Bool
}
deriving stock (Data)

Expand All @@ -15,11 +16,13 @@ instance CanonicalProjection CoreReplOptions Core.Options where
project c =
Core.defaultOptions
{ Core._optShowDeBruijnIndices = c ^. coreReplShowDeBruijn,
Core._optShowIdentIds = c ^. coreReplShowIdentIds
Core._optShowIdentIds = c ^. coreReplShowIdentIds,
Core._optShowArgsNum = c ^. coreReplShowArgsNum
}

parseCoreReplOptions :: Parser CoreReplOptions
parseCoreReplOptions = do
_coreReplShowDeBruijn <- optDeBruijn
_coreReplShowIdentIds <- optIdentIds
_coreReplShowArgsNum <- optArgsNum
pure CoreReplOptions {..}
7 changes: 7 additions & 0 deletions app/CommonOptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ optIdentIds =
<> help "Show identifier IDs"
)

optArgsNum :: Parser Bool
optArgsNum =
switch
( long "show-args-num"
<> help "Show identifier arguments number"
)

optNoDisambiguate :: Parser Bool
optNoDisambiguate =
switch
Expand Down
6 changes: 4 additions & 2 deletions src/Juvix/Compiler/Core/Pretty/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,15 @@ instance PrettyCode InfoTable where
case mii of
Nothing -> return Nothing
Just ii -> do
let ty = ii ^. identifierType
showArgsNum <- asks (^. optShowArgsNum)
let argsNum = if showArgsNum then brackets (pretty (ii ^. identifierArgsNum)) else mempty
ty = ii ^. identifierType
ty' <- ppCode ty
let tydoc
| isDynamic ty = mempty
| otherwise = space <> colon <+> ty'
blt = if isJust (ii ^. identifierBuiltin) then (Str.builtin <+> mempty) else mempty
return (Just (blt <> kwDef <+> sym' <> tydoc))
return (Just (blt <> kwDef <+> sym' <> argsNum <> tydoc))

ppSigs :: [IdentifierInfo] -> Sem r (Doc Ann)
ppSigs idents = do
Expand Down
9 changes: 6 additions & 3 deletions src/Juvix/Compiler/Core/Pretty/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import Juvix.Prelude

data Options = Options
{ _optShowIdentIds :: Bool,
_optShowDeBruijnIndices :: Bool
_optShowDeBruijnIndices :: Bool,
_optShowArgsNum :: Bool
}

makeLenses ''Options
Expand All @@ -13,14 +14,16 @@ defaultOptions :: Options
defaultOptions =
Options
{ _optShowIdentIds = False,
_optShowDeBruijnIndices = False
_optShowDeBruijnIndices = False,
_optShowArgsNum = False
}

traceOptions :: Options
traceOptions =
Options
{ _optShowIdentIds = False,
_optShowDeBruijnIndices = True
_optShowDeBruijnIndices = True,
_optShowArgsNum = True
}

fromGenericOptions :: GenericOptions -> Options
Expand Down
2 changes: 1 addition & 1 deletion src/Juvix/Compiler/Core/Transformation/RemoveTypeArgs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ convertIdent tab ii =
zipExact tyargs' $
map fst $
filter (not . isTypeConstr tab . snd) (zipExact (ii ^. identifierArgsInfo) tyargs),
_identifierArgsNum = length (typeArgs ty')
_identifierArgsNum = length tyargs'
}
where
tyargs = typeArgs (ii ^. identifierType)
Expand Down