Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Simply multi method construction and dispatcher testing.
  • Loading branch information
jnthn committed Apr 27, 2011
1 parent 0a24347 commit 6435cc3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
13 changes: 3 additions & 10 deletions src/NQP/Actions.pm
Expand Up @@ -814,15 +814,8 @@ class NQP::Actions is HLL::Actions {
my $name := ~$<private> ~ ~$<deflongname>[0].ast;
$past.name($name);

# If it's a proto, we'll mark it as such by giving it an empty candidate
# list. Also need to set sub PMC type to DispatcherSub.
my $to_add := $*MULTINESS ne 'proto' ??
PAST::Val.new( :value($past) ) !!
PAST::Op.new(
:pirop('set_dispatchees 0PP'),
PAST::Val.new( :value($past) ),
PAST::Op.new( :pasttype('list') )
);
# If it's a proto, we'll mark it as such setting the sub PMC
# type to DispatcherSub.
if $*MULTINESS eq 'proto' { $past.pirflags(':instanceof("DispatcherSub")'); }

# If it is a multi, we need to build a type signature object for
Expand All @@ -840,7 +833,7 @@ class NQP::Actions is HLL::Actions {
),
PAST::Var.new( :name('type_obj'), :scope('register') ),
PAST::Val.new( :value($name) ),
$to_add
PAST::Val.new( :value($past) )
));
}

Expand Down
8 changes: 5 additions & 3 deletions src/ops/nqp.ops
Expand Up @@ -625,8 +625,11 @@ Adds a single new code object to the end of a dispatcher's dispatchee list.

*/
inline op push_dispatchee(in PMC, in PMC) :base_core {
if ($1->vtable->base_type == disp_id)
if ($1->vtable->base_type == disp_id) {
if (PMC_IS_NULL(PARROT_DISPATCHERSUB($1)->dispatchees))
PARROT_DISPATCHERSUB($1)->dispatchees = pmc_new(interp, enum_class_ResizablePMCArray);
VTABLE_push_pmc(interp, PARROT_DISPATCHERSUB($1)->dispatchees, $2);
}
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use push_dispatchee if first operand is a DispatcherSub.");
Expand All @@ -643,8 +646,7 @@ list of dispatchees).

*/
inline op is_dispatcher(out INT, in PMC) :base_core {
$1 = $2->vtable->base_type == disp_id &&
!PMC_IS_NULL(PARROT_DISPATCHERSUB($2)->dispatchees);
$1 = $2->vtable->base_type == disp_id;
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/pmc/dispatchersub.pmc
Expand Up @@ -3,7 +3,7 @@
pmclass DispatcherSub extends Sub auto_attrs dynpmc group nqp {
ATTR PMC *dispatchees; /* Used if this code object is a dispatcher. */
ATTR PMC *dispatch_cache; /* Holds a (multi-)dispatch cache if needed. */

VTABLE void mark() {
PMC *dispatchees;
SUPER();
Expand Down

0 comments on commit 6435cc3

Please sign in to comment.