[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Strange behaviour??
I've been thinking about how to implement 'copy-on-write' slots --
attempts by objects other than the one that actually contains the slot
to write to it will result in that object getting its own copy of the
slot.
I was going to try and make the assignment slot private, and catch
the noPublicSelector:... and make the decision there (this won't work
I think)
I came across the following behaviour which I don't understand:
Try the following code (under 1.1):
_AddSlots: ( | copyWrite* = () | )
copyWrite _AddSlotsIfAbsent: ( |
top = ().
first = ().
second = ().
third = ().
| )
copyWrite top _Define: ( |
_ parent* = lobby.
| )
copyWrite first _Define: ( |
_ parent* = copyWrite top. " * "
^ noPublicSelector: sel Type: msgType Delegatee: del MethodHolder: mh Arguments: args = (
'sel = ' print. sel _Print.
'type= ' print. msgType _Print.
'del = ' print. del _Print.
'mh = ' print. mh _Print.
'args= ' print. args _Print ).
^_ prop1 <- 'InitVal'.
| )
copyWrite second _Define: ( |
_ parent* = copyWrite first.
| )
copyWrite first _Print
copyWrite first prop1: 'hi'
copyWrite first _Print
copyWrite second _Print
copyWrite second prop1: 'there'
copyWrite first _Print
copyWrite second _Print
======== output:
Found /home/latour/mcr/self/config/CopyOnWrite.self
reading /home/latour/mcr/self/config/CopyOnWrite.self...
<89>: ( | _ parent* = <90>. ^ noPublicSelector:Type:Delegatee:MethodHolder:Arguments: = <a method>. ^ prop1 = 'InitVal'. _ prop1: = <-. | )
<89>: ( | _ parent* = <90>. ^ noPublicSelector:Type:Delegatee:MethodHolder:Arguments: = <a method>. ^ prop1 = 'hi'. _ prop1: = <-. | )
<91>: ( | _ parent* = <89>. | )
<89>: ( | _ parent* = <90>. ^ noPublicSelector:Type:Delegatee:MethodHolder:Arguments: = <a method>. ^ prop1 = 'there'. _ prop1: = <-. | )
<91>: ( | _ parent* = <89>. | )
>
============
Now, comment out the line with the " * " (removing the parent):
======== output:
> run CopyOnWrite
Found /home/latour/mcr/self/config/CopyOnWrite.self
reading /home/latour/mcr/self/config/CopyOnWrite.self...
<92>: ( | ^ noPublicSelector:Type:Delegatee:MethodHolder:Arguments: = <a method>. ^ prop1 = 'InitVal'. _ prop1: = <-. | )
sel = 'prop1:' <25>: ( | ^ parent* = <26>. | byte array: {112, 114, 111, 112, 49, 58} )
type= 'normal' <27>: ( | ^ parent* = <26>. | byte array: {110, 111, 114, 109, 97, 108} )
del = nil <28>: ( | _ parent* = <29>. ^ printString = 'nil'. _ thisObjectPrints = true. ^ equals: = <a method>. | )
mh = lobby <4>: ( | _ shortcuts* = <31>. _ filein* = <32>. ^ globals* = <33>. ^ defaults* = <34>. _ doIt = <a method>. _ printIt = <a method>. ^ lobby = lobby. ^ findSlot:In:From: = <a method>. ^ findSlot:In: = <a method>. ^ findSlot: = <a method>. copyWrite = <93>. | )
args= <94>: ( | ^ parent* = <36>. | object array: {'hi'} )
<92>: ( | ^ noPublicSelector:Type:Delegatee:MethodHolder:Arguments: = <a method>. ^ prop1 = 'InitVal'. _ prop1: = <-. | )
<95>: ( | _ parent* = <92>. | )
sel = 'prop1:' <25>: ( | ^ parent* = <26>. | byte array: {112, 114, 111, 112, 49, 58} )
type= 'normal' <27>: ( | ^ parent* = <26>. | byte array: {110, 111, 114, 109, 97, 108} )
del = nil <28>: ( | _ parent* = <29>. ^ printString = 'nil'. _ thisObjectPrints = true. ^ equals: = <a method>. | )
mh = lobby <4>: ( | _ shortcuts* = <31>. _ filein* = <32>. ^ globals* = <33>. ^ defaults* = <34>. _ doIt = <a method>. _ printIt = <a method>. ^ lobby = lobby. ^ findSlot:In:From: = <a method>. ^ findSlot:In: = <a method>. ^ findSlot: = <a method>. copyWrite = <93>. | )
args= <96>: ( | ^ parent* = <36>. | object array: {'there'} )
<92>: ( | ^ noPublicSelector:Type:Delegatee:MethodHolder:Arguments: = <a method>. ^ prop1 = 'InitVal'. _ prop1: = <-. | )
<95>: ( | _ parent* = <92>. | )
>
========
WHY the difference? Somehow the local noPublicSelector:... isn't
getting called. The only other noPublicSelector: I can find from
copyWrite first is the one in errorHandling. It is supposed to
complain about accessing private slots and dump the stack. Somehow
this isn't happening. Something is saying 'that is okay. You can
access the private slots'
What is it?