1 m@(Map traits) acceptsFlagIndex: n
2 "Whether the bit fits into the logical space of the SmallInteger that maps use
4 [n between: 0 and: 30].
6 m@(Map traits) setFlag: index
8 (m acceptsFlagIndex: index)
9 ifTrue: [m flags := m flags bitOr: 1 << index]
10 ifFalse: [error: 'Not a valid Map flag index.']
13 m@(Map traits) clearFlag: index
15 (m acceptsFlagIndex: index)
16 ifTrue: [m flags := m flags bitAnd: (0 << index) bitNot]
17 ifFalse: [error: 'Not a valid Map flag index.']
20 m@(Map traits) isFlagSetAt: index
22 (m acceptsFlagIndex: index)
23 ifTrue: [(m flags bitAt: index) = 1]
24 ifFalse: [error: 'Not a valid Map flag index.']
27 x@(Root traits) replaceMap
28 "This ensures that updates to the map do not erroneously effect all objects
30 [x _map: x _map clone].
32 x@(Root traits) restrictDelegation
33 "Sets the flag that marks this object->traits relationship as base-to-meta
34 and therefore where to stop on method lookup. The map is replaced since we
35 do not want to modify siblings in this way."
41 x@(Root traits) restrictsDelegation
42 [x _map isFlagSetAt: 0].
44 x@(Root traits) isImmutable
45 "Whether the object is immutable - VM-protected flag."
46 [x _map isFlagSetAt: 1].
48 x@(Root traits) immutably
49 "Answers an immutable version of the given object."
52 ifTrue: [x] ifFalse: [x clone `>> [replaceMap. _map setFlag: 1. ]]
55 x@(Root traits) mutably
56 "Answers a mutable version of the given object."
59 ifTrue: [x clone `>> [replaceMap. _map clearFlag: 1. ]] ifFalse: [x]
62 x@(Root traits) immutable
63 [error: 'An attempt was made to modify an immutable object.'].
65 x@(Map traits) isDelegateOffset: offset
66 "Delegates are marked by the low-bit in the offset. This encapsulates that."
67 [(offset bitAnd: 1) = 1].
69 x@(Map traits) indexForOffset: offset
70 "Answers the ordinal index for a given offset, by clearing the low-bit which
71 marks delegation, and removing the base offset."
72 [(offset bitAnd: #[1 bitNot]) - 8 quo: 4].
74 x@(Root traits) representative
75 "Answers what object the map uses as its representative, which should be the
76 source of the clone family."
77 [x _map representative].
79 x@(Root traits) represents: another
80 "Answers whether x is the source of the clone family of the other argument."
81 [x == another representative].