sim: fix simulation loop when process catches an injected exception.
This commit is contained in:
parent
15b6068c57
commit
f48b8650c4
|
@ -59,12 +59,23 @@ class PyCoroProcess(BaseProcess):
|
||||||
self.clear_triggers()
|
self.clear_triggers()
|
||||||
|
|
||||||
response = None
|
response = None
|
||||||
|
exception = None
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
command = self.coroutine.send(response)
|
if exception is None:
|
||||||
|
command = self.coroutine.send(response)
|
||||||
|
else:
|
||||||
|
command = self.coroutine.throw(exception)
|
||||||
|
except StopIteration:
|
||||||
|
self.passive = True
|
||||||
|
self.coroutine = None
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
if command is None:
|
if command is None:
|
||||||
command = self.default_cmd
|
command = self.default_cmd
|
||||||
response = None
|
response = None
|
||||||
|
exception = None
|
||||||
|
|
||||||
if isinstance(command, ValueCastable):
|
if isinstance(command, ValueCastable):
|
||||||
command = Value.cast(command)
|
command = Value.cast(command)
|
||||||
|
@ -118,10 +129,6 @@ class PyCoroProcess(BaseProcess):
|
||||||
raise TypeError("Received unsupported command {!r} from process {!r}"
|
raise TypeError("Received unsupported command {!r} from process {!r}"
|
||||||
.format(command, self.src_loc()))
|
.format(command, self.src_loc()))
|
||||||
|
|
||||||
except StopIteration:
|
|
||||||
self.passive = True
|
|
||||||
self.coroutine = None
|
|
||||||
return
|
|
||||||
|
|
||||||
except Exception as exn:
|
except Exception as exn:
|
||||||
self.coroutine.throw(exn)
|
response = None
|
||||||
|
exception = exn
|
||||||
|
|
|
@ -685,7 +685,6 @@ class SimulatorIntegrationTestCase(FHDLTestCase):
|
||||||
with self.assertRaisesRegex(TypeError,
|
with self.assertRaisesRegex(TypeError,
|
||||||
r"Received unsupported command 1 from process .+?"):
|
r"Received unsupported command 1 from process .+?"):
|
||||||
yield 1
|
yield 1
|
||||||
yield Settle()
|
|
||||||
survived = True
|
survived = True
|
||||||
sim.add_process(process)
|
sim.add_process(process)
|
||||||
self.assertTrue(survived)
|
self.assertTrue(survived)
|
||||||
|
|
Loading…
Reference in a new issue