Skip to content

Commit

Permalink
More work on bringing our traits support closer in line with S14 and …
Browse files Browse the repository at this point in the history
…STD.pm. This kills trait_auxiliary in favor of trait_mod, adds parsing and an implementation of will (just delegates to is) and parsing of hides too (not yet implemnted), so now we should parse all the trait mods that STD does.
  • Loading branch information
jnthn committed Jul 1, 2009
1 parent 2dded8e commit 59d2b7a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions build/Makefile.in
Expand Up @@ -127,6 +127,7 @@ SETTING = \
src/setting/Range.pm \
src/setting/Temporal.pm \
src/setting/Whatever.pm \
src/setting/traits.pm \

PMCS = perl6str objectref perl6scalar mutablevar perl6multisub p6invocation p6opaque p6role

Expand Down
8 changes: 4 additions & 4 deletions src/builtins/guts.pir
Expand Up @@ -682,9 +682,9 @@ Add a trait with the given C<type> and C<name> to C<metaclass>.
.param pmc pos_args :slurpy
.param pmc named_args :slurpy :named

if type == 'trait_auxiliary:is' goto is
if type == 'trait_auxiliary:does' goto does
'die'("Unknown trait auxiliary ", type)
if type == 'trait_mod:is' goto is
if type == 'trait_mod:does' goto does
'die'("Unknown trait_mod: ", type)

is:
## get the (parrot)class object associated with name
Expand Down Expand Up @@ -911,7 +911,7 @@ and C<type>.
null arg
have_arg:

$S0 = substr trait, 16
$S0 = substr trait, 10
$S0 = concat '!var_trait_', $S0
$P0 = find_name $S0
if null $P0 goto done
Expand Down
14 changes: 7 additions & 7 deletions src/parser/actions.pm
Expand Up @@ -918,7 +918,7 @@ method trait_mod($/) {
my $sym := ~$<sym>;
my $trait := PAST::Op.new( :name('infix:,'));
if $sym eq 'is' {
$trait.push( 'trait_auxiliary:' ~ $sym );
$trait.push( 'trait_mod:' ~ $sym );
$trait.push( ~$<name> );
if $<postcircumfix> {
my $arg := $<postcircumfix>[0].ast;
Expand All @@ -927,7 +927,7 @@ method trait_mod($/) {
}
}
elsif $sym eq 'does' {
$trait.push( 'trait_auxiliary:' ~ $sym );
$trait.push( 'trait_mod:' ~ $sym );
$trait.push( ~$<name> );
if $<EXPR> {
for @(build_call($<EXPR>[0].ast)) {
Expand Down Expand Up @@ -1460,7 +1460,7 @@ method package_declarator($/, $key) {
$block[0].push(PAST::Op.new(
:name('!meta_trait'),
$?METACLASS,
'trait_auxiliary:does',
'trait_mod:does',
$typename
));
make PAST::Stmts.new()
Expand Down Expand Up @@ -1576,9 +1576,9 @@ method package_def($/, $key) {
my $trait := $_.ast;
if $trait[1] eq 'also' { $block<isalso> := 1; }
elsif $trait[1] ne 'rw' && $trait[1] ne 'hidden' {
## If it is a trait_auxiliary:does or a trait_auxiliary:is we
## If it is a trait_mod:does or a trait_mod:is we
## should check the name is a type.
if $trait[0] eq 'trait_auxiliary:is' || $trait[0] eq 'trait_auxiliary:does' {
if $trait[0] eq 'trait_mod:is' || $trait[0] eq 'trait_mod:does' {
unless $/.is_type($trait[1]) {
$_.panic("The type " ~ $trait[1] ~ " does not exist.");
}
Expand Down Expand Up @@ -3173,7 +3173,7 @@ sub make_sigparam($var) {
sub add_optoken($block, $match) {
my $category := ~$match<category>;
my $name := $category ~ ':' ~ ~$match[0];
if $category ne 'trait_auxiliary' {
if $category ne 'trait_mod' {
my $equiv := 'infix:+';
if $category eq 'prefix' { $equiv := 'prefix:+' }
elsif $category eq 'postfix' { $equiv := 'postfix:++' }
Expand Down Expand Up @@ -3268,7 +3268,7 @@ sub package_has_trait($name) {
my $block := $?BLOCK_OPEN || @?BLOCK[0];
for $block<traits> {
my $ast := $_.ast;
if +@($ast) >= 2 && $ast[0] eq 'trait_auxiliary:is' && $ast[1] eq $name {
if +@($ast) >= 2 && $ast[0] eq 'trait_mod:is' && $ast[1] eq $name {
return 1;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/parser/grammar.pg
Expand Up @@ -446,6 +446,7 @@ rule trait {
rule trait_mod {
[
| $<sym>=[is] <name><postcircumfix>?
| $<sym>=[hides] <module_name>
| $<sym>=[does] <name>['['<EXPR>?']']?
| $<sym>=[will] <identifier> <block>
| $<sym>=[of|returns] <fulltypename>
Expand Down Expand Up @@ -873,7 +874,7 @@ token subshortname {
<category> <colonpair>+
}

token category { 'infix' | 'prefix' | 'postfix' | 'circumfix' | 'postcircumfix' | 'trait_auxiliary' }
token category { 'infix' | 'prefix' | 'postfix' | 'circumfix' | 'postcircumfix' | 'trait_mod' }

## used internally to convert p6 opnames to internal ones
regex opname {
Expand Down
3 changes: 3 additions & 0 deletions src/setting/traits.pm
@@ -0,0 +1,3 @@
multi sub trait_mod:<will>($declarand, $trait, &arg) {
&trait_mod:<is>($declarand, $trait, &arg);
}

0 comments on commit 59d2b7a

Please sign in to comment.