Skip to content

Commit

Permalink
Add support for > 1 adverb to 1dim native shaped arrays
Browse files Browse the repository at this point in the history
To make them work just like the unshaped ones.  Specifically
:exists:(kv|p) and :delete:(kv|p)
  • Loading branch information
lizmat committed Dec 3, 2020
1 parent 7c0956b commit 02e48d8
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 59 deletions.
132 changes: 87 additions & 45 deletions src/core.c/native_array.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -3730,7 +3730,7 @@ multi sub postcircumfix:<[ ]>(array:D \SELF, Range:D \range ) is raw {
}

#- start of postcircumfix candidates of shaped1strarray ------------------------
#- Generated on 2020-12-03T16:41:03+01:00 by tools/build/makeNATIVE_SHAPED1_CANDIDATES.raku
#- Generated on 2020-12-03T18:41:33+01:00 by tools/build/makeNATIVE_SHAPED1_CANDIDATES.raku
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE

multi sub postcircumfix:<[ ]>(
Expand All @@ -3752,50 +3752,64 @@ multi sub postcircumfix:<[ ]>(
}

multi sub postcircumfix:<[ ]>(
array::shaped1strarray \SELF, Int:D $pos, :$exists!
array::shaped1strarray \SELF, Int:D $pos, :$exists!, *%_
) {
nqp::hllbool(
$exists
?? nqp::isge_i($pos,0)
&& nqp::islt_i($pos,nqp::elems(nqp::decont(SELF)))
!! nqp::islt_i($pos,0)
|| nqp::isge_i($pos,nqp::elems(nqp::decont(SELF)))
)
my int $state =
nqp::isge_i($pos,0) && nqp::islt_i($pos,nqp::elems(nqp::decont(SELF)));
my $value := nqp::hllbool($exists ?? $state !! nqp::not_i($state));

$state
?? nqp::elems(my $adverbs := nqp::getattr(%_,Map,'$!storage'))
?? nqp::atkey($adverbs,'kv')
?? ($pos,$value)
!! nqp::atkey($adverbs,'p')
?? Pair.new($pos,$value)
!! Failure.new(
X::Adverb.new(
what => "slice",
source => "native shaped1 str array",
nogo => ('exists', |%_.keys).sort
)
)
!! $value
!! $value
}

multi sub postcircumfix:<[ ]>(
array::shaped1strarray \SELF, Int:D \pos, :$delete!
array::shaped1strarray \SELF, Int:D $pos, :$delete!, *%_
) {
$delete
?? X::Delete.new(target => 'a shaped native str array').throw
!! nqp::atposref_s(nqp::decont(SELF),pos)
!! nqp::elems(nqp::getattr(%_,Map,'$!storage'))
?? postcircumfix:<[ ]>(SELF, $pos, |%_)
!! nqp::atposref_s(nqp::decont(SELF),$pos)
}

multi sub postcircumfix:<[ ]>(
array::shaped1strarray \SELF, Int:D $pos, :$kv!
--> Bool:D) is raw {
) is raw {
$kv
?? nqp::list($pos,nqp::atpos_s(nqp::decont(SELF),$pos))
!! nqp::atposref_s(nqp::decont(SELF),$pos)
}

multi sub postcircumfix:<[ ]>(
array::shaped1strarray \SELF, Int:D $pos, :$p!
--> Bool:D) is raw {
) is raw {
$p
?? Pair.new($pos,nqp::atpos_s(nqp::decont(SELF),$pos))
!! nqp::atposref_s(nqp::decont(SELF),$pos)
}

multi sub postcircumfix:<[ ]>(
array::shaped1strarray \SELF, Int:D $pos, :$k!
--> Bool:D) is raw {
) is raw {
$k ?? $pos !! nqp::atposref_s(nqp::decont(SELF),$pos)
}

multi sub postcircumfix:<[ ]>(
array::shaped1strarray \SELF, Int:D $pos, :$v!
--> Bool:D) is raw {
) is raw {
$v
?? nqp::isge_i($pos,0) && nqp::islt_i($pos,nqp::elems(nqp::decont(SELF)))
?? nqp::list(nqp::atpos_s(nqp::decont(SELF),$pos))
Expand All @@ -3813,7 +3827,7 @@ multi sub postcircumfix:<[ ]>(
#- end of postcircumfix candidates of shaped1strarray --------------------------

#- start of postcircumfix candidates of shaped1intarray ------------------------
#- Generated on 2020-12-03T16:41:03+01:00 by tools/build/makeNATIVE_SHAPED1_CANDIDATES.raku
#- Generated on 2020-12-03T18:41:33+01:00 by tools/build/makeNATIVE_SHAPED1_CANDIDATES.raku
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE

multi sub postcircumfix:<[ ]>(
Expand All @@ -3835,50 +3849,64 @@ multi sub postcircumfix:<[ ]>(
}

multi sub postcircumfix:<[ ]>(
array::shaped1intarray \SELF, Int:D $pos, :$exists!
array::shaped1intarray \SELF, Int:D $pos, :$exists!, *%_
) {
nqp::hllbool(
$exists
?? nqp::isge_i($pos,0)
&& nqp::islt_i($pos,nqp::elems(nqp::decont(SELF)))
!! nqp::islt_i($pos,0)
|| nqp::isge_i($pos,nqp::elems(nqp::decont(SELF)))
)
my int $state =
nqp::isge_i($pos,0) && nqp::islt_i($pos,nqp::elems(nqp::decont(SELF)));
my $value := nqp::hllbool($exists ?? $state !! nqp::not_i($state));

$state
?? nqp::elems(my $adverbs := nqp::getattr(%_,Map,'$!storage'))
?? nqp::atkey($adverbs,'kv')
?? ($pos,$value)
!! nqp::atkey($adverbs,'p')
?? Pair.new($pos,$value)
!! Failure.new(
X::Adverb.new(
what => "slice",
source => "native shaped1 int array",
nogo => ('exists', |%_.keys).sort
)
)
!! $value
!! $value
}

multi sub postcircumfix:<[ ]>(
array::shaped1intarray \SELF, Int:D \pos, :$delete!
array::shaped1intarray \SELF, Int:D $pos, :$delete!, *%_
) {
$delete
?? X::Delete.new(target => 'a shaped native int array').throw
!! nqp::atposref_i(nqp::decont(SELF),pos)
!! nqp::elems(nqp::getattr(%_,Map,'$!storage'))
?? postcircumfix:<[ ]>(SELF, $pos, |%_)
!! nqp::atposref_i(nqp::decont(SELF),$pos)
}

multi sub postcircumfix:<[ ]>(
array::shaped1intarray \SELF, Int:D $pos, :$kv!
--> Bool:D) is raw {
) is raw {
$kv
?? nqp::list($pos,nqp::atpos_i(nqp::decont(SELF),$pos))
!! nqp::atposref_i(nqp::decont(SELF),$pos)
}

multi sub postcircumfix:<[ ]>(
array::shaped1intarray \SELF, Int:D $pos, :$p!
--> Bool:D) is raw {
) is raw {
$p
?? Pair.new($pos,nqp::atpos_i(nqp::decont(SELF),$pos))
!! nqp::atposref_i(nqp::decont(SELF),$pos)
}

multi sub postcircumfix:<[ ]>(
array::shaped1intarray \SELF, Int:D $pos, :$k!
--> Bool:D) is raw {
) is raw {
$k ?? $pos !! nqp::atposref_i(nqp::decont(SELF),$pos)
}

multi sub postcircumfix:<[ ]>(
array::shaped1intarray \SELF, Int:D $pos, :$v!
--> Bool:D) is raw {
) is raw {
$v
?? nqp::isge_i($pos,0) && nqp::islt_i($pos,nqp::elems(nqp::decont(SELF)))
?? nqp::list(nqp::atpos_i(nqp::decont(SELF),$pos))
Expand All @@ -3896,7 +3924,7 @@ multi sub postcircumfix:<[ ]>(
#- end of postcircumfix candidates of shaped1intarray --------------------------

#- start of postcircumfix candidates of shaped1numarray ------------------------
#- Generated on 2020-12-03T16:41:03+01:00 by tools/build/makeNATIVE_SHAPED1_CANDIDATES.raku
#- Generated on 2020-12-03T18:41:33+01:00 by tools/build/makeNATIVE_SHAPED1_CANDIDATES.raku
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE

multi sub postcircumfix:<[ ]>(
Expand All @@ -3918,50 +3946,64 @@ multi sub postcircumfix:<[ ]>(
}

multi sub postcircumfix:<[ ]>(
array::shaped1numarray \SELF, Int:D $pos, :$exists!
array::shaped1numarray \SELF, Int:D $pos, :$exists!, *%_
) {
nqp::hllbool(
$exists
?? nqp::isge_i($pos,0)
&& nqp::islt_i($pos,nqp::elems(nqp::decont(SELF)))
!! nqp::islt_i($pos,0)
|| nqp::isge_i($pos,nqp::elems(nqp::decont(SELF)))
)
my int $state =
nqp::isge_i($pos,0) && nqp::islt_i($pos,nqp::elems(nqp::decont(SELF)));
my $value := nqp::hllbool($exists ?? $state !! nqp::not_i($state));

$state
?? nqp::elems(my $adverbs := nqp::getattr(%_,Map,'$!storage'))
?? nqp::atkey($adverbs,'kv')
?? ($pos,$value)
!! nqp::atkey($adverbs,'p')
?? Pair.new($pos,$value)
!! Failure.new(
X::Adverb.new(
what => "slice",
source => "native shaped1 num array",
nogo => ('exists', |%_.keys).sort
)
)
!! $value
!! $value
}

multi sub postcircumfix:<[ ]>(
array::shaped1numarray \SELF, Int:D \pos, :$delete!
array::shaped1numarray \SELF, Int:D $pos, :$delete!, *%_
) {
$delete
?? X::Delete.new(target => 'a shaped native num array').throw
!! nqp::atposref_n(nqp::decont(SELF),pos)
!! nqp::elems(nqp::getattr(%_,Map,'$!storage'))
?? postcircumfix:<[ ]>(SELF, $pos, |%_)
!! nqp::atposref_n(nqp::decont(SELF),$pos)
}

multi sub postcircumfix:<[ ]>(
array::shaped1numarray \SELF, Int:D $pos, :$kv!
--> Bool:D) is raw {
) is raw {
$kv
?? nqp::list($pos,nqp::atpos_n(nqp::decont(SELF),$pos))
!! nqp::atposref_n(nqp::decont(SELF),$pos)
}

multi sub postcircumfix:<[ ]>(
array::shaped1numarray \SELF, Int:D $pos, :$p!
--> Bool:D) is raw {
) is raw {
$p
?? Pair.new($pos,nqp::atpos_n(nqp::decont(SELF),$pos))
!! nqp::atposref_n(nqp::decont(SELF),$pos)
}

multi sub postcircumfix:<[ ]>(
array::shaped1numarray \SELF, Int:D $pos, :$k!
--> Bool:D) is raw {
) is raw {
$k ?? $pos !! nqp::atposref_n(nqp::decont(SELF),$pos)
}

multi sub postcircumfix:<[ ]>(
array::shaped1numarray \SELF, Int:D $pos, :$v!
--> Bool:D) is raw {
) is raw {
$v
?? nqp::isge_i($pos,0) && nqp::islt_i($pos,nqp::elems(nqp::decont(SELF)))
?? nqp::list(nqp::atpos_n(nqp::decont(SELF),$pos))
Expand Down
42 changes: 28 additions & 14 deletions tools/build/makeNATIVE_SHAPED1_CANDIDATES.raku
Original file line number Diff line number Diff line change
Expand Up @@ -70,50 +70,64 @@ multi sub postcircumfix:<[ ]>(
}
multi sub postcircumfix:<[ ]>(
array::shaped1#type#array \SELF, Int:D $pos, :$exists!
array::shaped1#type#array \SELF, Int:D $pos, :$exists!, *%_
) {
nqp::hllbool(
$exists
?? nqp::isge_i($pos,0)
&& nqp::islt_i($pos,nqp::elems(nqp::decont(SELF)))
!! nqp::islt_i($pos,0)
|| nqp::isge_i($pos,nqp::elems(nqp::decont(SELF)))
)
my int $state =
nqp::isge_i($pos,0) && nqp::islt_i($pos,nqp::elems(nqp::decont(SELF)));
my $value := nqp::hllbool($exists ?? $state !! nqp::not_i($state));
$state
?? nqp::elems(my $adverbs := nqp::getattr(%_,Map,'$!storage'))
?? nqp::atkey($adverbs,'kv')
?? ($pos,$value)
!! nqp::atkey($adverbs,'p')
?? Pair.new($pos,$value)
!! Failure.new(
X::Adverb.new(
what => "slice",
source => "native shaped1 #type# array",
nogo => ('exists', |%_.keys).sort
)
)
!! $value
!! $value
}
multi sub postcircumfix:<[ ]>(
array::shaped1#type#array \SELF, Int:D \pos, :$delete!
array::shaped1#type#array \SELF, Int:D $pos, :$delete!, *%_
) {
$delete
?? X::Delete.new(target => 'a shaped native #type# array').throw
!! nqp::atposref_#postfix#(nqp::decont(SELF),pos)
!! nqp::elems(nqp::getattr(%_,Map,'$!storage'))
?? postcircumfix:<[ ]>(SELF, $pos, |%_)
!! nqp::atposref_#postfix#(nqp::decont(SELF),$pos)
}
multi sub postcircumfix:<[ ]>(
array::shaped1#type#array \SELF, Int:D $pos, :$kv!
--> Bool:D) is raw {
) is raw {
$kv
?? nqp::list($pos,nqp::atpos_#postfix#(nqp::decont(SELF),$pos))
!! nqp::atposref_#postfix#(nqp::decont(SELF),$pos)
}
multi sub postcircumfix:<[ ]>(
array::shaped1#type#array \SELF, Int:D $pos, :$p!
--> Bool:D) is raw {
) is raw {
$p
?? Pair.new($pos,nqp::atpos_#postfix#(nqp::decont(SELF),$pos))
!! nqp::atposref_#postfix#(nqp::decont(SELF),$pos)
}
multi sub postcircumfix:<[ ]>(
array::shaped1#type#array \SELF, Int:D $pos, :$k!
--> Bool:D) is raw {
) is raw {
$k ?? $pos !! nqp::atposref_#postfix#(nqp::decont(SELF),$pos)
}
multi sub postcircumfix:<[ ]>(
array::shaped1#type#array \SELF, Int:D $pos, :$v!
--> Bool:D) is raw {
) is raw {
$v
?? nqp::isge_i($pos,0) && nqp::islt_i($pos,nqp::elems(nqp::decont(SELF)))
?? nqp::list(nqp::atpos_#postfix#(nqp::decont(SELF),$pos))
Expand Down

0 comments on commit 02e48d8

Please sign in to comment.