Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
First sketch of mixin support.
  • Loading branch information
jnthn committed Jul 10, 2011
1 parent ec206d6 commit 6503f6b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Perl6/Metamodel/ClassHOW.pm
Expand Up @@ -8,6 +8,7 @@ class Perl6::Metamodel::ClassHOW
does Perl6::Metamodel::RoleContainer
does Perl6::Metamodel::MultipleInheritance
does Perl6::Metamodel::C3MRO
does Perl6::Metamodel::Mixins
does Perl6::Metamodel::NonGeneric
does Perl6::Metamodel::ParrotInterop
{
Expand Down
21 changes: 21 additions & 0 deletions src/Perl6/Metamodel/Mixins.pm
@@ -0,0 +1,21 @@
role Perl6::Metamodel::Mixins {
method mixin($obj, *@roles) {
# Work out a type name for the post-mixed-in role.
my @role_names;
for @roles { @role_names.push($_.HOW.name($_)) }
my $new_name := self.name($obj) ~ '+{' ~
pir::join(',', @role_names) ~ '}';

# Create new type, derive it from ourself and then add
# all the roles we're mixing it.
my $new_type := self.new_type(:name($new_name));
$new_type.HOW.add_parent($new_type, $obj.WHAT);
for @roles {
$new_type.HOW.add_role($new_type, $_);
}
$new_type.HOW.compose($new_type);

# Call low-level op to do the actual mixing in.
pir::repr_change_type__0PP($obj, $new_type)
}
}
1 change: 1 addition & 0 deletions tools/build/Makefile.in
Expand Up @@ -93,6 +93,7 @@ METAMODEL_SOURCES = \
src/Perl6/Metamodel/RoleContainer.pm \
src/Perl6/Metamodel/MultipleInheritance.pm \
src/Perl6/Metamodel/C3MRO.pm \
src/Perl6/Metamodel/Mixins.pm \
src/Perl6/Metamodel/ParrotInterop.pm \
src/Perl6/Metamodel/TypePretence.pm \
src/Perl6/Metamodel/RolePunning.pm \
Expand Down

0 comments on commit 6503f6b

Please sign in to comment.