dan-fritchman / Hdl21

Hardware Description Library
BSD 3-Clause "New" or "Revised" License
69 stars 16 forks source link

Allow zero-arg `h.generator` #81

Open dan-fritchman opened 1 year ago

dan-fritchman commented 1 year ago

Currently to make an argument-less Generator, you need to actually declare a parameter and give it a type. Often h.HasNoParams is used for the latter, like so:

@h.generator
def PmosIdac(_: h.HasNoParams) -> h.Module:
  # ...

The issue: we should be able to just write

@h.generator
def PmosIdac() -> h.Module: # <= here
  # ...

We do enough inspection of the Generator call-signature already, and lots of tuning when we invoke them during elaboration. This should be a pretty straightforward case to add.

dan-fritchman commented 1 year ago

You might ask -
but why make a zero-argument generator?
Isn't that just a Module?

Kinda yeah.
I nonetheless end up doing it all the time, for a few reasons:

ThomasPluck commented 1 year ago

Another related piece of functionality that could be useful is arbitrary argument generators. That is, a way for generators to take ordinary arguments and have these become a "virtual" paramclass instance at Elaboration time that isn't immediately obvious to the user, ie.

@h.generator
def myFirstGenerator(params : MyParams) -> h.Module:
    # ...

Could be written as:

@h.generator
def myFirstGenerator(arg1 : int, arg2 : str, arg3 : Prefixed) -> h.Module:
    # ...

Maybe, this could be delivered alongside zero-arg generators?