Skip to content
Permalink
Browse files

Some fixes to 2683b3d

Turned out return value check was a bit too strict.
  • Loading branch information...
lizmat committed Jun 3, 2019
1 parent e118d4e commit 719eefdedff2438bfed9beea96fd0e10ff7634d0
Showing with 16 additions and 65 deletions.
  1. +16 −12 src/core/List.pm6
  2. +0 −53 src/core/Rakudo/Iterator.pm6
@@ -1128,16 +1128,20 @@ my class List does Iterable does Positional { # declared in BOOTSTRAP
)
}

method reverse(List:D: --> Seq:D) is nodal {
nqp::if(
self.is-lazy, # reifies
Failure.new(X::Cannot::Lazy.new(:action<reverse>)),
Seq.new(nqp::if(
$!reified,
Rakudo::Iterator.ReifiedListReverse($!reified),
Rakudo::Iterator.Empty
))
)
method reverse(List:D: --> List:D) is nodal {
self.is-lazy # reifies
?? Failure.new(X::Cannot::Lazy.new(:action<reverse>))
!! $!reified
?? nqp::stmts(
(my \src := nqp::clone(nqp::getattr(self,List,'$!reified'))),
(my \dst := nqp::create(src.WHAT)),
nqp::while(
nqp::elems(src),
nqp::push(dst,nqp::pop(src))
),
nqp::p6bindattrinvres(nqp::create(self),List,'$!reified',dst)
)
!! nqp::create(self)
}

method rotate(List:D: Int(Cool) $rotate = 1) is nodal {
@@ -1681,8 +1685,8 @@ multi sub infix:<xx>(Mu \x, Int:D $n) is pure {
}

proto sub reverse(|) {*}
multi sub reverse(@a --> Seq:D) { @a.reverse }
multi sub reverse(+@a --> Seq:D) { @a.reverse }
multi sub reverse(@a) { @a.reverse }
multi sub reverse(+@a) { @a.reverse }

proto sub rotate($, $?, *%) {*}
multi sub rotate(@a) { @a.rotate }
@@ -2797,59 +2797,6 @@ class Rakudo::Iterator {
ReifiedListIterator.new(list)
}

# Return an iterator that produces values in reverse order for a
# List that has been completely reified already. Returns an nqp::null
# for elements don't exist before the end of the reified list.
my class ReifiedListReverse does PredictiveIterator {
has $!reified;
has int $!i;

method !SET-SELF(\list) {
nqp::stmts(
($!reified := nqp::if(
nqp::istype(list,List),
nqp::getattr(list,List,'$!reified'),
list)),
($!i = nqp::elems($!reified)),
self
)
}
method new(\list) { nqp::create(self)!SET-SELF(list) }

method pull-one() is raw {
nqp::if(
$!i,
nqp::atpos($!reified,$!i = nqp::sub_i($!i,1)),
IterationEnd
)
}
method push-all(\target --> IterationEnd) {
nqp::stmts(
(my int $i = nqp::elems($!reified)),
nqp::while( # doesn't sink
$i,
target.push(nqp::atpos($!reified,($i = nqp::sub_i($i,1))))
),
($!i = 0)
)
}
method skip-one() {
nqp::if(
$!i,
nqp::isge_i(($!i = nqp::sub_i($!i,1)),0)
)
}
method skip-at-least(int $toskip) {
nqp::unless(
nqp::isge_i(($!i = nqp::sub_i($!i,$toskip)),0),
($!i = 0)
)
}
method count-only(--> Int:D) { nqp::p6box_i($!i) }
method sink-all(--> IterationEnd) { $!i = 0 }
}
method ReifiedListReverse(\list) { ReifiedListReverse.new(list) }

# Return a lazy iterator that will repeat the values of a given
# source iterator indefinitely. Even when given a lazy iterator,
# it will cache the values seen to handle case that the iterator

0 comments on commit 719eefd

Please sign in to comment.
You can’t perform that action at this time.