Skip to content

Commit 1b06d16

Browse files
committed
Eliminate the REPR PMC, which wrapped around the REPR function pointer table; after a previous refactor that table is now always a singleton. Makes things simpler, and removes a level of indirection for every REPR operation.
1 parent 4fb5124 commit 1b06d16

24 files changed

+255
-291
lines changed

src/6model/knowhow_bootstrapper.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ static void new_type(PARROT_INTERP, PMC *nci) {
3232
/* Create a new type object of the desired REPR. (Note that we can't
3333
* default to KnowHOWREPR here, since it doesn't know how to actually
3434
* store attributes, it's just for bootstrapping knowhow's. */
35-
PMC *repr_to_use = REPR_get_by_name(interp, repr_name);
36-
PMC *type_object = REPR_STRUCT(repr_to_use)->type_object_for(interp, HOW);
35+
REPROps *repr_to_use = REPR_get_by_name(interp, repr_name);
36+
PMC *type_object = repr_to_use->type_object_for(interp, HOW);
3737

3838
/* See if we were given a name; put it into the meta-object if so. */
3939
STRING *name = VTABLE_exists_keyed_str(interp, capture, name_str) ?
@@ -174,13 +174,13 @@ static PMC * bottom_find_method(PARROT_INTERP, PMC *obj, STRING *name, INTVAL hi
174174
PMC * SixModelObject_bootstrap_knowhow(PARROT_INTERP, PMC *sc) {
175175
/* Create our KnowHOW type object. Note we don't have a HOW just yet, so
176176
* pass in null. */
177-
PMC *REPR = REPR_get_by_name(interp, Parrot_str_new_constant(interp, "KnowHOWREPR"));
178-
PMC *knowhow_pmc = REPR_STRUCT(REPR)->type_object_for(interp, PMCNULL);
177+
REPROps *REPR = REPR_get_by_name(interp, Parrot_str_new_constant(interp, "KnowHOWREPR"));
178+
PMC *knowhow_pmc = REPR->type_object_for(interp, PMCNULL);
179179

180180
/* We create a KnowHOW instance that can describe itself. This means
181181
* .HOW.HOW.HOW.HOW etc will always return that, which closes the model
182182
* up. Also pull out its underlying struct. */
183-
PMC *knowhow_how_pmc = REPR_STRUCT(REPR)->instance_of(interp, knowhow_pmc);
183+
PMC *knowhow_how_pmc = REPR->instance_of(interp, knowhow_pmc);
184184
KnowHOWREPRInstance *knowhow_how = (KnowHOWREPRInstance *)PMC_data(knowhow_how_pmc);
185185

186186
/* Need to give the knowhow_how a twiddled STable with a different

src/6model/repr_registry.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,32 @@
1515
#include "reprs/Uninstantiable.h"
1616
#include "repr_registry.h"
1717

18-
/* An array of representations. */
19-
static PMC *repr_registry = NULL;
18+
/* An array mapping representation IDs to function tables. */
19+
static REPROps **repr_registry = NULL;
20+
21+
/* Number of representations registered so far. */
22+
static INTVAL num_reprs = 0;
2023

2124
/* Hash mapping representation names to IDs. */
2225
static PMC *repr_name_to_id_map = NULL;
2326

2427
/* Registers a representation. It this is ever made public, it should first be
2528
* made thread-safe. */
26-
static void register_repr(PARROT_INTERP, STRING *name, PMC *repr) {
27-
INTVAL ID = VTABLE_elements(interp, repr_registry);
28-
VTABLE_push_pmc(interp, repr_registry, repr);
29+
static void register_repr(PARROT_INTERP, STRING *name, REPROps *repr) {
30+
INTVAL ID = num_reprs;
31+
num_reprs++;
32+
if (repr_registry)
33+
repr_registry = mem_sys_realloc(repr_registry, num_reprs * sizeof(REPROps *));
34+
else
35+
repr_registry = mem_sys_allocate(num_reprs * sizeof(REPROps *));
36+
repr_registry[ID] = repr;
2937
VTABLE_set_integer_keyed_str(interp, repr_name_to_id_map, name, ID);
3038
}
3139

3240
/* Initializes the representations registry, building up all of the various
3341
* representations. */
3442
void REPR_initialize_registry(PARROT_INTERP) {
35-
/* Allocate registry and name to ID map, and anchor them so they won't
36-
* get nommed by the GC. */
37-
repr_registry = pmc_new(interp, enum_class_ResizablePMCArray);
38-
Parrot_pmc_gc_register(interp, repr_registry);
43+
/* Allocate name to ID map, and anchor it with the GC. */
3944
repr_name_to_id_map = pmc_new(interp, enum_class_Hash);
4045
Parrot_pmc_gc_register(interp, repr_name_to_id_map);
4146

@@ -63,12 +68,11 @@ INTVAL REPR_name_to_id(PARROT_INTERP, STRING *name) {
6368
}
6469

6570
/* Gets a representation by ID. */
66-
PMC * REPR_get_by_id(PARROT_INTERP, INTVAL id) {
67-
return VTABLE_get_pmc_keyed_int(interp, repr_registry, id);
71+
REPROps * REPR_get_by_id(PARROT_INTERP, INTVAL id) {
72+
return repr_registry[id];
6873
}
6974

7075
/* Gets a representation by name. */
71-
PMC * REPR_get_by_name(PARROT_INTERP, STRING *name) {
72-
return VTABLE_get_pmc_keyed_int(interp, repr_registry,
73-
VTABLE_get_integer_keyed_str(interp, repr_name_to_id_map, name));
76+
REPROps * REPR_get_by_name(PARROT_INTERP, STRING *name) {
77+
return repr_registry[VTABLE_get_integer_keyed_str(interp, repr_name_to_id_map, name)];
7478
}

src/6model/repr_registry.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#ifndef REPRREGISTRY_H_GUARD
55
#define REPRREGISTRY_H_GUARD
66

7-
void REPR_initialize_registry(PARROT_INTERP);
8-
INTVAL REPR_name_to_id (PARROT_INTERP, STRING *name);
9-
PMC * REPR_get_by_id (PARROT_INTERP, INTVAL id);
10-
PMC * REPR_get_by_name (PARROT_INTERP, STRING *name);
7+
void REPR_initialize_registry(PARROT_INTERP);
8+
INTVAL REPR_name_to_id (PARROT_INTERP, STRING *name);
9+
REPROps * REPR_get_by_id (PARROT_INTERP, INTVAL id);
10+
REPROps * REPR_get_by_name (PARROT_INTERP, STRING *name);
1111

1212
#endif

src/6model/reprs/HashAttrStore.c

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "HashAttrStore.h"
1010

1111
/* This representation's function pointer table. */
12-
static PMC *this_repr;
12+
static REPROps *this_repr;
1313

1414
/* Creates a new type object of this representation, and associates it with
1515
* the given HOW. */
@@ -187,33 +187,31 @@ static INTVAL is_attribute_initialized(PARROT_INTERP, PMC *obj, PMC *class_handl
187187
}
188188

189189
/* Initializes the HashAttrStore representation. */
190-
PMC * HashAttrStore_initialize(PARROT_INTERP) {
190+
REPROps * HashAttrStore_initialize(PARROT_INTERP) {
191191
/* Allocate and populate the representation function table. */
192-
REPRCommonalities *repr = mem_allocate_zeroed_typed(REPRCommonalities);
193-
repr->type_object_for = type_object_for;
194-
repr->instance_of = instance_of;
195-
repr->defined = defined;
196-
repr->get_attribute = get_attribute;
197-
repr->get_attribute_int = get_attribute_int;
198-
repr->get_attribute_num = get_attribute_num;
199-
repr->get_attribute_str = get_attribute_str;
200-
repr->bind_attribute = bind_attribute;
201-
repr->bind_attribute_int = bind_attribute_int;
202-
repr->bind_attribute_num = bind_attribute_num;
203-
repr->bind_attribute_str = bind_attribute_str;
204-
repr->hint_for = hint_for;
205-
repr->clone = repr_clone;
206-
repr->set_int = set_int;
207-
repr->get_int = get_int;
208-
repr->set_num = set_num;
209-
repr->get_num = get_num;
210-
repr->set_str = set_str;
211-
repr->get_str = get_str;
212-
repr->gc_mark = gc_mark;
213-
repr->gc_free = gc_free;
214-
repr->get_storage_spec = get_storage_spec;
215-
repr->is_attribute_initialized = is_attribute_initialized;
216-
217-
/* Wrap it in a PMC. */
218-
return (this_repr = wrap_repr(interp, repr));
192+
this_repr = mem_allocate_zeroed_typed(REPROps);
193+
this_repr->type_object_for = type_object_for;
194+
this_repr->instance_of = instance_of;
195+
this_repr->defined = defined;
196+
this_repr->get_attribute = get_attribute;
197+
this_repr->get_attribute_int = get_attribute_int;
198+
this_repr->get_attribute_num = get_attribute_num;
199+
this_repr->get_attribute_str = get_attribute_str;
200+
this_repr->bind_attribute = bind_attribute;
201+
this_repr->bind_attribute_int = bind_attribute_int;
202+
this_repr->bind_attribute_num = bind_attribute_num;
203+
this_repr->bind_attribute_str = bind_attribute_str;
204+
this_repr->hint_for = hint_for;
205+
this_repr->clone = repr_clone;
206+
this_repr->set_int = set_int;
207+
this_repr->get_int = get_int;
208+
this_repr->set_num = set_num;
209+
this_repr->get_num = get_num;
210+
this_repr->set_str = set_str;
211+
this_repr->get_str = get_str;
212+
this_repr->gc_mark = gc_mark;
213+
this_repr->gc_free = gc_free;
214+
this_repr->get_storage_spec = get_storage_spec;
215+
this_repr->is_attribute_initialized = is_attribute_initialized;
216+
return this_repr;
219217
}

src/6model/reprs/HashAttrStore.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ typedef struct {
1111
} HashAttrStoreInstance;
1212

1313
/* Initializes the Hash Attribute Store REPR. */
14-
PMC * HashAttrStore_initialize(PARROT_INTERP);
14+
REPROps * HashAttrStore_initialize(PARROT_INTERP);
1515

1616
#endif

src/6model/reprs/KnowHOWREPR.c

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "KnowHOWREPR.h"
1010

1111
/* This representation's function pointer table. */
12-
static PMC *this_repr;
12+
static REPROps *this_repr;
1313

1414
/* Creates a new type object of this representation, and associates it with
1515
* the given HOW. */
@@ -173,35 +173,33 @@ static INTVAL is_attribute_initialized(PARROT_INTERP, PMC *Object, PMC *ClassHan
173173
}
174174

175175
/* Initializes the KnowHOWREPR representation. */
176-
PMC * KnowHOWREPR_initialize(PARROT_INTERP) {
176+
REPROps * KnowHOWREPR_initialize(PARROT_INTERP) {
177177
/* Allocate and populate the representation function table. */
178-
REPRCommonalities *repr = mem_allocate_typed(REPRCommonalities);
179-
repr->type_object_for = type_object_for;
180-
repr->instance_of = instance_of;
181-
repr->defined = defined;
182-
repr->get_attribute = get_attribute;
183-
repr->get_attribute_int = get_attribute_int;
184-
repr->get_attribute_num = get_attribute_num;
185-
repr->get_attribute_str = get_attribute_str;
186-
repr->bind_attribute = bind_attribute;
187-
repr->bind_attribute_int = bind_attribute_int;
188-
repr->bind_attribute_num = bind_attribute_num;
189-
repr->bind_attribute_str = bind_attribute_str;
190-
repr->hint_for = hint_for;
191-
repr->clone = repr_clone;
192-
repr->set_int = set_int;
193-
repr->get_int = get_int;
194-
repr->set_num = set_num;
195-
repr->get_num = get_num;
196-
repr->set_str = set_str;
197-
repr->get_str = get_str;
198-
repr->gc_mark = gc_mark;
199-
repr->gc_free = gc_free;
200-
repr->gc_mark_repr = NULL;
201-
repr->gc_free_repr = NULL;
202-
repr->get_storage_spec = get_storage_spec;
203-
repr->is_attribute_initialized = is_attribute_initialized;
204-
205-
/* Wrap it in a PMC. */
206-
return (this_repr = wrap_repr(interp, repr));
178+
this_repr = mem_allocate_typed(REPROps);
179+
this_repr->type_object_for = type_object_for;
180+
this_repr->instance_of = instance_of;
181+
this_repr->defined = defined;
182+
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;
186+
this_repr->bind_attribute = bind_attribute;
187+
this_repr->bind_attribute_int = bind_attribute_int;
188+
this_repr->bind_attribute_num = bind_attribute_num;
189+
this_repr->bind_attribute_str = bind_attribute_str;
190+
this_repr->hint_for = hint_for;
191+
this_repr->clone = repr_clone;
192+
this_repr->set_int = set_int;
193+
this_repr->get_int = get_int;
194+
this_repr->set_num = set_num;
195+
this_repr->get_num = get_num;
196+
this_repr->set_str = set_str;
197+
this_repr->get_str = get_str;
198+
this_repr->gc_mark = gc_mark;
199+
this_repr->gc_free = gc_free;
200+
this_repr->gc_mark_repr = NULL;
201+
this_repr->gc_free_repr = NULL;
202+
this_repr->get_storage_spec = get_storage_spec;
203+
this_repr->is_attribute_initialized = is_attribute_initialized;
204+
return this_repr;
207205
}

src/6model/reprs/KnowHOWREPR.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ typedef struct {
1717
} KnowHOWREPRInstance;
1818

1919
/* Initializes the KnowHOW REPR. */
20-
PMC * KnowHOWREPR_initialize(PARROT_INTERP);
20+
REPROps * KnowHOWREPR_initialize(PARROT_INTERP);
2121

2222
#endif

src/6model/reprs/P6int.c

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "P6int.h"
99

1010
/* This representation's function pointer table. */
11-
static PMC *this_repr;
11+
static REPROps *this_repr;
1212

1313
/* Creates a new type object of this representation, and associates it with
1414
* the given HOW. */
@@ -164,35 +164,33 @@ static INTVAL is_attribute_initialized(PARROT_INTERP, PMC *Object, PMC *ClassHan
164164
}
165165

166166
/* Initializes the P6int representation. */
167-
PMC * P6int_initialize(PARROT_INTERP) {
167+
REPROps * P6int_initialize(PARROT_INTERP) {
168168
/* Allocate and populate the representation function table. */
169-
REPRCommonalities *repr = mem_allocate_typed(REPRCommonalities);
170-
repr->type_object_for = type_object_for;
171-
repr->instance_of = instance_of;
172-
repr->defined = defined;
173-
repr->get_attribute = get_attribute;
174-
repr->get_attribute_int = get_attribute_int;
175-
repr->get_attribute_num = get_attribute_num;
176-
repr->get_attribute_str = get_attribute_str;
177-
repr->bind_attribute = bind_attribute;
178-
repr->bind_attribute_int = bind_attribute_int;
179-
repr->bind_attribute_num = bind_attribute_num;
180-
repr->bind_attribute_str = bind_attribute_str;
181-
repr->hint_for = hint_for;
182-
repr->clone = repr_clone;
183-
repr->set_int = set_int;
184-
repr->get_int = get_int;
185-
repr->set_num = set_num;
186-
repr->get_num = get_num;
187-
repr->set_str = set_str;
188-
repr->get_str = get_str;
189-
repr->gc_mark = gc_mark;
190-
repr->gc_free = gc_free;
191-
repr->gc_mark_repr = NULL;
192-
repr->gc_free_repr = NULL;
193-
repr->get_storage_spec = get_storage_spec;
194-
repr->is_attribute_initialized = is_attribute_initialized;
195-
196-
/* Wrap it in a PMC. */
197-
return (this_repr = wrap_repr(interp, repr));
169+
this_repr = mem_allocate_typed(REPROps);
170+
this_repr->type_object_for = type_object_for;
171+
this_repr->instance_of = instance_of;
172+
this_repr->defined = defined;
173+
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;
177+
this_repr->bind_attribute = bind_attribute;
178+
this_repr->bind_attribute_int = bind_attribute_int;
179+
this_repr->bind_attribute_num = bind_attribute_num;
180+
this_repr->bind_attribute_str = bind_attribute_str;
181+
this_repr->hint_for = hint_for;
182+
this_repr->clone = repr_clone;
183+
this_repr->set_int = set_int;
184+
this_repr->get_int = get_int;
185+
this_repr->set_num = set_num;
186+
this_repr->get_num = get_num;
187+
this_repr->set_str = set_str;
188+
this_repr->get_str = get_str;
189+
this_repr->gc_mark = gc_mark;
190+
this_repr->gc_free = gc_free;
191+
this_repr->gc_mark_repr = NULL;
192+
this_repr->gc_free_repr = NULL;
193+
this_repr->get_storage_spec = get_storage_spec;
194+
this_repr->is_attribute_initialized = is_attribute_initialized;
195+
return this_repr;
198196
}

src/6model/reprs/P6int.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ typedef struct {
1111
} P6intInstance;
1212

1313
/* Initializes the P6int REPR. */
14-
PMC * P6int_initialize(PARROT_INTERP);
14+
REPROps * P6int_initialize(PARROT_INTERP);
1515

1616
#endif

0 commit comments

Comments
 (0)