Skip to content

Commit 4fbed5f

Browse files
authored
Merge amendment #29 to RFC #9: clarify that .const() can return a value-castable.
2 parents 4edf8cc + 1c12359 commit 4fbed5f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

text/0009-const-init-shape-castable.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Shape-castable objects must, in addition to the mandatory `.as_shape()` method,
3535

3636
This method is defined by shape-castable objects to convert arbitrary Python objects into Amaranth constants. For example, if a shape-castable object has complex internal structure, it can accept a dictionary with the values to be filled into various bits of this structure. If `Shape` implemented `ShapeCastable`, the method would be defined as `def const(self, value): return Const(value, self)`.
3737

38+
The value returned by this method can be a `Const` or a value-castable object whose `.as_value()` will return a `Const`.
39+
3840
This method can also be directly called by the developer to construct a constant using a given shape-castable object.
3941

4042
## Reference-level explanation
@@ -44,9 +46,9 @@ A method `def const(self, obj):` is added on `ShapeCastable`.
4446

4547
The `Signal(shape, reset=)` constructor is changed so that if `isinstance(shape, ShapeCastable)`, then `shape.const(reset)` is used instead of `reset`.
4648

47-
The `.const()` instance method is implemented on `Layout` to accept a `Sequence` or `Mapping` instance and returns a `Const` with a bit pattern that has the fields set to the given values. Overlapping fields are written in the order of iteration of the input. If the field shape is a shape-castable object, then the value for that field is computed using `Const.cast(value, field.shape)`.
49+
The `.const()` instance method is implemented on `Layout` to accept a `Sequence` or `Mapping` instance and returns a `View` over a `Const` with a bit pattern that has the fields set to the given values. Overlapping fields are written in the order of iteration of the input. If the field shape is a shape-castable object, then the value for that field is computed using `Const.cast(value, field.shape)`.
4850

49-
The `.const()` method is implemented on the metaclass of `Struct` and `Union` as `return self.as_shape().const(obj)`.
51+
The `.const()` method is implemented on the metaclass of `Struct` and `Union` as `return View(self, self.as_shape().const(obj))`.
5052

5153
The `View(..., reset=)` constructor is changed to pass `reset` through to the `Signal()` constructor.
5254

0 commit comments

Comments
 (0)