back.pysim: show more legible names for processes in errors.

This commit is contained in:
whitequark 2018-12-14 13:50:19 +00:00
parent 625c55a3b8
commit 1655b59d1b

View file

@ -435,6 +435,10 @@ class Simulator:
# Otherwise, do one more round of updates. # Otherwise, do one more round of updates.
def _run_process(self, process): def _run_process(self, process):
def format_process(process):
frame = process.gi_frame
return "{}:{}".format(inspect.getfile(frame), inspect.getlineno(frame))
try: try:
cmd = process.send(None) cmd = process.send(None)
while True: while True:
@ -462,14 +466,14 @@ class Simulator:
lhs_signals = cmd.lhs._lhs_signals() lhs_signals = cmd.lhs._lhs_signals()
for signal in lhs_signals: for signal in lhs_signals:
if not signal in self._signals: if not signal in self._signals:
raise ValueError("Process {!r} sent a request to set signal '{!r}', " raise ValueError("Process '{}' sent a request to set signal '{!r}', "
"which is not a part of simulation" "which is not a part of simulation"
.format(process, signal)) .format(format_process(process), signal))
if signal in self._comb_signals: if signal in self._comb_signals:
raise ValueError("Process {!r} sent a request to set signal '{!r}', " raise ValueError("Process '{}' sent a request to set signal '{!r}', "
"which is a part of combinatorial assignment in " "which is a part of combinatorial assignment in "
"simulation" "simulation"
.format(process, signal)) .format(format_process(process), signal))
funclet = _StatementCompiler()(cmd) funclet = _StatementCompiler()(cmd)
funclet(self._state) funclet(self._state)
@ -480,8 +484,8 @@ class Simulator:
self._commit_sync_signals(domains) self._commit_sync_signals(domains)
else: else:
raise TypeError("Received unsupported command '{!r}' from process {!r}" raise TypeError("Received unsupported command '{!r}' from process '{}'"
.format(cmd, process)) .format(cmd, format_process(process)))
break break