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

Object semantics

4 views
Skip to first unread message

Dan Sugalski

unread,
Jan 2, 2003, 4:55:42 PM1/2/03
to perl6-i...@perl.org
Okay, I've been working on getting bytecode generation nailed down,
and then digging into the vtable split stuff, but I thought I'd
specify at least a little how objects (this would be real
language-level "we're object-oriented dammit!" objects, not the
lower-level stuff we're currently working with) should/will behave.

Parrot, like all the OO languages that will live on top of it, uses
reference-style objects and non-reference values. The difference here
is that on assignment values are cloned and references are copied. If
you do this:

a = b

and b is a value, a will have a copy of the value in b, but it'll be
in a different location in memory, and changes to b won't affect a.

On the other hand, if b is an object, then a and be refer to the same
object, and actions on either a or b affect the other. (This is nasty
action at a distance, and I really don't like it, but nobody asked me
here :)

We are going to muddle things some by having value objects in
addition to reference objects, as arguably all the values that are in
PMCs can be treated as value objects. (When those PMCs hold
references to reference objects, the copied value is just an address
so the destination object, and thus our value objects handle the case
of being the front half of a reference object just fine)

Still, for 'real' OO, it's all reference object stuff, so things
should Just Work. The pending questions about ruby assignment work
out since, while the assignment part of vtable behaviour's
potentially troublesome, it doesn't make any difference since what
you're assigning into is the front half of a reference object, and
thus you get pointer-to-pointer semantics the way you want. (And if
it's not, then it should do the right thing on assignment, which may
be... interesting in a mixed-language environment)
--
Dan

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

Leopold Toetsch

unread,
Jan 2, 2003, 6:33:40 PM1/2/03
to Dan Sugalski, perl6-i...@perl.org
Dan Sugalski wrote:


> Still, for 'real' OO, it's all reference object stuff, so things should
> Just Work. The pending questions about


... strings still is pending ;-)
Remember string_set ins substr and 50% live performance increase.

Do we want do reuse string headers like PMCs (and change semantics
slightly) or do we not.

And: Subject "GC quick note"

One thing that might help the GC situation some.

Since we've got mutable strings (yep, it's OK) perhaps we should
thump the string functions a bit to not allocate new strings quite so
often. That'll leave us fewer headers to worry about.
--
Dan

leo


Gopal V

unread,
Jan 3, 2003, 6:28:46 PM1/3/03
to Dan Sugalski, perl6-i...@perl.org
If memory serves me right, Dan Sugalski wrote:
> language-level "we're object-oriented dammit!" objects, not the
> lower-level stuff we're currently working with) should/will behave.

yay ! ... finally !

> reference-style objects and non-reference values.

How large can a non-reference value be ? ... (in the .NET opcodes the
'struct' seems to be unlimited in size ...) But well, I'd settle for
a non-reference of at least large integers (64bit)...

And how will non-reference values dispatch methods ? ... would they be
"boxed" into a reference for each method call, so that the method call
can modify them ? ...or are all non-reference values immutable ?....

to put it down clearly ...

MyValueType a;
a.Modify();

would a be able to modify itself ? (unfortunately C# allows that)

Gopal
--
The difference between insanity and genius is measured by success

Erik Bågfors

unread,
Jan 3, 2003, 1:27:02 PM1/3/03
to Gopal V, Dan Sugalski, perl6-i...@perl.org
On Sat, 2003-01-04 at 00:28, Gopal V wrote:
> If memory serves me right, Dan Sugalski wrote:
> > language-level "we're object-oriented dammit!" objects, not the
> > lower-level stuff we're currently working with) should/will behave.
>
> yay ! ... finally !

The moment we've all been waiting for :)

> > reference-style objects and non-reference values.
>
> How large can a non-reference value be ? ... (in the .NET opcodes the
> 'struct' seems to be unlimited in size ...) But well, I'd settle for
> a non-reference of at least large integers (64bit)...
>
> And how will non-reference values dispatch methods ? ... would they be
> "boxed" into a reference for each method call, so that the method call
> can modify them ? ...or are all non-reference values immutable ?....
>
> to put it down clearly ...
>
> MyValueType a;
> a.Modify();
>
> would a be able to modify itself ? (unfortunately C# allows that)

So does ruby. We need that :)

/Erik

--
Erik Bågfors | er...@bagfors.nu
Supporter of free software | GSM +46 733 279 273
fingerprint: 6666 A85B 95D3 D26B 296B 6C60 4F32 2C0B 693D 6E32

Dan Sugalski

unread,
Jan 3, 2003, 10:05:33 PM1/3/03
to Erik Bågfors, Gopal V, perl6-i...@perl.org
At 7:27 PM +0100 1/3/03, Erik Bågfors wrote:
>On Sat, 2003-01-04 at 00:28, Gopal V wrote:
>> If memory serves me right, Dan Sugalski wrote:
>> > language-level "we're object-oriented dammit!" objects, not the
>> > lower-level stuff we're currently working with) should/will behave.
>>
>> yay ! ... finally !
>
>The moment we've all been waiting for :)

Sheesh, everyone lay on the guilt, why don't you? :-P

> > > reference-style objects and non-reference values.
>>
>> How large can a non-reference value be ? ... (in the .NET opcodes the
>> 'struct' seems to be unlimited in size ...) But well, I'd settle for
>> a non-reference of at least large integers (64bit)...
>>
>> And how will non-reference values dispatch methods ? ... would they be
>> "boxed" into a reference for each method call, so that the method call
>> can modify them ? ...or are all non-reference values immutable ?....
>>
>> to put it down clearly ...
>>
>> MyValueType a;
>> a.Modify();
>>
>> would a be able to modify itself ? (unfortunately C# allows that)
>
>So does ruby. We need that :)

I wasn't aware that ruby had value types--I thought it was all
reference types. Time to crack open the nutshell book again,
apparently.

Dan Sugalski

unread,
Jan 3, 2003, 10:04:34 PM1/3/03
to Gopal V, perl6-i...@perl.org
At 4:58 AM +0530 1/4/03, Gopal V wrote:
>If memory serves me right, Dan Sugalski wrote:
>> language-level "we're object-oriented dammit!" objects, not the
>> lower-level stuff we're currently working with) should/will behave.
>
>yay ! ... finally !
>
>> reference-style objects and non-reference values.
>
>How large can a non-reference value be ? ... (in the .NET opcodes the
>'struct' seems to be unlimited in size ...) But well, I'd settle for
>a non-reference of at least large integers (64bit)...

It can be as big as you like. Hang a buffer off the data pointer and
stick anything and everything you might want into it. Do we need to
build with 64 bit integers to make sure you have space? :)

>And how will non-reference values dispatch methods ? ... would they be
>"boxed" into a reference for each method call, so that the method call
>can modify them ? ...or are all non-reference values immutable ?....

Neither. Non-reference values are just plain PMCs. Reference values
are PMCs that point to other PMCs.

>to put it down clearly ...
>
>MyValueType a;
>a.Modify();
>
>would a be able to modify itself ? (unfortunately C# allows that)

Absolutely. It makes things generally faster and easier for perl, and
doesn't affect python or ruby. Yeah, I know, immutable values make a
number of static compilation things better with sufficient
engineering resources, but we're not particularly static, and our
resources are occasionally spotty. :)

Erik Bågfors

unread,
Jan 4, 2003, 8:03:40 AM1/4/03
to Dan Sugalski, Gopal V, perl6-i...@perl.org
On Sat, 2003-01-04 at 04:05, Dan Sugalski wrote:
> At 7:27 PM +0100 1/3/03, Erik Bågfors wrote:
> >On Sat, 2003-01-04 at 00:28, Gopal V wrote:
> >> If memory serves me right, Dan Sugalski wrote:
> >> > language-level "we're object-oriented dammit!" objects, not the
> >> > lower-level stuff we're currently working with) should/will behave.
> >>
> >> yay ! ... finally !
> >
> >The moment we've all been waiting for :)
>
> Sheesh, everyone lay on the guilt, why don't you? :-P

Working on it....
To be honest, I won't have much time from next week so now is probably
the only time I have to do something for a long time. So all I can do
is lay on the guilt :)

> > > > reference-style objects and non-reference values.
> >>
> >> How large can a non-reference value be ? ... (in the .NET opcodes the
> >> 'struct' seems to be unlimited in size ...) But well, I'd settle for
> >> a non-reference of at least large integers (64bit)...
> >>
> >> And how will non-reference values dispatch methods ? ... would they be
> >> "boxed" into a reference for each method call, so that the method call
> >> can modify them ? ...or are all non-reference values immutable ?....
> >>
> >> to put it down clearly ...
> >>
> >> MyValueType a;
> >> a.Modify();
> >>
> >> would a be able to modify itself ? (unfortunately C# allows that)
> >
> >So does ruby. We need that :)
>
> I wasn't aware that ruby had value types--I thought it was all
> reference types. Time to crack open the nutshell book again,
> apparently.

Well, An object can certainly modify itself.

: [bagfors@detrius]$ ; irb
irb(main):001:0> a="test"
"test"
irb(main):002:0> a.sub!('e','s')
"tsst"
irb(main):003:0> p a
"tsst"
nil


But they are still reference types.

irb(main):006:0> a="test"
"test"
irb(main):007:0> b=a
"test"
irb(main):008:0> a.sub!('e','s')
"tsst"
irb(main):009:0> p a
"tsst"
nil
irb(main):010:0> p b
"tsst"
nil

So I guess it just modifies the reference. (oh.. I really need to learn
more about low-level language-stuff...)

Gopal V

unread,
Jan 4, 2003, 8:26:29 AM1/4/03
to perl6-i...@perl.org
If memory serves me right, Erik Bågfors wrote:
> > >> would a be able to modify itself ? (unfortunately C# allows that)
> > >

To clarify here's my example ...

=cut

using System;
public struct MyStruct
{
int val;
public MyStruct(int x){ val=x; }
public void Modify(){ val=42; }
public override String ToString(){ return val.ToString(); }
}
public class FooBar
{
public static void Main()
{
MyStruct m1=new MyStruct(10);
MyStruct m2=m1;
m1.Modify();
Console.WriteLine(m1);
Console.WriteLine(m2);
}
}

=end cut

Which gives

42
10

If in anycase Parrot wants to avoid this , we could always add a special
case to the ILNode_Assign to generate an explicit copy step in parrot for
valuetypes...

So, workarounds are possible .. and neither the host nor the compiler
is there yet ;) ...

