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