Skip to content

Commit a76cd8b

Browse files
committed
Switch normal attribute binding over to the new REPR API.
1 parent 8f536de commit a76cd8b

File tree

10 files changed

+62
-37
lines changed

10 files changed

+62
-37
lines changed

src/6model/reprs/HashAttrStore.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,9 @@ static void * get_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *clas
6464
}
6565

6666
/* Binds the given value to the specified attribute. */
67-
static void bind_attribute(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
68-
HashAttrStoreInstance *instance = (HashAttrStoreInstance *)PMC_data(obj);
69-
if (!instance->body.store)
70-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
71-
"Cannot access attributes in a type object");
72-
VTABLE_set_pmc_keyed_str(interp, instance->body.store, name, value);
67+
static void bind_attribute_boxed(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
68+
HashAttrStoreBody *body = (HashAttrStoreBody *)data;
69+
VTABLE_set_pmc_keyed_str(interp, body->store, name, value);
7370
}
7471
static void bind_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint, void *value) {
7572
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
@@ -176,7 +173,7 @@ REPROps * HashAttrStore_initialize(PARROT_INTERP) {
176173
this_repr->copy_to = copy_to;
177174
this_repr->get_attribute_boxed = get_attribute_boxed;
178175
this_repr->get_attribute_ref = get_attribute_ref;
179-
this_repr->bind_attribute = bind_attribute;
176+
this_repr->bind_attribute_boxed = bind_attribute_boxed;
180177
this_repr->bind_attribute_ref = bind_attribute_ref;
181178
this_repr->hint_for = hint_for;
182179
this_repr->clone = repr_clone;

src/6model/reprs/KnowHOWREPR.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static void * get_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *clas
7474
}
7575

7676
/* Binds the given value to the specified attribute. */
77-
static void bind_attribute(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
77+
static void bind_attribute_boxed(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
7878
die_no_attrs(interp);
7979
}
8080
static void bind_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint, void *value) {
@@ -178,7 +178,7 @@ REPROps * KnowHOWREPR_initialize(PARROT_INTERP) {
178178
this_repr->copy_to = copy_to;
179179
this_repr->get_attribute_boxed = get_attribute_boxed;
180180
this_repr->get_attribute_ref = get_attribute_ref;
181-
this_repr->bind_attribute = bind_attribute;
181+
this_repr->bind_attribute_boxed = bind_attribute_boxed;
182182
this_repr->bind_attribute_ref = bind_attribute_ref;
183183
this_repr->hint_for = hint_for;
184184
this_repr->clone = repr_clone;

src/6model/reprs/P6int.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static void * get_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *clas
6666
}
6767

6868
/* Binds the given value to the specified attribute. */
69-
static void bind_attribute(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
69+
static void bind_attribute_boxed(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
7070
die_no_attrs(interp);
7171
}
7272
static void bind_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint, void *value) {
@@ -157,7 +157,7 @@ REPROps * P6int_initialize(PARROT_INTERP) {
157157
this_repr->copy_to = copy_to;
158158
this_repr->get_attribute_boxed = get_attribute_boxed;
159159
this_repr->get_attribute_ref = get_attribute_ref;
160-
this_repr->bind_attribute = bind_attribute;
160+
this_repr->bind_attribute_boxed = bind_attribute_boxed;
161161
this_repr->bind_attribute_ref = bind_attribute_ref;
162162
this_repr->hint_for = hint_for;
163163
this_repr->clone = repr_clone;

src/6model/reprs/P6num.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static void * get_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *clas
6767
}
6868

6969
/* Binds the given value to the specified attribute. */
70-
static void bind_attribute(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
70+
static void bind_attribute_boxed(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
7171
die_no_attrs(interp);
7272
}
7373
static void bind_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint, void *value) {
@@ -158,7 +158,7 @@ REPROps * P6num_initialize(PARROT_INTERP) {
158158
this_repr->copy_to = copy_to;
159159
this_repr->get_attribute_boxed = get_attribute_boxed;
160160
this_repr->get_attribute_ref = get_attribute_ref;
161-
this_repr->bind_attribute = bind_attribute;
161+
this_repr->bind_attribute_boxed = bind_attribute_boxed;
162162
this_repr->bind_attribute_ref = bind_attribute_ref;
163163
this_repr->hint_for = hint_for;
164164
this_repr->clone = repr_clone;

src/6model/reprs/P6opaque.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -466,21 +466,29 @@ static void * get_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *clas
466466

467467

468468
/* Binds the given value to the specified attribute. */
469-
static void bind_attribute(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
470-
P6opaqueInstance *instance = (P6opaqueInstance *)PMC_data(obj);
471-
P6opaqueREPRData *repr_data = (P6opaqueREPRData *)STABLE(obj)->REPR_data;
469+
static void bind_attribute_boxed(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
470+
P6opaqueREPRData *repr_data = (P6opaqueREPRData *)st->REPR_data;
472471
INTVAL slot;
473472

474-
/* Ensure it is a defined object. */
475-
if (PObj_flag_TEST(private0, obj))
476-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
477-
"Cannot access attributes in a type object");
478-
479473
/* Try the slot allocation first. */
480474
slot = hint >= 0 && !(repr_data->mi) ? hint :
481475
try_get_slot(interp, repr_data, class_handle, name);
482476
if (slot >= 0) {
483-
set_pmc_at_offset(instance, sizeof(P6opaqueInstance) + repr_data->attribute_offsets[slot], value);
477+
STable *st = repr_data->flattened_stables[slot];
478+
if (st) {
479+
if (st == STABLE(value))
480+
st->REPR->copy_to(interp, st, OBJECT_BODY(value),
481+
(char *)data + repr_data->attribute_offsets[slot]);
482+
else
483+
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
484+
"Type mismatch when storing value to attribute '%Ss' on class '%Ss'",
485+
name, VTABLE_get_string(interp, introspection_call(interp,
486+
class_handle, STABLE(class_handle)->HOW,
487+
Parrot_str_new_constant(interp, "name"), 0)));
488+
}
489+
else {
490+
set_pmc_at_offset(data, repr_data->attribute_offsets[slot], value);
491+
}
484492
}
485493
else {
486494
/* Otherwise, complain that the attribute doesn't exist. */
@@ -810,7 +818,7 @@ REPROps * P6opaque_initialize(PARROT_INTERP) {
810818
this_repr->copy_to = copy_to;
811819
this_repr->get_attribute_boxed = get_attribute_boxed;
812820
this_repr->get_attribute_ref = get_attribute_ref;
813-
this_repr->bind_attribute = bind_attribute;
821+
this_repr->bind_attribute_boxed = bind_attribute_boxed;
814822
this_repr->bind_attribute_ref = bind_attribute_ref;
815823
this_repr->hint_for = hint_for;
816824
this_repr->clone = repr_clone;

src/6model/reprs/P6str.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static void * get_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *clas
6767
}
6868

6969
/* Binds the given value to the specified attribute. */
70-
static void bind_attribute(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
70+
static void bind_attribute_boxed(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
7171
die_no_attrs(interp);
7272
}
7373
static void bind_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint, void *value) {
@@ -165,7 +165,7 @@ REPROps * P6str_initialize(PARROT_INTERP) {
165165
this_repr->copy_to = copy_to;
166166
this_repr->get_attribute_boxed = get_attribute_boxed;
167167
this_repr->get_attribute_ref = get_attribute_ref;
168-
this_repr->bind_attribute = bind_attribute;
168+
this_repr->bind_attribute_boxed = bind_attribute_boxed;
169169
this_repr->bind_attribute_ref = bind_attribute_ref;
170170
this_repr->hint_for = hint_for;
171171
this_repr->clone = repr_clone;

src/6model/reprs/Uninstantiable.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static STRING * get_attribute_str(PARROT_INTERP, PMC *obj, PMC *class_handle, ST
7373
}
7474

7575
/* Binds the given value to the specified attribute. */
76-
static void bind_attribute(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
76+
static void bind_attribute_boxed(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
7777
die_no_attrs(interp);
7878
}
7979
static void bind_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint, void *value) {
@@ -164,7 +164,7 @@ REPROps * Uninstantiable_initialize(PARROT_INTERP) {
164164
this_repr->copy_to = copy_to;
165165
this_repr->get_attribute_boxed = get_attribute_boxed;
166166
this_repr->get_attribute_ref = get_attribute_ref;
167-
this_repr->bind_attribute = bind_attribute;
167+
this_repr->bind_attribute_boxed = bind_attribute_boxed;
168168
this_repr->bind_attribute_ref = bind_attribute_ref;
169169
this_repr->hint_for = hint_for;
170170
this_repr->clone = repr_clone;

src/6model/sixmodelobject.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,12 @@ struct SixModel_REPROps {
181181
void * (*get_attribute_ref) (PARROT_INTERP, STable *st, void *data,
182182
PMC *class_handle, STRING *name, INTVAL hint);
183183

184-
/* Binds the given object value to the specified attribute. */
185-
void (*bind_attribute) (PARROT_INTERP, PMC *Object, PMC *ClassHandle, STRING *Name, INTVAL Hint, PMC *Value);
184+
/* Binds the given object value to the specified attribute. If it's
185+
* a reference type attribute, this just simply sets the value in
186+
* place. If instead it's some other flattened in representation, then
187+
* the value should be a boxed form of the data to store.*/
188+
void (*bind_attribute_boxed) (PARROT_INTERP, STable *st, void *data,
189+
PMC *class_handle, STRING *name, INTVAL hint, PMC *value);
186190

187191
/* Binds a flattened in attribute to the value at the passed reference.
188192
* Like with the get_attribute_ref function, presumably the thing calling

src/ops/nqp.ops

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,17 @@ an object - the repr is not obligated to do boxing/unboxing for you.
354354
*/
355355
inline op repr_bind_attr_obj(in PMC, in PMC, in STR, in PMC) :base_core {
356356
PMC *ch = decontainerize(interp, $2);
357-
if ($1->vtable->base_type == smo_id)
358-
REPR($1)->bind_attribute(interp, $1, ch, $3, NO_HINT, $4);
359-
else
357+
if ($1->vtable->base_type == smo_id) {
358+
if (IS_CONCRETE($1))
359+
REPR($1)->bind_attribute_boxed(interp, STABLE($1), OBJECT_BODY($1), ch, $3, NO_HINT, $4);
360+
else
361+
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
362+
"Cannot bind to attributes in a type object");
363+
}
364+
else {
360365
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
361366
"Can only use repr_bind_attr_obj on a SixModelObject");
367+
}
362368
PARROT_GC_WRITE_BARRIER(interp, $1);
363369
}
364370

@@ -549,11 +555,17 @@ an object - the repr is not obligated to do boxing/unboxing for you.
549555
*/
550556
inline op repr_bind_attr_obj(in PMC, in PMC, in STR, in INT, in PMC) :base_core {
551557
PMC *ch = decontainerize(interp, $2);
552-
if ($1->vtable->base_type == smo_id)
553-
REPR($1)->bind_attribute(interp, $1, ch, $3, $4, $5);
554-
else
558+
if ($1->vtable->base_type == smo_id) {
559+
if (IS_CONCRETE($1))
560+
REPR($1)->bind_attribute_boxed(interp, STABLE($1), OBJECT_BODY($1), ch, $3, $4, $5);
561+
else
562+
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
563+
"Cannot bind to attributes in a type object");
564+
}
565+
else {
555566
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
556567
"Can only use repr_bind_attr_obj on a SixModelObject");
568+
}
557569
PARROT_GC_WRITE_BARRIER(interp, $1);
558570
}
559571

src/pmc/sixmodelobject.pmc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,13 @@ pmclass SixModelObject manual_attrs dynpmc group nqp {
9797
return get_attr(interp, SELF, handle, name, NO_HINT);
9898
}
9999

100-
VTABLE void set_attr_keyed(PMC *class_handle, STRING *name, PMC* value) {
100+
VTABLE void set_attr_keyed(PMC *class_handle, STRING *name, PMC *value) {
101101
PMC *handle = decontainerize(interp, class_handle);
102-
REPR(SELF)->bind_attribute(interp, SELF, handle, name, NO_HINT, value);
102+
if (IS_CONCRETE(SELF))
103+
REPR(SELF)->bind_attribute_boxed(interp, STABLE(SELF), OBJECT_BODY(SELF), handle, name, NO_HINT, value);
104+
else
105+
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
106+
"Cannot bind attributes in a type object");
103107
}
104108

105109
VTABLE STRING * name() {

0 commit comments

Comments
 (0)