Improve ergonomics - #25
Draft
jmert wants to merge 4 commits into
Draft
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #25 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 202 220 +18
=========================================
+ Hits 202 220 +18 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Note that membership of the zero-valued flag is a special case; we choose to allow 0 ∈ 0 (but 0 ∉ N for N ≠ 0) only if there is a valid flag whose value is zero.
…ions Rather than passing through the type constructor, simply allow the bitwise operations to construct arbitrary bit patterns. This makes the test for the empty flag easier (through bitwise AND) to perform for flags which do not include an explicit 0-value: ```julia julia> @bitflag Flag::UInt8 v1 v2 v4 julia> iszero(v1 & v4) true ``` The non-error condition is also essentially required to allow a meaningful bitwise NOT to be defined: ```julia julia> ~(v1 | v2 | v4) reinterpret(Flag, 0xf8))::Flag = 0xf8 ```
This file contains hidden or 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
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.
Improve ergonomics of the bit flag types by expanding coverage / utility of
bitwise operations and type-generic helpers.
Define
zeroandiszeroto help with type-generic coding patterns.Define
into test the inclusion of a bit pattern within another, with special-casehandling for zero-valued flags in definitions that include an explicit zero — a zero
on the left-hand side is "in" the pattern on the right if and only if the right is
also zero (since otherwise all bit patterns include the zero value).
Add bitwise operations for NOT (
~) and XOR (⊻), and change all bitwise operatorsto produce "invalid" bit patterns in order to: (a) better support the
iszero(x & y)condition for flag types which do not include an explicit zero-valued flag, and
(b) allow for a practical definition of
~.Fixes #24