Skip to content

Commit 281bfbf

Browse files
committed
Make allocate operation more consistent with the rest of the API. Get P6opaque's get_attribute_boxed handle the flattened case (untested yet, but probably rightish).
1 parent 648845a commit 281bfbf

File tree

11 files changed

+51
-36
lines changed

11 files changed

+51
-36
lines changed

src/6model/knowhow_bootstrapper.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static void new_type(PARROT_INTERP, PMC *nci) {
2222
/* We first create a new HOW instance. */
2323
PMC *capture = Parrot_pcc_get_signature(interp, CURRENT_CONTEXT(interp));
2424
PMC *self = VTABLE_get_pmc_keyed_int(interp, capture, 0);
25-
PMC *HOW = REPR(self)->allocate(interp, STABLE_PMC(self));
25+
PMC *HOW = REPR(self)->allocate(interp, STABLE(self));
2626

2727
/* See if we have a representation name; if not default to P6opaque. */
2828
STRING *repr_name = VTABLE_exists_keyed_str(interp, capture, repr_str) ?
@@ -260,7 +260,7 @@ static void attr_new(PARROT_INTERP, PMC *nci) {
260260
PMC *capture = Parrot_pcc_get_signature(interp, CURRENT_CONTEXT(interp));
261261
PMC *type = VTABLE_get_pmc_keyed_int(interp, capture, 0);
262262
STRING *name = VTABLE_get_string_keyed_str(interp, capture, name_str);
263-
PMC *self = REPR(type)->allocate(interp, STABLE_PMC(type));
263+
PMC *self = REPR(type)->allocate(interp, STABLE(type));
264264
REPR(self)->set_str(interp, STABLE(self), OBJECT_BODY(self), name);
265265
unused = Parrot_pcc_build_call_from_c_args(interp, capture, "P", self);
266266
}

src/6model/reprs/HashAttrStore.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ static PMC * type_object_for(PARROT_INTERP, PMC *HOW) {
3434
}
3535

3636
/* Creates a new instance based on the type object. */
37-
static PMC * allocate(PARROT_INTERP, PMC *st) {
37+
static PMC * allocate(PARROT_INTERP, STable *st) {
3838
HashAttrStoreInstance *obj;
3939
obj = (HashAttrStoreInstance *) Parrot_gc_allocate_fixed_size_storage(interp, sizeof(HashAttrStoreInstance));
40-
obj->common.stable = st;
40+
obj->common.stable = st->stable_pmc;
4141
return wrap_object(interp, obj);
4242
}
4343

src/6model/reprs/KnowHOWREPR.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ static PMC * type_object_for(PARROT_INTERP, PMC *HOW) {
3333
}
3434

3535
/* Creates a new instance based on the type object. */
36-
static PMC * allocate(PARROT_INTERP, PMC *st) {
36+
static PMC * allocate(PARROT_INTERP, STable *st) {
3737
KnowHOWREPRInstance *obj = mem_allocate_zeroed_typed(KnowHOWREPRInstance);
38-
obj->common.stable = st;
38+
if (st)
39+
obj->common.stable = st->stable_pmc;
3940
return wrap_object(interp, obj);
4041
}
4142

src/6model/reprs/P6int.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ static PMC * type_object_for(PARROT_INTERP, PMC *HOW) {
3232
}
3333

3434
/* Creates a new instance based on the type object. */
35-
static PMC * allocate(PARROT_INTERP, PMC *st) {
35+
static PMC * allocate(PARROT_INTERP, STable *st) {
3636
P6intInstance *obj = mem_allocate_zeroed_typed(P6intInstance);
37-
obj->common.stable = st;
37+
obj->common.stable = st->stable_pmc;
3838
return wrap_object(interp, obj);
3939
}
4040

src/6model/reprs/P6num.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ static PMC * type_object_for(PARROT_INTERP, PMC *HOW) {
3232
}
3333

3434
/* Creates a new instance based on the type object. */
35-
static PMC * allocate(PARROT_INTERP, PMC *st) {
35+
static PMC * allocate(PARROT_INTERP, STable *st) {
3636
P6numInstance *obj = mem_allocate_zeroed_typed(P6numInstance);
37-
obj->common.stable = st;
37+
obj->common.stable = st->stable_pmc;
3838
return wrap_object(interp, obj);
3939
}
4040

src/6model/reprs/P6opaque.c

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -369,20 +369,20 @@ static PMC * type_object_for(PARROT_INTERP, PMC *HOW) {
369369
}
370370

371371
/* Creates a new instance based on the type object. */
372-
static PMC * allocate(PARROT_INTERP, PMC *st) {
372+
static PMC * allocate(PARROT_INTERP, STable *st) {
373373
P6opaqueInstance * obj;
374374

375375
/* Compute allocation strategy if we've not already done so. */
376-
P6opaqueREPRData * repr_data = (P6opaqueREPRData *) STABLE_STRUCT(st)->REPR_data;
376+
P6opaqueREPRData * repr_data = (P6opaqueREPRData *) st->REPR_data;
377377
if (!repr_data->allocation_size) {
378-
compute_allocation_strategy(interp, STABLE_STRUCT(st)->WHAT, repr_data);
379-
PARROT_GC_WRITE_BARRIER(interp, st);
378+
compute_allocation_strategy(interp, st->WHAT, repr_data);
379+
PARROT_GC_WRITE_BARRIER(interp, st->stable_pmc);
380380
}
381381

382382
/* Allocate and set up object instance. */
383383
obj = (P6opaqueInstance *) Parrot_gc_allocate_fixed_size_storage(interp, repr_data->allocation_size);
384384
memset(obj, 0, repr_data->allocation_size);
385-
obj->common.stable = st;
385+
obj->common.stable = st->stable_pmc;
386386

387387
return wrap_object(interp, obj);
388388
}
@@ -418,21 +418,31 @@ static PMC * get_attribute_boxed(PARROT_INTERP, STable *st, void *data, PMC *cla
418418
slot = hint >= 0 && !(repr_data->mi) ? hint :
419419
try_get_slot(interp, repr_data, class_handle, name);
420420
if (slot >= 0) {
421-
PMC *result = get_pmc_at_offset(data, repr_data->attribute_offsets[slot]);
422-
if (result) {
423-
return result;
424-
}
425-
else {
426-
/* Maybe we know how to auto-viv it to a container. */
427-
if (repr_data->auto_viv_values) {
428-
PMC *value = repr_data->auto_viv_values[slot];
429-
if (value != NULL) {
430-
value = REPR(value)->clone(interp, value);
431-
set_pmc_at_offset(data, repr_data->attribute_offsets[slot], value);
432-
return value;
421+
if (!repr_data->flattened_stables[slot]) {
422+
PMC *result = get_pmc_at_offset(data, repr_data->attribute_offsets[slot]);
423+
if (result) {
424+
return result;
425+
}
426+
else {
427+
/* Maybe we know how to auto-viv it to a container. */
428+
if (repr_data->auto_viv_values) {
429+
PMC *value = repr_data->auto_viv_values[slot];
430+
if (value != NULL) {
431+
value = REPR(value)->clone(interp, value);
432+
set_pmc_at_offset(data, repr_data->attribute_offsets[slot], value);
433+
return value;
434+
}
433435
}
436+
return PMCNULL;
434437
}
435-
return PMCNULL;
438+
}
439+
else {
440+
/* Need to produce a boxed version of this attribute. */
441+
STable *st = repr_data->flattened_stables[slot];
442+
PMC *result = st->REPR->allocate(interp, st);
443+
st->REPR->copy_to(interp, st, (char *)data + repr_data->attribute_offsets[slot],
444+
OBJECT_BODY(result));
445+
return result;
436446
}
437447
}
438448

src/6model/reprs/P6str.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ static PMC * type_object_for(PARROT_INTERP, PMC *HOW) {
3232
}
3333

3434
/* Creates a new instance based on the type object. */
35-
static PMC * allocate(PARROT_INTERP, PMC *st) {
35+
static PMC * allocate(PARROT_INTERP, STable *st) {
3636
P6strInstance *obj = mem_allocate_zeroed_typed(P6strInstance);
37-
obj->common.stable = st;
37+
obj->common.stable = st->stable_pmc;
3838
return wrap_object(interp, obj);
3939
}
4040

src/6model/reprs/Uninstantiable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static PMC * type_object_for(PARROT_INTERP, PMC *HOW) {
3232
}
3333

3434
/* Creates a new instance based on the type object. */
35-
static PMC * allocate(PARROT_INTERP, PMC *st) {
35+
static PMC * allocate(PARROT_INTERP, STable *st) {
3636
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
3737
"You cannot create an instance of this type");
3838
}

src/6model/sixmodelobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ PMC * create_stable(PARROT_INTERP, REPROps *REPR, PMC *HOW) {
163163
STABLE_STRUCT(st_pmc)->WHO = PMCNULL;
164164
STABLE_STRUCT(st_pmc)->find_method = default_find_method;
165165
STABLE_STRUCT(st_pmc)->type_check = default_type_check;
166+
STABLE_STRUCT(st_pmc)->stable_pmc = st_pmc;
166167
return st_pmc;
167168
}
168169

src/6model/sixmodelobject.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ typedef struct {
132132

133133
/* Parrot-specific set of v-table to object method mappings. */
134134
AttributeIdentifier *parrot_vtable_handler_mapping;
135+
136+
/* The PMC that wraps this s-table. */
137+
PMC *stable_pmc;
135138
} STable;
136139

137140
/* A representation is what controls the layout of an object and storage of
@@ -152,7 +155,7 @@ struct SixModel_REPROps {
152155

153156
/* Allocates a new, but uninitialized object, based on the
154157
* specified s-table. */
155-
PMC * (*allocate) (PARROT_INTERP, PMC *stable_pmc);
158+
PMC * (*allocate) (PARROT_INTERP, STable *st);
156159

157160
/* Used to initialize the body of an object representing the type
158161
* describe by the specified s-table. DATA points to the body. It

0 commit comments

Comments
 (0)