calyx
calyx copied to clipboard
Queues: change in `.expect` interface
This is a bookmark for a change that we'd like to make across all our queues. I'm parking it here because two big changes to the queues, https://github.com/calyxir/calyx/issues/2067 and https://github.com/calyxir/calyx/issues/1810, are in flight and I don't want to create an unnecessarily large diff.
Right now queue_call.py
starts up two counters, i
and j
, and then:
- Feeds
commands[i]
andvalues[i]
to the queue it is driving. Incrementsi
. - If the queue returns an answer (i.e., if the command passed was
pop
orpeek
and the queue executed it successfully), it writes the answer to theans_mem
memory like so:ans_mem[j++] = answer
.
This has a couple problems:
- When the queue returns errors (from overflow and underflow, chiefly), we have no "trace" of that fact in the answer memory and therefore no trace of that in our expect-testing.
- The fact that
i
andj
are out of sync means that it's hard to debug the behavior of a queue by looking over theexpect
files.
The new proposal is that queue_call.py
should start up one counter i
, and:
- Feed
commands[i]
andvalues[i]
to the queue it is driving. - If the queue returns an answer (i.e., if the command passed was
pop
orpeek
and the queue executed it successfully), write the answer to theanswers
memory just as before:ans_mem[i] = answer
. If the queue returns an error, indicate this in the answer memory by writing some special value inans_mem[i]
. Similarly, put some special value intoans_mem[i]
in case the command was apush
and no output was expected. - Increment
i
.