Skip to content

Commit

Permalink
Merge pull request #476 from tomsmeding/pprint-fixes
Browse files Browse the repository at this point in the history
Pretty printing fixes
  • Loading branch information
tmcdonell authored Oct 23, 2020
2 parents c48d169 + 1197faf commit f05f383
Showing 1 changed file with 7 additions and 6 deletions.
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

0 comments on commit f05f383

Please sign in to comment.