Skip to content

Commit

Permalink
A cheating, eager gather/take.
Browse files Browse the repository at this point in the history
Gets us by for the basic things for now, until MoarVM has continuation
support implemented.
  • Loading branch information
jnthn committed Dec 18, 2013
1 parent 0df06cf commit c5ecb99
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/core/GatherIter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class GatherIter is Iterator {
#?if jvm
my $GATHER_PROMPT = [];
my $SENTINEL := [];
#?endif
#?if moar
my $SENTINEL := [];
#?endif
method new($block, Mu :$infinite) {
#?if parrot
Expand All @@ -29,7 +32,22 @@ class GatherIter is Iterator {
my $coro := sub () is rw { nqp::continuationreset($GATHER_PROMPT, $state); $takings };
#?endif
#?if moar
my $coro = die 'GatherIter NYI on MoarVM';
# XXX Cheating, eager implementation for now.
my int $done = 0;
my $coro := -> {
if $done {
$SENTINEL
}
else {
my Mu $takings := nqp::list();
nqp::handle($block().eager(),
'TAKE', nqp::stmts(
nqp::push($takings, nqp::getpayload(nqp::exception())),
nqp::resume(nqp::exception())));
$done = 1;
nqp::p6parcel($takings, Mu)
}
}
#?endif
my Mu $new := nqp::create(self);
nqp::bindattr($new, GatherIter, '$!coro', $coro);
Expand Down Expand Up @@ -62,6 +80,9 @@ class GatherIter is Iterator {
#?endif
#?if jvm
$end = nqp::p6bool(nqp::eqaddr($parcel, $SENTINEL));
#?endif
#?if moar
$end = nqp::p6bool(nqp::eqaddr($parcel, $SENTINEL));
#?endif
nqp::push($rpa, $parcel) unless $end;
$count = $count - 1;
Expand Down

0 comments on commit c5ecb99

Please sign in to comment.