Implement RFC 35: Add ShapeLike, ValueLike.
This commit is contained in:
parent
422ba9ea51
commit
e9545efb22
7 changed files with 192 additions and 30 deletions
|
|
@ -61,7 +61,7 @@ While this implementation works, it is repetitive, error-prone, hard to read, an
|
|||
|
||||
m.d.comb += o_gray.eq((i_color.red + i_color.green + i_color.blue) << 1)
|
||||
|
||||
The :class:`View` is :ref:`value-castable <lang-valuecasting>` and can be used anywhere a plain value can be used. For example, it can be assigned to in the usual way:
|
||||
The :class:`View` is :ref:`value-like <lang-valuelike>` and can be used anywhere a plain value can be used. For example, it can be assigned to in the usual way:
|
||||
|
||||
.. testcode::
|
||||
|
||||
|
|
@ -135,7 +135,7 @@ In case the data has related operations or transformations, :class:`View` can be
|
|||
def brightness(self):
|
||||
return (self.red + self.green + self.blue)[-8:]
|
||||
|
||||
Here, the ``RGBLayout`` class itself is :ref:`shape-castable <lang-shapecasting>` and can be used anywhere a shape is accepted. When a :class:`Signal` is constructed with this layout, the returned value is wrapped in an ``RGBView``:
|
||||
Here, the ``RGBLayout`` class itself is :ref:`shape-like <lang-shapelike>` and can be used anywhere a shape is accepted. When a :class:`Signal` is constructed with this layout, the returned value is wrapped in an ``RGBView``:
|
||||
|
||||
.. doctest::
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ The ``shape=`` argument is optional. If not specified, classes from this module
|
|||
|
||||
In this way, this module is a drop-in replacement for the standard :mod:`enum` module, and in an Amaranth project, all ``import enum`` statements may be replaced with ``from amaranth.lib import enum``.
|
||||
|
||||
Signals with :class:`Enum` or :class:`Flag` based shape are automatically wrapped in the :class:`EnumView` or :class:`FlagView` value-castable wrappers, which ensure type safety. Any :ref:`value-castable <lang-valuecasting>` can also be explicitly wrapped in a view class by casting it to the enum type:
|
||||
Signals with :class:`Enum` or :class:`Flag` based shape are automatically wrapped in the :class:`EnumView` or :class:`FlagView` value-like wrappers, which ensure type safety. Any :ref:`value-like <lang-valuelike>` can also be explicitly wrapped in a view class by casting it to the enum type:
|
||||
|
||||
.. doctest::
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue