Skip to content

Commit

Permalink
Add uint postcircumfix:<[ ]> candidates for native arrays
Browse files Browse the repository at this point in the history
And some cleanup wrt to the generator script
  • Loading branch information
lizmat committed Feb 12, 2022
1 parent 548c255 commit 167c239
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 26 deletions.
54 changes: 45 additions & 9 deletions src/core.c/native_array.pm6
Expand Up @@ -4852,9 +4852,14 @@ multi sub postcircumfix:<[ ]>(array:D \SELF, Range:D \range ) is raw {
}

#- start of postcircumfix candidates of strarray -------------------------------
#- Generated on 2022-02-03T19:03:07+01:00 by tools/build/makeNATIVE_CANDIDATES.raku
#- Generated on 2022-02-12T20:29:54+01:00 by ./tools/build/makeNATIVE_CANDIDATES.raku
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE

multi sub postcircumfix:<[ ]>(
array::strarray:D \SELF, uint $pos
) is raw {
nqp::atposref_s(nqp::decont(SELF),$pos)
}
multi sub postcircumfix:<[ ]>(
array::strarray:D \SELF, Int:D $pos
) is raw {
Expand All @@ -4863,13 +4868,17 @@ multi sub postcircumfix:<[ ]>(
!! nqp::atposref_s(nqp::decont(SELF),$pos)
}

multi sub postcircumfix:<[ ]>(
array::strarray:D \SELF, uint $pos, Str:D \assignee
) is raw {
nqp::bindpos_s(nqp::decont(SELF),$pos,assignee)
}
multi sub postcircumfix:<[ ]>(
array::strarray:D \SELF, Int:D $pos, Str:D \assignee
) is raw {
nqp::islt_i($pos,0)
?? X::OutOfRange.new(:what<Index>, :got($pos), :range<0..^Inf>).throw
!! nqp::bindpos_s(nqp::decont(SELF),$pos,assignee);
assignee
}

multi sub postcircumfix:<[ ]>(
Expand Down Expand Up @@ -5047,7 +5056,7 @@ multi sub postcircumfix:<[ ]>(
) is raw {
my $self := nqp::decont(SELF);
my $indices := $pos.iterator;
my $values := Rakudo::Iterator.TailWith(values.iterator,'');
my $values := Rakudo::Iterator.TailWith(values.iterator,"");
my str @result;

nqp::until(
Expand Down Expand Up @@ -5104,9 +5113,14 @@ multi sub infix:<cmp>(array::strarray:D \a, array::strarray:D \b) {
#- end of postcircumfix candidates of strarray ---------------------------------

#- start of postcircumfix candidates of numarray -------------------------------
#- Generated on 2022-02-03T19:03:07+01:00 by tools/build/makeNATIVE_CANDIDATES.raku
#- Generated on 2022-02-12T20:29:54+01:00 by ./tools/build/makeNATIVE_CANDIDATES.raku
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE

multi sub postcircumfix:<[ ]>(
array::numarray:D \SELF, uint $pos
) is raw {
nqp::atposref_n(nqp::decont(SELF),$pos)
}
multi sub postcircumfix:<[ ]>(
array::numarray:D \SELF, Int:D $pos
) is raw {
Expand All @@ -5115,13 +5129,17 @@ multi sub postcircumfix:<[ ]>(
!! nqp::atposref_n(nqp::decont(SELF),$pos)
}

multi sub postcircumfix:<[ ]>(
array::numarray:D \SELF, uint $pos, Num:D \assignee
) is raw {
nqp::bindpos_n(nqp::decont(SELF),$pos,assignee)
}
multi sub postcircumfix:<[ ]>(
array::numarray:D \SELF, Int:D $pos, Num:D \assignee
) is raw {
nqp::islt_i($pos,0)
?? X::OutOfRange.new(:what<Index>, :got($pos), :range<0..^Inf>).throw
!! nqp::bindpos_n(nqp::decont(SELF),$pos,assignee);
assignee
}

multi sub postcircumfix:<[ ]>(
Expand Down Expand Up @@ -5356,9 +5374,14 @@ multi sub infix:<cmp>(array::numarray:D \a, array::numarray:D \b) {
#- end of postcircumfix candidates of numarray ---------------------------------

#- start of postcircumfix candidates of intarray -------------------------------
#- Generated on 2022-02-03T19:03:07+01:00 by tools/build/makeNATIVE_CANDIDATES.raku
#- Generated on 2022-02-12T20:29:54+01:00 by ./tools/build/makeNATIVE_CANDIDATES.raku
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE

multi sub postcircumfix:<[ ]>(
array::intarray:D \SELF, uint $pos
) is raw {
nqp::atposref_i(nqp::decont(SELF),$pos)
}
multi sub postcircumfix:<[ ]>(
array::intarray:D \SELF, Int:D $pos
) is raw {
Expand All @@ -5367,13 +5390,17 @@ multi sub postcircumfix:<[ ]>(
!! nqp::atposref_i(nqp::decont(SELF),$pos)
}

multi sub postcircumfix:<[ ]>(
array::intarray:D \SELF, uint $pos, Int:D \assignee
) is raw {
nqp::bindpos_i(nqp::decont(SELF),$pos,assignee)
}
multi sub postcircumfix:<[ ]>(
array::intarray:D \SELF, Int:D $pos, Int:D \assignee
) is raw {
nqp::islt_i($pos,0)
?? X::OutOfRange.new(:what<Index>, :got($pos), :range<0..^Inf>).throw
!! nqp::bindpos_i(nqp::decont(SELF),$pos,assignee);
assignee
}

multi sub postcircumfix:<[ ]>(
Expand Down Expand Up @@ -5608,9 +5635,14 @@ multi sub infix:<cmp>(array::intarray:D \a, array::intarray:D \b) {
#- end of postcircumfix candidates of intarray ---------------------------------

#- start of postcircumfix candidates of uintarray -------------------------------
#- Generated on 2022-02-03T19:03:07+01:00 by tools/build/makeNATIVE_CANDIDATES.raku
#- Generated on 2022-02-12T20:29:54+01:00 by ./tools/build/makeNATIVE_CANDIDATES.raku
#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE

multi sub postcircumfix:<[ ]>(
array::uintarray:D \SELF, uint $pos
) is raw {
nqp::atposref_u(nqp::decont(SELF),$pos)
}
multi sub postcircumfix:<[ ]>(
array::uintarray:D \SELF, Int:D $pos
) is raw {
Expand All @@ -5619,13 +5651,17 @@ multi sub postcircumfix:<[ ]>(
!! nqp::atposref_u(nqp::decont(SELF),$pos)
}

multi sub postcircumfix:<[ ]>(
array::uintarray:D \SELF, uint $pos, UInt:D \assignee
) is raw {
nqp::bindpos_u(nqp::decont(SELF),$pos,assignee)
}
multi sub postcircumfix:<[ ]>(
array::uintarray:D \SELF, Int:D $pos, UInt:D \assignee
) is raw {
nqp::islt_i($pos,0)
?? X::OutOfRange.new(:what<Index>, :got($pos), :range<0..^Inf>).throw
!! nqp::bindpos_u(nqp::decont(SELF),$pos,assignee);
assignee
}

multi sub postcircumfix:<[ ]>(
Expand Down
76 changes: 59 additions & 17 deletions tools/build/makeNATIVE_CANDIDATES.raku
Expand Up @@ -14,6 +14,45 @@ my $idpos = $start.chars;
my $idchars = 3;
my $end = '#- end of postcircumfix candidates of ';

my %type_mapper = (
int => ( :nullval("0"),
:postfix<i>,
:postfix_push<i>,
:postfix_cmp<i>,
:type<int>,
:Type<Int>,
:value<int>,
:Value<Int>,
).Map,
num => ( :nullval("0e0"),
:postfix<n>,
:postfix_push<n>,
:postfix_cmp<n>,
:type<num>,
:Type<Num>,
:value<num>,
:Value<Num>,
).Map,
str => ( :nullval('""'),
:postfix<s>,
:postfix_push<s>,
:postfix_cmp<s>,
:type<str>,
:Type<Str>,
:value<str>,
:Value<Str>,
).Map,
uint => ( :nullval("0"),
:postfix<u>,
:postfix_push<i>,
:postfix_cmp<i>,
:type<uint>,
:Type<UInt>,
:value<int>,
:Value<Int>,
).Map,
);

# slurp the whole file and set up writing to it
my $filename = "src/core.c/native_array.pm6";
my @lines = $filename.IO.lines;
Expand All @@ -29,10 +68,12 @@ while @lines {
next;
}

# found header
# found header, check validity and set up mapper
my $type = $line.substr($idpos,$idchars);
$type = 'uint' if $type eq 'uin';
die "Don't know how to handle $type" unless $type eq "int" | "uint" | "num" | "str";
$type = "uint" if $type eq "uin";
die "Don't know how to handle $type"
unless my %mapper := %type_mapper{$type};

say $start ~ $type ~ "array -------------------------------";
say "#- Generated on $generated by $generator";
say "#- PLEASE DON'T CHANGE ANYTHING BELOW THIS LINE";
Expand All @@ -42,17 +83,14 @@ while @lines {
last if @lines.shift.starts-with($end);
}

# set up template values
my %mapper =
postfix => $type.substr(0,1),
type => $type,
Type => $type eq 'uint' ?? 'UInt' !! $type.tclc,
nil => ($type eq "int" | "uint" ?? "0" !! $type eq "num" ?? "0e0" !! "''")
;

# spurt the candidates
say Q:to/SOURCE/.subst(/ '#' (\w+) '#' /, -> $/ { %mapper{$0} }, :g).chomp;
multi sub postcircumfix:<[ ]>(
array::#type#array:D \SELF, uint $pos
) is raw {
nqp::atposref_#postfix#(nqp::decont(SELF),$pos)
}
multi sub postcircumfix:<[ ]>(
array::#type#array:D \SELF, Int:D $pos
) is raw {
Expand All @@ -61,13 +99,17 @@ multi sub postcircumfix:<[ ]>(
!! nqp::atposref_#postfix#(nqp::decont(SELF),$pos)
}
multi sub postcircumfix:<[ ]>(
array::#type#array:D \SELF, uint $pos, #Type#:D \assignee
) is raw {
nqp::bindpos_#postfix#(nqp::decont(SELF),$pos,assignee)
}
multi sub postcircumfix:<[ ]>(
array::#type#array:D \SELF, Int:D $pos, #Type#:D \assignee
) is raw {
nqp::islt_i($pos,0)
?? X::OutOfRange.new(:what<Index>, :got($pos), :range<0..^Inf>).throw
!! nqp::bindpos_#postfix#(nqp::decont(SELF),$pos,assignee);
assignee
}
multi sub postcircumfix:<[ ]>(
Expand Down Expand Up @@ -190,7 +232,7 @@ multi sub postcircumfix:<[ ]>(
)),
Int
) && nqp::isge_i($got,0),
nqp::push_#postfix#(@result,nqp::atpos_#postfix#($self,$got)),
nqp::push_#postfix_push#(@result,nqp::atpos_#postfix#($self,$got)),
nqp::if(
nqp::istype($got,Int),
X::OutOfRange.new(:what<Index>, :$got, :range<0..^Inf>).throw,
Expand Down Expand Up @@ -221,7 +263,7 @@ multi sub postcircumfix:<[ ]>(
)),
Int
) && nqp::isge_i($got,0),
nqp::push_#postfix#(
nqp::push_#postfix_push#(
@result,
nqp::bindpos_#postfix#(
$self,
Expand All @@ -245,7 +287,7 @@ multi sub postcircumfix:<[ ]>(
) is raw {
my $self := nqp::decont(SELF);
my $indices := $pos.iterator;
my $values := Rakudo::Iterator.TailWith(values.iterator,#nil#);
my $values := Rakudo::Iterator.TailWith(values.iterator,#nullval#);
my #type# @result;
nqp::until(
Expand All @@ -259,7 +301,7 @@ multi sub postcircumfix:<[ ]>(
)),
Int
) && nqp::isge_i($got,0),
nqp::push_#postfix#(
nqp::push_#postfix_push#(
@result,
nqp::bindpos_#postfix#(
$self,
Expand Down Expand Up @@ -292,7 +334,7 @@ multi sub infix:<cmp>(array::#type#array:D \a, array::#type#array:D \b) {
my int $i = -1;
nqp::until(
nqp::isge_i(($i = nqp::add_i($i,1)),$elems)
|| (my $res = nqp::cmp_#postfix#(nqp::atpos_#postfix#(a,$i),nqp::atpos_#postfix#(b,$i))),
|| (my $res = nqp::cmp_#postfix_cmp#(nqp::atpos_#postfix#(a,$i),nqp::atpos_#postfix#(b,$i))),
nqp::null
);
ORDER($res || nqp::cmp_i($elems-a,$elems-b))
Expand Down

0 comments on commit 167c239

Please sign in to comment.