4
4
#include "../sixmodelobject.h"
5
5
#include "CStruct.h"
6
6
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
+
7
15
/* This representation's function pointer table. */
8
16
static REPROps * this_repr ;
9
17
@@ -147,6 +155,8 @@ static PMC * index_mapping_and_flat_list(PARROT_INTERP, PMC *WHAT, CStructREPRDa
147
155
* noting unbox targets. */
148
156
static void compute_allocation_strategy (PARROT_INTERP , PMC * WHAT , CStructREPRData * repr_data ) {
149
157
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);*/
150
160
PMC * flat_list ;
151
161
152
162
/*
@@ -211,6 +221,21 @@ static void compute_allocation_strategy(PARROT_INTERP, PMC *WHAT, CStructREPRDat
211
221
cur_init_slot ++ ;
212
222
}
213
223
}
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
+ }
214
239
else {
215
240
Parrot_ex_throw_from_c_args (interp , NULL , EXCEPTION_INVALID_OPERATION ,
216
241
"CStruct representation only implements native int and float members so far" );
@@ -329,7 +354,15 @@ static PMC * allocate(PARROT_INTERP, STable *st) {
329
354
/* Allocate and set up object instance. */
330
355
obj = (CStructInstance * ) Parrot_gc_allocate_fixed_size_storage (interp , sizeof (CStructInstance ));
331
356
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. */
333
366
334
367
return wrap_object_func (interp , obj );
335
368
}
@@ -352,6 +385,8 @@ static void initialize(PARROT_INTERP, STable *st, void *data) {
352
385
st -> REPR -> initialize (interp , st , (char * )body -> cstruct + offset );
353
386
}
354
387
}
388
+
389
+ /* TODO: Initialize child objects. */
355
390
}
356
391
357
392
/* Copies to the body of one object to another. */
0 commit comments