Skip to content

Unbased unsized literals in BH - #945

Merged
rsnikhil merged 2 commits into
B-Lang-org:mainfrom
MatX-inc:cdsmith-upstream/unsized-bit-literals
Sep 17, 2026
Merged

rsnikhil merged 2 commits into
B-Lang-org:mainfrom
MatX-inc:cdsmith-upstream/unsized-bit-literals

Conversation

@matx-chris

Copy link
Copy Markdown
Collaborator

This PR adds the '0 and '1 syntax for unbased unsized literals to the Bluespec Haskell parser.

Notes:

  • ' is an identifier character, so a literal like this must start after a token boundary; i.e., foo'0 is an identifier, but foo '0 is a function applied to an unbased unsized literal.
  • '0' is still a character literal
  • This is similar to a lot of Haskell syntax for TH and Data Kinds promotion, it doesn't actually conflict with any valid Haskell syntax, which is nice.

@nanavati

Copy link
Copy Markdown
Collaborator

LGTM, my only question is how does this compare to what BSV does with '0 ad '1?

@matx-chris

Copy link
Copy Markdown
Collaborator Author

LGTM, my only question is how does this compare to what BSV does with '0 and '1?

I believe it does the same thing. I followed the same implementation. They both produce cVar (idConstAllBitsUnsetAt pos) and cVar (idConstAllBitsSetAt pos) in the parser. There's a slight difference in 'x and 'z, which are accepted by the BSV lexer, but then rejected in the parser. Here, I didn't accept them in the lexer either. The reason is that I wanted to minimize the syntax grab.

@matx-chris

matx-chris commented Apr 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

I realized I missed one case, which is '0 as a pattern. (Note: '1 as a pattern is an error in BSV as well, so this only applies to '0.) Added that as well, for consistency.

@matx-chris
matx-chris marked this pull request as ready for review April 29, 2026 04:58
@quark17

quark17 commented May 15, 2026

Copy link
Copy Markdown
Collaborator

I realized I missed one case, which is '0 as a pattern. (Note: '1 as a pattern is an error in BSV as well, so this only applies to '0.) Added that as well, for consistency.

I don't know why '1 in pattern matching is an error in BSV -- note that this is Issue #243.

@matx-amy

Copy link
Copy Markdown
Contributor

reviewed, 👍

@rsnikhil

Copy link
Copy Markdown
Collaborator

Looks good to me.

@rsnikhil rsnikhil closed this Sep 15, 2026
@rsnikhil rsnikhil reopened this Sep 15, 2026

@rsnikhil rsnikhil left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved (comments, if any, in PR comment list)

@rsnikhil
rsnikhil merged commit 6aab259 into B-Lang-org:main Sep 17, 2026
180 of 182 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants