Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix up my ($a, $b) again, with a little refactoring of the way we han…
…dle symbol registration. This also fudges in multisig, though we don't actually parse multiple signatures just yet.
  • Loading branch information
jnthn committed Feb 3, 2010
1 parent 380ff4a commit 20f54dd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
32 changes: 18 additions & 14 deletions src/Perl6/Actions.pm
Expand Up @@ -655,11 +655,16 @@ method variable_declarator($/) {
my $past := $<variable>.ast;
my $sigil := $<variable><sigil>;
my $twigil := $<variable><twigil>[0];
my $name := ~$sigil ~ ~$twigil ~ ~$<variable><desigilname>;
if @BLOCK[0].symbol($name) {
$/.CURSOR.panic("Redeclaration of symbol ", $name);
}
make declare_variable($/, $past, ~$sigil, ~$twigil, ~$<variable><desigilname>, $<trait>);
}

sub declare_variable($/, $past, $sigil, $twigil, $desigilname, $trait_list) {
my $name := $sigil ~ $twigil ~ $desigilname;
my $name := $sigil ~ $twigil ~ $desigilname;
my $BLOCK := @BLOCK[0];

if $*SCOPE eq 'has' {
# Find the current package and add the attribute.
Expand All @@ -675,7 +680,6 @@ sub declare_variable($/, $past, $sigil, $twigil, $desigilname, $trait_list) {

# If no twigil, note $foo is an alias to $!foo.
if $twigil eq '' {
my $BLOCK := @BLOCK[0];
$BLOCK.symbol($name, :attr_alias($attrname));
}

Expand All @@ -685,13 +689,7 @@ sub declare_variable($/, $past, $sigil, $twigil, $desigilname, $trait_list) {
$past<attribute_data> := %attr_table{$attrname};
}
else {
# Not an attribute - need to emit delcaration here. Check it's
# not a duplicate.
my $BLOCK := @BLOCK[0];
if $BLOCK.symbol($name) {
$/.CURSOR.panic("Redeclaration of symbol ", $name);
}

# Not an attribute - need to emit delcaration here.
# First, create a container and give it a 'rw' property
# Create the container, give it a 'rw' property
my $cont := PAST::Op.new( sigiltype($sigil), :pirop('new Ps') );
Expand Down Expand Up @@ -752,10 +750,10 @@ method routine_def($/) {
my $past := $<blockoid>.ast;
$past.blocktype('declaration');
$past.control('return_pir');
if pir::defined__IP($past<placeholder_sig>) && $<signature> {
if pir::defined__IP($past<placeholder_sig>) && $<multisig> {
$/.CURSOR.panic('Placeholder variable cannot override existing signature');
}
my $signature := $<signature> ?? $<signature>[0].ast !!
my $signature := $<multisig> ?? $<multisig>[0].ast !!
pir::defined__IP($past<placeholder_sig>) ?? $past<placeholder_sig> !!
Perl6::Compiler::Signature.new();
$signature.set_default_parameter_type('Any');
Expand Down Expand Up @@ -858,7 +856,7 @@ method method_def($/) {
if pir::defined__IP($past<placeholder_sig>) {
$/.CURSOR.panic('Placeholder variables cannot be used in a method');
}
my $sig := $<signature> ?? $<signature>[0].ast !! Perl6::Compiler::Signature.new();
my $sig := $<multisig> ?? $<multisig>[0].ast !! Perl6::Compiler::Signature.new();
$sig.add_invocant();
$sig.set_default_parameter_type('Any');

Expand Down Expand Up @@ -974,6 +972,10 @@ method regex_declarator($/, $key?) {
}
}

method multisig($/) {
make $<signature>.ast;
}

method signature($/) {
my $signature := Perl6::Compiler::Signature.new();
my $cur_param := 0;
Expand Down Expand Up @@ -1048,8 +1050,10 @@ method param_var($/) {
}
else {
$*PARAMETER.var_name(~$/);
my @BlOCK;
@BLOCK[0].symbol(~$/, :scope('lexical'));
if @BLOCK[0].symbol(~$/) {
$/.CURSOR.panic("Redeclaration of symbol ", ~$/);
}
@BLOCK[0].symbol(~$/, :scope($*SCOPE eq 'my' ?? 'lexical' !! 'package'));
}
}

Expand Down
13 changes: 10 additions & 3 deletions src/Perl6/Grammar.pm
Expand Up @@ -274,6 +274,7 @@ token xblock($*IMPLICIT = 0) {
token pblock($*IMPLICIT = 0) {
| <.lambda>
<.newpad>
:my $*SCOPE := 'my';
<signature>
<blockoid>
| <?[{]>
Expand Down Expand Up @@ -586,7 +587,7 @@ rule routine_def {
:my $*IN_DECL := 'routine';
<deflongname>?
<.newpad>
[ '(' <signature> ')' ]?
[ '(' <multisig> ')' ]?
<trait>*
{ $*IN_DECL := ''; }
<blockoid>
Expand All @@ -597,8 +598,8 @@ rule method_def {
[
<.newpad>
[
| $<specials>=[<[ ! ^ ]>?]<longname> [ '(' <signature> ')' ]? <trait>*
| [ '(' <signature> ')' ]? <trait>*
| $<specials>=[<[ ! ^ ]>?]<longname> [ '(' <multisig> ')' ]? <trait>*
| [ '(' <multisig> ')' ]? <trait>*
| <?>
]
{ $*IN_DECL := ''; }
Expand All @@ -615,6 +616,12 @@ rule param_sep {
$<sep>=[','|':'|';'|';;'] { @*seps.push($<sep>) }
}

# XXX Not really implemented yet.
rule multisig {
:my $*SCOPE := 'my';
<signature>
}

token signature {
:my $*IN_DECL := 'sig';
:my $*zone := 'posreq';
Expand Down

0 comments on commit 20f54dd

Please sign in to comment.