Author: chromatic
Date: Mon Jun 18 23:12:05 2007
New Revision: 19118
Modified:
trunk/src/pmc/class.pmc
trunk/src/pmc/object.pmc
Log:
[PMC} Right, it's important to be able to call methods on instances of the
Class PMC, as well as on instances of the objects. That's why there are now
two C<find_method()>s defined here: one a vtable entry and one a PCCMETHOD.
Confused? See metacircular object systems, and r19108 which caused the
breakage.
Modified: trunk/src/pmc/class.pmc
==============================================================================
--- trunk/src/pmc/class.pmc (original)
+++ trunk/src/pmc/class.pmc Mon Jun 18 23:12:05 2007
@@ -507,36 +507,6 @@
/*
-=item C<PMC* find_method(STRING *name)>
-
-Walks the MRO of the class and finds the method with the given name.
-
-*/
-
- PMC* find_method(STRING *name) {
- Parrot_Class * const _class = PARROT_CLASS(SELF);
-
- /* Walk and search. One day, we'll use the cache first. */
- int num_classes = VTABLE_elements(interp, _class->all_parents);
- int i;
-
- for (i = 0; i < num_classes; i++) {
- /* Get the class and see if it has the method. */
- PMC * const cur_class =
- VTABLE_get_pmc_keyed_int(interp, _class->all_parents, i);
- const Parrot_Class * const class_info = PARROT_CLASS(cur_class);
-
- /* Found it! */
- if (VTABLE_exists_keyed_str(interp, class_info->methods, name))
- return VTABLE_get_pmc_keyed_str(interp, class_info->methods,
- name);
- }
-
- return PMCNULL;
- }
-
-/*
-
=item C<STRING* get_string()>
Return the fully qualified name of the class.
@@ -1187,6 +1157,45 @@
/*
+=item C<PMC* find_method(STRING *name)>
+
+Walks the MRO of the class and finds the method with the given name.
+
+*/
+
+ PCCMETHOD void find_method(STRING *name) {
+ Parrot_Class * const _class = PARROT_CLASS(SELF);
+ PMC *namespace = _class->_namespace;
+
+ if ( ! PMC_IS_NULL(namespace)
+ && VTABLE_exists_keyed_str(interp, namespace, name)) {
+ PMC *ret = VTABLE_get_pmc_keyed_str(interp, namespace, name);
+ PCCRETURN(PMC *ret);
+ }
+
+ /* Walk and search. One day, we'll use the cache first. */
+ int num_classes = VTABLE_elements(interp, _class->all_parents);
+ int i;
+
+ for (i = 0; i < num_classes; i++) {
+ /* Get the class and see if it has the method. */
+ PMC * const cur_class =
+ VTABLE_get_pmc_keyed_int(interp, _class->all_parents, i);
+ const Parrot_Class * const class_info = PARROT_CLASS(cur_class);
+
+ /* Found it! */
+ if (VTABLE_exists_keyed_str(interp, class_info->methods, name)) {
+ PMC *ret = VTABLE_get_pmc_keyed_str(interp,
class_info->methods,
+ name);
+ PCCRETURN(PMC *ret);
+ }
+ }
+
+ PCCRETURN(PMC *PMCNULL);
+ }
+
+/*
+
=item C<void parents()>
Return the parents array PMC.
Modified: trunk/src/pmc/object.pmc
==============================================================================
--- trunk/src/pmc/object.pmc (original)
+++ trunk/src/pmc/object.pmc Mon Jun 18 23:12:05 2007
@@ -181,7 +181,13 @@
*/
PMC* find_method(STRING *name) {
- return VTABLE_find_method(interp, PARROT_OBJECT(SELF)->_class, name);
+ PMC *method;
+
+ Parrot_PCCINVOKE(interp, PARROT_OBJECT(SELF)->_class,
+ string_from_cstring(interp, "find_method", 11), "S->P", name,
+ &method);
+
+ return method;
}
/*