Skip to content

Commit 2395763

Browse files
committed
Implement get_boxed_ref in P6opaque.
1 parent 1b2781c commit 2395763

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/6model/reprs/P6opaque.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ static void compute_allocation_strategy(PARROT_INTERP, PMC *WHAT, P6opaqueREPRDa
189189
INTVAL cur_init_slot = 0;
190190
INTVAL cur_mark_slot = 0;
191191
INTVAL cur_cleanup_slot = 0;
192+
INTVAL cur_unbox_slot = 0;
192193
INTVAL i;
193194

194195
/* Allocate offset array and GC mark info arrays. */
@@ -244,6 +245,7 @@ static void compute_allocation_strategy(PARROT_INTERP, PMC *WHAT, P6opaqueREPRDa
244245

245246
/* Is it a target for box/unbox operations? */
246247
if (!PMC_IS_NULL(box_target) && VTABLE_get_bool(interp, box_target)) {
248+
/* If it boxes a primitive, note that. */
247249
switch (unboxed_type) {
248250
case STORAGE_SPEC_BP_INT:
249251
if (repr_data->unbox_int_slot >= 0)
@@ -264,9 +266,16 @@ static void compute_allocation_strategy(PARROT_INTERP, PMC *WHAT, P6opaqueREPRDa
264266
repr_data->unbox_str_slot = i;
265267
break;
266268
default:
267-
/* nothing, just suppress 'missing default' warning */
269+
/* nothing, just suppress 'missing default' warning */
268270
break;
269271
}
272+
273+
/* Also list in the by-repr unbox list. */
274+
if (repr_data->unbox_slots == NULL)
275+
repr_data->unbox_slots = (P6opaqueBoxedTypeMap *) mem_sys_allocate_zeroed(info_alloc * sizeof(P6opaqueBoxedTypeMap));
276+
repr_data->unbox_slots[cur_unbox_slot].repr_id = REPR(type)->ID;
277+
repr_data->unbox_slots[cur_unbox_slot].slot = i;
278+
cur_unbox_slot++;
270279
}
271280
}
272281
}
@@ -657,8 +666,18 @@ static STRING * get_str(PARROT_INTERP, STable *st, void *data) {
657666
* gets the reference to such things, using the representation ID to distinguish
658667
* them. */
659668
static void * get_boxed_ref(PARROT_INTERP, STable *st, void *data, INTVAL repr_id) {
669+
P6opaqueREPRData *repr_data = (P6opaqueREPRData *)st->REPR_data;
670+
if (repr_data->unbox_slots) {
671+
INTVAL i;
672+
for (i = 0; i < repr_data->num_attributes; i++)
673+
if (repr_data->unbox_slots[i].repr_id == repr_id)
674+
return (char *)data + repr_data->attribute_offsets[repr_data->unbox_slots[i].slot];
675+
else if (repr_data->unbox_slots[i].repr_id == 0)
676+
break;
677+
}
660678
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
661-
"get_boxed_ref NYI in P6opaque");
679+
"get_boxed_ref could not unbox for the given representation");
680+
return NULL;
662681
}
663682

664683
/* This Parrot-specific addition to the API is used to mark an object. */

src/6model/reprs/P6opaque.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ typedef struct {
1818
PMC *name_map;
1919
} P6opaqueNameMap;
2020

21+
/* This is used in boxed type mappings. */
22+
typedef struct {
23+
INTVAL repr_id;
24+
INTVAL slot;
25+
} P6opaqueBoxedTypeMap;
26+
2127
/* The P6opaque REPR data has the slot mapping, allocation size and
2228
* various other bits of info. It hangs off the REPR_data pointer
2329
* in the s-table. */
@@ -54,6 +60,9 @@ typedef struct {
5460

5561
/* Slot to delegate to when we need to unbox to a native string. */
5662
INTVAL unbox_str_slot;
63+
64+
/* If we have any other boxings, this maps repr ID to slot. */
65+
P6opaqueBoxedTypeMap *unbox_slots;
5766

5867
/* A table mapping attribute names to indexes (which can then be looked
5968
* up in the offset table). Uses a final null entry as a sentinel. */

0 commit comments

Comments
 (0)