Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Eliminate the REPR PMC, which wrapped around the REPR function pointe…
…r 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.
  • Loading branch information
jnthn committed Jul 26, 2011
1 parent 4fb5124 commit 1b06d16
Show file tree
Hide file tree
Showing 24 changed files with 255 additions and 291 deletions.
10 changes: 5 additions & 5 deletions src/6model/knowhow_bootstrapper.c
Expand Up @@ -32,8 +32,8 @@ static void new_type(PARROT_INTERP, PMC *nci) {
/* Create a new type object of the desired REPR. (Note that we can't
* default to KnowHOWREPR here, since it doesn't know how to actually
* store attributes, it's just for bootstrapping knowhow's. */
PMC *repr_to_use = REPR_get_by_name(interp, repr_name);
PMC *type_object = REPR_STRUCT(repr_to_use)->type_object_for(interp, HOW);
REPROps *repr_to_use = REPR_get_by_name(interp, repr_name);
PMC *type_object = repr_to_use->type_object_for(interp, HOW);

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

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

/* Need to give the knowhow_how a twiddled STable with a different
Expand Down
32 changes: 18 additions & 14 deletions src/6model/repr_registry.c
Expand Up @@ -15,27 +15,32 @@
#include "reprs/Uninstantiable.h"
#include "repr_registry.h"

/* An array of representations. */
static PMC *repr_registry = NULL;
/* An array mapping representation IDs to function tables. */
static REPROps **repr_registry = NULL;

/* Number of representations registered so far. */
static INTVAL num_reprs = 0;

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

/* Registers a representation. It this is ever made public, it should first be
* made thread-safe. */
static void register_repr(PARROT_INTERP, STRING *name, PMC *repr) {
INTVAL ID = VTABLE_elements(interp, repr_registry);
VTABLE_push_pmc(interp, repr_registry, repr);
static void register_repr(PARROT_INTERP, STRING *name, REPROps *repr) {
INTVAL ID = num_reprs;
num_reprs++;
if (repr_registry)
repr_registry = mem_sys_realloc(repr_registry, num_reprs * sizeof(REPROps *));
else
repr_registry = mem_sys_allocate(num_reprs * sizeof(REPROps *));
repr_registry[ID] = repr;
VTABLE_set_integer_keyed_str(interp, repr_name_to_id_map, name, ID);
}

/* Initializes the representations registry, building up all of the various
* representations. */
void REPR_initialize_registry(PARROT_INTERP) {
/* Allocate registry and name to ID map, and anchor them so they won't
* get nommed by the GC. */
repr_registry = pmc_new(interp, enum_class_ResizablePMCArray);
Parrot_pmc_gc_register(interp, repr_registry);
/* Allocate name to ID map, and anchor it with the GC. */
repr_name_to_id_map = pmc_new(interp, enum_class_Hash);
Parrot_pmc_gc_register(interp, repr_name_to_id_map);

Expand Down Expand Up @@ -63,12 +68,11 @@ INTVAL REPR_name_to_id(PARROT_INTERP, STRING *name) {
}

/* Gets a representation by ID. */
PMC * REPR_get_by_id(PARROT_INTERP, INTVAL id) {
return VTABLE_get_pmc_keyed_int(interp, repr_registry, id);
REPROps * REPR_get_by_id(PARROT_INTERP, INTVAL id) {
return repr_registry[id];
}

/* Gets a representation by name. */
PMC * REPR_get_by_name(PARROT_INTERP, STRING *name) {
return VTABLE_get_pmc_keyed_int(interp, repr_registry,
VTABLE_get_integer_keyed_str(interp, repr_name_to_id_map, name));
REPROps * REPR_get_by_name(PARROT_INTERP, STRING *name) {
return repr_registry[VTABLE_get_integer_keyed_str(interp, repr_name_to_id_map, name)];
}
8 changes: 4 additions & 4 deletions src/6model/repr_registry.h
Expand Up @@ -4,9 +4,9 @@
#ifndef REPRREGISTRY_H_GUARD
#define REPRREGISTRY_H_GUARD

void REPR_initialize_registry(PARROT_INTERP);
INTVAL REPR_name_to_id (PARROT_INTERP, STRING *name);
PMC * REPR_get_by_id (PARROT_INTERP, INTVAL id);
PMC * REPR_get_by_name (PARROT_INTERP, STRING *name);
void REPR_initialize_registry(PARROT_INTERP);
INTVAL REPR_name_to_id (PARROT_INTERP, STRING *name);
REPROps * REPR_get_by_id (PARROT_INTERP, INTVAL id);
REPROps * REPR_get_by_name (PARROT_INTERP, STRING *name);

#endif
56 changes: 27 additions & 29 deletions src/6model/reprs/HashAttrStore.c
Expand Up @@ -9,7 +9,7 @@
#include "HashAttrStore.h"

/* This representation's function pointer table. */
static PMC *this_repr;
static REPROps *this_repr;

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

/* Initializes the HashAttrStore representation. */
PMC * HashAttrStore_initialize(PARROT_INTERP) {
REPROps * HashAttrStore_initialize(PARROT_INTERP) {
/* Allocate and populate the representation function table. */
REPRCommonalities *repr = mem_allocate_zeroed_typed(REPRCommonalities);
repr->type_object_for = type_object_for;
repr->instance_of = instance_of;
repr->defined = defined;
repr->get_attribute = get_attribute;
repr->get_attribute_int = get_attribute_int;
repr->get_attribute_num = get_attribute_num;
repr->get_attribute_str = get_attribute_str;
repr->bind_attribute = bind_attribute;
repr->bind_attribute_int = bind_attribute_int;
repr->bind_attribute_num = bind_attribute_num;
repr->bind_attribute_str = bind_attribute_str;
repr->hint_for = hint_for;
repr->clone = repr_clone;
repr->set_int = set_int;
repr->get_int = get_int;
repr->set_num = set_num;
repr->get_num = get_num;
repr->set_str = set_str;
repr->get_str = get_str;
repr->gc_mark = gc_mark;
repr->gc_free = gc_free;
repr->get_storage_spec = get_storage_spec;
repr->is_attribute_initialized = is_attribute_initialized;

/* Wrap it in a PMC. */
return (this_repr = wrap_repr(interp, repr));
this_repr = mem_allocate_zeroed_typed(REPROps);
this_repr->type_object_for = type_object_for;
this_repr->instance_of = instance_of;
this_repr->defined = defined;
this_repr->get_attribute = get_attribute;
this_repr->get_attribute_int = get_attribute_int;
this_repr->get_attribute_num = get_attribute_num;
this_repr->get_attribute_str = get_attribute_str;
this_repr->bind_attribute = bind_attribute;
this_repr->bind_attribute_int = bind_attribute_int;
this_repr->bind_attribute_num = bind_attribute_num;
this_repr->bind_attribute_str = bind_attribute_str;
this_repr->hint_for = hint_for;
this_repr->clone = repr_clone;
this_repr->set_int = set_int;
this_repr->get_int = get_int;
this_repr->set_num = set_num;
this_repr->get_num = get_num;
this_repr->set_str = set_str;
this_repr->get_str = get_str;
this_repr->gc_mark = gc_mark;
this_repr->gc_free = gc_free;
this_repr->get_storage_spec = get_storage_spec;
this_repr->is_attribute_initialized = is_attribute_initialized;
return this_repr;
}
2 changes: 1 addition & 1 deletion src/6model/reprs/HashAttrStore.h
Expand Up @@ -11,6 +11,6 @@ typedef struct {
} HashAttrStoreInstance;

/* Initializes the Hash Attribute Store REPR. */
PMC * HashAttrStore_initialize(PARROT_INTERP);
REPROps * HashAttrStore_initialize(PARROT_INTERP);

#endif
60 changes: 29 additions & 31 deletions src/6model/reprs/KnowHOWREPR.c
Expand Up @@ -9,7 +9,7 @@
#include "KnowHOWREPR.h"

/* This representation's function pointer table. */
static PMC *this_repr;
static REPROps *this_repr;

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

/* Initializes the KnowHOWREPR representation. */
PMC * KnowHOWREPR_initialize(PARROT_INTERP) {
REPROps * KnowHOWREPR_initialize(PARROT_INTERP) {
/* Allocate and populate the representation function table. */
REPRCommonalities *repr = mem_allocate_typed(REPRCommonalities);
repr->type_object_for = type_object_for;
repr->instance_of = instance_of;
repr->defined = defined;
repr->get_attribute = get_attribute;
repr->get_attribute_int = get_attribute_int;
repr->get_attribute_num = get_attribute_num;
repr->get_attribute_str = get_attribute_str;
repr->bind_attribute = bind_attribute;
repr->bind_attribute_int = bind_attribute_int;
repr->bind_attribute_num = bind_attribute_num;
repr->bind_attribute_str = bind_attribute_str;
repr->hint_for = hint_for;
repr->clone = repr_clone;
repr->set_int = set_int;
repr->get_int = get_int;
repr->set_num = set_num;
repr->get_num = get_num;
repr->set_str = set_str;
repr->get_str = get_str;
repr->gc_mark = gc_mark;
repr->gc_free = gc_free;
repr->gc_mark_repr = NULL;
repr->gc_free_repr = NULL;
repr->get_storage_spec = get_storage_spec;
repr->is_attribute_initialized = is_attribute_initialized;

/* Wrap it in a PMC. */
return (this_repr = wrap_repr(interp, repr));
this_repr = mem_allocate_typed(REPROps);
this_repr->type_object_for = type_object_for;
this_repr->instance_of = instance_of;
this_repr->defined = defined;
this_repr->get_attribute = get_attribute;
this_repr->get_attribute_int = get_attribute_int;
this_repr->get_attribute_num = get_attribute_num;
this_repr->get_attribute_str = get_attribute_str;
this_repr->bind_attribute = bind_attribute;
this_repr->bind_attribute_int = bind_attribute_int;
this_repr->bind_attribute_num = bind_attribute_num;
this_repr->bind_attribute_str = bind_attribute_str;
this_repr->hint_for = hint_for;
this_repr->clone = repr_clone;
this_repr->set_int = set_int;
this_repr->get_int = get_int;
this_repr->set_num = set_num;
this_repr->get_num = get_num;
this_repr->set_str = set_str;
this_repr->get_str = get_str;
this_repr->gc_mark = gc_mark;
this_repr->gc_free = gc_free;
this_repr->gc_mark_repr = NULL;
this_repr->gc_free_repr = NULL;
this_repr->get_storage_spec = get_storage_spec;
this_repr->is_attribute_initialized = is_attribute_initialized;
return this_repr;
}
2 changes: 1 addition & 1 deletion src/6model/reprs/KnowHOWREPR.h
Expand Up @@ -17,6 +17,6 @@ typedef struct {
} KnowHOWREPRInstance;

/* Initializes the KnowHOW REPR. */
PMC * KnowHOWREPR_initialize(PARROT_INTERP);
REPROps * KnowHOWREPR_initialize(PARROT_INTERP);

#endif
60 changes: 29 additions & 31 deletions src/6model/reprs/P6int.c
Expand Up @@ -8,7 +8,7 @@
#include "P6int.h"

/* This representation's function pointer table. */
static PMC *this_repr;
static REPROps *this_repr;

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

/* Initializes the P6int representation. */
PMC * P6int_initialize(PARROT_INTERP) {
REPROps * P6int_initialize(PARROT_INTERP) {
/* Allocate and populate the representation function table. */
REPRCommonalities *repr = mem_allocate_typed(REPRCommonalities);
repr->type_object_for = type_object_for;
repr->instance_of = instance_of;
repr->defined = defined;
repr->get_attribute = get_attribute;
repr->get_attribute_int = get_attribute_int;
repr->get_attribute_num = get_attribute_num;
repr->get_attribute_str = get_attribute_str;
repr->bind_attribute = bind_attribute;
repr->bind_attribute_int = bind_attribute_int;
repr->bind_attribute_num = bind_attribute_num;
repr->bind_attribute_str = bind_attribute_str;
repr->hint_for = hint_for;
repr->clone = repr_clone;
repr->set_int = set_int;
repr->get_int = get_int;
repr->set_num = set_num;
repr->get_num = get_num;
repr->set_str = set_str;
repr->get_str = get_str;
repr->gc_mark = gc_mark;
repr->gc_free = gc_free;
repr->gc_mark_repr = NULL;
repr->gc_free_repr = NULL;
repr->get_storage_spec = get_storage_spec;
repr->is_attribute_initialized = is_attribute_initialized;

/* Wrap it in a PMC. */
return (this_repr = wrap_repr(interp, repr));
this_repr = mem_allocate_typed(REPROps);
this_repr->type_object_for = type_object_for;
this_repr->instance_of = instance_of;
this_repr->defined = defined;
this_repr->get_attribute = get_attribute;
this_repr->get_attribute_int = get_attribute_int;
this_repr->get_attribute_num = get_attribute_num;
this_repr->get_attribute_str = get_attribute_str;
this_repr->bind_attribute = bind_attribute;
this_repr->bind_attribute_int = bind_attribute_int;
this_repr->bind_attribute_num = bind_attribute_num;
this_repr->bind_attribute_str = bind_attribute_str;
this_repr->hint_for = hint_for;
this_repr->clone = repr_clone;
this_repr->set_int = set_int;
this_repr->get_int = get_int;
this_repr->set_num = set_num;
this_repr->get_num = get_num;
this_repr->set_str = set_str;
this_repr->get_str = get_str;
this_repr->gc_mark = gc_mark;
this_repr->gc_free = gc_free;
this_repr->gc_mark_repr = NULL;
this_repr->gc_free_repr = NULL;
this_repr->get_storage_spec = get_storage_spec;
this_repr->is_attribute_initialized = is_attribute_initialized;
return this_repr;
}
2 changes: 1 addition & 1 deletion src/6model/reprs/P6int.h
Expand Up @@ -11,6 +11,6 @@ typedef struct {
} P6intInstance;

/* Initializes the P6int REPR. */
PMC * P6int_initialize(PARROT_INTERP);
REPROps * P6int_initialize(PARROT_INTERP);

#endif

0 comments on commit 1b06d16

Please sign in to comment.