Skip to content

Commit

Permalink
Merge pull request #3517 from vrurg/rakudo_3499
Browse files Browse the repository at this point in the history
Fix problems with nextcallee
  • Loading branch information
vrurg committed Feb 27, 2020
2 parents 8454f8d + 59a86c3 commit 0f223ac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/Perl6/Metamodel/Dispatchers.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,16 @@ class Perl6::Metamodel::BaseDispatcher {
}

method shift_callee() {
my $callee := @!candidates[$!idx];
++$!idx;
nqp::decont($callee)
my @call := [nqp::null(), nqp::null()];
if self.last_candidate {
if $!next_dispatcher {
@call := $!next_dispatcher.shift_callee;
}
}
else {
@call := self.get_call;
}
@call;
}

method add_from_mro(@methods, $class, $sub, :$skip_first = 0) {
Expand Down Expand Up @@ -128,8 +135,7 @@ class Perl6::Metamodel::MethodDispatcher is Perl6::Metamodel::BaseDispatcher {

method vivify_for($sub, $lexpad, $args) {
my $obj := $lexpad<self>;
my $class := nqp::getlexrel($lexpad, '::?CLASS');
my @methods := self.add_from_mro([], $class, $sub);
my @methods := self.add_from_mro([], $obj, $sub);
self.new(:candidates(@methods), :obj($obj), :idx(1))
}

Expand Down
15 changes: 14 additions & 1 deletion src/core.c/control.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,20 @@ sub lastcall(--> True) {

sub nextcallee() {
my Mu $dispatcher := nqp::p6finddispatcher('nextsame');
$dispatcher.exhausted ?? Nil !! $dispatcher.shift_callee()
if $dispatcher.exhausted {
Nil
}
else {
# XXX Until there is a nqp op which would repace $*NEXT-DISPATCHER, this is the only way for nextcallee to
# support chaining of dispatchers.
my @call = $dispatcher.shift_callee;
@call[0]
?? -> |args {
my $*NEXT-DISPATCHER := @call[1];
@call[0]( |args )
}
!! Nil
}
}

sub samewith(|c) {
Expand Down

0 comments on commit 0f223ac

Please sign in to comment.