NAME ^

objects.c - Class and object

DESCRIPTION ^

Handles class and object manipulation.

Functions ^

PARROT_API INTVAL Parrot_get_vtable_index(PARROT_INTERP, NOTNULL(const STRING *name))

Return index if name is a valid vtable slot name.

PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL static PMC *find_vtable_meth_ns(PARROT_INTERP, NOTNULL(PMC *ns), INTVAL vtable_index)

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

PARROT_API PARROT_CAN_RETURN_NULL PMC *Parrot_find_vtable_meth(PARROT_INTERP, NOTNULL(PMC *pmc), NOTNULL(STRING *meth))

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

PARROT_API PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL STRING *readable_name(PARROT_INTERP, NOTNULL(PMC *name))

Given a String or Key PMC return the STRING* representation

RT#45967 this function, key_set_to_string, and the key PMC get_repr should be consolidated

static void fail_if_exist(PARROT_INTERP, NOTNULL(PMC *name))

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

RT#45969 uses global class registry

static void rebuild_attrib_stuff(PARROT_INTERP, NOTNULL(PMC *_class))

Take the class and completely rebuild the attribute stuff for it. Horribly destructive, and definitely not a good thing to do if there are instantiated objects for the class

static void create_deleg_pmc_vtable(PARROT_INTERP, NOTNULL(PMC *_class), 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.

PARROT_API PARROT_PURE_FUNCTION PARROT_CAN_RETURN_NULL const char *Parrot_MMD_method_name(SHIM_INTERP, INTVAL idx)

Return the method name for the given MMD enum.

PARROT_API PARROT_PURE_FUNCTION INTVAL Parrot_MMD_method_idx(SHIM_INTERP, NOTNULL(const char *name))

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

RT#45973 allow dynamic expansion at runtime.

PARROT_API PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL PMC *Parrot_single_subclass(PARROT_INTERP, NOTNULL(PMC *base_class), NULLOK(PMC *name))

Subclass a class. Single parent class, nice and straightforward. If child_class is NULL, this is an anonymous subclass we're creating, function.

PARROT_API void Parrot_new_class(PARROT_INTERP, NOTNULL(PMC *_class), NOTNULL(PMC *name))

Creates a new class, named class_name.

PARROT_API PARROT_CAN_RETURN_NULL PARROT_WARN_UNUSED_RESULT PMC *Parrot_class_lookup(PARROT_INTERP, NOTNULL(STRING *class_name))

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

PARROT_CAN_RETURN_NULL PARROT_WARN_UNUSED_RESULT PMC *Parrot_class_lookup_p(PARROT_INTERP, NOTNULL(PMC *class_name))

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

PARROT_WARN_UNUSED_RESULT static INTVAL register_type(PARROT_INTERP, NOTNULL(PMC *name))

TODO: Not yet documented!!!

static void parrot_class_register(PARROT_INTERP, NOTNULL(PMC *name), NOTNULL(PMC *new_class), NULLOK(PMC *parent), NOTNULL(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.

PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL static PMC *get_init_meth(PARROT_INTERP, NOTNULL(PMC *_class), NOTNULL(STRING *prop_str), NOTNULL(STRING **meth_str))

TODO: Not yet documented!!!

static void do_initcall(PARROT_INTERP, NULLOK(PMC *_class), NULLOK(PMC *object), NULLOK(PMC *init))

TODO: Not yet documented!!!

PARROT_API void Parrot_instantiate_object_init(PARROT_INTERP, NOTNULL(PMC *object), NOTNULL(PMC *init))

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

PARROT_API void Parrot_instantiate_object(PARROT_INTERP, NOTNULL(PMC *object))

TODO: Not yet documented!!!

static void instantiate_object(PARROT_INTERP, NOTNULL(PMC *object), NULLOK(PMC *init))

TODO: Not yet documented!!!

PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL static PMC *not_empty(PARROT_INTERP, NOTNULL(PMC *seqs))

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

PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL static PMC *class_mro_merge(PARROT_INTERP, NOTNULL(PMC *seqs))

merge the list if lists

PARROT_WARN_UNUSED_RESULT PARROT_CANNOT_RETURN_NULL static PMC *create_class_mro(PARROT_INTERP, NOTNULL(PMC *_class))

create C3 MRO

PARROT_API PARROT_IGNORABLE_RESULT PARROT_CAN_RETURN_NULL PMC *Parrot_remove_parent(PARROT_INTERP, NOTNULL(PMC *removed_class), NOTNULL(PMC *existing_class))

This currently does nothing but return PMCNULL.

PARROT_API PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL PMC *Parrot_multi_subclass(PARROT_INTERP, NOTNULL(PMC *base_class_array), NOTNULL(STRING *child_class_name))

This currently does nothing but return PMCNULL.

PARROT_API PARROT_WARN_UNUSED_RESULT INTVAL Parrot_object_isa(PARROT_INTERP, NOTNULL(PMC *pmc), NOTNULL(PMC *_class))

Returns whether the object pmc is an instance of class _class.

PARROT_API PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL PMC *Parrot_new_method_cache(PARROT_INTERP)

This should create and return a new method cache PMC.

Currently it does nothing but return PMCNULL.

void mark_object_cache(PARROT_INTERP)

TODO: Not yet documented!!!

void init_object_cache(PARROT_INTERP)

TODO: Not yet documented!!!

void destroy_object_cache(PARROT_INTERP)

TODO: Not yet documented!!!

static void invalidate_type_caches(PARROT_INTERP, UINTVAL type)

TODO: Not yet documented!!!

static void invalidate_all_caches(PARROT_INTERP)

TODO: Not yet documented!!!

PARROT_API void Parrot_invalidate_method_cache(PARROT_INTERP, NULLOK(STRING *_class), NOTNULL(STRING *meth))

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

PARROT_API PARROT_CAN_RETURN_NULL PARROT_WARN_UNUSED_RESULT PMC *Parrot_find_method_direct(PARROT_INTERP, NOTNULL(PMC *_class), NOTNULL(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.

PARROT_API PARROT_CAN_RETURN_NULL PARROT_WARN_UNUSED_RESULT PMC *Parrot_find_method_with_cache(PARROT_INTERP, NOTNULL(PMC *_class), NOTNULL(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.

static void debug_trace_find_meth(PARROT_INTERP, NOTNULL(PMC *_class), NOTNULL(STRING *name), NULLOK(PMC *sub))

TODO: Not yet documented!!!

PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL static PMC *find_method_direct_1(PARROT_INTERP, NOTNULL(PMC *_class), NOTNULL(STRING *method_name))

TODO: Not yet documented!!!

PARROT_API void Parrot_note_method_offset(PARROT_INTERP, UINTVAL offset, NOTNULL(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.

PARROT_API INTVAL Parrot_add_attribute(PARROT_INTERP, NOTNULL(PMC *_class), NOTNULL(STRING *attr))

Adds the attribute attr to the class.

   Life is ever so much easier if a class keeps its attributes at the
   end of the attribute array, since we don't have to insert and
   reorder attributes. Inserting's no big deal, especially since we're
   going to break horribly if you insert into a class that's been
   subclassed, but it'll do for now.
PARROT_API PARROT_CAN_RETURN_NULL PARROT_WARN_UNUSED_RESULT PMC *Parrot_get_attrib_by_num(PARROT_INTERP, NOTNULL(PMC *object), INTVAL attrib)

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

static INTVAL attr_str_2_num(PARROT_INTERP, NOTNULL(PMC *object), NOTNULL(STRING *attr))

TODO: Not yet documented!!!

PARROT_API PARROT_CAN_RETURN_NULL PARROT_WARN_UNUSED_RESULT PMC *Parrot_get_attrib_by_str(PARROT_INTERP, NOTNULL(PMC *object), NOTNULL(STRING *attr))

Returns attribute with full qualified name attr from object.

PARROT_API void Parrot_set_attrib_by_num(PARROT_INTERP, NOTNULL(PMC *object), INTVAL attrib, NOTNULL(PMC *value))

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

PARROT_API void Parrot_set_attrib_by_str(PARROT_INTERP, NOTNULL(PMC *object), NOTNULL(STRING *attr), NOTNULL(PMC *value))

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

PARROT_API INTVAL Parrot_class_offset(PARROT_INTERP, NOTNULL(PMC *object), NOTNULL(STRING *_class))

TODO: Not yet documented!!!

PARROT_API PARROT_CAN_RETURN_NULL PMC *Parrot_find_class_constructor(PARROT_INTERP, NOTNULL(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).

PARROT_API PARROT_CAN_RETURN_NULL PMC *Parrot_find_class_destructor(PARROT_INTERP, NOTNULL(STRING *_class), INTVAL classtoken)

TODO: Not yet documented!!!

PARROT_API PARROT_CAN_RETURN_NULL PMC *Parrot_find_class_fallback(PARROT_INTERP, NOTNULL(STRING *_class), INTVAL classtoken)

TODO: Not yet documented!!!

PARROT_API void Parrot_set_class_constructor(PARROT_INTERP, NOTNULL(STRING *_class), INTVAL classtoken, NOTNULL(STRING *method))

TODO: Not yet documented!!!

PARROT_API void Parrot_set_class_destructor(PARROT_INTERP, NOTNULL(STRING *_class), INTVAL classtoken, NOTNULL(STRING *method))

TODO: Not yet documented!!!

PARROT_API void Parrot_set_class_fallback(PARROT_INTERP, NOTNULL(STRING *_class), INTVAL classtoken, NOTNULL(STRING *method))

TODO: Not yet documented!!!

PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL static PMC *C3_merge(PARROT_INTERP, NOTNULL(PMC *merge_list))

TODO: Not yet documented!!!

PARROT_API PARROT_WARN_UNUSED_RESULT PARROT_CAN_RETURN_NULL PMC *Parrot_ComputeMRO_C3(PARROT_INTERP, NOTNULL(PMC *_class))

Computes the C3 linearization for the given class.

PARROT_API void Parrot_ComposeRole(PARROT_INTERP, NOTNULL(PMC *role), NOTNULL(PMC *exclude), int got_exclude, NOTNULL(PMC *alias), int got_alias, NOTNULL(PMC *methods_hash), NOTNULL(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