Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>MyHDL is using the <code>yield</code> statement to communicate a list of conditions which, when one of them is <code>True</code>, will resume execution of the generator. For example, a generator might yield condition <code>clock.posedge</code> when the clock transitions from low to high (0 to 1) -- when the clock makes this transition, the generator will be resumed.</p> <p>To simulate (roughly) how this works, here is a Python generator which is resumed when one of its conditions (argument is evenly divisible by 3 or 7) are met:</p> <pre><code>def process(): j = 0 while True: yield (lambda x: x % 3 == 0, lambda x: x % 7 == 0) j += 1 print 'process j=', j gen = process() conds = next(gen) for i in range(1, 11): print 'i=', i if any(cond(i) for cond in conds): conds = next(gen) </code></pre> <p>Output:</p> <pre><code>i= 1 i= 2 i= 3 process j= 1 i= 4 i= 5 i= 6 process j= 2 i= 7 process j= 3 i= 8 i= 9 process j= 4 i= 10 </code></pre> <p><strong>Update</strong> - A bit more detail on some of the syntax I used:</p> <p>I tend to use the [<code>next(gen, [default])</code>] function as it is a bit more flexible than calling <code>gen.next()</code>. For example, if you pass the <code>default</code> arg, when the generator is exhausted it will return <code>default</code> rather than <a href="http://docs.python.org/library/exceptions.html#exceptions.StopIteration" rel="nofollow">raising <code>StopIteration</code></a>.</p> <p>The var <code>conds</code> points to a <a href="http://www.python.org/doc//current/library/functions.html?highlight=tuple#tuple" rel="nofollow">tuple</a> containing the conditions. In this case above it points to a <a href="http://www.python.org/doc//current/library/functions.html?highlight=tuple#tuple" rel="nofollow">tuple</a> containing the 2 <a href="http://www.python.org/doc//current/reference/expressions.html#lambda" rel="nofollow">lambda anonymous functions</a> returned by <code>process</code>.</p> <p>The syntax:</p> <pre><code>if any(cond(i) for cond in conds): conds = next(gen) </code></pre> <p>Calls the <a href="http://docs.python.org/library/functions.html#any" rel="nofollow"><code>any</code> built-in function</a>, passing it a <a href="http://www.python.org/dev/peps/pep-0289/" rel="nofollow">generator expression</a> which loops over <code>conds</code> and evaluates <code>if cond(i) is True</code>. It is shorthand for writing:</p> <pre><code>for cond in conds: if cond(i): conds = next(gen) break </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload