Skip to content

Commit

Permalink
Expression statements are so evil and non-portable… how about some la…
Browse files Browse the repository at this point in the history
…mbdas instead?

[Ugly hack so pretty printer generades lambdas instead of ({}) in hope of fixing issues with portability of kernels generated by accelerate-cuda.
  • Loading branch information
mwu-tow committed Aug 14, 2015
1 parent 7a126cd commit e670cfd
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Language/C/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,18 @@ instance Pretty Exp where
pprInit (Just d, ini) = ppr d <+> text "=" <+/> ppr ini

pprPrec _ (StmExpr blockItems loc) =
pprLoc loc $ parens $
ppr blockItems
-- Here comes the ugly hack to replace statement expressions with C++11
-- lambda expressions that are defined and called in place.
let addReturnToBlockStm (BlockStm (Exp maybeExpr srcLoc)) =
BlockStm (Return maybeExpr srcLoc)
addReturnToLastStm stmts =
if null stmts then
[]
else
init blockItems <> [addReturnToBlockStm $ last blockItems]
in pprLoc loc $ text "[&]"
<> ppr (addReturnToLastStm blockItems)
<> text "()"

pprPrec _ (BuiltinVaArg e ty loc) =
pprLoc loc $
Expand Down

0 comments on commit e670cfd

Please sign in to comment.