[svn:parrot] r39055 - in branches/tt_696: include/parrot src src/pmc
whiteknight at svn.parrot.org
whiteknight at svn.parrot.org
Fri May 22 21:54:23 UTC 2009
Author: whiteknight
Date: Fri May 22 21:54:22 2009
New Revision: 39055
URL: https://trac.parrot.org/parrot/changeset/39055
Log:
[tt_696] create Parrot_oo_clone_object function.
Modified:
branches/tt_696/include/parrot/oo.h
branches/tt_696/src/oo.c
branches/tt_696/src/pmc/object.pmc
Modified: branches/tt_696/include/parrot/oo.h
==============================================================================
--- branches/tt_696/include/parrot/oo.h Fri May 22 21:29:57 2009 (r39054)
+++ branches/tt_696/include/parrot/oo.h Fri May 22 21:54:22 2009 (r39055)
@@ -131,6 +131,14 @@
void mark_object_cache(PARROT_INTERP)
__attribute__nonnull__(1);
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+PMC * Parrot_oo_clone_object(PARROT_INTERP,
+ ARGIN(PMC * pmc),
+ ARGIN_NULLOK(PMC * to))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
void Parrot_oo_extract_methods_from_namespace(PARROT_INTERP,
ARGIN(PMC *self),
ARGIN(PMC *ns))
@@ -213,6 +221,9 @@
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_mark_object_cache __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
+#define ASSERT_ARGS_Parrot_oo_clone_object __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(pmc)
#define ASSERT_ARGS_Parrot_oo_extract_methods_from_namespace \
__attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
Modified: branches/tt_696/src/oo.c
==============================================================================
--- branches/tt_696/src/oo.c Fri May 22 21:29:57 2009 (r39054)
+++ branches/tt_696/src/oo.c Fri May 22 21:54:22 2009 (r39055)
@@ -23,6 +23,7 @@
#include "parrot/parrot.h"
#include "parrot/oo_private.h"
#include "pmc/pmc_class.h"
+#include "pmc/pmc_object.h"
#include "oo.str"
@@ -248,6 +249,69 @@
return classobj;
}
+/*
+
+=item C<PMC * Parrot_oo_clone_object(PARROT_INTERP, PMC * pmc, PMC * to)>
+
+=cut
+
+*/
+
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+PMC *
+Parrot_oo_clone_object(PARROT_INTERP, ARGIN(PMC * pmc),
+ ARGIN_NULLOK(PMC * to))
+{
+ Parrot_Object_attributes * const obj = PARROT_OBJECT(pmc);
+ Parrot_Class_attributes * const _class = PARROT_CLASS(obj->_class);
+ const int num_classes = VTABLE_elements(interp, _class->all_parents);
+ PMC * cloned;
+ Parrot_Object_attributes * cloned_guts;
+ INTVAL i, num_attrs;
+
+ cloned = pmc_new_noinit(interp, enum_class_Object);
+
+ /* Set custom GC mark and destroy on the object. */
+ PObj_custom_mark_SET(cloned);
+ PObj_active_destroy_SET(cloned);
+
+ /* Flag that it is an object */
+ PObj_is_object_SET(cloned);
+
+ /* Now create the underlying structure, and clone attributes list.class. */
+ cloned_guts = mem_allocate_zeroed_typed(Parrot_Object_attributes);
+ cloned_guts->_class = obj->_class;
+ cloned_guts->attrib_store = VTABLE_clone(interp, obj->attrib_store);
+ PMC_data(cloned) = cloned_guts;
+ num_attrs = VTABLE_elements(interp, cloned_guts->attrib_store);
+ for (i = 0; i < num_attrs; i++) {
+ PMC * const to_clone = VTABLE_get_pmc_keyed_int(interp, cloned_guts->attrib_store, i);
+ if (!PMC_IS_NULL(to_clone)) {
+ VTABLE_set_pmc_keyed_int(interp, cloned_guts->attrib_store, i,
+ VTABLE_clone(interp, to_clone));
+ }
+ }
+
+ /* Some of the attributes may have been the PMCs providing storage for any
+ * PMCs we inherited from; also need to clone those. */
+ if (CLASS_has_alien_parents_TEST(obj->_class)) {
+ /* Locate any PMC parents. */
+ for (i = 0; i < num_classes; i++) {
+ PMC * const cur_class = VTABLE_get_pmc_keyed_int(interp, _class->all_parents, i);
+ if (cur_class->vtable->base_type == enum_class_PMCProxy) {
+ /* Clone this PMC too. */
+ STRING * const proxy = CONST_STRING(interp, "proxy");
+ VTABLE_set_attr_keyed(interp, cloned, cur_class, proxy,
+ VTABLE_clone(interp,
+ VTABLE_get_attr_keyed(interp, cloned, cur_class, proxy)));
+ }
+ }
+ }
+
+ /* And we have ourselves a clone. */
+ return cloned;
+}
/*
Modified: branches/tt_696/src/pmc/object.pmc
==============================================================================
--- branches/tt_696/src/pmc/object.pmc Fri May 22 21:29:57 2009 (r39054)
+++ branches/tt_696/src/pmc/object.pmc Fri May 22 21:54:22 2009 (r39055)
@@ -639,15 +639,14 @@
*/
VTABLE PMC * clone() {
- Parrot_Object_attributes * const obj = PARROT_OBJECT(pmc);
+ Parrot_Object_attributes * const obj = PARROT_OBJECT(pmc);
Parrot_Class_attributes * const _class = PARROT_CLASS(obj->_class);
STRING * const meth_name = CONST_STRING(interp, "clone");
PMC * cloned;
- Parrot_Object_attributes * cloned_guts;
/* See if we have a custom override of the method first. */
const int num_classes = VTABLE_elements(interp, _class->all_parents);
- int i, num_attrs;
+ 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);
@@ -660,47 +659,7 @@
}
/* If we get here, no custom clone. Create a new object PMC. */
- cloned = pmc_new_noinit(interp, enum_class_Object);
-
- /* Set custom GC mark and destroy on the object. */
- PObj_custom_mark_SET(cloned);
- PObj_active_destroy_SET(cloned);
-
- /* Flag that it is an object */
- PObj_is_object_SET(cloned);
-
- /* Now create the underlying structure, and clone attributes list.class. */
- cloned_guts = mem_allocate_zeroed_typed(Parrot_Object_attributes);
- cloned_guts->_class = obj->_class;
- cloned_guts->attrib_store = VTABLE_clone(INTERP, obj->attrib_store);
- PMC_data(cloned) = cloned_guts;
- num_attrs = VTABLE_elements(INTERP, cloned_guts->attrib_store);
- for (i = 0; i < num_attrs; i++) {
- PMC * const to_clone = VTABLE_get_pmc_keyed_int(INTERP, cloned_guts->attrib_store, i);
- if (!PMC_IS_NULL(to_clone)) {
- VTABLE_set_pmc_keyed_int(INTERP, cloned_guts->attrib_store, i,
- VTABLE_clone(INTERP, to_clone));
- }
- }
-
- /* Some of the attributes may have been the PMCs providing storage for any
- * PMCs we inherited from; also need to clone those. */
- if (CLASS_has_alien_parents_TEST(obj->_class)) {
- /* Locate any PMC parents. */
- for (i = 0; i < num_classes; i++) {
- PMC * const cur_class = VTABLE_get_pmc_keyed_int(interp, _class->all_parents, i);
- if (cur_class->vtable->base_type == enum_class_PMCProxy) {
- /* Clone this PMC too. */
- STRING * const proxy = CONST_STRING(interp, "proxy");
- VTABLE_set_attr_keyed(interp, cloned, cur_class, proxy,
- VTABLE_clone(interp,
- VTABLE_get_attr_keyed(interp, cloned, cur_class, proxy)));
- }
- }
- }
-
- /* And we have ourselves a clone. */
- return cloned;
+ return Parrot_oo_clone_object(interp, SELF, NULL);
}
/*
More information about the parrot-commits
mailing list