Skip to content

Commit

Permalink
A bunch of multi-related changes. Perl6MultiSub is now mapped to Mult…
Browse files Browse the repository at this point in the history
…i, so .WHAT works (spectest added, needs to make it into the specification but seems to have consensus on #perl6). Also defined .candidates, which has similar consensus, and .push which allows constructing a multi on-the-fly.
  • Loading branch information
jnthn committed Mar 13, 2009
1 parent 88b6c25 commit 76b2652
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/Makefile.in
Expand Up @@ -75,6 +75,7 @@ BUILTINS_PIR = \
src/classes/Regex.pir \
src/classes/Method.pir \
src/classes/Submethod.pir \
src/classes/Multi.pir \
src/classes/Junction.pir \
src/classes/Failure.pir \
src/classes/Exception.pir \
Expand Down
36 changes: 36 additions & 0 deletions src/classes/Multi.pir
@@ -0,0 +1,36 @@
## $Id$

=head1 TITLE

Multi - Perl 6 multi-dispatch routine

=head1 SUBROUTINES

=over 4

=item onload()

=cut

.namespace [ 'Multi' ]

.sub 'onload' :anon :init :load
.local pmc p6meta, proto
p6meta = get_hll_global ['Perl6Object'], '$!P6META'
proto = p6meta.'new_class'('Multi', 'parent'=>'Perl6MultiSub Any')
p6meta.'register'('Perl6MultiSub', 'parent'=>proto, 'protoobject'=>proto)
.end

.sub 'Scalar' :method
.return (self)
.end

=back

=cut

# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir:
30 changes: 30 additions & 0 deletions src/pmc/perl6multisub.pmc
Expand Up @@ -1116,6 +1116,36 @@ Makes a copy of this Perl6MultiSub PMC.
SETATTR_Perl6MultiSub_candidates(interp, copy, unsorted);
return copy;
}

/*

=item METHOD void push(candidate)

Adds a candidate.

=cut

*/
METHOD push(PMC *candidate) {
VTABLE_push_pmc(interp, SELF, candidate);
RETURN ()
}

/*

=item METHOD PMC * candidates()

Gets a list of all candidates.

=cut

*/
METHOD PMC *candidates() {
PMC *candidates;
GETATTR_Perl6MultiSub_candidates(interp, SELF, candidates);
RETURN (PMC *candidates);
}

}

/*
Expand Down

0 comments on commit 76b2652

Please sign in to comment.