@@ -45,71 +45,42 @@ static PMC * introspection_call(PARROT_INTERP, PMC *WHAT, PMC *HOW, STRING *name
45
45
return VTABLE_get_pmc_keyed_int (interp , cappy , 0 );
46
46
}
47
47
48
- /* Helper to make an accessor call. */
49
- static PMC * accessor_call (PARROT_INTERP , PMC * obj , STRING * name ) {
50
- PMC * old_ctx , * cappy ;
51
-
52
- /* Look up method; if there is none hand back a null. */
53
- PMC * meth = VTABLE_find_method (interp , obj , name );
54
- if (PMC_IS_NULL (meth ))
55
- return meth ;
56
-
57
- /* Set up call capture. */
58
- old_ctx = Parrot_pcc_get_signature (interp , CURRENT_CONTEXT (interp ));
59
- cappy = Parrot_pmc_new (interp , enum_class_CallContext );
60
- VTABLE_push_pmc (interp , cappy , obj );
61
-
62
- /* Call. */
63
- Parrot_pcc_invoke_from_sig_object (interp , meth , cappy );
64
-
65
- /* Grab result. */
66
- cappy = Parrot_pcc_get_signature (interp , CURRENT_CONTEXT (interp ));
67
- Parrot_pcc_set_signature (interp , CURRENT_CONTEXT (interp ), old_ctx );
68
- return VTABLE_get_pmc_keyed_int (interp , cappy , 0 );
69
- }
70
-
71
48
/* Locates all of the attributes. Puts them onto a flattened, ordered
72
49
* list of attributes (populating the passed flat_list). Also builds
73
50
* the index mapping for doing named lookups. Note index is not related
74
51
* to the storage position. */
75
- static PMC * index_mapping_and_flat_list (PARROT_INTERP , PMC * WHAT , CStructREPRData * repr_data ) {
52
+ static PMC * index_mapping_and_flat_list (PARROT_INTERP , PMC * mro , CStructREPRData * repr_data ) {
76
53
PMC * flat_list = Parrot_pmc_new (interp , enum_class_ResizablePMCArray );
77
54
PMC * class_list = Parrot_pmc_new (interp , enum_class_ResizablePMCArray );
78
55
PMC * attr_map_list = Parrot_pmc_new (interp , enum_class_ResizablePMCArray );
79
- STRING * attributes_str = Parrot_str_new_constant (interp , "attributes" );
80
- STRING * parents_str = Parrot_str_new_constant (interp , "parents" );
81
56
STRING * name_str = Parrot_str_new_constant (interp , "name" );
82
- STRING * mro_str = Parrot_str_new_constant (interp , "mro" );
83
57
INTVAL current_slot = 0 ;
84
58
85
59
INTVAL num_classes , i ;
86
60
CStructNameMap * result = NULL ;
87
61
88
- /* Get the MRO. */
89
- PMC * mro = introspection_call (interp , WHAT , STABLE (WHAT )-> HOW , mro_str , 0 );
90
- INTVAL mro_idx = VTABLE_elements (interp , mro );
91
-
92
62
/* Walk through the parents list. */
63
+ INTVAL mro_idx = VTABLE_elements (interp , mro );
93
64
while (mro_idx )
94
65
{
95
66
/* Get current class in MRO. */
96
- PMC * current_class = decontainerize ( interp , VTABLE_get_pmc_keyed_int (interp , mro , -- mro_idx ) );
97
- PMC * HOW = STABLE ( current_class ) -> HOW ;
67
+ PMC * type_info = VTABLE_get_pmc_keyed_int (interp , mro , -- mro_idx );
68
+ PMC * current_class = decontainerize ( interp , VTABLE_get_pmc_keyed_int ( interp , type_info , 0 )) ;
98
69
99
70
/* Get its local parents; make sure we're not doing MI. */
100
- PMC * parents = introspection_call (interp , current_class , HOW , parents_str , 1 );
71
+ PMC * parents = VTABLE_get_pmc_keyed_int (interp , type_info , 2 );
101
72
INTVAL num_parents = VTABLE_elements (interp , parents );
102
73
if (num_parents <= 1 ) {
103
74
/* Get attributes and iterate over them. */
104
- PMC * attributes = introspection_call (interp , current_class , HOW , attributes_str , 1 );
75
+ PMC * attributes = VTABLE_get_pmc_keyed_int (interp , type_info , 1 );
105
76
PMC * attr_map = PMCNULL ;
106
77
PMC * attr_iter = VTABLE_get_iter (interp , attributes );
107
78
while (VTABLE_get_bool (interp , attr_iter )) {
108
79
/* Get attribute. */
109
80
PMC * attr = VTABLE_shift_pmc (interp , attr_iter );
110
81
111
82
/* Get its name. */
112
- PMC * name_pmc = accessor_call (interp , attr , name_str );
83
+ PMC * name_pmc = VTABLE_get_pmc_keyed_str (interp , attr , name_str );
113
84
STRING * name = VTABLE_get_string (interp , name_pmc );
114
85
115
86
/* Allocate a slot. */
@@ -148,7 +119,7 @@ static PMC * index_mapping_and_flat_list(PARROT_INTERP, PMC *WHAT, CStructREPRDa
148
119
/* This works out an allocation strategy for the object. It takes care of
149
120
* "inlining" storage of attributes that are natively typed, as well as
150
121
* noting unbox targets. */
151
- static void compute_allocation_strategy (PARROT_INTERP , PMC * WHAT , CStructREPRData * repr_data ) {
122
+ static void compute_allocation_strategy (PARROT_INTERP , PMC * repr_info , CStructREPRData * repr_data ) {
152
123
STRING * type_str = Parrot_str_new_constant (interp , "type" );
153
124
PMC * flat_list ;
154
125
@@ -164,7 +135,7 @@ static void compute_allocation_strategy(PARROT_INTERP, PMC *WHAT, CStructREPRDat
164
135
Parrot_block_GC_mark (interp );
165
136
166
137
/* Compute index mapping table and get flat list of attributes. */
167
- flat_list = index_mapping_and_flat_list (interp , WHAT , repr_data );
138
+ flat_list = index_mapping_and_flat_list (interp , repr_info , repr_data );
168
139
169
140
/* If we have no attributes in the index mapping, then just the header. */
170
141
if (repr_data -> name_to_index_mapping [0 ].class_key == NULL ) {
@@ -195,7 +166,7 @@ static void compute_allocation_strategy(PARROT_INTERP, PMC *WHAT, CStructREPRDat
195
166
for (i = 0 ; i < num_attrs ; i ++ ) {
196
167
/* Fetch its type; see if it's some kind of unboxed type. */
197
168
PMC * attr = VTABLE_get_pmc_keyed_int (interp , flat_list , i );
198
- PMC * type = accessor_call (interp , attr , type_str );
169
+ PMC * type = VTABLE_get_pmc_keyed_str (interp , attr , type_str );
199
170
INTVAL type_id = REPR (type )-> ID ;
200
171
INTVAL bits = sizeof (void * ) * 8 ;
201
172
INTVAL align = ALIGNOF1 (void * );
@@ -363,19 +334,18 @@ static PMC * type_object_for(PARROT_INTERP, PMC *HOW) {
363
334
364
335
/* Composes the representation. */
365
336
static void compose (PARROT_INTERP , STable * st , PMC * repr_info ) {
366
- /* TODO: move allocation strategy stuff here. */
337
+ /* Compute allocation strategy. */
338
+ CStructREPRData * repr_data = (CStructREPRData * ) st -> REPR_data ;
339
+ PMC * attr_info = VTABLE_get_pmc_keyed_str (interp , repr_info ,
340
+ Parrot_str_new_constant (interp , "attribute" ));
341
+ compute_allocation_strategy (interp , attr_info , repr_data );
342
+ PARROT_GC_WRITE_BARRIER (interp , st -> stable_pmc );
367
343
}
368
344
369
345
/* Creates a new instance based on the type object. */
370
346
static PMC * allocate (PARROT_INTERP , STable * st ) {
371
347
CStructInstance * obj ;
372
-
373
- /* Compute allocation strategy if we've not already done so. */
374
348
CStructREPRData * repr_data = (CStructREPRData * ) st -> REPR_data ;
375
- if (!repr_data -> struct_size ) {
376
- compute_allocation_strategy (interp , st -> WHAT , repr_data );
377
- PARROT_GC_WRITE_BARRIER (interp , st -> stable_pmc );
378
- }
379
349
380
350
/* Allocate and set up object instance. */
381
351
obj = (CStructInstance * ) Parrot_gc_allocate_fixed_size_storage (interp , sizeof (CStructInstance ));
0 commit comments