-
Notifications
You must be signed in to change notification settings - Fork 12
Interface Mixins #263
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
Merged
Interface Mixins #263
Conversation
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.
Infrastructural support for interface mixins - that is, the ability to add additional properties to an abstract block, e.g.
RotaryEncoderwithHasSwitch. Interface mixins can only be used on abstract classes, concrete classes may only be one class (but may implement multiple mixins, e.g. a single device can implementRotaryEncoderwithHasSwitch)In the Python HDL frontend, interface mixins are defined as a class. It does not inherit its base class, instead it declares its base class as a type parameterization. This is added into the superclass list on the proto. It's a bit inelegant structurally, but it allows the type checker and autocomplete to see the mixin fields only.
In the compiler, when it sees a unrefined mixin, the contents of the mixins are appended onto the (abstract) base class. This is only to support visualization - this will always produce an error, and the process may be unpredictable. Ultimately, it needs to be refined into a single use-defined concrete class, with the system checking for proper subclass relations.
On the proto side, this changes
BlockLike'slib_elemto also have optional mixins as library references. Pre-refinement mixins are also stored inHierarchyBlockFuture PRs will refactor some existing library elements to use mixins, and will likely also need to improve on the infrastructure.
Examples:
IoControllerwithHasI2s(maybe evenHasCan,HasUsb?)IoControllerwithHasPowerSource,HasUsbPowerSourceVoltageRegulatorwithHasEnableOther refactoring:
super_superclassesto all elem proto types, which defines non-immediate superclasses. This enables refinement / superclass checks to not need the full library and can operate solely on the design tree.Potential future work:
Resolves #104