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