rohd
rohd copied to clipboard
Dart Static Metaprogramming (macros) for common automation
Motivation
There are some things in ROHD that can be a bit verbose/redundant. For example, a simple port whose variable name and String port name are the same, and which needs a public get
ter, could required this kind of boilerplate:
Logic get _myPort => input('myPort');
MyClass({Logic myPort}) {
myPort = addInput('myPort', myPort);
// ...
}
Note the word "myPort" is written 6 times, when the intent is really "add an input port named myPort".
Dart's static metaprogramming feature (upcoming, currently experimental) could potentially help automate a lot of this so that a simple annotation, something like input('myPort')
could generate all the boilerplate.
A similar strategy could apply for ports on modules and interfaces, and perhaps many other places where things are a bit verbose in the "simple common" case.
The APIs themselves are very flexible, offering more capabilities than the simple case, which is why there is repetition in simple cases.
Desired solution
Implement static metaprogramming features in ROHD to handle the simple cases, while keeping the existing APIs for less simple cases (and backwards compatibility, or for those who don't want to use the new features).
Alternatives considered
No response
Additional details
Information on Dart's static metaprogramming features: https://github.com/dart-lang/language/issues/1482 https://github.com/dart-lang/language/blob/main/working/macros/feature-specification.md https://dart.dev/language/macros