Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a way to get the name of the representation an object is based on.
  • Loading branch information
jnthn committed Nov 27, 2011
1 parent 61a0eac commit 65cfe28
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/6model/repr_registry.c
Expand Up @@ -36,6 +36,7 @@ static void register_repr(PARROT_INTERP, STRING *name, REPROps *repr) {
repr_registry[ID] = repr;
VTABLE_set_integer_keyed_str(interp, repr_name_to_id_map, name, ID);
repr->ID = ID;
repr->name = name;
}

/* Dynamically registers a representation (that is, one defined outside of
Expand Down
3 changes: 3 additions & 0 deletions src/6model/sixmodelobject.h
Expand Up @@ -262,6 +262,9 @@ struct SixModel_REPROps {

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

/* The representation's name. */
STRING *name;
};

/* Hint value to indicate the absence of an attribute lookup or method
Expand Down
22 changes: 22 additions & 0 deletions src/ops/nqp.ops
Expand Up @@ -706,6 +706,28 @@ inline op repr_change_type(in PMC, in PMC) :base_core {
}
}


/*

=item repr_name

Takes an object and returns a string containing the name of its representation.

=cut

*/
inline op repr_name(out STR, in PMC) :base_core {
PMC *val = decontainerize(interp, $2);
if (val->vtable->base_type == smo_id) {
$1 = REPR(val)->name;
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use repr_name with a SixModelObject");
}
}


/*

=item type_check(obj, wanted_type)
Expand Down

0 comments on commit 65cfe28

Please sign in to comment.