lib.memory: Allow setting Memory.init.

The `init` property is already mutable, so this adds no actual new
functionality, just convenience.
This commit is contained in:
Wanda 2024-03-13 13:46:39 +01:00 committed by Catherine
parent cb96b15b8c
commit 455a7bc6c8
2 changed files with 6 additions and 0 deletions

View file

@ -408,6 +408,10 @@ class Memory(wiring.Component):
def init(self):
return self._init
@init.setter
def init(self, init):
self._init = Memory.Init(init, shape=self._shape, depth=self._depth)
@property
def attrs(self):
return self._attrs

View file

@ -311,6 +311,8 @@ class MemoryTestCase(FHDLTestCase):
self.assertEqual(m.init._raw, [0, 2, 0, 0])
m.init[2:] = [4, 5]
self.assertEqual(list(m.init), [0, 2, 4, 5])
m.init = [6, 7]
self.assertEqual(list(m.init), [6, 7, 0, 0])
def test_init_set_shapecastable(self):
m = Memory(shape=MyStruct, depth=4, init=[])