Hi, On Monday 22 March 2004 10:44, Ilya Martynov wrote: > Hello all, > > 1) First question is how to tell if variadic function recieved 11 or > 12 or more params (for simplicity let's suppose that we use only > pmc parameters). > > According calling conventions (pdd03) first 11 params end up in P5-P15 > registers and leftover goes into array in P3. The problem is that > there is no indication (unless I'm missing something) if function was > called with more than 11 params other than register P3 being > initialized with some array PMC. But it may be as well that function > was called with just 11 params and P3 contains some array by accident > (it could be for example some array from previous sub call). I0=1 => prototyped I0=0 => unprototyped I1=number of INT parameters I2=number of STRING parameters I3=number of PMC parameters I4=number of NUM parameters
Leo, is it easy to alias them as argc[ISPN]? > 2) Second question if there is an op to access registers by their > number (it is quite troublesome to write code to retrieve > parameters in variadic function from P5-P15 registeres without such > op). > > ops/set.ops has setp_ind op which allows to write to register by its > number but it seems there is no op to read register by its number. I had the same problem, too. > 3) Not really a question but a feature request for IMCC to provide > some support for variadic functions to avoid writing same code > again and again to read parameters of variadic function from either > P5-P15 registers or from array in P3 register as necessary. Not > sure about syntax though. It could look for example like this: > > # calculates sum of all parameters > .sub _sum > new $P1, .PerlInt > $P1 = 0 > # generates code which sets $I1 to a number of parameters > $I1 = .param_num $I1 = I3 > loop: > if $I1 == 0 goto return > # retrieves a parameter by its number > $P2 = .param($I1) I vote for getreg $P1, $I1 # put Px (x=I1) into $P1 and/or getarg $P1, $I1 # put PMC arg number I1 into $P1 (P5..P14, then P3[I-11]) > add $P1, $P2 > dec $I1 > goto loop > return: > .pcc_begin_return > .return $P1 > .pcc_end_return > .end Good idea. I second that. jens