Skip to content

Commit

Permalink
Workaround for various gather/take bugs.
Browse files Browse the repository at this point in the history
This in theory shouldn't be needed, and in practice is needed. The
reason probably lies deep in the bowels of code-gen, or deep in the
bowels of the interaction between the handler stack and continuations.
  • Loading branch information
jnthn committed Aug 13, 2015
1 parent 74a9c35 commit 95934a0
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/core/Seq.pm
Expand Up @@ -281,24 +281,26 @@ sub GATHER(&block) {
my \iter = self.CREATE;
my int $wanted;
my $taken;
my $taker := {
nqp::stmts(
($taken := nqp::getpayload(nqp::exception())),
nqp::if(nqp::istype($taken, Slip),
nqp::stmts(
iter!start-slip-wanted($taken),
($wanted = nqp::getattr_i(iter, self, '$!wanted'))),
nqp::stmts(
nqp::getattr(iter, self, '$!push-target').push($taken),
($wanted = nqp::bindattr_i(iter, self, '$!wanted',
nqp::sub_i(nqp::getattr_i(iter, self, '$!wanted'), 1))))),
nqp::if(nqp::iseq_i($wanted, 0),
nqp::continuationcontrol(0, PROMPT, -> Mu \c {
nqp::bindattr(iter, self, '&!resumption', c);
})),
nqp::resume(nqp::exception())
)
}
nqp::bindattr(iter, self, '&!resumption', {
nqp::handle(&block(),
'TAKE', nqp::stmts(
($taken := nqp::getpayload(nqp::exception())),
nqp::if(nqp::istype($taken, Slip),
nqp::stmts(
iter!start-slip-wanted($taken),
($wanted = nqp::getattr_i(iter, self, '$!wanted'))),
nqp::stmts(
nqp::getattr(iter, self, '$!push-target').push($taken),
($wanted = nqp::bindattr_i(iter, self, '$!wanted',
nqp::sub_i(nqp::getattr_i(iter, self, '$!wanted'), 1))))),
nqp::if(nqp::iseq_i($wanted, 0),
nqp::continuationcontrol(0, PROMPT, -> Mu \c {
nqp::bindattr(iter, self, '&!resumption', c);
})),
nqp::resume(nqp::exception())
));
nqp::handle(&block(), 'TAKE', $taker());
nqp::continuationcontrol(0, PROMPT, -> | {
nqp::bindattr(iter, self, '&!resumption', Callable)
});
Expand Down

0 comments on commit 95934a0

Please sign in to comment.