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

Pretty printing fixes #476

Merged
merged 2 commits into from
Oct 23, 2020
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
13 changes: 7 additions & 6 deletions src/Data/Array/Accelerate/Pretty/Print.hs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ prettyPreOpenAcc ctx prettyAcc extractAcc aenv pacc =
case pacc of
Avar (Var _ idx) -> prj idx aenv
Alet{} -> prettyAlet ctx prettyAcc extractAcc aenv pacc
Apair{} -> prettyAtuple prettyAcc extractAcc aenv pacc
Apair{} -> prettyAtuple ctx prettyAcc extractAcc aenv pacc
Anil -> "()"
Apply _ f a -> apply
where
Expand Down Expand Up @@ -225,7 +225,7 @@ prettyAlet
-> PreOpenAcc acc aenv arrs
-> Adoc
prettyAlet ctx prettyAcc extractAcc aenv0
= parensIf (needsParens ctx "let")
= parensIf (ctxPrecedence ctx > 0)
. align . wrap . collect aenv0
where
collect :: Val aenv' -> PreOpenAcc acc aenv' a -> ([Adoc], Adoc)
Expand Down Expand Up @@ -261,18 +261,19 @@ prettyAlet ctx prettyAcc extractAcc aenv0

prettyAtuple
:: forall acc aenv arrs.
PrettyAcc acc
Context
-> PrettyAcc acc
-> ExtractAcc acc
-> Val aenv
-> PreOpenAcc acc aenv arrs
-> Adoc
prettyAtuple prettyAcc extractAcc aenv0 acc = case collect acc of
prettyAtuple ctx prettyAcc extractAcc aenv0 acc = case collect acc of
Nothing -> align $ ppPair acc
Just tup ->
case tup of
[] -> "()"
[t] -> t
_ -> align $ "T" <> pretty (length tup) <+> sep tup
_ -> align $ parensIf (ctxPrecedence ctx > 0) ("T" <> pretty (length tup) <+> sep tup)
where
ppPair :: PreOpenAcc acc aenv arrs' -> Adoc
ppPair (Apair a1 a2) = "(" <> ppPair (extractAcc a1) <> "," <+> prettyAcc context0 aenv0 a2 <> ")"
Expand Down Expand Up @@ -455,7 +456,7 @@ prettyLet
-> OpenExp env aenv t
-> Adoc
prettyLet ctx env0 aenv
= parensIf (needsParens ctx "let")
= parensIf (ctxPrecedence ctx > 0)
. align . wrap . collect env0
where
collect :: Val env' -> OpenExp env' aenv e -> ([Adoc], Adoc)
Expand Down