On Thursday 06 December 2007 15:49:45 Jonathan Worthington wrote: > chromatic wrote: > >> If there isn't a better way to do this, how would I get the arity of a > >> subroutine?
> > I'm not sure you can from PIR, which I've argued is a problem. I think > > eventually we'll have to have some metadata available on invokable PMCs > > that lets us get the expected arity, as that will fix a nasty problem we > > have with NCI calls versus normal Subs. > For subs, the sub PMC contains the offset in the bytecode. From knowing > that, you can in look in the bytecode there for the get_params > instruction of the sub. That points you to the signature PMC, which > tells you how many args there are. > > What it implemented (when I get chance, which should be this weekend) as > an arity method on the Sub PMC? That would be much nicer, as then parameter passing wouldn't have to call invoke on a Sub or descendent to get the bytecode offset (which doesn't make sense with an NCI call) to determine if it has to pass parameters (which occurs *after* the invoke, which is sort of a problem if you want to pass parameters to the NCI call you've just invoked and which has already returned with an error that you haven't actually passed any parameters to it). > Another approach is to have a PMC that wraps up a sub PMC with the > supplied arguments. It'd have an array for supplied positionals and a > slurply for supplied named args. I think that'd give us what we want for > implementing Perl 6's .assuming too, and perhaps better than a thunk... Heh, wouldn't you call that the Thunk PMC? How about Future? -- c