Skip to content

Commit

Permalink
Start to tease apart abstract roles (the name for the whole set of po…
Browse files Browse the repository at this point in the history
…ssible parameterizations) and concrete roles (a particular variant) in the type system, and tweak infix:<does> to take advantage of it. Probably more to come on this, but it's a start.
  • Loading branch information
jnthn committed Mar 2, 2010
1 parent 6867a56 commit 9921175
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions build/Makefile.in
Expand Up @@ -91,6 +91,7 @@ BUILTINS_PIR = \
src/metamodel/GrammarHOW.pir \
src/builtins/Any.pir \
src/builtins/Role.pir \
src/builtins/ConcreteRole.pir \
src/builtins/Abstraction.pir \
src/builtins/Positional.pir \
src/builtins/Iterable.pir \
Expand Down
41 changes: 41 additions & 0 deletions src/builtins/ConcreteRole.pir
@@ -0,0 +1,41 @@
## $Id$

=head1 NAME

src/classes/ConcreteRole.pir - methods for the ConcreteRole class

=head1 Description

A concrete role is a role that has been selected from an abstract role by
providing a (possibly empty) set of role parameters. This class for now
is primarily just designed to know how to match one of them in a multiple
dispatch.

=head1 Methods

=over 4

=cut

.namespace ['ConcreteRole']

.sub 'onload' :anon :init :load
.local pmc p6meta, proto
p6meta = get_hll_global ['Mu'], '$!P6META'
proto = p6meta.'new_class'('ConcreteRole', 'parent'=>'Any')
.end

.sub 'PROTOOVERRIDES' :method
.return ('new', 'ACCEPTS')
.end

.sub 'ACCEPTS' :method
.param pmc topic
$I0 = isa topic, 'P6role'
$P0 = '&prefix:<?>'($I0)
.return ($P0)
.end

=back

=cut
7 changes: 5 additions & 2 deletions src/core/operators.pm
Expand Up @@ -93,8 +93,11 @@ our sub undefine(Mu \$x) {
}

our multi infix:<does>(Mu \$do-it-to-me, Role $r) {
my $specific_role = $r!select;
my $applicator = $specific_role.^applier_for($do-it-to-me);
&infix:<does>($do-it-to-me, $r!select)
}

our multi infix:<does>(Mu \$do-it-to-me, ConcreteRole $r) {
my $applicator = $r.^applier_for($do-it-to-me);
$applicator.apply($do-it-to-me, [$r]);
$do-it-to-me
}
Expand Down

0 comments on commit 9921175

Please sign in to comment.