|
1 "{ Package: 'stx:libcomp' }" |
|
2 |
|
3 ByteArray variableByteSubclass:#ImmutableByteArray |
|
4 instanceVariableNames:'' |
|
5 classVariableNames:'' |
|
6 poolDictionaries:'' |
|
7 category:'System-Compiler-Support' |
|
8 ! |
|
9 |
|
10 |
|
11 !ImmutableByteArray methodsFor:'accessing'! |
|
12 |
|
13 at:index put:value |
|
14 "Trigger an error if an immutable bytearray is stored into. |
|
15 The store will be performed (for compatibility reasons) if you continue |
|
16 in the debugger." |
|
17 |
|
18 self notifyStoreError. |
|
19 ^ super at:index put:value |
|
20 ! |
|
21 |
|
22 basicAt:index put:value |
|
23 "Trigger an error if an immutable bytearray is stored into. |
|
24 The store will be performed (for compatibility reasons) if you continue |
|
25 in the debugger." |
|
26 |
|
27 self notifyStoreError. |
|
28 ^ super basicAt:index put:value |
|
29 ! ! |
|
30 |
|
31 !ImmutableByteArray methodsFor:'converting'! |
|
32 |
|
33 asImmutableByteArray |
|
34 ^ self |
|
35 ! ! |
|
36 |
|
37 !ImmutableByteArray methodsFor:'copying'! |
|
38 |
|
39 copyEmpty |
|
40 "when copying, return a real (mutable) ByteArray" |
|
41 |
|
42 ^ ByteArray new:self size |
|
43 ! |
|
44 |
|
45 copyEmptyAndGrow:size |
|
46 "when copying, return a real (mutable) ByteArray" |
|
47 |
|
48 ^ ByteArray new:size |
|
49 ! |
|
50 |
|
51 postCopy |
|
52 "when copied, make me a real (mutable) ByteArray" |
|
53 |
|
54 self changeClassTo:ByteArray. |
|
55 ! |
|
56 |
|
57 postDeepCopy |
|
58 "when copied, make me a real (mutable) ByteArray" |
|
59 |
|
60 self changeClassTo:ByteArray. |
|
61 |
|
62 " |
|
63 #[1 2 3 4] asImmutableByteArray copy class |
|
64 #[1 2 3 4] asImmutableByteArray shallowCopy class |
|
65 #[1 2 3 4] asImmutableByteArray deepCopy class |
|
66 " |
|
67 ! |
|
68 |
|
69 shallowCopy |
|
70 "when copying, return a real (mutable) ByteArray" |
|
71 |
|
72 |sz| |
|
73 |
|
74 sz := self size. |
|
75 ^ (ByteArray new:sz) |
|
76 replaceFrom:1 to:sz with:self startingAt:1 |
|
77 ! ! |
|
78 |
|
79 !ImmutableByteArray methodsFor:'error handling'! |
|
80 |
|
81 creator |
|
82 "find the method that contains me" |
|
83 |
|
84 ^ Method allSubInstances detect:[:aMethod | (aMethod referencesGlobal:self)] ifNone:nil. |
|
85 |
|
86 " |
|
87 #(1 2 3) creator |
|
88 " |
|
89 |
|
90 "Modified: 24.6.1996 / 15:36:28 / stefan" |
|
91 ! |
|
92 |
|
93 notifyStoreError |
|
94 "a store is attempted - for our convenience, find the method that |
|
95 contains me, for a nicer error message" |
|
96 |
|
97 |creator msg| |
|
98 |
|
99 creator := self creator. |
|
100 msg := 'store into/change of literal'. |
|
101 creator notNil ifTrue:[ |
|
102 msg := msg , ' (' , creator whoString , ')' |
|
103 ]. |
|
104 " |
|
105 this error is reported on an attempt to store into a literal |
|
106 array. The literal was created in creator. |
|
107 If you press continue in the debugger, the store will be performed. |
|
108 If you don't want this, press abort and check your code. |
|
109 Storing into literals is VERY VERY bad coding style. |
|
110 " |
|
111 self error:msg mayProceed:true |
|
112 ! ! |
|
113 |
|
114 !ImmutableByteArray methodsFor:'private'! |
|
115 |
|
116 species |
|
117 "Copies should be mutable" |
|
118 |
|
119 ^ ByteArray |
|
120 ! ! |
|
121 |
|
122 !ImmutableByteArray methodsFor:'queries'! |
|
123 |
|
124 isLiteral |
|
125 "return true, if the receiver can be used as a literal constant in ST syntax |
|
126 (i.e. can be used in constant arrays)" |
|
127 |
|
128 "yes, I must be" |
|
129 ^ true |
|
130 |
|
131 ! ! |
|
132 |
|
133 !ImmutableByteArray methodsFor:'specials'! |
|
134 |
|
135 become:anotherObject |
|
136 "trigger an error if I should become something else |
|
137 (this would be an even more tricky manipulation)" |
|
138 |
|
139 self notifyStoreError. |
|
140 ^ super become:anotherObject |
|
141 ! |
|
142 |
|
143 becomeNil |
|
144 "trigger an error if I should become nil |
|
145 (this would be an even more tricky manipulation)" |
|
146 |
|
147 self notifyStoreError. |
|
148 ^ super becomeNil |
|
149 ! ! |
|
150 |
|
151 !ImmutableByteArray class methodsFor:'documentation'! |
|
152 |
|
153 version_CVS |
|
154 ^ '$Header: /cvs/stx/stx/libbasic/ImmutableByteArray.st,v 1.1 2009-11-05 14:34:35 cg Exp $' |
|
155 ! ! |