Threaded code: Difference between revisions

Content deleted Content added
m RPL: More copy editing.
Branches: Fix bugs in example
Line 309:
 
==Branches==
In all interpreters, a branch simply changes the thread pointer (<code>ip</code> above) to a different address in the thread. A conditional jump-if-zero branch, tothat jumpjumps only if the top-of-stack value is zero, mightcould be encodedimplemented as followsshown below. NoteThis thatexample uses the embedded parameter version of direct threading so the <code>&thread[123]</code> line is the ___locationdestination toof whichwhere to jump, notif the addresscondition ofis atrue, handler. So,so it must be skipped (<code>ip++</code>) regardlessover of whetherif the branch is not taken.
 
<syntaxhighlight lang="c">
Line 318:
...
brz:
when_true_ip = *ip++ // Get destination address for branch
tmp = ip++
if (*--sp == 0) // Pop/Consume top of stack and check if it's zero
if (*sp++ == 0)
ip = tmpwhen_true_ip
jump *ip++
</syntaxhighlight>