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

PIR: Arguments are passed without passing them

6 views
Skip to first unread message

Klaas-Jan Stol

unread,
Nov 8, 2004, 4:45:51 AM11/8/04
to perl6-i...@perl.org
Hello,

(* I'm trying a lot of things out, to figure out each part of the Lua
language. This is Yet Another Question , this time concerning "missing"
arguments *)

I'm currently figuring out how "missing arguments" should be handled.
Suppose there is a function foo, that takes 4 parameters. In Lua it is
allowed not to pass all arguments (or even none), but then the argument
is just /null/ or in Lua terms /nil/. However, it should not be a NULL
PMC, but it should be something like PerlUndef (but later on it should
be replaced by LuaNil PMC). For that to work, there must be some extra
code that checks on NULL PMCs. I figured out how it could be done. It
can be seen in the following code snippet.

.sub _main
.local pmc p
.local pmc q
.local pmc r
.local pmc s
p = new .PerlInt
q = new .PerlInt
r = new .PerlInt
s = new .PerlInt
p = 1
q = 2
r = 3
s = 4

_f()
_f(p)
_f(p, q)
_f(p, q, r)
_f(p, q, r, s)
_f(p, q, r)
_f(p, q)
_f(p)
_f()

end
.end

.sub _f non_prototyped
# fixed parameters
.param pmc a
.param pmc b
.param pmc c
.param pmc d

# check on arguments being NULL
isnull a, L1
isnull b, L2
isnull c, L3
isnull d, L4
branch L5
L1:
a = new .PerlInt # later on this should be LuaNil, but this is for
testing
a = 0
L2:
b = new .PerlInt
b = 0
L3:
c = new .PerlInt
c = 0
L4:
d = new .PerlInt
d = 0
L5:
# body
print "a = "
print a
print "; b = "
print b
print "; c = "
print c
print "; d = "
print d
print "\n"
.end

When I run this program, I get the following output:

a = 0; b = 0; c = 0; d = 0 <= ok!
a = 1; b = 0; c = 0; d = 0 <= ok!
a = 1; b = 2; c = 0; d = 0 <= ok!
a = 1; b = 2; c = 3; d = 0 <= ok!
a = 1; b = 2; c = 3; d = 4 <= ok!
a = 1; b = 2; c = 3; d = 4 <= huh?
a = 1; b = 2; c = 3; d = 4 <= huh?
a = 1; b = 2; c = 3; d = 4 <= huh?
a = 1; b = 2; c = 3; d = 4 <= huh?

The first 5 lines are ok, I expected those. I'm wondered by the last 4
lines.
The arguments are still being passed to the function, while it is clear
I didn't call the function
with those arguments (see above: _f(), _f(p), etc.)

I translated the thing to PASM, and that explained a lot: the arguments
from previous calls are
still in P5, P6 etc.

This can easily be solved by nulling these registers, but that seems a
bit strange to me.
But on the other hand, it may be that if I want this functionality (as
described) I should take care of it myself (thus nulling the PMC
argument register before making a new call).

Anyway, my question is: is this normal behaviour of PIR/IMCC? Should I
be aware of this fact and
generating extra code to null out argument registers before making a
call to a function?

Regards
Klaas-Jan

Leopold Toetsch

unread,
Nov 8, 2004, 5:30:04 AM11/8/04
to Klaas-Jan Stol, perl6-i...@perl.org
Klaas-Jan Stol <vand...@home.nl> wrote:
> Hello,

> I'm currently figuring out how "missing arguments" should be handled.

[ ... ]

> # check on arguments being NULL
> isnull a, L1

Don't assume you get NULL or anything for missing arguments. Use the
argument counts:

argcP ... number of P args passed in (I3)
argcI ... number of I args passed in (I1)
...

leo

Dan Sugalski

unread,
Nov 8, 2004, 11:59:26 AM11/8/04
to Klaas-Jan Stol, perl6-i...@perl.org
At 10:45 AM +0100 11/8/04, Klaas-Jan Stol wrote:
>Hello,
>
>(* I'm trying a lot of things out, to figure out each part of the
>Lua language. This is Yet Another Question , this time concerning
>"missing" arguments *)

Argument counts are there for this purpose.

Named arguments are a separate issue, which needs addressing at some
point, along with proper MMD for subs and methods. Perl 6,
unfortunately, makes this reasonably annoying at the lower levels (it
kills any scheme that assumes named parameters can be identified at
compile time), so I've been dodging it for now.
--
Dan

--------------------------------------it's like this-------------------
Dan Sugalski even samurai
d...@sidhe.org have teddy bears and even
teddy bears get drunk

0 new messages