Skip to content

Commit

Permalink
[dotnet] Update JnthnNQP to parse a * as the sole body of a proto and…
Browse files Browse the repository at this point in the history
… turn it into a dispatcher call. Do it a bit differently from STD, since we don't parse * at all otherwise.
  • Loading branch information
jnthn committed Oct 30, 2010
1 parent 92997a3 commit cac2fa6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
41 changes: 32 additions & 9 deletions dotnet/compiler/Actions.pm
Expand Up @@ -485,9 +485,18 @@ method routine_declarator:sym<sub>($/) { make $<routine_def>.ast; }
method routine_declarator:sym<method>($/) { make $<method_def>.ast; }

method routine_def($/) {
my $past := $<blockoid>.ast;
$past.blocktype('declaration');
$past.control('return_pir');
# If it's just got * as a body, make a multi-dispatch enterer.
# Otherwise, need to build a sub.
my $past;
if $<onlystar> {
$past := only_star_block();
}
else {
$past := $<blockoid>.ast;
$past.blocktype('declaration');
$past.control('return_pir');
}

if $<deflongname> {
my $name := ~$<sigil>[0] ~ $<deflongname>[0].ast;
$past.name($name);
Expand Down Expand Up @@ -569,13 +578,19 @@ method routine_def($/) {


method method_def($/) {
# Build method block PAST.
my $past := $<blockoid>.ast;
$past.blocktype('declaration');
if $*SCOPE eq 'our' {
$past.pirflags(':nsentry');
# If it's just got * as a body, make a multi-dispatch enterer.
# Otherwise, build method block PAST.
my $past;
if $<onlystar> {
$past := only_star_block();
}
$past.control('return_pir');
else {
$past := $<blockoid>.ast;
$past.blocktype('declaration');
$past.control('return_pir');
}

# Always need an invocant.
$past[0].unshift( PAST::Var.new( :name('self'), :scope('parameter') ) );
$past.symbol('self', :scope('lexical') );

Expand All @@ -598,6 +613,14 @@ method method_def($/) {
make $past;
}

sub only_star_block() {
my $past := @BLOCK.shift;
$past.closure(1);
$past.push(PAST::Op.new(
:pasttype('nqpop'), :name('multi_dispatch_over_lexical_candidates')
));
$past
}

method signature($/) {
my $BLOCKINIT := @BLOCK[0][0];
Expand Down
17 changes: 15 additions & 2 deletions dotnet/compiler/Grammar.pm
Expand Up @@ -328,15 +328,28 @@ rule routine_def {
<.newpad>
[ '(' <signature> ')'
|| <.panic: 'Routine declaration requires a signature'> ]
<blockoid>
[
| <onlystar>
| <blockoid>
]
}

rule method_def {
<deflongname>?
<.newpad>
[ '(' <signature> ')'
|| <.panic: 'Routine declaration requires a signature'> ]
<blockoid>
[
| <onlystar>
| <blockoid>
]
}

token onlystar {
<?{ $*MULTINESS eq 'proto' }>
'{' <.ws> '*' <.ws> '}'
<?ENDSTMT>
<.finishpad>
}

proto token multi_declarator { <...> }
Expand Down

0 comments on commit cac2fa6

Please sign in to comment.