Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[dotnet] Get JnthnNQP able to parse and compile explicit invocants in…
… method signatures.
  • Loading branch information
jnthn committed Nov 13, 2010
1 parent 826917e commit 4f8333c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
13 changes: 12 additions & 1 deletion dotnet/compiler/Actions.pm
Expand Up @@ -631,7 +631,9 @@ method method_def($/) {
}

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

# Provided it's named, install it in the methods table.
Expand Down Expand Up @@ -675,6 +677,15 @@ sub only_star_block() {

method signature($/) {
my $BLOCKINIT := @BLOCK[0][0];
if $<invocant> {
my $inv := $<invocant>[0].ast;
$BLOCKINIT.push($inv);
$BLOCKINIT.push(PAST::Var.new(
:name('self'), :scope('lexical'), :isdecl(1),
:viviself(PAST::Var.new( :scope('lexical'), :name($inv.name) ))
));
@BLOCK[0]<signature_has_invocant> := 1
}
for $<parameter> { $BLOCKINIT.push($_.ast); }
}

Expand Down
12 changes: 9 additions & 3 deletions dotnet/compiler/Grammar.pm
Expand Up @@ -19,8 +19,9 @@ method TOP() {
my %*HOW-METAATTR;
%*HOW-METAATTR<knowhow> := 'KnowHOWAttribute';

my $*SCOPE := '';
my $*MULTINESS := '';
my $*SCOPE := '';
my $*MULTINESS := '';
my $*INVOCANT_OK := 0;
self.comp_unit;
}

Expand Down Expand Up @@ -336,10 +337,12 @@ rule routine_def {
}

rule method_def {
:my $*INVOCANT_OK := 1;
<deflongname>?
<.newpad>
[ '(' <signature> ')'
|| <.panic: 'Routine declaration requires a signature'> ]
{ $*INVOCANT_OK := 0; }
[
| <onlystar>
| <blockoid>
Expand Down Expand Up @@ -369,7 +372,10 @@ token multi_declarator:sym<null> {
<declarator>
}

token signature { [ [<.ws><parameter><.ws>] ** ',' ]? }
token signature {
[ <?{ $*INVOCANT_OK }> <.ws><invocant=.parameter><.ws> ':' ]?
[ [<.ws><parameter><.ws>] ** ',' ]?
}

token parameter {
[ <typename> [ ':' $<definedness>=<[_DU]> ]? <.ws> ]* # <type_constraint>
Expand Down

0 comments on commit 4f8333c

Please sign in to comment.