[svn:parrot] r47817 - trunk/src/pmc
chromatic at svn.parrot.org
chromatic at svn.parrot.org
Fri Jun 25 03:14:30 UTC 2010
Author: chromatic
Date: Fri Jun 25 03:14:30 2010
New Revision: 47817
URL: https://trac.parrot.org/parrot/changeset/47817
Log:
[PMC] Tidied Object PMC; no functional changes.
Modified:
trunk/src/pmc/object.pmc
Modified: trunk/src/pmc/object.pmc
==============================================================================
--- trunk/src/pmc/object.pmc Fri Jun 25 03:14:05 2010 (r47816)
+++ trunk/src/pmc/object.pmc Fri Jun 25 03:14:30 2010 (r47817)
@@ -103,7 +103,7 @@
/* there's a semi-predicate problem with a retval of 0 */
if (retval
- || VTABLE_exists_keyed_str(interp, _class->attrib_cache, name)) {
+ || VTABLE_exists_keyed_str(interp, _class->attrib_cache, name)) {
Parrot_pcc_set_HLL(interp, CURRENT_CONTEXT(interp), cur_hll);
return retval;
}
@@ -138,6 +138,7 @@
return -1;
}
+
/* This variation bypasses the cache and finds the index of a particular
* parent's attribute in an object's attribute store and returns it. Returns -1
* if the attribute does not exist. */
@@ -148,8 +149,10 @@
{
ASSERT_ARGS(get_attrib_index_keyed)
Parrot_Class_attributes * const _class = PARROT_CLASS(self);
- PMC * const class_cache = VTABLE_get_pmc_keyed_str(interp,
- _class->attrib_cache, VTABLE_get_string(interp, key));
+ PMC * const class_cache =
+ VTABLE_get_pmc_keyed_str(interp, _class->attrib_cache,
+ VTABLE_get_string(interp, key));
+
PMC *parent_class;
STRING *fq_name;
@@ -173,6 +176,7 @@
return -1;
}
+
PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
static PMC *
@@ -188,8 +192,10 @@
return VTABLE_get_pmc_keyed_str(interp, cache, name);
}
+
static void
-cache_method(PARROT_INTERP, ARGIN(PMC *_class), ARGIN(STRING *name), ARGIN(PMC *method))
+cache_method(PARROT_INTERP, ARGIN(PMC *_class), ARGIN(STRING *name),
+ARGIN(PMC *method))
{
ASSERT_ARGS(cache_method)
PMC *cache;
@@ -207,6 +213,7 @@
ATTR PMC *_class; /* The class this is an instance of. */
ATTR PMC *attrib_store; /* The attributes store - a resizable PMC array. */
+
/*
=item C<void init()>
@@ -238,6 +245,7 @@
"Object must be created by a class.");
}
+
/*
=item C<void destroy()>
@@ -250,6 +258,7 @@
VTABLE void destroy() {
}
+
/*
=item C<STRING *name()>
@@ -265,7 +274,8 @@
STRING * const name = CONST_STRING(INTERP, "name");
/* If there's a vtable override for 'name' run that instead. */
- PMC * const method = Parrot_oo_find_vtable_override(INTERP, _class, name);
+ PMC * const method = Parrot_oo_find_vtable_override(INTERP,
+ _class, name);
if (!PMC_IS_NULL(method)) {
STRING *result = NULL;
@@ -277,6 +287,7 @@
return VTABLE_get_string(INTERP, _class);
}
+
/*
=item C<void mark()>
@@ -295,6 +306,7 @@
}
}
+
/*
=item C<PMC *get_attr_str(STRING *name)>
@@ -307,7 +319,8 @@
*/
VTABLE PMC *get_attr_str(STRING *name) {
Parrot_Object_attributes * const obj = PARROT_OBJECT(SELF);
- STRING * const get_attr = CONST_STRING(INTERP, "get_attr_str");
+ STRING * const get_attr = CONST_STRING(INTERP, "get_attr_str");
+
INTVAL index;
/* If there's a vtable override for 'get_attr_str' run that first. */
@@ -326,12 +339,13 @@
/* If lookup failed, exception. */
if (index == -1)
- Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ATTRIB_NOT_FOUND,
- "No such attribute '%S'", name);
+ Parrot_ex_throw_from_c_args(INTERP, NULL,
+ EXCEPTION_ATTRIB_NOT_FOUND, "No such attribute '%S'", name);
return VTABLE_get_pmc_keyed_int(INTERP, obj->attrib_store, index);
}
+
/*
=item C<PMC *get_attr_keyed(PMC *key, STRING *name)>
@@ -346,17 +360,20 @@
Parrot_Object_attributes * const obj = PARROT_OBJECT(SELF);
/* Look up the index. */
- const INTVAL index = get_attrib_index_keyed(INTERP, obj->_class, key, name);
+ const INTVAL index = get_attrib_index_keyed(INTERP, obj->_class,
+ key, name);
/* If lookup failed, exception. */
if (index == -1)
- Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ATTRIB_NOT_FOUND,
+ Parrot_ex_throw_from_c_args(INTERP, NULL,
+ EXCEPTION_ATTRIB_NOT_FOUND,
"No such attribute '%S' in class '%S'", name,
VTABLE_get_string(INTERP, key));
return VTABLE_get_pmc_keyed_int(INTERP, obj->attrib_store, index);
}
+
/*
=item C<void set_attr_str(STRING *name, PMC *value)>
@@ -368,13 +385,14 @@
*/
VTABLE void set_attr_str(STRING *name, PMC *value) {
- Parrot_Object_attributes * const obj = PARROT_OBJECT(SELF);
- STRING * const vtable_meth_name = CONST_STRING(INTERP, "set_attr_str");
+ Parrot_Object_attributes * const obj = PARROT_OBJECT(SELF);
+ STRING * const vtable_meth_name = CONST_STRING(INTERP, "set_attr_str");
INTVAL index;
/* If there's a vtable override for 'set_attr_str' run that first. */
PMC * const method = Parrot_oo_find_vtable_override(INTERP,
VTABLE_get_class(INTERP, SELF), vtable_meth_name);
+
if (!PMC_IS_NULL(method)) {
Parrot_pcc_invoke_sub_from_c_args(INTERP, method, "PiSP->",
SELF, name, value);
@@ -385,12 +403,13 @@
/* If lookup failed, exception. */
if (index == -1)
- Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ATTRIB_NOT_FOUND,
- "No such attribute '%S'", name);
+ Parrot_ex_throw_from_c_args(INTERP, NULL,
+ EXCEPTION_ATTRIB_NOT_FOUND, "No such attribute '%S'", name);
VTABLE_set_pmc_keyed_int(INTERP, obj->attrib_store, index, value);
}
+
/*
=item C<void set_attr_keyed(PMC *key, STRING *name, PMC *value)>
@@ -402,18 +421,21 @@
*/
VTABLE void set_attr_keyed(PMC *key, STRING *name, PMC *value) {
- Parrot_Object_attributes * const obj = PARROT_OBJECT(SELF);
- const INTVAL index = get_attrib_index_keyed(INTERP, obj->_class, key, name);
+ Parrot_Object_attributes * const obj = PARROT_OBJECT(SELF);
+ const INTVAL index =
+ get_attrib_index_keyed(INTERP, obj->_class, key, name);
/* If lookup failed, exception. */
if (index == -1)
- Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ATTRIB_NOT_FOUND,
+ Parrot_ex_throw_from_c_args(INTERP, NULL,
+ EXCEPTION_ATTRIB_NOT_FOUND,
"No such attribute '%S' in class '%S'", name,
VTABLE_get_string(INTERP, key));
VTABLE_set_pmc_keyed_int(INTERP, obj->attrib_store, index, value);
}
+
/*
=item C<PMC *find_method(STRING *name)>
@@ -426,7 +448,8 @@
VTABLE PMC *find_method(STRING *name) {
Parrot_Object_attributes * const obj = PARROT_OBJECT(SELF);
Parrot_Class_attributes * const _class = PARROT_CLASS(obj->_class);
- PMC *method = find_cached(INTERP, obj->_class, name);
+ PMC *method =
+ find_cached(INTERP, obj->_class, name);
if (!PMC_IS_NULL(method))
return method;
@@ -486,6 +509,7 @@
}
}
+
/*
=item C<INTVAL get_integer()>
@@ -498,37 +522,42 @@
VTABLE INTVAL get_integer() {
Parrot_Object_attributes * const obj = PARROT_OBJECT(SELF);
Parrot_Class_attributes * const _class = PARROT_CLASS(obj->_class);
- STRING * const meth_name = CONST_STRING(INTERP, "get_integer");
+ STRING * const meth_name = CONST_STRING(INTERP, "get_integer");
/* Walk and search for the vtable. */
const int num_classes = VTABLE_elements(INTERP, _class->all_parents);
- int i;
+ int i;
+
for (i = 0; i < num_classes; i++) {
/* Get the class. */
- PMC * const cur_class = VTABLE_get_pmc_keyed_int(INTERP, _class->all_parents, i);
+ PMC * const cur_class =
+ VTABLE_get_pmc_keyed_int(INTERP, _class->all_parents, i);
PMC * const meth = Parrot_oo_find_vtable_override_for_class(INTERP,
cur_class, meth_name);
+
if (!PMC_IS_NULL(meth)) {
INTVAL result;
- Parrot_pcc_invoke_sub_from_c_args(INTERP, meth, "Pi->I", SELF, &result);
+ Parrot_pcc_invoke_sub_from_c_args(INTERP, meth, "Pi->I",
+ SELF, &result);
return result;
}
+
if (cur_class->vtable->base_type == enum_class_PMCProxy) {
/* Get the PMC instance and call the vtable function on that. */
STRING * const proxy = CONST_STRING(INTERP, "proxy");
- PMC * const del_object = VTABLE_get_attr_str(INTERP, SELF, proxy);
+ PMC * const del_object =
+ VTABLE_get_attr_str(INTERP, SELF, proxy);
- if (!PMC_IS_NULL(del_object)) {
+ if (!PMC_IS_NULL(del_object))
return (INTVAL)VTABLE_get_integer(INTERP, del_object);
-
- }
}
}
return INTERP->vtables[enum_class_default]->get_integer(INTERP, SELF);
}
+
/*
=item C<PMC *get_class()>
@@ -541,8 +570,9 @@
VTABLE PMC *get_class() {
PMC * const classobj = PARROT_OBJECT(SELF)->_class;
STRING * const get_class = CONST_STRING(INTERP, "get_class");
+
/* If there's a vtable override for 'get_class' run that instead. */
- PMC * const method = Parrot_oo_find_vtable_override(INTERP,
+ PMC * const method = Parrot_oo_find_vtable_override(INTERP,
classobj, get_class);
if (!PMC_IS_NULL(method)) {
@@ -555,6 +585,7 @@
return classobj;
}
+
/*
=item C<PMC *get_namespace()>
@@ -568,8 +599,9 @@
VTABLE PMC *get_namespace() {
PMC * const classobj = VTABLE_get_class(INTERP, SELF);
STRING * const get_namespace = CONST_STRING(INTERP, "get_namespace");
- /* If there's a vtable override for 'get_namespace' run that instead. */
- PMC * const method = Parrot_oo_find_vtable_override(INTERP,
+
+ /* If there's a vtable override for 'get_namespace' run that instead */
+ PMC * const method = Parrot_oo_find_vtable_override(INTERP,
classobj, get_namespace);
if (!PMC_IS_NULL(method)) {
@@ -578,11 +610,11 @@
SELF, &result);
return result;
}
- else
- return VTABLE_inspect_str(INTERP, classobj, CONST_STRING(INTERP, "namespace"));
+ return VTABLE_inspect_str(INTERP, classobj, CONST_STRING(INTERP, "namespace"));
}
+
/*
=item C<INTVAL can(STRING *method_name)>
@@ -595,10 +627,12 @@
*/
VTABLE INTVAL can(STRING *method_name) {
/* Just use find_method and see it if finds anything. */
- const PMC * const method = VTABLE_find_method(INTERP, SELF, method_name);
+ const PMC * const method =
+ VTABLE_find_method(INTERP, SELF, method_name);
return !PMC_IS_NULL(method);
}
+
/*
=item C<INTVAL isa_pmc(PMC *classname)>
@@ -620,6 +654,7 @@
return VTABLE_isa_pmc(INTERP, VTABLE_get_class(INTERP, SELF), lookup);
}
+
/*
=item C<INTVAL isa(STRING *classname)>
@@ -631,15 +666,13 @@
*/
VTABLE INTVAL isa(STRING *classname) {
- PMC *_class;
-
if (SUPER(classname))
return 1;
- _class = VTABLE_get_class(INTERP, SELF);
- return VTABLE_isa(INTERP, _class, classname);
+ return VTABLE_isa(INTERP, VTABLE_get_class(INTERP, SELF), classname);
}
+
/*
=item C<INTVAL does(STRING *role_name)>
@@ -669,6 +702,7 @@
return 1;
}
}
+
/* Check the superclass's vtable interface, if any. */
if (SUPER(role_name))
return 1;
@@ -677,6 +711,7 @@
return VTABLE_does(INTERP, VTABLE_get_class(INTERP, SELF), role_name);
}
+
/*
=item C<INTVAL does_pmc(PMC *role)>
@@ -698,6 +733,7 @@
return VTABLE_does_pmc(INTERP, VTABLE_get_class(INTERP, SELF), role);
}
+
/*
=item C<opcode_t *invoke(void *next)>
@@ -720,17 +756,19 @@
/* Get the class. */
STRING * const meth_name = CONST_STRING(INTERP, "invoke");
STRING * const proxy = CONST_STRING(INTERP, "proxy");
- PMC * const cur_class =
+ PMC * const cur_class =
VTABLE_get_pmc_keyed_int(INTERP, _class->all_parents, i);
- PMC * const meth =
+ PMC * const meth =
Parrot_oo_find_vtable_override_for_class(INTERP, cur_class,
meth_name);
if (!PMC_IS_NULL(meth)) {
/* Experimental code. See DEPRECATED.pod */
- PMC *call_sig = Parrot_pcc_get_signature(INTERP, CURRENT_CONTEXT(INTERP));
- if ((VTABLE_elements(INTERP, call_sig) == 0 ||
- VTABLE_get_pmc_keyed_int(INTERP, call_sig, 0) != SELF))
+ PMC *call_sig =
+ Parrot_pcc_get_signature(INTERP, CURRENT_CONTEXT(INTERP));
+
+ if ((VTABLE_elements(INTERP, call_sig) == 0
+ || VTABLE_get_pmc_keyed_int(INTERP, call_sig, 0) != SELF))
VTABLE_unshift_pmc(INTERP, call_sig, SELF);
return VTABLE_invoke(INTERP, meth, next);
@@ -749,6 +787,7 @@
return (opcode_t *)INTERP->vtables[enum_class_default]->invoke(INTERP, SELF, next);
}
+
/*
=item C<INTVAL type()>
@@ -764,6 +803,7 @@
return VTABLE_type(INTERP, _class);
}
+
/*
=item C<PMC * clone()>
@@ -779,20 +819,20 @@
/* If we have a custom override, invoke it.
* If not, use the oo function. */
STRING * const meth_name = CONST_STRING(INTERP, "clone");
- PMC * const meth =
+ PMC * const meth =
Parrot_oo_find_vtable_override(INTERP, obj->_class, meth_name);
- PMC *result;
if (!PMC_IS_NULL(meth)) {
- Parrot_pcc_invoke_sub_from_c_args(INTERP, meth, "Pi->P", SELF, &result);
- }
- else {
- result = Parrot_oo_clone_object(INTERP, SELF, NULL);
+ PMC *result;
+ Parrot_pcc_invoke_sub_from_c_args(INTERP, meth, "Pi->P",
+ SELF, &result);
+ return result;
}
- return result;
+ return Parrot_oo_clone_object(INTERP, SELF, NULL);
}
+
/*
=item C<void visit(PMC *info)>
@@ -815,6 +855,7 @@
VISIT_PMC(INTERP, info, obj_data->attrib_store);
}
+
/*
=item C<void freeze(PMC *info)>
@@ -828,13 +869,12 @@
*/
VTABLE void freeze(PMC *info) {
- return;
}
VTABLE void thaw(PMC *info) {
- return;
}
+
/*
=item C<void thawfinish(PMC *info)>
@@ -854,6 +894,7 @@
PObj_is_object_SET(SELF);
}
+
/*
=item C<PMC * share_ro()>
@@ -913,6 +954,7 @@
return ret;
}
+
/*
=item C<void morph(PMC* type)>
@@ -927,8 +969,8 @@
PMC * const classobj = VTABLE_get_class(INTERP, SELF);
STRING * const meth_name = CONST_STRING(INTERP, "morph");
/* If there's a vtable override for 'morph' run that instead. */
- PMC * const method = Parrot_oo_find_vtable_override(INTERP,
- classobj, meth_name);
+ PMC * const method =
+ Parrot_oo_find_vtable_override(INTERP, classobj, meth_name);
if (!PMC_IS_NULL(method))
Parrot_pcc_invoke_sub_from_c_args(INTERP, method, "PiP->",
More information about the parrot-commits
mailing list