Used colon-less keyword syntax in method signatures where the optional variable name...
[cslatevm.git] / src / lib / immutable.slate
blob8d601f092039af6dc982d5bcb77133db2d411223
1 x@(Root traits) immutablySettingSlots: slotArray to: valueArray
2 "TODO: optimize this somehow to avoid the wasteful clone?"
4   x isImmutable
5     ifTrue: [x cloneSettingSlots: slotArray to: valueArray]
6     ifFalse: [x immutably cloneSettingSlots: slotArray to: valueArray]
7 ].
9 x@(Root traits) isFrozen
10 "Whether the object and all its slot values recursively are immutable."
12   x isImmutable /\
13    [x allSlotsDo: [| :obj | obj isImmutable ifFalse: [^ False]. True]]
16 "TODO: figure out a more systematic way to handle has-no-slots-and-never-will."
17 x@(Oddball traits) immutably [x].
18 x@(Oddball traits) freeze [x].
19 x@(SmallInteger traits) isImmutable [True].
20 x@(SmallInteger traits) isFrozen [True].
22 x@(Root traits) freeze &seen
23 "Make a frozen variant of the existing object, meaning an immutable version of
24 the object with frozen variants of its slot values (and so it must recurse)."
26   seen `defaultsTo: IdentityDictionary new.
27   x isFrozen \/ [x restrictsDelegation]
28     ifTrue: [x]
29     ifFalse: [seen at: x ifAbsentPut:
30       [x immutablySettingSlots: x slotNames to:
31         (x slotValues collect: [| :obj | obj freeze &seen: seen])]]