Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
First sketch of implementation of is_attribute_initialized for all re…
…prs.
  • Loading branch information
jnthn committed Jul 5, 2011
1 parent b003b38 commit 0ae9745
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/6model/reprs/HashAttrStore.c
Expand Up @@ -177,6 +177,15 @@ static storage_spec get_storage_spec(PARROT_INTERP, STable *st) {
return spec;
}

/* Checks if an attribute has been initialized. */
static INTVAL is_attribute_initialized(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
HashAttrStoreInstance *instance = (HashAttrStoreInstance *)PMC_data(obj);
if (!instance->store)
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot access attributes in a type object");
return VTABLE_exists_keyed_str(interp, instance->store, name);
}

/* Initializes the HashAttrStore representation. */
PMC * HashAttrStore_initialize(PARROT_INTERP) {
/* Allocate and populate the representation function table. */
Expand All @@ -203,6 +212,7 @@ PMC * HashAttrStore_initialize(PARROT_INTERP) {
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));
Expand Down
8 changes: 7 additions & 1 deletion src/6model/reprs/KnowHOWREPR.c
Expand Up @@ -47,7 +47,7 @@ static INTVAL defined(PARROT_INTERP, PMC *obj) {
/* Helper to die because this type doesn't support attributes. */
static void die_no_attrs(PARROT_INTERP) {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"P6str representation does not support attribute storage");
"KnowHOWREPR representation does not support attribute storage");
}

/* Gets the current value for an attribute. */
Expand Down Expand Up @@ -167,6 +167,11 @@ static storage_spec get_storage_spec(PARROT_INTERP, STable *st) {
return spec;
}

/* Checks if an attribute has been initialized. */
static INTVAL is_attribute_initialized(PARROT_INTERP, PMC *Object, PMC *ClassHandle, STRING *Name, INTVAL Hint) {
die_no_attrs(interp);
}

/* Initializes the KnowHOWREPR representation. */
PMC * KnowHOWREPR_initialize(PARROT_INTERP) {
/* Allocate and populate the representation function table. */
Expand Down Expand Up @@ -195,6 +200,7 @@ PMC * KnowHOWREPR_initialize(PARROT_INTERP) {
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));
Expand Down
6 changes: 6 additions & 0 deletions src/6model/reprs/P6int.c
Expand Up @@ -158,6 +158,11 @@ static storage_spec get_storage_spec(PARROT_INTERP, STable *st) {
return spec;
}

/* Checks if an attribute has been initialized. */
static INTVAL is_attribute_initialized(PARROT_INTERP, PMC *Object, PMC *ClassHandle, STRING *Name, INTVAL Hint) {
die_no_attrs(interp);
}

/* Initializes the P6int representation. */
PMC * P6int_initialize(PARROT_INTERP) {
/* Allocate and populate the representation function table. */
Expand Down Expand Up @@ -186,6 +191,7 @@ PMC * P6int_initialize(PARROT_INTERP) {
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));
Expand Down
6 changes: 6 additions & 0 deletions src/6model/reprs/P6num.c
Expand Up @@ -158,6 +158,11 @@ static storage_spec get_storage_spec(PARROT_INTERP, STable *st) {
return spec;
}

/* Checks if an attribute has been initialized. */
static INTVAL is_attribute_initialized(PARROT_INTERP, PMC *Object, PMC *ClassHandle, STRING *Name, INTVAL Hint) {
die_no_attrs(interp);
}

/* Initializes the P6num representation. */
PMC * P6num_initialize(PARROT_INTERP) {
/* Allocate and populate the representation function table. */
Expand Down Expand Up @@ -186,6 +191,7 @@ PMC * P6num_initialize(PARROT_INTERP) {
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));
Expand Down
18 changes: 18 additions & 0 deletions src/6model/reprs/P6opaque.c
Expand Up @@ -775,6 +775,23 @@ static storage_spec get_storage_spec(PARROT_INTERP, STable *st) {
return spec;
}

/* Checks if an attribute has been initialized. */
static INTVAL is_attribute_initialized(PARROT_INTERP, PMC *obj, PMC *class_handle, STRING *name, INTVAL hint) {
P6opaqueInstance *instance = (P6opaqueInstance *)PMC_data(obj);
P6opaqueREPRData *repr_data = (P6opaqueREPRData *)STABLE(obj)->REPR_data;
INTVAL slot;

if (!instance->spill)
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Cannot access attributes in a type object");

slot = try_get_slot(interp, repr_data, class_handle, name);
if (slot >= 0)
return NULL != get_pmc_at_offset(instance, repr_data->attribute_offsets[slot]);
else
no_such_attribute(interp, "initializedness check", class_handle, name);
}

/* Initializes the P6opaque representation. */
PMC * P6opaque_initialize(PARROT_INTERP) {
/* Allocate and populate the representation function table. */
Expand Down Expand Up @@ -803,6 +820,7 @@ PMC * P6opaque_initialize(PARROT_INTERP) {
repr->gc_mark_repr = gc_mark_repr;
repr->gc_free_repr = gc_free_repr;
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));
Expand Down
6 changes: 6 additions & 0 deletions src/6model/reprs/P6str.c
Expand Up @@ -160,6 +160,11 @@ static storage_spec get_storage_spec(PARROT_INTERP, STable *st) {
return spec;
}

/* Checks if an attribute has been initialized. */
static INTVAL is_attribute_initialized(PARROT_INTERP, PMC *Object, PMC *ClassHandle, STRING *Name, INTVAL Hint) {
die_no_attrs(interp);
}

/* Initializes the P6str representation. */
PMC * P6str_initialize(PARROT_INTERP) {
/* Allocate and populate the representation function table. */
Expand Down Expand Up @@ -188,6 +193,7 @@ PMC * P6str_initialize(PARROT_INTERP) {
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));
Expand Down
6 changes: 6 additions & 0 deletions src/6model/reprs/Uninstantiable.c
Expand Up @@ -156,6 +156,11 @@ static storage_spec get_storage_spec(PARROT_INTERP, STable *st) {
return spec;
}

/* Checks if an attribute has been initialized. */
static INTVAL is_attribute_initialized(PARROT_INTERP, PMC *Object, PMC *ClassHandle, STRING *Name, INTVAL Hint) {
die_no_attrs(interp);
}

/* Initializes the Uninstantiable representation. */
PMC * Uninstantiable_initialize(PARROT_INTERP) {
/* Allocate and populate the representation function table. */
Expand Down Expand Up @@ -184,6 +189,7 @@ PMC * Uninstantiable_initialize(PARROT_INTERP) {
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));
Expand Down

0 comments on commit 0ae9745

Please sign in to comment.