Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

ReadWrite/ReadOnly/WriteOnly should allow additional range types #28

Closed
phausler opened this issue Nov 8, 2023 · 2 comments · Fixed by #43
Closed

ReadWrite/ReadOnly/WriteOnly should allow additional range types #28

phausler opened this issue Nov 8, 2023 · 2 comments · Fixed by #43
Milestone

Comments

@phausler
Copy link
Member

phausler commented Nov 8, 2023

It would often be useful to express bit fields as closed ranges or other such range types:

@ReadWrite(22...22, as: Bool.self) var booleanLikeThing: BooleanLikeThing

or the remaining bits in a register layout:
@ReadOnly(16..., as: UInt16.self) var remainingBits: RemainingBits

@rauhul rauhul added the enhancement New feature or request label Nov 8, 2023
@rauhul rauhul added this to the 0.0.2 milestone Nov 17, 2023
@rauhul
Copy link
Collaborator

rauhul commented Dec 5, 2023

I have this mostly functional, but I'm trying to figure out if I can support ... (unbound range) without needing an additional overload which could hurt compiler performance

@rauhul
Copy link
Collaborator

rauhul commented Dec 5, 2023

Got it working with help from @ahoppen (thank you!)

rauhul added a commit that referenced this issue Dec 6, 2023
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 a pull request Dec 6, 2023 that will close this issue
@rauhul rauhul closed this as completed in #43 Dec 6, 2023
rauhul added a commit that referenced this issue Dec 6, 2023
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 removed the enhancement New feature or request label Mar 12, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants