This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/core/Any-iterable-methods.pm b/src/core/Any-iterable-methods.pm | |
| index 8ec6f9e..6cc0fbf 100644 | |
| --- a/src/core/Any-iterable-methods.pm | |
| +++ b/src/core/Any-iterable-methods.pm | |
| @@ -91,19 +91,26 @@ augment class Any { | |
| method pull-one() is rw { | |
| my int $redo = 1; | |
| + my int $NEXT; | |
| + my int $LAST; | |
| my $value; | |
| my $result; | |
| - unless $!did-run { | |
| - nqp::p6setfirstflag(&!block) | |
| - if (nqp::can(&!block, 'phasers') && &!block.phasers('FIRST')); | |
| - $!did-run = 1; | |
| + if nqp::can(&!block, 'fire_phasers') { | |
| + $NEXT = +&!block.phasers('NEXT'); | |
| + $LAST = 1; #+&!block.phasers('LAST'); | |
| + | |
| + unless $!did-run { | |
| + nqp::p6setfirstflag(&!block) if &!block.phasers('FIRST'); | |
| + $!did-run = 1; | |
| + } | |
| } | |
| if $!slipping && ($result := self.slip-one()) !=:= IterationEnd { | |
| $result | |
| } | |
| elsif ($value := $!source.pull-one()) =:= IterationEnd { | |
| + &!block.fire_phasers('LAST') if $LAST; | |
| $value | |
| } | |
| else { | |
| @@ -122,18 +129,38 @@ augment class Any { | |
| nqp::eqaddr($result, IterationEnd), | |
| nqp::stmts( | |
| ($value := $!source.pull-one()), | |
| - ($redo = 1 unless nqp::eqaddr($value, IterationEnd)) | |
| - )) | |
| - )) | |
| + nqp::if( | |
| + nqp::eqaddr($value, IterationEnd), | |
| + nqp::if($LAST, &!block.fire_phasers('LAST')), | |
| + ($redo = 1) | |
| + ) | |
| + ) | |
| + ) | |
| + ), | |
| + nqp::if( | |
| + nqp::istype($result, IterationEnd), | |
| + nqp::if($LAST, &!block.fire_phasers('LAST')), | |
| + ) | |
| + ), | |
| + nqp::if($NEXT, &!block.fire_phasers('NEXT')), | |
| ), | |
| 'LABELED', nqp::decont($!label), | |
| 'NEXT', nqp::stmts( | |
| + nqp::if($NEXT, &!block.fire_phasers('NEXT')), | |
| ($value := $!source.pull-one()), | |
| nqp::eqaddr($value, IterationEnd) | |
| - ?? ($result := IterationEnd) | |
| + ?? nqp::stmts( | |
| + nqp::if($LAST, &!block.fire_phasers('LAST')), | |
| + ($result := IterationEnd), | |
| + ) | |
| !! ($redo = 1)), | |
| 'REDO', $redo = 1, | |
| - 'LAST', ($result := IterationEnd))), | |
| + 'LAST', nqp::stmts( | |
| + nqp::if($LAST, &!block.fire_phasers('LAST')), | |
| + ($result := IterationEnd), | |
| + ) | |
| + ) | |
| + ), | |
| :nohandler); | |
| $result | |
| } | |
| @@ -150,12 +177,18 @@ augment class Any { | |
| ?? nqp::setelems($!value-buffer, 0) | |
| !! ($!value-buffer := IterationBuffer.new); | |
| my int $redo = 1; | |
| + my int $NEXT; | |
| + my int $LAST; | |
| my $result; | |
| - unless $!did-run { | |
| - nqp::p6setfirstflag(&!block) | |
| - if (nqp::can(&!block, 'phasers') && &!block.phasers('FIRST')); | |
| - $!did-run = 1; | |
| + if nqp::can(&!block, 'fire_phasers') { | |
| + $NEXT = +&!block.phasers('NEXT'); | |
| + $LAST = 1; #+&!block.phasers('LAST'); | |
| + | |
| + unless $!did-run { | |
| + nqp::p6setfirstflag(&!block) if &!block.phasers('FIRST'); | |
| + $!did-run = 1; | |
| + } | |
| } | |
| if $!slipping && ($result := self.slip-one()) !=:= IterationEnd { | |
| @@ -163,6 +196,7 @@ augment class Any { | |
| } | |
| elsif $!source.push-exactly($!value-buffer, $!count) =:= IterationEnd | |
| && nqp::elems($!value-buffer) == 0 { | |
| + &!block.fire_phasers('LAST') if $LAST; | |
| IterationEnd | |
| } | |
| else { | |
| @@ -181,22 +215,40 @@ augment class Any { | |
| nqp::eqaddr($result, IterationEnd), | |
| nqp::stmts( | |
| (nqp::setelems($!value-buffer, 0)), | |
| - ($redo = 1 unless nqp::eqaddr( | |
| - $!source.push-exactly($!value-buffer, $!count), | |
| - IterationEnd) | |
| - && nqp::elems($!value-buffer) == 0) | |
| - )) | |
| - )) | |
| + nqp::if( | |
| + nqp::eqaddr($!source.push-exactly($!value-buffer, $!count), | |
| + IterationEnd) && nqp::elems($!value-buffer) == 0, | |
| + nqp::if($LAST, &!block.fire_phasers('LAST')), | |
| + ($redo = 1) | |
| + ) | |
| + ) | |
| + ) | |
| + ), | |
| + nqp::if( | |
| + nqp::istype($result, IterationEnd), | |
| + nqp::if($LAST, &!block.fire_phasers('LAST')), | |
| + ) | |
| + ), | |
| + nqp::if($NEXT, &!block.fire_phasers('NEXT')), | |
| ), | |
| 'LABELED', nqp::decont($!label), | |
| 'NEXT', nqp::stmts( | |
| + nqp::if($NEXT, &!block.fire_phasers('NEXT')), | |
| (nqp::setelems($!value-buffer, 0)), | |
| nqp::eqaddr($!source.push-exactly($!value-buffer, $!count), IterationEnd) | |
| && nqp::elems($!value-buffer) == 0 | |
| - ?? ($result := IterationEnd) | |
| + ?? nqp::stmts( | |
| + nqp::if($LAST, &!block.fire_phasers('LAST')), | |
| + ($result := IterationEnd), | |
| + ) | |
| !! ($redo = 1)), | |
| 'REDO', $redo = 1, | |
| - 'LAST', ($result := IterationEnd))), | |
| + 'LAST', nqp::stmts( | |
| + nqp::if($LAST, &!block.fire_phasers('LAST')), | |
| + ($result := IterationEnd), | |
| + ) | |
| + ) | |
| + ), | |
| :nohandler); | |
| $result | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment