Skip to content

Commit

Permalink
generalise X macros with ...
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Jan 10, 2022
1 parent b7027ed commit c18cde0
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 35 deletions.
10 changes: 5 additions & 5 deletions Basic/Bad/bad.pd
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ _badvalue_int(val, type)
pdl* p = PDL->scalar(newval);
if (!p) PDL->pdl_barf("Error making new pdl");
if ( val.type != -1 ) {
#define X(datatype, ctype, ppsym, shortctype, defbval) \
#define X(datatype, ctype, ppsym, shortctype, ...) \
ANYVAL_TO_CTYPE(PDL->bvals.shortctype, ctype, val);
PDL_GENERICSWITCH(PDL_TYPELIST2_ALL, type, X, croak("Not a known data type code=%d", type))
#undef X
}
#define X(datatype, ctype, ppsym, shortctype, defbval) \
#define X(datatype, ctype, ppsym, shortctype, ...) \
*((ctype *)p->data) = PDL->bvals.shortctype;
PDL_GENERICSWITCH(PDL_TYPELIST2_ALL, type, X, croak("Not a known data type code=%d", type))
#undef X
Expand All @@ -289,12 +289,12 @@ _badvalue_per_pdl_int(pdl_val, val, type)
PDL->propagate_badvalue( pdl_val );
}
if (pdl_val->has_badvalue == 0) {
#define X(datatype, ctype, ppsym, shortctype, defbval) \
#define X(datatype, ctype, ppsym, shortctype, ...) \
*((ctype *)p->data) = PDL->bvals.shortctype;
PDL_GENERICSWITCH(PDL_TYPELIST2_ALL, type, X, croak("Not a known data type code=%d", type))
#undef X
} else {
#define X(datatype, ctype, ppsym, shortctype, defbval) \
#define X(datatype, ctype, ...) \
ANYVAL_TO_CTYPE(*((ctype *)p->data), ctype, pdl_val->badvalue);
PDL_GENERICSWITCH(PDL_TYPELIST2_ALL, type, X, croak("Not a known data type code=%d", type))
#undef X
Expand All @@ -311,7 +311,7 @@ _default_badvalue_int(type)
PDL_Anyval val = {type, {0}};
pdl* p = PDL->scalar(val);
if (!p) PDL->pdl_barf("Error making new pdl");
#define X(datatype, ctype, ppsym, shortctype, defbval) \
#define X(datatype, ctype, ppsym, shortctype, defbval, ...) \
*((ctype *)p->data) = defbval;
PDL_GENERICSWITCH(PDL_TYPELIST2_ALL, type, X, croak("Not a known data type code=%d", type))
#undef X
Expand Down
2 changes: 1 addition & 1 deletion Basic/Core/Core.xs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ BOOT:
#define X(sym, rettype, args) PDL.sym = pdl_ ## sym;
PDL_CORE_LIST(X)
#undef X
#define X(symbol, ctype, ppsym, shortctype, defbval) \
#define X(symbol, ctype, ppsym, shortctype, defbval, ...) \
PDL.bvals.shortctype = defbval;
PDL_TYPELIST_ALL(X)
#undef X
Expand Down
12 changes: 6 additions & 6 deletions Basic/Core/pdl.h.PL
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,25 @@ EOF
print OUT sprintf qq{#line %d "%s"\n}, __LINE__ + 2, __FILE__;
print OUT <<'!NO!SUBS!';
/* input vars have to be called exactly these as not expanded */
#define ANYVAL_TO_CTYPE_OFFSET_X(datatype, ctype, ppsym, shortctype, defbval) \
#define ANYVAL_TO_CTYPE_OFFSET_X(datatype, ctype, ...) \
ANYVAL_TO_CTYPE(((ctype *)x)[ioff], ctype, value);
#define ANYVAL_TO_CTYPE_OFFSET(x,ioff,datatype,value) \
PDL_GENERICSWITCH(PDL_TYPELIST2_ALL, datatype, ANYVAL_TO_CTYPE_OFFSET_X, return pdl_make_error(PDL_EUSERERROR, "Not a known data type code=%d", datatype))
#define ANYVAL_ISNAN(x) _anyval_isnan(x)
static inline int _anyval_isnan(PDL_Anyval x) {
#define X(datatype, ctype, ppsym, shortctype, defbval) \
#define X(datatype, ctype, ppsym, ...) \
return PDL_ISNAN_ ## ppsym(x.value.ppsym);
PDL_GENERICSWITCH(PDL_TYPELIST2_ALL, x.type, X, return -1)
#undef X
}
#define ANYVAL_EQ_ANYVAL(x,y) (_anyval_eq_anyval(x,y))
static inline int _anyval_eq_anyval(PDL_Anyval x, PDL_Anyval y) {
#define X_OUTER(datatype_x, ctype_x, ppsym_x, shortctype_x, defbval_x) \
#define X_OUTER(datatype_x, ctype_x, ppsym_x, ...) \
ctype_x cvalue_x = x.value.ppsym_x; \
PDL_GENERICSWITCH2(PDL_TYPELIST2_ALL_, y.type, X_INNER, return -1)
#define X_INNER(datatype_y, ctype_y, ppsym_y, shortctype_y, defbval_y) \
#define X_INNER(datatype_y, ctype_y, ppsym_y, ...) \
return (cvalue_x == y.value.ppsym_y) ? 1 : 0;
PDL_GENERICSWITCH(PDL_TYPELIST2_ALL, x.type, X_OUTER, return -1)
#undef X_INNER
Expand All @@ -187,7 +187,7 @@ static inline int _anyval_isbad(PDL_Anyval inany, PDL_Anyval badval) {
(PDL_ISNAN_ ## ppsym(badval) ? PDL_ISNAN_ ## ppsym(inval) : inval == badval)
typedef struct badvals {
#define X(symbol, ctype, ppsym, shortctype, defbval) ctype shortctype;
#define X(symbol, ctype, ppsym, shortctype, ...) ctype shortctype;
PDL_TYPELIST_ALL(X)
#undef X
} badvals;
Expand Down Expand Up @@ -568,7 +568,7 @@ typedef struct pdl_slice_args {
}
/* for use with PDL_TYPELIST_REAL */
#define PDL_QSORT(symbol, ctype, ppsym, shortctype, defbval) \
#define PDL_QSORT(symbol, ctype, ppsym, ...) \
static inline void qsort_ ## ppsym(ctype* xx, PDL_Indx a, PDL_Indx b) { \
PDL_Indx i,j; \
ctype t, median; \
Expand Down
10 changes: 5 additions & 5 deletions Basic/Core/pdlaffine.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pp_def(
pdl_error pdl_readdata_affine(pdl_trans *trans) {
pdl_error PDL_err = {0, NULL, 0};
if (!(trans->pdls[0]->state & trans->pdls[1]->state & PDL_ALLOCATED)) return PDL_err;
#define X(sym, ctype, ppsym, shortctype, defbval) COPYDATA(ctype, 0, 1)
#define X(sym, ctype, ...) COPYDATA(ctype, 0, 1)
PDL_GENERICSWITCH(PDL_TYPELIST2_ALL, trans->__datatype, X, return pdl_make_error(PDL_EUSERERROR, "Not a known data type code=%d", trans->__datatype))
#undef X
return PDL_err;
Expand All @@ -61,7 +61,7 @@ pdl_error pdl_readdata_affine(pdl_trans *trans) {
pdl_error pdl_writebackdata_affine(pdl_trans *trans) {
pdl_error PDL_err = {0, NULL, 0};
if (!(trans->pdls[0]->state & trans->pdls[1]->state & PDL_ALLOCATED)) return PDL_err;
#define X(sym, ctype, ppsym, shortctype, defbval) COPYDATA(ctype, 1, 0)
#define X(sym, ctype, ...) COPYDATA(ctype, 1, 0)
PDL_GENERICSWITCH(PDL_TYPELIST2_ALL, trans->__datatype, X, return pdl_make_error(PDL_EUSERERROR, "Not a known data type code=%d", trans->__datatype))
#undef X
return PDL_err;
Expand Down Expand Up @@ -245,10 +245,10 @@ pdl_error pdl_converttypei_redodims(pdl_trans *trans) {
pdl_error pdl_converttypei_readdata(pdl_trans *trans) {
pdl_error PDL_err = {0, NULL, 0};
pdl_params_converttypei *params = trans->params;
#define X_OUTER(datatype_out, ctype_out, ppsym_out, shortctype_out, defbval_out) \
#define X_OUTER(datatype_out, ctype_out, ...) \
PDL_DECLARE_PARAMETER_BADVAL(ctype_out, (trans->vtable->per_pdl_flags[1]), CHILD, (trans->pdls[1])) \
PDL_GENERICSWITCH2(PDL_TYPELIST2_ALL_, trans->__datatype, X_INNER, return pdl_make_error(PDL_EUSERERROR, "Not a known data type code=%d", trans->__datatype))
#define X_INNER(datatype_in, ctype_in, ppsym_in, shortctype_in, defbval_in) \
#define X_INNER(datatype_in, ctype_in, ...) \
PDL_DECLARE_PARAMETER_BADVAL(ctype_in, (trans->vtable->per_pdl_flags[0]), PARENT, (trans->pdls[0])) \
COPYCONVERT(PARENT, CHILD)
PDL_GENERICSWITCH(PDL_TYPELIST2_ALL, params->totype, X_OUTER, return pdl_make_error(PDL_EUSERERROR, "Not a known data type code=%d", params->totype))
Expand All @@ -259,7 +259,7 @@ pdl_error pdl_converttypei_readdata(pdl_trans *trans) {
pdl_error pdl_converttypei_writebackdata(pdl_trans *trans) {
pdl_error PDL_err = {0, NULL, 0};
pdl_params_converttypei *params = trans->params;
#define X_INNER(datatype_in, ctype_in, ppsym_in, shortctype_in, defbval_in) \
#define X_INNER(datatype_in, ctype_in, ...) \
PDL_DECLARE_PARAMETER_BADVAL(ctype_in, (trans->vtable->per_pdl_flags[0]), PARENT, (trans->pdls[0])) \
COPYCONVERT(CHILD, PARENT)
PDL_GENERICSWITCH(PDL_TYPELIST2_ALL, params->totype, X_OUTER, return pdl_make_error(PDL_EUSERERROR, "Not a known data type code=%d", params->totype))
Expand Down
2 changes: 1 addition & 1 deletion Basic/Core/pdlapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ void pdl_propagate_badvalue( pdl *it ) {

PDL_Anyval pdl_get_badvalue( int datatype ) {
PDL_Anyval retval = { PDL_INVALID, {0} };
#define X(datatype, ctype, ppsym, shortctype, defbval) \
#define X(datatype, ctype, ppsym, shortctype, ...) \
retval.type = datatype; retval.value.ppsym = PDL.bvals.shortctype;
PDL_GENERICSWITCH(PDL_TYPELIST2_ALL, datatype, X, return retval)
#undef X
Expand Down
6 changes: 3 additions & 3 deletions Basic/Core/pdlconv.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "pdl.h" /* Data structure declarations */
#include "pdlcore.h" /* Core declarations */

#define XCODE(code, datatype, ctype, ppsym, shortctype, defbval) \
#define XCODE(code, datatype, ctype, ...) \
ctype *ap = (ctype *) a->data; \
ctype *pp = (ctype *) a->vafftrans->from->data; \
pp += a->vafftrans->offs; \
Expand Down Expand Up @@ -69,13 +69,13 @@ pdl_error pdl_converttype( pdl* a, int targtype ) {
((from_badval_isnan) \
? isnan((double)(from_val)) \
: (from_val) == (from_badval))
#define X_OUTER(datatype_from, ctype_from, ppsym_from, shortctype_from, defbval_from) \
#define X_OUTER(datatype_from, ctype_from, ppsym_from, ...) \
PDL_Indx i = a->nvals; \
ctype_from *bb = (ctype_from *) b; \
ctype_from from_badval = pdl_get_pdl_badvalue(a).value.ppsym_from; \
char from_badval_isnan = PDL_ISNAN_##ppsym_from(from_badval); \
PDL_GENERICSWITCH2(PDL_TYPELIST2_ALL_, targtype, X_INNER, return pdl_make_error(PDL_EUSERERROR, "Not a known data type code=%d", targtype))
#define X_INNER(datatype_to, ctype_to, ppsym_to, shortctype_to, defbval_to) \
#define X_INNER(datatype_to, ctype_to, ppsym_to, shortctype_to, defbval_to, ...) \
ctype_to *aa = (ctype_to *) a->data; \
aa += i-1; bb += i-1; \
if (a->state & PDL_BADVAL) { \
Expand Down
10 changes: 5 additions & 5 deletions Basic/Core/pdlcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void pdl_SetSV_PDL ( SV *sv, pdl *it ) {
/* Size of data type information */

size_t pdl_howbig (int datatype) {
#define X(datatype, ctype, ppsym, shortctype, defbval) \
#define X(datatype, ctype, ...) \
return sizeof(ctype);
PDL_GENERICSWITCH(PDL_TYPELIST2_ALL, datatype, X, croak("Not a known data type code=%d", datatype))
#undef X
Expand Down Expand Up @@ -517,7 +517,7 @@ pdl* pdl_from_array(AV* av, AV* dims, int dtype, pdl* dest_pdl)
*/
PDLDEBUG_f(printf("pdl_from_array type: %d\n", dtype));
ANYVAL_FROM_SV(undefval, NULL, TRUE, dtype);
#define X(dtype, ctype, ppsym, shortctype, defbval) \
#define X(dtype, ctype, ppsym, ...) \
pdl_setav_ ## ppsym(dest_pdl->data,av,dest_dims,ndims,level, undefval.value.ppsym, dest_pdl);
PDL_GENERICSWITCH(PDL_TYPELIST2_ALL, dtype, X, return NULL)
#undef X
Expand Down Expand Up @@ -607,7 +607,7 @@ pdl_error pdl_set( void* x, int datatype, PDL_Indx* pos, PDL_Indx* dims, PDL_Ind
* block of memory.
*/

#define INNERLOOP_X(datatype, ctype, ppsym, shortctype, defbval) \
#define INNERLOOP_X(datatype, ctype, ppsym, ...) \
/* copy data (unless the source pointer is null) */ \
i=0; \
if(source_data && dest_data && pdlsiz) { \
Expand Down Expand Up @@ -638,7 +638,7 @@ pdl_error pdl_set( void* x, int datatype, PDL_Indx* pos, PDL_Indx* dims, PDL_Ind
for(; i< dest_dims[0]-dest_off; i++) dest_data[i] = undefval; \
}

#define PDL_KLUDGE_COPY_X(X, datatype_out, ctype_out, ppsym_out, shortctype, defbval) \
#define PDL_KLUDGE_COPY_X(X, datatype_out, ctype_out, ppsym_out, ...) \
PDL_Indx pdl_kludge_copy_ ## ppsym_out(PDL_Indx dest_off, /* Offset into the dest data array */ \
ctype_out* dest_data, /* Data pointer in the dest data array */ \
PDL_Indx* dest_dims,/* Pointer to the dimlist for the dest pdl */ \
Expand Down Expand Up @@ -744,7 +744,7 @@ PDL_TYPELIST2_ALL(PDL_KLUDGE_COPY_X, INNERLOOP_X)
* - ndims is the size of the dimlist
* - level is the recursion level, which is also the dimension that we are filling
*/
#define PDL_SETAV_X(X, datatype_out, ctype_out, ppsym_out, shortctype, defbval) \
#define PDL_SETAV_X(X, datatype_out, ctype_out, ppsym_out, ...) \
PDL_Indx pdl_setav_ ## ppsym_out(ctype_out* dest_data, AV* av, \
PDL_Indx* dest_dims, int ndims, int level, ctype_out undefval, pdl *dest_pdl) \
{ \
Expand Down
2 changes: 1 addition & 1 deletion Basic/Core/pdlcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void pdl_dump_anyval(PDL_Anyval v);
PDL_CORE_LIST(X)
#undef X

#define X(symbol, ctype, ppsym, shortctype, defbval) \
#define X(symbol, ctype, ppsym, ...) \
PDL_Indx pdl_setav_ ## ppsym(ctype * pdata, AV* av, \
PDL_Indx* pdims, PDL_Long ndims, int level, ctype undefval, pdl *p);
PDL_TYPELIST_ALL(X)
Expand Down
2 changes: 1 addition & 1 deletion Basic/Core/pdlperl.h.PL
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ print OUT <<'EOF';
/* Check minimum datatype required to represent number */
#define PDL_TESTTYPE(sym, ctype) {ctype foo = nv; if(nv == foo) return sym;}
static inline int _pdl_whichdatatype (IV nv) {
#define X(sym, ctype, ppsym, shortctype, defbval) \
#define X(sym, ctype, ...) \
PDL_TESTTYPE(sym, ctype)
PDL_TYPELIST_ALL(X)
#undef X
Expand Down
8 changes: 4 additions & 4 deletions Basic/Core/pdlutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ PDL_LIST_FLAGS_PARAMS(X)
NULL
};
int typeval[] = {
#define X(sym, ctype, ppsym, shortctype, defbval) sym,
#define X(sym, ...) sym,
PDL_TYPELIST_ALL(X)
#undef X
-1
};
char *typechar[] = {
#define X(sym, ctype, ppsym, shortctype, defbval) #sym,
#define X(sym, ...) #sym,
PDL_TYPELIST_ALL(X)
#undef X
NULL
Expand Down Expand Up @@ -483,12 +483,12 @@ void pdl_dump (pdl *it) {

void pdl_dump_anyval(PDL_Anyval v) {
if (v.type < PDL_CF) {
#define X(datatype, ctype, ppsym, shortctype, defbval) \
#define X(datatype, ctype, ppsym, ...) \
printf("%Lg", (long double)v.value.ppsym);
PDL_GENERICSWITCH(PDL_TYPELIST2_REAL, v.type, X, printf("(UNKNOWN PDL_Anyval type=%d)", v.type))
#undef X
} else {
#define X(datatype, ctype, ppsym, shortctype, defbval) \
#define X(datatype, ctype, ppsym, ...) \
printf("%Lg%+Lgi", creall((complex long double)v.value.ppsym), cimagl((complex long double)v.value.ppsym));
PDL_GENERICSWITCH(PDL_TYPELIST2_COMPLEX, v.type, X, printf("(UNKNOWN PDL_Anyval type=%d)", v.type))
#undef X
Expand Down
2 changes: 1 addition & 1 deletion Basic/Ufunc/ufunc.pd
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ EOD
pp_addhdr(PDL::PP::pp_line_numbers(__LINE__, <<'EOF'));
PDL_TYPELIST_REAL(PDL_QSORT)
#define QSORT_OTHER(symbol, ctype, ppsym, shortctype, defbval) \
#define QSORT_OTHER(symbol, ctype, ppsym, ...) \
static inline void qsort_ind_ ## ppsym(ctype* xx, PDL_Indx* ix, PDL_Indx a, PDL_Indx b) { \
PDL_Indx i,j; \
PDL_Indx t; \
Expand Down
2 changes: 1 addition & 1 deletion Libtmp/Image2D/image2d.pd
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pp_addhdr('
#define rint(X) floor( X + 0.5 )
#endif
#define X(symbol, ctype, ppsym, shortctype, defbval) \
#define X(symbol, ctype, ppsym, ...) \
ctype quick_select_ ## ppsym(ctype arr[], int n);
PDL_TYPELIST_REAL(X)
#undef X
Expand Down
2 changes: 1 addition & 1 deletion Libtmp/Image2D/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define ELEM_SWAP(ctype,a,b) { register ctype t=(a);(a)=(b);(b)=t; }

/* for use with PDL_TYPELIST_REAL */
#define X(symbol, ctype, ppsym, shortctype, defbval) \
#define X(symbol, ctype, ppsym, ...) \
ctype quick_select_ ## ppsym(ctype arr[], int n) \
{ \
int low, high ; \
Expand Down

0 comments on commit c18cde0

Please sign in to comment.