author | Claus Gittinger <cg@exept.de> |
Tue, 09 Jul 2019 20:55:17 +0200 | |
changeset 24417 | 03b083548da2 |
parent 24241 | 7fcbc1f15829 |
child 25030 | a74b4e68af6d |
permissions | -rw-r--r-- |
23849 | 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, |
23849 | 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 |
]. |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
135 |
^ AllocationFailure raise. |
608 | 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 |
|
23838 | 154 |
|
155 |
!Symbol class methodsFor:'Javascript support'! |
|
156 |
||
157 |
for:argument |
|
158 |
"Symbol.for(string) is the same as ST's string asSymbol" |
|
159 |
||
160 |
^ argument asSymbol |
|
161 |
||
162 |
"Created: / 05-03-2019 / 09:55:55 / Claus Gittinger" |
|
163 |
! ! |
|
164 |
||
165 |
||
1 | 166 |
!Symbol class methodsFor:'queries'! |
167 |
||
608 | 168 |
findInterned:aString |
169 |
"for ST-80 compatibility - if the argument, aString is known |
|
170 |
as Symbol, return this symbol. Otherwise return nil." |
|
171 |
||
172 |
^ aString asSymbolIfInterned |
|
173 |
! |
|
174 |
||
175 |
hasInterned:aString |
|
176 |
"return true, if the argument, aString is known as Symbol; |
|
177 |
false otherwise" |
|
178 |
||
179 |
^ aString knownAsSymbol |
|
180 |
! |
|
181 |
||
1 | 182 |
hasInterned:aString ifTrue:trueBlock |
183 |
"for ST-80 compatibility - if the argument, aString is known |
|
184 |
as Symbol, evaluate the block with the corresponding symbol |
|
185 |
as argument and return true; otherwise return false" |
|
186 |
||
275 | 187 |
|sym| |
188 |
||
189 |
(sym := aString asSymbolIfInterned) notNil ifTrue:[ |
|
190 |
trueBlock value:sym. |
|
159 | 191 |
^ true |
1 | 192 |
]. |
193 |
^ false |
|
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
194 |
! |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
195 |
|
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
196 |
hasSharedInstances |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
197 |
"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
|
198 |
with the same value are identical. |
4654 | 199 |
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
|
200 |
|
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
201 |
^ true |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
202 |
|
1 | 203 |
! ! |
204 |
||
13423 | 205 |
|
23838 | 206 |
|
11819 | 207 |
!Symbol methodsFor:'Compatibility-Squeak'! |
208 |
||
13690 | 209 |
precedence |
210 |
"the precedence in an expression; 0 is highest; |
|
23918 | 211 |
unary < binary < keyword" |
13690 | 212 |
|
23918 | 213 |
self size == 0 |
214 |
ifTrue: [^ 0]. |
|
13690 | 215 |
self first isLetter |
23918 | 216 |
ifFalse: [^ 2]. |
13690 | 217 |
self last = $: |
23918 | 218 |
ifTrue: [^ 3]. |
13690 | 219 |
^ 1 |
220 |
||
221 |
" |
|
13882
187a02bd5c99
OUCH: back to old hash; crashes Certificate compare in expecco (WHY??????=
Claus Gittinger <cg@exept.de>
parents:
13881
diff
changeset
|
222 |
self assert:(#foo precedence < #+ precedence). |
13690 | 223 |
self assert:(#+ precedence < #key: precedence). |
224 |
self assert:(#foo precedence < #key: precedence). |
|
225 |
" |
|
226 |
||
227 |
"Created: / 12-09-2011 / 14:53:54 / cg" |
|
23918 | 228 |
"Modified: / 15-03-2019 / 13:35:53 / Stefan Vogel" |
11819 | 229 |
! ! |
230 |
||
7261 | 231 |
!Symbol methodsFor:'Compatibility-VW'! |
7153 | 232 |
|
233 |
<< catalogID |
|
234 |
"create and return a new UserMessage, with the receiver as key, |
|
235 |
and the argument as cataglogID. |
|
236 |
VW compatibility." |
|
237 |
||
238 |
^ UserMessage key:self catalogID:catalogID |
|
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 |
||
247 |
>> aString |
|
248 |
"create and return a new UserMessage, with the receiver as key, |
|
249 |
and the argument as defaultString. |
|
250 |
VW compatibility." |
|
251 |
||
11859 | 252 |
^ UserMessage key:self defaultString:aString |
7153 | 253 |
|
254 |
" |
|
11859 | 255 |
(#theFooMessage << #myMessages) |
256 |
(#theFooMessage << #myMessages >> 'cannot read subclass of metaclass') |
|
257 |
(#theFooMessage >> 'cannot read subclass of metaclass') |
|
7153 | 258 |
" |
259 |
! ! |
|
260 |
||
1 | 261 |
!Symbol methodsFor:'accessing'! |
262 |
||
263 |
basicAt:index put:something |
|
345 | 264 |
"report an error if an interned symbol is about to be changed |
1219 | 265 |
- interned symbols may NOT be changed. |
266 |
For uninterned symbols, this is allowed." |
|
1 | 267 |
|
77 | 268 |
self knownAsSymbol ifTrue:[ |
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
269 |
self noModificationError. |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
270 |
"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
|
271 |
Raise again non-resumable" |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
272 |
NoModificationError raiseWith:self errorString:' - interned symbols cannot be changed'. |
77 | 273 |
]. |
274 |
" |
|
275 |
uninterned - allow change |
|
276 |
" |
|
277 |
^ super basicAt:index put:something |
|
1219 | 278 |
|
279 |
"Modified: 19.4.1996 / 11:16:10 / cg" |
|
13423 | 280 |
! |
281 |
||
282 |
nameSpace |
|
16735 | 283 |
"if I have the format of a namespace-selector, |
284 |
retrieve the namespace. Otherwise, return nil. |
|
18619 | 285 |
Also return nil, if that namespace does not exist (in contrast to nameSpacePart). |
286 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
|
16735 | 287 |
They must be of the form :<ns>::<sel>, |
17512 | 288 |
where <ns> is the namespace and <sel> is the raw selector. |
289 |
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
|
290 |
is legal, and this can be checked quickly by just looking at the first character." |
16735 | 291 |
|
17516 | 292 |
|nsPart| |
293 |
||
294 |
nsPart := self nameSpaceAndSelectorParts first. |
|
18619 | 295 |
nsPart isNil ifTrue:[^ nil]. |
17516 | 296 |
^ Smalltalk at:nsPart asSymbol |
16735 | 297 |
|
298 |
" |
|
299 |
#':foo:' nameSpace -> nil (bad format) |
|
300 |
#':foo::bar' nameSpace -> nil (non existing) |
|
17516 | 301 |
#':Tools::bar' nameSpace -> Tools |
18619 | 302 |
#'bar' nameSpace -> nil |
303 |
#'bar:' nameSpace -> nil |
|
16735 | 304 |
" |
13423 | 305 |
|
306 |
"Created: / 20-07-2010 / 10:41:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
307 |
! |
|
308 |
||
309 |
nameSpaceAndSelector |
|
16735 | 310 |
"return a two element tuple consisting of the namespace and the raw selector. |
311 |
If I do not have the format of a namespace-selector, or the namespace is non-existing, |
|
312 |
the first element of the returned tuple will be nil. |
|
18619 | 313 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
16735 | 314 |
They must be of the form :<ns>::<sel>, |
17512 | 315 |
where <ns> is the namespace and <sel> is the raw selector. |
316 |
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
|
317 |
is legal, and this can be checked quickly by just looking at the first character." |
16735 | 318 |
|
17516 | 319 |
|parts ns| |
13423 | 320 |
|
321 |
self isNameSpaceSelector ifFalse:[ |
|
18701 | 322 |
^ Array with:nil with:self |
13423 | 323 |
]. |
17516 | 324 |
parts := self nameSpaceAndSelectorParts. |
325 |
ns := Smalltalk at:parts first asSymbol. |
|
326 |
^ Array with:ns with:parts second |
|
13423 | 327 |
|
16735 | 328 |
" |
329 |
#':foo:bar' nameSpaceAndSelector -> #(nil #':foo:bar') |
|
330 |
#':foo::bar' nameSpaceAndSelector -> #(nil #bar) |
|
331 |
#':Tools::foo' nameSpaceAndSelector -> #(Tools (* NameSpace *) #foo) |
|
332 |
" |
|
333 |
||
13423 | 334 |
"Created: / 20-07-2010 / 10:23:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
335 |
! |
|
336 |
||
17516 | 337 |
nameSpaceAndSelectorParts |
338 |
"return a two element tuple consisting of the namespace name and the raw selector. |
|
18701 | 339 |
If I do not have the format of a namespace-selector, |
17516 | 340 |
the first element of the returned tuple will be nil. |
18619 | 341 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
17516 | 342 |
They must be of the form :<ns>::<sel>, |
343 |
where <ns> is the namespace and <sel> is the raw selector. |
|
344 |
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
|
345 |
is legal, and this can be checked quickly by just looking at the first character." |
17516 | 346 |
|
347 |
|nsPart selPart idx| |
|
348 |
||
349 |
self isNameSpaceSelector ifFalse:[ |
|
18701 | 350 |
^ Array with:nil with:self |
17516 | 351 |
]. |
352 |
idx := self indexOf:$: startingAt:3. |
|
353 |
nsPart := self copyFrom:2 to:idx - 1. |
|
354 |
selPart := self copyFrom:idx + 2. |
|
355 |
^ Array with:nsPart with:selPart asSymbol |
|
356 |
||
357 |
" |
|
18619 | 358 |
#':foo:bar' nameSpaceAndSelectorParts -> #(nil #':foo:bar') |
359 |
#':foo:bar' nameSpaceAndSelector -> #(nil #':foo:bar') |
|
360 |
||
361 |
#':foo::bar' nameSpaceAndSelectorParts -> #('foo' #bar) |
|
362 |
#':foo::bar' nameSpaceAndSelector -> #(nil #bar) |
|
363 |
||
364 |
#'bar' nameSpaceAndSelectorParts -> #(nil #bar) |
|
365 |
#'bar' nameSpaceAndSelector -> #(nil #bar) |
|
366 |
||
367 |
#':Tools::foo' nameSpaceAndSelectorParts -> #('Tools' #foo) |
|
368 |
#':Tools::foo' nameSpaceAndSelector -> #(Tools (* NameSpace *) #foo) |
|
17516 | 369 |
" |
370 |
||
371 |
"Created: / 20-07-2010 / 10:23:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
372 |
! |
|
373 |
||
374 |
nameSpacePart |
|
375 |
"if I have the format of a namespace-selector, |
|
376 |
retrieve the namespace name. Otherwise, return nil. |
|
18619 | 377 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
17516 | 378 |
They must be of the form :<ns>::<sel>, |
379 |
where <ns> is the namespace and <sel> is the raw selector. |
|
380 |
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
|
381 |
is legal, and this can be checked quickly by just looking at the first character." |
17516 | 382 |
|
383 |
^ self nameSpaceAndSelectorParts first. |
|
384 |
||
385 |
" |
|
386 |
#':foo:' nameSpacePart -> nil (bad format) |
|
387 |
#':foo::bar' nameSpacePart -> 'foo' |
|
388 |
#':Tools::bar' nameSpacePart -> 'Tools' |
|
389 |
" |
|
390 |
! |
|
391 |
||
13423 | 392 |
selector |
17512 | 393 |
<resource: #obsolete> |
394 |
||
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
395 |
"if I have the format of a namespace-selector, retrieve the raw selector. |
17512 | 396 |
Otherwise, return myself. |
397 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
|
16735 | 398 |
They must be of the form :<ns>::<sel>, |
17512 | 399 |
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
|
400 |
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
|
401 |
because almost every other selector is legal, |
19714 | 402 |
and this can be checked quickly in the VM, by just looking at the first character." |
17512 | 403 |
|
404 |
self obsoleteMethodWarning:'use selectorWithoutNameSpace'. |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
405 |
^ self selectorWithoutNameSpace |
17512 | 406 |
! |
407 |
||
408 |
selectorWithoutNameSpace |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
409 |
"if I have the format of a namespace-selector, retrieve the raw selector. |
17512 | 410 |
Otherwise, return myself. |
411 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
|
412 |
They must be of the form :<ns>::<sel>, |
|
413 |
where <ns> is the namespace and <sel> is the raw selector. |
|
414 |
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
|
415 |
is legal, and this can be checked quickly by just looking at the first character." |
16735 | 416 |
|
24121 | 417 |
|idx| |
418 |
||
419 |
self isNameSpaceSelector ifFalse:[ |
|
420 |
"avoid copy" |
|
421 |
^ self |
|
422 |
]. |
|
423 |
idx := self indexOf:$: startingAt:3. |
|
424 |
^ self copyFrom:idx + 2. |
|
16735 | 425 |
|
426 |
" |
|
17516 | 427 |
#':foo:' selectorWithoutNameSpace -> #':foo:' (bad format) |
24121 | 428 |
#':foo::bar' selectorWithoutNameSpace -> #bar |
429 |
#':Tools::bar' selectorWithoutNameSpace -> #bar |
|
16735 | 430 |
" |
13423 | 431 |
|
432 |
"Created: / 20-07-2010 / 10:41:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
24121 | 433 |
"Modified (format): / 08-05-2019 / 14:47:24 / Stefan Vogel" |
1 | 434 |
! ! |
435 |
||
13423 | 436 |
|
608 | 437 |
!Symbol methodsFor:'comparing'! |
159 | 438 |
|
608 | 439 |
= something |
440 |
"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
|
441 |
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
|
442 |
(which can to be compared using #==). |
608 | 443 |
If the argument is a symbol, we use a quick pointer compare, instead of |
444 |
the inherited value compare." |
|
13 | 445 |
|
608 | 446 |
%{ /* NOCONTEXT */ |
18701 | 447 |
#ifdef __SCHTEAM__ |
448 |
if (something.isSymbol()) { |
|
449 |
return context._RETURN ( self == something ? STObject.True : STObject.False ); |
|
450 |
} |
|
451 |
if (something.isSTString()) { |
|
452 |
return context._RETURN ( something.isStringEqual(self) ? STObject.True : STObject.False ); |
|
453 |
} |
|
454 |
if (something == STObject.Nil) { |
|
455 |
return context._RETURN_false ( ); |
|
456 |
} |
|
457 |
#else |
|
608 | 458 |
OBJ cls; |
13 | 459 |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
460 |
if (something == self) RETURN(true); |
608 | 461 |
if (! __isNonNilObject(something)) RETURN(false); |
462 |
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
|
463 |
RETURN (false); |
608 | 464 |
} |
14658 | 465 |
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
|
466 |
RETURN (strcmp(__stringVal(self), __stringVal(something)) == 0 ? true : false); |
345 | 467 |
} |
18701 | 468 |
#endif |
345 | 469 |
%}. |
608 | 470 |
"fall back; could be a TwoByteString, or a collection of Characters" |
1 | 471 |
|
608 | 472 |
^ super = something |
427 | 473 |
! |
474 |
||
356 | 475 |
identityHash |
476 |
"interned symbols can return a better hash key" |
|
477 |
||
13881 | 478 |
%{ /* NOCONTEXT */ |
479 |
||
16891
93560afff48f
oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents:
16890
diff
changeset
|
480 |
REGISTER unsigned int val; // yes: only 32 bit |
356 | 481 |
|
14651 | 482 |
if (__qIsSymbol(self)) { |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
483 |
val = __GET_HASH(self); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
484 |
/* |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
485 |
* 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
|
486 |
* 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
|
487 |
* 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
|
488 |
* after it got a hashKey assigned. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
489 |
*/ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
490 |
if (val == 0) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
491 |
extern unsigned int __symbolHash(char *); |
14651 | 492 |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
493 |
val = __symbolHash(__stringVal(self)); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
494 |
// make sure, it fits into a smallInt |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
495 |
val = (val ^ (val >> 30)) & 0x3FFFFFFF; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
496 |
} else { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
497 |
val = __MAKE_HASH__(val); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
498 |
} |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
499 |
RETURN ( __mkSmallInteger(val) ); |
14651 | 500 |
} |
356 | 501 |
%}. |
14651 | 502 |
|
503 |
^ super identityHash. |
|
3985 | 504 |
|
505 |
" |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
506 |
|hashColl hashSet| |
3985 | 507 |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
508 |
hashColl := OrderedCollection new:20000. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
509 |
Symbol allInstancesDo:[:instance | |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
510 |
hashColl add:instance identityHash |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
511 |
]. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
512 |
hashSet := hashColl asSet. |
3985 | 513 |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
514 |
Transcript showCR:'Symbols: ', hashColl size printString, |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
515 |
' unique hash keys: ', hashSet size printString, |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
516 |
' collisions:', (hashColl size - hashSet size) printString. |
3985 | 517 |
" |
13881 | 518 |
|
519 |
"Modified (comment): / 26-12-2011 / 14:32:10 / cg" |
|
370 | 520 |
! |
521 |
||
522 |
~= something |
|
523 |
"return true, if the receiver and argument do not consist of the same characters. |
|
11859 | 524 |
Redefined here, for more efficient #~= comparison of symbols |
370 | 525 |
(which ought to be compared using #~~). |
526 |
If the argument is a symbol, we use a quick pointer compare, instead of |
|
527 |
the inherited value compare." |
|
528 |
||
529 |
%{ /* NOCONTEXT */ |
|
18701 | 530 |
#ifdef __SCHTEAM__ |
531 |
if (something.isSymbol()) { |
|
532 |
return context._RETURN ( self == something ? STObject.False : STObject.True ); |
|
533 |
} |
|
534 |
if (something.isSTString()) { |
|
535 |
return context._RETURN ( something.isStringEqual(self) ? STObject.False : STObject.True ); |
|
536 |
} |
|
537 |
if (something == STObject.Nil) { |
|
538 |
return context._RETURN_true ( ); |
|
539 |
} |
|
540 |
#else |
|
370 | 541 |
OBJ cls; |
542 |
||
379 | 543 |
if (! __isNonNilObject(something)) RETURN(true); /* cannot be equal */ |
370 | 544 |
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
|
545 |
RETURN (self == something ? false : true); |
370 | 546 |
} |
14658 | 547 |
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
|
548 |
RETURN (strcmp(__stringVal(self), __stringVal(something)) == 0 ? false : true); |
370 | 549 |
} |
18701 | 550 |
#endif |
370 | 551 |
%}. |
552 |
"fall back; could be a TwoByteString, or a collection of Characters" |
|
553 |
||
554 |
^ super ~= something |
|
356 | 555 |
! ! |
556 |
||
608 | 557 |
!Symbol methodsFor:'converting'! |
558 |
||
23412 | 559 |
asClass |
560 |
"return the class named after me" |
|
561 |
||
562 |
^ (Smalltalk classNamed:self) ifNil:[ NotFoundError raiseErrorString:'No such class: ',self ] |
|
563 |
||
564 |
" |
|
565 |
#Array asClass |
|
566 |
#Foo asClass |
|
567 |
" |
|
568 |
! |
|
569 |
||
23413 | 570 |
asClassIfAbsent:exceptionValue |
571 |
"return the class named after me" |
|
572 |
||
573 |
^ (Smalltalk classNamed:self) ifNil:exceptionValue |
|
574 |
||
575 |
" |
|
576 |
#Array asClassIfAbsent:123 |
|
577 |
#Foo asClassIfAbsent:123 |
|
578 |
" |
|
579 |
||
580 |
"Created: / 10-10-2018 / 00:41:21 / Claus Gittinger" |
|
581 |
! |
|
582 |
||
23920 | 583 |
asImmutableCollection |
584 |
"I am immutable" |
|
585 |
||
586 |
^ self |
|
587 |
||
588 |
"Created: / 15-03-2019 / 13:50:55 / Stefan Vogel" |
|
589 |
! |
|
590 |
||
591 |
asImmutableString |
|
592 |
"I am immutable" |
|
593 |
||
594 |
^ self |
|
595 |
||
596 |
"Created: / 15-03-2019 / 13:50:44 / Stefan Vogel" |
|
597 |
! |
|
598 |
||
608 | 599 |
asString |
600 |
"return a string with printname taken from mine" |
|
601 |
||
602 |
%{ /* NOCONTEXT */ |
|
603 |
OBJ s; |
|
604 |
||
2565 | 605 |
s = __MKSTRING_ST(self); |
608 | 606 |
if (s != nil) { |
11859 | 607 |
RETURN (s); |
608 | 608 |
} |
609 |
%}. |
|
5434 | 610 |
^ (String new:(self size)) |
11859 | 611 |
replaceFrom:1 with:self startingAt:1 |
608 | 612 |
! |
613 |
||
614 |
asSymbol |
|
19467 | 615 |
"Return a unique symbol with the name taken from the receiver's characters. |
608 | 616 |
Since I am a symbol - just return myself" |
617 |
||
618 |
^ self |
|
619 |
! |
|
620 |
||
621 |
asSymbolIfInterned |
|
17185 | 622 |
"If a symbol with the receiver's characters is already known, return it. Otherwise, return nil. |
608 | 623 |
Since I am a symbol - just return myself" |
624 |
||
625 |
^ self |
|
21017 | 626 |
! |
627 |
||
628 |
asSymbolIfInternedOrSelf |
|
629 |
^ self |
|
23918 | 630 |
! |
631 |
||
632 |
beImmutable |
|
633 |
"I am already immutable" |
|
634 |
||
635 |
^ self |
|
636 |
||
637 |
"Created: / 15-03-2019 / 12:46:53 / Stefan Vogel" |
|
608 | 638 |
! ! |
639 |
||
640 |
!Symbol methodsFor:'copying'! |
|
641 |
||
642 |
copy |
|
643 |
"return a copy of myself |
|
4729 | 644 |
- reimplemented here since symbols are immutable." |
608 | 645 |
|
646 |
^ self |
|
647 |
! |
|
648 |
||
649 |
deepCopy |
|
650 |
"return a copy of myself |
|
4729 | 651 |
- reimplemented here since symbols are immutable." |
608 | 652 |
|
653 |
^ self |
|
654 |
! |
|
655 |
||
10950 | 656 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
8383 | 657 |
"return a deep copy of myself |
4729 | 658 |
- reimplemented here since symbols are immutable." |
608 | 659 |
|
660 |
^ self |
|
661 |
! |
|
662 |
||
663 |
shallowCopy |
|
664 |
"return a copy of myself |
|
10581 | 665 |
- reimplemented here since symbols are immutable and unique, |
666 |
so we return the receiver." |
|
608 | 667 |
|
668 |
^ self |
|
10581 | 669 |
|
670 |
"Modified: / 31-05-2007 / 15:32:30 / cg" |
|
608 | 671 |
! |
672 |
||
673 |
simpleDeepCopy |
|
674 |
"return a copy of myself |
|
4729 | 675 |
- reimplemented here since symbols are immutable." |
608 | 676 |
|
677 |
^ self |
|
678 |
! ! |
|
679 |
||
16154 | 680 |
!Symbol methodsFor:'evaluation'! |
681 |
||
23849 | 682 |
value:anObject |
683 |
"this is sent by collection enumeration methods, |
|
684 |
if a symbol is given instead of a block as loop-block argument" |
|
685 |
||
23918 | 686 |
^ anObject perform:self. |
687 |
||
688 |
" |
|
24241 | 689 |
this enables the elegant construct: |
690 |
#(1 2 3 4 5 6 7) collect:#negated |
|
691 |
||
692 |
but also, as a side effect, this ugly thing (if the arg understands the receiver): |
|
693 |
#negated value:#(1 2 3 4 5 6 7) |
|
23918 | 694 |
" |
23849 | 695 |
|
696 |
"Created: / 07-03-2019 / 17:11:23 / Stefan Vogel" |
|
23918 | 697 |
"Modified (format): / 15-03-2019 / 13:39:32 / Stefan Vogel" |
24241 | 698 |
"Modified (comment): / 30-05-2019 / 15:01:59 / Claus Gittinger" |
23849 | 699 |
! |
700 |
||
16154 | 701 |
value: el value:arg |
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
702 |
"this is sent by collection enumeration methods, |
16155 | 703 |
if a symbol is given instead of a block as loop-block argument" |
16154 | 704 |
|
705 |
^ el perform:self with:arg. |
|
706 |
||
707 |
" |
|
708 |
this allows us to say: |
|
709 |
||
710 |
#(1 2 3 4) with:#(10 20 30 40) collect: #+ |
|
711 |
" |
|
712 |
! ! |
|
713 |
||
14651 | 714 |
|
608 | 715 |
!Symbol methodsFor:'printing & storing'! |
716 |
||
22516 | 717 |
displayString |
718 |
"return a string used when displaying the receiver in a view; |
|
719 |
for example an Inspector. This is usually the same as printString, |
|
720 |
but sometimes redefined for a better look." |
|
721 |
||
22517 | 722 |
^ self storeString |
22516 | 723 |
|
724 |
"Created: / 31-01-2018 / 09:01:45 / stefan" |
|
725 |
! |
|
726 |
||
608 | 727 |
printOn:aStream |
4392 | 728 |
"append a user printed representation of the receiver to aStream. |
729 |
The format is suitable for a human - not meant to be read back. |
|
730 |
||
608 | 731 |
In contrast to ST-80, this does return the symbols characters |
732 |
without any leading #. Therefore, you can directly send symbols' |
|
733 |
printStrings to some output device. This is incompatible, but easier |
|
734 |
to use." |
|
735 |
||
736 |
"/ ST-80 behavior: |
|
737 |
||
738 |
"/ self storeOn:aStream |
|
739 |
||
740 |
aStream nextPutAll:self |
|
741 |
! |
|
742 |
||
743 |
printString |
|
744 |
"return a printed representation of the receiver. |
|
745 |
In contrast to ST-80, this does return the symbols characters |
|
746 |
without any leading #. Therefore, you can directly send symbols' |
|
747 |
printStrings to some output device. This is incompatible, but easier |
|
748 |
to use." |
|
749 |
||
750 |
"/ ST-80 behavior: |
|
751 |
"/ ^ self storeString |
|
752 |
||
753 |
^ self asString |
|
754 |
! |
|
755 |
||
756 |
storeOn:aStream |
|
757 |
"store myself on a stream" |
|
758 |
||
759 |
aStream nextPutAll:(self storeString) |
|
760 |
! |
|
761 |
||
762 |
storeString |
|
763 |
"return a String for storing the receiver" |
|
764 |
||
11859 | 765 |
|sz "{Class: SmallInteger }" |
5941
e194c325bee8
storeString fixed for symbols like #'foo:bar'
Claus Gittinger <cg@exept.de>
parents:
5896
diff
changeset
|
766 |
c anyColon| |
1125 | 767 |
|
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
768 |
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
|
769 |
(sz ~~ 0 and:[(self at:1) isLetter]) ifTrue:[ |
11859 | 770 |
anyColon := false. |
771 |
2 to:sz do:[:index | |
|
772 |
c := self at:index. |
|
773 |
c == $: ifTrue:[ |
|
774 |
(index == sz or:[(self at:(index+1)) isLetterOrDigit]) ifFalse:[ |
|
775 |
^ '#' , super storeString. |
|
776 |
]. |
|
777 |
anyColon := true. |
|
778 |
] ifFalse:[ |
|
779 |
c isLetterOrDigit ifFalse:[ |
|
780 |
^ '#' , super storeString |
|
781 |
]. |
|
782 |
]. |
|
783 |
]. |
|
784 |
"no colon in symbol or symbol ends with a colon" |
|
785 |
(anyColon and:[c ~~ $:]) ifFalse:[ |
|
786 |
^ '#' , self |
|
787 |
]. |
|
608 | 788 |
]. |
5896 | 789 |
^ '#' , super storeString |
3285
bd5827c97b21
Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents:
3086
diff
changeset
|
790 |
|
3286
c6987c5f15a8
Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents:
3285
diff
changeset
|
791 |
" |
11859 | 792 |
#'abc' storeString |
793 |
#'abc:' storeString |
|
794 |
#'abc:def:' storeString |
|
795 |
#'abc:def' storeString |
|
796 |
#'abc::def' storeString |
|
797 |
#'abc &^*' storeString |
|
798 |
#'abcdef::' storeString |
|
799 |
#'hello''world' storeString |
|
800 |
#'' storeString |
|
801 |
#'''' storeString |
|
802 |
#'_hello' storeString |
|
803 |
#'123' storeString |
|
3286
c6987c5f15a8
Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents:
3285
diff
changeset
|
804 |
" |
608 | 805 |
! ! |
806 |
||
24026 | 807 |
!Symbol methodsFor:'private array element printing'! |
808 |
||
809 |
displayArrayElementOn:aStream |
|
810 |
"Display myself as an Array element on a stream. |
|
811 |
I am displayed as an array element, so the '#' may be omitted sometimes. |
|
812 |
Take care for special symbols" |
|
813 |
||
814 |
self storeArrayElementOn:aStream. "storeString is same as printString" |
|
815 |
||
816 |
"Created: / 29-03-2019 / 12:00:50 / stefan" |
|
817 |
! |
|
818 |
||
819 |
printArrayElementOn:aStream |
|
820 |
"Print myself as an Array element on a stream. |
|
821 |
I am printed as an array element, so the '#' may be omitted sometimes. |
|
822 |
Take care for special symbols" |
|
823 |
||
824 |
self storeArrayElementOn:aStream. "storeString is same as printString" |
|
825 |
||
826 |
"Created: / 29-03-2019 / 11:56:25 / stefan" |
|
827 |
! |
|
828 |
||
829 |
storeArrayElementOn:aStream |
|
830 |
"store myself on a stream. |
|
831 |
I am stored as an array element, so the '#' may be omitted sometimes. |
|
832 |
Take care for special symbols" |
|
833 |
||
834 |
|storeString| |
|
835 |
||
836 |
storeString := self storeString. |
|
837 |
(self == #true or:[self == #false or:[self == #nil or:[(storeString at:2) == $']]]) ifTrue:[ |
|
838 |
aStream nextPutAll:storeString. |
|
839 |
] ifFalse:[ |
|
840 |
aStream nextPutAll:self. |
|
841 |
]. |
|
842 |
! ! |
|
843 |
||
608 | 844 |
!Symbol methodsFor:'queries'! |
845 |
||
846 |
species |
|
847 |
"when copying, or concatenating, return instances of this class" |
|
848 |
||
849 |
^ String |
|
850 |
! ! |
|
851 |
||
77 | 852 |
!Symbol methodsFor:'system primitives'! |
853 |
||
854 |
become:anotherObject |
|
855 |
"make all references to the receiver become references to anotherObject |
|
95 | 856 |
and vice-versa. For symbols, some special action is required, to |
857 |
correctly handle a become of the global dictionaries. |
|
77 | 858 |
Anyway: this is very dangerous - mysterous side-effects are to be |
95 | 859 |
expected. |
860 |
||
861 |
Notice: because of the danger here, this method may report an error |
|
159 | 862 |
in future versions" |
77 | 863 |
|
864 |
(Smalltalk includesKey:self) ifTrue:[ |
|
159 | 865 |
super become:anotherObject. |
77 | 866 |
%{ |
159 | 867 |
__rehashSystemDictionaries(); |
77 | 868 |
%}. |
869 |
] ifFalse:[ |
|
159 | 870 |
super become:anotherObject |
77 | 871 |
] |
872 |
! |
|
873 |
||
874 |
becomeNil |
|
875 |
"make all references to the receiver become nil - effectively getting |
|
95 | 876 |
rid of the receiver. For symbols, this is not allowed, if the receiver |
7765 | 877 |
is used as a key in some SystemDictionary. |
95 | 878 |
This can be a very dangerous operation - be warned. |
879 |
||
880 |
Notice: because of the danger here, this method may report an error |
|
23918 | 881 |
in future versions" |
77 | 882 |
|
883 |
(Smalltalk includesKey:self) ifTrue:[ |
|
23918 | 884 |
self noModificationError. |
77 | 885 |
] ifFalse:[ |
23918 | 886 |
super becomeNil |
77 | 887 |
] |
23918 | 888 |
|
889 |
"Modified: / 15-03-2019 / 13:30:41 / Stefan Vogel" |
|
13388 | 890 |
! |
891 |
||
892 |
grow:newSize |
|
13389 | 893 |
"blocked" |
13388 | 894 |
|
13389 | 895 |
self fixedSizeError |
13388 | 896 |
|
897 |
"Created: / 20-06-2011 / 14:57:36 / cg" |
|
13389 | 898 |
! |
899 |
||
900 |
removeAll |
|
901 |
"blocked" |
|
902 |
||
903 |
self fixedSizeError |
|
904 |
||
905 |
"Created: / 20-06-2011 / 14:59:02 / cg" |
|
77 | 906 |
! ! |
907 |
||
16774 | 908 |
!Symbol methodsFor:'testing'! |
909 |
||
23920 | 910 |
isImmutable |
911 |
"return true, if the receiver is immutable. |
|
912 |
Since I am a symbol, return always true" |
|
913 |
||
914 |
^ true |
|
915 |
||
916 |
"Created: / 15-03-2019 / 13:58:56 / Stefan Vogel" |
|
917 |
! |
|
918 |
||
16774 | 919 |
isSingleByteString |
920 |
"returns true only for strings and immutable strings. |
|
921 |
Must replace foo isMemberOf:String and foo class == String" |
|
922 |
||
923 |
^ false |
|
21127 | 924 |
! |
925 |
||
926 |
isSymbol |
|
927 |
"return true, if the receiver is some kind of symbol. |
|
928 |
Since I am a symbol, return always true" |
|
929 |
||
930 |
^ true |
|
16774 | 931 |
! ! |
932 |
||
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
933 |
!Symbol methodsFor:'tracing'! |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
934 |
|
4682 | 935 |
traceInto:aRequestor level:level from:referrer |
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
936 |
"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
|
937 |
|
4682 | 938 |
^ aRequestor traceSymbol:self level:level from:referrer |
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
939 |
|
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
940 |
|
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
941 |
! ! |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
942 |
|
8395
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
943 |
!Symbol methodsFor:'visiting'! |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
944 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
945 |
acceptVisitor:aVisitor with:aParameter |
16735 | 946 |
"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
|
947 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
948 |
^ aVisitor visitSymbol:self with:aParameter |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
949 |
! ! |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
950 |
|
632 | 951 |
!Symbol class methodsFor:'documentation'! |
952 |
||
16155 | 953 |
version |
18619 | 954 |
^ '$Header$' |
16155 | 955 |
! |
956 |
||
13423 | 957 |
version_CVS |
18619 | 958 |
^ '$Header$' |
12473
828e275ddf8b
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
11859
diff
changeset
|
959 |
! |
828e275ddf8b
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
11859
diff
changeset
|
960 |
|
13423 | 961 |
version_SVN |
15524 | 962 |
^ '$ Id: Symbol.st 10648 2011-06-23 15:55:10Z vranyj1 $' |
632 | 963 |
! ! |
21017 | 964 |