-
-
Save FROGGS/027719c37ee1baee64f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/6model/bootstrap.c b/src/6model/bootstrap.c | |
index 0add51b..26f7ba4 100644 | |
--- a/src/6model/bootstrap.c | |
+++ b/src/6model/bootstrap.c | |
@@ -570,6 +570,7 @@ static void string_consts(MVMThreadContext *tc) { | |
string_creator(dimensions, "dimensions"); | |
string_creator(ready, "ready"); | |
string_creator(multidim, "multidim"); | |
+ string_creator(shape, "shape"); | |
} | |
/* Drives the overall bootstrap process. */ | |
diff --git a/src/6model/reprs/CArray.c b/src/6model/reprs/CArray.c | |
index 6f29534..31bc9f3 100644 | |
--- a/src/6model/reprs/CArray.c | |
+++ b/src/6model/reprs/CArray.c | |
@@ -82,7 +82,8 @@ static void initialize(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, voi | |
if (!repr_data) | |
MVM_exception_throw_adhoc(tc, "CArray type must be composed before use"); | |
- body->storage = MVM_calloc(4, repr_data->elem_size); | |
+ if (!body->storage) | |
+ body->storage = MVM_calloc(4, repr_data->elem_size); | |
body->managed = 1; | |
/* Don't need child_objs for numerics. */ | |
diff --git a/src/6model/reprs/CPPStruct.c b/src/6model/reprs/CPPStruct.c | |
index 230b51d..3387225 100644 | |
--- a/src/6model/reprs/CPPStruct.c | |
+++ b/src/6model/reprs/CPPStruct.c | |
@@ -149,6 +149,13 @@ static void compute_allocation_strategy(MVMThreadContext *tc, MVMObject *repr_in | |
MVMint64 inlined = !MVM_is_null(tc, inlined_val) && MVM_repr_get_int(tc, inlined_val); | |
MVMint32 bits = sizeof(void *) * 8; | |
MVMint32 align = ALIGNOF(void *); | |
+ MVMObject *shape_val = MVM_repr_at_key_o(tc, attr, tc->instance->str_consts.shape); | |
+ MVMint64 shape = 0; | |
+ | |
+ if (!MVM_is_null(tc, shape_val) && REPR(shape_val)->name, REPR(shape_val)->ID == MVM_REPR_ID_MVMArray) { | |
+ shape = MVM_repr_at_pos_i(tc, shape_val, 0); | |
+ } | |
+ | |
if (!MVM_is_null(tc, type)) { | |
/* See if it's a type that we know how to handle in a C struct. */ | |
const MVMStorageSpec *spec = REPR(type)->get_storage_spec(tc, STABLE(type)); | |
@@ -188,9 +195,26 @@ static void compute_allocation_strategy(MVMThreadContext *tc, MVMObject *repr_in | |
} | |
else if (type_id == MVM_REPR_ID_MVMCArray) { | |
/* It's a CArray of some kind. */ | |
+ MVMCArrayREPRData *carray_repr_data = (MVMCArrayREPRData *)STABLE(type)->REPR_data; | |
repr_data->num_child_objs++; | |
repr_data->attribute_locations[i] = (cur_obj_attr++ << MVM_CPPSTRUCT_ATTR_SHIFT) | MVM_CPPSTRUCT_ATTR_CARRAY; | |
repr_data->member_types[i] = type; | |
+ repr_data->flattened_stables[i] = STABLE(type); | |
+ if (inlined) { | |
+ bits = carray_repr_data->elem_size * 8 * shape; | |
+ //~ align = carray_repr_data->struct_align; | |
+ repr_data->attribute_locations[i] |= MVM_CPPSTRUCT_ATTR_INLINED; | |
+ if (REPR(type)->initialize) { | |
+ if (!repr_data->initialize_slots) | |
+ repr_data->initialize_slots = (MVMint32 *) MVM_calloc(info_alloc + 1, sizeof(MVMint32)); | |
+ repr_data->initialize_slots[cur_init_slot] = i; | |
+ cur_init_slot++; | |
+ } | |
+ } | |
+ else { | |
+ bits = carray_repr_data->elem_size * 8 * shape; | |
+ //~ align = spec->align; | |
+ } | |
} | |
else if (type_id == MVM_REPR_ID_MVMCStruct) { | |
/* It's a CStruct. */ | |
@@ -345,11 +369,33 @@ static void initialize(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, voi | |
/* Initialize the slots. */ | |
if (repr_data->initialize_slots) { | |
MVMint32 i; | |
+ | |
+ MVM_gc_root_temp_push(tc, (MVMCollectable **)&root); | |
+ MVM_gc_root_temp_push(tc, (MVMCollectable **)&repr_data); | |
+ MVM_gc_root_temp_push(tc, (MVMCollectable **)&body); | |
+ | |
for (i = 0; repr_data->initialize_slots[i] >= 0; i++) { | |
- MVMint32 offset = repr_data->struct_offsets[repr_data->initialize_slots[i]]; | |
- MVMSTable *st = repr_data->flattened_stables[repr_data->initialize_slots[i]]; | |
- st->REPR->initialize(tc, st, root, (char *)body->cppstruct + offset); | |
+ MVMint32 slot = repr_data->initialize_slots[i]; | |
+ MVMint32 offset = repr_data->struct_offsets[slot]; | |
+ MVMSTable *st = repr_data->flattened_stables[slot]; | |
+ MVMObject *type = repr_data->member_types[slot]; | |
+ MVMint32 type_id = REPR(type)->ID; | |
+ | |
+ MVM_gc_root_temp_push(tc, (MVMCollectable **)&st); | |
+ MVM_gc_root_temp_push(tc, (MVMCollectable **)&type); | |
+ | |
+ if (type_id == MVM_REPR_ID_MVMCArray) { | |
+ MVMint32 real_slot = repr_data->attribute_locations[slot] >> MVM_CSTRUCT_ATTR_SHIFT; | |
+ MVMObject *obj = MVM_nativecall_make_carray(tc, type, (char *)body->cppstruct + offset); | |
+ MVMCArrayBody *carray_body = (MVMCArrayBody *)OBJECT_BODY(obj); | |
+ carray_body->elems = 4; // XXX shape; | |
+ MVM_ASSIGN_REF(tc, &(root->header), body->child_objs[real_slot], obj); | |
+ st->REPR->initialize(tc, st, obj, carray_body); | |
+ } | |
+ | |
+ MVM_gc_root_temp_pop_n(tc, 2); | |
} | |
+ MVM_gc_root_temp_pop_n(tc, 3); | |
} | |
} | |
@@ -399,13 +445,18 @@ static void get_attribute(MVMThreadContext *tc, MVMSTable *st, MVMObject *root, | |
else { | |
MVMObject *typeobj = repr_data->member_types[slot]; | |
MVMObject *obj = body->child_objs[real_slot]; | |
+ | |
if (!obj) { | |
/* No cached object. */ | |
void *cobj = get_ptr_at_offset(body->cppstruct, repr_data->struct_offsets[slot]); | |
if (cobj) { | |
MVMObject **child_objs = body->child_objs; | |
if (type == MVM_CPPSTRUCT_ATTR_CARRAY) { | |
- obj = MVM_nativecall_make_carray(tc, typeobj, cobj); | |
+ if (repr_data->attribute_locations[slot] & MVM_CPPSTRUCT_ATTR_INLINED) | |
+ obj = MVM_nativecall_make_carray(tc, typeobj, | |
+ (char *)body->cppstruct + repr_data->struct_offsets[slot]); | |
+ else | |
+ obj = MVM_nativecall_make_carray(tc, typeobj, cobj); | |
} | |
else if(type == MVM_CPPSTRUCT_ATTR_CSTRUCT) { | |
if (repr_data->attribute_locations[slot] & MVM_CPPSTRUCT_ATTR_INLINED) | |
diff --git a/src/core/instance.h b/src/core/instance.h | |
index 63531bd..1ee94a8 100644 | |
--- a/src/core/instance.h | |
+++ b/src/core/instance.h | |
@@ -75,6 +75,7 @@ struct MVMStringConsts { | |
MVMString *dimensions; | |
MVMString *ready; | |
MVMString *multidim; | |
+ MVMString *shape; | |
}; | |
/* An entry in the representations registry. */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment