> > Unprototyped :-) I guess I didn't make that quite > > clear, enough. > > Setup a param array, that's all. > > leo
Umm... OK. Here's what I've done: I created 2 functions that I can use when dealing with variable-length parameter lists. One to turn an array into pcc-compliant parameters, and one to turn incoming pcc-params into an array. AFAIK, these would also work for returns, as (especially with the CPS calling conventions) returns are almost identical to calls. Tell me if you think this is reasonable :) .sub _main # puts params in array, then calls # _array_to_params to make # pcc-compliant parameters # this is eequivalent to Ruby: # array = ["I", "like", "pickles"] # printstuff(*array) newsub P0, .Sub, _printstuff newsub P1, .Continuation, ret1 $P1 = new PerlArray push $P1, "I" push $P1, "like" push $P1, "pickles" P16 = $P1 call _array_to_params # unfortunately we can't use pcc_begin, etc. # here because we set up the params manually I3 = -1 I4 = 0 invoke ret1: end .end .sub _main2 # alternative main that just # calls printstuff as a pcc_sub newsub $P0, .Sub, _printstuff newsub P1, .Continuation, ret1 $P1 = new PerlString $P1 = "I" $P2 = new PerlString $P2 = "like" $P3 = new PerlString $P3 = "pickles" .pcc_begin non_prototyped .arg $P1 .arg $P2 .arg $P3 .pcc_call $P0, P1 ret1: .pcc_end end .end .pcc_sub _printstuff non_prototyped # prints all parameters, separated by space, # and followed by a newline # equivalent to Ruby: # def printstuff(*stuff) # for t in stuff # print t, " " # end # print "\n" # end P16 = new PerlArray call _params_to_array $I0 = 0 $I1 = P16 loopstart: if $I0 == $I1 goto done $S0 = P16[$I0] print $S0 print " " $I0 = $I0 + 1 goto loopstart done: print "\n" .pcc_begin_return .pcc_end_return .end # here are the params <-> array functions .sub _params_to_array # called at the beginning of a function if it # has been passed # parameters with the calling conventions. # Assumes all PMCs. # puts results in existing array in P16 # munges I0, I3, P4. uses them for # temporary variables I0 = I1 + I2 # total length of array assign P16, I0 unless I2 >= 1 goto done P16[0] = P5 unless I2 >= 2 goto done P16[1] = P6 unless I2 >= 3 goto done P16[2] = P7 unless I2 >= 4 goto done P16[3] = P8 unless I2 >= 5 goto done P16[4] = P9 unless I2 >= 6 goto done P16[5] = P10 unless I2 >= 7 goto done P16[6] = P11 unless I2 >= 8 goto done P16[7] = P12 unless I2 >= 9 goto done P16[8] = P13 unless I2 >= 10 goto done P16[9] = P14 unless I2 >= 11 goto done P16[10] = P15 unless I1 >= 0 goto done I0 = 0 # temp I3 = 11 # temp loopstart: P4 = P3[I0] P16[I3] = P4 I0 = I0 + 1 I3 = I3 + 1 unless I0 == I1 goto loopstart done: ret .end .sub _array_to_params # turn the array of PMCs in P16 into a # set of parameters # only sets I1 (num overflow) # and I2 (num pmc regs) # and I3 (overflow params) # munges I0, I3, P4. uses them for # temporary variables I0 = P16 # get length of incoming array unless I0 >= 1 goto nooverflow P5 = P16[0] unless I0 >= 2 goto nooverflow P6 = P16[1] unless I0 >= 3 goto nooverflow P7 = P16[2] unless I0 >= 4 goto nooverflow P8 = P16[3] unless I0 >= 5 goto nooverflow P9 = P16[4] unless I0 >= 6 goto nooverflow P10 = P16[5] unless I0 >= 7 goto nooverflow P11 = P16[6] unless I0 >= 8 goto nooverflow P12 = P16[7] unless I0 >= 9 goto nooverflow P13 = P16[8] unless I0 >= 10 goto nooverflow P14 = P16[9] unless I0 >= 11 goto nooverflow P15 = P16[10] unless I0 >= 12 goto nooverflow overflow: I2 = 11 # num PMC regs I1 = I0 - 11 # num overflow P3 = new PerlArray assign P3, I1 I0 = 0 # temp I3 = 11 # temp loopstart: P4 = P16[I3] P3[I0] = P4 I0 = I0 + 1 I3 = I3 + 1 unless I0 == I1 goto loopstart nooverflow: I2 = I0 # num PMC regs I1 = 0 # num overflow done: ret .end __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com