On Wed, 29 Jan 2014 15:32:52 PST Kevin Lawler <
kevin....@gmail.com> wrote:
> Alternate take. Bakul's macros except as "DO(3, a+=i)" instead of
> "DO(3) a+=i;".
Yes, that would fit in better with the existing code but macro
names will have to change to DO2,DO3,DO4.
> One caveat: the macros so far in this thread iterate
> closely over the indicated dimensions; they do not allow, for
> instance, putting a DO2 mixed with other instructions inside of a DO1.
One way to handle that is to make the index variable explicit.
Then one can choose diff index var for embedded DOs.
#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL(__VA_ARGS__, 7,6,5,4,3,2,1)
#define VA_NUM_ARGS_IMPL(_1,_2,_3,_4,_5,_6,_7,N,...) N
#define DO(...) mkmacro(DO, __VA_ARGS__)(__VA_ARGS__)
#define DO1(x) error
#define DO2(x,y) error
#define DO3(i,n,x) {for(I i=0, _i=(n);i<_i;++i){x;}}
#define DO4(x,y,z,w) error
#define DO5(i,j,m,n,x) DO1(m,for(I j=0,_j=(n);j<_j;++j){x;})
#define DO6(x,y,z,w,u,v) error
#define DO7(i,j,k,l,m,n,x) DO2(l,m,for(I k=0,_k=(n);k<_k;k++){x;})