Skip to content

Commit 6435cc3

Browse files
committed
Simply multi method construction and dispatcher testing.
1 parent 0a24347 commit 6435cc3

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

src/NQP/Actions.pm

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -814,15 +814,8 @@ class NQP::Actions is HLL::Actions {
814814
my $name := ~$<private> ~ ~$<deflongname>[0].ast;
815815
$past.name($name);
816816

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

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

src/ops/nqp.ops

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,11 @@ Adds a single new code object to the end of a dispatcher's dispatchee list.
625625

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

644647
*/
645648
inline op is_dispatcher(out INT, in PMC) :base_core {
646-
$1 = $2->vtable->base_type == disp_id &&
647-
!PMC_IS_NULL(PARROT_DISPATCHERSUB($2)->dispatchees);
649+
$1 = $2->vtable->base_type == disp_id;
648650
}
649651

650652
/*

src/pmc/dispatchersub.pmc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
pmclass DispatcherSub extends Sub auto_attrs dynpmc group nqp {
44
ATTR PMC *dispatchees; /* Used if this code object is a dispatcher. */
55
ATTR PMC *dispatch_cache; /* Holds a (multi-)dispatch cache if needed. */
6-
6+
77
VTABLE void mark() {
88
PMC *dispatchees;
99
SUPER();

0 commit comments

Comments
 (0)