/*
Copyright (C) 2001-2003, The Perl Foundation.
$Id: multisub.pmc 16275 2006-12-28 01:20:44Z particle $

=head1 NAME

src/pmc/multisub.pmc - A container for Perl6 multi subs

=head1 DESCRIPTION

This class inherits from ResizablePMCArray and provides an Array of
Sub PMCs with the same short name, but different long names.

=head2 Functions

=over 4

=cut

*/

#include "parrot/parrot.h"


pmclass MultiSub extends ResizablePMCArray need_ext does array {

    void push_pmc(PMC* value) {
        STRING *_sub = CONST_STRING(interp, "Sub");
        STRING *_nci = CONST_STRING(interp, "NCI");
        if (!VTABLE_isa(interp, value, _sub) &&
            !VTABLE_isa(interp, value, _nci))
            real_exception(interp, NULL, E_TypeError,
                    "attempt to push non Sub PMC");
        SUPER(value);
    }

    void set_pmc_keyed_int(INTVAL key, PMC* value) {
        STRING *_sub = CONST_STRING(interp, "Sub");
        if (!VTABLE_isa(interp, value, _sub))
            real_exception(interp, NULL, E_TypeError,
                    "attempt to set non Sub PMC");
        SUPER(key, value);
    }

    void set_integer_keyed_int(INTVAL key, INTVAL value) {
        real_exception(interp, NULL, E_TypeError,
                "attempt to set non Sub PMC");
    }

    void set_string_keyed_int(INTVAL key, STRING* value) {
        real_exception(interp, NULL, E_TypeError,
                "attempt to set non Sub PMC");
    }

    void set_number_keyed_int(INTVAL key, FLOATVAL value) {
        real_exception(interp, NULL, E_TypeError,
                "attempt to set non Sub PMC");
    }

    void* invoke(void *next) {
        PMC *list = Parrot_mmd_sort_candidate_list(interp, SELF);
        PMC *func = PMCNULL;
        if (!PMC_IS_NULL(list))
            func = VTABLE_get_pmc_keyed_int(interp, list, 0);
        return VTABLE_invoke(INTERP, func, next);
    }
}

/*

=back

=head1 SEE ALSO

F<src/mmd.c>,
F<$perl6/doc/trunk/design/apo/A12.pod>,
F<$perl6/doc/trunk/design/syn/S12.pod>

=head1 HISTORY

Initial version                  - leo 14.03.2005

=cut

*/

/*
 * Local variables:
 *   c-file-style: "parrot"
 * End:
 * vim: expandtab shiftwidth=4:
 */
