Skip to content

Commit

Permalink
Create an opcode for building Parcels; the opcode also handles replacing
Browse files Browse the repository at this point in the history
any PMCNULL values that might show up (e.g., in Arrays).
  • Loading branch information
pmichaud committed Jun 27, 2011
1 parent 3c22598 commit 8812718
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/Perl6/Actions.pm
Expand Up @@ -7,6 +7,7 @@ INIT {
p6box_n => 'perl6_box_num__Pn',
p6box_s => 'perl6_box_str__Ps',
p6bool => 'perl6_booleanize__Pi',
p6parcel => 'perl6_parcel_from_rpa__PPP',
p6listiter => 'perl6_iter_from_rpa__PPP',
p6list => 'perl6_list_from_rpa__PPPP',

Expand Down
10 changes: 9 additions & 1 deletion src/Perl6/Metamodel/BOOTSTRAP.pm
Expand Up @@ -415,6 +415,13 @@ Num.HOW.add_attribute(Num, BOOTSTRAPATTR.new(:name<$!value>, :type(num), :box_ta
# Stash these common types for box ops.
pir::perl6_set_types_ins__vPPP(Int, Num, Str);

# class Parcel is Cool {
# ...
# }
my stub Parcel metaclass Perl6::Metamodel::ClassHOW { ... };
Parcel.HOW.add_parent(Parcel, Cool);
Parcel.HOW.add_attribute(Parcel, scalar_attr('$!storage', Mu));

# class Iterable is Cool {
# ...
# }
Expand Down Expand Up @@ -487,7 +494,7 @@ Hash.HOW.add_parent(Hash, EnumMap);
Hash.HOW.add_attribute(Hash, BOOTSTRAPATTR.new(:name<$!descriptor>, :type(Mu)));

# Configure declarative listy/hashy types.
pir::perl6_set_types_list_array_lol__vPP(List, ListIter, Array, LoL);
pir::perl6_set_types_list_array_lol__vPP(List, ListIter, Array, LoL, Parcel);
pir::perl6_set_types_enummap_hash__vPP(EnumMap, Hash);

# XXX Quick and dirty Bool. Probably done by EnumHOW in the end.
Expand Down Expand Up @@ -578,6 +585,7 @@ my module EXPORT {
$?PACKAGE.WHO<Real> := Real;
$?PACKAGE.WHO<Int> := Int;
$?PACKAGE.WHO<Num> := Num;
$?PACKAGE.WHO<Parcel> := Parcel;
$?PACKAGE.WHO<Iterable> := Iterable;
$?PACKAGE.WHO<Iterator> := Iterator;
$?PACKAGE.WHO<ListIter> := ListIter;
Expand Down
21 changes: 21 additions & 0 deletions src/binder/bind.c
Expand Up @@ -63,6 +63,27 @@ static void setup_binder_statics(PARROT_INTERP) {
}


/* Creates a Parcel from a RPA, filling PMCNULL elements if needed. */
/* This function gets shared with perl6.ops for the perl6_parcel_from_rpa op. */
PMC *
Rakudo_binding_parcel_from_rpa(PARROT_INTERP, PMC *rpa, PMC *fill) {
PMC *type = Rakudo_types_parcel_get();
PMC *parcel = REPR(type)->instance_of(interp, type);
VTABLE_set_attr_keyed(interp, parcel, type, STORAGE_str, rpa);

if (!PMC_IS_NULL(fill)) {
INTVAL elems = VTABLE_elements(interp, rpa);
INTVAL i;
for (i = 0; i < elems; i++) {
if (PMC_IS_NULL(VTABLE_get_pmc_keyed_int(interp, rpa, i)))
VTABLE_set_pmc_keyed_int(interp, rpa, i, fill);
}
}

return parcel;
}


/* Creates a ListIter from a RPA */
/* This function gets shared with perl6.ops for the perl6_iter_from_rpa op. */
PMC *
Expand Down
1 change: 1 addition & 0 deletions src/binder/bind.h
Expand Up @@ -78,6 +78,7 @@ PMC * Rakudo_binder_get_top_type(void);
void Rakudo_binder_set_junction_type(PMC *type);
PMC * Rakudo_binder_get_junction_type(void);
/* for perl6.ops */
PMC * Rakudo_binding_parcel_from_rpa(PARROT_INTERP, PMC *rpa, PMC *fill);
PMC * Rakudo_binding_iter_from_rpa(PARROT_INTERP, PMC *rpa, PMC *list);
PMC * Rakudo_binding_list_from_rpa(PARROT_INTERP, PMC *rpa, PMC *type, PMC *flat);

Expand Down
4 changes: 4 additions & 0 deletions src/binder/types.c
Expand Up @@ -13,6 +13,7 @@ static PMC * Junction = NULL;
static PMC * Int = NULL;
static PMC * Num = NULL;
static PMC * Str = NULL;
static PMC * Parcel = NULL;
static PMC * List = NULL;
static PMC * ListIter = NULL;
static PMC * Array = NULL;
Expand All @@ -38,6 +39,9 @@ PMC * Rakudo_types_num_get(void) { return Num; }
void Rakudo_types_str_set(PMC * type) { Str = type; }
PMC * Rakudo_types_str_get(void) { return Str; }

void Rakudo_types_parcel_set(PMC * type) { Parcel = type; }
PMC * Rakudo_types_parcel_get(void) { return Parcel; }

void Rakudo_types_list_set(PMC * type) { List = type; }
PMC * Rakudo_types_list_get(void) { return List; }

Expand Down
3 changes: 3 additions & 0 deletions src/binder/types.h
Expand Up @@ -16,6 +16,9 @@ PMC * Rakudo_types_num_get(void);
void Rakudo_types_str_set(PMC * type);
PMC * Rakudo_types_str_get(void);

void Rakudo_types_parcel_set(PMC * type);
PMC * Rakudo_types_parcel_get(void);

void Rakudo_types_list_set(PMC * type);
PMC * Rakudo_types_list_get(void);

Expand Down
7 changes: 4 additions & 3 deletions src/core/List.pm
Expand Up @@ -28,7 +28,7 @@ class List does Positional {
nqp::bindattr(self, List, '$!items', nqp::list());
my Mu $rpa := nqp::clone($!items);
nqp::push($rpa, $!nextiter) if $!nextiter.defined;
pir__perl6_box_rpa__PP($rpa);
nqp::p6parcel($rpa, Any);
}

method at_pos(\$pos) {
Expand Down Expand Up @@ -88,8 +88,9 @@ class List does Positional {
self.gimme($n) if nqp::not_i(nqp::istype($n, Int))
|| nqp::isnull($!items)
|| nqp::islt_i(nqp::elems($!items), nqp::unbox_i($n));
pir__perl6_box_rpa__PP(
pir::perl6_shiftpush__0PPi(nqp::list(), $!items, nqp::unbox_i($n))
nqp::p6parcel(
pir::perl6_shiftpush__0PPi(nqp::list(), $!items, nqp::unbox_i($n)),
Any
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/ListIter.pm
Expand Up @@ -35,7 +35,7 @@ my class ListIter {
}
}
}
my $reified := pir__perl6_box_rpa__PP($rpa);
my $reified := nqp::p6parcel($rpa, Any);
$reified := $!list.REIFY($reified) if $!list.defined && !$sink;
nqp::push(
nqp::getattr($reified, Parcel, '$!storage'),
Expand Down
4 changes: 3 additions & 1 deletion src/core/Parcel.pm
@@ -1,5 +1,7 @@
my class Parcel does Positional {
has $!storage; # RPA of Parcel's elements
# declared in BOOTSTRAP.pm:
# is Cool; # parent class
# has $!storage; # RPA of Parcel's elements

method flat() {
nqp::p6list(pir::clone__PP($!storage), List, 1.Bool)
Expand Down
20 changes: 18 additions & 2 deletions src/ops/perl6.ops
Expand Up @@ -325,18 +325,19 @@ inline op perl6_set_types_ins(in PMC, in PMC, in PMC) :base_core {

/*

=item perl6_set_types_list_array_lol(in PMC, in PMC, in PMC, in PMC)
=item perl6_set_types_list_array_lol(in PMC, in PMC, in PMC, in PMC, in PMC)

Sets the List, ListIter, Array and LoL types.

=cut

*/
inline op perl6_set_types_list_array_lol(in PMC, in PMC, in PMC, in PMC) :base_core {
inline op perl6_set_types_list_array_lol(in PMC, in PMC, in PMC, in PMC, in PMC) :base_core {
Rakudo_types_list_set($1);
Rakudo_types_listiter_set($2);
Rakudo_types_array_set($3);
Rakudo_types_lol_set($4);
Rakudo_types_parcel_set($5);
}


Expand Down Expand Up @@ -722,6 +723,21 @@ inline op perl6_current_args_rpa(out PMC) :base_core {
}


/*

=item perl6_parcel_from_rpa(out PMC, in PMC, in PMC)

Creates a Perl 6 Parcel object from the RPA in $2, replacing
any PMCNULL elements with $3.

=cut

*/
inline op perl6_parcel_from_rpa(out PMC, in PMC, in PMC) :base_core {
$1 = Rakudo_binding_parcel_from_rpa(interp, $2, $3);
}


/*

=item perl6_iter_from_rpa(out PMC, in PMC, in PMC)
Expand Down
2 changes: 1 addition & 1 deletion tools/build/Makefile.in
Expand Up @@ -127,7 +127,6 @@ CORE_SOURCES = \
src/core/Any.pm \
src/core/Code.pm \
src/core/Attribute.pm \
src/core/Parcel.pm \
src/core/Cool.pm \
src/core/Bool.pm \
src/core/Numeric.pm \
Expand All @@ -136,6 +135,7 @@ CORE_SOURCES = \
src/core/Num.pm \
src/core/Stringy.pm \
src/core/Str.pm \
src/core/Parcel.pm \
src/core/Iterable.pm \
src/core/Iterator.pm \
src/core/Nil.pm \
Expand Down

0 comments on commit 8812718

Please sign in to comment.