Anyway, just after I sent the question a thing crossed my mind it happened to be a (or the) solution to the problem: the modified grammar has to be applied to $*LANG alongside with the MAIN slang. But then again, this is what I learned from add_package_declarator with only vague idea of why it works. Yet, I still need a confirmation that this is the correct approach either in a form of extended testing or by a confirmation from an expert.
I know that I'm diggin' in areas, where I don't even have enough expertise. Or, ad timotimo put is, I'm "operating at the edge of known science". But that is really the only way to achieve my goal – make things simpler for the user and the final code more readable by hiding as much as possible under the hood of the implementation module. > On Dec 26, 2018, at 7:47 AM, Elizabeth Mattijsen <l...@dijkmat.nl> wrote: > > This feels like you’re getting into the bleeding edges of MOP. My > understanding is that a MVMContext is purely a runtime thing. Not sure how > it comes to be that the MVMContext needs serializing, but that error message > indicates that the VM is not ready to do that. > > So my guess is that somehow during compilation, the MVMContext gets added to > the SC (Serialization Context) when it shouldn’t. > > Most likely Timo Paulssen or Jonathan Worthington can give you better answers. > >> On 26 Dec 2018, at 04:26, Vadim Belman <vr...@lflat.org> wrote: >> >> Hi! >> >> 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"; >> nextsame; >> } >> } >> >> 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)); >> <sym><.kok> >> <package_def> >> <.set_braid_from(self)> >> } >> } >> >> 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" } >> } >> >> My.new.foo; >> >> everything works as expected, I get this output: >> >> My compose >> !foo >> >> 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 >> ===SORRY!=== >> 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 >> > Best regards, Vadim Belman