Ticket #10: chromatic.patch

File chromatic.patch, 6.5 KB (added by coke, 13 years ago)

Patch suggested by chromatic...

  • src/pmc/namespace.pmc

    === src/pmc/namespace.pmc
    ==================================================================
     
    8686        } 
    8787    } 
    8888 
     89 
    8990    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")); 
    9192 
    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); 
    9596    } 
    9697 
    9798    /* If it's anonymous, we're done. */ 
     
    269270                PMC * const classobj = VTABLE_get_class(interp, SELF); 
    270271 
    271272                /* 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")); 
    274275 
    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); 
    283281                    SUPER(key, value); 
    284282                } 
    285283            } 
  • src/pmc/sub.pmc

    === src/pmc/sub.pmc
    ==================================================================
     
    625625 
    626626*/ 
    627627 
    628     PMC *inspect() 
    629     { 
     628    PMC *inspect() { 
    630629        /* Create a hash, then use inspect_str to get all of the data to 
    631630         * 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"); 
    638637        STRING * const named_slurpy_str   = CONST_STRING(interp, "named_slurpy"); 
     638        STRING * const method_name_str    = CONST_STRING(interp, "method_name"); 
    639639 
    640640        VTABLE_set_pmc_keyed_str(interp, metadata, pos_required_str, 
    641641            VTABLE_inspect_str(interp, SELF, pos_required_str)); 
     
    655655        VTABLE_set_pmc_keyed_str(interp, metadata, named_slurpy_str, 
    656656            VTABLE_inspect_str(interp, SELF, named_slurpy_str)); 
    657657 
     658        VTABLE_set_pmc_keyed_str(interp, metadata, method_name_str, 
     659            VTABLE_inspect_str(interp, SELF, method_name_str)); 
     660 
    658661        return metadata; 
    659662    } 
    660663 
     
    691694 
    6926951 if it takes slurpy named arguments, 0 if not 
    693696 
     697=item method_name 
     698 
     699A String PMC containing the name of the method, if this is a method, and 
     700PMCNULL if not. 
     701 
    694702=back 
    695703 
    696704=cut 
    697705 
    698706*/ 
    699707 
    700     PMC *inspect_str(STRING *what) 
    701     { 
     708    PMC *inspect_str(STRING *what) { 
     709        PMC *retval; 
    702710        Parrot_sub * const sub = PMC_sub(SELF); 
    703         INTVAL count_found = -1; 
    704         PMC *retval; 
     711        INTVAL count_found     = -1; 
    705712 
    706713        /* If the argument info hasn't been generated yet, generate it. */ 
    707         if (sub->arg_info == NULL) 
    708         { 
     714        if (sub->arg_info == NULL) { 
    709715            /* Get pointer into the bytecode where this sub starts. */ 
    710716            opcode_t *pc = sub->seg->base.data + sub->start_offs; 
    711717 
     
    714720 
    715721            /* If the first instruction is a get_params... */ 
    716722            if (*pc == PARROT_OP_get_params_pc) { 
     723                PMC *sig; 
    717724                int i, sig_length; 
    718                 PMC *sig; 
    719725 
    720726                /* Get the signature (the next thing in the bytecode). */ 
    721727                pc++; 
     
    724730 
    725731                /* Iterate over the signature and compute argument counts. */ 
    726732                sig_length = SIG_ELEMS(sig); 
    727                 for (i = 0; i < sig_length; i++) 
    728                 { 
     733 
     734                for (i = 0; i < sig_length; i++) { 
    729735                    int sig_item = SIG_ITEM(sig, i); 
     736 
    730737                    if (PARROT_ARG_SLURPY_ARRAY_ISSET(sig_item)){ 
    731738                        if (PARROT_ARG_NAME_ISSET(sig_item)) 
    732739                            sub->arg_info->named_slurpy = 1; 
     
    768775        else if (string_equal(interp, what, CONST_STRING(interp, "named_slurpy")) == 0) { 
    769776            count_found = (INTVAL)sub->arg_info->named_slurpy; 
    770777        } 
     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        } 
    771787        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, 
    773790                "Unknown introspection value '%S'", what); 
    774791        } 
    775792