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

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

<channel>
<title><![CDATA[Perl 6: SMOP Native Types]]></title>
<link>http://www.perlfoundation.org/perl6/index.cgi?smop_native_types</link>
<description></description>
<pubDate>Fri, 18 Jan 2008 17:09:58 -0000</pubDate>
<webMaster>synedra@gmail.com</webMaster>
<generator>Socialtext Workspace v2.14.7.2</generator>

<item>
<title><![CDATA[SMOP Native Types]]></title>
<link>http://www.perlfoundation.org/perl6/index.cgi?smop_native_types</link>
<description><![CDATA[<div class="wiki">
<p>
Besides the basic structures to which all objects must be<br />
binary-compatible with, we also need to have defined which are the<br />
native types for <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>. These types are the key for the SMOP runtime<br />
being able to actually do something in the low-level. The key to<br />
that is in S12:</p>
<blockquote>
You may derive from any built-in type, but the derivation of<br />
a low-level type like int may only add behaviors, not change<br />
the representation. Use composition and/or delegation to<br />
change the representation.</blockquote>
<br /><p>
This means that the native objects can have a fixed structure. As<br />
they are known and fixed, we can intermix high-level calls and<br />
low-level calls. An important thing then, is that the autoboxing<br />
from the native types to the immutable types must be available in<br />
both ways, as the non-native implementations may even be some<br />
object that acts like a Int, so we can only use it by calling the<br />
responder interface.</p>
<p>
This means that, besides having a way to enforce numeric context to<br />
all values, we need a way to also force native-type-context to that<br />
value. Which would be something like:</p>
<pre>
 my $a = +$someobject; # Returns Int, Num, Complex or even Rat
 my $b = $a.^native(int); # returns that as int
 my $b = $a.^native(float); # returns that as float
</pre>
<br /><p>
The thing is, this methods will be part of the API of any object<br />
that emulates one of the types that can be autoboxed to/from native<br />
types. Considering that a Int is any object that returns true to<br />
.^does(Int), the low-level runtime cannot presume to know which is<br />
the lowlevel implementation of an object, the only that knows it is<br />
the responder interface, so it's natural that this native-type<br />
coercion methods reside in the responder interface. This way, SMOP<br />
will count on that to provide a &quot;native&quot; method that receives the<br />
prototype of the native-type to convert to and returns a<br />
native-type object. One, possibly more important, reason for the<br />
&quot;native&quot; method to reside in the responder interface is because a<br />
responder interface will require at least some C code, and creating<br />
the lowlevel objects are C calls, so we concentrate that there.</p>
<p>
But this doesn't mean that every responder interface must implement<br />
it directly. The call to native may result in a call to coerce to<br />
the respective high-level type before.</p>
<p>
It's important to realize that the native-type objects are binary<br />
compatible with any other object, but as they can't have they<br />
representation changed, they can't be extended, and the only<br />
prototype that can answer true to .^does(int) is the lowlevel int<br />
implementation. It is considered illegal to answer true to that for<br />
any other prototype, as this would certainly cause a segfault.</p>
</div>
]]></description>
<author>Daniel Ruoso</author>
<guid isPermaLink="true">http://www.perlfoundation.org/perl6/index.cgi?smop_native_types</guid>
<pubDate>Fri, 18 Jan 2008 17:09:58 -0000</pubDate>
</item>

</channel>
</rss>