2 Copyright (C) 2001-2009, Parrot Foundation.
7 src/pmc/multisub.pmc - A container for multi-dispatched subs
11 This class inherits from ResizablePMCArray and provides an Array of
12 Sub PMCs with the same short name, but different long names.
22 pmclass MultiSub extends ResizablePMCArray need_ext provides array {
24 VTABLE void push_pmc(PMC *value) {
25 STRING * const _sub = CONST_STRING(interp, "Sub");
26 STRING * const _nci = CONST_STRING(interp, "NCI");
28 if (!VTABLE_isa(interp, value, _sub)
29 && !VTABLE_isa(interp, value, _nci))
30 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
31 "attempt to push non Sub PMC");
36 VTABLE void set_pmc_keyed_int(INTVAL key, PMC *value) {
37 STRING * const _sub = CONST_STRING(interp, "Sub");
38 if (!VTABLE_isa(interp, value, _sub))
39 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
40 "attempt to set non Sub PMC");
44 VTABLE void set_integer_keyed_int(INTVAL key, INTVAL value) {
45 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
46 "attempt to set non Sub PMC");
49 VTABLE void set_string_keyed_int(INTVAL key, STRING *value) {
50 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
51 "attempt to set non Sub PMC");
54 VTABLE void set_number_keyed_int(INTVAL key, FLOATVAL value) {
55 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
56 "attempt to set non Sub PMC");
59 VTABLE opcode_t *invoke(void *next) {
60 PMC * const func = Parrot_mmd_sort_manhattan(interp, SELF);
62 if (PMC_IS_NULL(func))
63 Parrot_ex_throw_from_c_args(INTERP, NULL, 1, "No applicable methods.\n");
65 return VTABLE_invoke(INTERP, func, next);
68 VTABLE PMC *get_iter() {
69 PMC * const sub = Parrot_mmd_sort_manhattan(INTERP, SELF);
72 Parrot_ex_throw_from_c_args(INTERP, NULL, 1, "No applicable methods.\n");
76 /* I don't really know how to implement these if they need something
77 special, so I'll sort the sub list and defer processing to the
78 ResizablePMCArray's VTABLE methods of the same names. Hopefully we
79 don't need anything beyond that. */
80 VTABLE PMC *get_pmc_keyed(PMC *key) {
81 PMC * const sub = Parrot_mmd_sort_manhattan(INTERP, SELF);
83 Parrot_ex_throw_from_c_args(INTERP, NULL, 1, "No applicable methods.\n");
87 VTABLE PMC *get_pmc_keyed_str(STRING *s) {
88 PMC * const sub = Parrot_mmd_sort_manhattan(INTERP, SELF);
90 Parrot_ex_throw_from_c_args(INTERP, NULL, 1, "No applicable methods.\n");
94 /* get_iter method should take one of two inputs: either an array of
95 arguments, or a string with a whitespace delimited function signature
96 (N, I, S, P). It should sort the argument list according to closeness
97 to this input argument list and return an iterator over that list. */
99 METHOD get_iter(PMC *args) {
100 STRING * const _array = CONST_STRING(interp, "Array");
101 STRING * const _string = CONST_STRING(interp, "String");
103 if (VTABLE_isa(INTERP, args, _array)){
104 /* TODO: What goes here? */
106 else if (VTABLE_isa(INTERP, args, _string)) {
107 STRING * const s = VTABLE_get_string(INTERP, args);
108 /* TODO: What goes here? */
111 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
112 "attempt to call get_iter method with invalid arg type.\n");
122 F<src/multidispatch.c>,
123 F<$perl6/doc/trunk/design/apo/A12.pod>,
124 F<$perl6/doc/trunk/design/syn/S12.pod>
132 * c-file-style: "parrot"
134 * vim: expandtab shiftwidth=4: