Skip to content

Commit 5cb979a

Browse files
committed
Replace all value type attribute lookups with a common approach; this means we'll be able to use it for getting hold of more complex nested value types too.
1 parent 4f25688 commit 5cb979a

File tree

9 files changed

+27
-134
lines changed

9 files changed

+27
-134
lines changed

src/6model/reprs/HashAttrStore.c

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,9 @@ static PMC * get_attribute(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *n
5454
"Cannot access attributes in a type object");
5555
return VTABLE_get_pmc_keyed_str(interp, instance->body.store, name);
5656
}
57-
static INTVAL get_attribute_int(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
57+
static void * get_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint) {
5858
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
59-
"HashAttrStore representation does not support native attribute storage");
60-
}
61-
static FLOATVAL get_attribute_num(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
62-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
63-
"HashAttrStore representation does not support native attribute storage");
64-
}
65-
static STRING * get_attribute_str(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
66-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
67-
"HashAttrStore representation does not support native attribute storage");
59+
"HashAttrStore representation does not support value type attributes");
6860
}
6961

7062
/* Binds the given value to the specified attribute. */
@@ -186,9 +178,7 @@ REPROps * HashAttrStore_initialize(PARROT_INTERP) {
186178
this_repr->allocate = allocate;
187179
this_repr->initialize = initialize;
188180
this_repr->get_attribute = get_attribute;
189-
this_repr->get_attribute_int = get_attribute_int;
190-
this_repr->get_attribute_num = get_attribute_num;
191-
this_repr->get_attribute_str = get_attribute_str;
181+
this_repr->get_attribute_ref = get_attribute_ref;
192182
this_repr->bind_attribute = bind_attribute;
193183
this_repr->bind_attribute_int = bind_attribute_int;
194184
this_repr->bind_attribute_num = bind_attribute_num;

src/6model/reprs/KnowHOWREPR.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,10 @@ static PMC * get_attribute(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *n
5858
die_no_attrs(interp);
5959
return PMCNULL;
6060
}
61-
static INTVAL get_attribute_int(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
61+
static void * get_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint) {
6262
die_no_attrs(interp);
6363
return 0;
6464
}
65-
static FLOATVAL get_attribute_num(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
66-
die_no_attrs(interp);
67-
return 0.0;
68-
}
69-
static STRING * get_attribute_str(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
70-
die_no_attrs(interp);
71-
return NULL;
72-
}
7365

7466
/* Binds the given value to the specified attribute. */
7567
static void bind_attribute(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
@@ -180,9 +172,7 @@ REPROps * KnowHOWREPR_initialize(PARROT_INTERP) {
180172
this_repr->allocate = allocate;
181173
this_repr->initialize = initialize;
182174
this_repr->get_attribute = get_attribute;
183-
this_repr->get_attribute_int = get_attribute_int;
184-
this_repr->get_attribute_num = get_attribute_num;
185-
this_repr->get_attribute_str = get_attribute_str;
175+
this_repr->get_attribute_ref = get_attribute_ref;
186176
this_repr->bind_attribute = bind_attribute;
187177
this_repr->bind_attribute_int = bind_attribute_int;
188178
this_repr->bind_attribute_num = bind_attribute_num;

src/6model/reprs/P6int.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,10 @@ static PMC * get_attribute(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *n
5555
die_no_attrs(interp);
5656
return PMCNULL;
5757
}
58-
static INTVAL get_attribute_int(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
58+
static void * get_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint) {
5959
die_no_attrs(interp);
6060
return 0;
6161
}
62-
static FLOATVAL get_attribute_num(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
63-
die_no_attrs(interp);
64-
return 0.0;
65-
}
66-
static STRING * get_attribute_str(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
67-
die_no_attrs(interp);
68-
return NULL;
69-
}
7062

7163
/* Binds the given value to the specified attribute. */
7264
static void bind_attribute(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
@@ -164,9 +156,7 @@ REPROps * P6int_initialize(PARROT_INTERP) {
164156
this_repr->allocate = allocate;
165157
this_repr->initialize = initialize;
166158
this_repr->get_attribute = get_attribute;
167-
this_repr->get_attribute_int = get_attribute_int;
168-
this_repr->get_attribute_num = get_attribute_num;
169-
this_repr->get_attribute_str = get_attribute_str;
159+
this_repr->get_attribute_ref = get_attribute_ref;
170160
this_repr->bind_attribute = bind_attribute;
171161
this_repr->bind_attribute_int = bind_attribute_int;
172162
this_repr->bind_attribute_num = bind_attribute_num;

src/6model/reprs/P6num.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,10 @@ static PMC * get_attribute(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *n
5656
die_no_attrs(interp);
5757
return PMCNULL;
5858
}
59-
static INTVAL get_attribute_int(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
59+
static void * get_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint) {
6060
die_no_attrs(interp);
6161
return 0;
6262
}
63-
static FLOATVAL get_attribute_num(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
64-
die_no_attrs(interp);
65-
return 0.0;
66-
}
67-
static STRING * get_attribute_str(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
68-
die_no_attrs(interp);
69-
return NULL;
70-
}
7163

7264
/* Binds the given value to the specified attribute. */
7365
static void bind_attribute(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
@@ -165,9 +157,7 @@ REPROps * P6num_initialize(PARROT_INTERP) {
165157
this_repr->allocate = allocate;
166158
this_repr->initialize = initialize;
167159
this_repr->get_attribute = get_attribute;
168-
this_repr->get_attribute_int = get_attribute_int;
169-
this_repr->get_attribute_num = get_attribute_num;
170-
this_repr->get_attribute_str = get_attribute_str;
160+
this_repr->get_attribute_ref = get_attribute_ref;
171161
this_repr->bind_attribute = bind_attribute;
172162
this_repr->bind_attribute_int = bind_attribute_int;
173163
this_repr->bind_attribute_num = bind_attribute_num;

src/6model/reprs/P6opaque.c

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -435,65 +435,20 @@ static PMC * get_attribute(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *n
435435
no_such_attribute(interp, "get", class_handle, name);
436436
}
437437

438-
static INTVAL get_attribute_int(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
439-
P6opaqueInstance *instance = (P6opaqueInstance *)PMC_data(obj);
440-
P6opaqueREPRData *repr_data = (P6opaqueREPRData *)STABLE(obj)->REPR_data;
438+
static void * get_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint) {
439+
P6opaqueREPRData *repr_data = (P6opaqueREPRData *)st->REPR_data;
441440
INTVAL slot;
442441

443-
/* Ensure it is a defined object. */
444-
if (PObj_flag_TEST(private0, obj))
445-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
446-
"Cannot access attributes in a type object");
447-
448-
/* Try the slot allocation first. */
442+
/* Look up slot, then offset and compute address. */
449443
slot = hint >= 0 && !(repr_data->mi) ? hint :
450444
try_get_slot(interp, repr_data, class_handle, name);
451445
if (slot >= 0)
452-
return get_int_at_offset(instance, sizeof(P6opaqueInstance) + repr_data->attribute_offsets[slot]);
446+
return ((char *)data) + repr_data->attribute_offsets[slot];
453447

454448
/* Otherwise, complain that the attribute doesn't exist. */
455449
no_such_attribute(interp, "get", class_handle, name);
456450
}
457-
static FLOATVAL get_attribute_num(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
458-
P6opaqueInstance *instance = (P6opaqueInstance *)PMC_data(obj);
459-
P6opaqueREPRData *repr_data = (P6opaqueREPRData *)STABLE(obj)->REPR_data;
460-
INTVAL slot;
461-
462-
/* Ensure it is a defined object. */
463-
if (PObj_flag_TEST(private0, obj))
464-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
465-
"Cannot access attributes in a type object");
466451

467-
/* Try the slot allocation first. */
468-
slot = hint >= 0 && !(repr_data->mi) ? hint :
469-
try_get_slot(interp, repr_data, class_handle, name);
470-
if (slot >= 0)
471-
return get_num_at_offset(instance, sizeof(P6opaqueInstance) + repr_data->attribute_offsets[slot]);
472-
473-
/* Otherwise, complain that the attribute doesn't exist. */
474-
no_such_attribute(interp, "get", class_handle, name);
475-
}
476-
static STRING * get_attribute_str(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
477-
P6opaqueInstance *instance = (P6opaqueInstance *)PMC_data(obj);
478-
P6opaqueREPRData *repr_data = (P6opaqueREPRData *)STABLE(obj)->REPR_data;
479-
INTVAL slot;
480-
481-
/* Ensure it is a defined object. */
482-
if (PObj_flag_TEST(private0, obj))
483-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
484-
"Cannot access attributes in a type object");
485-
486-
/* Try the slot allocation first. */
487-
slot = hint >= 0 && !(repr_data->mi) ? hint :
488-
try_get_slot(interp, repr_data, class_handle, name);
489-
if (slot >= 0) {
490-
STRING *result = get_str_at_offset(instance, sizeof(P6opaqueInstance) + repr_data->attribute_offsets[slot]);
491-
return result ? result : STRINGNULL;
492-
}
493-
494-
/* Otherwise, complain that the attribute doesn't exist. */
495-
no_such_attribute(interp, "get", class_handle, name);
496-
}
497452

498453
/* Binds the given value to the specified attribute. */
499454
static void bind_attribute(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
@@ -873,9 +828,7 @@ REPROps * P6opaque_initialize(PARROT_INTERP) {
873828
this_repr->allocate = allocate;
874829
this_repr->initialize = initialize;
875830
this_repr->get_attribute = get_attribute;
876-
this_repr->get_attribute_int = get_attribute_int;
877-
this_repr->get_attribute_num = get_attribute_num;
878-
this_repr->get_attribute_str = get_attribute_str;
831+
this_repr->get_attribute_ref = get_attribute_ref;
879832
this_repr->bind_attribute = bind_attribute;
880833
this_repr->bind_attribute_int = bind_attribute_int;
881834
this_repr->bind_attribute_num = bind_attribute_num;

src/6model/reprs/P6str.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,7 @@ static PMC * get_attribute(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *n
5555
die_no_attrs(interp);
5656
return PMCNULL;
5757
}
58-
static INTVAL get_attribute_int(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
59-
die_no_attrs(interp);
60-
return 0;
61-
}
62-
static FLOATVAL get_attribute_num(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
63-
die_no_attrs(interp);
64-
return 0.0;
65-
}
66-
static STRING * get_attribute_str(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
58+
static void * get_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint) {
6759
die_no_attrs(interp);
6860
return NULL;
6961
}
@@ -171,9 +163,7 @@ REPROps * P6str_initialize(PARROT_INTERP) {
171163
this_repr->allocate = allocate;
172164
this_repr->initialize = initialize;
173165
this_repr->get_attribute = get_attribute;
174-
this_repr->get_attribute_int = get_attribute_int;
175-
this_repr->get_attribute_num = get_attribute_num;
176-
this_repr->get_attribute_str = get_attribute_str;
166+
this_repr->get_attribute_ref = get_attribute_ref;
177167
this_repr->bind_attribute = bind_attribute;
178168
this_repr->bind_attribute_int = bind_attribute_int;
179169
this_repr->bind_attribute_num = bind_attribute_num;

src/6model/reprs/Uninstantiable.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ static PMC * get_attribute(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *n
5454
die_no_attrs(interp);
5555
return PMCNULL;
5656
}
57-
static INTVAL get_attribute_int(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
57+
static void * get_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint) {
5858
die_no_attrs(interp);
59-
return 0;
59+
return NULL;
6060
}
6161
static FLOATVAL get_attribute_num(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
6262
die_no_attrs(interp);
@@ -163,9 +163,7 @@ REPROps * Uninstantiable_initialize(PARROT_INTERP) {
163163
this_repr->allocate = allocate;
164164
this_repr->initialize = initialize;
165165
this_repr->get_attribute = get_attribute;
166-
this_repr->get_attribute_int = get_attribute_int;
167-
this_repr->get_attribute_num = get_attribute_num;
168-
this_repr->get_attribute_str = get_attribute_str;
166+
this_repr->get_attribute_ref = get_attribute_ref;
169167
this_repr->bind_attribute = bind_attribute;
170168
this_repr->bind_attribute_int = bind_attribute_int;
171169
this_repr->bind_attribute_num = bind_attribute_num;

src/6model/sixmodelobject.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,10 @@ struct SixModel_REPROps {
162162
/* Gets the current value for an object attribute. */
163163
PMC * (*get_attribute) (PARROT_INTERP, PMC *Object, PMC *ClassHandle, STRING *Name, INTVAL Hint);
164164

165-
/* Gets the current value for a native int attribute. */
166-
INTVAL (*get_attribute_int) (PARROT_INTERP, PMC *Object, PMC *ClassHandle, STRING *Name, INTVAL Hint);
167-
168-
/* Gets the current value for a native num attribute. */
169-
FLOATVAL (*get_attribute_num) (PARROT_INTERP, PMC *Object, PMC *ClassHandle, STRING *Name, INTVAL Hint);
170-
171-
/* Gets the current value for a native str attribute. */
172-
STRING * (*get_attribute_str) (PARROT_INTERP, PMC *Object, PMC *ClassHandle, STRING *Name, INTVAL Hint);
173-
174165
/* Gets a reference to the memory location of an attribute. Note
175166
* that this is only valid so long as the object itself is alive. */
176-
void * (*get_attribute_ref) (PARROT_INTERP, PMC *Object, PMC *ClassHandle, STRING *Name, INTVAL Hint);
167+
void * (*get_attribute_ref) (PARROT_INTERP, STable *st, void *data,
168+
PMC *class_handle, STRING *name, INTVAL hint);
177169

178170
/* Binds the given object value to the specified attribute. */
179171
void (*bind_attribute) (PARROT_INTERP, PMC *Object, PMC *ClassHandle, STRING *Name, INTVAL Hint, PMC *Value);

src/ops/nqp.ops

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ a native int - the repr is not obligated to do boxing/unboxing for you.
275275
inline op repr_get_attr_int(out INT, in PMC, in PMC, in STR) :base_core {
276276
PMC *ch = decontainerize(interp, $3);
277277
if ($2->vtable->base_type == smo_id)
278-
$1 = REPR($2)->get_attribute_int(interp, $2, ch, $4, NO_HINT);
278+
$1 = *((INTVAL *)REPR($2)->get_attribute_ref(interp, STABLE($2), OBJECT_BODY($2), ch, $4, NO_HINT));
279279
else
280280
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
281281
"Can only use repr_get_attr_int on a SixModelObject");
@@ -294,7 +294,7 @@ a native num - the repr is not obligated to do boxing/unboxing for you.
294294
inline op repr_get_attr_num(out NUM, in PMC, in PMC, in STR) :base_core {
295295
PMC *ch = decontainerize(interp, $3);
296296
if ($2->vtable->base_type == smo_id)
297-
$1 = REPR($2)->get_attribute_num(interp, $2, ch, $4, NO_HINT);
297+
$1 = *((FLOATVAL *)REPR($2)->get_attribute_ref(interp, STABLE($2), OBJECT_BODY($2), ch, $4, NO_HINT));
298298
else
299299
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
300300
"Can only use repr_get_attr_num on a SixModelObject");
@@ -313,7 +313,7 @@ a native str - the repr is not obligated to do boxing/unboxing for you.
313313
inline op repr_get_attr_str(out STR, in PMC, in PMC, in STR) :base_core {
314314
PMC *ch = decontainerize(interp, $3);
315315
if ($2->vtable->base_type == smo_id)
316-
$1 = REPR($2)->get_attribute_str(interp, $2, ch, $4, NO_HINT);
316+
$1 = *((STRING **)REPR($2)->get_attribute_ref(interp, STABLE($2), OBJECT_BODY($2), ch, $4, NO_HINT));
317317
else
318318
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
319319
"Can only use repr_get_attr_str on a SixModelObject");
@@ -429,7 +429,7 @@ a native int - the repr is not obligated to do boxing/unboxing for you.
429429
inline op repr_get_attr_int(out INT, in PMC, in PMC, in STR, in INT) :base_core {
430430
PMC *ch = decontainerize(interp, $3);
431431
if ($2->vtable->base_type == smo_id)
432-
$1 = REPR($2)->get_attribute_int(interp, $2, ch, $4, $5);
432+
$1 = *((INTVAL *)REPR($2)->get_attribute_ref(interp, STABLE($2), OBJECT_BODY($2), ch, $4, $5));
433433
else
434434
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
435435
"Can only use repr_get_attr_int on a SixModelObject");
@@ -448,7 +448,7 @@ a native num - the repr is not obligated to do boxing/unboxing for you.
448448
inline op repr_get_attr_num(out NUM, in PMC, in PMC, in STR, in INT) :base_core {
449449
PMC *ch = decontainerize(interp, $3);
450450
if ($2->vtable->base_type == smo_id)
451-
$1 = REPR($2)->get_attribute_num(interp, $2, ch, $4, $5);
451+
$1 = *((FLOATVAL *)REPR($2)->get_attribute_ref(interp, STABLE($2), OBJECT_BODY($2), ch, $4, $5));
452452
else
453453
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
454454
"Can only use repr_get_attr_num on a SixModelObject");
@@ -467,7 +467,7 @@ a native str - the repr is not obligated to do boxing/unboxing for you.
467467
inline op repr_get_attr_str(out STR, in PMC, in PMC, in STR, in INT) :base_core {
468468
PMC *ch = decontainerize(interp, $3);
469469
if ($2->vtable->base_type == smo_id)
470-
$1 = REPR($2)->get_attribute_str(interp, $2, ch, $4, $5);
470+
$1 = *((STRING **)REPR($2)->get_attribute_ref(interp, STABLE($2), OBJECT_BODY($2), ch, $4, $5));
471471
else
472472
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
473473
"Can only use repr_get_attr_str on a SixModelObject");

0 commit comments

Comments
 (0)