author | Claus Gittinger <cg@exept.de> |
Mon, 31 Mar 2003 11:53:22 +0200 | |
changeset 7142 | 7a6297c86ef4 |
parent 6054 | 7719f857af51 |
child 7153 | 87edd141467e |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
5434 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
3985 | 15 |
String variableByteSubclass:#Symbol |
1020 | 16 |
instanceVariableNames:'' |
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Collections-Text' |
|
1 | 20 |
! |
21 |
||
77 | 22 |
!Symbol class methodsFor:'documentation'! |
1 | 23 |
|
88 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
159 | 27 |
All Rights Reserved |
88 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
77 | 38 |
documentation |
39 |
" |
|
40 |
Symbols represent unique strings - every symbol with same printString |
|
41 |
exists exactly once in the system; Symbols are used for selectors, global |
|
345 | 42 |
variable-keys etc. Symbols can also be used to represent things which are |
43 |
enumeration type values in other programming languages (since symbols are |
|
370 | 44 |
created at compile time, comparing them using == is a fast pointer compare). |
345 | 45 |
|
46 |
A symbol may not change its characters - i.e. it is constant over its lifetime. |
|
47 |
Other than that, symbols behave much like strings. |
|
1290 | 48 |
|
49 |
[author:] |
|
2200 | 50 |
Claus Gittinger |
77 | 51 |
" |
52 |
! ! |
|
1 | 53 |
|
77 | 54 |
!Symbol class methodsFor:'instance creation'! |
1 | 55 |
|
62 | 56 |
basicNew:size |
57 |
"redefined to return a string instead of a symbol - |
|
58 |
this allows all copy methods inherited from String to |
|
59 |
return strings containing the symbols characters. |
|
1020 | 60 |
Real symbols are only created with #intern: or #asSymbol." |
62 | 61 |
|
62 |
^ String new:size |
|
1020 | 63 |
|
64 |
"Modified: 26.2.1996 / 12:51:38 / cg" |
|
62 | 65 |
! |
66 |
||
77 | 67 |
fromString:aString |
68 |
"same as intern: for Symbol, but may be used to create interned instances |
|
69 |
of subclasses. |
|
70 |
Notice: this fails, if you try to intern an instance of a subclass, AND |
|
71 |
a symbol with the same name already exists. In this case, the original |
|
72 |
symbol is returned. To use it for enum-type symbols, make certain, that the |
|
73 |
names are unique (for example by including the classes name as a prefix-string)." |
|
74 |
||
267 | 75 |
|sym len| |
77 | 76 |
|
267 | 77 |
sym := aString asSymbolIfInterned. |
78 |
sym notNil ifTrue:[ |
|
79 |
^ sym |
|
77 | 80 |
]. |
81 |
||
82 |
" |
|
83 |
create a new uninterned instance first |
|
84 |
" |
|
85 |
len := aString size. |
|
267 | 86 |
sym := super basicNew:len. |
87 |
sym replaceFrom:1 to:len with:aString. |
|
77 | 88 |
|
89 |
"now, intern it" |
|
90 |
%{ |
|
329 | 91 |
sym = __INTERNSYMBOL(sym, (OBJ *)0, __context); |
77 | 92 |
%}. |
267 | 93 |
^ sym |
77 | 94 |
! |
95 |
||
608 | 96 |
intern:aString |
97 |
"return a unique symbol with printname taken from the String-argument" |
|
98 |
||
99 |
%{ /* NOCONTEXT */ |
|
100 |
OBJ newSymbol; |
|
101 |
||
102 |
if (__isSymbol(aString)) { |
|
103 |
RETURN (aString); |
|
104 |
} |
|
105 |
if (__isString(aString)) { |
|
2200 | 106 |
newSymbol = __MKSYMBOL(__stringVal(aString), (OBJ *)0); |
608 | 107 |
if (newSymbol != nil) { |
108 |
RETURN (newSymbol); |
|
109 |
} |
|
110 |
} |
|
111 |
%}. |
|
112 |
aString class ~~ String ifTrue:[ |
|
113 |
"/ |
|
114 |
"/ only allowed to intern strings |
|
115 |
"/ |
|
116 |
^ self mustBeString |
|
117 |
]. |
|
118 |
^ ObjectMemory allocationFailureSignal raise. |
|
119 |
! |
|
120 |
||
1 | 121 |
internCharacter:aCharacter |
122 |
"return a unique symbol with printname taken from the Character-argument" |
|
123 |
||
124 |
^ self intern:(aCharacter asString) |
|
608 | 125 |
! |
126 |
||
127 |
new:size |
|
128 |
"redefined to return a string instead of a symbol - |
|
129 |
this allows all copy methods inherited from String to |
|
130 |
return strings containing the symbols characters. |
|
131 |
Real symbols are only created with intern: or asSymbol." |
|
132 |
||
133 |
^ String new:size |
|
134 |
! ! |
|
135 |
||
5185
15a129151b3b
fixed bug in storeString (must duplicate single quotes)
Claus Gittinger <cg@exept.de>
parents:
4987
diff
changeset
|
136 |
!Symbol class methodsFor:'Compatibility - ST80'! |
2570
26616a00d5aa
added #tableSize for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2565
diff
changeset
|
137 |
|
26616a00d5aa
added #tableSize for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2565
diff
changeset
|
138 |
tableSize |
26616a00d5aa
added #tableSize for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2565
diff
changeset
|
139 |
"return the size of the systems symbol table" |
26616a00d5aa
added #tableSize for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2565
diff
changeset
|
140 |
|
4838 | 141 |
"/ claus: I dont know, if the returned value should be exact. |
142 |
"/ the number below is just arbitrary ... |
|
2570
26616a00d5aa
added #tableSize for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2565
diff
changeset
|
143 |
|
26616a00d5aa
added #tableSize for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2565
diff
changeset
|
144 |
^ 10000 |
26616a00d5aa
added #tableSize for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2565
diff
changeset
|
145 |
|
26616a00d5aa
added #tableSize for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2565
diff
changeset
|
146 |
"Created: 18.4.1997 / 20:52:20 / cg" |
26616a00d5aa
added #tableSize for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2565
diff
changeset
|
147 |
! ! |
26616a00d5aa
added #tableSize for ST-80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2565
diff
changeset
|
148 |
|
608 | 149 |
!Symbol class methodsFor:'binary storage'! |
150 |
||
1253 | 151 |
binaryDefinitionFrom:stream manager:manager |
152 |
"retrieve a symbol from a binary input stream (nonpublic interface)" |
|
153 |
||
154 |
^ self intern:(super binaryDefinitionFrom:stream manager:manager) |
|
155 |
||
3086 | 156 |
"Modified: / 2.11.1997 / 16:17:06 / cg" |
1 | 157 |
! ! |
158 |
||
159 |
!Symbol class methodsFor:'queries'! |
|
160 |
||
608 | 161 |
findInterned:aString |
162 |
"for ST-80 compatibility - if the argument, aString is known |
|
163 |
as Symbol, return this symbol. Otherwise return nil." |
|
164 |
||
165 |
^ aString asSymbolIfInterned |
|
166 |
! |
|
167 |
||
168 |
hasInterned:aString |
|
169 |
"return true, if the argument, aString is known as Symbol; |
|
170 |
false otherwise" |
|
171 |
||
172 |
^ aString knownAsSymbol |
|
173 |
! |
|
174 |
||
1 | 175 |
hasInterned:aString ifTrue:trueBlock |
176 |
"for ST-80 compatibility - if the argument, aString is known |
|
177 |
as Symbol, evaluate the block with the corresponding symbol |
|
178 |
as argument and return true; otherwise return false" |
|
179 |
||
275 | 180 |
|sym| |
181 |
||
182 |
(sym := aString asSymbolIfInterned) notNil ifTrue:[ |
|
183 |
trueBlock value:sym. |
|
159 | 184 |
^ true |
1 | 185 |
]. |
186 |
^ false |
|
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
187 |
! |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
188 |
|
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
189 |
hasSharedInstances |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
190 |
"return true if this class has shared instances, that is, instances |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
191 |
with the same value are identical. |
4654 | 192 |
True returned here - there is only one of each symbol (per contents)." |
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
193 |
|
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
194 |
^ true |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
195 |
|
1 | 196 |
! ! |
197 |
||
198 |
!Symbol methodsFor:'accessing'! |
|
199 |
||
200 |
basicAt:index put:something |
|
345 | 201 |
"report an error if an interned symbol is about to be changed |
1219 | 202 |
- interned symbols may NOT be changed. |
203 |
For uninterned symbols, this is allowed." |
|
1 | 204 |
|
77 | 205 |
self knownAsSymbol ifTrue:[ |
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
206 |
self error:'interned symbols may not be changed'. |
77 | 207 |
]. |
208 |
" |
|
209 |
uninterned - allow change |
|
210 |
" |
|
211 |
^ super basicAt:index put:something |
|
1219 | 212 |
|
213 |
"Modified: 19.4.1996 / 11:16:10 / cg" |
|
252 | 214 |
! |
215 |
||
216 |
byteAt:index put:value |
|
217 |
"report an error if interned - interned symbols may not be changed." |
|
218 |
||
219 |
^ self basicAt:index put:(value asCharacter) |
|
1 | 220 |
! ! |
221 |
||
3086 | 222 |
!Symbol methodsFor:'binary storage'! |
223 |
||
224 |
storeBinaryDefinitionOn:stream manager:manager |
|
225 |
"append a binary representation of the receiver onto stream. |
|
226 |
Redefined since short Symbol can be stored with a special type code |
|
227 |
in a more compact way. |
|
228 |
This is an internal interface for the binary storage mechanism." |
|
229 |
||
230 |
|myClass myBasicSize| |
|
231 |
||
232 |
"/ not for subclasses with named instVars. |
|
233 |
(myClass := self class) instSize ~~ 0 ifTrue:[ |
|
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
234 |
^ super storeBinaryDefinitionOn:stream manager:manager |
3086 | 235 |
]. |
236 |
||
237 |
myBasicSize := self basicSize. |
|
238 |
||
239 |
"/ can use a more compact representation; |
|
240 |
"/ but not for subclasses ... |
|
241 |
||
242 |
((myClass == Symbol) |
|
243 |
and:[myBasicSize <= 255]) ifTrue:[ |
|
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
244 |
"/ special encoding: <codeForSymbol> <len> <bytes> ... |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
245 |
stream nextPut:(manager codeForSymbol); nextPut:myBasicSize. |
3086 | 246 |
] ifFalse:[ |
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
247 |
manager putIdOfClass:myClass on:stream. |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
248 |
stream nextNumber:4 put:myBasicSize. |
3086 | 249 |
]. |
250 |
stream nextPutBytes:myBasicSize from:self startingAt:1. |
|
251 |
||
252 |
"Modified: / 2.11.1997 / 15:28:56 / cg" |
|
253 |
"Created: / 2.11.1997 / 16:13:47 / cg" |
|
254 |
! ! |
|
255 |
||
608 | 256 |
!Symbol methodsFor:'comparing'! |
159 | 257 |
|
608 | 258 |
= something |
259 |
"return true, if the receiver and argument consist of the same characters. |
|
260 |
Redefined here, for more efficient #= comparison of symbols |
|
261 |
(which ought to be compared using #==). |
|
262 |
If the argument is a symbol, we use a quick pointer compare, instead of |
|
263 |
the inherited value compare." |
|
13 | 264 |
|
608 | 265 |
%{ /* NOCONTEXT */ |
266 |
OBJ cls; |
|
13 | 267 |
|
608 | 268 |
if (! __isNonNilObject(something)) RETURN(false); |
269 |
if ((cls = __qClass(something)) == Symbol) { |
|
270 |
RETURN (self == something ? true : false); |
|
271 |
} |
|
272 |
if (cls == String) { |
|
273 |
RETURN (strcmp(__stringVal(self), __stringVal(something)) == 0 ? true : false); |
|
345 | 274 |
} |
275 |
%}. |
|
608 | 276 |
"fall back; could be a TwoByteString, or a collection of Characters" |
1 | 277 |
|
608 | 278 |
^ super = something |
427 | 279 |
! |
280 |
||
356 | 281 |
identityHash |
282 |
"interned symbols can return a better hash key" |
|
283 |
||
284 |
%{ /* NOCONTEXT */ |
|
285 |
||
3985 | 286 |
REGISTER unsigned int g, val; |
287 |
REGISTER unsigned char *cp, *ce; |
|
356 | 288 |
int l; |
289 |
||
290 |
if (__Class(self) == Symbol) { |
|
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
291 |
val = __GET_HASH(self); |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
292 |
/* |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
293 |
* only do it, if I have no standard hash key |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
294 |
* assigned (which can only happen due to a #become:, |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
295 |
* or by creating a symbol uninterned, and interning it |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
296 |
* after it got a hashKey assigned. |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
297 |
*/ |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
298 |
if (val == 0) { |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
299 |
cp = __stringVal(self); |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
300 |
l = __stringSize(self); |
356 | 301 |
|
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
302 |
/* |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
303 |
* this is the dragon-book algorithm |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
304 |
* We have tested 5-bit shifts as well: |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
305 |
* |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
306 |
* ST/X Symbols: 17807 |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
307 |
* Hashkey collisions (4bit): 14 0.07% |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
308 |
* Hashkey collisions (5bit): 300 1.68% |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
309 |
*/ |
356 | 310 |
|
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
311 |
if (l > 0) { |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
312 |
val = cp[0]; |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
313 |
if (l > 1) { |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
314 |
val = (val << 4) + cp[1]; |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
315 |
if (l > 2) { |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
316 |
val = (val << 4) + cp[2]; |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
317 |
if (l > 3) { |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
318 |
val = (val << 4) + cp[3]; |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
319 |
if (l > 4) { |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
320 |
val = (val << 4) + cp[4]; |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
321 |
if (l > 5) { |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
322 |
val = (val << 4) + cp[5]; |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
323 |
if (l > 6) { |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
324 |
val = (val << 4) + cp[6]; |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
325 |
for (ce = cp + l, cp += 7; cp < ce; cp++) { |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
326 |
if (g = (val & 0xF0000000)) { |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
327 |
val ^= g >> 24; |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
328 |
val ^= g; |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
329 |
} |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
330 |
val = (val << 4) + *cp; |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
331 |
} |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
332 |
} |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
333 |
} |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
334 |
} |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
335 |
} |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
336 |
} |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
337 |
} |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
338 |
} else { |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
339 |
val = 0; |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
340 |
} |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
341 |
val = (val * 31415821) & 0x3fffffff; |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
342 |
} else { |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
343 |
val = __MAKE_HASH__(val); |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
344 |
} |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
345 |
RETURN ( __MKSMALLINT(val) ); |
356 | 346 |
} |
347 |
%}. |
|
348 |
^ super identityHash |
|
3985 | 349 |
|
350 |
" |
|
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
351 |
|hashColl hashSet| |
3985 | 352 |
|
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
353 |
hashColl := OrderedCollection new:20000. |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
354 |
Symbol allInstancesDo:[:instance | |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
355 |
hashColl add:instance identityHash |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
356 |
]. |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
357 |
hashSet := hashColl asSet. |
3985 | 358 |
|
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
359 |
Transcript showCR:'Symbols: ', hashColl size printString, |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
360 |
' unique hash keys: ', hashSet size printString, |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
361 |
' collisions:', (hashColl size - hashSet size) printString. |
3985 | 362 |
" |
363 |
||
370 | 364 |
! |
365 |
||
366 |
~= something |
|
367 |
"return true, if the receiver and argument do not consist of the same characters. |
|
368 |
Redefined here, for more efficient #~= comparison of symbols |
|
369 |
(which ought to be compared using #~~). |
|
370 |
If the argument is a symbol, we use a quick pointer compare, instead of |
|
371 |
the inherited value compare." |
|
372 |
||
373 |
%{ /* NOCONTEXT */ |
|
374 |
OBJ cls; |
|
375 |
||
379 | 376 |
if (! __isNonNilObject(something)) RETURN(true); /* cannot be equal */ |
370 | 377 |
if ((cls = __qClass(something)) == Symbol) { |
379 | 378 |
RETURN (self == something ? false : true); |
370 | 379 |
} |
380 |
if (cls == String) { |
|
379 | 381 |
RETURN (strcmp(__stringVal(self), __stringVal(something)) == 0 ? false : true); |
370 | 382 |
} |
383 |
%}. |
|
384 |
"fall back; could be a TwoByteString, or a collection of Characters" |
|
385 |
||
386 |
^ super ~= something |
|
356 | 387 |
! ! |
388 |
||
608 | 389 |
!Symbol methodsFor:'converting'! |
390 |
||
6001
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
391 |
<< catalogID |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
392 |
"create and return a new UserMessage, with the receiver as key, |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
393 |
and the argument as cataglogID. |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
394 |
VW compatibility." |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
395 |
|
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
396 |
^ UserMessage key:self catalogID:catalogID |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
397 |
|
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
398 |
" |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
399 |
(#theFooMessage << #myMessages) |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
400 |
(#theFooMessage << #myMessages >> 'cannot read subclass of metaclass') |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
401 |
(#theFooMessage >> 'cannot read subclass of metaclass') |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
402 |
" |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
403 |
! |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
404 |
|
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
405 |
>> aString |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
406 |
"create and return a new UserMessage, with the receiver as key, |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
407 |
and the argument as defaultString. |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
408 |
VW compatibility." |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
409 |
|
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
410 |
^ UserMessage key:self defaultString:aString |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
411 |
|
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
412 |
" |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
413 |
(#theFooMessage << #myMessages) |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
414 |
(#theFooMessage << #myMessages >> 'cannot read subclass of metaclass') |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
415 |
(#theFooMessage >> 'cannot read subclass of metaclass') |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
416 |
" |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
417 |
! |
315a853c51cd
VW compatible userMessage support.
Claus Gittinger <cg@exept.de>
parents:
5941
diff
changeset
|
418 |
|
608 | 419 |
asString |
420 |
"return a string with printname taken from mine" |
|
421 |
||
422 |
%{ /* NOCONTEXT */ |
|
423 |
OBJ s; |
|
424 |
||
2565 | 425 |
s = __MKSTRING_ST(self); |
608 | 426 |
if (s != nil) { |
5434 | 427 |
RETURN (s); |
608 | 428 |
} |
429 |
%}. |
|
5434 | 430 |
^ (String new:(self size)) |
431 |
replaceFrom:1 with:self startingAt:1 |
|
608 | 432 |
! |
433 |
||
434 |
asSymbol |
|
435 |
"return the receiver as a symbol. |
|
436 |
Since I am a symbol - just return myself" |
|
437 |
||
438 |
^ self |
|
439 |
! |
|
440 |
||
441 |
asSymbolIfInterned |
|
442 |
"return the receiver as a symbol if there is one. |
|
443 |
Since I am a symbol - just return myself" |
|
444 |
||
445 |
^ self |
|
2416 | 446 |
! |
447 |
||
448 |
decodeAsLiteralArray |
|
449 |
"given a literalEncoding in the receiver, |
|
450 |
create & return the corresponding object. |
|
451 |
The inverse operation to #literalArrayEncoding." |
|
452 |
||
453 |
^ self |
|
454 |
||
455 |
"Created: 25.2.1997 / 19:15:26 / cg" |
|
456 |
"Modified: 25.2.1997 / 19:17:40 / cg" |
|
608 | 457 |
! ! |
458 |
||
459 |
!Symbol methodsFor:'copying'! |
|
460 |
||
461 |
copy |
|
462 |
"return a copy of myself |
|
4729 | 463 |
- reimplemented here since symbols are immutable." |
608 | 464 |
|
465 |
^ self |
|
466 |
! |
|
467 |
||
3659 | 468 |
copyReplaceAll:oldElement with:newElement |
469 |
"return a copy of the receiver as a string, where all elements equal to oldElement |
|
470 |
have been replaced by newElement." |
|
471 |
||
6054
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
472 |
"/ 'Warning: #copyReplaceAll:with: will change semantics as defined in ANSI soon' errorPrintCR. |
3659 | 473 |
^ self asString replaceAll:oldElement with:newElement |
474 |
||
475 |
"Created: / 18.7.1998 / 23:03:38 / cg" |
|
476 |
! |
|
477 |
||
6054
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
478 |
copyReplacing:oldElement withObject:newElement |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
479 |
"return a copy of the receiver, where all elements equal to oldElement |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
480 |
have been replaced by newElement. |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
481 |
ANSI version of what used to be #copyReplaceAll:with:" |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
482 |
|
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
483 |
^ self asString replaceAll:oldElement with:newElement |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
484 |
! |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
485 |
|
608 | 486 |
deepCopy |
487 |
"return a copy of myself |
|
4729 | 488 |
- reimplemented here since symbols are immutable." |
608 | 489 |
|
490 |
^ self |
|
491 |
! |
|
492 |
||
493 |
deepCopyUsing:aDictionary |
|
494 |
"return a copy of myself |
|
4729 | 495 |
- reimplemented here since symbols are immutable." |
608 | 496 |
|
497 |
^ self |
|
498 |
! |
|
499 |
||
500 |
shallowCopy |
|
501 |
"return a copy of myself |
|
4729 | 502 |
- reimplemented here since symbols are immutable" |
608 | 503 |
|
504 |
^ self |
|
505 |
! |
|
506 |
||
507 |
simpleDeepCopy |
|
508 |
"return a copy of myself |
|
4729 | 509 |
- reimplemented here since symbols are immutable." |
608 | 510 |
|
511 |
^ self |
|
512 |
! ! |
|
513 |
||
5471
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5434
diff
changeset
|
514 |
!Symbol methodsFor:'encoding'! |
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5434
diff
changeset
|
515 |
|
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5434
diff
changeset
|
516 |
encodeOn:anEncoder with:aParameter |
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5434
diff
changeset
|
517 |
|
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5434
diff
changeset
|
518 |
anEncoder encodeSymbol:self with:aParameter |
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5434
diff
changeset
|
519 |
! ! |
a57eeb01c5ab
General encoding method (#encodeOn:with:)
Stefan Vogel <sv@exept.de>
parents:
5434
diff
changeset
|
520 |
|
608 | 521 |
!Symbol methodsFor:'printing & storing'! |
522 |
||
523 |
displayString |
|
524 |
"return a string for displaying the receiver" |
|
525 |
||
526 |
^ self storeString |
|
527 |
! |
|
528 |
||
529 |
printOn:aStream |
|
4392 | 530 |
"append a user printed representation of the receiver to aStream. |
531 |
The format is suitable for a human - not meant to be read back. |
|
532 |
||
608 | 533 |
In contrast to ST-80, this does return the symbols characters |
534 |
without any leading #. Therefore, you can directly send symbols' |
|
535 |
printStrings to some output device. This is incompatible, but easier |
|
536 |
to use." |
|
537 |
||
538 |
"/ ST-80 behavior: |
|
539 |
||
540 |
"/ self storeOn:aStream |
|
541 |
||
542 |
aStream nextPutAll:self |
|
543 |
! |
|
544 |
||
545 |
printString |
|
546 |
"return a printed representation of the receiver. |
|
547 |
In contrast to ST-80, this does return the symbols characters |
|
548 |
without any leading #. Therefore, you can directly send symbols' |
|
549 |
printStrings to some output device. This is incompatible, but easier |
|
550 |
to use." |
|
551 |
||
552 |
"/ ST-80 behavior: |
|
553 |
"/ ^ self storeString |
|
554 |
||
555 |
^ self asString |
|
556 |
! |
|
557 |
||
558 |
storeOn:aStream |
|
559 |
"store myself on a stream" |
|
560 |
||
561 |
aStream nextPutAll:(self storeString) |
|
562 |
! |
|
563 |
||
564 |
storeString |
|
565 |
"return a String for storing the receiver" |
|
566 |
||
4098 | 567 |
|sz "{Class: SmallInteger }" |
5941
e194c325bee8
storeString fixed for symbols like #'foo:bar'
Claus Gittinger <cg@exept.de>
parents:
5896
diff
changeset
|
568 |
c anyColon| |
1125 | 569 |
|
570 |
(sz := self size) > 0 ifTrue:[ "/ sigh |
|
5185
15a129151b3b
fixed bug in storeString (must duplicate single quotes)
Claus Gittinger <cg@exept.de>
parents:
4987
diff
changeset
|
571 |
(self at:1) isLetter ifTrue:[ |
5941
e194c325bee8
storeString fixed for symbols like #'foo:bar'
Claus Gittinger <cg@exept.de>
parents:
5896
diff
changeset
|
572 |
anyColon := false. |
5185
15a129151b3b
fixed bug in storeString (must duplicate single quotes)
Claus Gittinger <cg@exept.de>
parents:
4987
diff
changeset
|
573 |
2 to:sz do:[:index | |
5941
e194c325bee8
storeString fixed for symbols like #'foo:bar'
Claus Gittinger <cg@exept.de>
parents:
5896
diff
changeset
|
574 |
c := self at:index. |
e194c325bee8
storeString fixed for symbols like #'foo:bar'
Claus Gittinger <cg@exept.de>
parents:
5896
diff
changeset
|
575 |
c == $: ifTrue:[ anyColon := true ]. |
e194c325bee8
storeString fixed for symbols like #'foo:bar'
Claus Gittinger <cg@exept.de>
parents:
5896
diff
changeset
|
576 |
(c isLetterOrDigit |
5185
15a129151b3b
fixed bug in storeString (must duplicate single quotes)
Claus Gittinger <cg@exept.de>
parents:
4987
diff
changeset
|
577 |
or:[c == $: |
15a129151b3b
fixed bug in storeString (must duplicate single quotes)
Claus Gittinger <cg@exept.de>
parents:
4987
diff
changeset
|
578 |
and:[index == sz |
15a129151b3b
fixed bug in storeString (must duplicate single quotes)
Claus Gittinger <cg@exept.de>
parents:
4987
diff
changeset
|
579 |
or:[(self at:(index+1)) isLetterOrDigit]]] |
15a129151b3b
fixed bug in storeString (must duplicate single quotes)
Claus Gittinger <cg@exept.de>
parents:
4987
diff
changeset
|
580 |
) ifFalse:[ |
15a129151b3b
fixed bug in storeString (must duplicate single quotes)
Claus Gittinger <cg@exept.de>
parents:
4987
diff
changeset
|
581 |
^ '#' , super storeString |
15a129151b3b
fixed bug in storeString (must duplicate single quotes)
Claus Gittinger <cg@exept.de>
parents:
4987
diff
changeset
|
582 |
]. |
15a129151b3b
fixed bug in storeString (must duplicate single quotes)
Claus Gittinger <cg@exept.de>
parents:
4987
diff
changeset
|
583 |
]. |
5941
e194c325bee8
storeString fixed for symbols like #'foo:bar'
Claus Gittinger <cg@exept.de>
parents:
5896
diff
changeset
|
584 |
anyColon ifTrue:[ |
e194c325bee8
storeString fixed for symbols like #'foo:bar'
Claus Gittinger <cg@exept.de>
parents:
5896
diff
changeset
|
585 |
self last == $: ifFalse:[ |
e194c325bee8
storeString fixed for symbols like #'foo:bar'
Claus Gittinger <cg@exept.de>
parents:
5896
diff
changeset
|
586 |
^ '#' , super storeString |
e194c325bee8
storeString fixed for symbols like #'foo:bar'
Claus Gittinger <cg@exept.de>
parents:
5896
diff
changeset
|
587 |
] |
e194c325bee8
storeString fixed for symbols like #'foo:bar'
Claus Gittinger <cg@exept.de>
parents:
5896
diff
changeset
|
588 |
]. |
5185
15a129151b3b
fixed bug in storeString (must duplicate single quotes)
Claus Gittinger <cg@exept.de>
parents:
4987
diff
changeset
|
589 |
^ '#' , self |
15a129151b3b
fixed bug in storeString (must duplicate single quotes)
Claus Gittinger <cg@exept.de>
parents:
4987
diff
changeset
|
590 |
] |
608 | 591 |
]. |
5896 | 592 |
^ '#' , super storeString |
3285
bd5827c97b21
Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents:
3086
diff
changeset
|
593 |
|
3286
c6987c5f15a8
Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents:
3285
diff
changeset
|
594 |
" |
5896 | 595 |
#'abc' storeString |
596 |
#'abc:' storeString |
|
597 |
#'abc:def:' storeString |
|
4098 | 598 |
#'abc:def' storeString |
5896 | 599 |
#'abc::def' storeString |
600 |
#'abc &^*' storeString |
|
601 |
#'abcdef::' storeString |
|
602 |
#'hello''world' storeString |
|
603 |
#'' storeString |
|
604 |
#'''' storeString |
|
5185
15a129151b3b
fixed bug in storeString (must duplicate single quotes)
Claus Gittinger <cg@exept.de>
parents:
4987
diff
changeset
|
605 |
#'_hello' storeString |
5941
e194c325bee8
storeString fixed for symbols like #'foo:bar'
Claus Gittinger <cg@exept.de>
parents:
5896
diff
changeset
|
606 |
#'abcdef:' storeString |
e194c325bee8
storeString fixed for symbols like #'foo:bar'
Claus Gittinger <cg@exept.de>
parents:
5896
diff
changeset
|
607 |
#'abc:def:' storeString |
e194c325bee8
storeString fixed for symbols like #'foo:bar'
Claus Gittinger <cg@exept.de>
parents:
5896
diff
changeset
|
608 |
#'abc:def' storeString |
3286
c6987c5f15a8
Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents:
3285
diff
changeset
|
609 |
" |
c6987c5f15a8
Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents:
3285
diff
changeset
|
610 |
|
c6987c5f15a8
Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents:
3285
diff
changeset
|
611 |
"Modified: / 13.2.1998 / 22:06:15 / stefan" |
608 | 612 |
! ! |
613 |
||
614 |
!Symbol methodsFor:'queries'! |
|
615 |
||
4987 | 616 |
isInfix |
617 |
"return true, if the receiver is a binary message selector" |
|
618 |
||
619 |
^ self first isAlphaNumeric not |
|
620 |
||
621 |
" |
|
622 |
#at:put: isInfix |
|
623 |
#at: isInfix |
|
624 |
#+ isInfix |
|
625 |
#size isInfix |
|
626 |
" |
|
627 |
||
628 |
"Created: / 1.11.1997 / 12:34:55 / cg" |
|
629 |
"Modified: / 1.11.1997 / 12:36:37 / cg" |
|
630 |
! |
|
631 |
||
3086 | 632 |
isKeyword |
633 |
"return true, if the receiver is a keyword message selector" |
|
634 |
||
635 |
^ self includes:$: |
|
636 |
||
637 |
" |
|
638 |
#at:put: isKeyword |
|
639 |
#at: isKeyword |
|
640 |
#+ isKeyword |
|
641 |
#size isKeyword |
|
642 |
" |
|
643 |
||
644 |
"Created: / 1.11.1997 / 12:34:55 / cg" |
|
645 |
"Modified: / 1.11.1997 / 12:36:37 / cg" |
|
646 |
! |
|
647 |
||
608 | 648 |
isSymbol |
649 |
"return true, if the receiver is some kind of symbol. |
|
650 |
Since I am a symbol, return always true" |
|
651 |
||
652 |
^ true |
|
653 |
! |
|
654 |
||
655 |
keywords |
|
656 |
"assuming the receiver is a keyword message selector, |
|
657 |
return the individual keywords (i.e. break it up at colons) |
|
658 |
and return these as a collection. |
|
659 |
For binary and unary selectors, the result may be nonsense." |
|
660 |
||
661 |
|coll s part| |
|
662 |
||
663 |
coll := OrderedCollection new. |
|
664 |
s := ReadStream on:self. |
|
665 |
[s atEnd] whileFalse:[ |
|
666 |
part := s through:$:. |
|
667 |
coll add:part |
|
668 |
]. |
|
669 |
^ coll asArray |
|
670 |
||
671 |
" |
|
672 |
#at:put: keywords |
|
673 |
#at: keywords |
|
674 |
#+ keywords |
|
675 |
#size keywords |
|
676 |
" |
|
677 |
! |
|
678 |
||
679 |
species |
|
680 |
"when copying, or concatenating, return instances of this class" |
|
681 |
||
682 |
^ String |
|
683 |
! ! |
|
684 |
||
77 | 685 |
!Symbol methodsFor:'system primitives'! |
686 |
||
687 |
become:anotherObject |
|
688 |
"make all references to the receiver become references to anotherObject |
|
95 | 689 |
and vice-versa. For symbols, some special action is required, to |
690 |
correctly handle a become of the global dictionaries. |
|
77 | 691 |
Anyway: this is very dangerous - mysterous side-effects are to be |
95 | 692 |
expected. |
693 |
||
694 |
Notice: because of the danger here, this method may report an error |
|
159 | 695 |
in future versions" |
77 | 696 |
|
697 |
(Smalltalk includesKey:self) ifTrue:[ |
|
159 | 698 |
super become:anotherObject. |
77 | 699 |
%{ |
159 | 700 |
__rehashSystemDictionaries(); |
77 | 701 |
%}. |
702 |
] ifFalse:[ |
|
159 | 703 |
super become:anotherObject |
77 | 704 |
] |
705 |
! |
|
706 |
||
707 |
becomeNil |
|
708 |
"make all references to the receiver become nil - effectively getting |
|
95 | 709 |
rid of the receiver. For symbols, this is not allowed, if the receiver |
77 | 710 |
is used as a key in some SytemDictionary. |
95 | 711 |
This can be a very dangerous operation - be warned. |
712 |
||
713 |
Notice: because of the danger here, this method may report an error |
|
159 | 714 |
in future versions" |
77 | 715 |
|
716 |
(Smalltalk includesKey:self) ifTrue:[ |
|
159 | 717 |
self primitiveFailed |
77 | 718 |
] ifFalse:[ |
159 | 719 |
super becomeNil |
77 | 720 |
] |
721 |
! ! |
|
722 |
||
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
723 |
!Symbol methodsFor:'tracing'! |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
724 |
|
4682 | 725 |
traceInto:aRequestor level:level from:referrer |
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
726 |
"double dispatch into tracer, passing my type implicitely in the selector" |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
727 |
|
4682 | 728 |
^ aRequestor traceSymbol:self level:level from:referrer |
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
729 |
|
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
730 |
|
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
731 |
! ! |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
732 |
|
632 | 733 |
!Symbol class methodsFor:'documentation'! |
734 |
||
735 |
version |
|
6054
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
736 |
^ '$Header: /cvs/stx/stx/libbasic/Symbol.st,v 1.69 2001-09-26 16:52:14 cg Exp $' |
632 | 737 |
! ! |