Skip to content

Commit 139fb76

Browse files
committed
Split attribute and boxed parts of the REPR function table out into sub-tables. Breaks everything, of course.
1 parent e680f11 commit 139fb76

File tree

1 file changed

+54
-48
lines changed

1 file changed

+54
-48
lines changed

src/6model/sixmodelobject.h

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -138,39 +138,15 @@ typedef struct {
138138
PMC *stable_pmc;
139139
} STable;
140140

141-
/* A representation is what controls the layout of an object and storage of
142-
* attributes, as well as how it boxes/unboxes to the three primitive types
143-
* INTVAL, FLOATVAL and STRING * (if it can).
141+
/* A representation is what controls the layout of an object and access and
142+
* manipulation of the memory it manages. This includes attribute storage
143+
* for objects in the usual OO sense. However, representations may also
144+
* represent other things, such as pointers and arrays.
144145
*
145-
* This struct defines the set of operations that a representation
146-
* should implement to fulfil the representation API. Note that a
147-
* representation may also store some per-type data in the repr_data
148-
* slot of the s-table. That aside, representations are singletons,
149-
* and code being compiled with a known representation could even
150-
* inline the lookups. */
151-
struct SixModel_REPROps {
152-
/* Creates a new type object of this representation, and
153-
* associates it with the given HOW. Also sets up a new
154-
* representation instance if needed. */
155-
PMC * (*type_object_for) (PARROT_INTERP, PMC *HOW);
156-
157-
/* Allocates a new, but uninitialized object, based on the
158-
* specified s-table. */
159-
PMC * (*allocate) (PARROT_INTERP, STable *st);
160-
161-
/* Used to initialize the body of an object representing the type
162-
* describe by the specified s-table. DATA points to the body. It
163-
* may recursively call initialize for any flattened objects. */
164-
void (*initialize) (PARROT_INTERP, STable *st, void *data);
165-
166-
/* For the given type, copies the object data from the source memory
167-
* location to the destination one. Note that it may actually be more
168-
* involved than a straightforward bit of copying; what's important is
169-
* that the representation knows about that. Note that it may have to
170-
* call copy_to recursively on representations of any flattened objects
171-
* within its body. */
172-
void (*copy_to) (PARROT_INTERP, STable *st, void *src, void *dest);
173-
146+
* The following structs define the representation API. There are some
147+
* things that all representations have. There are some others that a
148+
* representation will only implement if it plays that "role".*/
149+
typedef struct SixModel_REPROps_Attribute {
174150
/* Gets the current value for an object attribute. For non-flattened
175151
* objects - that is, reference types - this just returns the object
176152
* stored in the attribute. For the flattened case, this will auto-box. */
@@ -199,6 +175,11 @@ struct SixModel_REPROps {
199175
/* Gets the hint for the given attribute ID. */
200176
INTVAL (*hint_for) (PARROT_INTERP, STable *st, PMC *class_handle, STRING *name);
201177

178+
/* Checks if an attribute has been initialized. */
179+
INTVAL (*is_attribute_initialized) (PARROT_INTERP, STable *st, void *data,
180+
PMC *class_handle, STRING *name, INTVAL hint);
181+
} REPROps_Attribute;
182+
typedef struct SixModel_REPROps_Boxing {
202183
/* Used with boxing. Sets an integer value, for representations that
203184
* can hold one. */
204185
void (*set_int) (PARROT_INTERP, STable *st, void *data, INTVAL value);
@@ -227,7 +208,48 @@ struct SixModel_REPROps {
227208
* gets the reference to such things, using the representation ID to distinguish
228209
* them. */
229210
void * (*get_boxed_ref) (PARROT_INTERP, STable *st, void *data, INTVAL repr_id);
211+
} REPROps_Boxing;
212+
struct SixModel_REPROps {
213+
/* Creates a new type object of this representation, and
214+
* associates it with the given HOW. Also sets up a new
215+
* representation instance if needed. */
216+
PMC * (*type_object_for) (PARROT_INTERP, PMC *HOW);
217+
218+
/* Allocates a new, but uninitialized object, based on the
219+
* specified s-table. */
220+
PMC * (*allocate) (PARROT_INTERP, STable *st);
221+
222+
/* Used to initialize the body of an object representing the type
223+
* describe by the specified s-table. DATA points to the body. It
224+
* may recursively call initialize for any flattened objects. */
225+
void (*initialize) (PARROT_INTERP, STable *st, void *data);
226+
227+
/* For the given type, copies the object data from the source memory
228+
* location to the destination one. Note that it may actually be more
229+
* involved than a straightforward bit of copying; what's important is
230+
* that the representation knows about that. Note that it may have to
231+
* call copy_to recursively on representations of any flattened objects
232+
* within its body. */
233+
void (*copy_to) (PARROT_INTERP, STable *st, void *src, void *dest);
230234

235+
/* Attribute access REPR function table. */
236+
struct SixModel_REPROps_Attribute *attr_funcs;
237+
238+
/* Boxing REPR function table. */
239+
struct SixModel_REPROps_Boxing *box_funcs;
240+
241+
/* Gets the storage specification for this representation. */
242+
storage_spec (*get_storage_spec) (PARROT_INTERP, STable *st);
243+
244+
/* Handles an object changing its type. The representation is responsible
245+
* for doing any changes to the underlying data structure, and may reject
246+
* changes that it's not willing to do (for example, a representation may
247+
* choose to only handle switching to a subclass). It is also left to update
248+
* the S-Table pointer as needed; while in theory this could be factored
249+
* out, the representation probably knows more about timing issues and
250+
* thread safety requirements. */
251+
void (*change_type) (PARROT_INTERP, PMC *Object, PMC *NewType);
252+
231253
/* This Parrot-specific addition to the API is used to mark an object. */
232254
void (*gc_mark) (PARROT_INTERP, STable *st, void *data);
233255

@@ -243,22 +265,6 @@ struct SixModel_REPROps {
243265

244266
/* This Parrot-specific addition to the API is used to free a REPR instance. */
245267
void (*gc_free_repr_data) (PARROT_INTERP, STable *st);
246-
247-
/* Gets the storage specification for this representation. */
248-
storage_spec (*get_storage_spec) (PARROT_INTERP, STable *st);
249-
250-
/* Checks if an attribute has been initialized. */
251-
INTVAL (*is_attribute_initialized) (PARROT_INTERP, STable *st, void *data,
252-
PMC *class_handle, STRING *name, INTVAL hint);
253-
254-
/* Handles an object changing its type. The representation is responsible
255-
* for doing any changes to the underlying data structure, and may reject
256-
* changes that it's not willing to do (for example, a representation may
257-
* choose to only handle switching to a subclass). It is also left to update
258-
* the S-Table pointer as needed; while in theory this could be factored
259-
* out, the representation probably knows more about timing issues and
260-
* thread safety requirements. */
261-
void (*change_type) (PARROT_INTERP, PMC *Object, PMC *NewType);
262268

263269
/* The representation's ID. */
264270
INTVAL ID;

0 commit comments

Comments
 (0)