Skip to content

Commit

Permalink
Our aggregates can benefit from some Infinite wisdom again.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Jun 23, 2011
1 parent 1e975bf commit 28c1fff
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/core/Any.pm
Expand Up @@ -11,6 +11,7 @@ my class Any {
method flat() { nqp::p6list(List, nqp::list(self), 1.Bool) }
method list() { nqp::p6list(List, nqp::list(self), Mu) }
method elems() { self.list.elems }
method infinite() { Mu }

method join($separator = ' ') {
my $list = (self,).flat.eager;
Expand Down
10 changes: 10 additions & 0 deletions src/core/Array.pm
Expand Up @@ -16,6 +16,16 @@ class Array {
!! self.WHAT.perl ~ '.new(' ~ self.map({.perl}).join(', ') ~ ')'
}

method REIFY(Parcel \$parcel) {
my Mu $rpa := $parcel.RPA;
my Mu $iter := nqp::iterator($rpa);
my $i = 0;
while $iter {
nqp::bindpos($rpa, nqp::unbox_i($i++), my $v = nqp::shift($iter));
}
pir::find_method__PPs(List, 'REIFY')(self, $parcel)
}

method STORE_AT_POS(\$pos, Mu $v is copy) {
pir::find_method__PPs(List, 'STORE_AT_POS')(self, $pos, $v);
}
Expand Down
3 changes: 1 addition & 2 deletions src/core/List.pm
Expand Up @@ -59,8 +59,7 @@ class List {
}

method infinite() {
self.gimme(*);
$!nextiter.defined
$!nextiter.defined && $!nextiter.infinite;
}

method iterator() {
Expand Down
3 changes: 2 additions & 1 deletion src/core/ListIter.pm
Expand Up @@ -25,6 +25,7 @@ my class ListIter {
if $!rest && nqp::islt_i(nqp::elems($rpa), nqp::unbox_i($count)) {
$x := nqp::shift($!rest);
if nqp::isconcrete($x) {
last if $eager && $x.infinite;
$x := $x.iterator.reify($count) if nqp::p6isa($x, Iterable);
nqp::splice($!rest, nqp::getattr($x, Parcel, '$!storage'), 0, 0);

Expand All @@ -51,7 +52,7 @@ my class ListIter {

method infinite() {
$!rest
?? Iterable.ACCEPTS(nqp::atpos($!rest,0))
?? nqp::p6isa(nqp::atpos($!rest, 0), Iterable)
&& nqp::atpos($!rest,0).infinite
|| Mu
!! 0.Bool
Expand Down

0 comments on commit 28c1fff

Please sign in to comment.