At 11:45 AM -0700 8/1/03, T.O.G. of Spookware wrote:

Hi, all. I've been following Parrot development and been playing with Parrot for a...bout a year and a half, now. First time posting to the list, though, so forgive me if this has already been covered or is stupid in some way :-)

Anyway, while playing around with IMCC, this kind of
bugged me:

P3 = 32   # tells the PMC referenced by P3 to
            set its value to 32
P3 = P5   # copies reference in P5 to P3

What I don't like about this is that it's not
immediately obvious from looking at the code whether
you're telling P3 to change its value or simply
replace the PMC reference stored in P3 with another.

This is a reasonable thing to worry about, because we have three separate semantics, set, assign, and clone.


For I and N registers, all three are identical, since integers and floats are value types at this level.

For S and P registers, things get odd. set just copies the contents of one register to another. Since P and S registers are pointers, it means you have two registers that point to the same string or PMC structure.

Assign takes the contents of the structure that the S or P source register points to and puts those contents into the structure the destination register points to. A new structure is not created, and if the destination is supposed to do something when a value is put into it, then the destination does that. (If, for example, the destination variable overloads assignment or is tied, depending on the language you come from)

Cloning makes a copy of the source, complete with new structure, and puts a pointer to the new structure into the destination register, throwing away whatever pointer was in there to begin with.

It's a bit funky, but you need all three semantics to make things work out right.
--
Dan


--------------------------------------"it's like this"-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to