Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add is_container and nqp_decontainerize ops.
  • Loading branch information
jnthn committed Jun 1, 2011
1 parent 1f9da88 commit 5f29114
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/ops/nqp.ops
Expand Up @@ -963,3 +963,61 @@ inline op repr_get_primitive_type_spec(out INT, in PMC) :base_core {
$1 = STORAGE_SPEC_BP_NONE;
}
}

/*

=item is_container

Checks if the type of thing in $2 is a container or not. Puts a non-zero
value in $1 if it is a container and 0 otherwise. Any non-6model type is
considered not to be a container.

=cut

*/
inline op is_container(out INT, in PMC) :base_core {
if ($2->vtable->base_type == smo_id)
$1 = STABLE($2)->container_spec != NULL;
else
$1 = 0;
}

/*

=item nqp_decontainerize

If the thing in $2 is a container, does a decontainerizing operation
and puts the contained value in $1.

=cut

*/
inline op nqp_decontainerize(out PMC, in PMC) :base_core {
if ($2->vtable->base_type == smo_id) {
ContainerSpec *spec = STABLE($2)->container_spec;
if (spec) {
if (!PMC_IS_NULL(spec->value_slot.class_handle)) {
/* Just get slot. */
$2 = VTABLE_get_attr_keyed(interp, $2, spec->value_slot.class_handle,
spec->value_slot.attr_name);
}
else {
/* Invoke FETCH method. */
PMC *old_ctx = Parrot_pcc_get_signature(interp, CURRENT_CONTEXT(interp));
PMC *meth = VTABLE_find_method(interp, $2, Parrot_str_new(interp, "FETCH", 0));
PMC *cappy = Parrot_pmc_new(interp, enum_class_CallContext);
VTABLE_push_pmc(interp, cappy, $2);
Parrot_pcc_invoke_from_sig_object(interp, meth, cappy);
cappy = Parrot_pcc_get_signature(interp, CURRENT_CONTEXT(interp));
Parrot_pcc_set_signature(interp, CURRENT_CONTEXT(interp), old_ctx);
$1 = VTABLE_get_pmc_keyed_int(interp, cappy, 0);
}
}
else {
$1 = $2;
}
}
else {
$1 = $2;
}
}

0 comments on commit 5f29114

Please sign in to comment.