=== src/pmc/namespace.pmc ================================================================== --- src/pmc/namespace.pmc (revision 33754) +++ src/pmc/namespace.pmc (local) @@ -86,12 +86,13 @@ } } + if (sub->comp_flags & SUB_COMP_FLAG_METHOD) { - STRING *method_name = key; + PMC *method_name = VTABLE_inspect_str(interp, value, CONST_STRING(interp, "method_name")); - if (0 != string_equal(interp, sub->method_name, CONST_STRING(interp, ""))) - method_name = sub->method_name; - add_to_class(interp, nsinfo, classobj, method_name, value); + if (!PMC_IS_NULL(method_name)) + add_to_class(interp, nsinfo, classobj, + VTABLE_get_string(interp, method_name), value); } /* If it's anonymous, we're done. */ @@ -269,17 +270,14 @@ PMC * const classobj = VTABLE_get_class(interp, SELF); /* Extract the first alternate and check if it is a method */ - PMC *pmc_sub = VTABLE_get_pmc_keyed_int(interp, value, 0); - Parrot_sub * const sub = PMC_sub(pmc_sub); + PMC *pmc_sub = VTABLE_get_pmc_keyed_int(interp, value, 0); + PMC *method_name = VTABLE_inspect_str(interp, pmc_sub, CONST_STRING(interp, "method_name")); - if (sub->comp_flags & SUB_COMP_FLAG_METHOD) { - STRING *method_name = key; - - if (0 != string_equal(interp, sub->method_name, CONST_STRING(interp, ""))) - method_name = sub->method_name; - - add_to_class(INTERP, nsinfo, classobj, method_name, value); - + if (PMC_IS_NULL(method_name)) + add_to_class(INTERP, nsinfo, classobj, key, value); + else { + add_to_class(INTERP, nsinfo, classobj, + VTABLE_get_string(interp, method_name), value); SUPER(key, value); } } === src/pmc/sub.pmc ================================================================== --- src/pmc/sub.pmc (revision 33754) +++ src/pmc/sub.pmc (local) @@ -625,17 +625,17 @@ */ - PMC *inspect() - { + PMC *inspect() { /* Create a hash, then use inspect_str to get all of the data to * fill it up with. */ - PMC * const metadata = pmc_new(interp, enum_class_Hash); - STRING * const pos_required_str = CONST_STRING(interp, "pos_required"); - STRING * const pos_optional_str = CONST_STRING(interp, "pos_optional"); - STRING * const named_required_str = CONST_STRING(interp, "named_required"); - STRING * const named_optional_str = CONST_STRING(interp, "named_optional"); - STRING * const pos_slurpy_str = CONST_STRING(interp, "pos_slurpy"); + PMC * const metadata = pmc_new(interp, enum_class_Hash); + STRING * const pos_required_str = CONST_STRING(interp, "pos_required"); + STRING * const pos_optional_str = CONST_STRING(interp, "pos_optional"); + STRING * const named_required_str = CONST_STRING(interp, "named_required"); + STRING * const named_optional_str = CONST_STRING(interp, "named_optional"); + STRING * const pos_slurpy_str = CONST_STRING(interp, "pos_slurpy"); STRING * const named_slurpy_str = CONST_STRING(interp, "named_slurpy"); + STRING * const method_name_str = CONST_STRING(interp, "method_name"); VTABLE_set_pmc_keyed_str(interp, metadata, pos_required_str, VTABLE_inspect_str(interp, SELF, pos_required_str)); @@ -655,6 +655,9 @@ VTABLE_set_pmc_keyed_str(interp, metadata, named_slurpy_str, VTABLE_inspect_str(interp, SELF, named_slurpy_str)); + VTABLE_set_pmc_keyed_str(interp, metadata, method_name_str, + VTABLE_inspect_str(interp, SELF, method_name_str)); + return metadata; } @@ -691,21 +694,24 @@ 1 if it takes slurpy named arguments, 0 if not +=item method_name + +A String PMC containing the name of the method, if this is a method, and +PMCNULL if not. + =back =cut */ - PMC *inspect_str(STRING *what) - { + PMC *inspect_str(STRING *what) { + PMC *retval; Parrot_sub * const sub = PMC_sub(SELF); - INTVAL count_found = -1; - PMC *retval; + INTVAL count_found = -1; /* If the argument info hasn't been generated yet, generate it. */ - if (sub->arg_info == NULL) - { + if (sub->arg_info == NULL) { /* Get pointer into the bytecode where this sub starts. */ opcode_t *pc = sub->seg->base.data + sub->start_offs; @@ -714,8 +720,8 @@ /* If the first instruction is a get_params... */ if (*pc == PARROT_OP_get_params_pc) { + PMC *sig; int i, sig_length; - PMC *sig; /* Get the signature (the next thing in the bytecode). */ pc++; @@ -724,9 +730,10 @@ /* Iterate over the signature and compute argument counts. */ sig_length = SIG_ELEMS(sig); - for (i = 0; i < sig_length; i++) - { + + for (i = 0; i < sig_length; i++) { int sig_item = SIG_ITEM(sig, i); + if (PARROT_ARG_SLURPY_ARRAY_ISSET(sig_item)){ if (PARROT_ARG_NAME_ISSET(sig_item)) sub->arg_info->named_slurpy = 1; @@ -768,8 +775,18 @@ else if (string_equal(interp, what, CONST_STRING(interp, "named_slurpy")) == 0) { count_found = (INTVAL)sub->arg_info->named_slurpy; } + else if (string_equal(interp, what, CONST_STRING(interp, "method_name")) == 0) { + if (string_equal(interp, sub->method_name, CONST_STRING(interp, "")) == 0) + return PMCNULL; + else { + PMC *name = pmc_new(interp, enum_class_String); + VTABLE_set_string_native(interp, name, sub->method_name); + return name; + } + } else { - Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, + Parrot_ex_throw_from_c_args(interp, NULL, + EXCEPTION_INVALID_OPERATION, "Unknown introspection value '%S'", what); }