-
Notifications
You must be signed in to change notification settings - Fork 37
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
Bitfield constants #1511
Merged
Merged
Bitfield constants #1511
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rsmmr
force-pushed
the
topic/robin/gh-1467-bitfield-constants
branch
from
September 1, 2023 08:24
a3bd5e9
to
3550048
Compare
rsmmr
force-pushed
the
topic/robin/gh-1467-bitfield-constants
branch
from
September 1, 2023 08:24
3550048
to
95ada1f
Compare
rsmmr
force-pushed
the
topic/robin/gh-1467-bitfield-constants
branch
from
September 1, 2023 11:08
95ada1f
to
22b31ed
Compare
bbannier
previously approved these changes
Sep 1, 2023
…lues. This will allow us to create bitfield constants where not at all elements are set. We also add an operator to test if an element is set (test forthcoming in a subsequent commit).
It's now possible to initialize a bitfield value through an assignment from a struct constructor expression: type BF = bitfield(8) { a: 0..3; b: 4..7; c: 4..5; }; global BF bf = [$a = 1, $c = 2];
This allows to associate an expression with each bit value. We don't use this from HILTI because there's isn't a good syntax to do so (and/or: it's not worth adding), but we'll use (and test) this from Spicy in a subsequent commit.
One can now define bitfield "constants" for parsing by providing integer expressions with fields: type Foo = unit { x: bitfield(8) { a: 0..3 = 2; b: 4..7; c: 7 = 1; }; This will first parse the bitfield as usual and then enforce that the two bit ranges that are coming with expressions (i.e., `a` and `c`) indeed containing the expected values. If they don't, that's a parse error. We also support using such bitfield constants for look-ahead parsing: type Foo = unit { x: uint8[]; y: bitfield(8) { a: 0..3 = 4; b: 4..7; }; }; This will parse uint8s until a value is discovered that has its bits set as defined by the bitfield constant. (We use the term "constant" loosely here: only the bits with values are actually enforced to be constant, all others are parsed as usual.) Closes #1467.
rsmmr
force-pushed
the
topic/robin/gh-1467-bitfield-constants
branch
from
September 7, 2023 09:31
27fb006
to
1c25f1b
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.