=== src/pmc/namespace.pmc
==================================================================
|
|
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
| 89 | |
89 | 90 | if (sub->comp_flags & SUB_COMP_FLAG_METHOD) { |
90 | | STRING *method_name = key; |
| 91 | PMC *method_name = VTABLE_inspect_str(interp, value, CONST_STRING(interp, "method_name")); |
91 | 92 | |
92 | | if (0 != string_equal(interp, sub->method_name, CONST_STRING(interp, ""))) |
93 | | method_name = sub->method_name; |
94 | | add_to_class(interp, nsinfo, classobj, method_name, value); |
| 93 | if (!PMC_IS_NULL(method_name)) |
| 94 | add_to_class(interp, nsinfo, classobj, |
| 95 | VTABLE_get_string(interp, method_name), value); |
95 | 96 | } |
96 | 97 | |
97 | 98 | /* If it's anonymous, we're done. */ |
… |
… |
|
269 | 270 | PMC * const classobj = VTABLE_get_class(interp, SELF); |
270 | 271 | |
271 | 272 | /* Extract the first alternate and check if it is a method */ |
272 | | PMC *pmc_sub = VTABLE_get_pmc_keyed_int(interp, value, 0); |
273 | | Parrot_sub * const sub = PMC_sub(pmc_sub); |
| 273 | PMC *pmc_sub = VTABLE_get_pmc_keyed_int(interp, value, 0); |
| 274 | PMC *method_name = VTABLE_inspect_str(interp, pmc_sub, CONST_STRING(interp, "method_name")); |
274 | 275 | |
275 | | if (sub->comp_flags & SUB_COMP_FLAG_METHOD) { |
276 | | STRING *method_name = key; |
277 | | |
278 | | if (0 != string_equal(interp, sub->method_name, CONST_STRING(interp, ""))) |
279 | | method_name = sub->method_name; |
280 | | |
281 | | add_to_class(INTERP, nsinfo, classobj, method_name, value); |
282 | | |
| 276 | if (PMC_IS_NULL(method_name)) |
| 277 | add_to_class(INTERP, nsinfo, classobj, key, value); |
| 278 | else { |
| 279 | add_to_class(INTERP, nsinfo, classobj, |
| 280 | VTABLE_get_string(interp, method_name), value); |
283 | 281 | SUPER(key, value); |
284 | 282 | } |
285 | 283 | } |
=== src/pmc/sub.pmc
==================================================================
|
|
|
625 | 625 | |
626 | 626 | */ |
627 | 627 | |
628 | | PMC *inspect() |
629 | | { |
| 628 | PMC *inspect() { |
630 | 629 | /* Create a hash, then use inspect_str to get all of the data to |
631 | 630 | * fill it up with. */ |
632 | | PMC * const metadata = pmc_new(interp, enum_class_Hash); |
633 | | STRING * const pos_required_str = CONST_STRING(interp, "pos_required"); |
634 | | STRING * const pos_optional_str = CONST_STRING(interp, "pos_optional"); |
635 | | STRING * const named_required_str = CONST_STRING(interp, "named_required"); |
636 | | STRING * const named_optional_str = CONST_STRING(interp, "named_optional"); |
637 | | STRING * const pos_slurpy_str = CONST_STRING(interp, "pos_slurpy"); |
| 631 | PMC * const metadata = pmc_new(interp, enum_class_Hash); |
| 632 | STRING * const pos_required_str = CONST_STRING(interp, "pos_required"); |
| 633 | STRING * const pos_optional_str = CONST_STRING(interp, "pos_optional"); |
| 634 | STRING * const named_required_str = CONST_STRING(interp, "named_required"); |
| 635 | STRING * const named_optional_str = CONST_STRING(interp, "named_optional"); |
| 636 | STRING * const pos_slurpy_str = CONST_STRING(interp, "pos_slurpy"); |
638 | 637 | STRING * const named_slurpy_str = CONST_STRING(interp, "named_slurpy"); |
| 638 | STRING * const method_name_str = CONST_STRING(interp, "method_name"); |
639 | 639 | |
640 | 640 | VTABLE_set_pmc_keyed_str(interp, metadata, pos_required_str, |
641 | 641 | VTABLE_inspect_str(interp, SELF, pos_required_str)); |
… |
… |
|
655 | 655 | VTABLE_set_pmc_keyed_str(interp, metadata, named_slurpy_str, |
656 | 656 | VTABLE_inspect_str(interp, SELF, named_slurpy_str)); |
657 | 657 | |
| 658 | VTABLE_set_pmc_keyed_str(interp, metadata, method_name_str, |
| 659 | VTABLE_inspect_str(interp, SELF, method_name_str)); |
| 660 | |
658 | 661 | return metadata; |
659 | 662 | } |
660 | 663 | |
… |
… |
|
691 | 694 | |
692 | 695 | 1 if it takes slurpy named arguments, 0 if not |
693 | 696 | |
| 697 | =item method_name |
| 698 | |
| 699 | A String PMC containing the name of the method, if this is a method, and |
| 700 | PMCNULL if not. |
| 701 | |
694 | 702 | =back |
695 | 703 | |
696 | 704 | =cut |
697 | 705 | |
698 | 706 | */ |
699 | 707 | |
700 | | PMC *inspect_str(STRING *what) |
701 | | { |
| 708 | PMC *inspect_str(STRING *what) { |
| 709 | PMC *retval; |
702 | 710 | Parrot_sub * const sub = PMC_sub(SELF); |
703 | | INTVAL count_found = -1; |
704 | | PMC *retval; |
| 711 | INTVAL count_found = -1; |
705 | 712 | |
706 | 713 | /* If the argument info hasn't been generated yet, generate it. */ |
707 | | if (sub->arg_info == NULL) |
708 | | { |
| 714 | if (sub->arg_info == NULL) { |
709 | 715 | /* Get pointer into the bytecode where this sub starts. */ |
710 | 716 | opcode_t *pc = sub->seg->base.data + sub->start_offs; |
711 | 717 | |
… |
… |
|
714 | 720 | |
715 | 721 | /* If the first instruction is a get_params... */ |
716 | 722 | if (*pc == PARROT_OP_get_params_pc) { |
| 723 | PMC *sig; |
717 | 724 | int i, sig_length; |
718 | | PMC *sig; |
719 | 725 | |
720 | 726 | /* Get the signature (the next thing in the bytecode). */ |
721 | 727 | pc++; |
… |
… |
|
724 | 730 | |
725 | 731 | /* Iterate over the signature and compute argument counts. */ |
726 | 732 | sig_length = SIG_ELEMS(sig); |
727 | | for (i = 0; i < sig_length; i++) |
728 | | { |
| 733 | |
| 734 | for (i = 0; i < sig_length; i++) { |
729 | 735 | int sig_item = SIG_ITEM(sig, i); |
| 736 | |
730 | 737 | if (PARROT_ARG_SLURPY_ARRAY_ISSET(sig_item)){ |
731 | 738 | if (PARROT_ARG_NAME_ISSET(sig_item)) |
732 | 739 | sub->arg_info->named_slurpy = 1; |
… |
… |
|
768 | 775 | else if (string_equal(interp, what, CONST_STRING(interp, "named_slurpy")) == 0) { |
769 | 776 | count_found = (INTVAL)sub->arg_info->named_slurpy; |
770 | 777 | } |
| 778 | else if (string_equal(interp, what, CONST_STRING(interp, "method_name")) == 0) { |
| 779 | if (string_equal(interp, sub->method_name, CONST_STRING(interp, "")) == 0) |
| 780 | return PMCNULL; |
| 781 | else { |
| 782 | PMC *name = pmc_new(interp, enum_class_String); |
| 783 | VTABLE_set_string_native(interp, name, sub->method_name); |
| 784 | return name; |
| 785 | } |
| 786 | } |
771 | 787 | else { |
772 | | Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, |
| 788 | Parrot_ex_throw_from_c_args(interp, NULL, |
| 789 | EXCEPTION_INVALID_OPERATION, |
773 | 790 | "Unknown introspection value '%S'", what); |
774 | 791 | } |
775 | 792 | |