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

Register field definitions are confusing due to vacuous types #33

Open
phausler opened this issue Nov 16, 2023 · 1 comment
Open

Register field definitions are confusing due to vacuous types #33

phausler opened this issue Nov 16, 2023 · 1 comment
Labels
mmio Related to the MMIO library

Comments

@phausler
Copy link
Member

Register fields are required to specify a type but common usage will use an as: parameter. This means that the type that is written for a given field is not really used. Instead it is a type information for storing via an un-inhabited enumeration.

@ReadWrite(bits: 0..<3, as: TestValues.self)
public var someField: Test

this expands in the register and the field to:

public var someField: Test {
    get {
        fatalError()
    }
}

public  enum Test: ContiguousBitField {

            public  typealias Storage = UInt8

            public  static let bitRange = 0 ..< 3
}

instead it could be more canonically written in standard swift parlance as:

@ReadWrite(bits: 0..<3)
public var someField: TestValues

which can expand (by using the name of the field instead of the name of the type)

public  enum SomeField: ContiguousBitField {

            public  typealias Storage = UInt8

            public  static let bitRange = 0 ..< 3
}
@fumoboy007
Copy link

fumoboy007 commented Jan 14, 2024

I agree! Swapping the projected type and the descriptor type would make it feel more natural.

As I wrote here, the register field macro could even have a generatedDescriptorType property to allow the developer to specify the generated type name. (It would be nice for the macro to automatically generate a name if the macro property was omitted though.)

@ReadWrite(bits: 0..<3, generatedDescriptorType: Test.self)
public var someField: TestValues

@rauhul rauhul added the mmio Related to the MMIO library label Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mmio Related to the MMIO library
Projects
None yet
Development

No branches or pull requests

3 participants