Ticket #1375: class_tt1375.pmc.patch
File class_tt1375.pmc.patch, 75.4 KB (added by jimmy, 12 years ago) |
---|
-
src/pmc/class.pmc
99 99 PMC *cache, int cur_index) 100 100 { 101 101 /* The attribute metadata hash. */ 102 Parrot_Class_attributes * const class_info = PARROT_CLASS(cur_class); 103 PMC * const attribs = class_info->attrib_metadata; 104 PMC * const iter = VTABLE_get_iter(interp, attribs); 102 PMC *attrib_metadata, *iter; 103 105 104 106 105 /* Build a string representing the fully qualified class name. */ 107 106 /* Retrieve the fully qualified class name for the class. */ 108 STRING * const fq_class = VTABLE_get_string(interp, cur_class); 109 PMC * const class_cache = pmc_new(interp, enum_class_Hash); 107 PMC * const class_cache = pmc_new(interp, enum_class_Hash); 108 STRING * const fq_class = VTABLE_get_string(interp, cur_class); 109 110 110 VTABLE_set_pmc_keyed_str(interp, cache, fq_class, class_cache); 111 111 112 GETATTR_Class_attrib_metadata(interp, cur_class, attrib_metadata); 113 114 iter = VTABLE_get_iter(interp, attrib_metadata); 115 112 116 /* Iterate over the attributes. */ 113 117 while (VTABLE_get_bool(interp, iter)) { 114 118 /* Get attribute. */ 115 119 PMC * const cur_attrib = VTABLE_get_pmc_keyed_str(interp, 116 attrib s, VTABLE_shift_string(interp, iter));120 attrib_metadata, VTABLE_shift_string(interp, iter)); 117 121 118 122 /* Get attribute name and append it to the key. */ 119 123 STRING * const name_str = CONST_STRING(interp, "name"); … … 134 138 /* This function builds the attribute index (table to map class name and 135 139 * attribute name to an index) for the current class. */ 136 140 static void 137 build_attrib_index(PARROT_INTERP, PMC * self)141 build_attrib_index(PARROT_INTERP, PMC *SELF) 138 142 { 139 Parrot_Class_attributes * const _class = PARROT_CLASS(self);140 int cur_index = 0;141 PMC * const 142 PMC * const 143 const int num_classes = VTABLE_elements(interp, _class->all_parents);144 int i;143 int i, num_classes, cur_index = 0; 144 PMC *all_parents; 145 PMC * const attrib_index = pmc_new(interp, enum_class_Hash); 146 PMC * const cache = pmc_new(interp, enum_class_Hash); 147 148 GETATTR_Class_all_parents(interp, SELF, all_parents); 145 149 150 num_classes =VTABLE_elements(interp, all_parents); 151 146 152 /* Go over the list of all parents to construct the attribute index. */ 147 153 for (i = 0; i < num_classes; i++) { 148 154 /* Get the class and check that it respects the standard class interface 149 155 * (if not we don't know how it stores its attributes, so we'll have to 150 156 * delegate the lookup). */ 151 157 PMC * const cur_class = VTABLE_get_pmc_keyed_int(interp, 152 _class->all_parents, i);158 all_parents, i); 153 159 154 160 if (PObj_is_class_TEST(cur_class)) 155 161 cur_index = cache_class_attribs(interp, cur_class, … … 157 163 } 158 164 159 165 /* Store built attribute index and invalidate cache. */ 160 _class->attrib_index = attrib_index;161 _class->attrib_cache = cache;166 SETATTR_Class_attrib_index(interp, SELF, attrib_index); 167 SETATTR_Class_attrib_cache(interp, SELF, cache); 162 168 } 169 163 170 /* Takes a hash and initializes the class based on it. */ 164 171 static void 165 init_class_from_hash(PARROT_INTERP, PMC * self, PMC *info)172 init_class_from_hash(PARROT_INTERP, PMC *SELF, PMC *info) 166 173 { 167 Parrot_Class_attributes * const _class = PARROT_CLASS(self);168 174 STRING * const name_str = CONST_STRING(interp, "name"); 169 175 STRING * const parents_str = CONST_STRING(interp, "parents"); 170 176 STRING * const methods_str = CONST_STRING(interp, "methods"); 171 177 STRING * const roles_str = CONST_STRING(interp, "roles"); 172 178 STRING * const attrs_str = CONST_STRING(interp, "attributes"); 173 PMC *old_ns;174 STRING *resolve_method_str;179 STRING *resolve_method_str; 180 PMC *old_namespace, *new_namespace; 175 181 176 182 /* Ensure we actually have some initialization info. */ 177 183 if (PMC_IS_NULL(info)) 178 184 return; 179 185 180 186 /* Take a copy of the current namespace the class is attached to. */ 181 old_ns = _class->_namespace;187 GETATTR_Class__namespace(interp, SELF, old_namespace); 182 188 183 189 /* Check if we have a name/namespace. */ 184 190 if (VTABLE_exists_keyed_str(interp, info, name_str)) { 191 INTVAL type_num; 185 192 STRING *new_name; 186 PMC *new_namespace; 193 VTABLE *new_vtable; 194 PMC *all_parents; 187 195 PMC *name_arg = VTABLE_get_pmc_keyed_str(interp, info, name_str); 188 VTABLE *new_vtable;189 INTVAL type_num;190 196 191 197 /* If we were passed a namespace PMC, set the namespace attribute 192 198 * directly. Otherwise, lookup or create the appropriate namespace. */ … … 213 219 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION, 214 220 "Failed to set name for class."); 215 221 216 _class->_namespace = new_namespace; 217 _class->name = new_name; 222 /* Set new name/namespace to SELF */ 223 SETATTR_Class_name(interp, SELF, new_name); 224 SETATTR_Class__namespace(interp, SELF, new_namespace); 218 225 219 226 /* At this point we know the class isn't anonymous */ 220 CLASS_is_anon_CLEAR( self);227 CLASS_is_anon_CLEAR(SELF); 221 228 222 229 /* Register a type number for the class. */ 223 230 type_num = Parrot_oo_register_type(interp, name_arg, new_namespace); 224 231 232 SETATTR_Class_id(interp, SELF, type_num); 233 234 GETATTR_Class_all_parents(interp, SELF, all_parents); 235 225 236 /* Link the type number with the class's vtable. */ 226 new_vtable = Parrot_clone_vtable(interp, self->vtable);237 new_vtable = Parrot_clone_vtable(interp, SELF->vtable); 227 238 239 new_vtable->pmc_class = SELF; 228 240 new_vtable->base_type = type_num; 229 new_vtable->pmc_class = self; 230 new_vtable->whoami = VTABLE_get_string(interp, self); 231 new_vtable->mro = _class->all_parents; 241 new_vtable->mro = all_parents; 242 new_vtable->whoami = VTABLE_get_string(interp, SELF); 232 243 new_vtable->ro_variant_vtable = 233 Parrot_clone_vtable(interp, self->vtable->ro_variant_vtable);244 Parrot_clone_vtable(interp, SELF->vtable->ro_variant_vtable); 234 245 235 246 /* Store the class's vtable in the global table */ 236 247 interp->vtables[type_num] = new_vtable; 237 238 _class->id = type_num; 248 } else { 249 /* no new namespace, so use the old one */ 250 new_namespace = old_namespace; 239 251 } 240 252 241 253 /* If we were attached to a namespace and are now attached to a new one, 242 254 * need to unset ourselves in the old namespace. */ 243 if (!PMC_IS_NULL(old_ns) && _class->_namespace != old_ns) 244 Parrot_pcc_invoke_method_from_c_args(interp, old_ns, CONST_STRING(interp, "set_class"), "P->", PMCNULL); 255 if (!PMC_IS_NULL(old_namespace) && new_namespace != old_namespace) { 256 STRING * const set_class_str = CONST_STRING(interp, "set_class"); 257 Parrot_pcc_invoke_method_from_c_args(interp, 258 old_namespace, set_class_str, "P->", PMCNULL); 259 } 245 260 246 261 /* Link namespace to this class, if there is one. */ 247 if (!PMC_IS_NULL( _class->_namespace)) {262 if (!PMC_IS_NULL(new_namespace)) { 248 263 STRING * const set_class_str = CONST_STRING(interp, "set_class"); 249 Parrot_pcc_invoke_method_from_c_args(interp, _class->_namespace, set_class_str, "P->",250 self);264 Parrot_pcc_invoke_method_from_c_args(interp, 265 new_namespace, set_class_str, "P->", SELF); 251 266 } 252 267 253 268 /* Initialize resolve_method. */ 254 269 resolve_method_str = CONST_STRING(interp, "resolve_method"); 255 270 if (VTABLE_exists_keyed_str(interp, info, resolve_method_str)) { 256 271 /* Set it. */ 257 _class->resolve_method =258 VTABLE_get_pmc_keyed_str(interp, info, resolve_method_str);272 SETATTR_Class_resolve_method(interp, SELF, 273 VTABLE_get_pmc_keyed_str(interp, info, resolve_method_str)); 259 274 } 260 275 261 276 /* Initialize parents, if we have any. */ 262 277 if (VTABLE_exists_keyed_str(interp, info, parents_str)) { 263 278 /* Loop over parents array and add them. */ 264 279 PMC * const parent_list = VTABLE_get_pmc_keyed_str(interp, info, 265 parents_str);280 parents_str); 266 281 const int parent_count = VTABLE_elements(interp, parent_list); 267 282 int i; 268 283 269 284 for (i = 0; i < parent_count; i++) 270 VTABLE_add_parent(interp, self,285 VTABLE_add_parent(interp, SELF, 271 286 VTABLE_get_pmc_keyed_int(interp, parent_list, i)); 272 287 } 273 288 … … 280 295 int i; 281 296 282 297 for (i = 0; i < role_count; i++) 283 VTABLE_add_role(interp, self,298 VTABLE_add_role(interp, SELF, 284 299 VTABLE_get_pmc_keyed_int(interp, role_list, i)); 285 300 } 286 301 … … 288 303 if (VTABLE_exists_keyed_str(interp, info, attrs_str)) { 289 304 /* Loop over attributes array and add them. */ 290 305 PMC * const attrs_name_list = VTABLE_get_pmc_keyed_str(interp, info, 291 attrs_str);306 attrs_str); 292 307 const int attrib_count = VTABLE_elements(interp, attrs_name_list); 293 308 int i; 294 309 295 310 for (i = 0; i < attrib_count; i++) { 296 311 STRING * const attr_name = VTABLE_get_string_keyed_int(interp, 297 312 attrs_name_list, i); 298 VTABLE_add_attribute(interp, self, attr_name, PMCNULL);313 VTABLE_add_attribute(interp, SELF, attr_name, PMCNULL); 299 314 } 300 315 } 301 316 … … 303 318 if (VTABLE_exists_keyed_str(interp, info, methods_str)) { 304 319 /* Get the methods hash. */ 305 320 PMC * const methods = VTABLE_get_pmc_keyed_str(interp, info, 306 methods_str);321 methods_str); 307 322 308 323 /* Iterate over the list of methods. */ 309 324 PMC * const iter = VTABLE_get_iter(interp, methods); … … 312 327 /* Add the method. */ 313 328 STRING * const method_name = VTABLE_shift_string(interp, iter); 314 329 PMC * const method_pmc = VTABLE_get_pmc_keyed_str(interp, 315 methods, method_name);316 VTABLE_add_method(interp, self, method_name, method_pmc);330 methods, method_name); 331 VTABLE_add_method(interp, SELF, method_name, method_pmc); 317 332 } 318 333 } 319 334 320 335 /* Extract any methods from the namespace */ 321 Parrot_oo_extract_methods_from_namespace(interp, self, _class->_namespace);336 Parrot_oo_extract_methods_from_namespace(interp, SELF, new_namespace); 322 337 } 323 338 324 339 static void … … 331 346 for (; parent_index >= 0; parent_index--) { 332 347 PMC *meth; 333 348 PMC * const parent = VTABLE_get_pmc_keyed_int(interp, 334 all_parents, parent_index);349 all_parents, parent_index); 335 350 336 351 /* PMCProxy parents store an instance to delegate to */ 337 352 if (parent->vtable->base_type == enum_class_PMCProxy) { 338 PMC * proxy = VTABLE_instantiate(interp, parent, PMCNULL);339 STRING * proxy_str = CONST_STRING(interp, "proxy");353 PMC * const proxy = VTABLE_instantiate(interp, parent, PMCNULL); 354 STRING * const proxy_str = CONST_STRING(interp, "proxy"); 340 355 VTABLE_set_attr_keyed(interp, object, parent, proxy_str, proxy); 341 356 } 342 357 … … 391 406 static STRING * 392 407 make_class_name(PARROT_INTERP, PMC *SELF) 393 408 { 394 P arrot_Class_attributes * const _class = PARROT_CLASS(SELF);395 PMC * const _namespace = _class->_namespace;409 PMC *_namespace; 410 STRING *name; 396 411 412 GETATTR_Class__namespace(interp, SELF, _namespace); 413 397 414 if (!PMC_IS_NULL(_namespace)) { 398 if (_class->fullname) 399 return _class->fullname; 415 STRING *fullname; 416 417 GETATTR_Class_fullname(interp, SELF, fullname); 418 419 if (fullname) 420 return fullname; 400 421 else { 401 402 422 /* Call the 'get_name' method on the class's associated 403 423 * namespace to retrieve a fully qualified list of names, then 404 424 * join the list with a semicolon. */ … … 407 427 if (!PMC_IS_NULL(names)) 408 428 /* remove the HLL namespace name */ 409 429 VTABLE_shift_string(interp, names); 410 _class->fullname = Parrot_str_join(interp, CONST_STRING(interp, ";"), names); 411 return _class->fullname; 430 431 fullname = Parrot_str_join(interp, CONST_STRING(interp, ";"), names); 432 433 SETATTR_Class_fullname(interp, SELF, fullname); 434 435 return fullname; 412 436 } 413 437 } 438 /* Otherwise, copy the stored string name of the class. */ 439 GETATTR_Class_name(interp, SELF, name); 414 440 415 /* Otherwise, copy the stored string name of the class. */ 416 return _class->name; 441 return name; 417 442 } 418 443 419 444 /* calculates the C3 method resolution order for this class. C3 is the … … 424 449 static void 425 450 calculate_mro(PARROT_INTERP, PMC *SELF, INTVAL num_parents) 426 451 { 427 P arrot_Class_attributes * const _class = PARROT_CLASS(SELF);452 PMC *mro; 428 453 429 454 /* SELF is already on the all_parents */ 430 455 if (num_parents == 0) 431 456 return; 432 457 433 458 if (num_parents == 1) { 434 STRING * const ap = CONST_STRING(interp, "all_parents"); 435 PMC * const parent = VTABLE_get_pmc_keyed_int(interp, 436 _class->parents, 0); 437 PMC * const parent_mro = VTABLE_inspect_str(interp, parent, ap); 438 PMC * const mro = VTABLE_clone(interp, parent_mro); 459 PMC *parent, *parents; 460 STRING * const ap = CONST_STRING(interp, "all_parents"); 461 462 GETATTR_Class_parents(interp, SELF, parents); 463 464 parent = VTABLE_get_pmc_keyed_int(interp, parents, 0); 465 mro = VTABLE_clone(interp, 466 VTABLE_inspect_str(interp, parent, ap)); 439 467 VTABLE_unshift_pmc(interp, mro, SELF); 440 _class->all_parents = mro;468 SETATTR_Class_all_parents(interp, SELF, mro);; 441 469 } 442 else 443 _class->all_parents = Parrot_ComputeMRO_C3(interp, SELF); 470 else { 471 mro = Parrot_ComputeMRO_C3(interp, SELF); 472 SETATTR_Class_all_parents(interp, SELF, mro); 473 } 444 474 445 475 if (!CLASS_is_anon_TEST(SELF)) 446 interp->vtables[VTABLE_type(interp, SELF)]->mro = _class->all_parents;476 interp->vtables[VTABLE_type(interp, SELF)]->mro = mro; 447 477 } 448 478 449 479 /* … … 459 489 */ 460 490 461 491 pmclass Class auto_attrs { 492 ATTR INTVAL id; /* The type number of the PMC. */ 493 ATTR INTVAL instantiated; /* Any instantiations since last modification? */ 494 ATTR STRING *name; /* The name of the class. */ 495 ATTR STRING *fullname; /* The name of the class. */ 496 ATTR PMC *_namespace; /* The namespace it's linked to, if any. */ 497 ATTR PMC *parents; /* Immediate parent classes. */ 498 ATTR PMC *all_parents; /* Cached list of ourself and all parents, in MRO order. */ 499 ATTR PMC *roles; /* An array of roles. */ 500 ATTR PMC *methods; /* Hash of method names to methods in this class. */ 501 ATTR PMC *vtable_overrides; /* Hash of Parrot v-table methods we override. */ 502 ATTR PMC *attrib_metadata; /* Hash of attributes in this class to hashes of metadata. */ 503 ATTR PMC *attrib_index; /* Lookup table for attributes in this and parents. */ 504 ATTR PMC *attrib_cache; /* Cache of visible attrib names to indexes. */ 505 ATTR PMC *resolve_method; /* List of method names the class provides to resolve 506 * conflicts with methods from roles. */ 507 ATTR PMC *parent_overrides; 508 ATTR PMC *meth_cache; 462 509 463 ATTR INTVAL id; /* The type number of the PMC. */464 ATTR STRING *name; /* The name of the class. */465 ATTR STRING *fullname; /* The name of the class. */466 ATTR PMC *_namespace; /* The namespace it's linked to, if any. */467 ATTR INTVAL instantiated; /* Any instantiations since last modification? */468 ATTR PMC *parents; /* Immediate parent classes. */469 ATTR PMC *all_parents; /* Cached list of ourself and all parents, in MRO order. */470 ATTR PMC *roles; /* An array of roles. */471 ATTR PMC *methods; /* Hash of method names to methods in this class. */472 ATTR PMC *vtable_overrides; /* Hash of Parrot v-table methods we override. */473 ATTR PMC *attrib_metadata; /* Hash of attributes in this class to hashes of metadata. */474 ATTR PMC *attrib_index; /* Lookup table for attributes in this and parents. */475 ATTR PMC *attrib_cache; /* Cache of visible attrib names to indexes. */476 ATTR PMC *resolve_method; /* List of method names the class provides to resolve477 * conflicts with methods from roles. */478 ATTR PMC *parent_overrides;479 ATTR PMC *meth_cache;480 481 510 /* 482 511 483 512 =item C<void init()> … … 495 524 */ 496 525 497 526 VTABLE void init() { 498 Parrot_Class_attributes * const _class = 499 (Parrot_Class_attributes *) PMC_data(SELF); 527 PMC * const all_parents = pmc_new(INTERP, enum_class_ResizablePMCArray); 500 528 501 529 /* Set flag for custom GC mark. */ 502 530 PObj_custom_mark_SET(SELF); 503 531 504 532 /* Set up the object. */ 505 _class->name = CONST_STRING(interp, ""); 506 _class->_namespace = PMCNULL; 507 _class->parents = pmc_new(interp, enum_class_ResizablePMCArray); 508 _class->all_parents = pmc_new(interp, enum_class_ResizablePMCArray); 509 _class->roles = pmc_new(interp, enum_class_ResizablePMCArray); 510 _class->methods = pmc_new(interp, enum_class_Hash); 511 _class->attrib_metadata = pmc_new(interp, enum_class_Hash); 512 _class->attrib_index = PMCNULL; 513 _class->attrib_cache = PMCNULL; 514 _class->meth_cache = PMCNULL; 515 _class->resolve_method = pmc_new(interp, enum_class_ResizablePMCArray); 533 SET_ATTR_name(INTERP, SELF, CONST_STRING(INTERP, "")); 534 SET_ATTR__namespace(INTERP, SELF, PMCNULL); 516 535 517 _class->vtable_overrides = pmc_new(interp, enum_class_Hash);518 _class->parent_overrides = pmc_new(interp, enum_class_Hash);536 SET_ATTR_parents(INTERP, SELF, pmc_new(INTERP, enum_class_ResizablePMCArray)); 537 SET_ATTR_all_parents(INTERP, SELF, all_parents); 519 538 539 SET_ATTR_roles(INTERP, SELF, pmc_new(INTERP, enum_class_ResizablePMCArray)); 540 SET_ATTR_methods(INTERP, SELF, pmc_new(INTERP, enum_class_Hash)); 541 542 SET_ATTR_attrib_metadata(INTERP, SELF, pmc_new(INTERP, enum_class_Hash)); 543 SET_ATTR_attrib_index(INTERP, SELF, PMCNULL); 544 SET_ATTR_attrib_cache(INTERP, SELF, PMCNULL); 545 546 SET_ATTR_meth_cache(INTERP, SELF, PMCNULL); 547 SET_ATTR_resolve_method(INTERP, SELF, pmc_new(INTERP, enum_class_ResizablePMCArray)); 548 549 SET_ATTR_vtable_overrides(INTERP, SELF, pmc_new(INTERP, enum_class_Hash)); 550 SET_ATTR_parent_overrides(INTERP, SELF, pmc_new(INTERP, enum_class_Hash)); 551 520 552 /* We put ourself on the all parents list. */ 521 VTABLE_push_pmc( interp, _class->all_parents, SELF);553 VTABLE_push_pmc(INTERP, all_parents, SELF); 522 554 523 555 /* We are a class. */ 524 556 PObj_is_class_SET(SELF); … … 529 561 530 562 VTABLE void init_pmc(PMC *init_data) { 531 563 PMC *arg; 532 const INTVAL arg_type = VTABLE_type( interp, init_data);533 STRING * const name_str = CONST_STRING( interp, "name");564 const INTVAL arg_type = VTABLE_type(INTERP, init_data); 565 STRING * const name_str = CONST_STRING(INTERP, "name"); 534 566 535 567 /* Set up the object. */ 536 S ELF.init();568 STATICSELF.init(); 537 569 538 570 /* fast attempt to determine init_data type */ 539 571 switch (arg_type) { … … 542 574 case enum_class_ResizableStringArray: 543 575 case enum_class_NameSpace: 544 576 /* set only the name property */ 545 arg = pmc_new( interp, enum_class_Hash);546 VTABLE_set_pmc_keyed_str( interp, arg, name_str, init_data);577 arg = pmc_new(INTERP, enum_class_Hash); 578 VTABLE_set_pmc_keyed_str(INTERP, arg, name_str, init_data); 547 579 break; 548 580 549 581 case enum_class_Hash: … … 552 584 553 585 /* slow attempt to determine init_data type */ 554 586 default: 555 if (VTABLE_isa( interp, init_data, CONST_STRING(interp, "String"))556 || VTABLE_isa( interp, init_data, CONST_STRING(interp, "Key"))557 || VTABLE_isa( interp, init_data, CONST_STRING(interp, "ResizableStringArray"))) {587 if (VTABLE_isa(INTERP, init_data, CONST_STRING(INTERP, "String")) 588 || VTABLE_isa(INTERP, init_data, CONST_STRING(INTERP, "Key")) 589 || VTABLE_isa(INTERP, init_data, CONST_STRING(INTERP, "ResizableStringArray"))) { 558 590 /* set only the name property */ 559 arg = pmc_new( interp, enum_class_Hash);560 VTABLE_set_pmc_keyed_str( interp, arg, name_str, init_data);591 arg = pmc_new(INTERP, enum_class_Hash); 592 VTABLE_set_pmc_keyed_str(INTERP, arg, name_str, init_data); 561 593 } 562 594 563 if (VTABLE_isa( interp, init_data, CONST_STRING(interp, "Hash")))595 if (VTABLE_isa(INTERP, init_data, CONST_STRING(INTERP, "Hash"))) 564 596 arg = init_data; 565 597 else 566 598 Parrot_ex_throw_from_c_args(INTERP, NULL, … … 570 602 } 571 603 572 604 /* Initialize the class with the supplied data. */ 573 init_class_from_hash( interp, SELF, arg);605 init_class_from_hash(INTERP, SELF, arg); 574 606 } 575 607 576 608 /* … … 584 616 */ 585 617 586 618 VTABLE STRING *get_string() { 587 return Parrot_str_copy( interp, make_class_name(interp, SELF));619 return Parrot_str_copy(INTERP, make_class_name(INTERP, SELF)); 588 620 } 589 621 590 622 /* … … 598 630 */ 599 631 600 632 VTABLE void mark() { 601 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF); 602 Parrot_gc_mark_STRING_alive(interp, _class->name); 603 Parrot_gc_mark_STRING_alive(interp, _class->fullname); 604 Parrot_gc_mark_PMC_alive(interp, _class->_namespace); 605 Parrot_gc_mark_PMC_alive(interp, _class->parents); 606 Parrot_gc_mark_PMC_alive(interp, _class->all_parents); 607 Parrot_gc_mark_PMC_alive(interp, _class->roles); 608 Parrot_gc_mark_PMC_alive(interp, _class->methods); 609 Parrot_gc_mark_PMC_alive(interp, _class->vtable_overrides); 610 Parrot_gc_mark_PMC_alive(interp, _class->parent_overrides); 611 Parrot_gc_mark_PMC_alive(interp, _class->attrib_metadata); 612 Parrot_gc_mark_PMC_alive(interp, _class->attrib_index); 613 Parrot_gc_mark_PMC_alive(interp, _class->attrib_cache); 614 Parrot_gc_mark_PMC_alive(interp, _class->resolve_method); 615 Parrot_gc_mark_PMC_alive(interp, _class->meth_cache); 633 STRING *tmp_name; 634 PMC *tmp; 635 636 if (!PMC_data(SELF)) 637 return; 638 639 GET_ATTR_name(INTERP, SELF, tmp_name); 640 Parrot_gc_mark_STRING_alive(INTERP, tmp_name); 641 642 GET_ATTR_fullname(INTERP, SELF, tmp_name); 643 Parrot_gc_mark_STRING_alive(INTERP, tmp_name); 644 645 GET_ATTR__namespace(INTERP, SELF, tmp); 646 Parrot_gc_mark_PMC_alive(INTERP, tmp); 647 648 GET_ATTR_parents(INTERP, SELF, tmp); 649 Parrot_gc_mark_PMC_alive(INTERP, tmp); 650 651 GET_ATTR_all_parents(INTERP, SELF, tmp); 652 Parrot_gc_mark_PMC_alive(INTERP, tmp); 653 654 GET_ATTR_roles(INTERP, SELF, tmp); 655 Parrot_gc_mark_PMC_alive(INTERP, tmp); 656 657 GET_ATTR_methods(INTERP, SELF, tmp); 658 Parrot_gc_mark_PMC_alive(INTERP, tmp); 659 660 GET_ATTR_vtable_overrides(INTERP, SELF, tmp); 661 Parrot_gc_mark_PMC_alive(INTERP, tmp); 662 663 GET_ATTR_parent_overrides(INTERP, SELF, tmp); 664 Parrot_gc_mark_PMC_alive(INTERP, tmp); 665 666 GET_ATTR_attrib_metadata(INTERP, SELF, tmp); 667 Parrot_gc_mark_PMC_alive(INTERP, tmp); 668 669 GET_ATTR_attrib_index(INTERP, SELF, tmp); 670 Parrot_gc_mark_PMC_alive(INTERP, tmp); 671 672 GET_ATTR_attrib_cache(INTERP, SELF, tmp); 673 Parrot_gc_mark_PMC_alive(INTERP, tmp); 674 675 GET_ATTR_resolve_method(INTERP, SELF, tmp); 676 Parrot_gc_mark_PMC_alive(INTERP, tmp); 677 678 GET_ATTR_meth_cache(INTERP, SELF, tmp); 679 Parrot_gc_mark_PMC_alive(INTERP, tmp); 616 680 } 617 681 618 682 … … 630 694 */ 631 695 632 696 VTABLE void add_attribute(STRING *name, PMC *type) { 633 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF); 634 PMC * const new_attribute = pmc_new(interp, enum_class_Hash); 697 INTVAL instantiated; 698 PMC *attrib_metadata; 699 PMC * const new_attribute = pmc_new(INTERP, enum_class_Hash); 635 700 701 GET_ATTR_instantiated(INTERP, SELF, instantiated); 702 636 703 /* If we've been instantiated already, not allowed. */ 637 if ( _class->instantiated)638 Parrot_ex_throw_from_c_args( interp, NULL, EXCEPTION_INVALID_OPERATION,704 if (instantiated) 705 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION, 639 706 "Modifications to classes are not allowed after instantiation."); 640 707 708 GET_ATTR_attrib_metadata(INTERP, SELF, attrib_metadata); 709 641 710 /* If we already have an attribute of this name, it's an error. */ 642 if (VTABLE_exists_keyed_str( interp, _class->attrib_metadata, name))643 Parrot_ex_throw_from_c_args( interp, NULL, EXCEPTION_INVALID_OPERATION,711 if (VTABLE_exists_keyed_str(INTERP, attrib_metadata, name)) 712 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION, 644 713 "Attribute '%Ss' already exists in '%Ss'.", name, 645 714 VTABLE_get_string(INTERP, SELF)); 646 715 647 716 /* Set name and type. */ 648 VTABLE_set_string_keyed_str( interp, new_attribute, CONST_STRING(interp, "name"), name);717 VTABLE_set_string_keyed_str(INTERP, new_attribute, CONST_STRING(INTERP, "name"), name); 649 718 650 719 if (!PMC_IS_NULL(type)) 651 VTABLE_set_pmc_keyed_str( interp, new_attribute, CONST_STRING(interp, "type"), type);720 VTABLE_set_pmc_keyed_str(INTERP, new_attribute, CONST_STRING(INTERP, "type"), type); 652 721 653 722 /* Enter the attribute in the attrib_metadata table. */ 654 VTABLE_set_pmc_keyed_str(interp, _class->attrib_metadata, name, 655 new_attribute); 723 VTABLE_set_pmc_keyed_str(INTERP, attrib_metadata, name, new_attribute); 656 724 } 657 725 658 726 /* … … 668 736 */ 669 737 670 738 VTABLE void remove_attribute(STRING *name) { 671 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF); 739 INTVAL instantiated; 740 PMC *attrib_metadata; 672 741 742 GET_ATTR_instantiated(INTERP, SELF, instantiated); 743 673 744 /* If we've been instantiated already, not allowed. */ 674 if ( _class->instantiated)675 Parrot_ex_throw_from_c_args( interp, NULL, EXCEPTION_INVALID_OPERATION,745 if (instantiated) 746 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION, 676 747 "Modifications to classes are not allowed after instantiation."); 677 748 749 GET_ATTR_attrib_metadata(INTERP, SELF, attrib_metadata); 750 678 751 /* If we don't have an attribute of this name, it's an error. */ 679 if (!VTABLE_exists_keyed_str( interp, _class->attrib_metadata, name))680 Parrot_ex_throw_from_c_args( interp, NULL, EXCEPTION_INVALID_OPERATION,752 if (!VTABLE_exists_keyed_str(INTERP, attrib_metadata, name)) 753 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION, 681 754 "Attribute '%Ss' cannot be removed, does not exist in '%Ss'.", name, 682 755 VTABLE_get_string(INTERP, SELF)); 683 756 684 757 /* Remove the attribute from the attrib_metadata table. */ 685 VTABLE_delete_keyed_str( interp, _class->attrib_metadata, name);758 VTABLE_delete_keyed_str(INTERP, attrib_metadata, name); 686 759 687 build_attrib_index( interp, SELF);760 build_attrib_index(INTERP, SELF); 688 761 } 689 762 690 763 /* … … 697 770 698 771 */ 699 772 VTABLE void add_method(STRING *name, PMC *sub) { 700 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF); 701 PMC * const method = 702 VTABLE_get_pmc_keyed_str(interp, _class->methods, name); 773 PMC *methods, *method; 703 774 775 GET_ATTR_methods(INTERP, SELF, methods); 776 777 method = VTABLE_get_pmc_keyed_str(INTERP, methods, name); 778 704 779 /* If we have already added a method with this name... */ 705 780 if (!PMC_IS_NULL(method)) { 706 781 if (method == sub) 707 782 return; 708 783 709 Parrot_ex_throw_from_c_args( interp, NULL, EXCEPTION_INVALID_OPERATION,784 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION, 710 785 "A method named '%S' already exists in class '%S'. " 711 786 "It may have been supplied by a role.", 712 name, VTABLE_get_string( interp, SELF));787 name, VTABLE_get_string(INTERP, SELF)); 713 788 } 714 789 715 790 /* Enter it into the table. */ 716 VTABLE_set_pmc_keyed_str( interp, _class->methods, name, sub);791 VTABLE_set_pmc_keyed_str(INTERP, methods, name, sub); 717 792 } 718 793 719 794 /* … … 726 801 727 802 */ 728 803 VTABLE void remove_method(STRING *name) { 729 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF); 730 if (VTABLE_exists_keyed_str(interp, _class->methods, name)) 731 VTABLE_delete_keyed_str(interp, _class->methods, name); 804 PMC *methods; 805 806 GET_ATTR_methods(INTERP, SELF, methods); 807 808 if (VTABLE_exists_keyed_str(INTERP, methods, name)) 809 VTABLE_delete_keyed_str(INTERP, methods, name); 732 810 else 733 Parrot_ex_throw_from_c_args( interp, NULL, EXCEPTION_INVALID_OPERATION,811 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION, 734 812 "No method named '%S' to remove in class '%S'.", 735 name, VTABLE_get_string( interp, SELF));813 name, VTABLE_get_string(INTERP, SELF)); 736 814 } 737 815 738 816 /* … … 745 823 746 824 */ 747 825 VTABLE void add_vtable_override(STRING *name, PMC *sub) { 748 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF); 749 PMC * const vtable = 750 VTABLE_get_pmc_keyed_str(interp, _class->vtable_overrides, name); 826 PMC *vtable_overrides, *vtable; 751 827 828 GET_ATTR_vtable_overrides(INTERP, SELF, vtable_overrides); 829 830 vtable = VTABLE_get_pmc_keyed_str(INTERP, vtable_overrides, name); 831 752 832 /* If we have already added a vtable override with this name... */ 753 833 if (!PMC_IS_NULL(vtable)) { 754 834 if (vtable == sub) 755 835 return; 756 836 757 Parrot_ex_throw_from_c_args( interp, NULL,837 Parrot_ex_throw_from_c_args(INTERP, NULL, 758 838 EXCEPTION_INVALID_OPERATION, 759 839 "A vtable override named '%S' already exists in class '%S'. " 760 840 "It may have been supplied by a role.", 761 name, VTABLE_get_string( interp, SELF));841 name, VTABLE_get_string(INTERP, SELF)); 762 842 } 763 843 764 844 /* Check that the name is actually valid as a vtable override */ 765 if (Parrot_get_vtable_index( interp, name) == -1)766 Parrot_ex_throw_from_c_args( interp, NULL,845 if (Parrot_get_vtable_index(INTERP, name) == -1) 846 Parrot_ex_throw_from_c_args(INTERP, NULL, 767 847 EXCEPTION_METHOD_NOT_FOUND, 768 848 "'%S' is not a valid vtable function name.", name); 769 849 770 850 /* Add it to vtable methods list. */ 771 VTABLE_set_pmc_keyed_str( interp, _class->vtable_overrides, name, sub);851 VTABLE_set_pmc_keyed_str(INTERP, vtable_overrides, name, sub); 772 852 } 773 853 774 854 /* … … 781 861 782 862 */ 783 863 VTABLE void add_parent(PMC *parent) { 784 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF); 785 int parent_count, index; 864 int parent_count, index; 865 INTVAL instantiated; 866 PMC *parents, *all_parents; 786 867 868 GET_ATTR_instantiated(INTERP, SELF, instantiated); 869 787 870 /* If we've been instantiated already, not allowed. */ 788 if ( _class->instantiated)789 Parrot_ex_throw_from_c_args( interp, NULL,871 if (instantiated) 872 Parrot_ex_throw_from_c_args(INTERP, NULL, 790 873 EXCEPTION_INVALID_OPERATION, 791 874 "Modifications to classes are not allowed after instantiation."); 792 875 793 876 /* Ensure it really is a class. */ 794 877 if (!PObj_is_class_TEST(parent)) 795 Parrot_ex_throw_from_c_args( interp, NULL,878 Parrot_ex_throw_from_c_args(INTERP, NULL, 796 879 EXCEPTION_INVALID_OPERATION, "Parent isn't a Class."); 797 880 798 881 /* Check is not self */ 799 882 if (parent == SELF) 800 Parrot_ex_throw_from_c_args( interp, NULL,883 Parrot_ex_throw_from_c_args(INTERP, NULL, 801 884 EXCEPTION_INVALID_OPERATION, "Can't be own parent"); 802 885 886 GET_ATTR_parents(INTERP, SELF, parents); 887 803 888 /* get number of direct parents */ 804 parent_count = VTABLE_elements( interp, _class->parents);889 parent_count = VTABLE_elements(INTERP, parents); 805 890 806 891 /* iterate over all direct parents, check whether this class already has 807 892 * the parent being added. */ 808 893 for (index = 0; index < parent_count; index++) { 809 894 /* get the next parent */ 810 PMC * const current_parent = VTABLE_get_pmc_keyed_int( interp,811 _class->parents, index);895 PMC * const current_parent = VTABLE_get_pmc_keyed_int(INTERP, 896 parents, index); 812 897 813 898 /* throw an exception if we already have this parent */ 814 899 if (current_parent == parent) 815 Parrot_ex_throw_from_c_args( interp, NULL,900 Parrot_ex_throw_from_c_args(INTERP, NULL, 816 901 EXCEPTION_INVALID_OPERATION, 817 902 "The class '%S' already has a parent class '%S'. " 818 903 "It may have been supplied by a role.", 819 VTABLE_get_string( interp, SELF),820 VTABLE_get_string( interp, parent));904 VTABLE_get_string(INTERP, SELF), 905 VTABLE_get_string(INTERP, parent)); 821 906 } 822 907 908 GET_ATTR_all_parents(INTERP, parent, all_parents); 909 823 910 /* Check that none of the parents is self */ 824 parent_count = VTABLE_elements( interp, PARROT_CLASS(parent)->all_parents);911 parent_count = VTABLE_elements(INTERP, all_parents); 825 912 826 913 for (index = 0; index < parent_count; index++) { 827 914 /* get the next parent */ 828 PMC * const current_parent = VTABLE_get_pmc_keyed_int( interp,829 PARROT_CLASS(parent)->all_parents, index);915 PMC * const current_parent = VTABLE_get_pmc_keyed_int(INTERP, 916 all_parents, index); 830 917 831 918 if (current_parent == SELF) 832 Parrot_ex_throw_from_c_args( interp, NULL,919 Parrot_ex_throw_from_c_args(INTERP, NULL, 833 920 EXCEPTION_INVALID_OPERATION, 834 921 "Loop in class hierarchy: '%S' is an ancestor of '%S'.", 835 VTABLE_get_string( interp, SELF),836 VTABLE_get_string( interp, parent));922 VTABLE_get_string(INTERP, SELF), 923 VTABLE_get_string(INTERP, parent)); 837 924 } 838 925 839 926 /* Add to the lists of our immediate parents and all parents. */ 840 VTABLE_push_pmc( interp, _class->parents, parent);841 calculate_mro( interp, SELF, parent_count + 1);927 VTABLE_push_pmc(INTERP, parents, parent); 928 calculate_mro(INTERP, SELF, parent_count + 1); 842 929 } 843 930 844 931 /* … … 853 940 854 941 */ 855 942 VTABLE void remove_parent(PMC *parent) { 856 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF); 857 int parent_count, index; 943 int parent_count, index; 944 INTVAL instantiated; 945 PMC *parents, *all_parents; 858 946 947 GET_ATTR_instantiated(INTERP, SELF, instantiated); 948 859 949 /* If we've been instantiated already, not allowed. */ 860 if ( _class->instantiated)861 Parrot_ex_throw_from_c_args( interp, NULL,950 if (instantiated) 951 Parrot_ex_throw_from_c_args(INTERP, NULL, 862 952 EXCEPTION_INVALID_OPERATION, 863 953 "Modifications to classes are not allowed after instantiation."); 864 954 865 955 /* Ensure it really is a class. */ 866 956 if (!PObj_is_class_TEST(parent)) 867 Parrot_ex_throw_from_c_args( interp, NULL,957 Parrot_ex_throw_from_c_args(INTERP, NULL, 868 958 EXCEPTION_INVALID_OPERATION, "Parent isn't a Class."); 869 959 960 GET_ATTR_parents(INTERP, SELF, parents); 961 870 962 /* get number of direct parents */ 871 parent_count = VTABLE_elements( interp, _class->parents);963 parent_count = VTABLE_elements(INTERP, parents); 872 964 873 965 /* iterate over all direct parents, looking for the parent to remove */ 874 966 for (index = 0; index < parent_count; index++) { 875 967 /* get the next parent */ 876 PMC * const current_parent = VTABLE_get_pmc_keyed_int( interp,877 _class->parents, index);968 PMC * const current_parent = VTABLE_get_pmc_keyed_int(INTERP, 969 parents, index); 878 970 if (current_parent == parent) 879 971 break; 880 972 } 881 973 882 974 if (index >= parent_count) 883 Parrot_ex_throw_from_c_args( interp, NULL,975 Parrot_ex_throw_from_c_args(INTERP, NULL, 884 976 EXCEPTION_INVALID_OPERATION, 885 977 "Can't remove_parent: is not a parent."); 886 978 887 VTABLE_delete_keyed_int( interp, _class->parents, index);888 calculate_mro( interp, SELF, parent_count - 1);979 VTABLE_delete_keyed_int(INTERP, parents, index); 980 calculate_mro(INTERP, SELF, parent_count - 1); 889 981 } 890 982 891 983 /* … … 899 991 900 992 */ 901 993 VTABLE void add_role(PMC *role) { 902 const Parrot_Class_attributes * const _class = PARROT_CLASS(SELF);994 PMC *resolve_method, *methods, *roles; 903 995 996 GET_ATTR_resolve_method(INTERP, SELF, resolve_method); 997 GET_ATTR_methods(INTERP, SELF, methods); 998 GET_ATTR_roles(INTERP, SELF, roles); 999 904 1000 /* Do the composition. */ 905 Parrot_ComposeRole( interp, role,906 _class->resolve_method, !PMC_IS_NULL(_class->resolve_method),907 PMCNULL, 0, _class->methods, _class->roles);1001 Parrot_ComposeRole(INTERP, role, 1002 resolve_method, !PMC_IS_NULL(resolve_method), 1003 PMCNULL, 0, methods, roles); 908 1004 } 909 1005 910 1006 /* … … 948 1044 949 1045 */ 950 1046 VTABLE PMC *inspect_str(STRING *what) { 951 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF);952 953 1047 /* What should we return? */ 954 1048 PMC *found; 955 1049 956 if (Parrot_str_equal( interp, what, CONST_STRING(interp, "attributes"))) {957 found = _class->attrib_metadata;1050 if (Parrot_str_equal(INTERP, what, CONST_STRING(INTERP, "attributes"))) { 1051 GET_ATTR_attrib_metadata(INTERP, SELF, found); 958 1052 } 959 else if (Parrot_str_equal( interp, what, CONST_STRING(interp, "parents"))) {960 found = _class->parents;1053 else if (Parrot_str_equal(INTERP, what, CONST_STRING(INTERP, "parents"))) { 1054 GET_ATTR_parents(INTERP, SELF, found); 961 1055 } 962 else if (Parrot_str_equal(interp, what, CONST_STRING(interp, "name"))) { 963 found = pmc_new(interp, enum_class_String); 964 VTABLE_set_string_native(interp, found, _class->name); 1056 else if (Parrot_str_equal(INTERP, what, CONST_STRING(INTERP, "name"))) { 1057 STRING *name; 1058 1059 GET_ATTR_name(INTERP, SELF, name); 1060 1061 found = pmc_new(INTERP, enum_class_String); 1062 VTABLE_set_string_native(INTERP, found, name); 965 1063 } 966 else if (Parrot_str_equal(interp, what, CONST_STRING(interp, "id"))) { 967 found = pmc_new(interp, enum_class_Integer); 968 VTABLE_set_integer_native(interp, found, _class->id); 1064 else if (Parrot_str_equal(INTERP, what, CONST_STRING(INTERP, "id"))) { 1065 INTVAL id; 1066 GET_ATTR_id(INTERP, SELF, id); 1067 1068 found = pmc_new(INTERP, enum_class_Integer); 1069 VTABLE_set_integer_native(INTERP, found, id); 969 1070 } 970 else if (Parrot_str_equal(interp, what, CONST_STRING(interp, "namespace"))) { 1071 else if (Parrot_str_equal(INTERP, what, CONST_STRING(INTERP, "namespace"))) { 1072 GET_ATTR__namespace(INTERP, SELF, found); 1073 971 1074 /* Should not clone this. */ 972 return _class->_namespace;1075 return found; 973 1076 } 974 else if (Parrot_str_equal( interp, what, CONST_STRING(interp, "attrib_index"))) {975 found = _class->attrib_index;1077 else if (Parrot_str_equal(INTERP, what, CONST_STRING(INTERP, "attrib_index"))) { 1078 GET_ATTR_attrib_index(INTERP, SELF, found); 976 1079 } 977 else if (Parrot_str_equal( interp, what, CONST_STRING(interp, "methods"))) {978 found = _class->methods;1080 else if (Parrot_str_equal(INTERP, what, CONST_STRING(INTERP, "methods"))) { 1081 GET_ATTR_methods(INTERP, SELF, found); 979 1082 } 980 else if (Parrot_str_equal( interp, what, CONST_STRING(interp, "vtable_overrides"))) {981 found = _class->vtable_overrides;1083 else if (Parrot_str_equal(INTERP, what, CONST_STRING(INTERP, "vtable_overrides"))) { 1084 GET_ATTR_vtable_overrides(INTERP, SELF, found); 982 1085 } 983 else if (Parrot_str_equal( interp, what, CONST_STRING(interp, "all_parents"))) {984 found = _class->all_parents;1086 else if (Parrot_str_equal(INTERP, what, CONST_STRING(INTERP, "all_parents"))) { 1087 GET_ATTR_all_parents(INTERP, SELF, found); 985 1088 } 986 else if (Parrot_str_equal( interp, what, CONST_STRING(interp, "roles"))) {987 found = _class->roles;1089 else if (Parrot_str_equal(INTERP, what, CONST_STRING(INTERP, "roles"))) { 1090 GET_ATTR_roles(INTERP, SELF, found); 988 1091 } 989 else if (Parrot_str_equal( interp, what, CONST_STRING(interp, "flags"))) {990 found = pmc_new( interp, enum_class_Integer);991 VTABLE_set_integer_native( interp, found,1092 else if (Parrot_str_equal(INTERP, what, CONST_STRING(INTERP, "flags"))) { 1093 found = pmc_new(INTERP, enum_class_Integer); 1094 VTABLE_set_integer_native(INTERP, found, 992 1095 (INTVAL)PObj_get_FLAGS(SELF)); 993 1096 } 994 1097 else 995 Parrot_ex_throw_from_c_args( interp, NULL, EXCEPTION_INVALID_OPERATION,1098 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION, 996 1099 "Unknown introspection value '%S'", what); 997 1100 998 1101 /* return found value */ … … 1002 1105 if (found->vtable->base_type == enum_class_Hash) { 1003 1106 /* for Hash return values, create and return a shallow 1004 1107 * clone because the VTABLE_clone does a deep clone */ 1005 PMC * const hash = pmc_new( interp, enum_class_Hash);1006 PMC * const iter = VTABLE_get_iter( interp, found);1007 while (VTABLE_get_bool( interp, iter)) {1008 STRING * const key = VTABLE_shift_string( interp, iter);1009 PMC * const value = VTABLE_get_pmc_keyed_str( interp, found, key);1010 VTABLE_set_pmc_keyed_str( interp, hash, key, value);1108 PMC * const hash = pmc_new(INTERP, enum_class_Hash); 1109 PMC * const iter = VTABLE_get_iter(INTERP, found); 1110 while (VTABLE_get_bool(INTERP, iter)) { 1111 STRING * const key = VTABLE_shift_string(INTERP, iter); 1112 PMC * const value = VTABLE_get_pmc_keyed_str(INTERP, found, key); 1113 VTABLE_set_pmc_keyed_str(INTERP, hash, key, value); 1011 1114 } 1012 1115 1013 1116 return hash; 1014 1117 } 1015 1118 1016 return VTABLE_clone( interp, found);1119 return VTABLE_clone(INTERP, found); 1017 1120 } 1018 1121 1019 1122 /* … … 1029 1132 VTABLE PMC *inspect() { 1030 1133 /* Create a hash, then use inspect_str to get all of the data to 1031 1134 * fill it up with. */ 1032 PMC * const metadata = pmc_new( interp, enum_class_Hash);1033 STRING * const name_str = CONST_STRING( interp, "name");1034 STRING * const ns_str = CONST_STRING( interp, "namespace");1035 STRING * const attrs_str = CONST_STRING( interp, "attributes");1036 STRING * const meths_str = CONST_STRING( interp, "methods");1037 STRING * const parents_str = CONST_STRING( interp, "parents");1038 STRING * const roles_str = CONST_STRING( interp, "roles");1039 STRING * const flags_str = CONST_STRING( interp, "flags");1135 PMC * const metadata = pmc_new(INTERP, enum_class_Hash); 1136 STRING * const name_str = CONST_STRING(INTERP, "name"); 1137 STRING * const ns_str = CONST_STRING(INTERP, "namespace"); 1138 STRING * const attrs_str = CONST_STRING(INTERP, "attributes"); 1139 STRING * const meths_str = CONST_STRING(INTERP, "methods"); 1140 STRING * const parents_str = CONST_STRING(INTERP, "parents"); 1141 STRING * const roles_str = CONST_STRING(INTERP, "roles"); 1142 STRING * const flags_str = CONST_STRING(INTERP, "flags"); 1040 1143 1041 VTABLE_set_pmc_keyed_str( interp, metadata, name_str,1042 VTABLE_inspect_str( interp, SELF, name_str));1144 VTABLE_set_pmc_keyed_str(INTERP, metadata, name_str, 1145 VTABLE_inspect_str(INTERP, SELF, name_str)); 1043 1146 1044 VTABLE_set_pmc_keyed_str( interp, metadata, ns_str,1045 VTABLE_inspect_str( interp, SELF, ns_str));1147 VTABLE_set_pmc_keyed_str(INTERP, metadata, ns_str, 1148 VTABLE_inspect_str(INTERP, SELF, ns_str)); 1046 1149 1047 VTABLE_set_pmc_keyed_str( interp, metadata, attrs_str,1048 VTABLE_inspect_str( interp, SELF, attrs_str));1150 VTABLE_set_pmc_keyed_str(INTERP, metadata, attrs_str, 1151 VTABLE_inspect_str(INTERP, SELF, attrs_str)); 1049 1152 1050 VTABLE_set_pmc_keyed_str( interp, metadata, meths_str,1051 VTABLE_inspect_str( interp, SELF, meths_str));1153 VTABLE_set_pmc_keyed_str(INTERP, metadata, meths_str, 1154 VTABLE_inspect_str(INTERP, SELF, meths_str)); 1052 1155 1053 VTABLE_set_pmc_keyed_str( interp, metadata, parents_str,1054 VTABLE_inspect_str( interp, SELF, parents_str));1156 VTABLE_set_pmc_keyed_str(INTERP, metadata, parents_str, 1157 VTABLE_inspect_str(INTERP, SELF, parents_str)); 1055 1158 1056 VTABLE_set_pmc_keyed_str( interp, metadata, roles_str,1057 VTABLE_inspect_str( interp, SELF, roles_str));1159 VTABLE_set_pmc_keyed_str(INTERP, metadata, roles_str, 1160 VTABLE_inspect_str(INTERP, SELF, roles_str)); 1058 1161 1059 VTABLE_set_pmc_keyed_str( interp, metadata, flags_str,1060 VTABLE_inspect_str( interp, SELF, flags_str));1162 VTABLE_set_pmc_keyed_str(INTERP, metadata, flags_str, 1163 VTABLE_inspect_str(INTERP, SELF, flags_str)); 1061 1164 1062 1165 return metadata; 1063 1166 } … … 1074 1177 */ 1075 1178 1076 1179 VTABLE PMC *clone() { 1077 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF); 1180 PMC *parents, *roles, *methods, *vtable_overrides; 1181 PMC *parent_overrides, *attrib_metadata, *resolve_method; 1078 1182 1079 1183 /* Create the new class PMC, of the same type of this one (we may 1080 1184 * have been subclassed). */ 1081 PMC * const copy= SUPER();1185 PMC * const copy = SUPER(); 1082 1186 1187 GET_ATTR_parents(INTERP, SELF, parents); 1188 GET_ATTR_roles(INTERP, SELF, roles); 1189 GET_ATTR_methods(INTERP, SELF, methods); 1190 GET_ATTR_vtable_overrides(INTERP, SELF, vtable_overrides); 1191 GET_ATTR_parent_overrides(INTERP, SELF, parent_overrides); 1192 GET_ATTR_attrib_metadata(INTERP, SELF, attrib_metadata); 1193 GET_ATTR_resolve_method(INTERP, SELF, resolve_method); 1194 1083 1195 /* Clone parents, roles, methods, attributes and resolve data. We do 1084 1196 * not copy name/namespace related stuff (need anonymous clone) or 1085 1197 * stuff that gets computed on the first instantiation. */ 1198 SET_ATTR_name(INTERP, copy, CONST_STRING(INTERP, "")); 1199 SET_ATTR__namespace(INTERP, copy, PMCNULL); 1200 SET_ATTR_parents(INTERP, copy, VTABLE_clone(INTERP, parents)); 1201 SET_ATTR_roles(INTERP, copy, VTABLE_clone(INTERP, roles)); 1202 SET_ATTR_methods(INTERP, copy, VTABLE_clone(INTERP, methods)); 1203 SET_ATTR_vtable_overrides(INTERP, copy, VTABLE_clone(INTERP, vtable_overrides)); 1204 SET_ATTR_parent_overrides(INTERP, copy, VTABLE_clone(INTERP, parent_overrides)); 1205 SET_ATTR_attrib_metadata(INTERP, copy, VTABLE_clone(INTERP, attrib_metadata)); 1206 SET_ATTR_resolve_method(INTERP, copy, VTABLE_clone(INTERP, resolve_method)); 1086 1207 1087 Parrot_Class_attributes * const new_class = PARROT_CLASS(copy);1088 1089 new_class->name = CONST_STRING(interp, "");1090 new_class->_namespace = PMCNULL;1091 new_class->parents = VTABLE_clone(interp, _class->parents);1092 new_class->roles = VTABLE_clone(interp, _class->roles);1093 new_class->methods = VTABLE_clone(interp, _class->methods);1094 new_class->vtable_overrides = VTABLE_clone(interp,1095 _class->vtable_overrides);1096 new_class->parent_overrides = VTABLE_clone(interp,1097 _class->parent_overrides);1098 new_class->attrib_metadata = VTABLE_clone(interp,1099 _class->attrib_metadata);1100 new_class->resolve_method = VTABLE_clone(interp,1101 _class->resolve_method);1102 1103 1208 /* Return cloned class. */ 1104 1209 return copy; 1105 1210 } … … 1119 1224 1120 1225 VTABLE PMC *clone_pmc(PMC *args) { 1121 1226 /* Do the standard clone. */ 1122 PMC * const copy = S ELF.clone();1227 PMC * const copy = STATICSELF.clone(); 1123 1228 1124 init_class_from_hash( interp, copy, args);1229 init_class_from_hash(INTERP, copy, args); 1125 1230 1126 1231 return copy; 1127 1232 } … … 1137 1242 */ 1138 1243 1139 1244 VTABLE PMC *instantiate(PMC *init) { 1140 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF);1141 PMC *object;1245 INTVAL instantiated; 1246 PMC *object, *all_parents; 1142 1247 1248 GET_ATTR_instantiated(INTERP, SELF, instantiated); 1249 GET_ATTR_all_parents(INTERP, SELF, all_parents); 1250 1143 1251 /* If we've not been instantiated before... */ 1144 if (!_class->instantiated) { 1252 if (!instantiated) { 1253 int i, resolve_count; 1254 INTVAL num_parents, mro_length; 1255 PMC *resolve_method, *parents, *methods, *attrib_index; 1256 const INTVAL cur_hll = Parrot_pcc_get_HLL(INTERP, CURRENT_CONTEXT(interp)); 1257 1258 GET_ATTR_parents(INTERP, SELF, parents); 1259 GET_ATTR_methods(INTERP, SELF, methods); 1260 GET_ATTR_resolve_method(INTERP, SELF, resolve_method); 1261 1145 1262 /* Check that we have all methods listed in resolve list. */ 1146 const int resolve_count = VTABLE_elements(interp, 1147 _class->resolve_method); 1148 const INTVAL cur_hll = Parrot_pcc_get_HLL(interp, CURRENT_CONTEXT(interp)); 1149 const INTVAL num_parents = VTABLE_elements(interp, _class->parents); 1150 INTVAL mro_length; 1151 int i; 1263 resolve_count = VTABLE_elements(INTERP, resolve_method); 1152 1264 1265 num_parents = VTABLE_elements(INTERP, parents); 1266 1153 1267 /* don't use HLL mappings for internal-only data */ 1154 Parrot_pcc_set_HLL( interp, CURRENT_CONTEXT(interp), 0);1268 Parrot_pcc_set_HLL(INTERP, CURRENT_CONTEXT(interp), 0); 1155 1269 1156 1270 for (i = 0; i < resolve_count; i++) { 1157 1271 STRING * const check_meth = 1158 VTABLE_get_string_keyed_int( interp, _class->resolve_method, i);1159 if (!VTABLE_exists_keyed_str( interp, _class->methods, check_meth))1160 Parrot_ex_throw_from_c_args( interp, NULL,1272 VTABLE_get_string_keyed_int(INTERP, resolve_method, i); 1273 if (!VTABLE_exists_keyed_str(INTERP, methods, check_meth)) 1274 Parrot_ex_throw_from_c_args(INTERP, NULL, 1161 1275 EXCEPTION_METHOD_NOT_FOUND, "The method '%S' was named " 1162 1276 "in the resolve list, but not supplied", check_meth); 1163 1277 } 1164 1278 1165 1279 /* Build full parents list. 1166 1280 * TT #1256: Need pluggable MRO, for now always do C3. */ 1167 calculate_mro( interp, SELF, num_parents);1168 build_attrib_index( interp, SELF);1281 calculate_mro(INTERP, SELF, num_parents); 1282 build_attrib_index(INTERP, SELF); 1169 1283 1170 if (PMC_IS_NULL(_class->attrib_index)) 1284 GET_ATTR_attrib_index(INTERP, SELF, attrib_index); 1285 1286 if (PMC_IS_NULL(attrib_index)) 1171 1287 return PMCNULL; 1172 1288 1173 1289 /* See if we have any parents from other universes and if so set a 1174 1290 * flag stating so. */ 1175 mro_length = VTABLE_elements( interp, _class->all_parents);1291 mro_length = VTABLE_elements(INTERP, all_parents); 1176 1292 1177 1293 for (i = 0; i < mro_length; i++) { 1178 PMC * const class_check = VTABLE_get_pmc_keyed_int( interp,1179 _class->all_parents, i);1294 PMC * const class_check = VTABLE_get_pmc_keyed_int(INTERP, 1295 all_parents, i); 1180 1296 if (class_check->vtable->base_type != enum_class_Class) { 1181 1297 /* Found one; that's enough. */ 1182 1298 CLASS_has_alien_parents_SET(SELF); … … 1184 1300 } 1185 1301 } 1186 1302 1187 Parrot_pcc_set_HLL( interp, CURRENT_CONTEXT(interp), cur_hll);1303 Parrot_pcc_set_HLL(INTERP, CURRENT_CONTEXT(interp), cur_hll); 1188 1304 } 1189 1305 1190 1306 /* Set instantiated flag. */ 1191 _class->instantiated = 1;1307 SET_ATTR_instantiated(INTERP, SELF, 1); 1192 1308 1193 1309 /* Create object. */ 1194 object = pmc_new_noinit( interp, enum_class_Object);1310 object = pmc_new_noinit(INTERP, enum_class_Object); 1195 1311 1196 1312 /* Set custom GC mark and destroy on the object. */ 1197 1313 PObj_custom_mark_destroy_SETALL(object); … … 1204 1320 /* TODO: this has been changed in order to use auto_attrs in the 1205 1321 * Object PMC. Needs to be redone in a cleaner way. */ 1206 1322 { 1207 Parrot_Object_attributes * const objattr = 1208 PMC_data_typed(object, Parrot_Object_attributes *); 1323 Parrot_Object_attributes * const objattr = PARROT_OBJECT(object); 1209 1324 objattr->_class = SELF; 1210 objattr->attrib_store = pmc_new( interp, enum_class_ResizablePMCArray);1325 objattr->attrib_store = pmc_new(INTERP, enum_class_ResizablePMCArray); 1211 1326 } 1212 1327 1213 1328 if (!PMC_IS_NULL(init)) { 1214 1329 /* Initialize attributes with the supplied values. */ 1215 PMC * const iter = VTABLE_get_iter( interp, init);1330 PMC * const iter = VTABLE_get_iter(INTERP, init); 1216 1331 1217 while (VTABLE_get_bool( interp, iter)) {1218 STRING * const name = VTABLE_shift_string( interp, iter);1219 PMC * const value = VTABLE_get_pmc_keyed_str( interp, init,1332 while (VTABLE_get_bool(INTERP, iter)) { 1333 STRING * const name = VTABLE_shift_string(INTERP, iter); 1334 PMC * const value = VTABLE_get_pmc_keyed_str(INTERP, init, 1220 1335 name); 1221 1336 1222 1337 /* Set the attribute. */ 1223 VTABLE_set_attr_str( interp, object, name, value);1338 VTABLE_set_attr_str(INTERP, object, name, value); 1224 1339 } 1225 1340 1226 1341 /* Check for overrides on the init_pmc vtable function */ 1227 initialize_parents_pmc( interp, object, _class->all_parents, init);1342 initialize_parents_pmc(INTERP, object, all_parents, init); 1228 1343 } 1229 1344 else 1230 1345 /* Check for overrides on the init vtable function */ 1231 initialize_parents( interp, object, _class->all_parents);1346 initialize_parents(INTERP, object, all_parents); 1232 1347 1233 1348 return object; 1234 1349 } … … 1245 1360 */ 1246 1361 1247 1362 VTABLE INTVAL isa_pmc(PMC *lookup) { 1248 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF); 1249 PMC *classobj; 1250 INTVAL i, num_classes; 1363 INTVAL i, num_classes; 1364 PMC *classobj, *parents; 1251 1365 1252 1366 if (PMC_IS_NULL(lookup)) 1253 1367 return 0; … … 1255 1369 if (PObj_is_class_TEST(lookup) && lookup == SELF) 1256 1370 return 1; 1257 1371 1258 classobj = Parrot_oo_get_class( interp, lookup);1372 classobj = Parrot_oo_get_class(INTERP, lookup); 1259 1373 1260 1374 if (PMC_IS_NULL(classobj)) 1261 1375 return 0; 1262 1376 1263 1377 /* Check if the class object is the same as self's class object */ 1264 if (VTABLE_is_same( interp, SELF, classobj))1378 if (VTABLE_is_same(INTERP, SELF, classobj)) 1265 1379 return 1; 1266 1380 1267 1381 /* this is effectively what the default PMC's isa_pmc does … … 1269 1383 * only in these two, very specific and common cases */ 1270 1384 if (classobj->vtable->base_type == enum_class_Class 1271 1385 || classobj->vtable->base_type == enum_class_PMCProxy) { 1272 STRING * classname = make_class_name(interp, classobj);1386 STRING * const classname = make_class_name(INTERP, classobj); 1273 1387 1274 if (Parrot_str_equal( interp, SELF->vtable->whoami, classname))1388 if (Parrot_str_equal(INTERP, SELF->vtable->whoami, classname)) 1275 1389 return 1; 1276 1390 1277 1391 if (SELF->vtable->isa_hash 1278 && parrot_hash_exists( interp, SELF->vtable->isa_hash,1392 && parrot_hash_exists(INTERP, SELF->vtable->isa_hash, 1279 1393 (void *)classname)) 1280 1394 return 1; 1281 1395 } 1282 1396 1397 GET_ATTR_parents(INTERP, SELF, parents); 1398 1283 1399 /* Iterate over all the parents and check if they respond true 1284 1400 * for 'isa' on the original comparison. */ 1285 num_classes = VTABLE_elements( interp, _class->parents);1401 num_classes = VTABLE_elements(INTERP, parents); 1286 1402 1287 1403 for (i = 0; i < num_classes; i++) { 1288 PMC * const cur_class = VTABLE_get_pmc_keyed_int( interp,1289 _class->parents, i);1404 PMC * const cur_class = VTABLE_get_pmc_keyed_int(INTERP, 1405 parents, i); 1290 1406 1291 if (VTABLE_isa_pmc( interp, cur_class, lookup))1407 if (VTABLE_isa_pmc(INTERP, cur_class, lookup)) 1292 1408 return 1; 1293 1409 } 1294 1410 … … 1309 1425 PMC *want_class; 1310 1426 1311 1427 /* hard-code this one exception right away */ 1312 if (Parrot_str_equal( interp, classname, CONST_STRING(interp, "Class")))1428 if (Parrot_str_equal(INTERP, classname, CONST_STRING(INTERP, "Class"))) 1313 1429 return 1; 1314 1430 1315 want_class = Parrot_oo_get_class_str( interp, classname);1431 want_class = Parrot_oo_get_class_str(INTERP, classname); 1316 1432 1317 1433 if (PMC_IS_NULL(want_class)) 1318 1434 return 0; … … 1320 1436 if (SELF == want_class) 1321 1437 return 1; 1322 1438 1323 return VTABLE_isa_pmc( interp, SELF, want_class);1439 return VTABLE_isa_pmc(INTERP, SELF, want_class); 1324 1440 } 1325 1441 1326 1442 /* … … 1333 1449 1334 1450 */ 1335 1451 VTABLE INTVAL does(STRING *role_name) { 1336 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF);1337 PMC * const role_list = _class->roles;1338 1452 INTVAL i, count; 1453 PMC *roles, *parents; 1339 1454 1340 if (!role_list) 1455 GET_ATTR_roles(INTERP, SELF, roles); 1456 1457 if (!roles) 1341 1458 return 0; 1342 1459 1343 count = VTABLE_elements( interp, role_list);1460 count = VTABLE_elements(INTERP, roles); 1344 1461 1345 1462 for (i = 0; i < count; i++) { 1346 PMC * const role = VTABLE_get_pmc_keyed_int( interp, role_list, i);1463 PMC * const role = VTABLE_get_pmc_keyed_int(INTERP, roles, i); 1347 1464 1348 if (VTABLE_does( interp, role, role_name))1465 if (VTABLE_does(INTERP, role, role_name)) 1349 1466 return 1; 1350 1467 } 1351 1468 1469 GET_ATTR_parents(INTERP, SELF, parents); 1470 1352 1471 /* Iterate over all the parents and check if they respond true 1353 1472 * for 'does' on the original comparison. */ 1354 count = VTABLE_elements( interp, _class->parents);1473 count = VTABLE_elements(INTERP, parents); 1355 1474 1356 1475 for (i = 0; i < count; i++) { 1357 PMC * const cur_class = VTABLE_get_pmc_keyed_int( interp,1358 _class->parents, i);1476 PMC * const cur_class = VTABLE_get_pmc_keyed_int(INTERP, 1477 parents, i); 1359 1478 1360 if (VTABLE_does( interp, cur_class, role_name))1479 if (VTABLE_does(INTERP, cur_class, role_name)) 1361 1480 return 1; 1362 1481 } 1363 1482 1364 return VTABLE_isa( interp, SELF, role_name);1483 return VTABLE_isa(INTERP, SELF, role_name); 1365 1484 } 1366 1485 1367 1486 /* … … 1374 1493 1375 1494 */ 1376 1495 VTABLE INTVAL does_pmc(PMC *role) { 1377 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF);1378 PMC * const role_list = _class->roles;1379 1496 INTVAL i, role_count, count; 1497 PMC *roles, *parents; 1380 1498 1381 if (!role_list) 1499 GET_ATTR_roles(INTERP, SELF, roles); 1500 1501 if (!roles) 1382 1502 return 0; 1383 1503 1384 role_count = VTABLE_elements( interp, role_list);1504 role_count = VTABLE_elements(INTERP, role); 1385 1505 1386 1506 for (i = 0; i < role_count; i++) { 1387 PMC * const test_role = VTABLE_get_pmc_keyed_int( interp, role_list, i);1388 if (VTABLE_does_pmc( interp, test_role, role))1507 PMC * const test_role = VTABLE_get_pmc_keyed_int(INTERP, roles, i); 1508 if (VTABLE_does_pmc(INTERP, test_role, role)) 1389 1509 return 1; 1390 1510 } 1391 1511 1512 GET_ATTR_parents(INTERP, SELF, parents); 1513 1392 1514 /* Iterate over all the parents and check if they respond true 1393 1515 * for 'does' on the original comparison. */ 1394 count = VTABLE_elements( interp, _class->parents);1516 count = VTABLE_elements(INTERP, parents); 1395 1517 1396 1518 for (i = 0; i < count; i++) { 1397 PMC * const cur_class = VTABLE_get_pmc_keyed_int( interp,1398 _class->parents, i);1519 PMC * const cur_class = VTABLE_get_pmc_keyed_int(INTERP, 1520 parents, i); 1399 1521 1400 if (VTABLE_does_pmc( interp, cur_class, role))1522 if (VTABLE_does_pmc(INTERP, cur_class, role)) 1401 1523 return 1; 1402 1524 } 1403 1525 1404 return VTABLE_isa_pmc( interp, SELF, role);1526 return VTABLE_isa_pmc(INTERP, SELF, role); 1405 1527 } 1406 1528 1407 1529 /* … … 1415 1537 */ 1416 1538 1417 1539 VTABLE INTVAL type() { 1418 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF); 1419 return _class->id; 1540 INTVAL id; 1541 1542 GET_ATTR_id(INTERP, SELF, id); 1543 1544 return id; 1420 1545 } 1421 1546 1422 1547 /* … … 1477 1602 */ 1478 1603 1479 1604 VTABLE void freeze(visit_info *info) { 1480 IMAGE_IO * const io = info->image_io; 1481 Parrot_Class_attributes * const class_data = PARROT_CLASS(SELF); 1482 STRING *serial_namespace = CONST_STRING(interp, ""); 1605 INTVAL id; 1606 PMC *_namespace; 1607 STRING *name; 1608 STRING *serial_namespace = CONST_STRING(INTERP, ""); 1609 IMAGE_IO * const io = info->image_io; 1483 1610 1611 GET_ATTR_id(INTERP, SELF, id); 1612 GET_ATTR_name(INTERP, SELF, name); 1613 GET_ATTR__namespace(INTERP, SELF, _namespace); 1614 1484 1615 /* 1) freeze class id */ 1485 VTABLE_push_integer(INTERP, io, class_data->id);1616 VTABLE_push_integer(INTERP, io, id); 1486 1617 1487 1618 /* 2) freeze class name */ 1488 VTABLE_push_string(INTERP, io, class_data->name);1619 VTABLE_push_string(INTERP, io, name); 1489 1620 1490 1621 /* 3) serialize namespace name, including HLL */ 1491 if (!PMC_IS_NULL( class_data->_namespace)) {1492 PMC * const names = Parrot_ns_get_name( interp,1493 class_data->_namespace);1622 if (!PMC_IS_NULL(_namespace)) { 1623 PMC * const names = Parrot_ns_get_name(INTERP, 1624 _namespace); 1494 1625 if (!PMC_IS_NULL(names)) 1495 serial_namespace = Parrot_str_join( interp, CONST_STRING(interp, ";"), names);1626 serial_namespace = Parrot_str_join(INTERP, CONST_STRING(INTERP, ";"), names); 1496 1627 } 1497 1628 VTABLE_push_string(INTERP, io, serial_namespace); 1498 1629 } … … 1526 1657 1527 1658 /* 3) deserialize namespace name, including HLL */ 1528 1659 STRING * const serial_namespace = VTABLE_shift_string(INTERP, io); 1529 STRING * const semicolon_str = CONST_STRING(INTERP, ";");1530 PMC * const namespace_array =1531 Parrot_str_split(INTERP, semicolon_str, serial_namespace);1532 PMC *ns = Parrot_get_namespace_keyed(interp,1660 STRING * const semicolon_str = CONST_STRING(INTERP, ";"); 1661 PMC * const namespace_array = 1662 Parrot_str_split(INTERP, semicolon_str, serial_namespace); 1663 PMC *ns = Parrot_get_namespace_keyed(INTERP, 1533 1664 INTERP->root_namespace, namespace_array); 1534 1665 1535 1666 /* If the namespace doesn't exist, we create it, and initialize 1536 1667 * ourselves in it */ 1537 1668 if (PMC_IS_NULL(ns)) { 1538 ns = Parrot_make_namespace_keyed( interp,1669 ns = Parrot_make_namespace_keyed(INTERP, 1539 1670 INTERP->root_namespace, namespace_array); 1540 S ELF.init_pmc(ns);1671 STATICSELF.init_pmc(ns); 1541 1672 } 1542 1673 /* If the namespace exists already, we point to it, but otherwise 1543 1674 * act as an anonymous class. */ 1544 1675 else { 1545 S ELF.init();1546 PARROT_CLASS(SELF)->_namespace = ns;1676 STATICSELF.init(); 1677 SET_ATTR__namespace(INTERP, SELF, ns); 1547 1678 } 1548 1679 1680 /* Set the class's id the frozen id */ 1681 SET_ATTR_id(INTERP, SELF, id); 1682 1549 1683 /* Set the class's short name to the frozen name */ 1550 PARROT_CLASS(SELF)->name = name; 1551 1552 /* Set the class's id the frozen id */ 1553 PARROT_CLASS(SELF)->id = id; 1684 SET_ATTR_name(INTERP, SELF, name); 1554 1685 } 1555 1686 } 1556 1687 … … 1567 1698 */ 1568 1699 1569 1700 VTABLE INTVAL get_integer() { 1570 return PARROT_CLASS(SELF)->id; 1701 INTVAL id; 1702 1703 GET_ATTR_id(INTERP, SELF, id); 1704 1705 return id; 1571 1706 } 1572 1707 1573 1708 /* … … 1581 1716 */ 1582 1717 1583 1718 VTABLE void thawfinish(visit_info *info) { 1584 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF);1585 1719 UNUSED(info) 1586 1720 1587 1721 /* Recalculate full MRO from thawed parents */ 1588 _class->all_parents = Parrot_ComputeMRO_C3(interp, SELF);1589 _class->parent_overrides = pmc_new(interp, enum_class_Hash);1722 SET_ATTR_all_parents(INTERP, SELF, Parrot_ComputeMRO_C3(INTERP, SELF)); 1723 SET_ATTR_parent_overrides(INTERP, SELF, pmc_new(INTERP, enum_class_Hash)); 1590 1724 1591 1725 /* Rebuild attribute index from thawed attribute metadata */ 1592 build_attrib_index( interp, SELF);1726 build_attrib_index(INTERP, SELF); 1593 1727 } 1594 1728 1595 1729 /* ********************************************************************** … … 1608 1742 1609 1743 */ 1610 1744 METHOD name(STRING *name :optional, int has_name :opt_flag) { 1611 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF);1612 1745 STRING *ret_name; 1613 1746 1614 1747 if (has_name) { 1615 1748 /* We'll build a hash just containing the name, then give this to 1616 1749 * init_class_from_hash - saves some code duplication. */ 1617 PMC * const naming_hash = pmc_new( interp, enum_class_Hash);1618 STRING * const name_str = CONST_STRING( interp, "name");1750 PMC * const naming_hash = pmc_new(INTERP, enum_class_Hash); 1751 STRING * const name_str = CONST_STRING(INTERP, "name"); 1619 1752 1620 VTABLE_set_string_keyed_str( interp, naming_hash, name_str, name);1621 init_class_from_hash( interp, SELF, naming_hash);1753 VTABLE_set_string_keyed_str(INTERP, naming_hash, name_str, name); 1754 init_class_from_hash(INTERP, SELF, naming_hash); 1622 1755 } 1623 1756 1624 ret_name = _class->name; 1757 GET_ATTR_name(INTERP, SELF, ret_name); 1758 1625 1759 RETURN(STRING *ret_name); 1626 1760 } 1627 1761 … … 1635 1769 1636 1770 */ 1637 1771 METHOD get_namespace(PMC *_namespace :optional, int has_name :opt_flag) { 1638 P arrot_Class_attributes * const _class = PARROT_CLASS(SELF);1639 PMC * const ret_namespace = _class->_namespace; 1772 PMC * ret_namespace; 1773 1640 1774 UNUSED(_namespace); 1641 1775 UNUSED(has_name); 1776 1777 GET_ATTR__namespace(INTERP, SELF, ret_namespace); 1778 1642 1779 RETURN(PMC *ret_namespace); 1643 1780 } 1644 1781 … … 1653 1790 1654 1791 */ 1655 1792 METHOD resolve_method(PMC *resolve_list :optional, int has_list :opt_flag) { 1656 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF);1657 1793 PMC *ret_list; 1658 1794 1659 1795 /* Store list. */ 1660 1796 if (has_list) 1661 _class->resolve_method = resolve_list;1797 SET_ATTR_resolve_method(INTERP, SELF, resolve_list); 1662 1798 1663 ret_list = _class->resolve_method; 1799 GET_ATTR_resolve_method(INTERP, SELF, ret_list); 1800 1664 1801 RETURN(PMC *ret_list); 1665 1802 } 1666 1803 … … 1678 1815 /* Check if any arguments are in the slurpy hash, don't pass an empty 1679 1816 * hash to instantiate */ 1680 1817 PMC * const obj = 1681 VTABLE_elements( interp, args) > 01682 ? VTABLE_instantiate( interp, SELF, args)1683 : VTABLE_instantiate( interp, SELF, PMCNULL);1818 VTABLE_elements(INTERP, args) > 0 1819 ? VTABLE_instantiate(INTERP, SELF, args) 1820 : VTABLE_instantiate(INTERP, SELF, PMCNULL); 1684 1821 1685 1822 RETURN(PMC *obj); 1686 1823 } … … 1696 1833 1697 1834 */ 1698 1835 METHOD attributes() { 1699 STRING * const attr_str = CONST_STRING( interp, "attributes");1836 STRING * const attr_str = CONST_STRING(INTERP, "attributes"); 1700 1837 PMC * const ret_attrib_metadata = SELF.inspect_str(attr_str); 1701 1838 1702 1839 RETURN(PMC *ret_attrib_metadata); … … 1727 1864 1728 1865 */ 1729 1866 METHOD methods() { 1730 PMC * const ret_methods = SELF.inspect_str(CONST_STRING( interp, "methods"));1867 PMC * const ret_methods = SELF.inspect_str(CONST_STRING(INTERP, "methods")); 1731 1868 1732 1869 RETURN(PMC *ret_methods); 1733 1870 } … … 1757 1894 1758 1895 */ 1759 1896 METHOD add_vtable_override(STRING *name, PMC *sub) { 1760 VTABLE_add_vtable_override(interp, SELF,name, sub);1897 SELF.add_vtable_override(name, sub); 1761 1898 } 1762 1899 1763 1900 /* … … 1770 1907 1771 1908 */ 1772 1909 METHOD remove_method(STRING *name) { 1773 VTABLE_remove_method(interp, SELF,name);1910 SELF.remove_method(name); 1774 1911 } 1775 1912 1776 1913 /* … … 1784 1921 */ 1785 1922 1786 1923 METHOD find_method(STRING *name) { 1787 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF);1788 int i;1924 int i, num_classes; 1925 PMC *all_parents; 1789 1926 1927 GET_ATTR_all_parents(INTERP, SELF , all_parents); 1928 1790 1929 /* Walk and search. One day, we'll use the cache first. */ 1791 const int num_classes = VTABLE_elements(interp, _class->all_parents);1930 num_classes = VTABLE_elements(INTERP, all_parents); 1792 1931 1793 1932 for (i = 0; i < num_classes; i++) { 1933 PMC *methods; 1934 1794 1935 /* Get the class and see if it has the method. */ 1795 1936 PMC * const cur_class = 1796 VTABLE_get_pmc_keyed_int(interp, _class->all_parents, i); 1797 const Parrot_Class_attributes * const class_info = PARROT_CLASS(cur_class); 1937 VTABLE_get_pmc_keyed_int(INTERP, all_parents, i); 1798 1938 1939 GET_ATTR_methods(INTERP, cur_class, methods); 1940 1799 1941 /* Found it! */ 1800 if (VTABLE_exists_keyed_str( interp, class_info->methods, name)) {1801 PMC * const ret = VTABLE_get_pmc_keyed_str( interp, class_info->methods, name);1942 if (VTABLE_exists_keyed_str(INTERP, methods, name)) { 1943 PMC * const ret = VTABLE_get_pmc_keyed_str(INTERP, methods, name); 1802 1944 RETURN(PMC *ret); 1803 1945 } 1804 1946 } … … 1816 1958 1817 1959 */ 1818 1960 METHOD parents() { 1819 PMC * const ret_parents = SELF.inspect_str(CONST_STRING( interp, "parents"));1961 PMC * const ret_parents = SELF.inspect_str(CONST_STRING(INTERP, "parents")); 1820 1962 1821 1963 RETURN(PMC *ret_parents); 1822 1964 } … … 1844 1986 1845 1987 */ 1846 1988 METHOD roles() { 1847 PMC * const ret_roles = SELF.inspect_str(CONST_STRING( interp, "roles"));1989 PMC * const ret_roles = SELF.inspect_str(CONST_STRING(INTERP, "roles")); 1848 1990 1849 1991 RETURN(PMC *ret_roles); 1850 1992 } … … 1860 2002 1861 2003 */ 1862 2004 METHOD add_role(PMC *role, 1863 PMC *exclude_method :optional :named("exclude_method"), 1864 int has_exclude_method :opt_flag, 1865 PMC *alias_method :optional :named("alias_method"), 1866 int has_alias_method :opt_flag) { 2005 PMC *exclude_method :optional :named("exclude_method"), 2006 int has_exclude_method :opt_flag, 2007 PMC *alias_method :optional :named("alias_method"), 2008 int has_alias_method :opt_flag) { 2009 PMC *resolve_method, *methods, *roles; 1867 2010 1868 Parrot_Class_attributes * const _class = PARROT_CLASS(SELF); 2011 GET_ATTR_resolve_method(INTERP, SELF, resolve_method); 2012 GET_ATTR_methods(INTERP, SELF, methods); 2013 GET_ATTR_roles(INTERP, SELF, roles); 1869 2014 1870 2015 /* Add everything on the resolve list to the exclude list; if we have 1871 2016 * no exclude list, pass along the resolve list in its place if it has 1872 2017 * any methods listed in it. */ 1873 2018 if (!has_exclude_method) { 1874 if (VTABLE_elements( interp, _class->resolve_method) != 0) {1875 exclude_method = _class->resolve_method;2019 if (VTABLE_elements(INTERP, resolve_method) != 0) { 2020 exclude_method = resolve_method; 1876 2021 has_exclude_method = 1; 1877 2022 } 1878 2023 } 1879 2024 else { 1880 const int resolve_count = VTABLE_elements( interp, _class->resolve_method);2025 const int resolve_count = VTABLE_elements(INTERP, resolve_method); 1881 2026 int i; 1882 2027 1883 2028 for (i = 0; i < resolve_count; i++) { 1884 STRING * const meth_name = VTABLE_get_string_keyed_int( interp,1885 _class->resolve_method, i);1886 VTABLE_push_string( interp, exclude_method, meth_name);2029 STRING * const meth_name = VTABLE_get_string_keyed_int(INTERP, 2030 resolve_method, i); 2031 VTABLE_push_string(INTERP, exclude_method, meth_name); 1887 2032 } 1888 2033 } 1889 2034 1890 2035 /* Do the composition. */ 1891 Parrot_ComposeRole(interp, role, exclude_method, has_exclude_method, 1892 alias_method, has_alias_method, 1893 _class->methods, _class->roles); 2036 Parrot_ComposeRole(INTERP, role, exclude_method, has_exclude_method, 2037 alias_method, has_alias_method, methods, roles); 1894 2038 } 1895 2039 1896 2040 /* … … 1942 2086 1943 2087 */ 1944 2088 METHOD does(STRING *role_name) { 1945 const INTVAL does = VTABLE_does( interp, SELF, role_name);2089 const INTVAL does = VTABLE_does(INTERP, SELF, role_name); 1946 2090 RETURN(INTVAL does); 1947 2091 } 1948 2092