Skip to content

Commit

Permalink
Move .^can into MROBasedMethodDispatch role.
Browse files Browse the repository at this point in the history
Before, it was only implemented in ClassHOW, meaning that other things
that could do method dispatch missed out on having it. This fixes the
lack of .^can on EnumHOW, but also means others using the role will
get a .^can for free.
  • Loading branch information
jnthn committed Jun 23, 2015
1 parent e862714 commit d078782
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 1 addition & 17 deletions src/Perl6/Metamodel/ClassHOW.nqp
Expand Up @@ -206,23 +206,7 @@ class Perl6::Metamodel::ClassHOW
method is_composed($obj) {
$!composed
}

# Maybe this belongs on a role. Also, may be worth memoizing.
method can($obj, $name) {
my @meths;
my %smt := self.submethod_table($obj);
if nqp::existskey(%smt, $name) {
@meths.push(%smt{$name});
}
for self.mro($obj) {
my %mt := $_.HOW.method_table($_);
if nqp::existskey(%mt, $name) {
@meths.push(%mt{$name})
}
}
@meths
}


# Stuff for junctiony dispatch fallback.
my $junction_type;
my $junction_autothreader;
Expand Down
18 changes: 17 additions & 1 deletion src/Perl6/Metamodel/MROBasedMethodDispatch.nqp
Expand Up @@ -32,7 +32,23 @@ role Perl6::Metamodel::MROBasedMethodDispatch {
nqp::findmethod($qtype, $name)
}
}


# Maybe this belongs on a role. Also, may be worth memoizing.
method can($obj, $name) {
my @meths;
my %smt := self.submethod_table($obj);
if nqp::existskey(%smt, $name) {
@meths.push(%smt{$name});
}
for self.mro($obj) {
my %mt := $_.HOW.method_table($_);
if nqp::existskey(%mt, $name) {
@meths.push(%mt{$name})
}
}
@meths
}

method publish_method_cache($obj) {
# Walk MRO and add methods to cache, unless another method
# lower in the class hierarchy "shadowed" it.
Expand Down

0 comments on commit d078782

Please sign in to comment.