Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Toss clone from the REPR API; it's just implementable in terms of the…
… more primitive allocate and copy_to.
  • Loading branch information
jnthn committed Oct 31, 2011
1 parent 7218de5 commit a743c97
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 92 deletions.
13 changes: 0 additions & 13 deletions src/6model/reprs/HashAttrStore.c
Expand Up @@ -78,18 +78,6 @@ static INTVAL hint_for(PARROT_INTERP, STable *st, PMC *class_handle, STRING *nam
return NO_HINT;
}

/* Clone. Clone object body and the attribute storage hash. */
static PMC * repr_clone(PARROT_INTERP, PMC *to_clone) {
HashAttrStoreInstance *obj;

/* Allocate and set up object instance. */
obj = (HashAttrStoreInstance *) Parrot_gc_allocate_fixed_size_storage(interp, sizeof(HashAttrStoreInstance));
obj->common.stable = STABLE_PMC(to_clone);
obj->body.store = VTABLE_clone(interp, ((HashAttrStoreInstance *)PMC_data(to_clone))->body.store);

return wrap_object(interp, obj);
}

/* Used with boxing. Sets an integer value, for representations that can hold
* one. */
static void set_int(PARROT_INTERP, STable *st, void *data, INTVAL value) {
Expand Down Expand Up @@ -173,7 +161,6 @@ REPROps * HashAttrStore_initialize(PARROT_INTERP) {
this_repr->bind_attribute_boxed = bind_attribute_boxed;
this_repr->bind_attribute_ref = bind_attribute_ref;
this_repr->hint_for = hint_for;
this_repr->clone = repr_clone;
this_repr->set_int = set_int;
this_repr->get_int = get_int;
this_repr->set_num = set_num;
Expand Down
12 changes: 0 additions & 12 deletions src/6model/reprs/KnowHOWREPR.c
Expand Up @@ -86,17 +86,6 @@ static INTVAL hint_for(PARROT_INTERP, STable *st, PMC *class_handle, STRING *nam
return NO_HINT;
}

/* Clones the current object. This involves cloning the method and
* attribute lists and copying the (immutable string) name. */
static PMC * repr_clone(PARROT_INTERP, PMC *to_clone) {
KnowHOWREPRInstance *obj = mem_allocate_zeroed_typed(KnowHOWREPRInstance);
obj->common.stable = STABLE_PMC(to_clone);
obj->body.methods = VTABLE_clone(interp, ((KnowHOWREPRInstance *)PMC_data(to_clone))->body.methods);
obj->body.attributes = VTABLE_clone(interp, ((KnowHOWREPRInstance *)PMC_data(to_clone))->body.attributes);
obj->body.name = ((KnowHOWREPRInstance *)PMC_data(to_clone))->body.name;
return wrap_object(interp, obj);
}

/* Used with boxing. Sets an integer value, for representations that can hold
* one. */
static void set_int(PARROT_INTERP, STable *st, void *data, INTVAL value) {
Expand Down Expand Up @@ -181,7 +170,6 @@ REPROps * KnowHOWREPR_initialize(PARROT_INTERP) {
this_repr->bind_attribute_boxed = bind_attribute_boxed;
this_repr->bind_attribute_ref = bind_attribute_ref;
this_repr->hint_for = hint_for;
this_repr->clone = repr_clone;
this_repr->set_int = set_int;
this_repr->get_int = get_int;
this_repr->set_num = set_num;
Expand Down
9 changes: 0 additions & 9 deletions src/6model/reprs/P6int.c
Expand Up @@ -78,14 +78,6 @@ static INTVAL hint_for(PARROT_INTERP, STable *st, PMC *class_handle, STRING *nam
return NO_HINT;
}

/* Clones the current object; simply copies the value. */
static PMC * repr_clone(PARROT_INTERP, PMC *to_clone) {
P6intInstance *obj = mem_allocate_zeroed_typed(P6intInstance);
obj->common.stable = STABLE_PMC(to_clone);
obj->body.value = ((P6intInstance *)PMC_data(to_clone))->body.value;
return wrap_object(interp, obj);
}

/* Used with boxing. Sets an integer value, for representations that can hold
* one. */
static void set_int(PARROT_INTERP, STable *st, void *data, INTVAL value) {
Expand Down Expand Up @@ -160,7 +152,6 @@ REPROps * P6int_initialize(PARROT_INTERP) {
this_repr->bind_attribute_boxed = bind_attribute_boxed;
this_repr->bind_attribute_ref = bind_attribute_ref;
this_repr->hint_for = hint_for;
this_repr->clone = repr_clone;
this_repr->set_int = set_int;
this_repr->get_int = get_int;
this_repr->set_num = set_num;
Expand Down
9 changes: 0 additions & 9 deletions src/6model/reprs/P6num.c
Expand Up @@ -79,14 +79,6 @@ static INTVAL hint_for(PARROT_INTERP, STable *st, PMC *class_handle, STRING *nam
return NO_HINT;
}

/* Clones the current object; simply copies the value. */
static PMC * repr_clone(PARROT_INTERP, PMC *to_clone) {
P6numInstance *obj = mem_allocate_zeroed_typed(P6numInstance);
obj->common.stable = STABLE_PMC(to_clone);
obj->body.value = ((P6numInstance *)PMC_data(to_clone))->body.value;
return wrap_object(interp, obj);
}

/* Used with boxing. Sets an integer value, for representations that can hold
* one. */
static void set_int(PARROT_INTERP, STable *st, void *data, INTVAL value) {
Expand Down Expand Up @@ -161,7 +153,6 @@ REPROps * P6num_initialize(PARROT_INTERP) {
this_repr->bind_attribute_boxed = bind_attribute_boxed;
this_repr->bind_attribute_ref = bind_attribute_ref;
this_repr->hint_for = hint_for;
this_repr->clone = repr_clone;
this_repr->set_int = set_int;
this_repr->get_int = get_int;
this_repr->set_num = set_num;
Expand Down
29 changes: 5 additions & 24 deletions src/6model/reprs/P6opaque.c
Expand Up @@ -428,9 +428,11 @@ static PMC * get_attribute_boxed(PARROT_INTERP, STable *st, void *data, PMC *cla
if (repr_data->auto_viv_values) {
PMC *value = repr_data->auto_viv_values[slot];
if (value != NULL) {
value = REPR(value)->clone(interp, value);
set_pmc_at_offset(data, repr_data->attribute_offsets[slot], value);
return value;
PMC *cloned = REPR(value)->allocate(interp, STABLE(value));
REPR(value)->copy_to(interp, STABLE(value), OBJECT_BODY(value), OBJECT_BODY(cloned));
PARROT_GC_WRITE_BARRIER(interp, cloned);
set_pmc_at_offset(data, repr_data->attribute_offsets[slot], cloned);
return cloned;
}
}
return PMCNULL;
Expand Down Expand Up @@ -531,26 +533,6 @@ static INTVAL hint_for(PARROT_INTERP, STable *st, PMC *class_key, STRING *name)
return slot >= 0 ? slot : NO_HINT;
}

/* Clones the current object. */
static PMC * repr_clone(PARROT_INTERP, PMC *to_clone) {
P6opaqueInstance *obj;
P6opaqueREPRData *repr_data = (P6opaqueREPRData *)STABLE(to_clone)->REPR_data;

if (IS_CONCRETE(to_clone)) {
obj = (P6opaqueInstance *)Parrot_gc_allocate_fixed_size_storage(interp, repr_data->allocation_size);
memcpy(obj, PMC_data(to_clone), repr_data->allocation_size);
return wrap_object(interp, obj);
}
else {
PMC *result;
obj = mem_allocate_zeroed_typed(P6opaqueInstance);
memcpy(obj, PMC_data(to_clone), sizeof(P6opaqueInstance));
result = wrap_object(interp, obj);
PObj_flag_SET(private0, result);
return result;
}
}

/* Used with boxing. Sets an integer value, for representations that can hold
* one. */
static void set_int(PARROT_INTERP, STable *st, void *data, INTVAL value) {
Expand Down Expand Up @@ -814,7 +796,6 @@ REPROps * P6opaque_initialize(PARROT_INTERP) {
this_repr->bind_attribute_boxed = bind_attribute_boxed;
this_repr->bind_attribute_ref = bind_attribute_ref;
this_repr->hint_for = hint_for;
this_repr->clone = repr_clone;
this_repr->set_int = set_int;
this_repr->get_int = get_int;
this_repr->set_num = set_num;
Expand Down
9 changes: 0 additions & 9 deletions src/6model/reprs/P6str.c
Expand Up @@ -79,14 +79,6 @@ static INTVAL hint_for(PARROT_INTERP, STable *st, PMC *class_handle, STRING *nam
return NO_HINT;
}

/* Clone; just copy the string pointer, since strings are immutable. */
static PMC * repr_clone(PARROT_INTERP, PMC *to_clone) {
P6strInstance *obj = mem_allocate_zeroed_typed(P6strInstance);
obj->common.stable = STABLE_PMC(to_clone);
obj->body.value = ((P6strInstance *)PMC_data(to_clone))->body.value;
return wrap_object(interp, obj);
}

/* Used with boxing. Sets an integer value, for representations that can hold
* one. */
static void set_int(PARROT_INTERP, STable *st, void *data, INTVAL value) {
Expand Down Expand Up @@ -168,7 +160,6 @@ REPROps * P6str_initialize(PARROT_INTERP) {
this_repr->bind_attribute_boxed = bind_attribute_boxed;
this_repr->bind_attribute_ref = bind_attribute_ref;
this_repr->hint_for = hint_for;
this_repr->clone = repr_clone;
this_repr->set_int = set_int;
this_repr->get_int = get_int;
this_repr->set_num = set_num;
Expand Down
8 changes: 0 additions & 8 deletions src/6model/reprs/Uninstantiable.c
Expand Up @@ -85,13 +85,6 @@ static INTVAL hint_for(PARROT_INTERP, STable *st, PMC *class_handle, STRING *nam
return NO_HINT;
}

/* Clones the current object. */
static PMC * repr_clone(PARROT_INTERP, PMC *to_clone) {
UninstantiableInstance *obj = mem_allocate_zeroed_typed(UninstantiableInstance);
obj->common.stable = STABLE_PMC(to_clone);
return wrap_object(interp, obj);
}

/* Used with boxing. Sets an integer value, for representations that can hold
* one. */
static void set_int(PARROT_INTERP, STable *st, void *data, INTVAL value) {
Expand Down Expand Up @@ -167,7 +160,6 @@ REPROps * Uninstantiable_initialize(PARROT_INTERP) {
this_repr->bind_attribute_boxed = bind_attribute_boxed;
this_repr->bind_attribute_ref = bind_attribute_ref;
this_repr->hint_for = hint_for;
this_repr->clone = repr_clone;
this_repr->set_int = set_int;
this_repr->get_int = get_int;
this_repr->set_num = set_num;
Expand Down
6 changes: 1 addition & 5 deletions src/6model/sixmodelobject.h
Expand Up @@ -198,10 +198,6 @@ struct SixModel_REPROps {
/* Gets the hint for the given attribute ID. */
INTVAL (*hint_for) (PARROT_INTERP, STable *st, PMC *class_handle, STRING *name);

/* Clones the object, optionally cloning any containers in its
* attributes. */
PMC * (*clone) (PARROT_INTERP, PMC *to_clone);

/* Used with boxing. Sets an integer value, for representations that
* can hold one. */
void (*set_int) (PARROT_INTERP, STable *st, void *data, INTVAL value);
Expand Down Expand Up @@ -230,7 +226,7 @@ struct SixModel_REPROps {
void (*gc_mark) (PARROT_INTERP, STable *st, void *data);

/* This Parrot-specific addition to the API is used to free an object. */
void (*gc_free) (PARROT_INTERP, PMC *Object);
void (*gc_free) (PARROT_INTERP, PMC *object);

/* This Parrot-specific addition to the API is used to mark a REPR instance. */
void (*gc_mark_repr_data) (PARROT_INTERP, STable *st);
Expand Down
14 changes: 11 additions & 3 deletions src/ops/nqp.ops
Expand Up @@ -199,6 +199,7 @@ inline op repr_instance_of(out PMC, in PMC) :base_core {
if ($2->vtable->base_type == smo_id) {
$1 = REPR($2)->allocate(interp, STABLE($2));
REPR($1)->initialize(interp, STABLE($2), OBJECT_BODY($1));
PARROT_GC_WRITE_BARRIER(interp, $1);
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
Expand All @@ -217,11 +218,18 @@ Gets a REPR to clone itself.
*/
inline op repr_clone(out PMC, in PMC) :base_core {
PMC *var = decontainerize(interp, $2);
if (var->vtable->base_type == smo_id)
$1 = REPR(var)->clone(interp, var);
else
if (var->vtable->base_type == smo_id) {
$1 = REPR(var)->allocate(interp, STABLE(var));
if (IS_CONCRETE(var))
REPR($1)->copy_to(interp, $1, OBJECT_BODY(var), OBJECT_BODY($1));
else
MARK_AS_TYPE_OBJECT($1);
PARROT_GC_WRITE_BARRIER(interp, $1);
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use repr_clone on a SixModelObject");
}
}


Expand Down

0 comments on commit a743c97

Please sign in to comment.