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