author | Stefan Vogel <sv@exept.de> |
Fri, 19 Jan 2018 10:40:29 +0100 | |
changeset 22455 | 63a545a97d4a |
parent 22399 | cb8919387ef4 |
child 22516 | 8fe8242e6c72 |
permissions | -rw-r--r-- |
22399 | 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, |
22399 | 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 |
|
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 |
||
1 | 247 |
!Symbol methodsFor:'accessing'! |
248 |
||
249 |
basicAt:index put:something |
|
345 | 250 |
"report an error if an interned symbol is about to be changed |
1219 | 251 |
- interned symbols may NOT be changed. |
252 |
For uninterned symbols, this is allowed." |
|
1 | 253 |
|
77 | 254 |
self knownAsSymbol ifTrue:[ |
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
255 |
self noModificationError. |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
256 |
"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
|
257 |
Raise again non-resumable" |
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
258 |
NoModificationError raiseWith:self errorString:' - interned symbols cannot be changed'. |
77 | 259 |
]. |
260 |
" |
|
261 |
uninterned - allow change |
|
262 |
" |
|
263 |
^ super basicAt:index put:something |
|
1219 | 264 |
|
265 |
"Modified: 19.4.1996 / 11:16:10 / cg" |
|
13423 | 266 |
! |
267 |
||
268 |
nameSpace |
|
16735 | 269 |
"if I have the format of a namespace-selector, |
270 |
retrieve the namespace. Otherwise, return nil. |
|
18619 | 271 |
Also return nil, if that namespace does not exist (in contrast to nameSpacePart). |
272 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
|
16735 | 273 |
They must be of the form :<ns>::<sel>, |
17512 | 274 |
where <ns> is the namespace and <sel> is the raw selector. |
275 |
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
|
276 |
is legal, and this can be checked quickly by just looking at the first character." |
16735 | 277 |
|
17516 | 278 |
|nsPart| |
279 |
||
280 |
nsPart := self nameSpaceAndSelectorParts first. |
|
18619 | 281 |
nsPart isNil ifTrue:[^ nil]. |
17516 | 282 |
^ Smalltalk at:nsPart asSymbol |
16735 | 283 |
|
284 |
" |
|
285 |
#':foo:' nameSpace -> nil (bad format) |
|
286 |
#':foo::bar' nameSpace -> nil (non existing) |
|
17516 | 287 |
#':Tools::bar' nameSpace -> Tools |
18619 | 288 |
#'bar' nameSpace -> nil |
289 |
#'bar:' nameSpace -> nil |
|
16735 | 290 |
" |
13423 | 291 |
|
292 |
"Created: / 20-07-2010 / 10:41:53 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
293 |
! |
|
294 |
||
295 |
nameSpaceAndSelector |
|
16735 | 296 |
"return a two element tuple consisting of the namespace and the raw selector. |
297 |
If I do not have the format of a namespace-selector, or the namespace is non-existing, |
|
298 |
the first element of the returned tuple will be nil. |
|
18619 | 299 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
16735 | 300 |
They must be of the form :<ns>::<sel>, |
17512 | 301 |
where <ns> is the namespace and <sel> is the raw selector. |
302 |
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
|
303 |
is legal, and this can be checked quickly by just looking at the first character." |
16735 | 304 |
|
17516 | 305 |
|parts ns| |
13423 | 306 |
|
307 |
self isNameSpaceSelector ifFalse:[ |
|
18701 | 308 |
^ Array with:nil with:self |
13423 | 309 |
]. |
17516 | 310 |
parts := self nameSpaceAndSelectorParts. |
311 |
ns := Smalltalk at:parts first asSymbol. |
|
312 |
^ Array with:ns with:parts second |
|
13423 | 313 |
|
16735 | 314 |
" |
315 |
#':foo:bar' nameSpaceAndSelector -> #(nil #':foo:bar') |
|
316 |
#':foo::bar' nameSpaceAndSelector -> #(nil #bar) |
|
317 |
#':Tools::foo' nameSpaceAndSelector -> #(Tools (* NameSpace *) #foo) |
|
318 |
" |
|
319 |
||
13423 | 320 |
"Created: / 20-07-2010 / 10:23:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
321 |
! |
|
322 |
||
17516 | 323 |
nameSpaceAndSelectorParts |
324 |
"return a two element tuple consisting of the namespace name and the raw selector. |
|
18701 | 325 |
If I do not have the format of a namespace-selector, |
17516 | 326 |
the first element of the returned tuple will be nil. |
18619 | 327 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
17516 | 328 |
They must be of the form :<ns>::<sel>, |
329 |
where <ns> is the namespace and <sel> is the raw selector. |
|
330 |
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
|
331 |
is legal, and this can be checked quickly by just looking at the first character." |
17516 | 332 |
|
333 |
|nsPart selPart idx| |
|
334 |
||
335 |
self isNameSpaceSelector ifFalse:[ |
|
18701 | 336 |
^ Array with:nil with:self |
17516 | 337 |
]. |
338 |
idx := self indexOf:$: startingAt:3. |
|
339 |
nsPart := self copyFrom:2 to:idx - 1. |
|
340 |
selPart := self copyFrom:idx + 2. |
|
341 |
^ Array with:nsPart with:selPart asSymbol |
|
342 |
||
343 |
" |
|
18619 | 344 |
#':foo:bar' nameSpaceAndSelectorParts -> #(nil #':foo:bar') |
345 |
#':foo:bar' nameSpaceAndSelector -> #(nil #':foo:bar') |
|
346 |
||
347 |
#':foo::bar' nameSpaceAndSelectorParts -> #('foo' #bar) |
|
348 |
#':foo::bar' nameSpaceAndSelector -> #(nil #bar) |
|
349 |
||
350 |
#'bar' nameSpaceAndSelectorParts -> #(nil #bar) |
|
351 |
#'bar' nameSpaceAndSelector -> #(nil #bar) |
|
352 |
||
353 |
#':Tools::foo' nameSpaceAndSelectorParts -> #('Tools' #foo) |
|
354 |
#':Tools::foo' nameSpaceAndSelector -> #(Tools (* NameSpace *) #foo) |
|
17516 | 355 |
" |
356 |
||
357 |
"Created: / 20-07-2010 / 10:23:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
358 |
! |
|
359 |
||
360 |
nameSpacePart |
|
361 |
"if I have the format of a namespace-selector, |
|
362 |
retrieve the namespace name. Otherwise, return nil. |
|
18619 | 363 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
17516 | 364 |
They must be of the form :<ns>::<sel>, |
365 |
where <ns> is the namespace and <sel> is the raw selector. |
|
366 |
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
|
367 |
is legal, and this can be checked quickly by just looking at the first character." |
17516 | 368 |
|
369 |
^ self nameSpaceAndSelectorParts first. |
|
370 |
||
371 |
" |
|
372 |
#':foo:' nameSpacePart -> nil (bad format) |
|
373 |
#':foo::bar' nameSpacePart -> 'foo' |
|
374 |
#':Tools::bar' nameSpacePart -> 'Tools' |
|
375 |
" |
|
376 |
! |
|
377 |
||
13423 | 378 |
selector |
17512 | 379 |
<resource: #obsolete> |
380 |
||
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
381 |
"if I have the format of a namespace-selector, retrieve the raw selector. |
17512 | 382 |
Otherwise, return myself. |
383 |
Namespace selectors have a special, fix defined format, which is also known in the VM. |
|
16735 | 384 |
They must be of the form :<ns>::<sel>, |
17512 | 385 |
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
|
386 |
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
|
387 |
because almost every other selector is legal, |
19714 | 388 |
and this can be checked quickly in the VM, by just looking at the first character." |
17512 | 389 |
|
390 |
self obsoleteMethodWarning:'use selectorWithoutNameSpace'. |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
391 |
^ self selectorWithoutNameSpace |
17512 | 392 |
! |
393 |
||
394 |
selectorWithoutNameSpace |
|
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. |
|
398 |
They must be of the form :<ns>::<sel>, |
|
399 |
where <ns> is the namespace and <sel> is the raw selector. |
|
400 |
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
|
401 |
is legal, and this can be checked quickly by just looking at the first character." |
16735 | 402 |
|
18619 | 403 |
^ self nameSpaceAndSelectorParts second |
16735 | 404 |
|
405 |
" |
|
17516 | 406 |
#':foo:' selectorWithoutNameSpace -> #':foo:' (bad format) |
407 |
#':foo::bar' selectorWithoutNameSpace -> bar |
|
408 |
#':Tools::bar' selectorWithoutNameSpace -> bar |
|
16735 | 409 |
" |
13423 | 410 |
|
411 |
"Created: / 20-07-2010 / 10:41:32 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1 | 412 |
! ! |
413 |
||
13423 | 414 |
|
608 | 415 |
!Symbol methodsFor:'comparing'! |
159 | 416 |
|
608 | 417 |
= something |
418 |
"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
|
419 |
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
|
420 |
(which can to be compared using #==). |
608 | 421 |
If the argument is a symbol, we use a quick pointer compare, instead of |
422 |
the inherited value compare." |
|
13 | 423 |
|
608 | 424 |
%{ /* NOCONTEXT */ |
18701 | 425 |
#ifdef __SCHTEAM__ |
426 |
if (something.isSymbol()) { |
|
427 |
return context._RETURN ( self == something ? STObject.True : STObject.False ); |
|
428 |
} |
|
429 |
if (something.isSTString()) { |
|
430 |
return context._RETURN ( something.isStringEqual(self) ? STObject.True : STObject.False ); |
|
431 |
} |
|
432 |
if (something == STObject.Nil) { |
|
433 |
return context._RETURN_false ( ); |
|
434 |
} |
|
435 |
#else |
|
608 | 436 |
OBJ cls; |
13 | 437 |
|
18360
21b8e3adff85
can avoid a string compare sometimes when comparing symbols
Claus Gittinger <cg@exept.de>
parents:
17516
diff
changeset
|
438 |
if (something == self) RETURN(true); |
608 | 439 |
if (! __isNonNilObject(something)) RETURN(false); |
440 |
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
|
441 |
RETURN (false); |
608 | 442 |
} |
14658 | 443 |
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
|
444 |
RETURN (strcmp(__stringVal(self), __stringVal(something)) == 0 ? true : false); |
345 | 445 |
} |
18701 | 446 |
#endif |
345 | 447 |
%}. |
608 | 448 |
"fall back; could be a TwoByteString, or a collection of Characters" |
1 | 449 |
|
608 | 450 |
^ super = something |
427 | 451 |
! |
452 |
||
356 | 453 |
identityHash |
454 |
"interned symbols can return a better hash key" |
|
455 |
||
13881 | 456 |
%{ /* NOCONTEXT */ |
457 |
||
16891
93560afff48f
oops - hashes should fit into a smallInt
Claus Gittinger <cg@exept.de>
parents:
16890
diff
changeset
|
458 |
REGISTER unsigned int val; // yes: only 32 bit |
356 | 459 |
|
14651 | 460 |
if (__qIsSymbol(self)) { |
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
461 |
val = __GET_HASH(self); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
462 |
/* |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
463 |
* 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
|
464 |
* 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
|
465 |
* 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
|
466 |
* after it got a hashKey assigned. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
467 |
*/ |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
468 |
if (val == 0) { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
469 |
extern unsigned int __symbolHash(char *); |
14651 | 470 |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
471 |
val = __symbolHash(__stringVal(self)); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
472 |
// make sure, it fits into a smallInt |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
473 |
val = (val ^ (val >> 30)) & 0x3FFFFFFF; |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
474 |
} else { |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
475 |
val = __MAKE_HASH__(val); |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
476 |
} |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
477 |
RETURN ( __mkSmallInteger(val) ); |
14651 | 478 |
} |
356 | 479 |
%}. |
14651 | 480 |
|
481 |
^ super identityHash. |
|
3985 | 482 |
|
483 |
" |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
484 |
|hashColl hashSet| |
3985 | 485 |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
486 |
hashColl := OrderedCollection new:20000. |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
487 |
Symbol allInstancesDo:[:instance | |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
488 |
hashColl add:instance identityHash |
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 |
hashSet := hashColl asSet. |
3985 | 491 |
|
20706
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
492 |
Transcript showCR:'Symbols: ', hashColl size printString, |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
493 |
' unique hash keys: ', hashSet size printString, |
009b8269bd08
we have class based exceptions - use them
Claus Gittinger <cg@exept.de>
parents:
19714
diff
changeset
|
494 |
' collisions:', (hashColl size - hashSet size) printString. |
3985 | 495 |
" |
13881 | 496 |
|
497 |
"Modified (comment): / 26-12-2011 / 14:32:10 / cg" |
|
370 | 498 |
! |
499 |
||
500 |
~= something |
|
501 |
"return true, if the receiver and argument do not consist of the same characters. |
|
11859 | 502 |
Redefined here, for more efficient #~= comparison of symbols |
370 | 503 |
(which ought to be compared using #~~). |
504 |
If the argument is a symbol, we use a quick pointer compare, instead of |
|
505 |
the inherited value compare." |
|
506 |
||
507 |
%{ /* NOCONTEXT */ |
|
18701 | 508 |
#ifdef __SCHTEAM__ |
509 |
if (something.isSymbol()) { |
|
510 |
return context._RETURN ( self == something ? STObject.False : STObject.True ); |
|
511 |
} |
|
512 |
if (something.isSTString()) { |
|
513 |
return context._RETURN ( something.isStringEqual(self) ? STObject.False : STObject.True ); |
|
514 |
} |
|
515 |
if (something == STObject.Nil) { |
|
516 |
return context._RETURN_true ( ); |
|
517 |
} |
|
518 |
#else |
|
370 | 519 |
OBJ cls; |
520 |
||
379 | 521 |
if (! __isNonNilObject(something)) RETURN(true); /* cannot be equal */ |
370 | 522 |
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
|
523 |
RETURN (self == something ? false : true); |
370 | 524 |
} |
14658 | 525 |
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
|
526 |
RETURN (strcmp(__stringVal(self), __stringVal(something)) == 0 ? false : true); |
370 | 527 |
} |
18701 | 528 |
#endif |
370 | 529 |
%}. |
530 |
"fall back; could be a TwoByteString, or a collection of Characters" |
|
531 |
||
532 |
^ super ~= something |
|
356 | 533 |
! ! |
534 |
||
608 | 535 |
!Symbol methodsFor:'converting'! |
536 |
||
537 |
asString |
|
538 |
"return a string with printname taken from mine" |
|
539 |
||
540 |
%{ /* NOCONTEXT */ |
|
541 |
OBJ s; |
|
542 |
||
2565 | 543 |
s = __MKSTRING_ST(self); |
608 | 544 |
if (s != nil) { |
11859 | 545 |
RETURN (s); |
608 | 546 |
} |
547 |
%}. |
|
5434 | 548 |
^ (String new:(self size)) |
11859 | 549 |
replaceFrom:1 with:self startingAt:1 |
608 | 550 |
! |
551 |
||
552 |
asSymbol |
|
19467 | 553 |
"Return a unique symbol with the name taken from the receiver's characters. |
608 | 554 |
Since I am a symbol - just return myself" |
555 |
||
556 |
^ self |
|
557 |
! |
|
558 |
||
559 |
asSymbolIfInterned |
|
17185 | 560 |
"If a symbol with the receiver's characters is already known, return it. Otherwise, return nil. |
608 | 561 |
Since I am a symbol - just return myself" |
562 |
||
563 |
^ self |
|
21017 | 564 |
! |
565 |
||
566 |
asSymbolIfInternedOrSelf |
|
567 |
^ self |
|
608 | 568 |
! ! |
569 |
||
570 |
!Symbol methodsFor:'copying'! |
|
571 |
||
572 |
copy |
|
573 |
"return a copy of myself |
|
4729 | 574 |
- reimplemented here since symbols are immutable." |
608 | 575 |
|
576 |
^ self |
|
577 |
! |
|
578 |
||
3659 | 579 |
copyReplaceAll:oldElement with:newElement |
580 |
"return a copy of the receiver as a string, where all elements equal to oldElement |
|
581 |
have been replaced by newElement." |
|
582 |
||
6054
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
583 |
"/ 'Warning: #copyReplaceAll:with: will change semantics as defined in ANSI soon' errorPrintCR. |
3659 | 584 |
^ self asString replaceAll:oldElement with:newElement |
585 |
||
586 |
"Created: / 18.7.1998 / 23:03:38 / cg" |
|
587 |
! |
|
588 |
||
6054
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
589 |
copyReplacing:oldElement withObject:newElement |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
590 |
"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
|
591 |
have been replaced by newElement. |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
592 |
ANSI version of what used to be #copyReplaceAll:with:" |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
593 |
|
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
594 |
^ self asString replaceAll:oldElement with:newElement |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
595 |
! |
7719f857af51
added #copyReplacing:withObject: (ANSI)
Claus Gittinger <cg@exept.de>
parents:
6001
diff
changeset
|
596 |
|
608 | 597 |
deepCopy |
598 |
"return a copy of myself |
|
4729 | 599 |
- reimplemented here since symbols are immutable." |
608 | 600 |
|
601 |
^ self |
|
602 |
! |
|
603 |
||
10950 | 604 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
8383 | 605 |
"return a deep copy of myself |
4729 | 606 |
- reimplemented here since symbols are immutable." |
608 | 607 |
|
608 |
^ self |
|
609 |
! |
|
610 |
||
611 |
shallowCopy |
|
612 |
"return a copy of myself |
|
10581 | 613 |
- reimplemented here since symbols are immutable and unique, |
614 |
so we return the receiver." |
|
608 | 615 |
|
616 |
^ self |
|
10581 | 617 |
|
618 |
"Modified: / 31-05-2007 / 15:32:30 / cg" |
|
608 | 619 |
! |
620 |
||
621 |
simpleDeepCopy |
|
622 |
"return a copy of myself |
|
4729 | 623 |
- reimplemented here since symbols are immutable." |
608 | 624 |
|
625 |
^ self |
|
626 |
! ! |
|
627 |
||
16154 | 628 |
!Symbol methodsFor:'evaluation'! |
629 |
||
22399 | 630 |
value:el |
19605 | 631 |
"this is sent by collection enumeration methods, |
632 |
if a symbol is given instead of a block as loop-block argument" |
|
633 |
||
634 |
^ el perform:self. |
|
635 |
||
636 |
" |
|
637 |
this allows us to say: |
|
638 |
||
639 |
#(1 2 3 4) do: #printCR |
|
640 |
#(1 -2 -3 4) collect: #abs |
|
22399 | 641 |
#(1 2 3 4) select: #even |
642 |
'hello' collect: #rot13 |
|
19605 | 643 |
someCollection collect: #withoutSeparators |
644 |
" |
|
645 |
! |
|
646 |
||
16154 | 647 |
value: el value:arg |
16890
8fa6938075c2
refer to the VM's internal symbol hash algorithm,
Claus Gittinger <cg@exept.de>
parents:
16774
diff
changeset
|
648 |
"this is sent by collection enumeration methods, |
16155 | 649 |
if a symbol is given instead of a block as loop-block argument" |
16154 | 650 |
|
651 |
^ el perform:self with:arg. |
|
652 |
||
653 |
" |
|
654 |
this allows us to say: |
|
655 |
||
656 |
#(1 2 3 4) with:#(10 20 30 40) collect: #+ |
|
657 |
" |
|
658 |
! ! |
|
659 |
||
14651 | 660 |
|
608 | 661 |
!Symbol methodsFor:'printing & storing'! |
662 |
||
663 |
printOn:aStream |
|
4392 | 664 |
"append a user printed representation of the receiver to aStream. |
665 |
The format is suitable for a human - not meant to be read back. |
|
666 |
||
608 | 667 |
In contrast to ST-80, this does return the symbols characters |
668 |
without any leading #. Therefore, you can directly send symbols' |
|
669 |
printStrings to some output device. This is incompatible, but easier |
|
670 |
to use." |
|
671 |
||
672 |
"/ ST-80 behavior: |
|
673 |
||
674 |
"/ self storeOn:aStream |
|
675 |
||
676 |
aStream nextPutAll:self |
|
677 |
! |
|
678 |
||
679 |
printString |
|
680 |
"return a printed representation of the receiver. |
|
681 |
In contrast to ST-80, this does return the symbols characters |
|
682 |
without any leading #. Therefore, you can directly send symbols' |
|
683 |
printStrings to some output device. This is incompatible, but easier |
|
684 |
to use." |
|
685 |
||
686 |
"/ ST-80 behavior: |
|
687 |
"/ ^ self storeString |
|
688 |
||
689 |
^ self asString |
|
690 |
! |
|
691 |
||
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
692 |
storeArrayElementOn:aStream |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
693 |
"store myself on a stream. |
8368 | 694 |
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
|
695 |
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
|
696 |
|
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
697 |
|storeString| |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
698 |
|
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
699 |
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
|
700 |
(self == #true or:[self == #false or:[self == #nil or:[(storeString at:2) == $']]]) ifTrue:[ |
11859 | 701 |
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
|
702 |
] ifFalse:[ |
11859 | 703 |
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
|
704 |
]. |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
705 |
! |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
706 |
|
608 | 707 |
storeOn:aStream |
708 |
"store myself on a stream" |
|
709 |
||
710 |
aStream nextPutAll:(self storeString) |
|
711 |
! |
|
712 |
||
713 |
storeString |
|
714 |
"return a String for storing the receiver" |
|
715 |
||
11859 | 716 |
|sz "{Class: SmallInteger }" |
5941
e194c325bee8
storeString fixed for symbols like #'foo:bar'
Claus Gittinger <cg@exept.de>
parents:
5896
diff
changeset
|
717 |
c anyColon| |
1125 | 718 |
|
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7350
diff
changeset
|
719 |
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
|
720 |
(sz ~~ 0 and:[(self at:1) isLetter]) ifTrue:[ |
11859 | 721 |
anyColon := false. |
722 |
2 to:sz do:[:index | |
|
723 |
c := self at:index. |
|
724 |
c == $: ifTrue:[ |
|
725 |
(index == sz or:[(self at:(index+1)) isLetterOrDigit]) ifFalse:[ |
|
726 |
^ '#' , super storeString. |
|
727 |
]. |
|
728 |
anyColon := true. |
|
729 |
] ifFalse:[ |
|
730 |
c isLetterOrDigit ifFalse:[ |
|
731 |
^ '#' , super storeString |
|
732 |
]. |
|
733 |
]. |
|
734 |
]. |
|
735 |
"no colon in symbol or symbol ends with a colon" |
|
736 |
(anyColon and:[c ~~ $:]) ifFalse:[ |
|
737 |
^ '#' , self |
|
738 |
]. |
|
608 | 739 |
]. |
5896 | 740 |
^ '#' , super storeString |
3285
bd5827c97b21
Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents:
3086
diff
changeset
|
741 |
|
3286
c6987c5f15a8
Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents:
3285
diff
changeset
|
742 |
" |
11859 | 743 |
#'abc' storeString |
744 |
#'abc:' storeString |
|
745 |
#'abc:def:' storeString |
|
746 |
#'abc:def' storeString |
|
747 |
#'abc::def' storeString |
|
748 |
#'abc &^*' storeString |
|
749 |
#'abcdef::' storeString |
|
750 |
#'hello''world' storeString |
|
751 |
#'' storeString |
|
752 |
#'''' storeString |
|
753 |
#'_hello' storeString |
|
754 |
#'123' storeString |
|
3286
c6987c5f15a8
Do not need quotes in #storeString when a symbol contains a ':'.
Stefan Vogel <sv@exept.de>
parents:
3285
diff
changeset
|
755 |
" |
608 | 756 |
! ! |
757 |
||
758 |
!Symbol methodsFor:'queries'! |
|
759 |
||
760 |
species |
|
761 |
"when copying, or concatenating, return instances of this class" |
|
762 |
||
763 |
^ String |
|
764 |
! ! |
|
765 |
||
77 | 766 |
!Symbol methodsFor:'system primitives'! |
767 |
||
768 |
become:anotherObject |
|
769 |
"make all references to the receiver become references to anotherObject |
|
95 | 770 |
and vice-versa. For symbols, some special action is required, to |
771 |
correctly handle a become of the global dictionaries. |
|
77 | 772 |
Anyway: this is very dangerous - mysterous side-effects are to be |
95 | 773 |
expected. |
774 |
||
775 |
Notice: because of the danger here, this method may report an error |
|
159 | 776 |
in future versions" |
77 | 777 |
|
778 |
(Smalltalk includesKey:self) ifTrue:[ |
|
159 | 779 |
super become:anotherObject. |
77 | 780 |
%{ |
159 | 781 |
__rehashSystemDictionaries(); |
77 | 782 |
%}. |
783 |
] ifFalse:[ |
|
159 | 784 |
super become:anotherObject |
77 | 785 |
] |
786 |
! |
|
787 |
||
788 |
becomeNil |
|
789 |
"make all references to the receiver become nil - effectively getting |
|
95 | 790 |
rid of the receiver. For symbols, this is not allowed, if the receiver |
7765 | 791 |
is used as a key in some SystemDictionary. |
95 | 792 |
This can be a very dangerous operation - be warned. |
793 |
||
794 |
Notice: because of the danger here, this method may report an error |
|
11859 | 795 |
in future versions" |
77 | 796 |
|
797 |
(Smalltalk includesKey:self) ifTrue:[ |
|
11859 | 798 |
self primitiveFailed |
77 | 799 |
] ifFalse:[ |
11859 | 800 |
super becomeNil |
77 | 801 |
] |
13388 | 802 |
! |
803 |
||
804 |
grow:newSize |
|
13389 | 805 |
"blocked" |
13388 | 806 |
|
13389 | 807 |
self fixedSizeError |
13388 | 808 |
|
809 |
"Created: / 20-06-2011 / 14:57:36 / cg" |
|
13389 | 810 |
! |
811 |
||
812 |
removeAll |
|
813 |
"blocked" |
|
814 |
||
815 |
self fixedSizeError |
|
816 |
||
817 |
"Created: / 20-06-2011 / 14:59:02 / cg" |
|
77 | 818 |
! ! |
819 |
||
16774 | 820 |
!Symbol methodsFor:'testing'! |
821 |
||
822 |
isSingleByteString |
|
823 |
"returns true only for strings and immutable strings. |
|
824 |
Must replace foo isMemberOf:String and foo class == String" |
|
825 |
||
826 |
^ false |
|
21127 | 827 |
! |
828 |
||
829 |
isSymbol |
|
830 |
"return true, if the receiver is some kind of symbol. |
|
831 |
Since I am a symbol, return always true" |
|
832 |
||
833 |
^ true |
|
16774 | 834 |
! ! |
835 |
||
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
836 |
!Symbol methodsFor:'tracing'! |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
837 |
|
4682 | 838 |
traceInto:aRequestor level:level from:referrer |
4651
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
839 |
"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
|
840 |
|
4682 | 841 |
^ aRequestor traceSymbol:self level:level from:referrer |
4651
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 |
! ! |
18a6ac30b36f
added #hasSharedInstances & tracing support
Claus Gittinger <cg@exept.de>
parents:
4530
diff
changeset
|
845 |
|
8395
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
846 |
!Symbol methodsFor:'visiting'! |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
847 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
848 |
acceptVisitor:aVisitor with:aParameter |
16735 | 849 |
"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
|
850 |
|
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
851 |
^ aVisitor visitSymbol:self with:aParameter |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
852 |
! ! |
6bd97113cb4c
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
853 |
|
632 | 854 |
!Symbol class methodsFor:'documentation'! |
855 |
||
16155 | 856 |
version |
18619 | 857 |
^ '$Header$' |
16155 | 858 |
! |
859 |
||
13423 | 860 |
version_CVS |
18619 | 861 |
^ '$Header$' |
12473
828e275ddf8b
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
11859
diff
changeset
|
862 |
! |
828e275ddf8b
change __isString() to __isStringLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
11859
diff
changeset
|
863 |
|
13423 | 864 |
version_SVN |
15524 | 865 |
^ '$ Id: Symbol.st 10648 2011-06-23 15:55:10Z vranyj1 $' |
632 | 866 |
! ! |
21017 | 867 |