<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0" xmlns:blogChannel="http://backend.userland.com/blogChannelModule">

<channel>
<title><![CDATA[Perl 6: SMOP Inter Continuation Communication]]></title>
<link>http://www.perlfoundation.org/perl6/index.cgi?smop_inter_continuation_communication</link>
<description></description>
<pubDate>Thu, 30 Oct 2008 19:57:54 -0000</pubDate>
<webMaster>synedra@gmail.com</webMaster>
<generator>Socialtext Workspace v2.14.7.2</generator>

<item>
<title><![CDATA[SMOP Inter Continuation Communication]]></title>
<link>http://www.perlfoundation.org/perl6/index.cgi?smop_inter_continuation_communication</link>
<description><![CDATA[<div class="wiki">
<p>
The way <a href="http://www.perlfoundation.org/perl6/index.cgi?smop" title="(6 months)  Simple Meta Object Programming Simple Matter Of Programming is a C based interpreter (runloop) that...">SMOP</a> is designed allows a feature called <a href="http://www.perlfoundation.org/perl6/index.cgi?polymorphic_eval" title="(64 months) Polymorphic Eval is the ability of chaining the execution of different interpreters from within the ...">Polymorphic Eval</a>. This feature basically means that different interpreter executions can be part of the same run loop, by using <a href="http://www.perlfoundation.org/perl6/index.cgi?continuation_passing_style" title="(64 months) Abbreviated as CPS, this is a technique of a stackless implementation of function call. This basical...">Continuation Passing Style</a>. The challenge here is how to send information from one continuation to the other, considering that the only thing known about each continuation is the API.</p>
<p>
For instance, let's consider during an execution of some code in the perl5 stack, a method in the smop default interpreter implementation must be called with some parameters, and that the return of this should be returned to the perl5 stack like in the diagram below:</p>
<pre>
  p5 -&gt; p5 -&gt; p5 -&gt; entersub  -  -   -   -   -   - &gt; p5 -&gt; p5
                       |                        ^
                       V                        |
                      smop -&gt; smop -&gt; smop -&gt; smop
</pre>
<br /><p>
As I said before, this interposition won't be made in terms of a stack, but in tems of CPS. This means that before calling goto on the interpreter to switch to smop, the entersub needs to send the parameters to the smop, the same way that smop needs to send the result to p5.</p>
<p>
On the other hand, in some cases, the interception in the interpreter must not change any information in the original execution, for instance, for a warning call.</p>
<pre>
 foo -&gt; foo -&gt; (something that generates a warning) -&gt; foo -&gt; foo
                 |                              ^
                 V                              |
                warning -&gt; code -&gt; being -&gt; executed
</pre>
<br /><p>
And the original execution shouldn't even realise that it was interrupted. The exact same pattern should map a OS interruption callback.</p>
<pre>
 foo -&gt; foo -&gt; foo  ... ... ... ... ... ... ... ... -&gt; foo -&gt; foo
                 |                              ^
                 V                              |
            interrupt -&gt; handler -&gt; being -&gt; executed
</pre>
<br /><h2 id="related_api">Related API</h2>
<p>
This kind of behaviour can be achieved by using two methods in the interpreter API:</p>
<ul>
<li>goto(|$continuation) -- This call will consider the running interpreter as the invocant.</li>
<li>goto($interpreter: $continuation)</li>
<li>continuation($interpreter: ) -- returns the current continuation</li>
</ul>
<p>
The goto method does what it says, switches the interpreter's context to the given continuation. The setr method, on the other hand, delegates to the implementation a signal that the &quot;result&quot; of the &quot;current point of execution evaluation&quot; should be the given value. This is how return values must be implemented, and how parameters passing must be implemented also, considering that because of the run loop design, the first node won't be evaluated.</p>
</div>
]]></description>
<author>Daniel Ruoso</author>
<guid isPermaLink="true">http://www.perlfoundation.org/perl6/index.cgi?smop_inter_continuation_communication</guid>
<pubDate>Thu, 30 Oct 2008 19:57:54 -0000</pubDate>
</item>

</channel>
</rss>