Skip to content
This repository was archived by the owner on Feb 3, 2021. It is now read-only.

Commit 2f51f68

Browse files
committed
Pull the old meta-model's handling of method_def out into something we can easily toss later. (Can't quite toss it yet; grammar is not using 6model yet, and there are grammars with methods within nqp-rx itself, so removing it now would break the bootstrap.)
1 parent d3290da commit 2f51f68

File tree

1 file changed

+49
-45
lines changed

1 file changed

+49
-45
lines changed

src/NQP/Actions.pm

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -579,59 +579,63 @@ method routine_def($/) {
579579

580580

581581
method method_def($/) {
582-
if $*PACKAGE-SETUP {
583-
# Set up block including adding self (invocant) parameter.
584-
my $past := $<blockoid>.ast;
585-
$past.control('return_pir');
586-
$past[0].unshift( PAST::Var.new( :name('self'), :scope('parameter') ) );
587-
$past.symbol('self', :scope('lexical') );
588-
589-
# Install it where it should go (methods table / namespace).
590-
if $<deflongname> {
591-
my $name := ~$<deflongname>[0].ast;
592-
$past.name($name);
593-
$*PACKAGE-SETUP.push(PAST::Op.new(
594-
:pasttype('callmethod'), :name($*MULTINESS eq 'multi' ?? 'add_multi_method' !! 'add_method'),
595-
PAST::Op.new(
596-
# XXX Should be nqpop at some point.
597-
:pirop('get_how PP'),
598-
PAST::Var.new( :name('type_obj'), :scope('register') )
599-
),
600-
PAST::Var.new( :name('type_obj'), :scope('register') ),
601-
PAST::Val.new( :value($name) ),
602-
PAST::Val.new( :value($past) )
603-
));
604-
}
605-
if $*SCOPE eq 'our' {
606-
$past.pirflags(':nsentry');
607-
}
582+
# XXX Remove this when grammar switches over to using 6model.
583+
unless $*PACKAGE-SETUP {
584+
return OLD_method_def($/);
585+
}
608586

609-
$past<block_past> := $past;
610-
make $past;
587+
# Set up block including adding self (invocant) parameter.
588+
my $past := $<blockoid>.ast;
589+
$past.control('return_pir');
590+
$past[0].unshift( PAST::Var.new( :name('self'), :scope('parameter') ) );
591+
$past.symbol('self', :scope('lexical') );
592+
593+
# Install it where it should go (methods table / namespace).
594+
if $<deflongname> {
595+
my $name := ~$<deflongname>[0].ast;
596+
$past.name($name);
597+
$*PACKAGE-SETUP.push(PAST::Op.new(
598+
:pasttype('callmethod'), :name($*MULTINESS eq 'multi' ?? 'add_multi_method' !! 'add_method'),
599+
PAST::Op.new(
600+
# XXX Should be nqpop at some point.
601+
:pirop('get_how PP'),
602+
PAST::Var.new( :name('type_obj'), :scope('register') )
603+
),
604+
PAST::Var.new( :name('type_obj'), :scope('register') ),
605+
PAST::Val.new( :value($name) ),
606+
PAST::Val.new( :value($past) )
607+
));
611608
}
612-
else {
613-
my $past := $<blockoid>.ast;
614-
$past.blocktype('method');
615-
if $*SCOPE eq 'our' {
616-
$past.pirflags(':nsentry');
617-
}
618-
$past.control('return_pir');
619-
$past[0].unshift( PAST::Op.new( :inline(' .lex "self", self') ) );
620-
$past.symbol('self', :scope('lexical') );
621-
if $<deflongname> {
622-
my $name := ~$<deflongname>[0].ast;
623-
$past.name($name);
624-
}
625-
if $*MULTINESS eq 'multi' { $past.multi().unshift('_'); }
626-
$past<block_past> := $past;
627-
make $past;
609+
if $*SCOPE eq 'our' {
610+
$past.pirflags(':nsentry');
628611
}
612+
613+
$past<block_past> := $past;
614+
make $past;
615+
}
616+
617+
# XXX Toss this when grammar moves over to 6model.
618+
sub OLD_method_def($/) {
619+
my $past := $<blockoid>.ast;
620+
$past.blocktype('method');
621+
if $*SCOPE eq 'our' {
622+
$past.pirflags(':nsentry');
623+
}
624+
$past.control('return_pir');
625+
$past[0].unshift( PAST::Op.new( :inline(' .lex "self", self') ) );
626+
$past.symbol('self', :scope('lexical') );
627+
if $<deflongname> {
628+
my $name := ~$<deflongname>[0].ast;
629+
$past.name($name);
630+
}
631+
if $*MULTINESS eq 'multi' { $past.multi().unshift('_'); }
632+
$past<block_past> := $past;
629633
if $<trait> {
630634
for $<trait> { $_.ast()($/); }
631635
}
636+
make $past;
632637
}
633638

634-
635639
method signature($/) {
636640
my $BLOCKINIT := @BLOCK[0][0];
637641

0 commit comments

Comments
 (0)