NAME ^

src/pmc/parrotobject.pmc - Parrot Object

DESCRIPTION ^

A Parrot Object is reasonably simple. Its data pointer points to an array with the attributes of the object in it. The int cache value holds the attribute count of this instance.

The object is actually constructed by the instantiation code in src/objects.c, at least for right now.

Methods ^

void init()

Raises an exception to make sure all users call new on the registered class PMC and not the ParrotObject itself.

During Parrot_class_register() this init() method gets replaced by Parrot_instantiate_object().

void destroy()

Call the '__finalize' method if it exists and destruct the object.

XXX Finalization from within the destroy method is of course wrong. The finalization code could resurrect the object, by e.g. storing it into some structure. But as destruction is also done in this step, the stored object is unusable (in best case) or even recycled to a new PMC. All access to such a zombie would be really interesting.

TODO

  - create a tobe_finalized list in the GC
  - don't destroy these objects immediately
  - create a dedicated finalize vtable
  - run the finalization code after GC has finished
  - run all finalizers in MRO order
  - postpone destruction to the next GC cycle
STRING *name()

Shortcut for .class().name()

XXX - this is bad and should go

PMC *find_method(STRING *name)

Finds the method for *name.

PMC *get_attr(INTVAL idx)

Return attribute number idx.

PMC *get_attr_str(STRING *name)

Return attribute named name.

void set_attr(INTVAL idx, PMC *val)

Set attribute number idx.

void set_attr_str(STRING *name, PMC *val)

Set attribute named name.

PMC *get_class()

Return the class of this object.

INTVAL get_integer_keyed_int(INTVAL key)

FLOATVAL get_number_keyed_int(INTVAL key)

STRING *get_string_keyed_int(INTVAL key)

PMC *get_pmc_keyed_int(INTVAL key)

void set_integer_keyed_int (INTVAL key, INTVAL value)

void set_number_keyed_int (INTVAL key, FLOATVAL value)

void set_string_keyed_int (INTVAL key, STRING *value)

void set_pmc_keyed_int (INTVAL key, PMC *value)

void delete_keyed_int(INTVAL key)

INTVAL defined_keyed_int(INTVAL key)

INTVAL exists_keyed_int(INTVAL key)

These methods have default implementations in src/pmc/default.pmc which redirect to PMC keys. Test if a specialized method exists, else use fallback.

If the parent isa PMC, the fallback is the deleg_pmc method, else it's just SUPER aka the default implementation.

void visit(visit_info *info)

This is used by freeze/thaw to visit the contents of the object.

*info is the visit info, (see include/parrot/pmc_freeze.h).

void freeze(visit_info *info)

Used to archive the object.

void thaw(visit_info *info)

Used to unarchive the object.

void thawfinish(visit_info *info)


parrot