Skip to content

Commit

Permalink
Parrot implementation of nqp::p6scalarfromdesc.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Aug 18, 2013
1 parent 1c86f71 commit db2330c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/vm/parrot/Perl6/Ops.nqp
Expand Up @@ -68,6 +68,7 @@ $ops.add_hll_op('perl6', 'p6staticouter', -> $qastcomp, $op {
$op[0]
))
});
$ops.add_hll_pirop_mapping('perl6', 'p6scalarfromdesc', 'p6scalarfromdesc', 'PP', :inlinable(1));

# Make some of them also available from NQP land, since we use them in the
# metamodel and bootstrap.
Expand Down
38 changes: 38 additions & 0 deletions src/vm/parrot/ops/perl6.ops
Expand Up @@ -252,6 +252,8 @@ static PMC* sub_find_pad(PARROT_INTERP, ARGIN(STRING *lex_name), ARGIN(PMC *ctx)
}
}

static PMC *defaultContainerDescriptor = NULL;

static INTVAL initialized_ops = 0;

PARROT_DYNEXT_EXPORT PMC*
Expand Down Expand Up @@ -658,6 +660,20 @@ inline op p6settypes(invar PMC) :base_core {
Parrot_str_new_constant(interp, "Junction")));
Rakudo_types_nil_set(VTABLE_get_pmc_keyed_str(interp, $1,
Parrot_str_new_constant(interp, "Nil")));

{
PMC *CD = VTABLE_get_pmc_keyed_str(interp, $1,
Parrot_str_new_constant(interp, "ContainerDescriptor"));
PMC *defCD = REPR(CD)->allocate(interp, STABLE(CD));
Rakudo_ContainerDescriptor *cd = ((Rakudo_ContainerDescriptor *)PMC_data(defCD));
REPR(defCD)->initialize(interp, STABLE(defCD), OBJECT_BODY(defCD));
cd->of = Rakudo_types_mu_get();
cd->name = Parrot_str_new_constant(interp, "<element>");
cd->rw = 1;
cd->the_default = Rakudo_types_any_get();
defaultContainerDescriptor = defCD;
Parrot_pmc_gc_register(interp, defaultContainerDescriptor);
}
}


Expand Down Expand Up @@ -1562,6 +1578,28 @@ inline op perl6_get_outer_ctx(out PMC, in PMC) {
}
}

/*

=item p6scalarfromdesc

Creates a Scalar from the specified descriptor.

=cut

*/
inline op p6scalarfromdesc(out PMC, invar PMC) {
PMC *cont;
PMC *desc = $2;

if (PMC_IS_NULL($2) || !IS_CONCRETE($2))
desc = defaultContainerDescriptor;

cont = Rakudo_cont_scalar_from_descriptor(interp, desc);
((Rakudo_Scalar *)PMC_data(cont))->value = ((Rakudo_ContainerDescriptor *)PMC_data(desc))->the_default;

$1 = cont;
}

/*
* Local variables:
* c-file-style: "parrot"
Expand Down

0 comments on commit db2330c

Please sign in to comment.