Skip to content

Commit 337cd40

Browse files
committed
Implement copy_to methods for all the reprs; untested.
1 parent 0fd5c74 commit 337cd40

File tree

7 files changed

+50
-0
lines changed

7 files changed

+50
-0
lines changed

src/6model/reprs/HashAttrStore.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ static void initialize(PARROT_INTERP, STable *st, void *data) {
4646
((HashAttrStoreBody *)data)->store = pmc_new(interp, enum_class_Hash);
4747
}
4848

49+
/* Copies to the body of one object to another. */
50+
static void copy_to(PARROT_INTERP, STable *st, void *src, void *dest) {
51+
HashAttrStoreBody *src_body = (HashAttrStoreBody *)src;
52+
HashAttrStoreBody *dest_body = (HashAttrStoreBody *)dest;
53+
dest_body->store = VTABLE_clone(interp, src_body->store);
54+
}
55+
4956
/* Gets the current value for an attribute. */
5057
static PMC * get_attribute_boxed(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint) {
5158
HashAttrStoreBody *body = (HashAttrStoreBody *)data;
@@ -174,6 +181,7 @@ REPROps * HashAttrStore_initialize(PARROT_INTERP) {
174181
this_repr->type_object_for = type_object_for;
175182
this_repr->allocate = allocate;
176183
this_repr->initialize = initialize;
184+
this_repr->copy_to = copy_to;
177185
this_repr->get_attribute_boxed = get_attribute_boxed;
178186
this_repr->get_attribute_ref = get_attribute_ref;
179187
this_repr->bind_attribute = bind_attribute;

src/6model/reprs/KnowHOWREPR.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ static void initialize(PARROT_INTERP, STable *st, void *data) {
4646
body->attributes = pmc_new(interp, enum_class_ResizablePMCArray);
4747
}
4848

49+
/* Copies to the body of one object to another. */
50+
static void copy_to(PARROT_INTERP, STable *st, void *src, void *dest) {
51+
KnowHOWREPRBody *src_body = (KnowHOWREPRBody *)src;
52+
KnowHOWREPRBody *dest_body = (KnowHOWREPRBody *)dest;
53+
dest_body->name = src_body->name;
54+
dest_body->methods = VTABLE_clone(interp, src_body->methods);
55+
dest_body->attributes = VTABLE_clone(interp, src_body->attributes);
56+
}
57+
4958
/* Helper to die because this type doesn't support attributes. */
5059
PARROT_DOES_NOT_RETURN
5160
static void die_no_attrs(PARROT_INTERP) {
@@ -171,6 +180,7 @@ REPROps * KnowHOWREPR_initialize(PARROT_INTERP) {
171180
this_repr->type_object_for = type_object_for;
172181
this_repr->allocate = allocate;
173182
this_repr->initialize = initialize;
183+
this_repr->copy_to = copy_to;
174184
this_repr->get_attribute_boxed = get_attribute_boxed;
175185
this_repr->get_attribute_ref = get_attribute_ref;
176186
this_repr->bind_attribute = bind_attribute;

src/6model/reprs/P6int.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ static void initialize(PARROT_INTERP, STable *st, void *data) {
4343
((P6intBody *)data)->value = 0;
4444
}
4545

46+
/* Copies to the body of one object to another. */
47+
static void copy_to(PARROT_INTERP, STable *st, void *src, void *dest) {
48+
*((INTVAL *)dest) = *((INTVAL *)src);
49+
}
50+
4651
/* Helper to die because this type doesn't support attributes. */
4752
PARROT_DOES_NOT_RETURN
4853
static void die_no_attrs(PARROT_INTERP) {
@@ -155,6 +160,7 @@ REPROps * P6int_initialize(PARROT_INTERP) {
155160
this_repr->type_object_for = type_object_for;
156161
this_repr->allocate = allocate;
157162
this_repr->initialize = initialize;
163+
this_repr->copy_to = copy_to;
158164
this_repr->get_attribute_boxed = get_attribute_boxed;
159165
this_repr->get_attribute_ref = get_attribute_ref;
160166
this_repr->bind_attribute = bind_attribute;

src/6model/reprs/P6num.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ static void initialize(PARROT_INTERP, STable *st, void *data) {
4444
((P6numBody *)data)->value = 0.0/x;
4545
}
4646

47+
/* Copies to the body of one object to another. */
48+
static void copy_to(PARROT_INTERP, STable *st, void *src, void *dest) {
49+
*((FLOATVAL *)dest) = *((FLOATVAL *)src);
50+
}
51+
4752
/* Helper to die because this type doesn't support attributes. */
4853
PARROT_DOES_NOT_RETURN
4954
static void die_no_attrs(PARROT_INTERP) {
@@ -156,6 +161,7 @@ REPROps * P6num_initialize(PARROT_INTERP) {
156161
this_repr->type_object_for = type_object_for;
157162
this_repr->allocate = allocate;
158163
this_repr->initialize = initialize;
164+
this_repr->copy_to = copy_to;
159165
this_repr->get_attribute_boxed = get_attribute_boxed;
160166
this_repr->get_attribute_ref = get_attribute_ref;
161167
this_repr->bind_attribute = bind_attribute;

src/6model/reprs/P6opaque.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,12 @@ static void initialize(PARROT_INTERP, STable *st, void *data) {
388388
/* XXX Fill this out when we may have nested things to initialize. */
389389
}
390390

391+
/* Copies to the body of one object to another. */
392+
static void copy_to(PARROT_INTERP, STable *st, void *src, void *dest) {
393+
P6opaqueREPRData * repr_data = (P6opaqueREPRData *) st->REPR_data;
394+
memcpy(dest, src, repr_data->allocation_size - sizeof(P6opaqueInstance));
395+
}
396+
391397
/* Helper for complaining about attribute access errors. */
392398
PARROT_DOES_NOT_RETURN
393399
static void no_such_attribute(PARROT_INTERP, const char *action, PMC *class_handle, STRING *name) {
@@ -821,6 +827,7 @@ REPROps * P6opaque_initialize(PARROT_INTERP) {
821827
this_repr->type_object_for = type_object_for;
822828
this_repr->allocate = allocate;
823829
this_repr->initialize = initialize;
830+
this_repr->copy_to = copy_to;
824831
this_repr->get_attribute_boxed = get_attribute_boxed;
825832
this_repr->get_attribute_ref = get_attribute_ref;
826833
this_repr->bind_attribute = bind_attribute;

src/6model/reprs/P6str.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ static void initialize(PARROT_INTERP, STable *st, void *data) {
4343
((P6strBody *)data)->value = STRINGNULL;
4444
}
4545

46+
/* Copies to the body of one object to another. */
47+
static void copy_to(PARROT_INTERP, STable *st, void *src, void *dest) {
48+
/* Strings are immutable, so this is safe. */
49+
*((STRING **)dest) = *((STRING **)src);
50+
}
51+
4652
/* Helper to die because this type doesn't support attributes. */
4753
PARROT_DOES_NOT_RETURN
4854
static void die_no_attrs(PARROT_INTERP) {
@@ -162,6 +168,7 @@ REPROps * P6str_initialize(PARROT_INTERP) {
162168
this_repr->type_object_for = type_object_for;
163169
this_repr->allocate = allocate;
164170
this_repr->initialize = initialize;
171+
this_repr->copy_to = copy_to;
165172
this_repr->get_attribute_boxed = get_attribute_boxed;
166173
this_repr->get_attribute_ref = get_attribute_ref;
167174
this_repr->bind_attribute = bind_attribute;

src/6model/reprs/Uninstantiable.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ static void initialize(PARROT_INTERP, STable *st, void *data) {
4242
/* Nothing to do. */
4343
}
4444

45+
/* Copies to the body of one object to another. */
46+
static void copy_to(PARROT_INTERP, STable *st, void *src, void *dest) {
47+
/* Nothing to copy. */
48+
}
49+
4550
/* Helper to die because this type doesn't support attributes. */
4651
PARROT_DOES_NOT_RETURN
4752
static void die_no_attrs(PARROT_INTERP) {
@@ -162,6 +167,7 @@ REPROps * Uninstantiable_initialize(PARROT_INTERP) {
162167
this_repr->type_object_for = type_object_for;
163168
this_repr->allocate = allocate;
164169
this_repr->initialize = initialize;
170+
this_repr->copy_to = copy_to;
165171
this_repr->get_attribute_boxed = get_attribute_boxed;
166172
this_repr->get_attribute_ref = get_attribute_ref;
167173
this_repr->bind_attribute = bind_attribute;

0 commit comments

Comments
 (0)