Ticket #1367: codestring.pmc.patch

File codestring.pmc.patch, 5.6 KB (added by jimmy, 12 years ago)
  • src/pmc/codestring.pmc

     
    4848*/ 
    4949 
    5050    VTABLE void init() { 
    51         Parrot_CodeString_attributes * const attrs = PARROT_CODESTRING(SELF); 
    5251        SUPER(); 
    53         attrs->linepos = PMCNULL; 
     52        SET_ATTR_linepos(INTERP, SELF, PMCNULL); 
    5453        PObj_custom_mark_SET(SELF); 
    5554    } 
    5655 
     
    6564*/ 
    6665 
    6766    VTABLE void mark() { 
    68         Parrot_CodeString_attributes * const attrs = PARROT_CODESTRING(SELF); 
     67        PMC *linepos; 
     68 
    6969        SUPER(); 
    70         if (!attrs) return; 
    71         Parrot_gc_mark_PMC_alive(INTERP, attrs->linepos); 
     70        if (!PMC_data(SELF)) 
     71            return; 
     72 
     73        GET_ATTR_linepos(INTERP, SELF, linepos); 
     74 
     75        Parrot_gc_mark_PMC_alive(INTERP, linepos); 
    7276    } 
    7377 
    7478/* 
     
    97101*/ 
    98102 
    99103  METHOD emit(STRING *fmt, PMC *args :slurpy, PMC *hash :slurpy :named) { 
    100     STRING *percent     = CONST_STRING(INTERP, "%"); 
    101     STRING *comma       = CONST_STRING(INTERP, ","); 
    102     STRING *comma_space = CONST_STRING(INTERP, ", "); 
    103     STRING *newline     = CONST_STRING(INTERP, "\n"); 
     104    STRING * const percent     = CONST_STRING(INTERP, "%"); 
     105    STRING * const comma       = CONST_STRING(INTERP, ","); 
     106    STRING * const comma_space = CONST_STRING(INTERP, ", "); 
     107    STRING * const newline     = CONST_STRING(INTERP, "\n"); 
    104108    STRING *key, *repl, *S0, *S1; 
    105109    INTVAL pos          = 0; 
    106110    INTVAL replen       = 0; 
     
    150154    } 
    151155 
    152156    /* Add a newline if necessary */ 
    153     if ('\n' != Parrot_str_indexed(INTERP, fmt, Parrot_str_byte_length(interp, fmt) - 1)) 
     157    if ('\n' != Parrot_str_indexed(INTERP, fmt, Parrot_str_byte_length(INTERP, fmt) - 1)) 
    154158        fmt = Parrot_str_concat(INTERP, fmt, newline, 0); 
    155159 
    156160    GET_ATTR_str_val(INTERP, SELF, S1); 
     
    174178 
    175179  METHOD lineof(INTVAL pos) { 
    176180    PMC    *linepos; 
    177     INTVAL  line; 
    178181    INTVAL  count; 
     182    INTVAL  line = 0; 
    179183 
    180184    GET_ATTR_linepos(INTERP, SELF, linepos); 
    181185 
     
    216220     * search for now, * perhaps a binary search would be better someday. 
    217221     */ 
    218222    count = VTABLE_elements(INTERP, linepos); 
    219     line  = 0; 
    220223    while (line < count 
    221224          && VTABLE_get_integer_keyed_int(INTERP, linepos, line) <= pos) 
    222225        line++; 
     
    269272*/ 
    270273 
    271274  METHOD escape(STRING *str) { 
    272     STRING *escaped_str = Parrot_str_escape(INTERP, str); 
    273     STRING *quote      = CONST_STRING(INTERP, "\x22"); 
    274     STRING *x           = CONST_STRING(INTERP, "\\x"); 
     275    STRING *escaped_str  = Parrot_str_escape(INTERP, str); 
     276    STRING * const quote = CONST_STRING(INTERP, "\x22"); 
     277    STRING * const x     = CONST_STRING(INTERP, "\\x"); 
    275278    INTVAL x_pos; 
    276279    INTVAL is_unicode = 0; 
    277280    UNUSED(SELF); 
     
    283286    if (x_pos != -1) { 
    284287        is_unicode = 1; 
    285288    } 
    286     else 
    287     { 
    288         STRING *u = CONST_STRING(INTERP, "\\u"); 
     289    else { 
     290        STRING * const u = CONST_STRING(INTERP, "\\u"); 
    289291        INTVAL u_pos = Parrot_str_find_index(INTERP, escaped_str, u, 0); 
    290292        if (u_pos != -1) 
    291293            is_unicode = 1; 
    292294    } 
    293295 
    294296    if (is_unicode) { 
    295         STRING *unicode = CONST_STRING(INTERP, "unicode:"); 
    296         escaped_str     = Parrot_str_concat(INTERP, unicode, escaped_str, 1); 
     297        STRING * const unicode = CONST_STRING(INTERP, "unicode:"); 
     298        escaped_str            = Parrot_str_concat(INTERP, unicode, escaped_str, 1); 
    297299    } 
    298300 
    299301    RETURN(STRING *escaped_str); 
     
    313315 
    314316  METHOD charname_to_ord(STRING *name) { 
    315317#if PARROT_HAS_ICU 
    316     UChar32    codepoint; 
    317     UErrorCode err       = U_ZERO_ERROR; 
    318     char       *cstr     = Parrot_str_to_cstring(INTERP, name); 
    319     codepoint = u_charFromName(U_EXTENDED_CHAR_NAME, cstr, &err); 
     318    UErrorCode   err       = U_ZERO_ERROR; 
     319    char * const cstr      = Parrot_str_to_cstring(INTERP, name); 
     320    UChar32      codepoint = u_charFromName(U_EXTENDED_CHAR_NAME, cstr, &err); 
    320321    Parrot_str_free_cstring(cstr); 
    321322    if (U_SUCCESS(err)) { 
    322323        RETURN(INTVAL codepoint); 
    323324    } 
    324325    RETURN(INTVAL -1); 
    325326#else 
    326     Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_LIBRARY_ERROR, 
     327    Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_LIBRARY_ERROR, 
    327328        "no ICU lib loaded"); 
    328329#endif 
    329330  } 
     
    340341*/ 
    341342 
    342343  METHOD key(PMC *args :slurpy) { 
    343     STRING *open_bracket  = CONST_STRING(INTERP, "["); 
    344     STRING *semi          = CONST_STRING(INTERP, ";"); 
    345     STRING *close_bracket = CONST_STRING(INTERP, "]"); 
    346     STRING *s_array       = CONST_STRING(INTERP, "array"); 
    347     STRING *prefix        = NULL; 
    348     STRING *out           = open_bracket; 
    349     INTVAL elements, index; 
     344    INTVAL         index; 
     345    INTVAL         elements      = VTABLE_elements(INTERP, args); 
     346    STRING * const open_bracket  = CONST_STRING(INTERP, "["); 
     347    STRING * const semi          = CONST_STRING(INTERP, ";"); 
     348    STRING * const close_bracket = CONST_STRING(INTERP, "]"); 
     349    STRING * const s_array       = CONST_STRING(INTERP, "array"); 
     350    STRING *       prefix        = NULL; 
     351    STRING *       out           = open_bracket; 
    350352 
    351     elements     = VTABLE_elements(INTERP, args); 
    352  
    353353    for (index = 0; index < elements; index++) { 
    354354        PMC *P0      = VTABLE_get_pmc_keyed_int(INTERP, args, index); 
    355355        if (PMC_IS_NULL(P0)) continue; 
    356         else if (VTABLE_does(interp, P0, s_array)) { 
     356        else if (VTABLE_does(INTERP, P0, s_array)) { 
    357357            INTVAL elements2, index2; 
    358358            elements2 = VTABLE_elements(INTERP, P0); 
    359359            for (index2 = 0; index2 < elements2; index2++) {