Steve Fink

unread,
Jan 4, 2003, 8:21:16 PM1/4/03
to Gopal V, perl6-i...@perl.org
On Jan-04, Gopal V wrote:
> So, workarounds are possible .. and neither the host nor the compiler
> is there yet ;) ...

Good point -- we'd better speed up on this Parrot stuff, so we can
push more of the really hard things onto you compiler guys. ;)

Dan Sugalski

unread,
Jan 5, 2003, 1:35:18 PM1/5/03
to Gopal V, perl6-i...@perl.org

Why would we want to avoid this? It looks exactly like what ought to happen.

Attriel

unread,
Jan 5, 2003, 3:29:08 PM1/5/03
to perl6-i...@perl.org

I think he was explaining what he meant in another post that someone
questioned, with this example; then the "wants to avoid this" referred to
"avoiding the easy-path error of NOT doing this". I think Gopal was
saying that C#/NET does it that way, and I can't imagine him asking to
have functionality he explicitly needs to be "carefully avoided" :)

OTOH, I may have misread a bunch of things, I'm not doing so hot on my
interpretations the last few days :o

--attriel


Dan Sugalski

unread,
Jan 5, 2003, 6:37:58 PM1/5/03
to att...@d20boards.net, perl6-i...@perl.org

Just because C# does it doesn't mean that he likes it. :)

Gopal V

unread,
Jan 6, 2003, 12:30:06 AM1/6/03
to perl6-i...@perl.org
If memory serves me right, Dan Sugalski wrote:
> >> Why would we want to avoid this? It looks exactly like what ought to
> >> happen.

If you can provide that in-vm , it would be a lot faster ...(hmm, that's
one argument that should convince you ;)

But like I said , I need lots of sticky notes for all the opcodes for
parrot ...(I'm still in "can't remember all opcodes" mode)....

> Just because C# does it doesn't mean that he likes it. :)

To end all further debate --

*) C# has something like this ,

*) I can't see what Dan has in head for parrot ,

*) I don't want feature creep into parrot

*) Our C# -> JVM compiler already has the workarounds for this like:
invokestatic "MyStruct" "copyIn__" "(LMyStruct;)LMyStruct;"

*) I really don't like valuetypes that much :).

*) Rhys will be doing most of the design , this is his headache actually :-)

So does that cover all bases ?....

Dan Sugalski

unread,
Jan 6, 2003, 2:49:19 PM1/6/03
to Gopal V, perl6-i...@perl.org
At 11:00 AM +0530 1/6/03, Gopal V wrote:
>If memory serves me right, Dan Sugalski wrote:
>> >> Why would we want to avoid this? It looks exactly like what ought to
>> >> happen.
>
>If you can provide that in-vm , it would be a lot faster ...(hmm, that's
>one argument that should convince you ;)

Struct copying? Not a problem. Cloning this sort of thing is the same
as cloning off strings. Deeper copies, where we trace the tree, are a
bit trickier, but there are vtable entries to do that, so classes can
implement things as fast as possible if people need them.

>But like I said , I need lots of sticky notes for all the opcodes for
>parrot ...(I'm still in "can't remember all opcodes" mode)....
>
>> Just because C# does it doesn't mean that he likes it. :)
>
>To end all further debate --
>
>*) C# has something like this ,
>
>*) I can't see what Dan has in head for parrot ,

IIRC, it's grey and squishy. :)

>*) I don't want feature creep into parrot

If you can find a feature that we don't have, I'd be surprised. :)
There's not much left out of perl, so there's not much left out of
parrot.

>*) Our C# -> JVM compiler already has the workarounds for this like:
> invokestatic "MyStruct" "copyIn__" "(LMyStruct;)LMyStruct;"

I think we can make things a bit easier than that. We should build a
good base struct PMC type to build on to make this faster, though.

>*) I really don't like valuetypes that much :).

And I don't much like reftypes, so we're even. :)

>*) Rhys will be doing most of the design , this is his headache actually :-)
>
>So does that cover all bases ?....

I think so. I'm about ready to get objects formally(ish) defined, but
given that I'm in a coffee shop and unconnected now, it might hit the
list at the same time this does. (Or before, depending on how the
mail queues go...)

Piers Cawley

unread,
Jan 8, 2003, 4:28:38 AM1/8/03
to Dan Sugalski, Gopal V, perl6-i...@perl.org
Dan Sugalski <d...@sidhe.org> writes:
> Absolutely. It makes things generally faster and easier for perl, and
> doesn't affect python or ruby. Yeah, I know, immutable values make a
> number of static compilation things better with sufficient engineering
> resources, but we're not particularly static, and our resources are
> occasionally spotty. :)

Hey, I know some of the Parrot developers are young, but it doesn't
necessarily follow that they have acne.

--
Piers

0 new messages