Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Create an opcode for building Parcels; the opcode also handles replacing

any PMCNULL values that might show up (e.g., in Arrays).
  • Loading branch information...
commit 88127187ef76047a710e7845ab496a6ab5a16824 1 parent 3c22598
@pmichaud pmichaud authored
View
1  src/Perl6/Actions.pm
@@ -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',
View
10 src/Perl6/Metamodel/BOOTSTRAP.pm
@@ -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 {
# ...
# }
@@ -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.
@@ -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;
View
21 src/binder/bind.c
@@ -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 *
View
1  src/binder/bind.h
@@ -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);
View
4 src/binder/types.c
@@ -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;
@@ -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; }
View
3  src/binder/types.h
@@ -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);
View
7 src/core/List.pm
@@ -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) {
@@ -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
)
}
View
2  src/core/ListIter.pm
@@ -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'),
View
4 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)
View
20 src/ops/perl6.ops
@@ -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);
}
@@ -724,6 +725,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)
Creates a lazy Perl 6 ListIter object from the RPA in $2
View
2  tools/build/Makefile.in
@@ -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 \
@@ -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 \
Please sign in to comment.
Something went wrong with that request. Please try again.