NAME ^

objects.c - Class and object

DESCRIPTION ^

Handles class and object manipulation.

Functions ^

int Parrot_get_vtable_index(Interp *, const char *name)

Return index if name is a valid vtable slot name.

static PMC *find_vtable_override_byname(Interp *interp, PMC *class, STRING *method_name)

Tries to locate a PIR override method for the given v-table method in the given class. If one is found, returns the method.

static void create_deleg_pmc_vtable(Interp *, PMC *class, PMC *class_name, int full)

Create a vtable that dispatches either to the contained PMC in the first attribute (deleg_pmc) or to an overridden method (delegate), depending on the existence of the method for this class.

const char *Parrot_MMD_method_name(Interp*, INTVAL)

Return the method name for the given MMD enum.

INTVAL Parrot_MMD_method_idx(Interp*, STRING *)

Return the MMD function number for method name or -1 on failure.

TODO allow dynamic expansion at runtime.

PMC *Parrot_single_subclass(Interp *interp, PMC *base_class, PMC *child_class_name)

Subclass a class. Single parent class, nice and straightforward. If child_class is NULL, this is an anonymous subclass we're creating, which happens commonly enough to warrant an actual single-subclass function.

void Parrot_new_class(Interp *interp, PMC *class, PMC *class_name)

Creates a new class, named class_name.

PMC *Parrot_class_lookup(Interp *interp, STRING *class_name)

PMC *Parrot_class_lookup_p(Interp *interp, PMC *class_name)

Looks for the class named class_name and returns it if it exists. Otherwise it returns PMCNULL.

static void parrot_class_register(Interp *interp, PMC *class_name, PMC *new_class, PMC *mro)

This is the way to register a new Parrot class as an instantiable type. Doing this involves putting it in the class hash, setting its vtable so that the init method initializes objects of the class rather than the class itself, and adding it to the interpreter's base type table so you can create a new foo in PASM like this: new Px, foo.

void Parrot_instantiate_object(Interp *interp, PMC *object, PMC *init)

Creates a Parrot object. Takes a passed-in class PMC that has sufficient information to describe the layout of the object and, well, makes the darned object.

PMC *Parrot_add_parent(Interp *interp, PMC *class, PMC *parent)

Add the parent class to the current class' parent list. This also involved adding all the parent's parents, as well as all attributes of the parent classes that we're adding in.

The MRO (method resolution order) is the C3 algorithm used by Perl6 and Python (>= 2.3). See also: http://pugs.blogs.com/pugs/2005/07/day_165_r5671_j.html

PMC *Parrot_remove_parent(Interp *interp, PMC *removed_class, PMC *existing_class)

This currently does nothing but return NULL.

PMC *Parrot_multi_subclass(Interp *interp, PMC *base_class_array, STRING *child_class_name)

This currently does nothing but return NULL.

INTVAL Parrot_object_isa(Interp *interp, PMC *pmc, PMC *cl)

Return whether the object pmc is an instance of class cl.

PMC *Parrot_new_method_cache(Interp *interp)

This should create and return a new method cache PMC.

Currently it does nothing but return NULL.

PMC *Parrot_find_method_with_cache(Interp *interp, PMC *class, STRING *method_name)

Find a method PMC for a named method, given the class PMC, current interp, and name of the method.

This routine should use the current scope's method cache, if there is one. If not, it creates a new method cache. Or, rather, it will when we've got that bit working. For now it unconditionally goes and looks up the name in the global stash.

PMC *Parrot_find_method_direct(Interp *interp, PMC *class, STRING *method_name)

Find a method PMC for a named method, given the class PMC, current interpreter, and name of the method. Don't use a possible method cache.

void Parrot_invalidate_method_cache(Interp *, STRING *class)

Clear method cache for the given class. If class is NULL caches for all classes are invalidated.

void Parrot_note_method_offset(Interp *interp, UINTVAL offset, PMC *method)

Notes where in the hierarchy we just found a method. Used so that we can do a next and continue the search through the hierarchy for the next instance of this method.

*/ void Parrot_note_method_offset(Interp *interp, UINTVAL offset, PMC *method) { }

/*

INTVAL Parrot_add_attribute(Interp *interp, PMC *class, STRING *attr)

Adds the attribute attr to the class.

PMC *Parrot_get_attrib_by_num(Interp *interp, PMC *object, INTVAL attrib)

Returns attribute number attrib from object. Presumably the code is asking for the correct attribute number.

PMC *Parrot_get_attrib_by_str(Interp *interp, PMC *object, STRING *attr)

Returns attribute with full qualified name attr from object.

PMC *Parrot_set_attrib_by_num(Interp *interp, PMC *object, INTVAL attrib, PMC *value)

Set attribute number attrib from object to value. Presumably the code is asking for the correct attribute number.

PMC *Parrot_set_attrib_by_str(Interp *interp, PMC *object, STRING *attr, PMC *value)

Sets attribute with full qualified name attr from object to value.

PMC *Parrot_find_class_constructor(Interp *interp, STRING *class, INTVAL classtoken)

Find and return the constructor method PMC for the named sub. The classtoken is an identifier for the class used for fast lookup, or 0 if you don't have an identifier token. Which, as they're currently undefined, is pretty likely

SEE ALSO ^

include/parrot/objects.h, docs/pdds/pdd15_objects.pod.


parrot