Symbol.st
author Claus Gittinger <cg@exept.de>
Sat, 06 Apr 1996 15:23:05 +0200
changeset 1138 993e6ffdbf51
parent 1134 7cb7cd7ebeb8
child 1219 054f7eff0c30
permissions -rw-r--r--
removed external decls for VM functions (should look for more)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1988 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
String subclass:#Symbol
1020
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    14
	instanceVariableNames:''
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    15
	classVariableNames:''
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    16
	poolDictionaries:''
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    17
	category:'Collections-Text'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    19
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    20
!Symbol class methodsFor:'documentation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    21
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    22
copyright
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    23
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    24
 COPYRIGHT (c) 1988 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
    25
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    26
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    27
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    28
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    30
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    31
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    32
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    33
"
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    34
!
81dacba7a63a *** empty log message ***
claus
parents: 77
diff changeset
    35
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    36
documentation
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    37
"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    38
    Symbols represent unique strings - every symbol with same printString
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    39
    exists exactly once in the system; Symbols are used for selectors, global
345
claus
parents: 329
diff changeset
    40
    variable-keys etc. Symbols can also be used to represent things which are
claus
parents: 329
diff changeset
    41
    enumeration type values in other programming languages (since symbols are
370
claus
parents: 356
diff changeset
    42
    created at compile time, comparing them using == is a fast pointer compare).
345
claus
parents: 329
diff changeset
    43
claus
parents: 329
diff changeset
    44
    A symbol may not change its characters - i.e. it is constant over its lifetime.
claus
parents: 329
diff changeset
    45
    Other than that, symbols behave much like strings.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    46
"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    47
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    48
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    49
!Symbol class methodsFor:'instance creation'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    50
62
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    51
basicNew:size
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    52
    "redefined to return a string instead of a symbol -
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    53
     this allows all copy methods inherited from String to
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    54
     return strings containing the symbols characters.
1020
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    55
     Real symbols are only created with #intern: or #asSymbol."
62
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    56
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    57
    ^ String new:size
1020
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    58
c4de0381c847 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 999
diff changeset
    59
    "Modified: 26.2.1996 / 12:51:38 / cg"
62
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    60
!
e1b4369c61fb *** empty log message ***
claus
parents: 13
diff changeset
    61
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    62
fromString:aString
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    63
    "same as intern: for Symbol, but may be used to create interned instances
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    64
     of subclasses.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    65
     Notice: this fails, if you try to intern an instance of a subclass, AND
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    66
     a symbol with the same name already exists. In this case, the original
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    67
     symbol is returned. To use it for enum-type symbols, make certain, that the
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    68
     names are unique (for example by including the classes name as a prefix-string)."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    69
267
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
    70
    |sym len|
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    71
267
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
    72
    sym := aString asSymbolIfInterned.
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
    73
    sym notNil ifTrue:[
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
    74
	^ sym
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    75
    ].
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    76
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    77
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    78
     create a new uninterned instance first
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    79
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    80
    len := aString size.
267
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
    81
    sym := super basicNew:len.
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
    82
    sym replaceFrom:1 to:len with:aString.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    83
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    84
    "now, intern it"
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    85
%{
329
claus
parents: 314
diff changeset
    86
    sym = __INTERNSYMBOL(sym, (OBJ *)0, __context);
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    87
%}.
267
54bcd20b369d *** empty log message ***
claus
parents: 252
diff changeset
    88
    ^ sym
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    89
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
    90
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
    91
