develooper Front page | perl.perl6.users | Postings from December 2018

Slangs: extending package_declarator problem

Thread Next
Vadim Belman
December 26, 2018 03:27
Slangs: extending package_declarator problem
Message ID:

By playing with slangs I stumbled upon pretty confusing issue. I have a module with a test slang which looks like this:

     class My::Metamodel::MyHOW is Metamodel::ClassHOW {
         method compose (|) {
             note "My compose";

     sub EXPORT {
         use nqp;
         use NQPHLL:from<NQP>;

         my role MySlang {
             token package_declarator:sym<myclass> {
                 :my $*OUTERPACKAGE := self.package;
                 :my $*PKGDECL := 'myclass';
                 :my $*LINE_NO := HLL::Compiler.lineof(self.orig(), self.from(), :cache(1));

         my role MyActions {
             method package_declarator:sym<myclass>(Mu $/) {
                 $/.make( nqp::atkey(nqp::findmethod($/, 'hash')($/), 'package_def').ast );
         $ = $*LANG.refine_slang( 'MAIN', MySlang, MyActions );
         $*LANG.set_how('myclass', My::Metamodel::MyHOW);

And when it's used in a script:

     use lib '.';
     use myslang;

     myclass My {
         method foo { say "!foo" }

everything works as expected, I get this output:

    My compose

Then I define a module smodule.pm6:

     use myslang;

     myclass Foo {

And load it dynamically with 'require':

    require ::('smodule');

only to get this:

    My compose
    Missing serialize REPR function for REPR MVMContext (BOOTContext)

Now I wonder if it's a bug or I'm missing a thing or two in what I'm doing? So far, basic guidelines of adding a new package type were taken from World.nqp add_package_declarator method which does some extra work some of which is clearly not needed in my case; and some perhaps necessary but I don't understand it yet.

Best regards,
Vadim Belman

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About