Skip to content
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

Allow any range type as macro bits parameter #43

Conversation

rauhul
Copy link
Collaborator

@rauhul rauhul commented Dec 6, 2023

Updates bit-field macros bits parameter to be generic over BinaryInteger RangeExpressions and adds an additional overload to enable the use of UnboundedRange.

Example new uses:

@Register(bitWidth: 32)
struct Example0 {
  @ReadWrite(bits: ...)
  var unbounded: Unbounded
}

@Register(bitWidth: 32)
struct Example1 {
  @ReadWrite(bits: ...16)
  var partialThrough: PartialThrough

  @ReadWrite(bits: 17...)
  var partialFrom: PartialFrom
}

@Register(bitWidth: 32)
struct Example2 {
  @ReadWrite(bits: ..<16)
  var partialUpTo: PartialUpTo

  @ReadWrite(bits: 16...31)
  var closed: Closed
}

Fixes #28

Updates bit-field macros bits parameter to be generic over
`BinaryInteger` `RangeExpression`s and adds an additional overload to
enable the use of `UnboundedRange`.

Example new uses:
```swift
@register(bitWidth: 32)
struct Example0 {
  @readwrite(bits: ...)
  var unbounded: Unbounded
}

@register(bitWidth: 32)
struct Example1 {
  @readwrite(bits: ...16)
  var partialThrough: PartialThrough

  @readwrite(bits: 17...)
  var partialFrom: PartialFrom
}

@register(bitWidth: 32)
struct Example2 {
  @readwrite(bits: ..<16)
  var partialUpTo: PartialUpTo

  @readwrite(bits: 16...31)
  var closed: Closed
}
```

Fixes #28
@rauhul rauhul linked an issue Dec 6, 2023 that may be closed by this pull request
@rauhul rauhul merged commit 84a7b68 into main Dec 6, 2023
@rauhul rauhul deleted the 28-readwritereadonlywriteonly-should-allow-additional-range-types branch December 6, 2023 16:42
perihare pushed a commit to perihare/swift-mmio that referenced this pull request Jul 10, 2024
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.

ReadWrite/ReadOnly/WriteOnly should allow additional range types
1 participant