sim: fix ValueCastable not being recognized as a coroutine command

This commit is contained in:
Jaro Habiger 2024-01-05 14:57:27 +01:00 committed by Catherine
parent 4014aef033
commit ded84fe9d6
2 changed files with 24 additions and 1 deletions

View file

@ -1,7 +1,7 @@
import inspect
from ..hdl import *
from ..hdl.ast import Statement, SignalSet
from ..hdl.ast import Statement, SignalSet, ValueCastable
from .core import Tick, Settle, Delay, Passive, Active
from ._base import BaseProcess
from ._pyrtl import _ValueCompiler, _RHSValueCompiler, _StatementCompiler
@ -66,6 +66,8 @@ class PyCoroProcess(BaseProcess):
command = self.default_cmd
response = None
if isinstance(command, ValueCastable):
command = Value.cast(command)
if isinstance(command, Value):
exec(_RHSValueCompiler.compile(self.state, command, mode="curr"),
self.exec_locals)

View file

@ -690,6 +690,27 @@ class SimulatorIntegrationTestCase(FHDLTestCase):
sim.add_process(process)
self.assertTrue(survived)
def test_value_castable(self):
class MyValue(ValueCastable):
@ValueCastable.lowermethod
def as_value(self):
return Signal()
def shape():
return unsigned(1)
a = Array([1,2,3])
a[MyValue()]
survived = False
with self.assertSimulation(Module()) as sim:
def process():
nonlocal survived
yield MyValue()
survived = True
sim.add_process(process)
self.assertTrue(survived)
def setUp_memory(self, rd_synchronous=True, rd_transparent=True, wr_granularity=None):
self.m = Module()
self.memory = Memory(width=8, depth=4, init=[0xaa, 0x55])