Skip to content

Commit 51a3250

Browse files
committed
Start letting CStruct have CArray members.
1 parent e49a91d commit 51a3250

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/6model/reprs/CStruct.c

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
#include "../sixmodelobject.h"
55
#include "CStruct.h"
66

7+
/* TODO:
8+
* - The initialize_slots member in the REPRData needs to be more complex
9+
* - So that we can handle initialisation of member objects as well as numbers
10+
* - We need to handle setting and getting non-number members. In particular,
11+
* setting an object member needs to not only update the child_obj pointer,
12+
* but also set the pointer in the cstruct part.
13+
*/
14+
715
/* This representation's function pointer table. */
816
static REPROps *this_repr;
917

@@ -147,6 +155,8 @@ static PMC * index_mapping_and_flat_list(PARROT_INTERP, PMC *WHAT, CStructREPRDa
147155
* noting unbox targets. */
148156
static void compute_allocation_strategy(PARROT_INTERP, PMC *WHAT, CStructREPRData *repr_data) {
149157
STRING *type_str = Parrot_str_new_constant(interp, "type");
158+
STRING *carray_str = Parrot_str_new_constant(interp, "CArray");
159+
/*INTVAL carray_id = REPR_name_to_id(interp, carray_str);*/
150160
PMC *flat_list;
151161

152162
/*
@@ -211,6 +221,21 @@ static void compute_allocation_strategy(PARROT_INTERP, PMC *WHAT, CStructREPRDat
211221
cur_init_slot++;
212222
}
213223
}
224+
else if(STRING_equal(interp, REPR(type)->name, carray_str)) {
225+
/* It's a CArray of some kind. */
226+
227+
repr_data->num_child_objs++;
228+
if (REPR(type)->initialize) {
229+
/* Copy-pasta of what happens in the flattening case.
230+
* initialize_slots probably needs to be a list of
231+
* something more complex to handle objects as well,
232+
* though.
233+
if (!repr_data->initialize_slots)
234+
repr_data->initialize_slots = (INTVAL *) mem_sys_allocate_zeroed((info_alloc + 1) * sizeof(INTVAL));
235+
repr_data->initialize_slots[cur_init_slot] = i;
236+
cur_init_slot++;*/
237+
}
238+
}
214239
else {
215240
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
216241
"CStruct representation only implements native int and float members so far");
@@ -329,7 +354,15 @@ static PMC * allocate(PARROT_INTERP, STable *st) {
329354
/* Allocate and set up object instance. */
330355
obj = (CStructInstance *) Parrot_gc_allocate_fixed_size_storage(interp, sizeof(CStructInstance));
331356
obj->common.stable = st->stable_pmc;
332-
/* XXX allocate child str and obj arrays if needed. */
357+
358+
/* Allocate child obj array. */
359+
if(repr_data->num_child_objs > 0) {
360+
size_t bytes = repr_data->num_child_objs*sizeof(PMC *);
361+
obj->body.child_objs = mem_sys_allocate(bytes);
362+
memset(obj->body.child_objs, 0, bytes);
363+
}
364+
365+
/* XXX allocate child str array if needed. */
333366

334367
return wrap_object_func(interp, obj);
335368
}
@@ -352,6 +385,8 @@ static void initialize(PARROT_INTERP, STable *st, void *data) {
352385
st->REPR->initialize(interp, st, (char *)body->cstruct + offset);
353386
}
354387
}
388+
389+
/* TODO: Initialize child objects. */
355390
}
356391

357392
/* Copies to the body of one object to another. */

0 commit comments

Comments
 (0)