Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IMC and variable number of arguments

5 views
Skip to first unread message

K Stol

unread,
Apr 18, 2003, 10:46:13 AM4/18/03
to perl6-i...@perl.org
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


Will Coleda

unread,
Apr 18, 2003, 11:04:06 AM4/18/03
to K Stol, perl6-i...@perl.org
I believe the best way to handle this is to pass a PMC (say, a PerlArray)
instead of N single registers. You then know you're passing a single
object each time, and can introspect how many there are on the receiving
end.

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.

Dan Sugalski

unread,
Apr 18, 2003, 11:36:05 AM4/18/03
to K Stol, perl6-i...@perl.org
At 4:46 PM +0200 4/18/03, K Stol wrote:
>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)

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

Leopold Toetsch

unread,
Apr 18, 2003, 11:26:46 AM4/18/03
to K Stol, perl6-i...@perl.org
K Stol wrote:

> 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


0 new messages