Skip to content

Commit

Permalink
PP add CHeader key
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Mar 2, 2024
1 parent 1b8bdb8 commit 7160322
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
16 changes: 7 additions & 9 deletions Basic/Gen/PP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -923,16 +923,14 @@ sub pp_def {
croak("ERROR: No FreeFunc for pp_def=$name!\n")
unless exists $obj{FreeFunc};

my $ctext = join("\n\n",grep $_, @obj{'StructDecl','RedoDimsFunc',
'ReadDataFunc','WriteBackDataFunc',
'FreeFunc',
'VTableDef','RunFunc',
}
);
my $ctext = join("\n\n",grep $_, @obj{qw(
CHeader StructDecl RedoDimsFunc
ReadDataFunc WriteBackDataFunc
FreeFunc
VTableDef RunFunc
)});
if ($::PDLMULTI_C) {
PDL::PP->printxsc(undef, <<EOF);
$obj{RunFuncHdr};
EOF
PDL::PP->printxsc(undef, "$obj{RunFuncHdr};\n");
PDL::PP->printxsc("pp-$obj{Name}.c", $ctext);
} else {
PDL::PP->printxsc(undef, $ctext);
Expand Down
7 changes: 7 additions & 0 deletions Basic/Pod/PP.pod
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,10 @@ especially CPU intensive code) only once per thread, i.e.
}'
);

As of 2.086, you can put those C<#define>s in a C<CHeader> instead of
C<pp_addhdr>ing so that if you're using multi-C files, it doesn't cause
recompilation (or warnings) for any other transformations you C<pp_def>.

=head3 types

The types function works similar to the C<$T> macro. However, with the
Expand Down Expand Up @@ -1899,6 +1903,9 @@ C<pp_def>s, e.g.:
',
);

If such things are relevant for only one transformation, consider putting
it in a C<CHeader> key for that C<pp_def> (as of 2.086).

=head3 pp_addpm

In many cases the actual PP code (meaning the arguments to C<pp_def>
Expand Down
18 changes: 8 additions & 10 deletions Basic/Slices/slices.pd
Original file line number Diff line number Diff line change
Expand Up @@ -2467,16 +2467,6 @@ SLICE-MC
EOF
);

pp_addhdr(<<END
static int cmp_pdll(const void *a_,const void *b_) {
PDL_Indx *a = (PDL_Indx *)a_; PDL_Indx *b=(PDL_Indx *)b_;
if(*a>*b) return 1;
else if(*a==*b) return 0;
else return -1;
}
END
);

pp_def('diagonal',
P2Child => 1,
TwoWay => 1,
Expand All @@ -2488,6 +2478,14 @@ pp_def('diagonal',
qsort($COMP(whichdims), $COMP(whichdims_count), sizeof(PDL_Indx),
cmp_pdll);
'),
CHeader => <<'END',
static int cmp_pdll(const void *a_,const void *b_) {
PDL_Indx *a = (PDL_Indx *)a_; PDL_Indx *b=(PDL_Indx *)b_;
if(*a>*b) return 1;
else if(*a==*b) return 0;
else return -1;
}
END
RedoDims => pp_line_numbers(__LINE__-1, '
PDL_Indx nthp,nthc,nthd, cd = $COMP(whichdims)[0];
$SETNDIMS($PDL(PARENT)->ndims-$COMP(whichdims_count)+1);
Expand Down
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- revert the use of ArgOrder for PDL::Ops so op($a,$b,$c,$swap) works again as pre 2.082_01
- error on inflating output ndarrays over dims sized 1 or implicit as undefined
- make HdrCode and FtrCode run when PMCode supplied (#463) - thanks @jo-37 for suggestion
- PP add CHeader key

2.085_01 2024-02-10
- test, document PDL::string, make more consistent (#459) - thanks @vadim-160102 for report
Expand Down

0 comments on commit 7160322

Please sign in to comment.