Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Re-implement is default trait for multis.
  • Loading branch information
jnthn committed Jul 2, 2010
1 parent 7017d2b commit ffe80d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/core/traits.pm
Expand Up @@ -16,6 +16,10 @@ multi trait_mod:<is>(Mu $type where { !.defined }, :$rw!) {
$type.HOW does role { method rw { True } }
}

multi trait_mod:<is>(Routine $r, :$default!) {
$r does role { method default { True } }
}

role Positional { ... }
role Associative { ... }
our multi trait_mod:<of>(ContainerDeclarand $cont, Mu \$type) {
Expand Down
20 changes: 12 additions & 8 deletions src/pmc/perl6multisub.pmc
Expand Up @@ -611,15 +611,19 @@ static PMC* do_dispatch(PARROT_INTERP, PMC *self, candidate_info **candidates, P
INTVAL i;

for (i = 0; i < possibles_count; i++) {
PMC * const default_prop = VTABLE_getprop(interp, possibles[i]->sub,
PMC * const default_meth = VTABLE_find_method(interp, possibles[i]->sub,
CONST_STRING(interp, "default"));
if (!PMC_IS_NULL(default_prop)) {
if (default_cand == NULL) {
default_cand = possibles[i];
}
else {
default_cand = NULL;
break;
if (!PMC_IS_NULL(default_meth)) {
PMC *result = PMCNULL;;
Parrot_ext_call(interp, default_meth, "Pi->P", possibles[i]->sub, &result);
if (VTABLE_get_bool(interp, result)) {
if (default_cand == NULL) {
default_cand = possibles[i];
}
else {
default_cand = NULL;
break;
}
}
}
}
Expand Down

0 comments on commit ffe80d7

Please sign in to comment.