Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add repr_change_type op, for asking the repr to do a type change on t…
…he object.
  • Loading branch information
jnthn committed Jul 10, 2011
1 parent 1f28be4 commit dbc9e77
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/ops/nqp.ops
Expand Up @@ -374,6 +374,33 @@ inline op repr_is_attr_initialized(out INT, in PMC, in PMC, in STR) :base_core {
}


/*

=item repr_change_type()

Tries to change the type of the object in $1 to the type $2. This
delegates to the REPR to do the work, so it is ultimately up to the
REPR to decide what changes it will or won't allow.

=cut

*/
inline op repr_change_type(in PMC, in PMC) :base_core {
PMC *obj = decontainerize(interp, $1);
PMC *new_type = decontainerize(interp, $2);
if (obj->vtable->base_type == smo_id && new_type->vtable->base_type == smo_id) {
if (REPR(obj)->change_type)
REPR(obj)->change_type(interp, obj, new_type);
else
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Representation does not implement change_type");
}
else {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"Can only use repr_change_type on SixModelObjects");
}
}

/*

=item type_check(obj, wanted_type)
Expand Down

0 comments on commit dbc9e77

Please sign in to comment.