Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bring dispatcher up to date with latest handles dispatch fallback han…
…dling approach. Also, can't just go on truth for if we have a $!handles value because type objects are undefined and untrue. With this, we handle all the cases the alpha did again.
  • Loading branch information
jnthn committed Jun 20, 2010
1 parent 13fabba commit 5624fe3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
17 changes: 17 additions & 0 deletions src/glue/dispatch.pir
Expand Up @@ -306,6 +306,23 @@ Helper for handling calls of the form .$indirectthingy()
.end
=item !handles_dispatch_helper
Helper for implementing delegation to a handles method.
=cut
.sub '!handles_dispatch_helper'
.param string methodname
.param string attrname
.param pmc self
.param pmc pos_args :slurpy
.param pmc named_args :slurpy :named
$P0 = getattribute self, attrname
.tailcall $P0.methodname(pos_args :flat, named_args :flat :named)
.end
=item !deferal_fail
Used by P6invocation to help us get soft-failure semantics when no deferal
Expand Down
2 changes: 1 addition & 1 deletion src/metamodel/Attribute.nqp
Expand Up @@ -84,7 +84,7 @@ method compose($package) {
}

# If we've a handles, pass it along to the handles setup helper.
if $!handles {
unless pir::isa__ips($!handles, 'Undef') {
Rakudo::Guts.add_handles_method($package, $!name, $!handles);
}
}
Expand Down
25 changes: 14 additions & 11 deletions src/pmc/p6opaque.pmc
Expand Up @@ -125,7 +125,7 @@ static PMC *do_handles(PARROT_INTERP, PMC *cur_class, PMC *handlers, STRING *nam
else {
/* Use what we were given as something to smart-match against. */
PMC * const accepts_meth = VTABLE_find_method(interp, matcher, ACCEPTS_str);
PMC * result = PMCNULL;;
PMC * result = PMCNULL;
Parrot_ext_call(interp, accepts_meth, "PiS->P", matcher, name, &result);
if (VTABLE_get_bool(interp, result)) {
attr = VTABLE_get_string_keyed_str(interp, handles_hash, attrname);
Expand All @@ -141,16 +141,16 @@ static PMC *do_handles(PARROT_INTERP, PMC *cur_class, PMC *handlers, STRING *nam

/* Did we find anything? */
if (attr) {
/* Look up helper, clone it, attach names and return that. */
/* Look up helper, clone it, unshift names onto argument list and return. */
PMC *sub = Parrot_ns_find_namespace_global(interp, Parrot_get_ctx_HLL_namespace(interp),
CONST_STRING(interp, "!HANDLES_DISPATCH_HELPER"));
CONST_STRING(interp, "!handles_dispatch_helper"));
PMC *call_sig = Parrot_pcc_get_signature(interp, CURRENT_CONTEXT(interp));
PMC *boxed_attrname = pmc_new(interp, enum_class_String);
PMC *boxed_methodname = pmc_new(interp, enum_class_String);
VTABLE_set_string_native(interp, boxed_attrname, attr);
VTABLE_set_string_native(interp, boxed_methodname, name);
sub = VTABLE_clone(interp, sub);
VTABLE_setprop(interp, sub, attrname_str, boxed_attrname);
VTABLE_setprop(interp, sub, methodname_str, boxed_methodname);
VTABLE_unshift_pmc(interp, call_sig, boxed_attrname);
VTABLE_unshift_pmc(interp, call_sig, boxed_methodname);
return sub;
}
else {
Expand Down Expand Up @@ -245,11 +245,14 @@ PMC *look_for_method(PARROT_INTERP, PMC *search_list, INTVAL *start_pos, STRING
if (PMC_IS_NULL(method)) {
for (i = *start_pos; i < num_classes; i++) {
PMC * const cur_class = VTABLE_get_pmc_keyed_int(interp, search_list, i);
PMC *handles = VTABLE_getprop(interp, cur_class, CONST_STRING(interp, "@!handles_dispatchers"));
if (!PMC_IS_NULL(handles)) {
method = do_handles(interp, cur_class, handles, name);
if (!PMC_IS_NULL(method))
break;
PMC * const how = VTABLE_getprop(interp, cur_class, metaclass_str);
if (!PMC_IS_NULL(how) && VTABLE_isa(interp, how, CONST_STRING(interp, "ClassHOW"))) {
PMC * handles = VTABLE_get_attr_str(interp, how, CONST_STRING(interp, "$!handles_dispatchers"));
if (!PMC_IS_NULL(handles)) {
method = do_handles(interp, cur_class, handles, name);
if (!PMC_IS_NULL(method))
break;
}
}
}
}
Expand Down

0 comments on commit 5624fe3

Please sign in to comment.