hdl.ast: make Slice const-castable.

Fixes #1006.
This commit is contained in:
Wanda 2023-12-30 12:10:29 +01:00 committed by Catherine
parent 6780c838b2
commit 0849e1af0b
4 changed files with 21 additions and 0 deletions

View file

@ -731,6 +731,9 @@ class Const(Value):
value |= part_value << width
width += len(const)
return Const(value, width)
elif type(obj) is Slice:
value = Const.cast(obj.value)
return Const(value.value >> obj.start, unsigned(obj.stop - obj.start))
else:
raise TypeError(f"Value {obj!r} cannot be converted to an Amaranth constant")