dan-fritchman / Hdl21

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

Broke `Literal` in `Sim` class-defs #190

Closed dan-fritchman closed 1 year ago

dan-fritchman commented 1 year ago

This:

    @hs.sim
    class MySim:
        # ...
        l = hs.Literal("whatever")

Now generates:

  File "/tools/users/dan_fritchman/Hdl21/hdl21/sim/data.py", line 537, in sim
    val.name = key
  File "<string>", line 4, in __setattr__
dataclasses.FrozenInstanceError: cannot assign to field 'name'

And it should; Literal is an immutable frozen type.

Either:

dan-fritchman commented 1 year ago

Or, without any changes, this just requires passing Literal to the add method, or appending it to the sim attributes.
E.g.

@hs.sim
class MySim:
    # ... all the other stuff

# Then add literals
M.add(h.Literal("whatever"))

Seems fine to stick with.