I have a question about how to handle a variable number of arguments.
suppose I have some function that takes 1 argument, but the function call is done with 2 (or more). The compiler (actually, the Lua -> parrot compiler which I'm working on)
cannot and will not check on this. How should this be handled in IMC (if even possible)
According to calling_conventions in the imcc/docs dir, it would be something like this:
-- push arguments onto stack and call function
.arg y
.arg x
call _foo
------------
.sub _foo
saveall
.param int a
/* do something*/
restoreall
ret
.end
somehow, the extra argument should be removed from the stack, or else, in time, the stack will be filled with garbage (or won't it?).
Or is this not possible in imc?
regards,
Klaas-Jan
Or, pass all the fixed parameters normally, and just use the PMC for the
variable part of the args.
Hope this helps. (FYI, I had the same question looking into tcl - the
perl6 implementation already solved the problem, that's where I got the
solution from.)
> Hi,
>
> I have a question about how to handle a variable number of arguments.
> suppose I have some function that takes 1 argument, but the function
> call is done with 2 (or more). The compiler (actually, the Lua -> parrot
> compiler which I'm working on)
> cannot and will not check on this. How should this be handled in IMC (if
> even possible)
>
> According to calling_conventions in the imcc/docs dir, it would be
> something like this:
>
> -- push arguments onto stack and call function
> ..arg y
> ..arg x
> call _foo
> ------------
> ..sub _foo
> saveall
> ..param int a
> /* do something*/
> restoreall
> ret
> ..end
>
> somehow, the extra argument should be removed from the stack, or else,
> in time, the stack will be filled with garbage (or won't it?).
> Or is this not possible in imc?
>
> regards,
> Klaas-Jan
>
>
>
---------------------------------------------
This message was sent using Road Runner's Web-based
e-mail.
For variable number of arguments, use the parrot calling conventions.
(Arguably you should always use them, though if the subs you're
writing can't be called from other generic parrot code it doesn't
matter)
The docs say that it's not implemented yet, so you may have to read
PDD03 and roll it by hand.
--
Dan
--------------------------------------"it's like this"-------------------
Dan Sugalski even samurai
d...@sidhe.org have teddy bears and even
teddy bears get drunk
> Hi,
>
> I have a question about how to handle a variable number of arguments.
> somehow, the extra argument should be removed from the stack,
The HL has to do it. If you always have a variing amount of arguments
the you'll probably push an argument count last.
> regards,
> Klaas-Jan
leo