Skip to content

Commit 851deb3

Browse files
committed
Initial attempt to update representations for the sub-table change. Many bits of copy-paste boilerplate go away.
1 parent 139fb76 commit 851deb3

File tree

11 files changed

+96
-746
lines changed

11 files changed

+96
-746
lines changed

src/6model/reprs/CPointer.c

Lines changed: 2 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -51,84 +51,6 @@ static void copy_to(PARROT_INTERP, STable *st, void *src, void *dest) {
5151
dest_body->ptr = src_body->ptr;
5252
}
5353

54-
/* Helper to die because this type doesn't support attributes. */
55-
PARROT_DOES_NOT_RETURN
56-
static void die_no_attrs(PARROT_INTERP) {
57-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
58-
"CPointer representation does not support attribute storage");
59-
}
60-
61-
/* Gets the current value for an attribute. */
62-
static PMC * get_attribute_boxed(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint) {
63-
die_no_attrs(interp);
64-
}
65-
static void * get_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint) {
66-
die_no_attrs(interp);
67-
}
68-
69-
/* Binds the given value to the specified attribute. */
70-
static void bind_attribute_boxed(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint, PMC *value) {
71-
die_no_attrs(interp);
72-
}
73-
static void bind_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint, void *value) {
74-
die_no_attrs(interp);
75-
}
76-
77-
/* Gets the hint for the given attribute ID. */
78-
static INTVAL hint_for(PARROT_INTERP, STable *st, PMC *class_handle, STRING *name) {
79-
return NO_HINT;
80-
}
81-
82-
/* Used with boxing. Sets an integer value, for representations that can hold
83-
* one. */
84-
static void set_int(PARROT_INTERP, STable *st, void *data, INTVAL value) {
85-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
86-
"CPointer cannot box a native int");
87-
}
88-
89-
/* Used with boxing. Gets an integer value, for representations that can
90-
* hold one. */
91-
static INTVAL get_int(PARROT_INTERP, STable *st, void *data) {
92-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
93-
"CPointer cannot unbox to a native int");
94-
}
95-
96-
/* Used with boxing. Sets a floating point value, for representations that can
97-
* hold one. */
98-
static void set_num(PARROT_INTERP, STable *st, void *data, FLOATVAL value) {
99-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
100-
"CPointer cannot box a native num");
101-
}
102-
103-
/* Used with boxing. Gets a floating point value, for representations that can
104-
* hold one. */
105-
static FLOATVAL get_num(PARROT_INTERP, STable *st, void *data) {
106-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
107-
"CPointer cannot unbox to a native num");
108-
}
109-
110-
/* Used with boxing. Sets a string value, for representations that can hold
111-
* one. */
112-
static void set_str(PARROT_INTERP, STable *st, void *data, STRING *value) {
113-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
114-
"CPointer cannot box a native string");
115-
}
116-
117-
/* Used with boxing. Gets a string value, for representations that can hold
118-
* one. */
119-
static STRING * get_str(PARROT_INTERP, STable *st, void *data) {
120-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
121-
"CPointer cannot unbox to a native string");
122-
}
123-
124-
/* Some objects serve primarily as boxes of others, inlining them. This gets
125-
* gets the reference to such things, using the representation ID to distinguish
126-
* them. */
127-
static void * get_boxed_ref(PARROT_INTERP, STable *st, void *data, INTVAL repr_id) {
128-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
129-
"CPointer cannot box other types");
130-
}
131-
13254
/* This Parrot-specific addition to the API is used to free an object. */
13355
static void gc_free(PARROT_INTERP, PMC *obj) {
13456
mem_sys_free(PMC_data(obj));
@@ -144,11 +66,6 @@ static storage_spec get_storage_spec(PARROT_INTERP, STable *st) {
14466
return spec;
14567
}
14668

147-
/* Checks if an attribute has been initialized. */
148-
static INTVAL is_attribute_initialized(PARROT_INTERP, STable *st, void *data, PMC *ClassHandle, STRING *Name, INTVAL Hint) {
149-
die_no_attrs(interp);
150-
}
151-
15269
/* Initializes the CPointer representation. */
15370
REPROps * CPointer_initialize(PARROT_INTERP,
15471
PMC * (* wrap_object_func_ptr) (PARROT_INTERP, void *obj),
@@ -163,24 +80,13 @@ REPROps * CPointer_initialize(PARROT_INTERP,
16380
this_repr->allocate = allocate;
16481
this_repr->initialize = initialize;
16582
this_repr->copy_to = copy_to;
166-
this_repr->get_attribute_boxed = get_attribute_boxed;
167-
this_repr->get_attribute_boxed = get_attribute_boxed;
168-
this_repr->bind_attribute_boxed = bind_attribute_boxed;
169-
this_repr->bind_attribute_ref = bind_attribute_ref;
170-
this_repr->hint_for = hint_for;
171-
this_repr->set_int = set_int;
172-
this_repr->get_int = get_int;
173-
this_repr->set_num = set_num;
174-
this_repr->get_num = get_num;
175-
this_repr->set_str = set_str;
176-
this_repr->get_str = get_str;
177-
this_repr->get_boxed_ref = get_boxed_ref;
83+
this_repr->attr_funcs = NULL;
84+
this_repr->box_funcs = NULL;
17885
this_repr->gc_mark = NULL;
17986
this_repr->gc_free = gc_free;
18087
this_repr->gc_cleanup = NULL;
18188
this_repr->gc_mark_repr_data = NULL;
18289
this_repr->gc_free_repr_data = NULL;
18390
this_repr->get_storage_spec = get_storage_spec;
184-
this_repr->is_attribute_initialized = is_attribute_initialized;
18591
return this_repr;
18692
}

src/6model/reprs/CStruct.c

Lines changed: 13 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -428,61 +428,16 @@ static void bind_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *class
428428
}
429429
}
430430

