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

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

<channel>
<title><![CDATA[Perl 6: SMOP Mold]]></title>
<link>http://www.perlfoundation.org/perl6/index.cgi?smop_mold</link>
<description></description>
<pubDate>Thu, 11 Sep 2008 07:58:21 -0000</pubDate>
<webMaster>synedra@gmail.com</webMaster>
<generator>Socialtext Workspace v2.14.7.2</generator>

<item>
<title><![CDATA[SMOP Mold]]></title>
<link>http://www.perlfoundation.org/perl6/index.cgi?smop_mold</link>
<description><![CDATA[<div class="wiki">
<p>
(Mold is currently under implementation)<br />
SMOP Mold is a register based interpreter implementation<br />
A DSL called m0ld is used to represent mold opcodes in text form</p>
<p>
A Mold block(?) is composed of three parts</p>
<ul>
<li>the number of registers used by the program (not counting the ones used to put constants or the 3 special ones)</li>
<li>constants - which are put into registers</li>
<li>opcodes</li>
</ul>
<p>
The registers 1,2,3 are initialised with</p>
<ul>
<li>interpreter</li>
<li>identifier</li>
<li>capture</li>
</ul>
<h2 id="mold_accepts_following_directives">Mold accepts following directives</h2>
<p>
my $register_name;<br />
declares an empty register</p>
<p>
my $register_name = &lt;value&gt;;<br />
with &lt;value&gt; being either an integer, c string literal, or a C var with a ¢prefix<br />
which declares an register which is set to &lt;value&gt; at frame creation time</p>
<h2 id="bytecode_format">Bytecode format</h2>
<p>
The bytecode ends with a 0</p>
<ol>
<li>Call - 1,&lt;reg&gt; target,&lt;reg&gt; invocant,&lt;reg&gt; identifier,&lt;int&gt; number_of_positionals,(&lt;reg&gt; positional)**{number_of_positionals},&lt;int&gt; number_of_named_arguments,(&lt;reg&gt; name,&lt;reg&gt; value) ** {number_of_named_arguments}</li>
<li>Call2 - 2,&lt;reg&gt; target,&lt;reg&gt; responder_interface,&lt;reg&gt; identifier,&lt;reg&gt; capture</li>
<li>Goto - 3, &lt;absolute offset&gt; where</li>
<li>Br - 4,&lt;reg&gt; condition,&lt;absolute offset&gt; iftrue,&lt;absolute offset&gt; iffalse</li>
</ol>
<h2 id="opcodes">Opcodes</h2>
<h3 id="call">Call</h3>
<p>
$target = $invocant.$method_name($pos1,$pos2,:$named1($named1_value)...)</p>
<p>
Creates a capture and calls method whose name is stored in $method_name using the responder interface of $invocant</p>
<h3 id="call2">Call2</h3>
<p>
$target = $invocant.$method_name(|$catpure)</p>
<h3 id="goto">Goto</h3>
<p>
goto label</p>
<p>
Jumps to label</p>
<h3 id="br">Br</h3>
<p>
if $condition {goto iftrue} else {goto iffalse}</p>
<p>
Jumps to iiftrue if $condition is equal to a native True, to iffalse if it's equal to False, aborts executions and prints out an error otherwise (TODO throw an exception)</p>
<h2 id="example">Example</h2>
<p>
$*OUT.print(&quot;hello world\n&quot;) is translated to</p>
<pre>
# register declarations
my $r10;
my $r11;
my $r12; # we have to store even unused return values somewhere

# constants
my $r4 = $SMOP__S1P__RootNamespace;
my $r5 = &quot;postcircumfix:{ }&quot;;
my $r6 = &quot;$*OUT&quot;;
my $r7 = &quot;FETCH&quot;;
my $r8 = &quot;print&quot;;
my $r9 = &quot;hello world\n&quot;;


#opcodes
$r10 = $r4.$r5($r6);
$r11 = $r10.$r7();
$r12 = $r11.$r8($r9);
</pre>
<br /><p>
The opcodes part ultimatly compiles to such byte code</p>
<pre>
10 4 5 1 6 0
11 10 7 0 0
12 11 8 1 9 0
0
</pre>
<br /><h2 id="syntax_sugar">Syntax Sugar</h2>
<p>
my $foo = $bar.$baz(...);</p>
<p>
is treated like</p>
<p>
my $foo;<br />
$foo = $baz.$baz(...);</p>
</div>
]]></description>
<author>pawelmurias@hidden</author>
<guid isPermaLink="true">http://www.perlfoundation.org/perl6/index.cgi?smop_mold</guid>
<pubDate>Thu, 11 Sep 2008 07:58:21 -0000</pubDate>
</item>

</channel>
</rss>