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

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

<channel>
<title><![CDATA[Perl 6: SMOP OO Bootstrap]]></title>
<link>http://www.perlfoundation.org/perl6/index.cgi?smop_oo_bootstrap</link>
<description></description>
<pubDate>Mon, 12 May 2008 20:45:44 -0000</pubDate>
<webMaster>synedra@gmail.com</webMaster>
<generator>Socialtext Workspace v2.14.7.2</generator>

<item>
<title><![CDATA[SMOP OO Bootstrap]]></title>
<link>http://www.perlfoundation.org/perl6/index.cgi?smop_oo_bootstrap</link>
<description><![CDATA[<div class="wiki">
<p>
At first, it's important to understand that all C typedef structs in<br />
<a href="http://www.perlfoundation.org/perl6/index.cgi?smop" title="(7 months)  Simple Meta Object Programming Simple Matter Of Programming is a C based interpreter (runloop) that...">SMOP</a> are meant to support Perl 6 features from bottom-up. This means<br />
that the exact same instances of the low-level <a href="http://www.perlfoundation.org/perl6/index.cgi?smop" title="(7 months)  Simple Meta Object Programming Simple Matter Of Programming is a C based interpreter (runloop) that...">SMOP</a> will be naturally<br />
available to the high-level implementation that uses SMOP (probably<br />
KP6).</p>
<p>
So, the basic structure is:</p>
<pre>
        all responder interfaces are objects
            ____________________________ 
           |                            |
           V                            |
      SMOP__Object*        SMOP__ResponderInterface*
           |                            ^
           |                            |
            ---------------------------- 
        all objects have a responder interface
</pre>
<br /><p>
These two C types (typedef struct) are the basic elements of the SMOP<br />
runtime, and they implement the features that Perl 6 needs.</p>
<h2 id="basic_idea">Basic Idea</h2>
<p>
The Object is completely dependant on its <a href="http://www.perlfoundation.org/perl6/index.cgi?Responder%20Interface" title="[click to create page]" class="incipient">Responder Interface</a>, which<br />
is the only ones that knows its internal structure. It knows<br />
how to define which members the object have. An object without a <br />
Responder Interface must be a Responder Interface.</p>
<p>
The only fixed thing here is that these two types must be presented<br />
as types in the low-level also, which means that implementing a perl5<br />
extension to SMOP means writing a responder interface object that has<br />
the same C structure as other responder interfaces.</p>
<h2 id="concept_testing">Concept testing</h2>
<p>
Let's consider we have the yap6_lowlevel_responder that support the<br />
SMOP lowlevel objects, and that we want to create a new instance of<br />
a SMOP__MUTAB__List (which probably will be the default SMOP Array).</p>
<p>
We won't discuss namespaces here, only object references, in theory<br />
we can work with completely anonymous objects all the time. The<br />
namespace thing is just a high level helper for it.</p>
<pre>
SMOP__Object* list_prototype = get_list_prototype();
</pre>
<br /><p>
Now that we have the prototype, we want to construct a new list,<br />
and we do that by calling new, which is the default Perl 6<br />
constructor, but to do that, we need to get the call &quot;new&quot; on the<br />
responder interface.</p>
<pre>
SMOP__ResponderInterface* list_responder = SMOP_RI(list_prototype);
</pre>
<br /><p>
The method resolution is something that depends entirely on the<br />
responder, so we need to provide with an already high-level compatible<br />
capture object.</p>
<pre>
SMOP__Object* capture =
  SMOP_LOWL_CAPTURE(list_prototype /* invocant */,
               NULL /* no positional arguments */,
               NULL /* no named arguments */);
</pre>
<br /><p>
Now that we have the capture for the &quot;new&quot; call, we can send a<br />
message to the responder. Notice that the binding and the actual call<br />
will happen inside the responder.</p>
<pre>
SMOP__Object* result =
  SMOP_DISPATCH(
       interpreter,
       list_responder,
       SMOP__ID__new,
       arguments);
</pre>
<br /><p>
The method new, in this case would probably be the new method for<br />
lowlevel prototype. which looks just like:</p>
<pre>
sub new ($prototype: |@_, |%_) {
    my $object = $prototype.CREATE();
    $prototype.bless($object, |@_, |%_);
}
</pre>
<br /><p>
And this would behave just the same. The responder would know <br />
to call CREATE on the prototype, and the same for bless. And that's<br />
all. The object is created. bless will call BUILDALL, BUILDALL will<br />
call BUILD where fit.</p>
<h2 id="the_bootstrap">The Bootstrap</h2>
<p>
The bootstrap would happen when the high level defines a new prototype<br />
that will have a responder of the higher level object system, and this<br />
responder will be able to implement all Perl 6 object features.</p>
<p>
At this point any object+responder can be mixed together, as<br />
in the low-level they will be binary-compatible to the lowlevel basic SMOP<br />
structures.</p>
</div>
]]></description>
<author>pawelmurias@hidden</author>
<guid isPermaLink="true">http://www.perlfoundation.org/perl6/index.cgi?smop_oo_bootstrap</guid>
<pubDate>Mon, 12 May 2008 20:45:44 -0000</pubDate>
</item>

</channel>
</rss>