Skip to content

Commit

Permalink
Add option 'CallFQ' to pp_def
Browse files Browse the repository at this point in the history
  • Loading branch information
jo-37 committed Feb 17, 2025
1 parent bda65d4 commit bb98bb0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/PDL/Ops.pd
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ EOF
NoBadifNaN => 1,
Inplace => [ 'a' ],
Overload => [$op, $mutator, $bitwise],
CallFQ => 1,
Code => pp_line_numbers(__LINE__, <<EOF),
PDL_IF_BAD(char anybad = 0;,)
broadcastloop %{
Expand Down
14 changes: 8 additions & 6 deletions lib/PDL/PP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1390,10 +1390,10 @@ $PDL::PP::deftbl =
}),
PDL::PP::Rule::Returns::EmptyString->new("InplaceCode", []),
PDL::PP::Rule->new("InplaceDocValues",
[qw(Name SignatureObj InplaceNormalised)],
[qw(Name SignatureObj InplaceNormalised CallFQ?)],
'doc describing usage inplace',
sub {
my ($name, $sig, $inplace) = @_;
my ($name, $sig, $inplace, $call_fq) = @_;
my @args = @{ $sig->args_callorder };
my %inplace_involved = map +($_=>1), my ($in, $out) = @$inplace;
my $meth_call = $args[0] eq $in;
Expand All @@ -1403,7 +1403,8 @@ $PDL::PP::deftbl =
!@args ? '' : "(@{[join ',', map qq{\$$_}, @args]})"
).";", []
];
push @vals, [ "$name(\$$in->inplace".(
my $prefix = $call_fq ? "$::PDLOBJ\::" : "";
push @vals, [ "$prefix$name(\$$in->inplace".(
!@args ? '' : ",@{[join ',', map qq{\$$_}, @args]}"
).");", []];
$vals[0][1] = ["can be used inplace"];
Expand Down Expand Up @@ -1475,12 +1476,12 @@ EOF

PDL::PP::Rule->new([qw(UsageDoc ParamDoc)],
[qw(Name Doc? SignatureObj OtherParsDefaults? ArgOrder?
OverloadDocValues InplaceDocValues ParamDesc? Lvalue?
OverloadDocValues InplaceDocValues ParamDesc? Lvalue? CallFQ?
)],
'generate "usage" section of doc',
sub {
my ($name, $doc, $sig, $otherdefaults, $argorder,
$overloadvals, $inplacevals, $paramdesc, $lvalue,
$overloadvals, $inplacevals, $paramdesc, $lvalue, $call_fq,
) = @_;
$otherdefaults ||= {};
$paramdesc ||= {};
Expand Down Expand Up @@ -1523,10 +1524,11 @@ EOF
push @argsets, [\@args, [], ['all arguments given']];
}
my @invocs = @$overloadvals;
my $prefix = $call_fq ? "$::PDLOBJ\::" : "";
push @invocs, map [(!@{$_->[1]} ? '' :
@{$_->[1]} == 1 ? "\$$_->[1][0] = " :
"(".join(", ", map "\$$_", @{$_->[1]}).") = "
)."$name(".join(", ", map "\$$_", @{$_->[0]}).");",
)."$prefix$name(".join(", ", map "\$$_", @{$_->[0]}).");",
[@{$_->[2]}]], @argsets;
$argsets[0][2] = ['method call'];
$argsets[$_][2] = [] for 1..$#argsets; # they get the idea
Expand Down

0 comments on commit bb98bb0

Please sign in to comment.