tagged release 0.6.4
[parrot.git] / src / pmc / multisub.pmc
blob4fa05fa5a1f4f35322ff85ebdf7a94dd2aaa1ba5
1 /*
2 Copyright (C) 2001-2007, The Perl Foundation.
3 $Id$
5 =head1 NAME
7 src/pmc/multisub.pmc - A container for multi-dispatched subs
9 =head1 DESCRIPTION
11 This class inherits from ResizablePMCArray and provides an Array of
12 Sub PMCs with the same short name, but different long names.
14 =head2 Functions
16 =over 4
18 =cut
22 #include "parrot/parrot.h"
25 pmclass MultiSub extends ResizablePMCArray need_ext provides array {
27     void push_pmc(PMC *value) {
28         STRING * const _sub = CONST_STRING(interp, "Sub");
29         STRING * const _nci = CONST_STRING(interp, "NCI");
30         if (!VTABLE_isa(interp, value, _sub) &&
31             !VTABLE_isa(interp, value, _nci))
32             real_exception(interp, NULL, E_TypeError,
33                     "attempt to push non Sub PMC");
34         SUPER(value);
35     }
37     VTABLE void set_pmc_keyed_int(INTVAL key, PMC *value) {
38         STRING *_sub = CONST_STRING(interp, "Sub");
39         if (!VTABLE_isa(interp, value, _sub))
40             real_exception(interp, NULL, E_TypeError,
41                     "attempt to set non Sub PMC");
42         SUPER(key, value);
43     }
45     VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) {
46         real_exception(interp, NULL, E_TypeError,
47                 "attempt to set non Sub PMC");
48     }
50     VTABLE void set_string_keyed_int(INTVAL key, STRING *value) {
51         real_exception(interp, NULL, E_TypeError,
52                 "attempt to set non Sub PMC");
53     }
55     VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) {
56         real_exception(interp, NULL, E_TypeError,
57                 "attempt to set non Sub PMC");
58     }
60     VTABLE opcode_t *invoke(void *next) {
61         PMC * const list = Parrot_mmd_sort_candidate_list(interp, SELF);
62         PMC *func;
64         if (PMC_IS_NULL(list))
65             real_exception(INTERP, NULL, 1, "No applicable methods.\n");
67         func = VTABLE_get_pmc_keyed_int(interp, list, 0);
68         return VTABLE_invoke(INTERP, func, next);
69     }
74 =back
76 =head1 SEE ALSO
78 F<src/mmd.c>,
79 F<$perl6/doc/trunk/design/apo/A12.pod>,
80 F<$perl6/doc/trunk/design/syn/S12.pod>
82 =head1 HISTORY
84 Initial version                  - leo 14.03.2005
86 =cut
91  * Local variables:
92  *   c-file-style: "parrot"
93  * End:
94  * vim: expandtab shiftwidth=4:
95  */