Skip to content

Commit

Permalink
Pretty-print lets with surrounding braces
Browse files Browse the repository at this point in the history
The pretty-printer for `letseq` and `letrec` was not adding braces around
the variables being bound, resulting in malformed pretty-printed output such as
`letseq hw =  "Hello, World!";; ...`. After adding braces, this now becomes
`letseq { hw =  "Hello, World!"; };`, which is valid Bluespec code.

Fixes B-Lang-org#529.
  • Loading branch information
RyanGlScott committed Jan 6, 2023
1 parent f897d70 commit e0bf249
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/comp/CSyntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,12 +1044,12 @@ instance PPrint CExpr where
pPrint d p (Cletseq [] e) = pparen (p > 0) $
(t"letseq in" <+> pp d e)
pPrint d p (Cletseq ds e) = pparen (p > 0) $
(t"letseq" <+> foldr1 ($+$) (map (pp d) ds)) $+$
(t"letseq" <+> text "{" <+> foldr1 ($+$) (map (pp d) ds)) <+> text "}" $+$
(t"in " <> pp d e)
pPrint d p (Cletrec [] e) = pparen (p > 0) $
(t"let in" <+> pp d e)
pPrint d p (Cletrec ds e) = pparen (p > 0) $
(t"let" <+> foldr1 ($+$) (map (pp d) ds)) $+$
(t"let" <+> text "{" <+> foldr1 ($+$) (map (pp d) ds)) <+> text "}" $+$
(t"in " <> pp d e)
pPrint d p (CSelect e i) = pparen (p > (maxPrec+2)) $ pPrint d (maxPrec+2) e <> t"." <> ppVarId d i
pPrint d p (CCon i []) = ppConId d i
Expand Down Expand Up @@ -1151,9 +1151,9 @@ instance PPrint CStmt where
(map (ppPProp d . snd) pprops) ++
[pp d pat <+> t "<-" <+> pp d e]
pPrint d p (CSletseq []) = internalError "CSyntax.PPrint(CStmt): CSletseq []"
pPrint d p (CSletseq ds) = text "letseq" <+> foldr1 ($+$) (map (pp d) ds)
pPrint d p (CSletseq ds) = text "letseq" <+> text "{" <+> foldr1 ($+$) (map (pp d) ds) <+> text "}"
pPrint d p (CSletrec []) = internalError "CSyntax.PPrint(CStmt): CSletrec []"
pPrint d p (CSletrec ds) = text "let" <+> foldr1 ($+$) (map (pp d) ds)
pPrint d p (CSletrec ds) = text "let" <+> text "{" <+> foldr1 ($+$) (map (pp d) ds) <+> text "}"
pPrint d p (CSExpr _ e) = pPrint d p e

instance PPrint CMStmt where
Expand Down
6 changes: 3 additions & 3 deletions testsuite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ on the file and checking for an error exit code. There are
also a small number of tests that explicitly run `vcdcheck`
as part of their testing.

One test (`bsc.bugs/b611/`) checks for a bug in `bsc2bsv`
but otherwise this tool is not used. There are no tests
for the related tool, `bsv2bsc`.
There are a number of tests that check for bugs in the `bsc2bsv` tool (e.g.,
`bsc.bugs/bluespec_inc/b611/`) and the `bsv2bsc` tool (e.g.,
`bsc.bugs/github/gh529/`), but otherwise these tools are not used.

### Running some or all tests

Expand Down
2 changes: 2 additions & 0 deletions testsuite/bsc.bugs/github/gh529/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Generated file
Bug529.bs
7 changes: 7 additions & 0 deletions testsuite/bsc.bugs/github/gh529/Bug529.bsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module helloWorld (Empty);
rule hello_world;
let hw = "Hello, World!";
$display (hw);
$finish;
endrule
endmodule
5 changes: 5 additions & 0 deletions testsuite/bsc.bugs/github/gh529/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# for "make clean" to work everywhere

CONFDIR = $(realpath ../../..)

include $(CONFDIR)/clean.mk
6 changes: 6 additions & 0 deletions testsuite/bsc.bugs/github/gh529/gh529.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
if [do_internal_checks] {
run_bsv2bsc Bug529.bsv
# We need a file extension that bsc recognizes
copy Bug529.bsv.bsv2bsc-out Bug529.bs
compile_pass Bug529.bs
}

0 comments on commit e0bf249

Please sign in to comment.