Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Provide fix for #126503
  • Loading branch information
lizmat committed Oct 30, 2015
1 parent 74ff317 commit b855790
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 28 deletions.
10 changes: 6 additions & 4 deletions src/core/Any.pm
Expand Up @@ -251,13 +251,15 @@ my class Any { # declared in BOOTSTRAP
}

multi method AT-POS(Any:D: int \pos) is raw {
fail X::OutOfRange.new(:what<Index>, :got(pos), :range<0..0>)
unless nqp::not_i(pos);
fail X::OutOfRange.new(
:what($*INDEX // 'Index'), :got(pos), :range<0..0>)
unless nqp::not_i(pos);
self;
}
multi method AT-POS(Any:D: Int:D \pos) is raw {
fail X::OutOfRange.new(:what<Index>, :got(pos), :range<0..0>)
if pos != 0;
fail X::OutOfRange.new(
:what($*INDEX // 'Index'), :got(pos), :range<0..0>)
if pos != 0;
self;
}
multi method AT-POS(Any:D: Num:D \pos) is raw {
Expand Down
20 changes: 12 additions & 8 deletions src/core/Array.pm
Expand Up @@ -408,8 +408,9 @@ my class Array { # declared in BOOTSTRAP
!! self!AT-POS-SLOWPATH($ipos)
}
method !AT-POS-SLOWPATH(int $ipos) is raw {
fail X::OutOfRange.new(:what<Index>,:got($ipos),:range<0..Inf>)
if nqp::islt_i($ipos, 0);
fail X::OutOfRange.new(
:what($*INDEX // 'Index'),:got($ipos),:range<0..Inf>)
if nqp::islt_i($ipos, 0);
self!ensure-allocated();
my $todo := nqp::getattr(self, List, '$!todo');
if $todo.DEFINITE {
Expand All @@ -427,8 +428,9 @@ my class Array { # declared in BOOTSTRAP
}

multi method ASSIGN-POS(Array:D: int $ipos, Mu \assignee) {
X::OutOfRange.new(:what<Index>,:got($ipos),:range<0..Inf>).throw
if nqp::islt_i($ipos, 0);
X::OutOfRange.new(
:what($*INDEX // 'Index'),:got($ipos),:range<0..Inf>).throw
if nqp::islt_i($ipos, 0);
my Mu \reified := nqp::getattr(self, List, '$!reified');
reified.DEFINITE && $ipos < nqp::elems(reified)
?? nqp::isnull(nqp::atpos(reified, $ipos))
Expand All @@ -438,8 +440,9 @@ my class Array { # declared in BOOTSTRAP
}
multi method ASSIGN-POS(Array:D: Int:D $pos, Mu \assignee) {
my int $ipos = nqp::unbox_i($pos);
X::OutOfRange.new(:what<Index>,:got($pos),:range<0..Inf>).throw
if nqp::islt_i($ipos, 0);
X::OutOfRange.new(
:what($*INDEX // 'Index'),:got($pos),:range<0..Inf>).throw
if nqp::islt_i($ipos, 0);
my Mu \reified := nqp::getattr(self, List, '$!reified');
reified.DEFINITE && $ipos < nqp::elems(reified)
?? nqp::isnull(nqp::atpos(reified, $ipos))
Expand All @@ -448,8 +451,9 @@ my class Array { # declared in BOOTSTRAP
!! self!ASSIGN-POS-SLOWPATH($ipos, assignee)
}
method !ASSIGN-POS-SLOWPATH(int $ipos, Mu \assignee) {
fail X::OutOfRange.new(:what<Index>,:got($ipos),:range<0..Inf>)
if nqp::islt_i($ipos, 0);
fail X::OutOfRange.new(
:what($*INDEX // 'Index'),:got($ipos),:range<0..Inf>)
if nqp::islt_i($ipos, 0);
self!ensure-allocated();
my $todo := nqp::getattr(self, List, '$!todo');
if $todo.DEFINITE {
Expand Down
24 changes: 14 additions & 10 deletions src/core/Buf.pm
Expand Up @@ -33,7 +33,7 @@ my role Blob[::T = uint8] does Positional[T] does Stringy is repr('VMArray') is

multi method AT-POS(Blob:D: int \pos) {
fail X::OutOfRange.new(
:what<Index>,
:what($*INDEX // 'Index'),
:got(pos),
:range("0..{nqp::elems(self)-1}")
) if nqp::isge_i(pos,nqp::elems(self)) || nqp::islt_i(pos,0);
Expand All @@ -42,7 +42,7 @@ my role Blob[::T = uint8] does Positional[T] does Stringy is repr('VMArray') is
multi method AT-POS(Blob:D: Int:D \pos) {
my int $pos = nqp::unbox_i(pos);
fail X::OutOfRange.new(
:what<Index>,
:what($*INDEX // 'Index'),
:got(pos),
:range("0..{nqp::elems(self)-1}")
) if nqp::isge_i($pos,nqp::elems(self)) || nqp::islt_i($pos,0);
Expand Down Expand Up @@ -259,26 +259,30 @@ my class utf32 does Blob[uint32] is repr('VMArray') {

my role Buf[::T = uint8] does Blob[T] is repr('VMArray') is array_type(T) {
multi method AT-POS(Buf:D: int \pos) is raw {
fail X::OutOfRange.new(:what<Index>,:got(pos),:range<0..Inf>)
if nqp::islt_i(pos,0);
fail X::OutOfRange.new(
:what($*INDEX // 'Index'),:got(pos),:range<0..Inf>)
if nqp::islt_i(pos,0);
nqp::atposref_i(self, pos);
}
multi method AT-POS(Buf:D: Int:D \pos) is raw {
my int $pos = nqp::unbox_i(pos);
fail X::OutOfRange.new(:what<Index>,:got(pos),:range<0..Inf>)
if nqp::islt_i($pos,0);
fail X::OutOfRange.new(
:what($*INDEX // 'Index'),:got(pos),:range<0..Inf>)
if nqp::islt_i($pos,0);
nqp::atposref_i(self,$pos);
}

multi method ASSIGN-POS(Buf:D: int \pos, Mu \assignee) {
X::OutOfRange.new(:what<Index>,:got(pos),:range<0..Inf>).throw
if nqp::islt_i(pos,0);
X::OutOfRange.new(
:what($*INDEX // 'Index'),:got(pos),:range<0..Inf>).throw
if nqp::islt_i(pos,0);
nqp::bindpos_i(self,\pos,assignee)
}
multi method ASSIGN-POS(Buf:D: Int:D \pos, Mu \assignee) {
my int $pos = nqp::unbox_i(pos);
fail X::OutOfRange.new(:what<Index>,:got(pos),:range<0..Inf>)
if nqp::islt_i($pos,0);
fail X::OutOfRange.new(
:what($*INDEX // 'Index'),:got(pos),:range<0..Inf>)
if nqp::islt_i($pos,0);
nqp::bindpos_i(self,$pos,assignee)
}

Expand Down
8 changes: 5 additions & 3 deletions src/core/Capture.pm
Expand Up @@ -41,13 +41,15 @@ my class Capture { # declared in BOOTSTRAP
}

multi method AT-POS(Capture:D: int \pos) is raw {
fail X::OutOfRange.new(:what<Index>,:got(pos),:range<0..Inf>)
if nqp::islt_i(pos,0);
fail X::OutOfRange.new(
:what($*INDEX // 'Index'),:got(pos),:range<0..Inf>)
if nqp::islt_i(pos,0);
nqp::existspos($!list,pos) ?? nqp::atpos($!list,pos) !! Nil;
}
multi method AT-POS(Capture:D: Int:D \pos) is raw {
my int $pos = nqp::unbox_i(pos);
fail X::OutOfRange.new(:what<Index>,:got(pos),:range<0..Inf>)
fail X::OutOfRange.new(
:what($*INDEX // 'Index'),:got(pos),:range<0..Inf>)
if nqp::islt_i($pos,0);
nqp::existspos($!list,$pos) ?? nqp::atpos($!list,$pos) !! Nil;
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/List.pm
Expand Up @@ -329,7 +329,8 @@ my class List does Iterable does Positional { # declared in BOOTSTRAP
}

method !AT-POS-SLOWPATH(int $pos) is raw {
fail X::OutOfRange.new(:what<Index>, :got($pos), :range<0..Inf>)
fail X::OutOfRange.new(
:what($*INDEX // 'Index'), :got($pos), :range<0..Inf>)
if $pos < 0;
$!todo.DEFINITE && $!todo.reify-at-least($pos + 1) > $pos
?? nqp::atpos($!reified, $pos)
Expand Down
4 changes: 2 additions & 2 deletions src/core/Uni.pm
Expand Up @@ -66,7 +66,7 @@ my class Uni does Positional[uint32] does Stringy is repr('VMArray') is array_ty

multi method AT-POS(Uni:D: int \pos) {
fail X::OutOfRange.new(
:what<Index>,
:what($*INDEX // 'Index'),
:got(pos),
:range("0..{nqp::elems(self)-1}")
) if nqp::isge_i(pos,nqp::elems(self)) || nqp::islt_i(pos,0);
Expand All @@ -75,7 +75,7 @@ my class Uni does Positional[uint32] does Stringy is repr('VMArray') is array_ty
multi method AT-POS(Uni:D: Int:D \pos) {
my int $pos = nqp::unbox_i(pos);
fail X::OutOfRange.new(
:what<Index>,
:what($*INDEX // 'Index'),
:got(pos),
:range("0..{nqp::elems(self)-1}")
) if nqp::isge_i($pos,nqp::elems(self)) || nqp::islt_i($pos,0);
Expand Down
9 changes: 9 additions & 0 deletions src/core/array_slice.pm
Expand Up @@ -322,48 +322,57 @@ multi sub postcircumfix:<[ ]>(\SELF, Iterable:D \pos, :$v!, *%other) is raw {

# @a[->{}]
multi sub postcircumfix:<[ ]>(\SELF, Callable:D $block ) is raw {
my $*INDEX = 'Effective index';
SELF[$block(|(SELF.cache.elems xx ($block.count == Inf ?? 1 !! $block.count)))];
}
multi sub postcircumfix:<[ ]>(\SELF, Callable:D $block, Mu \assignee ) is raw {
my $*INDEX = 'Effective index';
SELF[$block(|(SELF.cache.elems xx ($block.count == Inf ?? 1 !! $block.count)))] = assignee;
}
multi sub postcircumfix:<[ ]>(\SELF, Callable:D $block, :$BIND!) is raw {
X::Bind::Slice.new(type => SELF.WHAT).throw;
}
multi sub postcircumfix:<[ ]>(\SELF, Callable:D $block, :$SINK!, *%other) is raw {
my $*INDEX = 'Effective index';
SLICE_MORE_LIST( SELF, POSITIONS(SELF,$block), (:$SINK), %other );
}
multi sub postcircumfix:<[ ]>(\SELF,Callable:D $block,:$delete!,*%other) is raw {
my $*INDEX = 'Effective index';
my $pos := $block(|(SELF.cache.elems xx ($block.count == Inf ?? 1 !! $block.count)));
nqp::istype($pos,Int)
?? SLICE_ONE_LIST( SELF, $pos, (:$delete), %other )
!! SLICE_MORE_LIST( SELF, @$pos, (:$delete), %other );
}
multi sub postcircumfix:<[ ]>(\SELF,Callable:D $block,:$exists!,*%other) is raw {
my $*INDEX = 'Effective index';
my $pos := $block(|(SELF.cache.elems xx ($block.count == Inf ?? 1 !! $block.count)));
nqp::istype($pos,Int)
?? SLICE_ONE_LIST( SELF, $pos, (:$exists), %other )
!! SLICE_MORE_LIST( SELF, @$pos, (:$exists), %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Callable:D $block, :$kv!, *%other) is raw {
my $*INDEX = 'Effective index';
my $pos := $block(|(SELF.cache.elems xx ($block.count == Inf ?? 1 !! $block.count)));
nqp::istype($pos,Int)
?? SLICE_ONE_LIST( SELF, $pos, (:$kv), %other )
!! SLICE_MORE_LIST( SELF, @$pos, (:$kv), %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Callable:D $block, :$p!, *%other) is raw {
my $*INDEX = 'Effective index';
my $pos := $block(|(SELF.cache.elems xx ($block.count == Inf ?? 1 !! $block.count)));
nqp::istype($pos,Int)
?? SLICE_ONE_LIST( SELF, $pos, (:$p), %other )
!! SLICE_MORE_LIST( SELF, @$pos, (:$p), %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Callable:D $block, :$k!, *%other) is raw {
my $*INDEX = 'Effective index';
my $pos := $block(|(SELF.cache.elems xx ($block.count == Inf ?? 1 !! $block.count)));
nqp::istype($pos,Int)
?? SLICE_ONE_LIST( SELF, $pos, (:$k), %other )
!! SLICE_MORE_LIST( SELF, @$pos, (:$k), %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Callable:D $block, :$v!, *%other) is raw {
my $*INDEX = 'Effective index';
my $pos := $block(|(SELF.cache.elems xx ($block.count == Inf ?? 1 !! $block.count)));
nqp::istype($pos,Int)
?? SLICE_ONE_LIST( SELF, $pos, (:$v), %other )
Expand Down

0 comments on commit b855790

Please sign in to comment.