intern:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
    92
    "return a unique symbol with printname taken from the String-argument"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
    93
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
    94
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
    95
    OBJ newSymbol;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
    96
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
    97
    if (__isSymbol(aString)) {
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
    98
	RETURN (aString);
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
    99
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   100
    if (__isString(aString)) {
1134
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1125
diff changeset
   101
	newSymbol = __MKSYMBOL(__stringVal(aString), (OBJ *)0, SENDER);
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   102
	if (newSymbol != nil) {
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   103
	    RETURN (newSymbol);
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   104
	}
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   105
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   106
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   107
    aString class ~~ String ifTrue:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   108
	"/
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   109
	"/ only allowed to intern strings
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   110
	"/
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   111
	^ self mustBeString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   112
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   113
    ^ ObjectMemory allocationFailureSignal raise.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   114
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   115
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   116
internCharacter:aCharacter
a27a279701f8 Initial revision
claus
parents:
diff changeset
   117
    "return a unique symbol with printname taken from the Character-argument"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   118
a27a279701f8 Initial revision
claus
parents:
diff changeset
   119
    ^ self intern:(aCharacter asString)
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   120
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   121
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   122
new:size
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   123
    "redefined to return a string instead of a symbol -
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   124
     this allows all copy methods inherited from String to
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   125
     return strings containing the symbols characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   126
     Real symbols are only created with intern: or asSymbol."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   127
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   128
    ^ String new:size
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   129
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   130
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   131
!Symbol class methodsFor:'binary storage'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   132
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   133
binaryDefinitionFrom: stream manager: manager
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   134
    ^ self intern: (super binaryDefinitionFrom: stream manager: manager)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   135
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   136
a27a279701f8 Initial revision
claus
parents:
diff changeset
   137
!Symbol class methodsFor:'queries'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   138
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   139
findInterned:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   140
    "for ST-80 compatibility - if the argument, aString is known
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   141
     as Symbol, return this symbol. Otherwise return nil."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   142
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   143
    ^ aString asSymbolIfInterned
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   144
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   145
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   146
hasInterned:aString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   147
    "return true, if the argument, aString is known as Symbol;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   148
     false otherwise"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   149
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   150
    ^ aString knownAsSymbol
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   151
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   152
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   153
hasInterned:aString ifTrue:trueBlock
a27a279701f8 Initial revision
claus
parents:
diff changeset
   154
    "for ST-80 compatibility - if the argument, aString is known
a27a279701f8 Initial revision
claus
parents:
diff changeset
   155
     as Symbol, evaluate the block with the corresponding symbol
a27a279701f8 Initial revision
claus
parents:
diff changeset
   156
     as argument and return true; otherwise return false"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   157
275
a76029ddaa98 *** empty log message ***
claus
parents: 268
diff changeset
   158
    |sym|
a76029ddaa98 *** empty log message ***
claus
parents: 268
diff changeset
   159
a76029ddaa98 *** empty log message ***
claus
parents: 268
diff changeset
   160
    (sym := aString asSymbolIfInterned) notNil ifTrue:[
a76029ddaa98 *** empty log message ***
claus
parents: 268
diff changeset
   161
	trueBlock value:sym.
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   162
	^ true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   163
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   164
    ^ false
a27a279701f8 Initial revision
claus
parents:
diff changeset
   165
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   166
a27a279701f8 Initial revision
claus
parents:
diff changeset
   167
!Symbol methodsFor:'accessing'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   168
a27a279701f8 Initial revision
claus
parents:
diff changeset
   169
basicAt:index put:something
345
claus
parents: 329
diff changeset
   170
    "report an error if an interned symbol is about to be changed
claus
parents: 329
diff changeset
   171
     - interned symbols may NOT be changed."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   172
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   173
    self knownAsSymbol ifTrue:[
345
claus
parents: 329
diff changeset
   174
	self error:'interned symbols may not be changed'.
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   175
	^ something
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   176
    ].
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   177
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   178
     uninterned - allow change
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   179
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   180
    ^ super basicAt:index put:something
252
   181
!
   182
   183
byteAt:index put:value
   184
    "report an error if interned - interned symbols may not be changed."
   185
   186
    ^ self basicAt:index put:(value asCharacter)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   187
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   188
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   189
!Symbol methodsFor:'comparing'!
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   190
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   191
= something
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   192
    "return true, if the receiver and argument consist of the same characters.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   193
     Redefined here, for more efficient #= comparison of symbols 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   194
     (which ought to be compared using #==).
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   195
     If the argument is a symbol, we use a quick pointer compare, instead of
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   196
     the inherited value compare."
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   197
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   198
%{   /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   199
    OBJ cls;
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   200
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   201
    if (! __isNonNilObject(something)) RETURN(false);
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   202
    if ((cls = __qClass(something)) == Symbol) {
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   203
	RETURN (self == something ? true : false);
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   204
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   205
    if (cls == String) {
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   206
	RETURN (strcmp(__stringVal(self), __stringVal(something)) == 0 ? true : false); 
345
claus
parents: 329
diff changeset
   207
    }
claus
parents: 329
diff changeset
   208
%}.
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   209
    "fall back; could be a TwoByteString, or a collection of Characters"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   210
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   211
    ^ super = something
427
claus
parents: 384
diff changeset
   212
!
claus
parents: 384
diff changeset
   213
356
claus
parents: 345
diff changeset
   214
identityHash
claus
parents: 345
diff changeset
   215
    "interned symbols can return a better hash key"
claus
parents: 345
diff changeset
   216
claus
parents: 345
diff changeset
   217
%{  /* NOCONTEXT */
claus
parents: 345
diff changeset
   218
claus
parents: 345
diff changeset
   219
    REGISTER int g, val;
claus
parents: 345
diff changeset
   220
    REGISTER unsigned char *cp, *cp0;
claus
parents: 345
diff changeset
   221
    int l;
claus
parents: 345
diff changeset
   222
claus
parents: 345
diff changeset
   223
    if (__Class(self) == Symbol) {
375
claus
parents: 370
diff changeset
   224
	val = __GET_HASH(self);
356
claus
parents: 345
diff changeset
   225
	/*
claus
parents: 345
diff changeset
   226
	 * only do it, if I have no standard hash key
375
claus
parents: 370
diff changeset
   227
	 * assigned (which can only happen due to a #become:,
claus
parents: 370
diff changeset
   228
	 * or by creating a symbol uninterned, and interning it
claus
parents: 370
diff changeset
   229
	 * after it got a hashKey assigned.
356
claus
parents: 345
diff changeset
   230
	 */
claus
parents: 345
diff changeset
   231
	if (val == 0) {
1134
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1125
diff changeset
   232
	    cp = __stringVal(self);
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1125
diff changeset
   233
	    l = __stringSize(self);
356
claus
parents: 345
diff changeset
   234
        
claus
parents: 345
diff changeset
   235
	    /*
claus
parents: 345
diff changeset
   236
	     * this is the dragon-book algorithm
claus
parents: 345
diff changeset
   237
	     *
claus
parents: 345
diff changeset
   238
	     * the algorithm hashes pretty good:
claus
parents: 345
diff changeset
   239
	     *   with (currently) 9963 symbols in the system,
claus
parents: 345
diff changeset
   240
	     *   there are only about 200 hash key collisions.
claus
parents: 345
diff changeset
   241
	     *   where the maximum collision count in these 200
claus
parents: 345
diff changeset
   242
	     *   is 3. This means, that in most situations,
claus
parents: 345
diff changeset
   243
	     *   a single probe will find the right element in
claus
parents: 345
diff changeset
   244
	     *   a symbol-hashed collection.
claus
parents: 345
diff changeset
   245
	     */
claus
parents: 345
diff changeset
   246
	    val = 0;
claus
parents: 345
diff changeset
   247
	    for (cp0 = cp, cp += l - 1; cp >= cp0; cp--) {
claus
parents: 345
diff changeset
   248
		val = (val << 5) + (*cp & 0x1F);
claus
parents: 345
diff changeset
   249
		if (g = (val & 0x3E000000))
claus
parents: 345
diff changeset
   250
		    val ^= g >> 25 /* 23 */ /* 25 */;
claus
parents: 345
diff changeset
   251
		val &= 0x3FFFFFFF;
claus
parents: 345
diff changeset
   252
	    }
claus
parents: 345
diff changeset
   253
claus
parents: 345
diff changeset
   254
	    if (l) {
claus
parents: 345
diff changeset
   255
		l |= 1; 
claus
parents: 345
diff changeset
   256
		val = (val * l) & 0x3FFFFFFF;
claus
parents: 345
diff changeset
   257
	    }
375
claus
parents: 370
diff changeset
   258
	} else {
claus
parents: 370
diff changeset
   259
	    val <<= __HASH_SHIFT__;
356
claus
parents: 345
diff changeset
   260
	}
1134
7cb7cd7ebeb8 underline cleanup
Claus Gittinger <cg@exept.de>
parents: 1125
diff changeset
   261
	RETURN ( __MKSMALLINT(val) );
356
claus
parents: 345
diff changeset
   262
     }
claus
parents: 345
diff changeset
   263
%}.
claus
parents: 345
diff changeset
   264
     ^ super identityHash
370
claus
parents: 356
diff changeset
   265
!
claus
parents: 356
diff changeset
   266
claus
parents: 356
diff changeset
   267
~= something
claus
parents: 356
diff changeset
   268
    "return true, if the receiver and argument do not consist of the same characters.
claus
parents: 356
diff changeset
   269
     Redefined here, for more efficient #~= comparison of symbols 
claus
parents: 356
diff changeset
   270
     (which ought to be compared using #~~).
claus
parents: 356
diff changeset
   271
     If the argument is a symbol, we use a quick pointer compare, instead of
claus
parents: 356
diff changeset
   272
     the inherited value compare."
claus
parents: 356
diff changeset
   273
claus
parents: 356
diff changeset
   274
%{   /* NOCONTEXT */
claus
parents: 356
diff changeset
   275
    OBJ cls;
claus
parents: 356
diff changeset
   276
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   277
    if (! __isNonNilObject(something)) RETURN(true);    /* cannot be equal */
370
claus
parents: 356
diff changeset
   278
    if ((cls = __qClass(something)) == Symbol) {
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   279
	RETURN (self == something ? false : true);
370
claus
parents: 356
diff changeset
   280
    }
claus
parents: 356
diff changeset
   281
    if (cls == String) {
379
5b5a130ccd09 revision added
claus
parents: 375
diff changeset
   282
	RETURN (strcmp(__stringVal(self), __stringVal(something)) == 0 ? false : true);
370
claus
parents: 356
diff changeset
   283
    }
claus
parents: 356
diff changeset
   284
%}.
claus
parents: 356
diff changeset
   285
    "fall back; could be a TwoByteString, or a collection of Characters"
claus
parents: 356
diff changeset
   286
claus
parents: 356
diff changeset
   287
    ^ super ~= something
356
claus
parents: 345
diff changeset
   288
! !
claus
parents: 345
diff changeset
   289
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   290
!Symbol methodsFor:'converting'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   291
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   292
asString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   293
    "return a string with printname taken from mine"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   294
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   295
%{  /* NOCONTEXT */
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   296
    OBJ s;
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   297
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   298
    s = __MKSTRING_ST(self COMMA_SND);
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   299
    if (s != nil) {
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   300
	RETURN (s);
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   301
    }
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   302
%}.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   303
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   304
     memory allocation (for the new string) failed.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   305
     When we arrive here, there was no memory, even after a garbage collect.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   306
     This means, that the VM wanted to get some more memory from the
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   307
     OS, which was not kind enough to give it.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   308
     Bad luck - you should increase the swap space on your machine,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   309
     or if you have set a soft memoryLimit, increase it.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   310
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   311
    ^ ObjectMemory allocationFailureSignal raise.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   312
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   313
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   314
asSymbol
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   315
    "return the receiver as a symbol.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   316
     Since I am a symbol - just return myself"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   317
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   318
    ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   319
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   320
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   321
asSymbolIfInterned
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   322
    "return the receiver as a symbol if there is one.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   323
     Since I am a symbol - just return myself"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   324
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   325
    ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   326
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   327
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   328
knownAsSymbol 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   329
    "return true if the receiver is known as a symbol.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   330
     Since I am a symbol - just return true"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   331
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   332
    ^ true
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   333
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   334
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   335
!Symbol methodsFor:'copying'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   336
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   337
copy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   338
    "return a copy of myself
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   339
     - reimplemented here since symbols are unique and copy should
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   340
     return a new string with my characters."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   341
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   342
     ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   343
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   344
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   345
deepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   346
    "return a copy of myself
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   347
     - reimplemented here since symbols are unique and copy should
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   348
     return a new string with my characters."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   349
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   350
     ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   351
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   352
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   353
deepCopyUsing:aDictionary
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   354
    "return a copy of myself
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   355
     - reimplemented here since symbols are unique and copy should
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   356
     return a new string with my characters."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   357
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   358
     ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   359
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   360
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   361
shallowCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   362
    "return a copy of myself
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   363
     - reimplemented here since symbols are unique"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   364
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   365
     ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   366
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   367
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   368
simpleDeepCopy
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   369
    "return a copy of myself
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   370
     - reimplemented here since symbols are unique and copy should
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   371
     return a new string with my characters."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   372
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   373
     ^ self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   374
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   375
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   376
!Symbol methodsFor:'printing & storing'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   377
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   378
displayString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   379
    "return a string for displaying the receiver"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   380
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   381
    ^ self storeString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   382
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   383
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   384
printOn:aStream
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   385
    "append a printed representation of the receiver on aStream.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   386
     In contrast to ST-80, this does return the symbols characters
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   387
     without any leading #. Therefore, you can directly send symbols'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   388
     printStrings to some output device. This is incompatible, but easier
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   389
     to use."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   390
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   391
"/ ST-80 behavior:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   392
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   393
"/  self storeOn:aStream
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   394
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   395
    aStream nextPutAll:self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   396
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   397
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   398
printString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   399
    "return a printed representation of the receiver.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   400
     In contrast to ST-80, this does return the symbols characters
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   401
     without any leading #. Therefore, you can directly send symbols'
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   402
     printStrings to some output device. This is incompatible, but easier
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   403
     to use."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   404
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   405
"/ ST-80 behavior:
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   406
"/  ^ self storeString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   407
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   408
    ^ self asString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   409
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   410
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   411
storeOn:aStream
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   412
    "store myself on a stream"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   413
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   414
    aStream nextPutAll:(self storeString)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   415
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   416
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   417
storeString
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   418
    "return a String for storing the receiver"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   419
1125
2bfcfb490837 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1020
diff changeset
   420
    |sz|
2bfcfb490837 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1020
diff changeset
   421
2bfcfb490837 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1020
diff changeset
   422
    (sz := self size) > 0 ifTrue:[  "/ sigh
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   423
	(self at:1) isLetter ifTrue:[
1125
2bfcfb490837 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1020
diff changeset
   424
	    2 to:sz do:[:index |
608
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   425
		(self at:index) isLetterOrDigit ifFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   426
		    ^ '#''' , self , ''''
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   427
		].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   428
	    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   429
	    ^ '#' , self
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   430
	]
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   431
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   432
    ^ '#''' , self , ''''
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   433
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   434
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   435
!Symbol methodsFor:'queries'!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   436
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   437
isSymbol 
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   438
    "return true, if the receiver is some kind of symbol.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   439
     Since I am a symbol, return always true"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   440
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   441
    ^ true
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   442
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   443
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   444
keywords
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   445
    "assuming the receiver is a keyword message selector,
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   446
     return the individual keywords (i.e. break it up at colons)
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   447
     and return these as a collection.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   448
     For binary and unary selectors, the result may be nonsense."
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   449
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   450
    |coll s part|
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   451
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   452
    coll := OrderedCollection new.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   453
    s := ReadStream on:self.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   454
    [s atEnd] whileFalse:[
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   455
	part := s through:$:.
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   456
	coll add:part
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   457
    ].
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   458
    ^ coll asArray
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   459
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   460
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   461
     #at:put: keywords  
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   462
     #at: keywords      
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   463
     #+ keywords        
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   464
     #size keywords     
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   465
    "
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   466
!
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   467
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   468
species
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   469
    "when copying, or concatenating, return instances of this class"
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   470
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   471
    ^ String
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   472
! !
cd5ac440fa95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   473
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   474
!Symbol methodsFor:'system primitives'!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   475
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   476
become:anotherObject
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   477
    "make all references to the receiver become references to anotherObject
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   478
     and vice-versa. For symbols, some special action is required, to
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   479
     correctly handle a become of the global dictionaries.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   480
     Anyway: this is very dangerous - mysterous side-effects are to be
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   481
     expected.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   482
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   483
     Notice: because of the danger here, this method may report an error
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   484
	     in future versions"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   485
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   486
    (Smalltalk includesKey:self) ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   487
	super become:anotherObject.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   488
%{
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   489
	__rehashSystemDictionaries();
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   490
%}.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   491
    ] ifFalse:[
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   492
	super become:anotherObject
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   493
    ]
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   494
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   495
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   496
becomeNil
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   497
    "make all references to the receiver become nil - effectively getting
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   498
     rid of the receiver. For symbols, this is not allowed, if the receiver
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   499
     is used as a key in some SytemDictionary.
95
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   500
     This can be a very dangerous operation - be warned.
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   501
d22739a0c6e9 *** empty log message ***
claus
parents: 88
diff changeset
   502
     Notice: because of the danger here, this method may report an error
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   503
	     in future versions"
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   504
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   505
    (Smalltalk includesKey:self) ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   506
	self primitiveFailed
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   507
    ] ifFalse:[
159
514c749165c3 *** empty log message ***
claus
parents: 95
diff changeset
   508
	super becomeNil
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   509
    ]
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   510
! !
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   511
632
31498e8b424c version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   512
!Symbol class methodsFor:'documentation'!
31498e8b424c version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   513
31498e8b424c version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   514
version
1138
993e6ffdbf51 removed external decls for VM functions (should look for more)
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
   515
    ^ '$Header: /cvs/stx/stx/libbasic/Symbol.st,v 1.39 1996-04-06 13:23:05 cg Exp $'
632
31498e8b424c version at the end
Claus Gittinger <cg@exept.de>
parents: 608
diff changeset
   516
! !