On Thu, Jul 07, 2005 at 11:22:27AM -0400, Chip Salzenberg wrote:
> On Thu, Jul 07, 2005 at 10:09:27AM -0500, Patrick R. Michaud wrote:
> > On Thu, Jul 07, 2005 at 11:05:00AM -0400, Chip Salzenberg wrote:
> > > On Thu, Jul 07, 2005 at 10:57:40AM -0400, Will Coleda wrote:
> > > > To manage varargs-style subroutines?
> > > 
> > > But that's what :slurpy is for.
> > 
> > But :slurpy always pulls things into a PMC (and creates PMCs
> > along the way).
> > 
> > We need get_argc in order to know how many things were passed
> > into params marked :optional .
> 
> Hm.  Well, as long as everybody knows it defeats lazy evaluation, I
> guess that works.

Well, there's another way of looking at it:  I don't really need
to know exactly how many total arguments were passed in by the caller,
I just need to know how many :optional param registers were filled
in.  In other words, with something like

    .sub "foo"
        .param int beta
        .param string gamma :optional
        .param string delta :optional
        .param pmc epislon :slurpy

I think it's okay if get_argc (which perhaps should be called something
else) simply tells me something like "4" -- the number of registers 
filled in -- even if epsilon ends up (lazily?) grabbing 100 arguments 
from a list.

If I need to know the number of arguments slurped, I can just check
the length of the slurpy pmc.

So, all we really need is something that can tell us how many :optional
arguments were filled in.  In the above example that something could 
return 0, 1, or 2 depending on which of gamma or delta were supplied
by the caller.  In fact, this might be greatly preferable, since if
I later decide I need another non-optional parameter

    .sub "foo"
        .param int beta
        .param int omega
        .param string gamma :optional
        .param string delta :optional
        .param pmc epislon :slurpy

I don't have to go through my code and fix all of the optional
argument counts.  

Pm

Reply via email to