Ticket #1367: codestring.pmc.patch
File codestring.pmc.patch, 5.6 KB (added by jimmy, 12 years ago) |
---|
-
src/pmc/codestring.pmc
48 48 */ 49 49 50 50 VTABLE void init() { 51 Parrot_CodeString_attributes * const attrs = PARROT_CODESTRING(SELF);52 51 SUPER(); 53 attrs->linepos = PMCNULL;52 SET_ATTR_linepos(INTERP, SELF, PMCNULL); 54 53 PObj_custom_mark_SET(SELF); 55 54 } 56 55 … … 65 64 */ 66 65 67 66 VTABLE void mark() { 68 Parrot_CodeString_attributes * const attrs = PARROT_CODESTRING(SELF); 67 PMC *linepos; 68 69 69 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); 72 76 } 73 77 74 78 /* … … 97 101 */ 98 102 99 103 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"); 104 108 STRING *key, *repl, *S0, *S1; 105 109 INTVAL pos = 0; 106 110 INTVAL replen = 0; … … 150 154 } 151 155 152 156 /* 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)) 154 158 fmt = Parrot_str_concat(INTERP, fmt, newline, 0); 155 159 156 160 GET_ATTR_str_val(INTERP, SELF, S1); … … 174 178 175 179 METHOD lineof(INTVAL pos) { 176 180 PMC *linepos; 177 INTVAL line;178 181 INTVAL count; 182 INTVAL line = 0; 179 183 180 184 GET_ATTR_linepos(INTERP, SELF, linepos); 181 185 … … 216 220 * search for now, * perhaps a binary search would be better someday. 217 221 */ 218 222 count = VTABLE_elements(INTERP, linepos); 219 line = 0;220 223 while (line < count 221 224 && VTABLE_get_integer_keyed_int(INTERP, linepos, line) <= pos) 222 225 line++; … … 269 272 */ 270 273 271 274 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"); 275 278 INTVAL x_pos; 276 279 INTVAL is_unicode = 0; 277 280 UNUSED(SELF); … … 283 286 if (x_pos != -1) { 284 287 is_unicode = 1; 285 288 } 286 else 287 { 288 STRING *u = CONST_STRING(INTERP, "\\u"); 289 else { 290 STRING * const u = CONST_STRING(INTERP, "\\u"); 289 291 INTVAL u_pos = Parrot_str_find_index(INTERP, escaped_str, u, 0); 290 292 if (u_pos != -1) 291 293 is_unicode = 1; 292 294 } 293 295 294 296 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); 297 299 } 298 300 299 301 RETURN(STRING *escaped_str); … … 313 315 314 316 METHOD charname_to_ord(STRING *name) { 315 317 #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); 320 321 Parrot_str_free_cstring(cstr); 321 322 if (U_SUCCESS(err)) { 322 323 RETURN(INTVAL codepoint); 323 324 } 324 325 RETURN(INTVAL -1); 325 326 #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, 327 328 "no ICU lib loaded"); 328 329 #endif 329 330 } … … 340 341 */ 341 342 342 343 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; 350 352 351 elements = VTABLE_elements(INTERP, args);352 353 353 for (index = 0; index < elements; index++) { 354 354 PMC *P0 = VTABLE_get_pmc_keyed_int(INTERP, args, index); 355 355 if (PMC_IS_NULL(P0)) continue; 356 else if (VTABLE_does( interp, P0, s_array)) {356 else if (VTABLE_does(INTERP, P0, s_array)) { 357 357 INTVAL elements2, index2; 358 358 elements2 = VTABLE_elements(INTERP, P0); 359 359 for (index2 = 0; index2 < elements2; index2++) {