NAME ^

objects.c - Class and object

DESCRIPTION ^

Handles class and object manipulation.

Functions ^

INTVAL Parrot_get_vtable_index(Interp *, STRING *name)

Return index if name is a valid vtable slot name.

static PMC *find_vtable_meth_ns(Interp *interp, PMC *ns, INTVAL vtable_index)

Return sub PMC if a method with the vtable name exists in ns

PMC *Parrot_find_vtable_meth(Interp *interp, PMC *pmc, STRING *meth)

Given pmc, run through its mro looking for the meth vtable method Return the vtable method PMC if found

STRING *readable_name(Interp *interp, PMC *name)

Given a String or Key PMC return the STRING* representation

static void fail_if_exist(Interp *interp, PMC *name)

Throws an exception if a PMC or class with the same name already exists.

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, 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

PMC *Parrot_ComputeMRO_C3(Interp *interp, PMC *_class)

Computes the C3 linearization for the given class.

void Parrot_ComposeRole(Interp *interp, PMC *role, PMC *exclude, int got_exclude, PMC *alias, int got_alias, PMC *methods_hash, PMC *roles_list)

Used by the Class and Object PMCs internally to compose a role into either of them. The role parameter is the role that we are composing into the class or role. methods_hash is the hash of method names to invokable PMCs that contains the methods the class or role has. roles_list is the list of roles the the class or method does.

The role parameter is only dealt with by its external interface. Whether this routine is usable by any other object system implemented in Parrot very much depends on how closely the role composition semantics they want are to the default implementation.

SEE ALSO ^

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


parrot