2010-05-22

Perlesque: Class Predeclarations Enable Cylical Dependencies

It took a bit of mental effort/stamina to fix the bug(s) in Perlesque's class declarations pointed out by ++pmurias, but now that I did, I can see the next step for Perlesque is to enable class predeclarations (a la the ones in Perl 6), which was another lack-of-a-feature that pmurias was [implicitly ;)] grousing about.

This is an issue because Perlesque is fully strongly/statically typed (though it has upward type-inference on untyped declarations with initializers) and because its parser does the type-checking as it parses (in the first/same pass).  A na├»ve implementation, yes, but accordingly one that was quick-to-implement.  It also helps enforce the try-to-prevent-unnecessary-backtracking or write-the-grammar-in-such-a-way-that-backtracking-rarely-occurs strategies that ++TimToady follows with the STanDard grammar.

Perl 6 class predeclarations are provided for a similar reason, so that a typename can be referenced before its declaration body is executed (appears in the input files(s)) and its members/properties/fields/slots/state/methods are declared.  Perlesque has a stronger requirement - a class' attributes and methods must also be predeclared, but interestingly, they can be declared gradually, so a dependency graph of two classes can be built up with multiple predeclarations of each interdependent class.  This is possible because, at parse-time, the CLR TypeBuilder objects hidden behind RunSharp's TypeGen objects support gradual typing.

The syntax for method predeclaration is similar to the Perl 6 ones - a fully type-annotated method signature and an empty routine body, perhaps with a ... ellipsis to denote "stub".  

On another note, I'm still trying to think about how best to help the bootstrapping effort.  ++sorear is feverishly working on fleshing out viv's emit_p5 (the Perl 5 emission target) so that gimme5 will no longer be needed to translate STanDard to Perl 5 (an edition of STanDard that has already been translated to Perl 5 by gimme5 will initially use viv's emit_p5 to translate its own Perl 6 original to Perl 5, and from then on, the translated-by-viv edition can be used).

After trying to understand sorear's code in viv (and TimToady's, for that matter), I'm starting to suspect I should stick to the "lower" level tasks (at the VM layer).  That is, the things that Parrot provides for Rakudo.  Following that to its logical conclusion, perhaps I should continue to flesh out Perlesque so that it provides all the same sorts of features that Parrot and NQP-RX provide.  Thoughts?

No comments:

Post a Comment