431+
/* Checks if an attribute has been initialized. */
432+
static INTVAL is_attribute_initialized(PARROT_INTERP, STable *st, void *data, PMC *ClassHandle, STRING *Name, INTVAL Hint) {
433+
die_no_attrs(interp);
434+
}
435+
431436
/* Gets the hint for the given attribute ID. */
432437
static INTVAL hint_for(PARROT_INTERP, STable *st, PMC *class_handle, STRING *name) {
433438
return NO_HINT;
434439
}
435440

436-
/* Used with boxing. Sets an integer value, for representations that can hold
437-
* one. */
438-
static void set_int(PARROT_INTERP, STable *st, void *data, INTVAL value) {
439-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
440-
"CStruct cannot box a native int");
441-
}
442-
443-
/* Used with boxing. Gets an integer value, for representations that can
444-
* hold one. */
445-
static INTVAL get_int(PARROT_INTERP, STable *st, void *data) {
446-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
447-
"CStruct cannot unbox to a native int");
448-
}
449-
450-
/* Used with boxing. Sets a floating point value, for representations that can
451-
* hold one. */
452-
static void set_num(PARROT_INTERP, STable *st, void *data, FLOATVAL value) {
453-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
454-
"CStruct cannot box a native num");
455-
}
456-
457-
/* Used with boxing. Gets a floating point value, for representations that can
458-
* hold one. */
459-
static FLOATVAL get_num(PARROT_INTERP, STable *st, void *data) {
460-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
461-
"CStruct cannot unbox to a native num");
462-
}
463-
464-
/* Used with boxing. Sets a string value, for representations that can hold
465-
* one. */
466-
static void set_str(PARROT_INTERP, STable *st, void *data, STRING *value) {
467-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
468-
"CStruct cannot box a native string");
469-
}
470-
471-
/* Used with boxing. Gets a string value, for representations that can hold
472-
* one. */
473-
static STRING * get_str(PARROT_INTERP, STable *st, void *data) {
474-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
475-
"CStruct cannot unbox to a native string");
476-
}
477-
478-
/* Some objects serve primarily as boxes of others, inlining them. This gets
479-
* gets the reference to such things, using the representation ID to distinguish
480-
* them. */
481-
static void * get_boxed_ref(PARROT_INTERP, STable *st, void *data, INTVAL repr_id) {
482-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
483-
"CStruct cannot box other types");
484-
}
485-
486441
/* This Parrot-specific addition to the API is used to mark an object. */
487442
static void gc_mark(PARROT_INTERP, STable *st, void *data) {
488443
CStructREPRData *repr_data = (CStructREPRData *) st->REPR_data;
@@ -522,11 +477,6 @@ static storage_spec get_storage_spec(PARROT_INTERP, STable *st) {
522477
return spec;
523478
}
524479

525-
/* Checks if an attribute has been initialized. */
526-
static INTVAL is_attribute_initialized(PARROT_INTERP, STable *st, void *data, PMC *ClassHandle, STRING *Name, INTVAL Hint) {
527-
die_no_attrs(interp);
528-
}
529-
530480
/* Initializes the CStruct representation. */
531481
REPROps * CStruct_initialize(PARROT_INTERP,
532482
PMC * (* wrap_object_func_ptr) (PARROT_INTERP, void *obj),
@@ -541,24 +491,19 @@ REPROps * CStruct_initialize(PARROT_INTERP,
541491
this_repr->allocate = allocate;
542492
this_repr->initialize = initialize;
543493
this_repr->copy_to = copy_to;
544-
this_repr->get_attribute_boxed = get_attribute_boxed;
545-
this_repr->get_attribute_ref = get_attribute_ref;
546-
this_repr->bind_attribute_boxed = bind_attribute_boxed;
547-
this_repr->bind_attribute_ref = bind_attribute_ref;
548-
this_repr->hint_for = hint_for;
549-
this_repr->set_int = set_int;
550-
this_repr->get_int = get_int;
551-
this_repr->set_num = set_num;
552-
this_repr->get_num = get_num;
553-
this_repr->set_str = set_str;
554-
this_repr->get_str = get_str;
555-
this_repr->get_boxed_ref = get_boxed_ref;
494+
this_repr->attr_funcs = mem_allocate_typed(REPROps_Attributes);
495+
this_repr->attr_funcs->get_attribute_boxed = get_attribute_boxed;
496+
this_repr->attr_funcs->get_attribute_ref = get_attribute_ref;
497+
this_repr->attr_funcs->bind_attribute_boxed = bind_attribute_boxed;
498+
this_repr->attr_funcs->bind_attribute_ref = bind_attribute_ref;
499+
this_repr->attr_funcs->is_attribute_initialized = is_attribute_initialized;
500+
this_repr->attr_funcs->hint_for = hint_for;
501+
this_repr->box_funcs = NULL;
556502
this_repr->gc_mark = gc_mark;
557503
this_repr->gc_free = gc_free;
558504
this_repr->gc_cleanup = gc_cleanup;
559505
this_repr->gc_mark_repr_data = NULL;
560506
this_repr->gc_free_repr_data = NULL;
561507
this_repr->get_storage_spec = get_storage_spec;
562-
this_repr->is_attribute_initialized = is_attribute_initialized;
563508
return this_repr;
564509
}

src/6model/reprs/HashAttrStore.c

Lines changed: 14 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -73,61 +73,17 @@ static void bind_attribute_ref(PARROT_INTERP, STable *st, void *data, PMC *class
7373
"HashAttrStore representation does not support native attribute storage");
7474
}
7575

76+
/* Checks if an attribute has been initialized. */
77+
static INTVAL is_attribute_initialized(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint) {
78+
HashAttrStoreBody *body = (HashAttrStoreBody *)data;
79+
return VTABLE_exists_keyed_str(interp, body->store, name);
80+
}
81+
7682
/* Gets the hint for the given attribute ID. */
7783
static INTVAL hint_for(PARROT_INTERP, STable *st, PMC *class_handle, STRING *name) {
7884
return NO_HINT;
7985
}
8086

81-
/* Used with boxing. Sets an integer value, for representations that can hold
82-
* one. */
83-
static void set_int(PARROT_INTERP, STable *st, void *data, INTVAL value) {
84-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
85-
"HashAttrStore cannot box a native int");
86-
}
87-
88-
/* Used with boxing. Gets an integer value, for representations that can
89-
* hold one. */
90-
static INTVAL get_int(PARROT_INTERP, STable *st, void *data) {
91-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
92-
"HashAttrStore cannot unbox to a native int");
93-
}
94-
95-
/* Used with boxing. Sets a floating point value, for representations that can
96-
* hold one. */
97-
static void set_num(PARROT_INTERP, STable *st, void *data, FLOATVAL value) {
98-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
99-
"HashAttrStore cannot box a native num");
100-
}
101-
102-
/* Used with boxing. Gets a floating point value, for representations that can
103-
* hold one. */
104-
static FLOATVAL get_num(PARROT_INTERP, STable *st, void *data) {
105-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
106-
"HashAttrStore cannot unbox to a native num");
107-
}
108-
109-
/* Used with boxing. Sets a string value, for representations that can hold
110-
* one. */
111-
static void set_str(PARROT_INTERP, STable *st, void *data, STRING *value) {
112-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
113-
"HashAttrStore cannot box a native string");
114-
}
115-
116-
/* Used with boxing. Gets a string value, for representations that can hold
117-
* one. */
118-
static STRING * get_str(PARROT_INTERP, STable *st, void *data) {
119-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
120-
"HashAttrStore cannot unbox to a native string");
121-
}
122-
123-
/* Some objects serve primarily as boxes of others, inlining them. This gets
124-
* gets the reference to such things, using the representation ID to distinguish
125-
* them. */
126-
static void * get_boxed_ref(PARROT_INTERP, STable *st, void *data, INTVAL repr_id) {
127-
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
128-
"HashAttrStore cannot box other types");
129-
}
130-
13187
/* This Parrot-specific addition to the API is used to mark an object. */
13288
static void gc_mark(PARROT_INTERP, STable *st, void *data) {
13389
HashAttrStoreBody *body = (HashAttrStoreBody *)data;
@@ -150,12 +106,6 @@ static storage_spec get_storage_spec(PARROT_INTERP, STable *st) {
150106
return spec;
151107
}
152108

153-
/* Checks if an attribute has been initialized. */
154-
static INTVAL is_attribute_initialized(PARROT_INTERP, STable *st, void *data, PMC *class_handle, STRING *name, INTVAL hint) {
155-
HashAttrStoreBody *body = (HashAttrStoreBody *)data;
156-
return VTABLE_exists_keyed_str(interp, body->store, name);
157-
}
158-
159109
/* Initializes the HashAttrStore representation. */
160110
REPROps * HashAttrStore_initialize(PARROT_INTERP) {
161111
/* Allocate and populate the representation function table. */
@@ -164,24 +114,19 @@ REPROps * HashAttrStore_initialize(PARROT_INTERP) {
164114
this_repr->allocate = allocate;
165115
this_repr->initialize = initialize;
166116
this_repr->copy_to = copy_to;
167-
this_repr->get_attribute_boxed = get_attribute_boxed;
168-
this_repr->get_attribute_ref = get_attribute_ref;
169-
this_repr->bind_attribute_boxed = bind_attribute_boxed;
170-
this_repr->bind_attribute_ref = bind_attribute_ref;
171-
this_repr->hint_for = hint_for;
172-
this_repr->set_int = set_int;
173-
this_repr->get_int = get_int;
174-
this_repr->set_num = set_num;
175-
this_repr->get_num = get_num;
176-
this_repr->set_str = set_str;
177-
this_repr->get_str = get_str;
178-
this_repr->get_boxed_ref = get_boxed_ref;
117+
this_repr->attr_funcs = mem_allocate_typed(REPROps_Attributes);
118+
this_repr->attr_funcs->get_attribute_boxed = get_attribute_boxed;
119+
this_repr->attr_funcs->get_attribute_ref = get_attribute_ref;
120+
this_repr->attr_funcs->bind_attribute_boxed = bind_attribute_boxed;
121+
this_repr->attr_funcs->bind_attribute_ref = bind_attribute_ref;
122+
this_repr->attr_funcs->is_attribute_initialized = is_attribute_initialized;
123+
this_repr->attr_funcs->hint_for = hint_for;
124+
this_repr->box_funcs = NULL;
179125
this_repr->gc_mark = gc_mark;
180126
this_repr->gc_free = gc_free;
181127
this_repr->gc_cleanup = NULL;
182128
this_repr->gc_mark_repr_data = NULL;
183129
this_repr->gc_free_repr_data = NULL;
184130
this_repr->get_storage_spec = get_storage_spec;
185-
this_repr->is_attribute_initialized = is_attribute_initialized;
186131
return this_repr;
187132
}

0 commit comments

Comments
 (0)