SMOP Grant special update
Tue, 25-Nov-2008 by
Alberto Simões
edit post
Daniel Ruoso's Grant Manager just forwarded a big update on SMOP. To keep people up-to-date on current developments I am publishing it off schedule. Please refer to the extended version of this post for details.
We are already a month off-scedule ;) . But I'm pretty happy anyway, and I'm pretty confident that this delay is worth the trouble, considering the interesting amount of progress we're having (except for this last week, when my child has just born and a lot of personal issues arose). So, to the update:
We're working on adding features to mildew, which is the STD->SMOP compiler, meaning that it uses the STD grammar directly, meaning that the parse nodes as returned by the STD parse are used directly from mildew. This is, IMHO, a very important aspect, and something that was not covered by the initial grant proposal. In the initial grant proposal we meant to have a first-stage compiler that would compile just a subset of Perl 6, now we have a real Perl 6 compiler. Comparing with previous projects, we're one step ahead of where KP6 got, it would be pretty fair to compile mildew with rakudo, except that rakudo is far ahead in the number of features supported, while mildew, because of the strong MOP orientation of SMOP, probably have runtime support for some OO features that rakudo doesn't yet support. The most important part of this, is that we (SMOP and Parrot hackers) are more and more sharing information and getting around problems and corner cases of the specs, Larry is hav
ing a lot of work this days...
On the specifics of mildew and smop, we already support the following piece of code:
knowhow ClassHOW {
method add_method($how: $object, $name, $code) {
$object.^!methods.{$name} = $code;
}
method dispatch($responder, $identifier, $capture) {
my $invocant = $capture.invocant();
if $invocant.^!methods.exists($identifier) {
$invocant.^!methods.{$identifier}.postcircumfix:<( )>($capture);
} else {
die 'No method ',$identifier;
}
}
}
class Foo {
my $inner_var;
method bar {
$OUT.print($inner_var.FETCH);
}
method foo($value) {
$inner_var = $value;
}
}
$OUT.print("1..1\n");
Foo.foo("ok 1 - methods are called.\n");
Foo.bar;
What is important to notice here, is that the keyword knowhow (already part of the STD) implements a Pure Prototype object, implemented by the low-level PurePrototypeHOW, the keyword "class" OTOH, creates a new class which have ClassHOW as its "HOW" (yes, actually the code above it). What happens here is that we have the class Foo MOP implemented by ClassHOW which is implemented itself in Perl 6.
Additionally, the method declaration happens by a lexical lookup for $?CLASS, which is previously declared by the package declarator, together with $?PACKAGE. This means that the compiler itself is using the compiler runtime to create the classes, this is a very important bootstrap milestone.
Well, we're working towards the implementation of ClassHOW, which is the default Perl 6 metaclass, the list of tests in v6/mildew/t/ in the pugs repository shows the evolution of the compiler, after we finish that, we can move on to implement Object, and then all the built-in types, and that would be the end of this grant.
Comments (3)
Great work! I'm really excited with this [promising] project.
Looks interesting, though it seems it uses a few features I haven't seen before. The knowhow keyword is interesting, but can someone explain me why it can't just be a class itself (with an indication it's implemented by PurePrototypeHOW)?
Also, I'm not familiar with the ^!methods syntax. I get the caret, but what does the exclamation mark do?
Exclamation mark is for private variables/methods.