Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created December 18, 2016 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/8574ee473e590d709d5e0051914249bd to your computer and use it in GitHub Desktop.
Save zoffixznet/8574ee473e590d709d5e0051914249bd to your computer and use it in GitHub Desktop.
diff --git a/src/core/array_slice.pm b/src/core/array_slice.pm
index ce51d2c..9f63b91 100644
--- a/src/core/array_slice.pm
+++ b/src/core/array_slice.pm
@@ -12,7 +12,7 @@
# the caller's scope.
proto sub POSITIONS(|) { * }
multi sub POSITIONS(\SELF, \pos, Callable :$eagerize = -> $idx {
- $idx ~~ Whatever ?? SELF.cache.elems !! SELF.EXISTS-POS($idx)
+ $idx ~~ Whatever ?? (SELF === Any ?? 0 !! SELF.cache.elems) !! SELF.EXISTS-POS($idx)
}) {
my class IndicesReificationTarget {
has $!target;
@@ -315,53 +315,53 @@ 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)))];
+ SELF[$block(|((SELF === Any ?? 0 !! 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;
+ SELF[$block(|((SELF === Any ?? 0 !! 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,:$delete!,*%other) is raw {
my $*INDEX = 'Effective index';
- my $pos := $block(|(SELF.cache.elems xx ($block.count == Inf ?? 1 !! $block.count)));
+ my $pos := $block(|((SELF === Any ?? 0 !! SELF.cache.elems) xx ($block.count == Inf ?? 1 !! $block.count)));
nqp::istype($pos,Int)
?? SLICE_ONE_LIST( SELF, $pos, 'delete', $delete, %other )
!! SLICE_MORE_LIST( SELF, @$pos, 'delete', $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)));
+ my $pos := $block(|((SELF === Any ?? 0 !! SELF.cache.elems) xx ($block.count == Inf ?? 1 !! $block.count)));
nqp::istype($pos,Int)
?? SLICE_ONE_LIST( SELF, $pos, 'exists', $exists, %other )
!! SLICE_MORE_LIST( SELF, @$pos, 'exists', $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)));
+ my $pos := $block(|((SELF === Any ?? 0 !! SELF.cache.elems) xx ($block.count == Inf ?? 1 !! $block.count)));
nqp::istype($pos,Int)
?? SLICE_ONE_LIST( SELF, $pos, 'kv', $kv, %other )
!! SLICE_MORE_LIST( SELF, @$pos, 'kv', $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)));
+ my $pos := $block(|((SELF === Any ?? 0 !! SELF.cache.elems) xx ($block.count == Inf ?? 1 !! $block.count)));
nqp::istype($pos,Int)
?? SLICE_ONE_LIST( SELF, $pos, 'p', $p, %other )
!! SLICE_MORE_LIST( SELF, @$pos, 'p', $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)));
+ my $pos := $block(|((SELF === Any ?? 0 !! SELF.cache.elems) xx ($block.count == Inf ?? 1 !! $block.count)));
nqp::istype($pos,Int)
?? SLICE_ONE_LIST( SELF, $pos, 'k', $k, %other )
!! SLICE_MORE_LIST( SELF, @$pos, 'k', $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)));
+ my $pos := $block(|((SELF === Any ?? 0 !! SELF.cache.elems) xx ($block.count == Inf ?? 1 !! $block.count)));
nqp::istype($pos,Int)
?? SLICE_ONE_LIST( SELF, $pos, 'v', $v, %other )
!! SLICE_MORE_LIST( SELF, @$pos, 'v', $v, %other );
@@ -369,33 +369,33 @@ multi sub postcircumfix:<[ ]>(\SELF, Callable:D $block, :$v!, *%other) is raw {
# @a[*]
multi sub postcircumfix:<[ ]>( \SELF, Whatever:D ) is raw {
- SELF[^SELF.cache.elems];
+ SELF[^(SELF === Any ?? 0 !! SELF.cache.elems)];
}
multi sub postcircumfix:<[ ]>( \SELF, Whatever:D, Mu \assignee ) is raw {
- SELF[^SELF.cache.elems] = assignee;
+ SELF[^(SELF === Any ?? 0 !! SELF.cache.elems)] = assignee;
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, :$BIND!) is raw {
X::Bind::Slice.new(type => SELF.WHAT).throw;
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, :$delete!, *%other) is raw {
- SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'delete', $delete, %other );
+ SLICE_MORE_LIST( SELF, ^(SELF === Any ?? 0 !! SELF.cache.elems), 'delete', $delete, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, :$exists!, *%other) is raw {
- SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'exists', $exists, %other );
+ SLICE_MORE_LIST( SELF, ^(SELF === Any ?? 0 !! SELF.cache.elems), 'exists', $exists, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, :$kv!, *%other) is raw {
- SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'kv', $kv, %other );
+ SLICE_MORE_LIST( SELF, ^(SELF === Any ?? 0 !! SELF.cache.elems), 'kv', $kv, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, :$p!, *%other) is raw {
- SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'p', $p, %other );
+ SLICE_MORE_LIST( SELF, ^(SELF === Any ?? 0 !! SELF.cache.elems), 'p', $p, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, :$k!, *%other) is raw {
- SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'k', $k, %other );
+ SLICE_MORE_LIST( SELF, ^(SELF === Any ?? 0 !! SELF.cache.elems), 'k', $k, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, Whatever:D, :$v!, *%other) is raw {
nqp::elems(nqp::getattr(%other,Map,'$!storage'))
- ?? SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'v', $v, %other )
- !! SELF[^SELF.cache.elems];
+ ?? SLICE_MORE_LIST( SELF, ^(SELF === Any ?? 0 !! SELF.cache.elems), 'v', $v, %other )
+ !! SELF[^(SELF === Any ?? 0 !! SELF.cache.elems)];
}
# @a[**]
@@ -411,24 +411,24 @@ multi sub postcircumfix:<[ ]>(\SELF, :$BIND!) is raw {
X::Bind::ZenSlice.new(type => SELF.WHAT).throw;
}
multi sub postcircumfix:<[ ]>(\SELF, :$delete!, *%other) is raw {
- SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'delete', $delete, %other );
+ SLICE_MORE_LIST( SELF, ^(SELF === Any ?? 0 !! SELF.cache.elems), 'delete', $delete, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, :$exists!, *%other) is raw {
- SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'exists', $exists, %other );
+ SLICE_MORE_LIST( SELF, ^(SELF === Any ?? 0 !! SELF.cache.elems), 'exists', $exists, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, :$kv!, *%other) is raw {
- SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'kv', $kv, %other );
+ SLICE_MORE_LIST( SELF, ^(SELF === Any ?? 0 !! SELF.cache.elems), 'kv', $kv, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, :$p!, *%other) is raw {
- SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'p', $p, %other );
+ SLICE_MORE_LIST( SELF, ^(SELF === Any ?? 0 !! SELF.cache.elems), 'p', $p, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, :$k!, *%other) is raw {
- SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'k', $k, %other );
+ SLICE_MORE_LIST( SELF, ^(SELF === Any ?? 0 !! SELF.cache.elems), 'k', $k, %other );
}
multi sub postcircumfix:<[ ]>(\SELF, :$v!, *%other) is raw {
nqp::elems(nqp::getattr(%other,Map,'$!storage'))
- ?? SLICE_MORE_LIST( SELF, ^SELF.cache.elems, 'v', $v, %other )
- !! SELF[^SELF.cache.elems];
+ ?? SLICE_MORE_LIST( SELF, ^(SELF === Any ?? 0 !! SELF.cache.elems), 'v', $v, %other )
+ !! SELF[^(SELF === Any ?? 0 !! SELF.cache.elems)];
}
multi sub postcircumfix:<[ ]>(\SELF, *%other) is raw {
SELF.ZEN-POS(|%other);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment