back.pysim: allow coroutines as processes.
authorwhitequark <whitequark@whitequark.org>
Wed, 21 Aug 2019 03:28:48 +0000 (03:28 +0000)
committerwhitequark <whitequark@whitequark.org>
Wed, 21 Aug 2019 03:30:37 +0000 (03:30 +0000)
commit1fc63a62c04a9c1eb3724ed671ecd284d7fd2d4e
tree9032f66cc936e3c9ee35f2cbe3f48a7ca3b07027
parentc934fc66e90a768d9cf6088b7d3cacf1ab1bc136
back.pysim: allow coroutines as processes.

This is a somewhat obscure use case, but it is possible to use async
functions with pysim by carefully using @asyncio.coroutine. That is,
async functions can call back into pysim if they are declared in
a specific way:

  @asyncio.coroutine
  def do_something(self, value):
    yield self.reg.eq(value)

which may then be called from elsewhere with:

  async def test_case(self):
    await do_something(0x1234)

This approach is unfortunately limited in that async functions
cannot yield directly. It should likely be improved by using async
generators, but supporting coroutines in pysim is unobtrustive and
allows existing code that made use of this feature in oMigen to work.
nmigen/back/pysim.py