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

More object questions...

13 views
Skip to first unread message

Simon Glover

unread,
Feb 25, 2004, 1:51:09 PM2/25/04
to Dan Sugalski, perl6-i...@perl.org

Currently, calling get_integer on a ParrotClass returns the attribute
count, so you can do:

newclass P1, "Foo"
addattribute P1, "foo_i"
addattribute P1, "foo_j"
set I1, P1
print I1

and the code will print '2'. Will this be part of the new API, or is it
simply a relic of the previous implementation.

Similarly, calling get_integer_keyed_str with a fully-qualified attribute
name returns the attribute offsets, meaning that this:

newclass P1, "Foo"
addattribute P1, "foo_i"
addattribute P1, "foo_j"
set I2, P1["Foo\x00foo_j"]
print I2

prints '1' -- is this part of the API or not?

Finally, a number of the current tests seem to rely on being able to
set and get attribute values with the syntax:

set P2["Foo\x00i"], 10
set P3["Foo\x00i"], 20
set I2, P2["Foo\x00i"]
set I3, P3["Foo\x00i"]

(where P2, P3 are objects of class Foo, and Foo has an attribute i).
Is this part of the API?

Simon

Dan Sugalski

unread,
Feb 25, 2004, 2:03:36 PM2/25/04
to Simon Glover, perl6-i...@perl.org
At 1:51 PM -0500 2/25/04, Simon Glover wrote:
> Currently, calling get_integer on a ParrotClass returns the attribute
> count, so you can do:
>
> newclass P1, "Foo"
> addattribute P1, "foo_i"
> addattribute P1, "foo_j"
> set I1, P1
> print I1
>
> and the code will print '2'. Will this be part of the new API, or is it
> simply a relic of the previous implementation.

Relic.

> Similarly, calling get_integer_keyed_str with a fully-qualified attribute
> name returns the attribute offsets, meaning that this:
>
> newclass P1, "Foo"
> addattribute P1, "foo_i"
> addattribute P1, "foo_j"
> set I2, P1["Foo\x00foo_j"]
> print I2
>
> prints '1' -- is this part of the API or not?

Relic.

> Finally, a number of the current tests seem to rely on being able to
> set and get attribute values with the syntax:
>
> set P2["Foo\x00i"], 10
> set P3["Foo\x00i"], 20
> set I2, P2["Foo\x00i"]
> set I3, P3["Foo\x00i"]
>
> (where P2, P3 are objects of class Foo, and Foo has an attribute i).
> Is this part of the API?

Relic.

In all these cases the object will ultimately do a method lookup to
see if it has a method in place to do the operation, so you can
substitute an object for any other sort of PMC. Attribute access
should be only through the attribute API.
--
Dan

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

Simon Glover

unread,
Feb 25, 2004, 2:21:02 PM2/25/04
to Dan Sugalski, perl6-i...@perl.org

(You're probably getting sick of these by now...)

Should asking for a non-existant attribute cause Parrot to throw an
exception. Currently, it doesn't seem to be able to make up its mind
-- this:

newclass P1, "Foo"
find_type I0, "Foo"
new P2, I0
getattribute P3, P2, -2
getattribute P3, P2, -1
getattribute P3, P2, 0
getattribute P3, P2, 1
end

completes silently, but if we ask for an attribute with an offset >= 2
or <= -3, we get an "Array index out of bounds!" exception. Which is the
correct behaviour?

(Incidentally, I get the same behaviour with setattribute).

Simon

Dan Sugalski

unread,
Feb 26, 2004, 8:07:31 AM2/26/04
to Simon Glover, perl6-i...@perl.org
At 2:21 PM -0500 2/25/04, Simon Glover wrote:
> (You're probably getting sick of these by now...)
>
> Should asking for a non-existant attribute cause Parrot to throw an
> exception. Currently, it doesn't seem to be able to make up its mind
[snip]

> but if we ask for an attribute with an offset >= 2
> or <= -3, we get an "Array index out of bounds!" exception. Which is the
> correct behaviour?

That was a problem with array wraparound -- I put in checking code
for this, FWIW.

0 new messages