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

Slightly improve prettyprinting for Core #2094

Merged
merged 1 commit into from
May 15, 2023
Merged
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
27 changes: 15 additions & 12 deletions src/Juvix/Compiler/Core/Pretty/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ ppCodeLet' name mty lt = do
mempty <+> kwColon <+> ty
Nothing ->
mempty
return $ kwLet <+> n' <> tty <+> kwAssign <+> v' <+> kwIn <+> b'
return $ kwLet <+> n' <> tty <+> kwAssign <> oneLineOrNext v' <+> kwIn <> line <> b'

ppCodeCase' :: (PrettyCode a, Member (Reader Options) r) => [[Text]] -> [[Maybe (Doc Ann)]] -> [Text] -> Case' i bi a ty -> Sem r (Doc Ann)
ppCodeCase' branchBinderNames branchBinderTypes branchTagNames Case {..} =
Expand Down Expand Up @@ -297,6 +297,18 @@ instance PrettyCode LetRec where
getName :: Binder -> Sem r (Doc Ann)
getName i = ppName KNameLocal (i ^. binderName)

instance PrettyCode Lambda where
ppCode (Lambda _ bi body) = do
b <- ppCode body
lam <- do
n <- ppName KNameLocal (bi ^. binderName)
case bi ^. binderType of
NDyn {} -> return $ kwLambda <> n
ty -> do
tty <- ppCode ty
return $ kwLambda <> parens (n <+> kwColon <+> tty)
return (lam <> oneLineOrNext b)

instance PrettyCode Node where
ppCode :: forall r. (Member (Reader Options) r) => Node -> Sem r (Doc Ann)
ppCode node = case node of
Expand All @@ -312,16 +324,7 @@ instance PrettyCode Node where
NCtr x ->
let name = getInfoName (x ^. constrInfo)
in ppCodeConstr' name x
NLam (Lambda _ bi body) -> do
b <- ppCode body
lam <- do
n <- ppName KNameLocal (bi ^. binderName)
case bi ^. binderType of
NDyn {} -> return $ kwLambda <> n
ty -> do
tty <- ppCode ty
return $ kwLambda <> parens (n <+> kwColon <+> tty)
return (lam <+> b)
NLam l -> ppCode l
NLet x -> ppCode x
NRec l -> ppCode l
NCase x@Case {..} -> do
Expand Down Expand Up @@ -475,7 +478,7 @@ instance PrettyCode InfoTable where
case msig of
Just sig -> do
body' <- ppCode n
return (Just (sig <+> kwAssign <+> nest' body' <> kwSemicolon))
return (Just (sig <+> kwAssign <> oneLineOrNext body' <> kwSemicolon))
Nothing ->
return Nothing

Expand Down