author | Claus Gittinger <cg@exept.de> |
Mon, 16 Jun 1997 20:21:41 +0200 | |
changeset 2689 | ada9b102abcf |
parent 2673 | f514189f6096 |
child 2704 | 3f56a3a9908a |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
783 | 13 |
nil subclass:#Object |
14 |
instanceVariableNames:'' |
|
15 |
classVariableNames:'ErrorSignal HaltSignal MessageNotUnderstoodSignal |
|
16 |
UserInterruptSignal RecursionInterruptSignal |
|
17 |
ExceptionInterruptSignal SubscriptOutOfBoundsSignal |
|
18 |
NonIntegerIndexSignal NotFoundSignal KeyNotFoundSignal |
|
19 |
ElementOutOfBoundsSignal UserNotificationSignal InformationSignal |
|
20 |
WarningSignal PrimitiveFailureSignal DeepCopyErrorSignal |
|
21 |
AbortSignal ErrorRecursion Dependencies InfoPrinting |
|
2231 | 22 |
ActivityNotificationSignal InternalErrorSignal |
2295 | 23 |
NonWeakDependencies SynchronizationSemaphores' |
783 | 24 |
poolDictionaries:'' |
25 |
category:'Kernel-Objects' |
|
1 | 26 |
! |
27 |
||
1788 | 28 |
!Object class methodsFor:'documentation'! |
71 | 29 |
|
88 | 30 |
copyright |
31 |
" |
|
32 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
159 | 33 |
All Rights Reserved |
88 | 34 |
|
35 |
This software is furnished under a license and may be used |
|
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
39 |
other person. No title to or ownership of the software is |
|
40 |
hereby transferred. |
|
41 |
" |
|
42 |
! |
|
43 |
||
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
44 |
dependencies |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
45 |
" |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
46 |
ST/X dependencies are slightly modified from ST-80's |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
47 |
(we think they are better ;-). |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
48 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
49 |
One problem occuring very often in ST-80 is that some object |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
50 |
cannot be garbage collected because some dependency is present, |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
51 |
having the object as a dependent of some other object. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
52 |
In ST-80, this association remains alive (because a Dictionary |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
53 |
is used to hold dependents) - even if no other references exist to |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
54 |
to dependent or the dependee. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
55 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
56 |
This means, that in ST-80, a #release is mandatory in order to |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
57 |
prevent memory leaks. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
58 |
We think, that this is a bad solution, since after all, exactly that |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
59 |
kind of work should be performed by a garbage collector - you should not |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
60 |
need to care about dependencies. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
61 |
From a philosophical point of view, why should some object depend on |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
62 |
something that the programmer considers a dead object ? |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
63 |
(well - worse than that: it seems that some ST-80 code even depends on |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
64 |
that behavior) |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
65 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
66 |
In order to limit the trouble, ST-80 reimplemented the way dependents |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
67 |
are stored in the model class - this one keeps the dependents locally, |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
68 |
so these dependents go away, once the model is reclaimed. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
69 |
That may make things even more confusing: with models, no #release is |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
70 |
needed, with general objects it is mandatory. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
71 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
72 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
73 |
In ST/X, dependencies are implemented using a WeakDictionary; this means, |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
74 |
that once the dependee dies, the dependency association is removed automatically, |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
75 |
and the dependent can be reclaimed by the garbage collector, if no other |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
76 |
references exist to the dependent. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
77 |
In order to (at least) provide a mechanism for the old behavior |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
78 |
(in case your application heavily depends on the ST-80 mechanism), complementary |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
79 |
protocol to add nonWeak dependencies is provided |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
80 |
(see #addNonWeakDependent / #removeNonWeakDependent). |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
81 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
82 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
83 |
Caveat: |
1751
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
84 |
since interests are implemented using InterestConverter (which are simply |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
85 |
forwarding messages), these must use the nonWeak mechanism (as done in ST-80 |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
86 |
automatically). |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
87 |
The reason is that there are usually no direct references to the converters, |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
88 |
and those would be reclaimed if stored in a weakDictionary. |
1751
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
89 |
This means, that those interests MUST be removed with #retractInterest |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
90 |
(which is bug-compatible to ST-80). |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
91 |
We rewrite things to provide a more convenient mechanism in the future ... |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
92 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
93 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
94 |
I like to hear comments on the above - do you think its better ? |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
95 |
" |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
96 |
! |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
97 |
|
71 | 98 |
documentation |
99 |
" |
|
1294 | 100 |
Object is the superclass of most other classes. |
101 |
(except for nil-subclasses, which inherit nothing, |
|
102 |
to catch any message into their #doesNotUnderstand: method) |
|
103 |
||
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
104 |
Protocol which is common to every object is defined here. |
71 | 105 |
Also some utility stuff (like notify) and error handling is implemented here. |
106 |
||
107 |
Object has no instance variables (and may not get any added). One reason is, that |
|
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
108 |
UndefinedObject and SmallInteger are also inheriting from Object - these two cannot |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
109 |
have instance variables (due to their implementation). |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
110 |
The other reason is that the runtime system (VM) knows about the layout of some built-in |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
111 |
classes (think of Class, Method, Block and also Integer or Float). |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
112 |
If you were allowed to add instance variables to Object, the VM had to be recompiled |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
113 |
(and also rewritten in some places). |
71 | 114 |
|
1294 | 115 |
[Class variables:] |
71 | 116 |
|
2647 | 117 |
ErrorSignal <Signal> Signal raised for error/error: messages |
118 |
also, parent of all other signals. |
|
119 |
||
120 |
HaltSignal <Signal> Signal raised for halt/halt: messages |
|
121 |
||
122 |
MessageNotUnderstoodSignal Signals raised for various error conditions |
|
123 |
UserInterruptSignal |
|
124 |
RecursionInterruptSignal |
|
125 |
ExceptionInterruptSignal |
|
126 |
SubscriptOutOfBoundsSignal |
|
127 |
NonIntegerIndexSignal |
|
128 |
NotFoundSignal |
|
129 |
KeyNotFoundSignal |
|
130 |
ElementOutOfBoundsSignal |
|
131 |
InformationSignal |
|
132 |
WarningSignal |
|
133 |
DeepCopyErrorSignal |
|
134 |
InternalErrorSignal |
|
135 |
||
136 |
AbortSignal <Signal> Signal raised by debugger, to abort a computation |
|
137 |
BUT, the debugger will only raise it if it is handled. |
|
138 |
By handling the abortSignal, you can control where the |
|
139 |
debuggers abort-function resumes execution in case of |
|
140 |
an error. |
|
141 |
||
142 |
ErrorRecursion <Boolean> controls behavior when recursive errors occur (i.e. |
|
143 |
an error while handling an error). |
|
144 |
||
145 |
Dependencies <WeakDependencyDictionary> |
|
146 |
keeps track of object dependencies. |
|
147 |
||
148 |
InfoPrinting <Boolean> controls weather informational messages |
|
149 |
are printed. |
|
150 |
||
151 |
ActivityNotificationSignal <QuerySignal> |
|
152 |
raised on #activityNotification: |
|
153 |
||
154 |
NonWeakDependencies <Dictionary> keeps track of object dependencies. |
|
155 |
Dependents stay alive. |
|
156 |
||
157 |
SynchronizationSemaphores <WeakIdentityDictionary> |
|
158 |
Semaphores for per-object-monitor. |
|
2295 | 159 |
|
1294 | 160 |
|
161 |
[author:] |
|
2647 | 162 |
Claus Gittinger |
1294 | 163 |
|
71 | 164 |
" |
165 |
! ! |
|
1 | 166 |
|
1788 | 167 |
!Object class methodsFor:'initialization'! |
1 | 168 |
|
169 |
initialize |
|
170 |
"called only once - initialize signals" |
|
171 |
||
172 |
ErrorSignal isNil ifTrue:[ |
|
2647 | 173 |
ErrorSignal := (Signal new) mayProceed:true. |
174 |
ErrorSignal nameClass:self message:#errorSignal. |
|
175 |
ErrorSignal notifierString:'error encountered'. |
|
176 |
||
177 |
HaltSignal := ErrorSignal newSignalMayProceed:true. |
|
178 |
HaltSignal nameClass:self message:#haltSignal. |
|
179 |
HaltSignal notifierString:'halt encountered'. |
|
180 |
||
181 |
MessageNotUnderstoodSignal := ErrorSignal newSignalMayProceed:true. |
|
182 |
MessageNotUnderstoodSignal nameClass:self message:#messageNotUnderstoodSignal. |
|
183 |
MessageNotUnderstoodSignal notifierString:'message not understood'. |
|
184 |
||
185 |
PrimitiveFailureSignal := ErrorSignal newSignalMayProceed:true. |
|
186 |
PrimitiveFailureSignal nameClass:self message:#primitiveFailureSignal. |
|
187 |
PrimitiveFailureSignal notifierString:'primitive failed'. |
|
188 |
||
189 |
InternalErrorSignal := ErrorSignal newSignalMayProceed:false. |
|
190 |
InternalErrorSignal nameClass:self message:#internalError. |
|
191 |
InternalErrorSignal notifierString:'VM internal error: '. |
|
2227
eb1e28c62f14
use an extra signal for internal errors
Claus Gittinger <cg@exept.de>
parents:
2209
diff
changeset
|
192 |
|
362 | 193 |
"/ UserInterruptSignal := ErrorSignal newSignalMayProceed:true. |
2647 | 194 |
UserInterruptSignal := (Signal new) mayProceed:true. |
195 |
UserInterruptSignal nameClass:self message:#userInterruptSignal. |
|
196 |
UserInterruptSignal notifierString:'user Interrupt'. |
|
159 | 197 |
|
362 | 198 |
"/ RecursionInterruptSignal := ErrorSignal newSignalMayProceed:false. |
2647 | 199 |
RecursionInterruptSignal := (Signal new) mayProceed:true. |
200 |
RecursionInterruptSignal nameClass:self message:#recursionInterruptSignal. |
|
201 |
RecursionInterruptSignal notifierString:'recursion limit reached'. |
|
202 |
||
203 |
ExceptionInterruptSignal := ErrorSignal newSignalMayProceed:true. |
|
204 |
ExceptionInterruptSignal nameClass:self message:#exceptionInterruptSignal. |
|
205 |
ExceptionInterruptSignal notifierString:'exception Interrupt'. |
|
206 |
||
207 |
SubscriptOutOfBoundsSignal := ErrorSignal newSignalMayProceed:false. |
|
208 |
SubscriptOutOfBoundsSignal nameClass:self message:#subscriptOutOfBoundsSignal. |
|
209 |
SubscriptOutOfBoundsSignal notifierString:'subscript out of bounds: '. |
|
210 |
||
211 |
ElementOutOfBoundsSignal := ErrorSignal newSignalMayProceed:false. |
|
212 |
ElementOutOfBoundsSignal nameClass:self message:#elementOutOfBoundsSignal. |
|
213 |
ElementOutOfBoundsSignal notifierString:'element not appropriate or out of bounds'. |
|
214 |
||
215 |
NotFoundSignal := ErrorSignal newSignalMayProceed:true. |
|
216 |
NotFoundSignal nameClass:self message:#notFoundSignal. |
|
217 |
NotFoundSignal notifierString:'no such element'. |
|
218 |
||
219 |
KeyNotFoundSignal := ErrorSignal newSignalMayProceed:true. |
|
220 |
KeyNotFoundSignal nameClass:self message:#keyNotFoundSignal. |
|
221 |
KeyNotFoundSignal notifierString:'no such key: '. |
|
222 |
||
223 |
NonIntegerIndexSignal := ErrorSignal newSignalMayProceed:false. |
|
224 |
NonIntegerIndexSignal nameClass:self message:#nonIntegerIndexSignal. |
|
225 |
NonIntegerIndexSignal notifierString:'index must be integer'. |
|
226 |
||
227 |
UserNotificationSignal := QuerySignal new. |
|
228 |
UserNotificationSignal nameClass:self message:#userNotificationSignal. |
|
229 |
UserNotificationSignal notifierString:'user notifiaction wanted'. |
|
230 |
||
231 |
InformationSignal := UserNotificationSignal newSignalMayProceed:true. |
|
232 |
InformationSignal nameClass:self message:#informationSignal. |
|
233 |
InformationSignal notifierString:'information'. |
|
234 |
||
235 |
WarningSignal := UserNotificationSignal newSignalMayProceed:true. |
|
236 |
WarningSignal nameClass:self message:#warnungSignal. |
|
237 |
WarningSignal notifierString:'warning'. |
|
238 |
||
239 |
ActivityNotificationSignal := UserNotificationSignal newSignalMayProceed:true. |
|
240 |
ActivityNotificationSignal nameClass:self message:#activityNotificationSignal. |
|
241 |
ActivityNotificationSignal notifierString:'activity'. |
|
242 |
||
243 |
DeepCopyErrorSignal := ErrorSignal newSignalMayProceed:true. |
|
244 |
DeepCopyErrorSignal nameClass:self message:#deepCopyErrorSignal. |
|
245 |
DeepCopyErrorSignal notifierString:'object cannot be deepCopy-ed'. |
|
246 |
||
247 |
" |
|
248 |
AbortSignal is not a child of ErrorSignal - |
|
249 |
this would complicate abort from within a signal handler |
|
250 |
" |
|
251 |
AbortSignal := Signal new mayProceed:true. |
|
252 |
AbortSignal nameClass:self message:#abortSignal. |
|
253 |
AbortSignal notifierString:'unhandled abort signal'. |
|
254 |
||
255 |
Dependencies isNil ifTrue:[ |
|
256 |
Dependencies := WeakDependencyDictionary new. |
|
257 |
]. |
|
258 |
NonWeakDependencies isNil ifTrue:[ |
|
259 |
NonWeakDependencies := IdentityDictionary new. |
|
260 |
]. |
|
261 |
SynchronizationSemaphores isNil ifTrue:[ |
|
262 |
SynchronizationSemaphores := WeakIdentityDictionary new. |
|
263 |
]. |
|
356 | 264 |
]. |
2114
706cf3f9019a
initialize InfoPrinting flag from VM's setting
Claus Gittinger <cg@exept.de>
parents:
2096
diff
changeset
|
265 |
|
706cf3f9019a
initialize InfoPrinting flag from VM's setting
Claus Gittinger <cg@exept.de>
parents:
2096
diff
changeset
|
266 |
"/ initialize InfoPrinting to the VM's infoPrint setting |
706cf3f9019a
initialize InfoPrinting flag from VM's setting
Claus Gittinger <cg@exept.de>
parents:
2096
diff
changeset
|
267 |
"/ (which can be turned off via a command line argument) |
706cf3f9019a
initialize InfoPrinting flag from VM's setting
Claus Gittinger <cg@exept.de>
parents:
2096
diff
changeset
|
268 |
InfoPrinting := ObjectMemory infoPrinting. |
1 | 269 |
|
270 |
"Object initialize" |
|
812
00db9c0646fe
notificationsignals are no longer children of ErrorSignal
Claus Gittinger <cg@exept.de>
parents:
783
diff
changeset
|
271 |
|
2096
bc7296b593ee
use new WeakDependencyDictionary
Claus Gittinger <cg@exept.de>
parents:
2082
diff
changeset
|
272 |
"Modified: 9.1.1997 / 00:28:38 / cg" |
2295 | 273 |
"Modified: 28.1.1997 / 19:38:58 / stefan" |
1 | 274 |
! ! |
275 |
||
1788 | 276 |
!Object class methodsFor:'Signal constants'! |
1 | 277 |
|
783 | 278 |
abortSignal |
279 |
"return the signal used to abort user actions. This signal is only |
|
2689 | 280 |
raised if caught (by the debugger), and will lead way out of the |
783 | 281 |
currently active doIt/printIt or inspectIt. (also some others use |
282 |
this for a save abort)" |
|
283 |
||
284 |
^ AbortSignal |
|
579
2d26193415b5
allow catching of information: and warn: boxes
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
285 |
! |
2d26193415b5
allow catching of information: and warn: boxes
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
286 |
|
782 | 287 |
activityNotificationSignal |
288 |
"return the signal used for activity notifications. |
|
289 |
A handler for this signal gets all #activityNotification: sends" |
|
290 |
||
291 |
^ ActivityNotificationSignal |
|
292 |
! |
|
293 |
||
159 | 294 |
deepCopyErrorSignal |
295 |
"return the signal raised when a deepcopy is asked for |
|
296 |
an object which cannot do this (for example, BlockClosures |
|
297 |
or Contexts)." |
|
298 |
||
299 |
^ DeepCopyErrorSignal |
|
300 |
! |
|
301 |
||
783 | 302 |
elementOutOfBoundsSignal |
303 |
"return the signal used for element error reporting |
|
304 |
(this signal is used for example when a value not in 0..255 is to |
|
305 |
be put into a bytearray)" |
|
306 |
||
307 |
^ ElementOutOfBoundsSignal |
|
308 |
! |
|
309 |
||
310 |
errorSignal |
|
311 |
"return the signal used for error/error: - handling" |
|
312 |
||
313 |
^ ErrorSignal |
|
314 |
! |
|
315 |
||
316 |
exceptionInterruptSignal |
|
317 |
"return the signal used for exception (display errors) error handling" |
|
318 |
||
319 |
^ ExceptionInterruptSignal |
|
320 |
! |
|
321 |
||
322 |
haltSignal |
|
323 |
"return the signal used for halt/halt: - handling" |
|
324 |
||
325 |
^ HaltSignal |
|
326 |
! |
|
327 |
||
328 |
informationSignal |
|
329 |
"return the signal used for informations. |
|
330 |
A handler for this signal gets all #information: sends" |
|
331 |
||
332 |
^ InformationSignal |
|
333 |
! |
|
334 |
||
2227
eb1e28c62f14
use an extra signal for internal errors
Claus Gittinger <cg@exept.de>
parents:
2209
diff
changeset
|
335 |
internalErrorSignal |
eb1e28c62f14
use an extra signal for internal errors
Claus Gittinger <cg@exept.de>
parents:
2209
diff
changeset
|
336 |
"return the signal used to report internal (VM-) errors." |
eb1e28c62f14
use an extra signal for internal errors
Claus Gittinger <cg@exept.de>
parents:
2209
diff
changeset
|
337 |
|
eb1e28c62f14
use an extra signal for internal errors
Claus Gittinger <cg@exept.de>
parents:
2209
diff
changeset
|
338 |
^ InternalErrorSignal |
eb1e28c62f14
use an extra signal for internal errors
Claus Gittinger <cg@exept.de>
parents:
2209
diff
changeset
|
339 |
! |
eb1e28c62f14
use an extra signal for internal errors
Claus Gittinger <cg@exept.de>
parents:
2209
diff
changeset
|
340 |
|
783 | 341 |
keyNotFoundSignal |
342 |
"return the signal used for no such key error reporting" |
|
343 |
||
344 |
^ KeyNotFoundSignal |
|
345 |
! |
|
346 |
||
347 |
messageNotUnderstoodSignal |
|
348 |
"return the signal used for doesNotUnderstand: - error handling" |
|
349 |
||
350 |
^ MessageNotUnderstoodSignal |
|
351 |
! |
|
352 |
||
353 |
nonIntegerIndexSignal |
|
354 |
"return the signal used for bad subscript error reporting" |
|
355 |
||
356 |
^ NonIntegerIndexSignal |
|
357 |
! |
|
358 |
||
359 |
notFoundSignal |
|
360 |
"return the signal used for no element found error reporting" |
|
361 |
||
362 |
^ NotFoundSignal |
|
363 |
! |
|
364 |
||
365 |
primitiveFailureSignal |
|
366 |
"return the signal used for primitiveFailed - error handling" |
|
367 |
||
368 |
^ PrimitiveFailureSignal |
|
369 |
! |
|
370 |
||
371 |
privateMethodSignal |
|
372 |
"return the signal used for privateMethod - error handling" |
|
373 |
||
374 |
^ MessageNotUnderstoodSignal |
|
375 |
! |
|
376 |
||
377 |
recursionInterruptSignal |
|
378 |
"return the signal used for recursion overflow error handling" |
|
379 |
||
380 |
^ RecursionInterruptSignal |
|
381 |
! |
|
382 |
||
383 |
subscriptOutOfBoundsSignal |
|
384 |
"return the signal used for subscript error reporting. |
|
385 |
(this signal is used for example when an array is accessed with an |
|
386 |
index less than 1 or greater than the array size)" |
|
387 |
||
388 |
^ SubscriptOutOfBoundsSignal |
|
389 |
! |
|
390 |
||
391 |
userInterruptSignal |
|
392 |
"return the signal used for ^C interrupts handling" |
|
393 |
||
394 |
^ UserInterruptSignal |
|
395 |
! |
|
396 |
||
397 |
userNotificationSignal |
|
398 |
"the parent signal used with information and warnings. |
|
399 |
Handling this allows handling of both information- and warning notifications." |
|
400 |
||
401 |
^ UserNotificationSignal |
|
402 |
! |
|
403 |
||
404 |
warningSignal |
|
405 |
"return the signal used for warnings. |
|
406 |
A handler for this signal gets all #warn: sends" |
|
407 |
||
408 |
^ WarningSignal |
|
1 | 409 |
! ! |
410 |
||
1788 | 411 |
!Object class methodsFor:'info messages'! |
356 | 412 |
|
783 | 413 |
infoPrinting |
414 |
"return the flag which controls information messages." |
|
415 |
||
416 |
^ InfoPrinting |
|
417 |
! |
|
418 |
||
356 | 419 |
infoPrinting:aBoolean |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
420 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
421 |
|
356 | 422 |
"turn on/off printing of information messages. |
423 |
If the argument, aBoolean is false, infoPrint will not output |
|
424 |
messages. The default is true." |
|
425 |
||
426 |
InfoPrinting := aBoolean |
|
427 |
! ! |
|
428 |
||
1788 | 429 |
!Object class methodsFor:'queries'! |
3 | 430 |
|
431 |
isBuiltInClass |
|
49 | 432 |
"return true, if this class is known by the run-time-system, |
433 |
i.e. you cannot add/remove instance variables without recompiling |
|
1266 | 434 |
the VM. |
435 |
Here, true is returned for myself, false for subclasses." |
|
3 | 436 |
|
437 |
^ self == Object |
|
1266 | 438 |
|
439 |
"Modified: 23.4.1996 / 16:00:07 / cg" |
|
3 | 440 |
! ! |
441 |
||
1 | 442 |
!Object methodsFor:'accessing'! |
443 |
||
444 |
at:index |
|
445 |
"return the indexed instance variable with index, anInteger; |
|
446 |
this method can be redefined in subclasses." |
|
447 |
||
448 |
^ self basicAt:index |
|
449 |
! |
|
450 |
||
783 | 451 |
at:index put:anObject |
452 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
453 |
this method can be redefined in subclasses. Returns anObject (sigh)" |
783 | 454 |
|
455 |
^ self basicAt:index put:anObject |
|
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
456 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
457 |
"Modified: 19.4.1996 / 11:13:29 / cg" |
783 | 458 |
! |
459 |
||
1 | 460 |
basicAt:index |
461 |
"return the indexed instance variable with index, anInteger. |
|
462 |
Trigger an error if the receiver has no indexed instance variables. |
|
2148 | 463 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
1 | 464 |
|
465 |
%{ /* NOCONTEXT */ |
|
466 |
||
329 | 467 |
REGISTER int nbytes, indx; |
1 | 468 |
OBJ myClass; |
329 | 469 |
REGISTER char *pFirst; |
1 | 470 |
unsigned char *cp; |
471 |
unsigned short *sp; |
|
1515
49a8587fcc8f
added support for signedWord and signedLong indexable classes.
Claus Gittinger <cg@exept.de>
parents:
1445
diff
changeset
|
472 |
short *ssp; |
49a8587fcc8f
added support for signedWord and signedLong indexable classes.
Claus Gittinger <cg@exept.de>
parents:
1445
diff
changeset
|
473 |
unsigned long *lp; |
49a8587fcc8f
added support for signedWord and signedLong indexable classes.
Claus Gittinger <cg@exept.de>
parents:
1445
diff
changeset
|
474 |
long *slp; |
49a8587fcc8f
added support for signedWord and signedLong indexable classes.
Claus Gittinger <cg@exept.de>
parents:
1445
diff
changeset
|
475 |
unsigned long ul; |
49a8587fcc8f
added support for signedWord and signedLong indexable classes.
Claus Gittinger <cg@exept.de>
parents:
1445
diff
changeset
|
476 |
long l; |
1 | 477 |
OBJ *op; |
329 | 478 |
/* int nInstBytes, nInstVars, flags; */ |
479 |
REGISTER int n; |
|
1 | 480 |
|
481 |
||
482 |
/* |
|
56 | 483 |
* notice the missing test for self being a nonNilObject - |
1 | 484 |
* this can be done since basicAt: is defined both in UndefinedObject |
485 |
* and SmallInteger |
|
486 |
*/ |
|
253 | 487 |
if (__isSmallInteger(index)) { |
2647 | 488 |
myClass = __qClass(self); |
489 |
indx = __intVal(index) - 1; |
|
490 |
n /* nInstVars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
491 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* nInstVars */); |
|
492 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
493 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
494 |
||
495 |
/* |
|
496 |
* replaced switch by open-coded if; this is slightly faster |
|
497 |
* since it avoids the range check and also handles the most common case first |
|
498 |
*/ |
|
499 |
n = (INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK); |
|
500 |
||
501 |
if ((n == __MASKSMALLINT(POINTERARRAY)) |
|
502 |
|| (n == __MASKSMALLINT(WKPOINTERARRAY))) { |
|
503 |
if ((indx >= 0) && (indx < (__BYTES2OBJS__(nbytes)))) { |
|
504 |
op = (OBJ *)pFirst + indx; |
|
505 |
RETURN ( *op ); |
|
506 |
} |
|
507 |
} else if (n == __MASKSMALLINT(BYTEARRAY)) { |
|
508 |
if ((indx >= 0) && (indx < (nbytes / sizeof(char)))) { |
|
509 |
cp = (unsigned char *)pFirst + indx; |
|
510 |
RETURN ( __MKSMALLINT(*cp & 0xFF) ); |
|
511 |
} |
|
512 |
} else if (n == __MASKSMALLINT(FLOATARRAY)) { |
|
513 |
if ((indx >= 0) && (indx < (nbytes / sizeof(float)))) { |
|
514 |
float *fp; |
|
515 |
||
516 |
fp = (float *)pFirst + indx; |
|
517 |
RETURN ( __MKFLOAT((double)(*fp))); |
|
518 |
} |
|
519 |
} else if (n == __MASKSMALLINT(DOUBLEARRAY)) { |
|
520 |
if ((indx >= 0) && (indx < (nbytes / sizeof(double)))) { |
|
521 |
double *dp; |
|
1 | 522 |
|
56 | 523 |
#ifdef NEED_DOUBLE_ALIGN |
2647 | 524 |
/* |
525 |
* care for filler |
|
526 |
*/ |
|
527 |
pFirst += sizeof(FILLTYPE); |
|
56 | 528 |
#endif |
2647 | 529 |
dp = (double *)pFirst + indx; |
530 |
RETURN ( __MKFLOAT(*dp)); |
|
531 |
} |
|
532 |
} else if (n == __MASKSMALLINT(WORDARRAY)) { |
|
533 |
if ((indx >= 0) && (indx < (nbytes / sizeof(short)))) { |
|
534 |
sp = (unsigned short *)pFirst + indx; |
|
535 |
RETURN ( __MKSMALLINT(*sp & 0xFFFF) ); |
|
536 |
} |
|
537 |
} else if (n == __MASKSMALLINT(SWORDARRAY)) { |
|
538 |
if ((indx >= 0) && (indx < (nbytes / sizeof(short)))) { |
|
539 |
ssp = (short *)pFirst + indx; |
|
540 |
RETURN ( __MKSMALLINT(*ssp) ); |
|
541 |
} |
|
542 |
} else if (n == __MASKSMALLINT(LONGARRAY)) { |
|
543 |
if ((indx >= 0) && (indx < (nbytes / sizeof(long)))) { |
|
544 |
lp = (unsigned long *)pFirst + indx; |
|
545 |
ul = *lp; |
|
546 |
if (ul <= _MAX_INT) |
|
547 |
RETURN ( __MKSMALLINT(ul) ); |
|
548 |
RETURN ( __MKULARGEINT(ul) ); |
|
549 |
} |
|
550 |
} else if (n == __MASKSMALLINT(SLONGARRAY)) { |
|
551 |
if ((indx >= 0) && (indx < (nbytes / sizeof(long)))) { |
|
552 |
slp = (long *)pFirst + indx; |
|
553 |
l = *slp; |
|
554 |
if ((l >= _MIN_INT) && (l <= _MAX_INT)) |
|
555 |
RETURN ( __MKSMALLINT(l) ); |
|
556 |
RETURN ( __MKLARGEINT(l) ); |
|
557 |
} |
|
558 |
} |
|
1 | 559 |
} |
1386
a31cecccdfd8
_MASKSMALLINT -> __MASKSMALLINT;
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
560 |
%}. |
10 | 561 |
index isInteger ifFalse:[ |
2647 | 562 |
^ self indexNotInteger |
1 | 563 |
]. |
159 | 564 |
^ self subscriptBoundsError:index |
1 | 565 |
! |
566 |
||
567 |
basicAt:index put:anObject |
|
568 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
569 |
Returns anObject (sigh). |
1 | 570 |
Trigger an error if the receiver has no indexed instance variables. |
2148 | 571 |
|
572 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
1 | 573 |
|
574 |
%{ /* NOCONTEXT */ |
|
575 |
||
576 |
register int nbytes, indx; |
|
577 |
OBJ myClass; |
|
578 |
register char *pFirst; |
|
579 |
char *cp; |
|
1515
49a8587fcc8f
added support for signedWord and signedLong indexable classes.
Claus Gittinger <cg@exept.de>
parents:
1445
diff
changeset
|
580 |
unsigned short *sp; |
49a8587fcc8f
added support for signedWord and signedLong indexable classes.
Claus Gittinger <cg@exept.de>
parents:
1445
diff
changeset
|
581 |
short *ssp; |
49a8587fcc8f
added support for signedWord and signedLong indexable classes.
Claus Gittinger <cg@exept.de>
parents:
1445
diff
changeset
|
582 |
unsigned long *lp; |
49a8587fcc8f
added support for signedWord and signedLong indexable classes.
Claus Gittinger <cg@exept.de>
parents:
1445
diff
changeset
|
583 |
long *slp; |
1 | 584 |
OBJ *op; |
329 | 585 |
/* int nInstBytes, ninstvars, flags; */ |
586 |
REGISTER int n; |
|
1515
49a8587fcc8f
added support for signedWord and signedLong indexable classes.
Claus Gittinger <cg@exept.de>
parents:
1445
diff
changeset
|
587 |
unsigned int u; |
1 | 588 |
int val; |
589 |
||
56 | 590 |
/* notice the missing test for self being a nonNilObject - |
77 | 591 |
this can be done since basicAt: is defined both in UndefinedObject |
1 | 592 |
and SmallInteger */ |
593 |
||
253 | 594 |
if (__isSmallInteger(index)) { |
2647 | 595 |
indx = __intVal(index) - 1; |
596 |
myClass = __qClass(self); |
|
597 |
n /* ninstvars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
598 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* ninstvars */); |
|
599 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
600 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
601 |
||
602 |
n = (INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK); |
|
603 |
||
604 |
/* |
|
605 |
* replaced switch by open-coded if; this is slightly faster |
|
606 |
* since it avoids the range check and also handles the most common case first |
|
607 |
*/ |
|
608 |
if ((n == __MASKSMALLINT(POINTERARRAY)) |
|
609 |
|| (n == __MASKSMALLINT(WKPOINTERARRAY))) { |
|
610 |
if ((indx >= 0) && (indx < (__BYTES2OBJS__(nbytes)))) { |
|
611 |
op = (OBJ *)pFirst + indx; |
|
612 |
*op = anObject; |
|
613 |
__STORE(self, anObject); |
|
614 |
RETURN ( anObject ); |
|
615 |
} |
|
616 |
} else if (n == __MASKSMALLINT(BYTEARRAY)) { |
|
617 |
if (__isSmallInteger(anObject)) { |
|
618 |
val = __intVal(anObject); |
|
619 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
|
620 |
if ((indx >= 0) && (indx < (nbytes / sizeof(char)))) { |
|
621 |
cp = pFirst + indx; |
|
622 |
*cp = val; |
|
623 |
RETURN ( anObject ); |
|
624 |
} |
|
625 |
} |
|
626 |
} |
|
627 |
} else if (n == __MASKSMALLINT(FLOATARRAY)) { |
|
628 |
if ((indx >= 0) && (indx < (nbytes / sizeof(float)))) { |
|
629 |
float *fp; |
|
630 |
||
631 |
fp = (float *)pFirst + indx; |
|
632 |
if (__isFloatLike(anObject)) { |
|
633 |
*fp = _floatVal(anObject); |
|
634 |
RETURN ( anObject ); |
|
635 |
} |
|
636 |
if (__isSmallInteger(anObject)) { |
|
637 |
*fp = (float) __intVal(anObject); |
|
638 |
RETURN ( anObject ); |
|
639 |
} |
|
640 |
} |
|
641 |
} else if (n == __MASKSMALLINT(DOUBLEARRAY)) { |
|
642 |
if ((indx >= 0) && (indx < (nbytes / sizeof(double)))) { |
|
643 |
double *dp; |
|
13 | 644 |
|
56 | 645 |
#ifdef NEED_DOUBLE_ALIGN |
2647 | 646 |
/* |
647 |
* care for filler |
|
648 |
*/ |
|
649 |
pFirst += sizeof(FILLTYPE); |
|
56 | 650 |
#endif |
2647 | 651 |
dp = (double *)pFirst + indx; |
652 |
if (__isFloatLike(anObject)) { |
|
653 |
*dp = _floatVal(anObject); |
|
654 |
RETURN ( anObject ); |
|
655 |
} |
|
656 |
if (__isSmallInteger(anObject)) { |
|
657 |
*dp = (double) __intVal(anObject); |
|
658 |
RETURN ( anObject ); |
|
659 |
} |
|
660 |
} |
|
661 |
} else if (n == __MASKSMALLINT(WORDARRAY)) { |
|
662 |
if (__isSmallInteger(anObject)) { |
|
663 |
val = __intVal(anObject); |
|
664 |
if ((val >= 0) && (val <= 0xFFFF)) { |
|
665 |
if ((indx >= 0) && (indx < (nbytes / sizeof(short)))) { |
|
666 |
sp = (unsigned short *)pFirst + indx; |
|
667 |
*sp = val; |
|
668 |
RETURN ( anObject ); |
|
669 |
} |
|
670 |
} |
|
671 |
} |
|
672 |
} else if (n == __MASKSMALLINT(SWORDARRAY)) { |
|
673 |
if (__isSmallInteger(anObject)) { |
|
674 |
val = __intVal(anObject); |
|
675 |
if ((val >= -32768) && (val < 32768)) { |
|
676 |
if ((indx >= 0) && (indx < (nbytes / sizeof(short)))) { |
|
677 |
ssp = (short *)pFirst + indx; |
|
678 |
*ssp = val; |
|
679 |
RETURN ( anObject ); |
|
680 |
} |
|
681 |
} |
|
682 |
} |
|
683 |
} else if (n == __MASKSMALLINT(SLONGARRAY)) { |
|
684 |
if ((indx >= 0) && (indx < (nbytes / sizeof(long)))) { |
|
685 |
slp = (long *)pFirst + indx; |
|
686 |
if (__isSmallInteger(anObject)) { |
|
687 |
*slp = __intVal(anObject); |
|
688 |
RETURN ( anObject ); |
|
689 |
} |
|
690 |
n = __signedLongIntVal(anObject); |
|
691 |
/* zero means failure for an int larger than 4 bytes ... (would be a smallInteger) */ |
|
692 |
if (n) { |
|
693 |
*slp = n; |
|
694 |
RETURN ( anObject ); |
|
695 |
} |
|
696 |
} |
|
697 |
} else if (n == __MASKSMALLINT(LONGARRAY)) { |
|
698 |
if ((indx >= 0) && (indx < (nbytes / sizeof(long)))) { |
|
699 |
lp = (unsigned long *)pFirst + indx; |
|
700 |
if (anObject == __MKSMALLINT(0)) { |
|
701 |
*lp = 0; |
|
702 |
RETURN ( anObject ); |
|
703 |
} |
|
704 |
u = __longIntVal(anObject); |
|
705 |
/* zero means failure for an int larger than 4 bytes ... (would be a smallInteger) */ |
|
706 |
if (u) { |
|
707 |
*lp = u; |
|
708 |
RETURN ( anObject ); |
|
709 |
} |
|
710 |
} |
|
711 |
} |
|
1 | 712 |
} |
1386
a31cecccdfd8
_MASKSMALLINT -> __MASKSMALLINT;
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
713 |
%}. |
10 | 714 |
index isInteger ifFalse:[ |
2647 | 715 |
" |
716 |
the index should be an integer number |
|
717 |
" |
|
718 |
^ self indexNotInteger |
|
1 | 719 |
]. |
720 |
(index between:1 and:self size) ifFalse:[ |
|
2647 | 721 |
" |
722 |
the index is less than 1 or greater than the size of the |
|
723 |
receiver collection |
|
724 |
" |
|
725 |
^ self subscriptBoundsError:index |
|
1 | 726 |
]. |
643 | 727 |
(self class isFloatsOrDoubles) ifTrue:[ |
2647 | 728 |
anObject isNumber ifTrue:[ |
729 |
^ self basicAt:index put:(anObject asFloat) |
|
730 |
] |
|
13 | 731 |
]. |
10 | 732 |
anObject isInteger ifFalse:[ |
2647 | 733 |
" |
734 |
the object to put into the receiver collection |
|
735 |
should be an integer number |
|
736 |
" |
|
737 |
^ self elementNotInteger |
|
2 | 738 |
]. |
159 | 739 |
" |
213 | 740 |
the object to put into the receiver collection |
362 | 741 |
is not an instance of the expected element class, |
742 |
or the value is not within the elements valid range. |
|
159 | 743 |
" |
2 | 744 |
^ self elementBoundsError |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
745 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
746 |
"Modified: 19.4.1996 / 11:14:10 / cg" |
1 | 747 |
! |
748 |
||
2574
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
749 |
byteAt:index |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
750 |
"return the byte at index. |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
751 |
This is only allowed for non-pointer indexed objects |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
752 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
753 |
The receivers indexed instvars are treated as an uninterpreted |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
754 |
collection of bytes. |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
755 |
Only useful with binary storage." |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
756 |
|
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
757 |
%{ /* NOCONTEXT */ |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
758 |
|
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
759 |
REGISTER int indx; |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
760 |
int nIndex; |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
761 |
REGISTER OBJ slf; |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
762 |
REGISTER OBJ cls; |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
763 |
|
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
764 |
if (__isSmallInteger(index)) { |
2647 | 765 |
slf = self; |
766 |
if (__isNonNilObject(slf)) { |
|
767 |
cls = __qClass(slf); |
|
768 |
||
769 |
switch (__intVal(__ClassInstPtr(cls)->c_flags) & ARRAYMASK) { |
|
770 |
case BYTEARRAY: |
|
771 |
case WORDARRAY: |
|
772 |
case LONGARRAY: |
|
773 |
case SWORDARRAY: |
|
774 |
case SLONGARRAY: |
|
775 |
case FLOATARRAY: |
|
776 |
case DOUBLEARRAY: |
|
777 |
indx = __intVal(index) - 1; |
|
778 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
779 |
nIndex = __byteArraySize(slf); |
|
780 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
781 |
RETURN ( __MKSMALLINT(__ByteArrayInstPtr(slf)->ba_element[indx]) ); |
|
782 |
} |
|
783 |
break; |
|
784 |
} |
|
785 |
} |
|
2574
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
786 |
} |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
787 |
%}. |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
788 |
"/ index not integer or index out of range |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
789 |
"/ or non-byte indexable receiver |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
790 |
|
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
791 |
^ self primitiveFailed |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
792 |
|
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
793 |
" |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
794 |
Point new byteAt:1 |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
795 |
(ByteArray with:1 with:2) byteAt:2 |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
796 |
(WordArray with:1) byteAt:1 |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
797 |
(FloatArray with:1.0) byteAt:2 |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
798 |
'hello' byteAt:1 |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
799 |
" |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
800 |
! |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
801 |
|
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
802 |
byteAt:index put:byteValue |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
803 |
"set the byte at index. |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
804 |
This is only allowed for non-pointer indexed objects |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
805 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
806 |
The receivers indexed instvars are treated as an uninterpreted |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
807 |
collection of bytes. |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
808 |
Only useful with binary storage." |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
809 |
|
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
810 |
%{ /* NOCONTEXT */ |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
811 |
|
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
812 |
REGISTER int indx; |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
813 |
int val, nIndex; |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
814 |
REGISTER OBJ slf; |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
815 |
REGISTER OBJ cls; |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
816 |
|
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
817 |
if (__bothSmallInteger(index, byteValue)) { |
2647 | 818 |
val = __intVal(byteValue); |
819 |
if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) { |
|
820 |
slf = self; |
|
821 |
if (__isNonNilObject(slf)) { |
|
822 |
cls = __qClass(slf); |
|
823 |
||
824 |
switch (__intVal(__ClassInstPtr(cls)->c_flags) & ARRAYMASK) { |
|
825 |
case BYTEARRAY: |
|
826 |
case WORDARRAY: |
|
827 |
case LONGARRAY: |
|
828 |
case SWORDARRAY: |
|
829 |
case SLONGARRAY: |
|
830 |
case FLOATARRAY: |
|
831 |
case DOUBLEARRAY: |
|
832 |
indx = __intVal(index) - 1; |
|
833 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
834 |
nIndex = __byteArraySize(slf); |
|
835 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
836 |
__ByteArrayInstPtr(slf)->ba_element[indx] = val; |
|
837 |
RETURN ( byteValue ); |
|
838 |
} |
|
839 |
break; |
|
840 |
} |
|
841 |
} |
|
842 |
} |
|
2574
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
843 |
} |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
844 |
%}. |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
845 |
"/ index not integer or index out of range |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
846 |
"/ or non-byte indexable receiver |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
847 |
|
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
848 |
^ self primitiveFailed |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
849 |
|
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
850 |
" |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
851 |
(ByteArray with:1 with:2) byteAt:2 put:3; yourself |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
852 |
'hello' copy byteAt:1 put:105; yourself |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
853 |
" |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
854 |
! |
3df87ac8838c
added #byteAt: / #byteAt:put: to access any non-pointer objects
Claus Gittinger <cg@exept.de>
parents:
2511
diff
changeset
|
855 |
|
1 | 856 |
instVarAt:index |
857 |
"return a non-indexed instance variable; |
|
13 | 858 |
peeking into an object this way is not very object oriented |
859 |
- use with care (needed for copy, inspector etc.)" |
|
1 | 860 |
|
861 |
%{ /* NOCONTEXT */ |
|
862 |
||
863 |
OBJ myClass; |
|
864 |
int idx, ninstvars; |
|
865 |
||
253 | 866 |
if (__isSmallInteger(index)) { |
329 | 867 |
myClass = __Class(self); |
755
eaab1d1dacbd
_-macros replcaed by __-macros (needed especially for MKLARGINT)
Claus Gittinger <cg@exept.de>
parents:
751
diff
changeset
|
868 |
idx = __intVal(index) - 1; |
357 | 869 |
/* |
870 |
* do not allow return of non-object fields. |
|
871 |
* if subclass did not make privisions for that, |
|
872 |
* we wont do so here ... |
|
873 |
*/ |
|
1386
a31cecccdfd8
_MASKSMALLINT -> __MASKSMALLINT;
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
874 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
357 | 875 |
if (idx == 0) { |
876 |
RETURN ( nil ) |
|
877 |
} |
|
878 |
} |
|
1133 | 879 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
159 | 880 |
if ((idx >= 0) && (idx < ninstvars)) { |
1133 | 881 |
RETURN ( __InstPtr(self)->i_instvars[idx] ); |
159 | 882 |
} |
1 | 883 |
} |
884 |
%} |
|
885 |
. |
|
886 |
index isInteger ifFalse:[ |
|
159 | 887 |
^ self indexNotInteger |
1 | 888 |
]. |
159 | 889 |
^ self subscriptBoundsError:index |
1 | 890 |
! |
891 |
||
892 |
instVarAt:index put:value |
|
893 |
"change a non-indexed instance variable; |
|
13 | 894 |
peeking into an object this way is not very object oriented |
895 |
- use with care (needed for copy, inspector etc.)" |
|
1 | 896 |
|
897 |
%{ /* NOCONTEXT */ |
|
898 |
||
899 |
OBJ myClass; |
|
900 |
int idx, ninstvars; |
|
901 |
||
253 | 902 |
if (__isSmallInteger(index)) { |
329 | 903 |
myClass = __Class(self); |
755
eaab1d1dacbd
_-macros replcaed by __-macros (needed especially for MKLARGINT)
Claus Gittinger <cg@exept.de>
parents:
751
diff
changeset
|
904 |
idx = __intVal(index) - 1; |
1133 | 905 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
357 | 906 |
/* |
907 |
* do not allow setting of non-object fields. |
|
908 |
* if subclass did not make privisions for that, |
|
909 |
* we wont do so here ... |
|
910 |
*/ |
|
1386
a31cecccdfd8
_MASKSMALLINT -> __MASKSMALLINT;
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
911 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
357 | 912 |
if (idx == 0) { |
913 |
RETURN ( nil ) |
|
914 |
} |
|
915 |
} |
|
159 | 916 |
if ((idx >= 0) && (idx < ninstvars)) { |
1133 | 917 |
__InstPtr(self)->i_instvars[idx] = value; |
159 | 918 |
__STORE(self, value); |
919 |
RETURN ( value ); |
|
920 |
} |
|
1 | 921 |
} |
922 |
%} |
|
923 |
. |
|
924 |
index isInteger ifFalse:[ |
|
159 | 925 |
^ self indexNotInteger |
1 | 926 |
]. |
159 | 927 |
^ self subscriptBoundsError:index |
359 | 928 |
! |
929 |
||
930 |
instVarNamed:name |
|
931 |
"return a non-indexed instance variables value by name; |
|
932 |
peeking into an object this way is not very object oriented |
|
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
933 |
- use with care if at all (provided for inspectors and memory usage monitor). |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
934 |
Notice, this access is very slow (because the classes instVar-description has to be |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
935 |
parsed ad runtime)" |
359 | 936 |
|
937 |
^ self instVarAt:(self class instVarOffsetOf:name) |
|
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
938 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
939 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
940 |
" |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
941 |
|p| |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
942 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
943 |
p := Point x:10 y:20. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
944 |
p instVarNamed:'x' |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
945 |
" |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
946 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
947 |
"Modified: 19.4.1996 / 11:12:39 / cg" |
359 | 948 |
! |
949 |
||
1528
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
950 |
instVarNamed:name ifAbsent:exceptionBlock |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
951 |
"return a non-indexed instance variables value by name, |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
952 |
or the value of exceptionBlock, if there is no such instance variable. |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
953 |
peeking into an object this way is not very object oriented |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
954 |
- use with care if at all (provided for inspectors and memory usage monitor). |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
955 |
Notice, this access is very slow (because the classes instVar-description has to be |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
956 |
parsed ad runtime)" |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
957 |
|
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
958 |
|idx| |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
959 |
|
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
960 |
idx := self class instVarOffsetOf:name. |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
961 |
idx isNil ifTrue:[^ exceptionBlock value]. |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
962 |
^ self instVarAt:idx |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
963 |
|
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
964 |
|
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
965 |
" |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
966 |
|p| |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
967 |
|
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
968 |
p := Point x:10 y:20. |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
969 |
p instVarNamed:'x' |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
970 |
" |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
971 |
|
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
972 |
"Created: 6.7.1996 / 23:02:49 / cg" |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
973 |
"Modified: 6.7.1996 / 23:03:41 / cg" |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
974 |
! |
af168e6dadc9
added #instVarNamed:ifAbsent:
Claus Gittinger <cg@exept.de>
parents:
1515
diff
changeset
|
975 |
|
359 | 976 |
instVarNamed:name put:value |
977 |
"set a non-indexed instance variable by name; |
|
978 |
peeking into an object this way is not very object oriented |
|
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
979 |
- if at all, use with care (provided for protocol completeness). |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
980 |
Notice, this access is very slow (because the classes instVar-description has to be |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
981 |
parsed ad runtime)" |
359 | 982 |
|
983 |
^ self instVarAt:(self class instVarOffsetOf:name) put:value |
|
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
984 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
985 |
" |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
986 |
|p| |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
987 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
988 |
p := Point x:10 y:20. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
989 |
p instVarNamed:'x' put:30. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
990 |
p |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
991 |
" |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
992 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
993 |
"Modified: 19.4.1996 / 11:12:49 / cg" |
1 | 994 |
! ! |
995 |
||
783 | 996 |
!Object methodsFor:'binary storage'! |
997 |
||
998 |
hasSpecialBinaryRepresentation |
|
999 |
"return true, if the receiver has a special binary representation; |
|
1000 |
default here is false, but can be redefined in class which provide |
|
1001 |
their own storeBinary/readBinary methods. |
|
1002 |
||
1003 |
Normal user classes should not use this, it is meant as a hook for |
|
1004 |
special classes such as True, False, UndefinedObject or SmallInteger. |
|
1005 |
||
1006 |
If your instances should be stored in a special way, see |
|
1007 |
#representBinaryOn: and #readBinaryContentsFromdata:manager:." |
|
1008 |
||
1009 |
^ false |
|
1 | 1010 |
! |
1011 |
||
783 | 1012 |
readBinaryContentsFrom:stream manager:manager |
1013 |
"reconstruct the receivers instance variables by reading a binary |
|
1014 |
binary representation from stream. |
|
1015 |
This is a general implementation, walking over instances |
|
1016 |
and loading each recursively using manager. |
|
1017 |
Redefined by some classes to read a more compact representations |
|
1018 |
(see String, SmallInteger etc). |
|
1019 |
||
1020 |
Notice, that the object is already recreated as an empty corps |
|
1021 |
with instance variables all nil and bit-instances (bytes, words etc.) |
|
1022 |
already read and restored. |
|
1023 |
||
1024 |
Also notice: this method is not called for if a private representation |
|
1025 |
has been stored (see representBinaryOn:). |
|
1026 |
In that case, #readBinaryContentsFromData:manager: is called, which |
|
1027 |
has to be reimplemented in the objects class." |
|
1028 |
||
1029 |
|size "{ Class: SmallInteger }" |
|
1030 |
instvarArray| |
|
1031 |
||
1032 |
stream next == 1 ifTrue:[ |
|
1033 |
"/ |
|
1034 |
"/ special representation ... |
|
1035 |
"/ |
|
1036 |
instvarArray := Array new:(size := stream nextNumber:3). |
|
1037 |
1 to:size do:[:i | |
|
1038 |
instvarArray basicAt:i put:(manager nextObject) |
|
1039 |
]. |
|
1040 |
self readBinaryContentsFromData:instvarArray manager:manager. |
|
1041 |
^ self |
|
1042 |
]. |
|
1043 |
||
1044 |
"/ |
|
1045 |
"/ standard representation |
|
1046 |
"/ |
|
1047 |
size := self basicSize. |
|
1048 |
size ~~ 0 ifTrue:[ |
|
1049 |
self class isPointers ifTrue:[ |
|
1050 |
1 to:size do:[:i | |
|
1051 |
self basicAt:i put:(manager nextObject) |
|
1052 |
] |
|
1053 |
] |
|
1054 |
]. |
|
1055 |
size := self class instSize. |
|
1056 |
1 to:size do:[:i | |
|
1057 |
self instVarAt:i put:(manager nextObject) |
|
1058 |
]. |
|
1059 |
! |
|
1060 |
||
1061 |
readBinaryContentsFromData:instvarArray manager:manager |
|
1062 |
"reconstruct the receivers instance variables by filling instance |
|
1063 |
variables with values from instvarArray. This array contains the instvars |
|
1064 |
as specified in #representBinaryOn: when the object was stored. |
|
1065 |
It is the receivers responsibility to set its instance variables in the |
|
1066 |
same order from that array." |
|
1067 |
||
1068 |
^ self subclassResponsibility |
|
1069 |
||
1070 |
"typical implementation (see also comment in #representBinaryOn:) |
|
1071 |
(for an object with foo, bar and baz as instance variables, |
|
1072 |
which did not store baz and wants baz to be reinitialized to |
|
1073 |
some constant string) |
|
1074 |
||
1075 |
foo := instvarArray at:1. |
|
1076 |
bar := instvarArray at:2. |
|
1077 |
baz := 'aConstant'. |
|
1078 |
" |
|
1079 |
! |
|
1080 |
||
1081 |
representBinaryOn:manager |
|
1082 |
"this method is called by the storage manager to ask objects |
|
1083 |
if they wish to provide their own binary representation. |
|
1084 |
||
1085 |
If they want to do so, they should return an array containing all |
|
1086 |
instance variables (named & indexed pointer) to be stored. |
|
1087 |
If not redefined, this method returns nil which means that all |
|
1088 |
instance variables are to be stored. |
|
1089 |
||
1090 |
It should be redefined in objects which do not want all instance variables |
|
1091 |
to be stored (for example: objects which keep references to a view etc.). |
|
1092 |
||
1093 |
If this is redefined returning non-nil, the corresponding class needs |
|
1094 |
a redefined instance method named #readBinaryContentsFromData:manager: |
|
1095 |
which has to fill the receivers named (and optionally indexed pointer) |
|
1096 |
instance variables with corresponding values from a data array." |
|
1097 |
||
1098 |
^ nil |
|
1099 |
||
1100 |
"typical implementation: |
|
1101 |
(see also comment in #readBinaryContentsFromData:manager:) |
|
1102 |
for an object with foo, bar and baz as instance variables, |
|
1103 |
which does not want to store baz: |
|
1104 |
||
1105 |
representBinaryOn:manager |
|
1106 |
|data| |
|
1107 |
||
1108 |
data := Array new:2. |
|
1109 |
data at:1 put:foo. |
|
1110 |
data at:2 put:bar. |
|
1111 |
^ data |
|
1112 |
" |
|
159 | 1113 |
! |
1114 |
||
783 | 1115 |
storeBinaryContentsFromData:instvarArray on:stream manager:manager |
1116 |
"store the instvars (both named & indexed pointer) |
|
1117 |
as returned by #representBinaryOn:." |
|
1118 |
||
1119 |
|size "{ Class: SmallInteger }"| |
|
1120 |
||
1121 |
size := instvarArray size. |
|
1122 |
1 to:size do:[:i | |
|
1123 |
manager putIdOf:(instvarArray at:i) on:stream |
|
1124 |
]. |
|
1125 |
! |
|
1126 |
||
1127 |
storeBinaryContentsOn:stream manager:manager |
|
1128 |
"store the receivers instance variables in a binary representation |
|
1129 |
on a stream using manager. |
|
1130 |
This is a general implementation, walking over instances |
|
1131 |
and storing each recursively using manager. |
|
1132 |
||
1133 |
Notice, that the objects definition and bit-instances (bytes, words etc.) |
|
1134 |
are already stored. |
|
1135 |
Here, we only have to deal with indexed-pointer and named instance variables. |
|
1136 |
||
1137 |
Also notice: this method is not called for if a private representation |
|
1138 |
has been stored (see representBinaryOn:). |
|
1139 |
In that case, #storeBinaryContentsFromData:manager: is called." |
|
1140 |
||
1141 |
|size "{ Class: SmallInteger }"| |
|
1142 |
||
1143 |
size := self basicSize. |
|
1144 |
size ~~ 0 ifTrue:[ |
|
1145 |
self class isPointers ifTrue:[ |
|
1146 |
1 to:size do:[:i | |
|
1147 |
manager putIdOf:(self basicAt:i) on:stream |
|
1148 |
]. |
|
1149 |
]. |
|
1150 |
]. |
|
1151 |
size := self class instSize. |
|
1152 |
1 to:size do:[:i | |
|
1153 |
manager putIdOf:(self instVarAt:i) on:stream |
|
1154 |
]. |
|
1 | 1155 |
! |
1156 |
||
783 | 1157 |
storeBinaryDefinitionBodyOn:stream manager:manager |
1158 |
"append a binary representation of the receivers body onto stream. |
|
1159 |
This is a general implementation walking over instances storing |
|
1160 |
each recursively as an ID using manager. |
|
1161 |
Can be redefined in subclasses." |
|
1162 |
||
1163 |
|basicSize "{ Class: SmallInteger }" |
|
1164 |
instSize "{ Class: SmallInteger }" |
|
1165 |
myClass specialRep pointers| |
|
1166 |
||
1167 |
myClass := self class. |
|
1168 |
instSize := myClass instSize. |
|
1169 |
||
1170 |
(pointers := myClass isPointers) ifTrue:[ |
|
1171 |
"/ |
|
1172 |
"/ inst size not needed - if you uncomment the line below, |
|
1173 |
"/ also uncomment the corresponding line in |
|
1174 |
"/ Object>>binaryDefinitionFrom:manager: |
|
1175 |
"/ |
|
1176 |
"/ stream nextPut:instSize. "mhmh this limits us to 255 named instvars" |
|
1177 |
||
1178 |
myClass isVariable ifTrue:[ |
|
1179 |
stream nextNumber:3 put:(basicSize := self basicSize) |
|
1180 |
] ifFalse:[ |
|
1181 |
basicSize := 0 |
|
1182 |
]. |
|
1183 |
] ifFalse: [ |
|
1184 |
stream nextNumber:4 put:(basicSize := self basicSize). |
|
1185 |
myClass isBytes ifTrue:[ |
|
1186 |
1 to:basicSize do:[:i | |
|
1187 |
stream nextPut:(self basicAt:i) |
|
1188 |
] |
|
1189 |
] ifFalse:[ |
|
1190 |
myClass isWords ifTrue:[ |
|
1191 |
1 to:basicSize do:[:i | |
|
1192 |
stream nextNumber:2 put:(self basicAt: i) |
|
1193 |
] |
|
1194 |
] ifFalse:[ |
|
1195 |
myClass isLongs ifTrue:[ |
|
1196 |
1 to:basicSize do:[:i | |
|
1197 |
stream nextNumber:4 put:(self basicAt: i) |
|
1198 |
] |
|
1199 |
] ifFalse:[ |
|
1200 |
myClass isFloats ifTrue:[ |
|
1201 |
"could do it in one big write on machines which use IEEE floats ..." |
|
1202 |
1 to:basicSize do:[:i | |
|
1203 |
Float storeBinaryIEEESingle:(self basicAt:i) on:stream |
|
1204 |
] |
|
1205 |
] ifFalse:[ |
|
1206 |
myClass isDoubles ifTrue:[ |
|
1207 |
"could do it in one big write on machines which use IEEE doubles ..." |
|
1208 |
1 to:basicSize do:[:i | |
|
1209 |
Float storeBinaryIEEEDouble:(self basicAt:i) on:stream |
|
1210 |
] |
|
1211 |
] ifFalse:[ |
|
1212 |
"/ should never be reached ... |
|
1213 |
1 to:basicSize do:[:i | |
|
1214 |
manager putIdOf:(self basicAt:i) on:stream |
|
1215 |
] |
|
1216 |
] |
|
1217 |
] |
|
1218 |
] |
|
1219 |
] |
|
1220 |
]. |
|
1221 |
]. |
|
1222 |
||
1223 |
(pointers or:[instSize ~~ 0]) ifTrue:[ |
|
1224 |
specialRep := self representBinaryOn:manager. |
|
1225 |
specialRep notNil ifTrue:[ |
|
1226 |
stream nextPut:1. "/ means: private representation follows |
|
1227 |
stream nextNumber:3 put:(specialRep basicSize). |
|
1228 |
self storeBinaryContentsFromData:specialRep on:stream manager:manager |
|
1229 |
] ifFalse:[ |
|
1230 |
stream nextPut:0. "/ means: full representation follows |
|
1231 |
self storeBinaryContentsOn:stream manager:manager |
|
159 | 1232 |
] |
1 | 1233 |
] |
783 | 1234 |
|
1235 |
"Modified: 25.10.1995 / 14:00:51 / cg" |
|
1 | 1236 |
! |
1237 |
||
783 | 1238 |
storeBinaryDefinitionOn:stream manager:manager |
1239 |
"append a binary representation of the receiver onto stream. |
|
1260 | 1240 |
This is an internal interface for binary storage mechanism. |
783 | 1241 |
This method first stores the class, then the body, which is done |
1242 |
in a separate method to allow redefinition of the bodies format. |
|
1243 |
Can be redefined in subclasses to write more compact representations |
|
1244 |
(see String, SmallInteger etc)." |
|
1245 |
||
1246 |
manager putIdOfClass:(self class) on:stream. |
|
1247 |
self storeBinaryDefinitionBodyOn:stream manager:manager |
|
1260 | 1248 |
|
1249 |
"Modified: 23.4.1996 / 09:31:12 / cg" |
|
783 | 1250 |
! |
1251 |
||
1252 |
storeBinaryOn:aStream |
|
1253 |
"Writes a description of the receiver onto aStream, in a way that allows |
|
1254 |
the object's structure to be reconstructed from the stream's contents" |
|
1255 |
||
1256 |
BinaryOutputManager store:self on:aStream |
|
899 | 1257 |
|
1258 |
" |
|
1259 |
|a s1 s2| |
|
1260 |
||
1261 |
s1 := 'hello'. |
|
1262 |
s2 := 'world'. |
|
1263 |
a := Array new:5. |
|
1264 |
a at:1 put:s1. |
|
1265 |
a at:2 put:s2. |
|
1266 |
a at:3 put:s1. |
|
1267 |
a at:4 put:s2. |
|
1268 |
a storeBinaryOn:'test.boss' |
|
1269 |
" |
|
1270 |
||
1271 |
" |
|
1272 |
(BinaryObjectStorage onOld:'test.boss' asFilename readStream) |
|
1273 |
next |
|
1274 |
inspect |
|
1275 |
" |
|
783 | 1276 |
! |
1277 |
||
1278 |
storeBinaryOn:stream manager:manager |
|
1279 |
"append a binary representation of the receiver onto stream." |
|
1280 |
||
1281 |
manager putIdOf:self on:stream |
|
1 | 1282 |
! ! |
1283 |
||
1826 | 1284 |
!Object methodsFor:'change & update'! |
1 | 1285 |
|
783 | 1286 |
broadcast:aSelectorSymbol |
1287 |
"send a message with selector aSelectorSymbol to all my dependents" |
|
1288 |
||
1289 |
self dependentsDo:[:dependent | |
|
1290 |
dependent perform:aSelectorSymbol |
|
1291 |
] |
|
1292 |
! |
|
1293 |
||
1294 |
broadcast:aSelectorSymbol with:anArgument |
|
1295 |
"send a message with selector aSelectorSymbol with an additional |
|
1296 |
argument anArgument to all my dependents." |
|
1297 |
||
1298 |
self dependentsDo:[:dependent | |
|
1299 |
dependent perform:aSelectorSymbol with:anArgument |
|
1300 |
] |
|
1301 |
! |
|
1302 |
||
159 | 1303 |
changeRequest |
1304 |
"the receiver wants to change - check if all dependents |
|
1305 |
grant the request, and return true if so" |
|
1306 |
||
1307 |
self dependentsDo:[:dependent | |
|
1308 |
dependent updateRequest ifFalse:[^ false]. |
|
1309 |
]. |
|
1310 |
^ true |
|
1311 |
! |
|
1312 |
||
1313 |
changeRequest:aParameter |
|
1314 |
"the receiver wants to change - check if all dependents |
|
1315 |
grant the request, and return true if so" |
|
1316 |
||
1317 |
self dependentsDo:[:dependent | |
|
1318 |
(dependent updateRequest:aParameter) ifFalse:[^ false]. |
|
1319 |
]. |
|
1320 |
^ true |
|
1321 |
! |
|
1322 |
||
783 | 1323 |
changeRequest:aParameter from:anObject |
1324 |
"the receiver wants to change - check if all dependents |
|
1325 |
except anObject grant the request, and return true if so. |
|
1326 |
The argument anObject is typically going to be the one who is |
|
1327 |
about to send the change request." |
|
1328 |
||
1329 |
self dependentsDo:[:dependent | |
|
1330 |
dependent == anObject ifFalse:[ |
|
1331 |
(dependent updateRequest:aParameter) ifFalse:[^ false]. |
|
1332 |
] |
|
1333 |
]. |
|
1334 |
^ true |
|
1335 |
! |
|
1336 |
||
159 | 1337 |
changeRequestFrom:anObject |
1338 |
"the receiver wants to change - check if all dependents |
|
202 | 1339 |
except anObject grant the request, and return true if so. |
1340 |
The argument anObject is typically going to be the one who is |
|
1341 |
about to send the change request." |
|
159 | 1342 |
|
1343 |
self dependentsDo:[:dependent | |
|
1344 |
dependent == anObject ifFalse:[ |
|
1345 |
(dependent updateRequest) ifFalse:[^ false]. |
|
1346 |
] |
|
1347 |
]. |
|
1348 |
^ true |
|
1349 |
! |
|
1350 |
||
1 | 1351 |
changed |
1352 |
"notify all dependents that the receiver has changed. |
|
71 | 1353 |
Each dependent gets a '#update:'-message with the original |
1354 |
receiver as argument." |
|
1 | 1355 |
|
159 | 1356 |
self changed:nil |
1 | 1357 |
! |
1358 |
||
1359 |
changed:aParameter |
|
1360 |
"notify all dependents that the receiver has changed somehow. |
|
71 | 1361 |
Each dependent gets a '#update:'-message with aParameter |
1362 |
as argument." |
|
1 | 1363 |
|
159 | 1364 |
self changed:aParameter with:nil |
1 | 1365 |
! |
1366 |
||
71 | 1367 |
changed:aParameter with:anArgument |
1 | 1368 |
"notify all dependents that the receiver has changed somehow. |
159 | 1369 |
Each dependent gets a '#update:with:from:'-message, with aParameter |
71 | 1370 |
and anArgument as arguments." |
1 | 1371 |
|
159 | 1372 |
self dependentsDo:[:dependent | |
1373 |
dependent update:aParameter with:anArgument from:self |
|
1 | 1374 |
] |
1375 |
! |
|
1376 |
||
1377 |
update:aParameter |
|
71 | 1378 |
"the message is sent to a dependent, when one of the objects |
1379 |
on whom the receiver depends, has changed. The argument aParameter |
|
1380 |
is either the changed object or the argument to the #changed: message. |
|
1381 |
||
1382 |
Default behavior here is to do nothing" |
|
1 | 1383 |
|
1384 |
^ self |
|
1385 |
! |
|
1386 |
||
1387 |
update:aParameter with:anArgument |
|
1388 |
"dependent is notified of some change - |
|
159 | 1389 |
Default is to try update:" |
1 | 1390 |
|
1391 |
^ self update:aParameter |
|
1392 |
! |
|
1393 |
||
1394 |
update:aParameter with:anArgument from:sender |
|
1395 |
"dependent is notified of some change - |
|
159 | 1396 |
Default is to try update:with:" |
1 | 1397 |
|
1398 |
^ self update:aParameter with:anArgument |
|
159 | 1399 |
! |
1400 |
||
1401 |
updateRequest |
|
1402 |
"return true, if an update request is granted. |
|
1403 |
Default here is to grant updates - may be used |
|
1404 |
to lock updates if someone is making other changes |
|
202 | 1405 |
from within an update. Or if someone has locked its |
1406 |
state and does not want others to change things. |
|
1407 |
However, these dependents must all honor the |
|
1408 |
changeRequest - ifTrue - change protocol. I.e. they |
|
1409 |
must first ask all others via changeRequest, and only do the change |
|
1410 |
it returns true. The others must decide in updateRequest and |
|
1411 |
return true if they think a change is ok." |
|
159 | 1412 |
|
1413 |
^ true |
|
1414 |
! |
|
1415 |
||
1416 |
updateRequest:aSymbol |
|
1417 |
"return true, if an update request is granted. |
|
1418 |
Default here a simple updateRequest" |
|
1419 |
||
1420 |
^ self updateRequest |
|
1 | 1421 |
! ! |
1422 |
||
783 | 1423 |
!Object methodsFor:'cleanup'! |
1424 |
||
1425 |
lowSpaceCleanup |
|
1426 |
"ignored here - redefined in some classes to |
|
1427 |
cleanup in low-memory situations" |
|
1428 |
||
1429 |
^ self |
|
1430 |
! ! |
|
1431 |
||
1432 |
!Object methodsFor:'comparing'! |
|
1433 |
||
1434 |
= anObject |
|
1435 |
"return true, if the receiver and the arg have the same structure" |
|
1436 |
||
1437 |
^ self == anObject |
|
1438 |
! |
|
1439 |
||
1440 |
== anObject |
|
2505 | 1441 |
"return true, if the receiver and the arg are the same object. |
1442 |
Never redefine this in any class. |
|
1443 |
The compilers generates inline code for it - redefinition is useless." |
|
783 | 1444 |
|
1445 |
%{ /* NOCONTEXT */ |
|
1446 |
||
1447 |
RETURN ( (self == anObject) ? true : false ); |
|
1448 |
%} |
|
1449 |
! |
|
1450 |
||
1451 |
hash |
|
1452 |
"return an Integer useful as a hash key for the receiver. |
|
1453 |
This hash should return same values for objects with same |
|
1454 |
contents (i.e. use this to hash on structure)" |
|
1455 |
||
1456 |
^ self identityHash |
|
1457 |
! |
|
1458 |
||
1459 |
identityHash |
|
1460 |
"return an Integer useful as a hash key for the receiver. |
|
1461 |
This hash should return same values for the same object (i.e. use |
|
1462 |
this to hash on identity of objects). |
|
1463 |
||
1464 |
We cannot use the Objects address (as other smalltalks do) since |
|
1465 |
no object-table exists and the hashval must not change when objects |
|
1466 |
are moved by the collector. Therefore we assign each object a unique |
|
1467 |
Id in the object header itself as its hashed upon. |
|
1468 |
(luckily we have 11 bits spare to do this - unluckily its only 11 bits). |
|
1469 |
Time will show, if 11 bits are enough; if not, another entry in the |
|
1470 |
object header will be needed, adding 4 bytes to every object. Alternatively, |
|
1471 |
hashed-upon objects could add an instvar containing the hash value." |
|
1472 |
||
1473 |
%{ /* NOCONTEXT */ |
|
1474 |
||
1475 |
REGISTER unsigned hash; |
|
1476 |
static unsigned nextHash = 0; |
|
1477 |
||
1478 |
if (__isNonNilObject(self)) { |
|
1479 |
hash = __GET_HASH(self); |
|
1480 |
if (hash == 0) { |
|
2462
5ba287e9f5bf
slightly faster identityHash
Claus Gittinger <cg@exept.de>
parents:
2448
diff
changeset
|
1481 |
/* has no hash yet */ |
5ba287e9f5bf
slightly faster identityHash
Claus Gittinger <cg@exept.de>
parents:
2448
diff
changeset
|
1482 |
|
2480 | 1483 |
if (++nextHash > __MAX_HASH__) { |
1484 |
nextHash = 1; |
|
2462
5ba287e9f5bf
slightly faster identityHash
Claus Gittinger <cg@exept.de>
parents:
2448
diff
changeset
|
1485 |
} |
2480 | 1486 |
hash = nextHash; |
783 | 1487 |
__SET_HASH(self, hash); |
1488 |
} |
|
1489 |
||
1490 |
/* |
|
1491 |
* now, we got 11 bits for hashing; |
|
1492 |
* make it as large as possible; since most hashers use the returned |
|
1493 |
* key and take it modulu some prime number, this will allow for |
|
1494 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
1495 |
*/ |
|
2480 | 1496 |
hash = __MAKE_HASH__(hash); |
2462
5ba287e9f5bf
slightly faster identityHash
Claus Gittinger <cg@exept.de>
parents:
2448
diff
changeset
|
1497 |
RETURN ( __MKSMALLINT(hash) ); |
783 | 1498 |
} |
1499 |
%}. |
|
1500 |
^ 0 "never reached, since redefined in UndefinedObject and SmallInteger" |
|
1501 |
! |
|
1502 |
||
2479
6d9c516e04d8
added special hash for binaryStorage
Claus Gittinger <cg@exept.de>
parents:
2478
diff
changeset
|
1503 |
identityHashForBinaryStore |
6d9c516e04d8
added special hash for binaryStorage
Claus Gittinger <cg@exept.de>
parents:
2478
diff
changeset
|
1504 |
"hash which is usable if the object does not change its class |
6d9c516e04d8
added special hash for binaryStorage
Claus Gittinger <cg@exept.de>
parents:
2478
diff
changeset
|
1505 |
and does not #become something else, while the hash is used. |
6d9c516e04d8
added special hash for binaryStorage
Claus Gittinger <cg@exept.de>
parents:
2478
diff
changeset
|
1506 |
This is only used by the binary storage mechanism, during the |
6d9c516e04d8
added special hash for binaryStorage
Claus Gittinger <cg@exept.de>
parents:
2478
diff
changeset
|
1507 |
object writing phase." |
6d9c516e04d8
added special hash for binaryStorage
Claus Gittinger <cg@exept.de>
parents:
2478
diff
changeset
|
1508 |
|
6d9c516e04d8
added special hash for binaryStorage
Claus Gittinger <cg@exept.de>
parents:
2478
diff
changeset
|
1509 |
%{ /* NOCONTEXT */ |
6d9c516e04d8
added special hash for binaryStorage
Claus Gittinger <cg@exept.de>
parents:
2478
diff
changeset
|
1510 |
|
6d9c516e04d8
added special hash for binaryStorage
Claus Gittinger <cg@exept.de>
parents:
2478
diff
changeset
|
1511 |
REGISTER unsigned hash, hash1, hash2, sz; |
6d9c516e04d8
added special hash for binaryStorage
Claus Gittinger <cg@exept.de>
parents:
2478
diff
changeset
|
1512 |
OBJ o; |
6d9c516e04d8
added special hash for binaryStorage
Claus Gittinger <cg@exept.de>
parents:
2478
diff
changeset
|
1513 |
static unsigned nextHash = 0; |
2480 | 1514 |
static unsigned nextClassHash = 0; |
2479
6d9c516e04d8
added special hash for binaryStorage
Claus Gittinger <cg@exept.de>
parents:
2478
diff
changeset
|
1515 |
|
6d9c516e04d8
added special hash for binaryStorage
Claus Gittinger <cg@exept.de>
parents:
2478
diff
changeset
|
1516 |
if (__isNonNilObject(self)) { |
2647 | 1517 |
/* |
1518 |
* my own identityHash |
|
1519 |
*/ |
|
1520 |
hash1 = __GET_HASH(self); |
|
1521 |
if (hash1 == 0) { |
|
1522 |
/* has no hash yet */ |
|
1523 |
||
1524 |
if (++nextHash > __MAX_HASH__) { |
|
1525 |
nextHash = 1; |
|
1526 |
} |
|
1527 |
hash1 = nextHash; |
|
1528 |
__SET_HASH(self, hash1); |
|
1529 |
} |
|
1530 |
/* |
|
1531 |
* my classes identityHash |
|
1532 |
*/ |
|
1533 |
o = __qClass(self); |
|
1534 |
hash2 = __GET_HASH(o); |
|
1535 |
if (hash2 == 0) { |
|
1536 |
/* has no hash yet */ |
|
1537 |
||
1538 |
if (++nextClassHash > __MAX_HASH__) { |
|
1539 |
nextClassHash = 1; |
|
1540 |
} |
|
1541 |
hash2 = nextClassHash; |
|
1542 |
__SET_HASH(o, hash2); |
|
1543 |
} |
|
1544 |
||
1545 |
/* |
|
1546 |
* some bits of my size |
|
1547 |
*/ |
|
1548 |
sz = __qSize(self); |
|
1549 |
||
1550 |
/* |
|
1551 |
* now, we got 11 + 11 + 8 bits for hashing; |
|
1552 |
* make it as large as possible; since most hashers use the returned |
|
1553 |
* key and take it modulu some prime number, this will allow for |
|
1554 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
1555 |
*/ |
|
1556 |
hash = (hash1 << 11) | hash2; /* 22 bits */ |
|
1557 |
hash = (hash << 8) | (sz & 0xFC); /* 30 bits */ |
|
1558 |
||
1559 |
while ((hash & 0x20000000) == 0) { |
|
1560 |
hash <<= 1; |
|
1561 |
} |
|
1562 |
||
1563 |
RETURN ( __MKSMALLINT(hash) ); |
|
2479
6d9c516e04d8
added special hash for binaryStorage
Claus Gittinger <cg@exept.de>
parents:
2478
diff
changeset
|
1564 |
} |
6d9c516e04d8
added special hash for binaryStorage
Claus Gittinger <cg@exept.de>
parents:
2478
diff
changeset
|
1565 |
%}. |
2480 | 1566 |
^ nil "never reached, since UndefinedObject and SmallInteger are not hashed upon in binary storage" |
2479
6d9c516e04d8
added special hash for binaryStorage
Claus Gittinger <cg@exept.de>
parents:
2478
diff
changeset
|
1567 |
! |
6d9c516e04d8
added special hash for binaryStorage
Claus Gittinger <cg@exept.de>
parents:
2478
diff
changeset
|
1568 |
|
783 | 1569 |
isNil |
1570 |
"return true, if the receiver is nil" |
|
1571 |
||
1572 |
^ false |
|
1573 |
! |
|
1574 |
||
1575 |
notNil |
|
1576 |
"return true, if the receiver is not nil" |
|
1577 |
||
1578 |
^ true |
|
1579 |
! |
|
1580 |
||
1581 |
~= anObject |
|
1582 |
"return true, if the receiver and the arg do not have the same structure" |
|
1583 |
||
1584 |
^ (self = anObject) not |
|
1585 |
! |
|
1586 |
||
1587 |
~~ anObject |
|
2505 | 1588 |
"return true, if the receiver and the arg are not the same object. |
1589 |
Never redefine this in any class. |
|
1590 |
The compilers generates inline code for it - redefinition is useless." |
|
783 | 1591 |
|
1592 |
%{ /* NOCONTEXT */ |
|
1593 |
RETURN ( (self == anObject) ? false : true ); |
|
1594 |
%} |
|
1595 |
! ! |
|
1596 |
||
1597 |
!Object methodsFor:'converting'! |
|
1598 |
||
1599 |
asValue |
|
1600 |
"return a valueHolder for for the receiver" |
|
1601 |
||
1602 |
^ ValueHolder with:self |
|
1603 |
! ! |
|
1604 |
||
1605 |
!Object methodsFor:'copying'! |
|
1606 |
||
1607 |
copy |
|
1608 |
"return a copy of the receiver - defaults to shallowcopy here. |
|
1609 |
Notice, that copy does not copy dependents." |
|
1610 |
||
1611 |
^ self shallowCopy postCopy |
|
1612 |
! |
|
1613 |
||
1614 |
deepCopy |
|
1615 |
"return a copy of the object with all subobjects also copied. |
|
1616 |
This method DOES handle cycles/self-refs; however the receivers |
|
1617 |
class is not copied (to avoid the 'total' copy). |
|
1618 |
This deepCopy is a bit slower than the old (unsecure) one, since it |
|
1619 |
keeps track of already copied objects. If you are sure, that your |
|
1129 | 1620 |
copied object does not include duplicates (or you do not care) and |
783 | 1621 |
no cycles, you can use the old simpleDeepCopy, which avoids this overhead, |
1622 |
but may run into trouble. |
|
1623 |
Notice, that copy does not copy dependents." |
|
1624 |
||
1625 |
^ self deepCopyUsing:(IdentityDictionary new) |
|
1626 |
||
1627 |
"an example which is not handled by the old deepCopy: |
|
1628 |
||
1629 |
|a| |
|
1630 |
a := Array new:3. |
|
1631 |
a at:3 put:a. |
|
1632 |
a deepCopy inspect |
|
1633 |
" |
|
1129 | 1634 |
|
1635 |
"Modified: 27.3.1996 / 16:31:20 / stefan" |
|
783 | 1636 |
! |
1637 |
||
1638 |
deepCopyError |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
1639 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
1640 |
|
783 | 1641 |
"raise a signal, that deepCopy is not allowed for this object" |
1642 |
||
1643 |
^ DeepCopyErrorSignal raise |
|
1644 |
! |
|
1645 |
||
1646 |
deepCopyUsing:aDictionary |
|
1647 |
"a helper for deepCopy; return a copy of the object with |
|
1648 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
1649 |
use the value found there. The class of the receiver is not copied. |
|
1650 |
This method DOES handle cycles/self references." |
|
1651 |
||
1652 |
|myClass aCopy |
|
1653 |
sz "{ Class: SmallInteger }" |
|
1654 |
iOrig iCopy| |
|
1655 |
||
1656 |
myClass := self class. |
|
1657 |
myClass isVariable ifTrue:[ |
|
1658 |
sz := self basicSize. |
|
1659 |
aCopy := myClass basicNew:sz. |
|
1660 |
] ifFalse:[ |
|
1661 |
sz := 0. |
|
1662 |
aCopy := myClass basicNew |
|
1663 |
]. |
|
1664 |
aCopy setHashFrom:self. |
|
1665 |
||
1666 |
aDictionary at:self put:aCopy. |
|
143 | 1667 |
|
1668 |
" |
|
783 | 1669 |
copy indexed instvars - if any |
1670 |
" |
|
1671 |
sz ~~ 0 ifTrue:[ |
|
1672 |
myClass isBits ifTrue:[ |
|
1673 |
"block-copy indexed instvars" |
|
1674 |
aCopy replaceFrom:1 to:sz with:self startingAt:1 |
|
1675 |
] ifFalse:[ |
|
1676 |
"individual deep copy the indexed variables" |
|
1677 |
1 to:sz do:[:i | |
|
1678 |
iOrig := self basicAt:i. |
|
1679 |
iOrig notNil ifTrue:[ |
|
1680 |
(aDictionary includesKey:iOrig) ifTrue:[ |
|
1681 |
iCopy := aDictionary at:iOrig |
|
1682 |
] ifFalse:[ |
|
1683 |
iCopy := iOrig deepCopyUsing:aDictionary. |
|
1684 |
]. |
|
1685 |
aCopy basicAt:i put:iCopy |
|
1686 |
] |
|
1687 |
] |
|
1688 |
] |
|
1689 |
]. |
|
1690 |
||
1691 |
" |
|
1692 |
copy the instance variables |
|
1693 |
" |
|
1694 |
sz := myClass instSize. |
|
1695 |
sz ~~ 0 ifTrue:[ |
|
1696 |
1 to:sz do:[:i | |
|
1697 |
iOrig := self instVarAt:i. |
|
1698 |
iOrig notNil ifTrue:[ |
|
1699 |
(aDictionary includesKey:iOrig) ifTrue:[ |
|
1700 |
iCopy := aDictionary at:iOrig |
|
1701 |
] ifFalse:[ |
|
1702 |
iCopy := iOrig deepCopyUsing:aDictionary. |
|
1703 |
]. |
|
1704 |
aCopy instVarAt:i put:iCopy |
|
1705 |
] |
|
1706 |
]. |
|
1707 |
]. |
|
1708 |
||
1709 |
^ aCopy |
|
1710 |
! |
|
1711 |
||
1712 |
postCopy |
|
1713 |
"this is for compatibility with ST-80 code, which uses postCopy for |
|
1714 |
cleanup after copying, while ST/X passes the original in postCopyFrom: |
|
1715 |
(see there)" |
|
1716 |
||
1717 |
^ self |
|
1718 |
! |
|
1719 |
||
1720 |
postCopyFrom:original |
|
1721 |
"sent to a freshly deep-copied object to give it a chance to adjust things. |
|
1722 |
(a font could flush its device-handle for example). |
|
1723 |
Notice, that for Sets/Dicts etc. a rehash is not needed, since the deepCopy |
|
1724 |
will have the same hash key as the receiver (as long as ST/X provides the |
|
1725 |
setHash: functionality)." |
|
1726 |
||
1727 |
"for ST-80 compatibility, we try postCopy here ..." |
|
1728 |
^ self postCopy |
|
1729 |
! |
|
1730 |
||
1731 |
setHashFrom:anObject |
|
1732 |
"set my identity-hash key to be the same as anObjects hash key. |
|
1733 |
This is an ST/X speciality, which is NOT available in other (especially OT based) |
|
1734 |
Smalltalks, and may not be available in future ST/X versions. |
|
1735 |
DO NEVER use this for normal application code." |
|
1736 |
||
1737 |
%{ /* NOCONTEXT */ |
|
1738 |
||
1739 |
REGISTER unsigned h; |
|
1740 |
||
1741 |
if (__isNonNilObject(self) && __isNonNilObject(anObject)) { |
|
1742 |
h = __GET_HASH(anObject); |
|
1743 |
__SET_HASH(self, h); |
|
1744 |
RETURN (self); |
|
1745 |
} |
|
2647 | 1746 |
%}. |
783 | 1747 |
self primitiveFailed "neither receiver not arg may be nil or SmallInteger" |
1748 |
! |
|
1749 |
||
1750 |
shallowCopy |
|
1751 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
1752 |
i.e. the copy shares referenced instvars with its original." |
|
1753 |
||
2647 | 1754 |
%{ /* NOCONTEXT */ |
1755 |
int ninsts, spc; |
|
1756 |
int sz; |
|
1757 |
OBJ slf, theCopy; |
|
1758 |
OBJ cls; |
|
1759 |
int flags; |
|
1760 |
||
2651
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1761 |
cls = __qClass(self); |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1762 |
flags = __intVal(__ClassInstPtr(cls)->c_flags); |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1763 |
|
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1764 |
/* |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1765 |
* bail out for special objects .. |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1766 |
*/ |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1767 |
if (((flags & ~ARRAYMASK) == 0) |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1768 |
&& ((flags & ARRAYMASK) != WKPOINTERARRAY)) { |
2652 | 1769 |
sz = __qSize(self); |
2651
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1770 |
__PROTECT2__(self, cls); |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1771 |
__qNew(theCopy, sz); |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1772 |
__UNPROTECT2__(cls, slf); |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1773 |
if (theCopy) { |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1774 |
spc = __qSpace(theCopy); |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1775 |
|
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1776 |
theCopy->o_class = cls; __STORE_SPC(theCopy, cls, spc); |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1777 |
|
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1778 |
sz = sz - OHDR_SIZE; |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1779 |
if (sz) { |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1780 |
char *src, *dst; |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1781 |
|
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1782 |
src = (char *)(__InstPtr(slf)->i_instvars); |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1783 |
dst = (char *)(__InstPtr(theCopy)->i_instvars); |
2647 | 1784 |
#ifdef bcopy4 |
2651
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1785 |
{ |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1786 |
/* care for odd-number of longs */ |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1787 |
int nW = sz >> 2; |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1788 |
|
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1789 |
if (sz & 3) { |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1790 |
nW++; |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1791 |
} |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1792 |
|
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1793 |
bcopy4(src, dst, nW); |
2647 | 1794 |
} |
1795 |
#else |
|
2651
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1796 |
bcopy(src, dst, sz); |
2647 | 1797 |
#endif |
1798 |
||
2651
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1799 |
flags &= ARRAYMASK; |
2652 | 1800 |
if (flags == POINTERARRAY) { |
2651
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1801 |
ninsts = __BYTES2OBJS__(sz); |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1802 |
} else { |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1803 |
ninsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1804 |
} |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1805 |
if (ninsts) { |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1806 |
do { |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1807 |
OBJ el; |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1808 |
|
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1809 |
el = __InstPtr(theCopy)->i_instvars[ninsts-1]; |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1810 |
__STORE_SPC(theCopy, el, spc); |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1811 |
} while (--ninsts); |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1812 |
} |
2647 | 1813 |
} |
2651
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1814 |
RETURN (theCopy); |
2647 | 1815 |
} |
1816 |
} |
|
1817 |
%}. |
|
2651
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1818 |
"/ fallBack for special objects & memoryAllocation failure case |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1819 |
|
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1820 |
^ self slowShallowCopy |
783 | 1821 |
! |
1822 |
||
1823 |
shallowCopyForFinalization |
|
1824 |
"this is used to aquire a copy to be used for finalization - |
|
1825 |
(the copy will get a dispose-notification; see the documentation in the Registry class) |
|
1826 |
This method can be redefined for more efficient copying - especially for large objects." |
|
1827 |
||
1828 |
^ self shallowCopy |
|
1829 |
! |
|
1830 |
||
1831 |
simpleDeepCopy |
|
1832 |
"return a copy of the object with all subobjects also copied. |
|
1833 |
This method does NOT handle cycles - but is included to allow this |
|
1834 |
slightly faster copy in situations where it is known that |
|
1835 |
no recursive references occur (LargeIntegers for example). |
|
1836 |
NOTICE: you will run into trouble, when trying this with recursive |
|
1837 |
objects (usually recursionInterrupt or memory-alert). |
|
1838 |
This method corresponds to the 'traditional' deepCopy found in |
|
1839 |
the Blue book." |
|
1840 |
||
1841 |
|myClass aCopy |
|
1842 |
sz "{ Class: SmallInteger }" | |
|
1843 |
||
1844 |
myClass := self class. |
|
1845 |
myClass isVariable ifTrue:[ |
|
1846 |
sz := self basicSize. |
|
1847 |
aCopy := myClass basicNew:sz. |
|
1848 |
||
1849 |
"copy the indexed variables" |
|
1850 |
1 to:sz do:[:i | |
|
1851 |
aCopy basicAt:i put:((self basicAt:i) simpleDeepCopy) |
|
1852 |
] |
|
1853 |
] ifFalse:[ |
|
1854 |
aCopy := myClass basicNew |
|
1855 |
]. |
|
1856 |
||
1857 |
"copy the instance variables" |
|
1858 |
sz := myClass instSize. |
|
1859 |
1 to:sz do:[:i | |
|
1860 |
aCopy instVarAt:i put:((self instVarAt:i) simpleDeepCopy) |
|
1861 |
]. |
|
1862 |
||
1863 |
^ aCopy |
|
1864 |
||
1865 |
"a bad example (but ST/X should survive ...)" |
|
1866 |
" |
|
1867 |
|a| |
|
1868 |
a := Array new:3. |
|
1869 |
a at:3 put:a. |
|
1870 |
a simpleDeepCopy |
|
1871 |
" |
|
2651
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1872 |
! |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1873 |
|
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1874 |
slowShallowCopy |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1875 |
"return a copy of the object with shared subobjects (a shallow copy) |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1876 |
i.e. the copy shares referenced instvars with its original. |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1877 |
This method is only invoked as a fallback from #shallowCopy." |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1878 |
|
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1879 |
|myClass aCopy |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1880 |
sz "{ Class: SmallInteger }" | |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1881 |
|
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1882 |
myClass := self class. |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1883 |
myClass isVariable ifTrue:[ |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1884 |
sz := self basicSize. |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1885 |
aCopy := myClass basicNew:sz. |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1886 |
|
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1887 |
"copy the indexed variables" |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1888 |
1 to:sz do:[:i | |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1889 |
aCopy basicAt:i put:(self basicAt:i) |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1890 |
] |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1891 |
] ifFalse:[ |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1892 |
aCopy := myClass basicNew |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1893 |
]. |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1894 |
|
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1895 |
"copy the instance variables" |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1896 |
sz := myClass instSize. |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1897 |
1 to:sz do:[:i | |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1898 |
aCopy instVarAt:i put:(self instVarAt:i) |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1899 |
]. |
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1900 |
|
63087903a3e0
oops - shallowCopy was wrong
Claus Gittinger <cg@exept.de>
parents:
2647
diff
changeset
|
1901 |
^ aCopy |
783 | 1902 |
! ! |
1903 |
||
1904 |
!Object methodsFor:'debugging'! |
|
1905 |
||
1906 |
basicInspect |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
1907 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
1908 |
|
783 | 1909 |
"launch an inspector on the receiver. |
1910 |
this method should NOT be redefined in subclasses." |
|
1911 |
||
1912 |
Inspector isNil ifTrue:[ |
|
2647 | 1913 |
" |
1914 |
for systems without GUI |
|
1915 |
" |
|
1916 |
Transcript showCR:'no Inspector' |
|
783 | 1917 |
] ifFalse:[ |
2647 | 1918 |
Inspector openOn:self |
783 | 1919 |
] |
1417 | 1920 |
|
1921 |
"Modified: 18.5.1996 / 15:43:25 / cg" |
|
783 | 1922 |
! |
1923 |
||
1924 |
inspect |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
1925 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
1926 |
|
783 | 1927 |
"launch an inspector on the receiver. |
1928 |
this method (or better: inspectorClass) can be redefined in subclasses |
|
1929 |
to start special inspectors." |
|
1930 |
||
1931 |
|cls| |
|
1932 |
||
1933 |
cls := self inspectorClass. |
|
1934 |
cls isNil ifTrue:[ |
|
1935 |
^ self basicInspect |
|
1936 |
]. |
|
1937 |
cls openOn:self |
|
1938 |
||
1939 |
" |
|
1940 |
Object new inspect |
|
1941 |
(1 @ 2) inspect |
|
1942 |
Smalltalk inspect |
|
1943 |
#(1 2 3) asOrderedCollection inspect |
|
1944 |
(Color red) inspect |
|
1945 |
(Image fromFile:'bitmaps/garfield.gif') inspect |
|
143 | 1946 |
" |
71 | 1947 |
! |
1948 |
||
783 | 1949 |
inspectorClass |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
1950 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
1951 |
|
783 | 1952 |
"return the class to use for inspect. |
1953 |
Can (should) be redefined in classes for which a better inspector is available" |
|
1954 |
||
1955 |
^ Inspector |
|
1956 |
! |
|
1957 |
||
1958 |
mustBeKindOf:aClass |
|
1959 |
"for compatibility & debugging support: |
|
1960 |
check if the receiver isKindOf:aClass and raise an error if not. |
|
1961 |
Notice: |
|
1962 |
it is VERY questionable, if it makes sense to add manual |
|
1963 |
type checks to a dynamically typed language like smalltalk. |
|
1964 |
It will, at least, slow down performance, |
|
1965 |
make your code less reusable and clutter your code with stupid sends |
|
1966 |
of this selector. Also, read the comment in isKindOf:, regarding the |
|
1967 |
use of isXXX check methods. |
|
1968 |
You see: The author does not like this at all ..." |
|
1969 |
||
1970 |
(self isKindOf:aClass) ifFalse:[ |
|
1971 |
self error:'argument is not of expected type' |
|
1972 |
] |
|
1973 |
! |
|
1974 |
||
1975 |
obsoleteMethodWarning |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
1976 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
1977 |
|
783 | 1978 |
"in methods which are going to be obsoleted, a self send to |
1979 |
this method is used to tell programmers that a method is |
|
1980 |
used which is going to be removed in later ST/X versions. |
|
1981 |
Find all methods which will be obsolete soon by looking at senders |
|
1982 |
of this message. |
|
1983 |
Hopefully, this warning message is annoying enough for you to |
|
1984 |
change the code ... ;-)" |
|
1985 |
||
1986 |
self obsoleteMethodWarning:nil from:thisContext sender |
|
1987 |
! |
|
1988 |
||
1989 |
obsoleteMethodWarning:message |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
1990 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
1991 |
|
783 | 1992 |
"in methods which are going to be obsoleted, a self send to |
1993 |
this method is used to tell programmers that a method is |
|
1994 |
used which is going to be removed in later ST/X versions. |
|
1995 |
Find all methods which will be obsolete soon by looking at senders |
|
1996 |
of this message. |
|
1997 |
Hopefully, this warning message is annoying enough for you to |
|
1998 |
change the code ... ;-)" |
|
1999 |
||
2000 |
self obsoleteMethodWarning:message from:thisContext sender |
|
2001 |
! |
|
2002 |
||
2003 |
obsoleteMethodWarning:message from:aContext |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2004 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2005 |
|
783 | 2006 |
"in methods which are going to be obsoleted, a self-send to |
2007 |
this method is used to tell programmers that a method is |
|
2008 |
used which is going to be removed in later ST/X versions. |
|
2009 |
Find all methods which will be obsolete soon by looking at senders |
|
2010 |
of this message. |
|
2011 |
Hopefully, this warning message is annoying enough for you to |
|
2012 |
change the code ... ;-)" |
|
2013 |
||
2014 |
|spec| |
|
2015 |
||
2016 |
spec := aContext methodPrintString. |
|
2136 | 2017 |
('WARNING: the ''' , spec , ''' method is obsolete.') errorPrintCR. |
2018 |
(' And may not be present in future ST/X versions.') errorPrintCR. |
|
2019 |
(' called from ' , aContext sender printString) errorPrintCR. |
|
783 | 2020 |
message notNil ifTrue:[ |
2647 | 2021 |
'------> ' errorPrint. message errorPrintCR |
783 | 2022 |
] |
2023 |
||
2024 |
" |
|
2025 |
Object obsoleteMethodWarning:'foo' from:thisContext sender sender |
|
2026 |
" |
|
2136 | 2027 |
|
2028 |
"Modified: 10.1.1997 / 19:08:42 / cg" |
|
783 | 2029 |
! ! |
2030 |
||
2031 |
!Object methodsFor:'dependents access'! |
|
2032 |
||
2033 |
addDependent:anObject |
|
2034 |
"make the argument, anObject be a dependent of the receiver" |
|
2035 |
||
1585
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2036 |
|wasBlocked| |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2037 |
|
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2038 |
"/ must do this save from interrupts, since the dependents collection |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2039 |
"/ is possibly accessed from multiple threads. |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2040 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2041 |
"/ faster execution. |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2042 |
|
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2043 |
wasBlocked := OperatingSystem blockInterrupts. |
863
2c83fe958ca7
change dependencies uninterruptably
Claus Gittinger <cg@exept.de>
parents:
861
diff
changeset
|
2044 |
[ |
2647 | 2045 |
|deps dep| |
2046 |
||
2047 |
deps := self dependents. |
|
2048 |
||
2049 |
"/ to save a fair amount of memory in case of |
|
2050 |
"/ many dependencies, we store a single dependent in |
|
2051 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
2052 |
"/ added. |
|
2053 |
||
2054 |
deps isNil ifTrue:[ |
|
2055 |
self dependents:(WeakArray with:anObject) |
|
2056 |
] ifFalse:[ |
|
2057 |
deps class == WeakArray ifTrue:[ |
|
2058 |
dep := deps at:1. |
|
2059 |
dep ~~ anObject ifTrue:[ |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1762
diff
changeset
|
2060 |
(dep isNil or:[dep == 0]) ifTrue:[ |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1762
diff
changeset
|
2061 |
deps at:1 put:anObject |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1762
diff
changeset
|
2062 |
] ifFalse:[ |
2647 | 2063 |
self dependents:(WeakIdentitySet with:dep with:anObject) |
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1762
diff
changeset
|
2064 |
] |
2647 | 2065 |
] |
2066 |
] ifFalse:[ |
|
2067 |
deps add:anObject |
|
2068 |
] |
|
2069 |
] |
|
1585
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2070 |
] valueNowOrOnUnwindDo:[ |
2647 | 2071 |
wasBlocked ifFalse:[ |
2072 |
OperatingSystem unblockInterrupts |
|
2073 |
] |
|
1585
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2074 |
] |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2075 |
|
1624
50c5849dc9d4
mhmh - care for dependent being already in the array,
Claus Gittinger <cg@exept.de>
parents:
1611
diff
changeset
|
2076 |
"Modified: 1.8.1996 / 14:21:20 / cg" |
783 | 2077 |
! |
2078 |
||
2079 |
dependents |
|
2080 |
"return a Collection of dependents - nil if there is none. |
|
1231
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2081 |
The default implementation here uses a global WeakDictionary to store |
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2082 |
dependents |
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2083 |
This may be too slow for high frequency change&update, |
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2084 |
therefore, some classes (Model) redefine this for better performance. |
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2085 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
783 | 2086 |
|
2087 |
^ Dependencies at:self ifAbsent:[nil] |
|
1231
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2088 |
|
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2089 |
"Modified: 19.4.1996 / 12:36:46 / cg" |
783 | 2090 |
! |
2091 |
||
2092 |
dependents:aCollection |
|
2093 |
"set the collection of dependents. |
|
2094 |
The default implementation here uses a global Dictionary to store |
|
2095 |
dependents which may be too slow for high frequency change&update. |
|
2096 |
Therefore, some classes (Model) redefine this for better performance." |
|
2097 |
||
1624
50c5849dc9d4
mhmh - care for dependent being already in the array,
Claus Gittinger <cg@exept.de>
parents:
1611
diff
changeset
|
2098 |
"/ must do this save from interrupts, since the dependents collection |
50c5849dc9d4
mhmh - care for dependent being already in the array,
Claus Gittinger <cg@exept.de>
parents:
1611
diff
changeset
|
2099 |
"/ is possibly accessed from multiple threads. |
50c5849dc9d4
mhmh - care for dependent being already in the array,
Claus Gittinger <cg@exept.de>
parents:
1611
diff
changeset
|
2100 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
2336 | 2101 |
"/ faster execution (and to avoid creation of garbage blocks). |
2102 |
||
2103 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
2647 | 2104 |
"/ the common case - already blocked |
2105 |
||
2106 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
2107 |
Dependencies removeKey:self ifAbsent:[] |
|
2108 |
] ifFalse:[ |
|
2109 |
Dependencies at:self put:aCollection |
|
2110 |
]. |
|
2111 |
^ self |
|
2336 | 2112 |
]. |
2113 |
||
863
2c83fe958ca7
change dependencies uninterruptably
Claus Gittinger <cg@exept.de>
parents:
861
diff
changeset
|
2114 |
[ |
2647 | 2115 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
2116 |
Dependencies removeKey:self ifAbsent:[] |
|
2117 |
] ifFalse:[ |
|
2118 |
Dependencies at:self put:aCollection |
|
2119 |
]. |
|
1624
50c5849dc9d4
mhmh - care for dependent being already in the array,
Claus Gittinger <cg@exept.de>
parents:
1611
diff
changeset
|
2120 |
] valueNowOrOnUnwindDo:[ |
2647 | 2121 |
OperatingSystem unblockInterrupts |
1624
50c5849dc9d4
mhmh - care for dependent being already in the array,
Claus Gittinger <cg@exept.de>
parents:
1611
diff
changeset
|
2122 |
] |
50c5849dc9d4
mhmh - care for dependent being already in the array,
Claus Gittinger <cg@exept.de>
parents:
1611
diff
changeset
|
2123 |
|
2336 | 2124 |
"Modified: 30.1.1997 / 21:22:10 / cg" |
783 | 2125 |
! |
2126 |
||
2127 |
dependentsDo:aBlock |
|
2128 |
"evaluate aBlock for all of my dependents" |
|
2129 |
||
1231
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2130 |
|deps nwDeps| |
783 | 2131 |
|
2132 |
deps := self dependents. |
|
2133 |
deps notNil ifTrue:[ |
|
2647 | 2134 |
deps do:[:d | |
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1762
diff
changeset
|
2135 |
(d notNil and:[d ~~ 0]) ifTrue:[ |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1762
diff
changeset
|
2136 |
aBlock value:d |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1762
diff
changeset
|
2137 |
] |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1762
diff
changeset
|
2138 |
] |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2139 |
]. |
1231
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2140 |
nwDeps := self nonWeakDependents. |
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2141 |
(nwDeps notNil and:[nwDeps ~~ deps]) ifTrue:[ |
2647 | 2142 |
nwDeps do:aBlock |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2143 |
]. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2144 |
|
1231
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2145 |
"Modified: 19.4.1996 / 12:35:54 / cg" |
1098
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1097
diff
changeset
|
2146 |
! |
e8543399e2a0
support aspect-specific interests
Claus Gittinger <cg@exept.de>
parents:
1097
diff
changeset
|
2147 |
|
2445 | 2148 |
myDependents |
2149 |
"same as dependents - ST-80 compatibility" |
|
2150 |
||
2151 |
^ self dependents |
|
2152 |
! |
|
2153 |
||
783 | 2154 |
release |
2155 |
"remove all dependencies from the receiver" |
|
2156 |
||
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2157 |
self dependents:nil. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2158 |
self nonWeakDependents:nil |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2159 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2160 |
"Modified: 19.4.1996 / 10:55:36 / cg" |
783 | 2161 |
! |
2162 |
||
2163 |
removeDependent:anObject |
|
2164 |
"make the argument, anObject be independent of the receiver" |
|
2165 |
||
1585
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2166 |
|wasBlocked| |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2167 |
|
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2168 |
"/ must do this save from interrupts, since the dependents collection |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2169 |
"/ is possibly accessed from multiple threads. |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2170 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2171 |
"/ faster execution. |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2172 |
|
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2173 |
wasBlocked := OperatingSystem blockInterrupts. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2174 |
[ |
2647 | 2175 |
|deps n d| |
2176 |
||
2177 |
deps := self dependents. |
|
2178 |
deps notNil ifTrue:[ |
|
2179 |
||
2180 |
"/ to save a fair amount of memory in case of |
|
2181 |
"/ many dependencies, we store a single dependent in |
|
2182 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
2183 |
"/ added. Here we have to do the inverse ... |
|
2184 |
||
2185 |
deps class == WeakArray ifTrue:[ |
|
2186 |
((d := deps at:1) == anObject |
|
2187 |
or:[d isNil |
|
2188 |
or:[d == 0]]) ifTrue:[ |
|
2189 |
self dependents:nil |
|
2190 |
] |
|
2191 |
] ifFalse:[ |
|
2192 |
deps remove:anObject ifAbsent:[]. |
|
2193 |
(n := deps size) == 0 ifTrue:[ |
|
2194 |
self dependents:nil |
|
2195 |
] ifFalse:[ |
|
2196 |
n == 1 ifTrue:[ |
|
2197 |
d := deps firstIfEmpty:nil. |
|
2198 |
d notNil ifTrue:[ |
|
2199 |
deps := WeakArray with:d |
|
2200 |
] ifFalse:[ |
|
2201 |
deps := nil |
|
2202 |
]. |
|
2203 |
self dependents:deps. |
|
2204 |
] |
|
2205 |
] |
|
2206 |
] |
|
2207 |
] |
|
1585
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2208 |
] valueNowOrOnUnwindDo:[ |
2647 | 2209 |
wasBlocked ifFalse:[ |
2210 |
OperatingSystem unblockInterrupts |
|
2211 |
] |
|
1585
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2212 |
] |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2213 |
|
2341 | 2214 |
"Modified: 31.1.1997 / 12:36:16 / cg" |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2215 |
! ! |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2216 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2217 |
!Object methodsFor:'dependents access (nonWeak)'! |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2218 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2219 |
addNonWeakDependent:anObject |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2220 |
"make the argument, anObject be a nonWeak dependent of the receiver. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2221 |
Be careful: this nonWeakDependency will prevent the dependent from being |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2222 |
garbage collected unless the dependency is removed. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2223 |
This is a private mechanism, for directed dependencies." |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2224 |
|
1585
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2225 |
|wasBlocked| |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2226 |
|
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2227 |
"/ must do this save from interrupts, since the dependents collection |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2228 |
"/ is possibly accessed from multiple threads. |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2229 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2230 |
"/ faster execution. |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2231 |
|
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2232 |
wasBlocked := OperatingSystem blockInterrupts. |
863
2c83fe958ca7
change dependencies uninterruptably
Claus Gittinger <cg@exept.de>
parents:
861
diff
changeset
|
2233 |
[ |
2647 | 2234 |
|deps dep| |
2235 |
||
2236 |
deps := self nonWeakDependents. |
|
2237 |
||
2238 |
"/ to save a fair amount of memory in case of |
|
2239 |
"/ many dependencies, we store a single dependent in |
|
2240 |
"/ an Array, and switch to a Set if more dependents are |
|
2241 |
"/ added. |
|
2242 |
||
2243 |
deps isNil ifTrue:[ |
|
2244 |
self nonWeakDependents:(Array with:anObject) |
|
2245 |
] ifFalse:[ |
|
2246 |
deps class == Array ifTrue:[ |
|
2247 |
dep := deps at:1. |
|
2248 |
dep ~~ anObject ifTrue:[ |
|
2249 |
self nonWeakDependents:(IdentitySet with:dep with:anObject) |
|
2250 |
] |
|
2251 |
] ifFalse:[ |
|
2252 |
deps add:anObject |
|
2253 |
] |
|
2254 |
] |
|
1585
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2255 |
] valueNowOrOnUnwindDo:[ |
2647 | 2256 |
wasBlocked ifFalse:[ |
2257 |
OperatingSystem unblockInterrupts |
|
2258 |
] |
|
1585
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2259 |
] |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2260 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2261 |
"Created: 19.4.1996 / 10:54:08 / cg" |
1624
50c5849dc9d4
mhmh - care for dependent being already in the array,
Claus Gittinger <cg@exept.de>
parents:
1611
diff
changeset
|
2262 |
"Modified: 1.8.1996 / 14:22:12 / cg" |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2263 |
! |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2264 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2265 |
nonWeakDependents |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2266 |
"return a Collection of nonWeakDependents - nil if there is none. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2267 |
This is a private mechanism for directed dependencies." |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2268 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2269 |
NonWeakDependencies isNil ifTrue:[^nil]. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2270 |
^ NonWeakDependencies at:self ifAbsent:[nil] |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2271 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2272 |
"Created: 19.4.1996 / 10:55:06 / cg" |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2273 |
! |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2274 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2275 |
nonWeakDependents:aCollection |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2276 |
"set the collection of nonWeak dependents. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2277 |
This is a private helper for directed dependencies." |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2278 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2279 |
[ |
2647 | 2280 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
2281 |
NonWeakDependencies removeKey:self ifAbsent:[] |
|
2282 |
] ifFalse:[ |
|
2283 |
NonWeakDependencies at:self put:aCollection |
|
2284 |
] |
|
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2285 |
] valueUninterruptably |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2286 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2287 |
"Created: 19.4.1996 / 11:07:47 / cg" |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2288 |
! |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2289 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2290 |
removeNonWeakDependent:anObject |
1231
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2291 |
"remove a nonWeak dependency from the receiver to the argument, anObject. |
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2292 |
(i.e. make it independent of the receiver)" |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2293 |
|
1585
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2294 |
|wasBlocked| |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2295 |
|
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2296 |
"/ must do this save from interrupts, since the dependents collection |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2297 |
"/ is possibly accessed from multiple threads. |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2298 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2299 |
"/ faster execution. |
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2300 |
|
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2301 |
wasBlocked := OperatingSystem blockInterrupts. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2302 |
[ |
2647 | 2303 |
|deps n| |
2304 |
||
2305 |
deps := self nonWeakDependents. |
|
2306 |
deps notNil ifTrue:[ |
|
2307 |
deps class == Array ifTrue:[ |
|
2308 |
(deps at:1) == anObject ifTrue:[ |
|
2309 |
self nonWeakDependents:nil |
|
2310 |
] |
|
2311 |
] ifFalse:[ |
|
2312 |
deps remove:anObject ifAbsent:[]. |
|
2313 |
(n := deps size) == 0 ifTrue:[ |
|
2314 |
self nonWeakDependents:nil |
|
2315 |
] ifFalse:[ |
|
2316 |
n == 1 ifTrue:[ |
|
2317 |
self nonWeakDependents:(Array with:(deps first)) |
|
2318 |
] |
|
2319 |
] |
|
2320 |
] |
|
2321 |
] |
|
1585
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2322 |
] valueNowOrOnUnwindDo:[ |
2647 | 2323 |
wasBlocked ifFalse:[ |
2324 |
OperatingSystem unblockInterrupts |
|
2325 |
] |
|
1585
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2326 |
] |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2327 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2328 |
"Created: 19.4.1996 / 11:44:44 / cg" |
1585
5cfa7f2586ad
use inline interrupt blocking in dependents acces methods.
Claus Gittinger <cg@exept.de>
parents:
1533
diff
changeset
|
2329 |
"Modified: 19.7.1996 / 12:42:08 / cg" |
783 | 2330 |
! ! |
2331 |
||
2332 |
!Object methodsFor:'error handling'! |
|
2333 |
||
2334 |
appropriateDebugger:aSelector |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2335 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2336 |
|
783 | 2337 |
"return an appropriate debugger to use. |
2338 |
If there is already a debugger active on the stack, and it is |
|
2339 |
the DebugView, return MiniDebugger (as a last chance) otherwise abort." |
|
2340 |
||
2341 |
|context| |
|
2342 |
||
1678
1c0fc4e322d0
Change #appropriateDebugger: to call Minidebugger when being called by
Stefan Vogel <sv@exept.de>
parents:
1674
diff
changeset
|
2343 |
"DebugView cannot run without system processes" |
1c0fc4e322d0
Change #appropriateDebugger: to call Minidebugger when being called by
Stefan Vogel <sv@exept.de>
parents:
1674
diff
changeset
|
2344 |
|
1685 | 2345 |
(Processor isNil |
1684 | 2346 |
or:[Processor activeProcessIsSystemProcess]) ifTrue:[ |
2647 | 2347 |
^ MiniDebugger |
1678
1c0fc4e322d0
Change #appropriateDebugger: to call Minidebugger when being called by
Stefan Vogel <sv@exept.de>
parents:
1674
diff
changeset
|
2348 |
]. |
1c0fc4e322d0
Change #appropriateDebugger: to call Minidebugger when being called by
Stefan Vogel <sv@exept.de>
parents:
1674
diff
changeset
|
2349 |
|
783 | 2350 |
context := thisContext. |
2511
35de13a3a71e
dont mark all contexts as nonLifo in approriateDebugger.
Claus Gittinger <cg@exept.de>
parents:
2506
diff
changeset
|
2351 |
context := context findNextContextWithSelector:aSelector or:nil. |
783 | 2352 |
[context notNil] whileTrue:[ |
2647 | 2353 |
((context receiver class == Debugger) |
2354 |
and:[context selector == aSelector]) ifTrue:[ |
|
2355 |
"we are already in some Debugger" |
|
2356 |
(Debugger == MiniDebugger) ifTrue:[ |
|
2357 |
"we are already in the MiniDebugger" |
|
2358 |
ErrorRecursion ifFalse:[ |
|
2359 |
Smalltalk fatalAbort:'recursive error ...' |
|
2360 |
] |
|
2361 |
]. |
|
2362 |
MiniDebugger isNil ifTrue:[ |
|
2363 |
Smalltalk fatalAbort:'no debugger' |
|
2364 |
]. |
|
2365 |
||
2366 |
"ok, an error occured while in the graphical debugger; |
|
2367 |
lets try MiniDebugger" |
|
2368 |
^ MiniDebugger |
|
2369 |
]. |
|
2370 |
context := context findNextContextWithSelector:aSelector or:nil. |
|
71 | 2371 |
]. |
783 | 2372 |
"not within Debugger - no problem" |
2373 |
^ Debugger |
|
1678
1c0fc4e322d0
Change #appropriateDebugger: to call Minidebugger when being called by
Stefan Vogel <sv@exept.de>
parents:
1674
diff
changeset
|
2374 |
|
1c0fc4e322d0
Change #appropriateDebugger: to call Minidebugger when being called by
Stefan Vogel <sv@exept.de>
parents:
1674
diff
changeset
|
2375 |
"Modified: 23.9.1996 / 12:14:52 / stefan" |
2511
35de13a3a71e
dont mark all contexts as nonLifo in approriateDebugger.
Claus Gittinger <cg@exept.de>
parents:
2506
diff
changeset
|
2376 |
"Modified: 27.3.1997 / 18:21:07 / cg" |
783 | 2377 |
! |
2378 |
||
2229
a9881102b243
new feature: cannotSendMessage:to:
Claus Gittinger <cg@exept.de>
parents:
2227
diff
changeset
|
2379 |
cannotSendMessage:aMessage to:someReceiver |
a9881102b243
new feature: cannotSendMessage:to:
Claus Gittinger <cg@exept.de>
parents:
2227
diff
changeset
|
2380 |
"this message is sent by the runtime system (VM), |
a9881102b243
new feature: cannotSendMessage:to:
Claus Gittinger <cg@exept.de>
parents:
2227
diff
changeset
|
2381 |
when a message is sent to some object, whose class is not |
2231 | 2382 |
a valid behavior (see documentation in Behavior)." |
2229
a9881102b243
new feature: cannotSendMessage:to:
Claus Gittinger <cg@exept.de>
parents:
2227
diff
changeset
|
2383 |
|
a9881102b243
new feature: cannotSendMessage:to:
Claus Gittinger <cg@exept.de>
parents:
2227
diff
changeset
|
2384 |
^ InternalErrorSignal |
2647 | 2385 |
raiseRequestWith:someReceiver |
2386 |
errorString:('bad class in send of #' , aMessage selector) |
|
2231 | 2387 |
|
2388 |
"Modified: 23.1.1997 / 00:05:39 / cg" |
|
2229
a9881102b243
new feature: cannotSendMessage:to:
Claus Gittinger <cg@exept.de>
parents:
2227
diff
changeset
|
2389 |
! |
a9881102b243
new feature: cannotSendMessage:to:
Claus Gittinger <cg@exept.de>
parents:
2227
diff
changeset
|
2390 |
|
783 | 2391 |
doesNotUnderstand:aMessage |
2392 |
"this message is sent by the runtime system (VM) when |
|
2393 |
a message is not understood by some object (i.e. there |
|
2394 |
is no method for that selector). The original message has |
|
2395 |
been packed into aMessage (i.e. the receiver, selector and |
|
2396 |
any arguments) and the original receiver is then sent the |
|
2397 |
#doesNotUnderstand: message. |
|
2398 |
Here, we raise another signal which usually enters the debugger. |
|
2399 |
You can of course redefine #doesNotUnderstand: in your classes |
|
1327 | 2400 |
to implement message delegation, |
2401 |
or handle the MessageNotUnderstoodSignal gracefully." |
|
783 | 2402 |
|
2403 |
|sel errorString cls sender| |
|
2404 |
||
2405 |
"/ handle the case of an error during early startup |
|
2406 |
"/ (output streams not yet initialized) |
|
2407 |
"/ |
|
2408 |
Stdout isNil ifTrue:[ |
|
2647 | 2409 |
Smalltalk fatalAbort:'error during init: ' , aMessage selector , ' not understood'. |
783 | 2410 |
]. |
2411 |
||
2412 |
(sel := aMessage selector) isNil ifTrue:[ |
|
2647 | 2413 |
"/ |
2414 |
"/ happens when things go mad, or a method has been |
|
2415 |
"/ called by valueWithReceiver: with a wrong receiver. |
|
2416 |
"/ To avoid later trouble (when concatenating strings), |
|
2417 |
"/ replace the selector by some (nonNil) string |
|
2418 |
"/ |
|
2419 |
sel := '(nil)' |
|
783 | 2420 |
]. |
2421 |
||
2422 |
"/ |
|
2423 |
"/ extract the class that should have implemented the message. |
|
2424 |
"/ (in case of a super-send, this is not the receivers class) |
|
2425 |
"/ |
|
2426 |
sender := thisContext sender. |
|
2427 |
cls := sender searchClass. |
|
2428 |
cls isNil ifTrue:[ |
|
2647 | 2429 |
"it was NOT a super or directed send ..." |
2430 |
cls := self class |
|
783 | 2431 |
]. |
2432 |
||
2433 |
cls notNil ifTrue:[ |
|
2647 | 2434 |
"/ |
2435 |
"/ displayString is better than 'cls name', |
|
2436 |
"/ since it appends (obsolete) for outdated classes. |
|
2437 |
"/ (this happens if you send messages to old instances |
|
2438 |
"/ after changing a classes definition) |
|
2439 |
"/ |
|
2440 |
errorString := cls displayString. |
|
783 | 2441 |
] ifFalse:[ |
2647 | 2442 |
errorString := '(** nil-class **)' |
783 | 2443 |
]. |
2444 |
errorString := errorString , ' does not understand: ' , sel. |
|
2445 |
||
2446 |
"/ |
|
2447 |
"/ this only happens, when YOU play around with my classvars ... |
|
1327 | 2448 |
"/ (or an error occurs during very early startup, when signals are not yet set) |
783 | 2449 |
"/ |
2450 |
MessageNotUnderstoodSignal isNil ifTrue:[ |
|
2647 | 2451 |
^ self |
1674 | 2452 |
enterDebuggerWithMessage:'oops - MessageNotUnderstoodSignal is gone' |
2453 |
on:thisContext. |
|
783 | 2454 |
]. |
2455 |
||
2456 |
"/ |
|
2457 |
"/ thats where we end up normally - raise a signal which (if unhandled) opens a debugger |
|
2458 |
"/ |
|
2459 |
^ MessageNotUnderstoodSignal |
|
2647 | 2460 |
raiseRequestWith:aMessage |
2461 |
errorString:errorString |
|
2462 |
in:sender |
|
1327 | 2463 |
|
2464 |
"Modified: 3.5.1996 / 11:51:45 / cg" |
|
783 | 2465 |
! |
2466 |
||
2467 |
elementBoundsError |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2468 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2469 |
|
1345 | 2470 |
"report an error that badElement is out of bounds |
2471 |
(i.e. cannot be put into that collection). |
|
2472 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
783 | 2473 |
|
2474 |
^ ElementOutOfBoundsSignal raiseIn:thisContext sender |
|
1345 | 2475 |
|
2476 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
|
783 | 2477 |
! |
2478 |
||
2479 |
elementNotCharacter |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2480 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2481 |
|
1345 | 2482 |
"report an error that object to be stored is no Character. |
2483 |
(usually when storing into Strings). |
|
2484 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
783 | 2485 |
|
2486 |
^ ElementOutOfBoundsSignal raiseIn:thisContext sender |
|
1345 | 2487 |
|
2488 |
"Modified: 8.5.1996 / 09:12:49 / cg" |
|
783 | 2489 |
! |
2490 |
||
2491 |
elementNotInteger |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2492 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2493 |
|
1345 | 2494 |
"report an error that object to be stored is not Integer. |
2495 |
(in collections that store integers only). |
|
2496 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
783 | 2497 |
|
2498 |
^ ElementOutOfBoundsSignal raiseIn:thisContext sender |
|
1345 | 2499 |
|
2500 |
"Modified: 8.5.1996 / 09:12:51 / cg" |
|
783 | 2501 |
! |
2502 |
||
2503 |
enterDebuggerWith:anException message:aString |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2504 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2505 |
|
783 | 2506 |
"enter the debugger with error-message aString" |
2507 |
||
1674 | 2508 |
^ self |
2509 |
enterDebuggerWithMessage:aString |
|
2510 |
on:anException suspendedContext |
|
2511 |
! |
|
2512 |
||
2513 |
enterDebuggerWithMessage:aString on:aContext |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2514 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2515 |
|
783 | 2516 |
"enter the debugger with error-message aString. |
2517 |
The first visible context shown there is aContext |
|
2518 |
(this allows intermediate helpers to hide themselfes from what is |
|
2519 |
presented to the user)" |
|
2520 |
||
1094
af10927dc0f2
standAlone graphical app gives user a chance to ignore errors
Claus Gittinger <cg@exept.de>
parents:
1089
diff
changeset
|
2521 |
|debugger msg| |
71 | 2522 |
|
2523 |
" |
|
783 | 2524 |
if there is no debugger, exit smalltalk |
2525 |
" |
|
2526 |
Debugger isNil ifTrue:[ |
|
2647 | 2527 |
msg := 'error: ' , aString. |
2528 |
||
2529 |
Smalltalk isStandAloneApp ifTrue:[ |
|
2530 |
Dialog notNil ifTrue:[ |
|
2531 |
(Dialog |
|
2532 |
confirm:msg title:(Smalltalk commandName) |
|
2533 |
yesLabel:'ignore' noLabel:'exit' |
|
2534 |
) ifTrue:[ |
|
2535 |
^ AbortSignal raise |
|
2536 |
] |
|
2537 |
]. |
|
2538 |
msg errorPrintCR. |
|
2539 |
OperatingSystem exit:1 |
|
2540 |
]. |
|
2541 |
msg errorPrintCR. |
|
2542 |
Smalltalk fatalAbort:'no Debugger defined' |
|
783 | 2543 |
]. |
983 | 2544 |
|
783 | 2545 |
" |
2546 |
find an appropriate debugger to use |
|
71 | 2547 |
" |
783 | 2548 |
debugger := self appropriateDebugger:#'enter:withMessage:'. |
2549 |
^ debugger enter:aContext withMessage:aString. |
|
1094
af10927dc0f2
standAlone graphical app gives user a chance to ignore errors
Claus Gittinger <cg@exept.de>
parents:
1089
diff
changeset
|
2550 |
|
2136 | 2551 |
"Modified: 10.1.1997 / 19:11:52 / cg" |
783 | 2552 |
! |
2553 |
||
2554 |
error |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2555 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2556 |
|
1345 | 2557 |
"report error that an error occured. |
2558 |
The error is reported by raising the ErrorSignal exception." |
|
2559 |
||
2560 |
^ ErrorSignal raiseIn:thisContext sender |
|
2561 |
||
2562 |
"Modified: 8.5.1996 / 09:13:01 / cg" |
|
783 | 2563 |
! |
2564 |
||
2565 |
error:aString |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2566 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2567 |
|
1345 | 2568 |
"enter debugger with error-message aString. |
2569 |
The error is reported by raising the ErrorSignal exception." |
|
783 | 2570 |
|
2571 |
^ ErrorSignal raiseRequestWith:#error: |
|
2647 | 2572 |
errorString:aString |
2573 |
in:thisContext sender |
|
1345 | 2574 |
|
2575 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
2576 |
! |
|
2577 |
||
2578 |
error:aString in:aContext |
|
2579 |
"{ Pragma: +optSpace }" |
|
2580 |
||
2581 |
"enter debugger with error-message aString. |
|
2582 |
The error is reported by raising the ErrorSignal exception." |
|
2583 |
||
2584 |
^ ErrorSignal raiseRequestWith:#error: |
|
2647 | 2585 |
errorString:aString |
2586 |
in:aContext |
|
1345 | 2587 |
|
2588 |
"Created: 8.5.1996 / 09:07:59 / cg" |
|
2589 |
"Modified: 8.5.1996 / 09:13:06 / cg" |
|
783 | 2590 |
! |
2591 |
||
2592 |
errorKeyNotFound:aKey |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2593 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2594 |
|
1345 | 2595 |
"report an error that a key was not found in a collection. |
2596 |
The error is reported by raising the KeyNotFoundSignal exception." |
|
783 | 2597 |
|
2598 |
^ KeyNotFoundSignal raiseRequestWith:aKey in:thisContext sender |
|
1345 | 2599 |
|
2600 |
"Modified: 8.5.1996 / 09:13:08 / cg" |
|
783 | 2601 |
! |
2602 |
||
2603 |
errorNotFound |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2604 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2605 |
|
1345 | 2606 |
"report an error that no element was found in a collection. |
2607 |
The error is reported by raising the NotFoundSignal exception." |
|
783 | 2608 |
|
2609 |
^ NotFoundSignal raiseIn:thisContext sender |
|
1345 | 2610 |
|
2611 |
"Modified: 8.5.1996 / 09:13:11 / cg" |
|
783 | 2612 |
! |
2613 |
||
2614 |
halt |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2615 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2616 |
|
1345 | 2617 |
"enter debugger with halt-message. |
2618 |
The error is reported by raising the HaltSignal exception." |
|
783 | 2619 |
|
2620 |
^ HaltSignal raiseIn:thisContext sender. |
|
1345 | 2621 |
|
2622 |
"Modified: 8.5.1996 / 09:12:38 / cg" |
|
783 | 2623 |
! |
2624 |
||
2625 |
halt:aString |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2626 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2627 |
|
1345 | 2628 |
"enter debugger with halt-message. |
2629 |
The error is reported by raising the HaltSignal exception." |
|
783 | 2630 |
|
2631 |
^ HaltSignal raiseRequestWith:#halt: |
|
2647 | 2632 |
errorString:aString |
2633 |
in:thisContext sender |
|
1345 | 2634 |
|
2635 |
"Modified: 8.5.1996 / 09:13:23 / cg" |
|
783 | 2636 |
! |
2637 |
||
2638 |
implementedBySubclass |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2639 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2640 |
|
783 | 2641 |
"this is sent by ST/V code - its the same as #subclassResponsibility" |
2642 |
||
2643 |
^ self subclassResponsibility |
|
2644 |
! |
|
2645 |
||
2646 |
indexNotInteger |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2647 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2648 |
|
1345 | 2649 |
"report an error that index is not an Integer. |
2650 |
(when accessing collections indexed by an integer key). |
|
2651 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
783 | 2652 |
|
2653 |
^ NonIntegerIndexSignal raiseIn:thisContext sender |
|
1345 | 2654 |
|
2655 |
"Modified: 8.5.1996 / 09:13:37 / cg" |
|
783 | 2656 |
! |
2657 |
||
2658 |
integerCheckError |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2659 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2660 |
|
783 | 2661 |
"generated when a variable declared with an integer type gets a bad |
2662 |
value assigned" |
|
2663 |
||
2664 |
^ self error:'bad assign of ' , self printString , |
|
2665 |
' (' , self class name , ') to integer-typed variable' |
|
71 | 2666 |
! |
2667 |
||
783 | 2668 |
invalidMessage |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2669 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2670 |
|
783 | 2671 |
"this is sent by ST/V code - its the same as #shouldNotImplement" |
2672 |
||
2673 |
^ self shouldNotImplement |
|
2674 |
! |
|
2675 |
||
2676 |
mustBeRectangle |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2677 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2678 |
|
783 | 2679 |
"report an argument-not-rectangle-error" |
2680 |
||
2681 |
^ self error:'argument must be a Rectangle' |
|
2682 |
! |
|
2683 |
||
2684 |
mustBeString |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2685 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2686 |
|
783 | 2687 |
"report an argument-not-string-error" |
2688 |
||
2689 |
^ self error:'argument must be a String' |
|
2690 |
! |
|
2691 |
||
2692 |
notIndexed |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2693 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2694 |
|
1611
f8c9a3ab9929
notIndexedError now uses SubscriptBoundsErrorSignal
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
2695 |
"report an error that receiver has no indexed instance variables. |
f8c9a3ab9929
notIndexedError now uses SubscriptBoundsErrorSignal
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
2696 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
f8c9a3ab9929
notIndexedError now uses SubscriptBoundsErrorSignal
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
2697 |
|
f8c9a3ab9929
notIndexedError now uses SubscriptBoundsErrorSignal
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
2698 |
^ SubscriptOutOfBoundsSignal |
2647 | 2699 |
raiseErrorString:'receiver has no indexed variables' |
2700 |
in:thisContext sender |
|
1611
f8c9a3ab9929
notIndexedError now uses SubscriptBoundsErrorSignal
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
2701 |
|
f8c9a3ab9929
notIndexedError now uses SubscriptBoundsErrorSignal
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
2702 |
"Modified: 26.7.1996 / 16:43:13 / cg" |
783 | 2703 |
! |
2704 |
||
2705 |
primitiveFailed |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2706 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2707 |
|
1345 | 2708 |
"report an error that some primitive code failed. |
2709 |
The error is reported by raising the PrimitiveFailureSignal exception." |
|
783 | 2710 |
|
2711 |
^ PrimitiveFailureSignal raiseIn:(thisContext sender) |
|
1345 | 2712 |
|
2713 |
"Modified: 8.5.1996 / 09:14:07 / cg" |
|
783 | 2714 |
! |
2715 |
||
2716 |
shouldNotImplement |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2717 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2718 |
|
1345 | 2719 |
"report an error that this message should not be implemented" |
783 | 2720 |
|
2721 |
^ self error:'method not appropriate for this class' |
|
1345 | 2722 |
|
2723 |
"Modified: 8.5.1996 / 09:09:44 / cg" |
|
783 | 2724 |
! |
2725 |
||
2726 |
subclassResponsibility |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2727 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2728 |
|
1345 | 2729 |
"report an error that this message should have been reimplemented in a |
783 | 2730 |
subclass" |
2731 |
||
1345 | 2732 |
^ self error:'method must be reimplemented in subclass' in:thisContext sender |
2733 |
||
2734 |
"Modified: 8.5.1996 / 09:09:26 / cg" |
|
783 | 2735 |
! |
2736 |
||
2737 |
subscriptBoundsError |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2738 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2739 |
|
1345 | 2740 |
"report an error that some index is out of bounds. |
2741 |
(when accessing indexable collections). |
|
2742 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
783 | 2743 |
|
1611
f8c9a3ab9929
notIndexedError now uses SubscriptBoundsErrorSignal
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
2744 |
^ SubscriptOutOfBoundsSignal |
2647 | 2745 |
raiseIn:thisContext sender |
1611
f8c9a3ab9929
notIndexedError now uses SubscriptBoundsErrorSignal
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
2746 |
|
f8c9a3ab9929
notIndexedError now uses SubscriptBoundsErrorSignal
Claus Gittinger <cg@exept.de>
parents:
1585
diff
changeset
|
2747 |
"Modified: 26.7.1996 / 16:45:42 / cg" |
783 | 2748 |
! |
2749 |
||
2750 |
subscriptBoundsError:anIndex |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2751 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2752 |
|
1345 | 2753 |
"report an error that anIndex is out of bounds. |
2754 |
(when accessing indexable collections). |
|
2755 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
783 | 2756 |
|
1021
b0c7f4a235fb
show bad index in subscriptBoundsError
Claus Gittinger <cg@exept.de>
parents:
985
diff
changeset
|
2757 |
^ SubscriptOutOfBoundsSignal |
2647 | 2758 |
raiseRequestWith:anIndex |
2759 |
errorString:('subscript (' , anIndex printString , ') out of bounds') |
|
2760 |
in:thisContext sender |
|
1021
b0c7f4a235fb
show bad index in subscriptBoundsError
Claus Gittinger <cg@exept.de>
parents:
985
diff
changeset
|
2761 |
|
1345 | 2762 |
"Modified: 8.5.1996 / 09:14:34 / cg" |
783 | 2763 |
! |
2764 |
||
2765 |
typeCheckError |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2766 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
2767 |
|
783 | 2768 |
"generated when a variable declared with a type hint gets a bad |
2769 |
value assigned" |
|
2770 |
||
2771 |
^ self error:'bad assign of ' , self printString , |
|
2772 |
' (' , self class name , ') to typed variable' |
|
2773 |
! ! |
|
2774 |
||
2775 |
!Object methodsFor:'evaluation'! |
|
2776 |
||
2777 |
value |
|
1327 | 2778 |
"return the receiver itself. |
2779 |
This allows every object to be used where blocks or valueHolders |
|
2780 |
are typically used, and allows for valueHolders and blocks to be |
|
2781 |
used interchangably in some situations. |
|
2782 |
||
783 | 2783 |
Time will show, if this is a good idea or leads to sloppy programming |
2784 |
style ... (the idea was borrowed from the Self language). |
|
1327 | 2785 |
|
2786 |
WARNING: dont 'optimize' away ifXXX: blocks |
|
2647 | 2787 |
(i.e. do NOT replace |
2788 |
foo ifTrue:[var1] ifFalse:[var2] |
|
2789 |
by: |
|
2790 |
foo ifTrue:var1 ifFalse:var2 |
|
2791 |
) |
|
2792 |
- the compilers will only generate inline code for the if, |
|
2793 |
iff the argument(s) are blocks - otherwise, a true send is |
|
2794 |
generated. |
|
2795 |
This 'oprimization' will work semantically correct, |
|
2796 |
but execute SLOWER instead." |
|
783 | 2797 |
|
2798 |
^ self |
|
71 | 2799 |
|
2800 |
" |
|
1327 | 2801 |
#(1 2 3 4) indexOf:5 ifAbsent:0 |
2802 |
#(1 2 3 4) indexOf:5 ifAbsent:[0] |
|
2803 |
1 > 2 ifTrue:['yes'] ifFalse:['no'] |
|
2804 |
1 > 2 ifTrue:'yes' ifFalse:'no' |
|
783 | 2805 |
" |
2806 |
||
2807 |
"DO NOT DO THIS (its slower) |
|
2808 |
(1 > 4) ifTrue:'oops' ifFalse:'ok' |
|
2809 |
||
2810 |
USE (the compiler optimizes blocks in if/while): |
|
2811 |
(1 > 4) ifTrue:['oops'] ifFalse:['ok'] |
|
2812 |
" |
|
1327 | 2813 |
|
2814 |
"Modified: 3.5.1996 / 11:57:08 / cg" |
|
783 | 2815 |
! ! |
2816 |
||
2817 |
!Object methodsFor:'initialization'! |
|
2818 |
||
2819 |
initialize |
|
2820 |
"just to ignore initialize to objects which do not need it" |
|
2821 |
||
2822 |
^ self |
|
2823 |
! ! |
|
2824 |
||
1751
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2825 |
!Object methodsFor:'interest'! |
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2826 |
|
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2827 |
addInterest:anInterest |
1762
e7267ff590ff
Fix misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1751
diff
changeset
|
2828 |
"install an interest forwarder. |
1231
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2829 |
Here, we use the nonWeakDependencies." |
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2830 |
|
1751
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2831 |
self addNonWeakDependent:anInterest |
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2832 |
|
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2833 |
"Created: 14.10.1996 / 22:27:34 / stefan" |
1231
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2834 |
! |
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2835 |
|
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2836 |
expressInterestIn:aspect for:anObject sendBack:aSelector |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2837 |
"arrange for aSelector to be sent to anObject whenever the receiver |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2838 |
changes aspect." |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2839 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2840 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2841 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2842 |
|
1751
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2843 |
self addInterest:(InterestConverter |
2647 | 2844 |
destination:anObject |
2845 |
selector:aSelector |
|
2846 |
aspect:aspect) |
|
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2847 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2848 |
" |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2849 |
|p b| |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2850 |
|
1422 | 2851 |
b := [Transcript showCR:' -> the point changed']. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2852 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2853 |
p := Point new. |
1422 | 2854 |
Transcript showCR:'interest in #foo:'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2855 |
p expressInterestIn:#foo for:b sendBack:#value. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2856 |
p x:1. |
1422 | 2857 |
Transcript showCR:'now changing #bar ... (expect no notification)'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2858 |
p changed:#bar. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2859 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2860 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2861 |
Delay waitForSeconds:1. |
1422 | 2862 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2863 |
p changed:#foo. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2864 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2865 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2866 |
Delay waitForSeconds:1. |
1422 | 2867 |
Transcript showCR:'no more interest in #foo:'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2868 |
p retractInterestIn:#foo for:b. |
1422 | 2869 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2870 |
p changed:#foo. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2871 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2872 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2873 |
Delay waitForSeconds:1. |
1422 | 2874 |
Transcript showCR:'interest in #bar now:'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2875 |
p expressInterestIn:#bar for:b sendBack:#value. |
1422 | 2876 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2877 |
p changed:#foo. |
1422 | 2878 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2879 |
p changed:#bar. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2880 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2881 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2882 |
Delay waitForSeconds:1. |
1422 | 2883 |
Transcript showCR:'interest in #foo now:'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2884 |
p expressInterestIn:#foo for:b sendBack:#value. |
1422 | 2885 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2886 |
p changed:#foo. |
1422 | 2887 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2888 |
p changed:#bar. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2889 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2890 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2891 |
Delay waitForSeconds:1. |
1422 | 2892 |
Transcript showCR:'no more interests:'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2893 |
p retractInterestsFor:b. |
1422 | 2894 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2895 |
p changed:#foo. |
1422 | 2896 |
Transcript showCR:'now changing #bar... (expect no notification)'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2897 |
p changed:#bar. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2898 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2899 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2900 |
p release. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2901 |
" |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2902 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2903 |
"Created: 19.4.1996 / 10:26:22 / cg" |
1231
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2904 |
"Modified: 19.4.1996 / 12:34:08 / cg" |
1751
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2905 |
"Modified: 14.10.1996 / 22:28:20 / stefan" |
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2906 |
! |
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2907 |
|
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2908 |
interests |
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2909 |
"return a Collection of interests - nil if there is none. |
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2910 |
Here, we use the nonWeakDependents for interests." |
1231
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2911 |
|
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2912 |
^ self nonWeakDependents |
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2913 |
|
1751
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2914 |
"Created: 14.10.1996 / 22:20:51 / stefan" |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2915 |
! |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2916 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2917 |
onChangeSend:aSelector to:anObject |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2918 |
"arrange for aSelector to be sent to anObject whenever the receiver |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2919 |
changes." |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2920 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2921 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2922 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2923 |
|
1751
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2924 |
self addInterest:(InterestConverter |
2647 | 2925 |
destination:anObject |
2926 |
selector:aSelector) |
|
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2927 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2928 |
" |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2929 |
|p b| |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2930 |
|
1422 | 2931 |
b := [Transcript showCR:'the point changed']. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2932 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2933 |
p := Point new. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2934 |
p onChangeSend:#value to:b. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2935 |
p x:1. |
1422 | 2936 |
Transcript showCR:'now changing'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2937 |
p changed. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2938 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2939 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2940 |
Delay waitForSeconds:1. |
1422 | 2941 |
Transcript showCR:'now changing'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2942 |
p changed. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2943 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2944 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2945 |
Delay waitForSeconds:1. |
1422 | 2946 |
Transcript showCR:'no more interest'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2947 |
p retractInterestsFor:b. |
1422 | 2948 |
Transcript showCR:'now changing again'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2949 |
p changed. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2950 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2951 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2952 |
Delay waitForSeconds:1. |
1422 | 2953 |
Transcript showCR:'interest again'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2954 |
p onChangeSend:#value to:b. |
1422 | 2955 |
Transcript showCR:'now changing again'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2956 |
p changed. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2957 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2958 |
" |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2959 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2960 |
"Created: 19.4.1996 / 10:26:38 / cg" |
1231
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2961 |
"Modified: 19.4.1996 / 12:34:26 / cg" |
1751
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2962 |
"Modified: 14.10.1996 / 22:28:27 / stefan" |
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2963 |
! |
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2964 |
|
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2965 |
removeInterest:anInterest |
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2966 |
"remove an interest forwarder. |
1231
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2967 |
Here, we use the nonWeakDependencies." |
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
2968 |
|
1751
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2969 |
self removeNonWeakDependent:anInterest |
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2970 |
|
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2971 |
"Created: 14.10.1996 / 22:21:59 / stefan" |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2972 |
! |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2973 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2974 |
retractInterestIn:aspect for:someOne |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2975 |
"remove the interest of someOne in the receiver changing aspect |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2976 |
(as installed with #expressInterestIn:for:sendBack:)." |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2977 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2978 |
"/ for now, remove the interestConverter. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2979 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2980 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2981 |
|deps| |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2982 |
|
1751
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
2983 |
deps := self interests. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2984 |
deps notNil ifTrue:[ |
2647 | 2985 |
deps do:[:dep | |
2986 |
(dep isMemberOf:InterestConverter) ifTrue:[ |
|
2987 |
dep destination == someOne ifTrue:[ |
|
2988 |
dep aspect == aspect ifTrue:[ |
|
2989 |
self removeInterest:dep. |
|
2990 |
^ self |
|
2991 |
] |
|
2992 |
] |
|
2993 |
] |
|
2994 |
] |
|
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2995 |
]. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2996 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2997 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2998 |
" |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2999 |
|p b| |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3000 |
|
1422 | 3001 |
b := [Transcript showCR:'the point changed']. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3002 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3003 |
p := Point new. |
1422 | 3004 |
Transcript showCR:'interest in #foo'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3005 |
p expressInterestIn:#foo for:b sendBack:#value. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3006 |
p x:1. |
1422 | 3007 |
Transcript showCR:'now changing #bar'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3008 |
p changed:#bar. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3009 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3010 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3011 |
Delay waitForSeconds:1. |
1422 | 3012 |
Transcript showCR:'now changing #foo'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3013 |
p changed:#foo. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3014 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3015 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3016 |
Delay waitForSeconds:1. |
1422 | 3017 |
Transcript showCR:'no more interest in #foo'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3018 |
p retractInterestIn:#foo for:b. |
1422 | 3019 |
Transcript showCR:'now changing #foo'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3020 |
p changed:#foo. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3021 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3022 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3023 |
Delay waitForSeconds:1. |
1422 | 3024 |
Transcript showCR:'interest in #bar now'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3025 |
p expressInterestIn:#bar for:b sendBack:#value. |
1422 | 3026 |
Transcript showCR:'now changing #foo'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3027 |
p changed:#foo. |
1422 | 3028 |
Transcript showCR:'now changing #bar'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3029 |
p changed:#bar. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3030 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3031 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3032 |
Delay waitForSeconds:1. |
1422 | 3033 |
Transcript showCR:'interest in #foo now'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3034 |
p expressInterestIn:#foo for:b sendBack:#value. |
1422 | 3035 |
Transcript showCR:'now changing #foo'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3036 |
p changed:#foo. |
1422 | 3037 |
Transcript showCR:'now changing #bar'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3038 |
p changed:#bar. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3039 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3040 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3041 |
Delay waitForSeconds:1. |
1422 | 3042 |
Transcript showCR:'no more interests'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3043 |
p retractInterestsFor:b. |
1422 | 3044 |
Transcript showCR:'now changing #foo'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3045 |
p changed:#foo. |
1422 | 3046 |
Transcript showCR:'now changing #bar'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3047 |
p changed:#bar. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3048 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3049 |
" |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3050 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3051 |
"Created: 19.4.1996 / 10:27:11 / cg" |
1231
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
3052 |
"Modified: 19.4.1996 / 12:29:52 / cg" |
1751
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
3053 |
"Modified: 14.10.1996 / 22:21:19 / stefan" |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3054 |
! |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3055 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3056 |
retractInterestsFor:someOne |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3057 |
"remove the interest of someOne in the receiver |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3058 |
(as installed with #onChangeSend:to:)." |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3059 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3060 |
"/ for now, remove the interestConverter. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3061 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3062 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3063 |
|coll deps| |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3064 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3065 |
"/ cannot removeDependent within the loop - the collection rehashes |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3066 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3067 |
coll := IdentitySet new. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3068 |
|
1751
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
3069 |
deps := self interests. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3070 |
deps notNil ifTrue:[ |
2647 | 3071 |
deps do:[:dep | |
3072 |
(dep isMemberOf:InterestConverter) ifTrue:[ |
|
3073 |
dep destination == someOne ifTrue:[ |
|
3074 |
coll add:dep. |
|
3075 |
] |
|
3076 |
] |
|
3077 |
]. |
|
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3078 |
]. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3079 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3080 |
coll do:[:dep | |
2647 | 3081 |
self removeInterest:dep. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3082 |
]. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3083 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3084 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3085 |
" |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3086 |
|p b| |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3087 |
|
1422 | 3088 |
b := [Transcript showCR:'the point changed']. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3089 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3090 |
p := Point new. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3091 |
p onChangeSend:#value to:b. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3092 |
p x:1. |
1422 | 3093 |
Transcript showCR:'now changing'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3094 |
p changed. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3095 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3096 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3097 |
Delay waitForSeconds:1. |
1422 | 3098 |
Transcript showCR:'now changing'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3099 |
p changed. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3100 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3101 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3102 |
Delay waitForSeconds:1. |
1422 | 3103 |
Transcript showCR:'no more interest'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3104 |
p retractInterestsFor:b. |
1422 | 3105 |
Transcript showCR:'now changing again'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3106 |
p changed. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3107 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3108 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3109 |
Delay waitForSeconds:1. |
1422 | 3110 |
Transcript showCR:'interest again'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3111 |
p onChangeSend:#value to:b. |
1422 | 3112 |
Transcript showCR:'now changing again'. |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3113 |
p changed. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3114 |
Transcript cr. |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3115 |
" |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3116 |
|
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3117 |
"Created: 19.4.1996 / 10:23:46 / cg" |
1231
4f457f654e57
interrests slightly rewritten
Claus Gittinger <cg@exept.de>
parents:
1217
diff
changeset
|
3118 |
"Modified: 19.4.1996 / 12:30:03 / cg" |
1751
0902cadafee2
Rename misspelled "interrest" to "interest".
Stefan Vogel <sv@exept.de>
parents:
1705
diff
changeset
|
3119 |
"Modified: 14.10.1996 / 22:21:25 / stefan" |
1217
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3120 |
! ! |
4f7099eb007c
separated dependencies into weak-ones and nonWeak ones
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3121 |
|
783 | 3122 |
!Object methodsFor:'interrupt handling'! |
3123 |
||
3124 |
childSignalInterrupt |
|
3125 |
"death of a child process (unix process) - do nothing" |
|
3126 |
||
3127 |
^ self |
|
3128 |
! |
|
3129 |
||
3130 |
customInterrupt |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3131 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3132 |
|
783 | 3133 |
"a custom interrupt" |
3134 |
||
3135 |
^ self error:'custom interrupt' |
|
3136 |
! |
|
3137 |
||
3138 |
errorInterrupt:errorID with:aParameter |
|
3139 |
"subsystem error. The arguments errorID and aParameter are the values passed |
|
3140 |
to the 'errorInterruptWithIDAndParameter(id, param)' function, |
|
3141 |
which can be called from C subsystems to raise an (asynchronous) |
|
3142 |
error exception. |
|
3143 |
||
3144 |
Currently, this is used to map XErrors to smalltalk errors, but can be |
|
3145 |
used from other C subsystems too, to upcast errors. |
|
3146 |
Especially, for subsystems which call errorHandler functions asynchronously. |
|
3147 |
IDs (currently) used: |
|
3148 |
#DisplayError ..... x-error interrupt |
|
3149 |
#XtError ..... xt-error interrupt (Xt interface is not yet published) |
|
71 | 3150 |
" |
783 | 3151 |
|
3152 |
|handler| |
|
3153 |
||
3154 |
handler := ObjectMemory registeredErrorInterruptHandlers at:errorID ifAbsent:nil. |
|
3155 |
handler notNil ifTrue:[ |
|
3156 |
"/ |
|
3157 |
"/ handler found; let it do whatever it wants ... |
|
3158 |
"/ |
|
3159 |
handler errorInterrupt:errorID with:aParameter. |
|
3160 |
^ self |
|
3161 |
]. |
|
3162 |
||
3163 |
"/ |
|
3164 |
"/ no handler - raise errorSignal passing the errorId as parameter |
|
3165 |
"/ |
|
3166 |
^ ErrorSignal |
|
3167 |
raiseRequestWith:errorID |
|
3168 |
errorString:('Subsystem error. ErrorID = ' , errorID printString) |
|
3169 |
! |
|
3170 |
||
3171 |
exceptionInterrupt |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3172 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3173 |
|
783 | 3174 |
"exception interrupt - enter debugger" |
3175 |
||
3176 |
self error:'exception Interrupt' |
|
3177 |
! |
|
3178 |
||
3179 |
fpExceptionInterrupt |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3180 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3181 |
|
783 | 3182 |
"a floating point exception occured - this one |
3183 |
has to be handled differently since it comes asynchronous |
|
3184 |
on some machines (for example, on machines with a separate FPU |
|
3185 |
or superscalar architectures. Also, errors from within primitive code |
|
3186 |
(or library functions such as GL) are sent via the Unix-signal |
|
3187 |
mechanism this way." |
|
3188 |
||
3189 |
^ Float domainErrorSignal raise |
|
3190 |
! |
|
3191 |
||
3192 |
internalError:msg |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3193 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3194 |
|
2227
eb1e28c62f14
use an extra signal for internal errors
Claus Gittinger <cg@exept.de>
parents:
2209
diff
changeset
|
3195 |
"this is triggered, when VM hits some bad error, |
783 | 3196 |
such as corrupted class, corrupted method/selector array |
3197 |
etc. The argument string gives some more information on what happened. |
|
2227
eb1e28c62f14
use an extra signal for internal errors
Claus Gittinger <cg@exept.de>
parents:
2209
diff
changeset
|
3198 |
(for example, if you set an objects class to a non-behavior, nil etc.). |
783 | 3199 |
Its not guaranteed, that the system is in a working condition once |
3200 |
this error occurred ...." |
|
3201 |
||
2227
eb1e28c62f14
use an extra signal for internal errors
Claus Gittinger <cg@exept.de>
parents:
2209
diff
changeset
|
3202 |
^ InternalErrorSignal |
2647 | 3203 |
raiseRequestWith:self |
3204 |
errorString:msg |
|
783 | 3205 |
! |
3206 |
||
3207 |
ioInterrupt |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3208 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3209 |
|
783 | 3210 |
"I/O (SIGIO/SIGPOLL) interrupt (supposed to be sent to Processor). |
3211 |
If we arrive here, there is either no handler (ObjMem>>ioInterruptHandler) |
|
3212 |
or it does not understand the ioInterrupt message. |
|
3213 |
In any case, this is a sign of some big trouble. Enter debugger." |
|
3214 |
||
3215 |
self error:'I/O Interrupt - but no handler' |
|
3216 |
! |
|
3217 |
||
3218 |
memoryInterrupt |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3219 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3220 |
|
783 | 3221 |
"out-of-memory interrupt and no handler - enter debugger" |
3222 |
||
3223 |
^ self error:'almost out of memory' |
|
3224 |
! |
|
3225 |
||
3226 |
recursionInterrupt |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3227 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3228 |
|
783 | 3229 |
"recursion limit (actually: stack overflow) interrupt. |
3230 |
This interrupt is triggered, when a process stack grows above |
|
3231 |
its stackLimit - usually, this leads into the debugger, but |
|
2689 | 3232 |
could be caught and the stackLimit increased in the handler. |
783 | 3233 |
At the time we arrive here, the system has still some stack |
3234 |
as a reserve so we can continue to do some useful work or cleanup or |
|
3235 |
debugging for a while. |
|
3236 |
If the signal is ignored, and the stack continues to grow, there |
|
3237 |
will be a few more chances (and more interrupts) before the VM |
|
3238 |
hard-terminates the process." |
|
3239 |
||
3240 |
thisContext isRecursive ifFalse:[ |
|
3241 |
^ RecursionInterruptSignal raise |
|
3242 |
] |
|
3243 |
! |
|
3244 |
||
3245 |
schedulerInterrupt |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3246 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3247 |
|
783 | 3248 |
"scheduler interrupt (supposed to be sent to Processor). |
3249 |
If we arrive here, either the Processor does not understand it, |
|
3250 |
or it has been set to nil. In any case, this is a sign of some |
|
3251 |
big trouble. Enter debugger." |
|
3252 |
||
3253 |
self error:'schedulerInterrupt - but no Processor' |
|
3254 |
! |
|
3255 |
||
3256 |
signalInterrupt:signalNumber |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3257 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3258 |
|
783 | 3259 |
"unix signal occured - some signals are handled as Smalltalk Exceptions |
3260 |
(SIGPIPE), others (SIGBUS) are rather fatal ... |
|
3261 |
In any case, if a smalltalk-signal has been connected to the OS signal, |
|
3262 |
that one is raised. |
|
3263 |
TODO: add another argument, giving more detailed signal info (PC, VADDR, |
|
3264 |
exact cause etc.). This helps if segvs occur in primitive code. |
|
3265 |
Currently (temporary kludge), these are passed as global variables." |
|
3266 |
||
3267 |
|box name here sig ignorable titles actions badContext msg pc addr| |
|
3268 |
||
3269 |
" |
|
3270 |
special case - since SIGPIPE has an ST-signal associated |
|
3271 |
" |
|
3272 |
(signalNumber == 13) ifTrue:[ |
|
2647 | 3273 |
"SIGPIPE - write on a pipe with no one to read" |
3274 |
||
3275 |
^ PipeStream brokenPipeSignal raise. |
|
783 | 3276 |
]. |
3277 |
||
3278 |
"if there has been an ST-signal installed, use it ..." |
|
3279 |
||
3280 |
sig := OperatingSystem operatingSystemSignal:signalNumber. |
|
3281 |
sig notNil ifTrue:[ |
|
2647 | 3282 |
^ sig raise |
783 | 3283 |
]. |
3284 |
||
3285 |
" |
|
3286 |
... otherwise , bring up a box asking for what to do ... |
|
3287 |
" |
|
3288 |
name := OperatingSystem nameForSignal:signalNumber. |
|
3289 |
here := thisContext. |
|
3290 |
||
3291 |
" |
|
3292 |
the context, in which the signal occurred: |
|
3293 |
" |
|
3294 |
badContext := here sender. |
|
3295 |
||
3296 |
" |
|
3297 |
ungrab - in case it happened in a box/popupview |
|
3298 |
otherwise display stays locked |
|
3299 |
" |
|
3300 |
Display notNil ifTrue:[ |
|
2647 | 3301 |
Display ungrabPointer. |
2655 | 3302 |
Display ungrabKeyboard. |
783 | 3303 |
]. |
3304 |
||
3305 |
" |
|
3306 |
SIGBUS, SIGSEGV and SIGILL do not make sense to ignore (i.e. continue) |
|
3307 |
since the system will retry the faulty instruction, which leads to |
|
3308 |
another signal - to avoid frustration, better not offer this option. |
|
3309 |
" |
|
3310 |
ignorable := (signalNumber ~~ OperatingSystem sigBUS) |
|
2647 | 3311 |
and:[signalNumber ~~ OperatingSystem sigILL |
3312 |
and:[signalNumber ~~ OperatingSystem sigSEGV]]. |
|
783 | 3313 |
|
3314 |
ignorable ifFalse:[ |
|
2647 | 3315 |
here isRecursive ifTrue:[ |
3316 |
'Object [hard error]: signal ' errorPrint. signalNumber errorPrintCR. |
|
3317 |
MiniDebugger enterWithMessage:'recursive signal'. |
|
3318 |
^ self |
|
3319 |
]. |
|
3320 |
" |
|
3321 |
a hard signal - go into debugger immediately |
|
3322 |
" |
|
3323 |
msg := 'OS-signal: ', name. |
|
3324 |
InterruptPcLow notNil ifTrue:[ |
|
3325 |
pc := InterruptPcLow + (InterruptPcHi bitShift:16). |
|
3326 |
pc ~~ 0 ifTrue:[ |
|
3327 |
msg := msg , ' PC=' , (pc printStringRadix:16) |
|
3328 |
]. |
|
3329 |
]. |
|
3330 |
InterruptAddrLow notNil ifTrue:[ |
|
3331 |
addr := InterruptAddrLow + (InterruptAddrHi bitShift:16). |
|
3332 |
addr ~~ 0 ifTrue:[ |
|
3333 |
msg := msg , ' ADDR=' , (addr printStringRadix:16) |
|
3334 |
]. |
|
3335 |
]. |
|
3336 |
Debugger enter:here withMessage:msg. |
|
3337 |
badContext return. |
|
3338 |
^ nil. |
|
783 | 3339 |
]. |
3340 |
||
3341 |
OptionBox isNil ifTrue:[ |
|
2647 | 3342 |
" |
3343 |
a system without GUI ... |
|
3344 |
go into minidebugger (if there is one) |
|
3345 |
" |
|
3346 |
MiniDebugger isNil ifTrue:[ |
|
3347 |
" |
|
3348 |
a system without debugging facilities |
|
3349 |
(i.e. a standalone system) |
|
3350 |
output a message and exit. |
|
3351 |
" |
|
3352 |
('Object [error]: exit due to Signal ' , name , ' - and no debugger.') errorPrintCR. |
|
3353 |
Smalltalk exit. |
|
3354 |
]. |
|
2689 | 3355 |
MiniDebugger enterWithMessage:'Signal caught (' , name, ')'. |
2647 | 3356 |
^ self |
783 | 3357 |
]. |
3358 |
||
3359 |
box := OptionBox |
|
2689 | 3360 |
title:'Signal caught (' , name, ')' |
2647 | 3361 |
numberOfOptions:(ignorable ifTrue:[5] ifFalse:[4]). |
783 | 3362 |
|
3363 |
titles := #('return' 'debug' 'dump' 'exit'). |
|
3364 |
actions := Array |
|
2647 | 3365 |
with:[badContext return] |
3366 |
with:[Debugger enter:here withMessage:('Signal ', name). ^nil] |
|
3367 |
with:[Smalltalk fatalAbort] |
|
3368 |
with:[Smalltalk exit]. |
|
783 | 3369 |
|
3370 |
ignorable ifTrue:[ |
|
2647 | 3371 |
titles := #('ignore') , titles. |
3372 |
actions := (Array with:[^ nil]) , actions. |
|
783 | 3373 |
]. |
3374 |
box buttonTitles:titles. |
|
3375 |
box actions:actions. |
|
3376 |
box showAtPointer |
|
2043 | 3377 |
|
2136 | 3378 |
"Modified: 10.1.1997 / 19:09:39 / cg" |
783 | 3379 |
! |
3380 |
||
3381 |
spyInterrupt |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3382 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3383 |
|
783 | 3384 |
"spy interrupt and no handler - enter debugger" |
3385 |
||
3386 |
self error:'spy Interrupt - but no handler' |
|
3387 |
! |
|
3388 |
||
3389 |
timerInterrupt |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3390 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3391 |
|
783 | 3392 |
"timer interrupt and no handler - enter debugger" |
3393 |
||
3394 |
self error:'timer Interrupt - but no handler' |
|
3395 |
! |
|
3396 |
||
3397 |
userInterrupt |
|
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3398 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
3399 |
|
1792 | 3400 |
"user (^c) interrupt. |
3401 |
This is typically sent by the VM, when a ctrl-C is typed at the |
|
3402 |
controlling tty (i.e. in the xterm)." |
|
783 | 3403 |
|
3404 |
UserInterruptSignal raise |
|
1788 | 3405 |
! |
3406 |
||
3407 |
userInterruptIn:aContext |
|
3408 |
"{ Pragma: +optSpace }" |
|
3409 |
||
3410 |
"user (^c) interrupt - enter debugger, but show aContext |
|
1792 | 3411 |
as top-context. |
3412 |
This is used to hide any intermediate scheduler contexts, |
|
3413 |
in case of an interrupted process. Typically, this is sent by |
|
3414 |
the WindowGroup, when a keyboardEvent for the ctrl-C key is |
|
3415 |
processed." |
|
1788 | 3416 |
|
3417 |
UserInterruptSignal raiseIn:aContext |
|
3418 |
||
3419 |
"Created: 18.10.1996 / 20:46:04 / cg" |
|
3420 |
"Modified: 20.10.1996 / 13:06:38 / cg" |
|
71 | 3421 |
! ! |
3422 |
||
1 | 3423 |
!Object methodsFor:'message sending'! |
3424 |
||
3425 |
perform:aSelector |
|
3426 |
"send the message aSelector to the receiver" |
|
3427 |
||
1533
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3428 |
%{ |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3429 |
struct inlineCache *pIlc; |
1820
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3430 |
static struct inlineCache ilc_0 = __ILCPERF0(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3431 |
static struct inlineCache ilc_1 = __ILCPERF0(0); |
1533
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3432 |
static OBJ last_0 = nil; |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3433 |
static OBJ last_1 = nil; |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3434 |
static flip = 0; |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3435 |
|
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3436 |
if (aSelector != last_0) { |
2647 | 3437 |
if (aSelector != last_1) { |
3438 |
if (flip) { |
|
3439 |
pIlc = &ilc_0; |
|
3440 |
flip = 0; |
|
3441 |
last_0 = aSelector; |
|
3442 |
} else { |
|
3443 |
pIlc = &ilc_1; |
|
3444 |
flip = 1; |
|
3445 |
last_1 = aSelector; |
|
3446 |
} |
|
3447 |
pIlc->ilc_func = __SEND0ADDR__; |
|
3448 |
if (pIlc->ilc_poly) { |
|
3449 |
__flushPolyCache(pIlc->ilc_poly); |
|
3450 |
pIlc->ilc_poly = 0; |
|
3451 |
} |
|
3452 |
} else { |
|
3453 |
pIlc = &ilc_1; |
|
3454 |
} |
|
1533
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3455 |
} else { |
2647 | 3456 |
pIlc = &ilc_0; |
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3457 |
} |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1685
diff
changeset
|
3458 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc) ); |
1 | 3459 |
%} |
3460 |
! |
|
3461 |
||
783 | 3462 |
perform:aSelector inClass:aClass withArguments:argArray |
3463 |
"send the message aSelector with all args taken from argArray |
|
3464 |
to the receiver as a super-send message. |
|
3465 |
This is actually more flexible than the normal super-send, since it allows |
|
3466 |
to execute a method in ANY superclass of the receiver (not just the |
|
3467 |
immediate superclass). |
|
3468 |
Thus, it is (theoretically) possible to do |
|
2647 | 3469 |
'5 perform:#< inClass:Magnitude withArguments:#(6)' |
783 | 3470 |
and evaluate Magnitudes compare method even if there was one in Number. |
3471 |
This method is used by the interpreter to evaluate super sends |
|
3472 |
and could be used for very special behavior (language extension ?). |
|
3473 |
||
3474 |
WARNING: this is an ST/X feature - probably not found in other smalltalks." |
|
3475 |
||
3476 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
|
3477 |
||
3478 |
" |
|
3479 |
check, if aClass is really a superclass of the receiver |
|
3480 |
" |
|
3481 |
(self class isSubclassOf:aClass) ifFalse:[ |
|
2647 | 3482 |
self error:'class argument is not a superclass of the receiver'. |
3483 |
^ nil |
|
783 | 3484 |
]. |
3485 |
numberOfArgs := argArray size. |
|
3486 |
%{ |
|
3487 |
REGISTER OBJ *argP; |
|
3488 |
int nargs, i; |
|
1818
384851e6fa7e
performs must be treated like self-sends,
Claus Gittinger <cg@exept.de>
parents:
1792
diff
changeset
|
3489 |
static struct inlineCache ilc0 = _DUMMYILCSELF0; |
384851e6fa7e
performs must be treated like self-sends,
Claus Gittinger <cg@exept.de>
parents:
1792
diff
changeset
|
3490 |
static struct inlineCache ilc1 = _DUMMYILCSELF1; |
384851e6fa7e
performs must be treated like self-sends,
Claus Gittinger <cg@exept.de>
parents:
1792
diff
changeset
|
3491 |
static struct inlineCache ilc2 = _DUMMYILCSELF2; |
384851e6fa7e
performs must be treated like self-sends,
Claus Gittinger <cg@exept.de>
parents:
1792
diff
changeset
|
3492 |
static struct inlineCache ilc3 = _DUMMYILCSELF3; |
384851e6fa7e
performs must be treated like self-sends,
Claus Gittinger <cg@exept.de>
parents:
1792
diff
changeset
|
3493 |
static struct inlineCache ilc4 = _DUMMYILCSELF4; |
384851e6fa7e
performs must be treated like self-sends,
Claus Gittinger <cg@exept.de>
parents:
1792
diff
changeset
|
3494 |
static struct inlineCache ilc5 = _DUMMYILCSELF5; |
384851e6fa7e
performs must be treated like self-sends,
Claus Gittinger <cg@exept.de>
parents:
1792
diff
changeset
|
3495 |
static struct inlineCache ilc6 = _DUMMYILCSELF6; |
384851e6fa7e
performs must be treated like self-sends,
Claus Gittinger <cg@exept.de>
parents:
1792
diff
changeset
|
3496 |
static struct inlineCache ilc7 = _DUMMYILCSELF7; |
384851e6fa7e
performs must be treated like self-sends,
Claus Gittinger <cg@exept.de>
parents:
1792
diff
changeset
|
3497 |
static struct inlineCache ilc8 = _DUMMYILCSELF8; |
384851e6fa7e
performs must be treated like self-sends,
Claus Gittinger <cg@exept.de>
parents:
1792
diff
changeset
|
3498 |
static struct inlineCache ilc9 = _DUMMYILCSELF9; |
384851e6fa7e
performs must be treated like self-sends,
Claus Gittinger <cg@exept.de>
parents:
1792
diff
changeset
|
3499 |
static struct inlineCache ilc10 = _DUMMYILCSELF10; |
384851e6fa7e
performs must be treated like self-sends,
Claus Gittinger <cg@exept.de>
parents:
1792
diff
changeset
|
3500 |
static struct inlineCache ilc11 = _DUMMYILCSELF11; |
384851e6fa7e
performs must be treated like self-sends,
Claus Gittinger <cg@exept.de>
parents:
1792
diff
changeset
|
3501 |
static struct inlineCache ilc12 = _DUMMYILCSELF12; |
384851e6fa7e
performs must be treated like self-sends,
Claus Gittinger <cg@exept.de>
parents:
1792
diff
changeset
|
3502 |
static struct inlineCache ilc13 = _DUMMYILCSELF13; |
384851e6fa7e
performs must be treated like self-sends,
Claus Gittinger <cg@exept.de>
parents:
1792
diff
changeset
|
3503 |
static struct inlineCache ilc14 = _DUMMYILCSELF14; |
384851e6fa7e
performs must be treated like self-sends,
Claus Gittinger <cg@exept.de>
parents:
1792
diff
changeset
|
3504 |
static struct inlineCache ilc15 = _DUMMYILCSELF15; |
783 | 3505 |
|
3506 |
if (__isSmallInteger(numberOfArgs)) { |
|
2647 | 3507 |
nargs = __intVal(numberOfArgs); |
3508 |
if (nargs == 0) { |
|
3509 |
RETURN (_SEND0(self, aSelector, aClass, &ilc0)); |
|
3510 |
} |
|
3511 |
||
3512 |
argP = (OBJ *)(&a1); |
|
3513 |
if (__Class(argArray) == @global(Array)) { |
|
3514 |
for (i=0; i < nargs; i++) { |
|
3515 |
*argP++ = __ArrayInstPtr(argArray)->a_element[i]; |
|
3516 |
} |
|
3517 |
} else { |
|
3518 |
for (i=1; i <= nargs; i++) { |
|
3519 |
*argP++ = __AT_(argArray, __MKSMALLINT(i)); |
|
3520 |
} |
|
3521 |
} |
|
3522 |
switch (nargs) { |
|
3523 |
case 1: |
|
3524 |
RETURN ( _SEND1(self, aSelector, aClass, &ilc1, a1)); |
|
3525 |
||
3526 |
case 2: |
|
3527 |
RETURN ( _SEND2(self, aSelector, aClass, &ilc2, a1, a2)); |
|
3528 |
||
3529 |
case 3: |
|
3530 |
RETURN ( _SEND3(self, aSelector, aClass, &ilc3, a1, a2, a3)); |
|
3531 |
||
3532 |
case 4: |
|
3533 |
RETURN ( _SEND4(self, aSelector, aClass, &ilc4, a1, a2, a3, a4)); |
|
3534 |
||
3535 |
case 5: |
|
3536 |
RETURN ( _SEND5(self, aSelector, aClass, &ilc5, |
|
3537 |
a1, a2, a3, a4, a5)); |
|
3538 |
||
3539 |
case 6: |
|
3540 |
RETURN ( _SEND6(self, aSelector, aClass, &ilc6, |
|
3541 |
a1, a2, a3, a4, a5, a6)); |
|
3542 |
||
3543 |
case 7: |
|
3544 |
RETURN ( _SEND7(self, aSelector, aClass, &ilc7, |
|
3545 |
a1, a2, a3, a4, a5, a6, a7)); |
|
3546 |
||
3547 |
case 8: |
|
3548 |
RETURN ( _SEND8(self, aSelector, aClass, &ilc8, |
|
3549 |
a1, a2, a3, a4, a5, a6, a7, a8)); |
|
3550 |
||
3551 |
case 9: |
|
3552 |
RETURN ( _SEND9(self, aSelector, aClass, &ilc9, |
|
3553 |
a1, a2, a3, a4, a5, a6, a7, a8, a9)); |
|
3554 |
||
3555 |
case 10: |
|
3556 |
RETURN ( _SEND10(self, aSelector, aClass, &ilc10, |
|
3557 |
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)); |
|
3558 |
||
3559 |
case 11: |
|
3560 |
RETURN ( _SEND11(self, aSelector, aClass, &ilc11, |
|
3561 |
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)); |
|
3562 |
||
3563 |
case 12: |
|
3564 |
RETURN ( _SEND12(self, aSelector, aClass, &ilc12, |
|
3565 |
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)); |
|
3566 |
||
3567 |
case 13: |
|
3568 |
RETURN ( _SEND13(self, aSelector, aClass, &ilc13, |
|
3569 |
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, |
|
3570 |
a13)); |
|
3571 |
||
3572 |
case 14: |
|
3573 |
RETURN ( _SEND14(self, aSelector, aClass, &ilc14, |
|
3574 |
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, |
|
3575 |
a13, a14)); |
|
3576 |
||
3577 |
case 15: |
|
3578 |
RETURN ( _SEND15(self, aSelector, aClass, &ilc15, |
|
3579 |
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, |
|
3580 |
a13, a14, a15)); |
|
3581 |
} |
|
783 | 3582 |
} |
1626 | 3583 |
%}. |
3584 |
"/ arrive here, if bad number of arguments (too many) |
|
3585 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
3586 |
||
783 | 3587 |
^ self primitiveFailed |
3588 |
! |
|
3589 |
||
1 | 3590 |
perform:aSelector with:anObject |
3591 |
"send the one-arg-message aSelector to the receiver" |
|
3592 |
||
1533
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3593 |
%{ |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3594 |
struct inlineCache *pIlc; |
1820
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3595 |
static struct inlineCache ilc_0 = __ILCPERF1(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3596 |
static struct inlineCache ilc_1 = __ILCPERF1(0); |
1533
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3597 |
static OBJ last_0 = nil; |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3598 |
static OBJ last_1 = nil; |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3599 |
static flip = 0; |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3600 |
|
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3601 |
if (aSelector != last_0) { |
2647 | 3602 |
if (aSelector != last_1) { |
3603 |
if (flip) { |
|
3604 |
pIlc = &ilc_0; |
|
3605 |
flip = 0; |
|
3606 |
last_0 = aSelector; |
|
3607 |
} else { |
|
3608 |
pIlc = &ilc_1; |
|
3609 |
flip = 1; |
|
3610 |
last_1 = aSelector; |
|
3611 |
} |
|
3612 |
pIlc->ilc_func = __SEND1ADDR__; |
|
3613 |
if (pIlc->ilc_poly) { |
|
3614 |
__flushPolyCache(pIlc->ilc_poly); |
|
3615 |
pIlc->ilc_poly = 0; |
|
3616 |
} |
|
3617 |
} else { |
|
3618 |
pIlc = &ilc_1; |
|
3619 |
} |
|
1533
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3620 |
} else { |
2647 | 3621 |
pIlc = &ilc_0; |
1 | 3622 |
} |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1685
diff
changeset
|
3623 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, anObject) ); |
1 | 3624 |
%} |
1533
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3625 |
|
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3626 |
! |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3627 |
|
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3628 |
perform:aSelector with:arg1 with:arg2 |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3629 |
"send the two-arg-message aSelector to the receiver" |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3630 |
|
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3631 |
%{ |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3632 |
struct inlineCache *pIlc; |
1820
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3633 |
static struct inlineCache ilc_0 = __ILCPERF2(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3634 |
static struct inlineCache ilc_1 = __ILCPERF2(0); |
1533
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3635 |
static OBJ last_0 = nil; |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3636 |
static OBJ last_1 = nil; |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3637 |
static flip = 0; |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3638 |
|
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3639 |
if (aSelector != last_0) { |
2647 | 3640 |
if (aSelector != last_1) { |
3641 |
if (flip) { |
|
3642 |
pIlc = &ilc_0; |
|
3643 |
flip = 0; |
|
3644 |
last_0 = aSelector; |
|
3645 |
} else { |
|
3646 |
pIlc = &ilc_1; |
|
3647 |
flip = 1; |
|
3648 |
last_1 = aSelector; |
|
3649 |
} |
|
3650 |
pIlc->ilc_func = __SEND2ADDR__; |
|
3651 |
if (pIlc->ilc_poly) { |
|
3652 |
__flushPolyCache(pIlc->ilc_poly); |
|
3653 |
pIlc->ilc_poly = 0; |
|
3654 |
} |
|
3655 |
} else { |
|
3656 |
pIlc = &ilc_1; |
|
3657 |
} |
|
1533
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3658 |
} else { |
2647 | 3659 |
pIlc = &ilc_0; |
1533
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3660 |
} |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1685
diff
changeset
|
3661 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2) ); |
1533
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3662 |
%} |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3663 |
|
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3664 |
! |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3665 |
|
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3666 |
perform:aSelector with:arg1 with:arg2 with:arg3 |
1 | 3667 |
"send the three-arg-message aSelector to the receiver" |
3668 |
||
1533
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3669 |
%{ |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3670 |
struct inlineCache *pIlc; |
1820
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3671 |
static struct inlineCache ilc_0 = __ILCPERF3(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3672 |
static struct inlineCache ilc_1 = __ILCPERF3(0); |
1533
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3673 |
static OBJ last_0 = nil; |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3674 |
static OBJ last_1 = nil; |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3675 |
static flip = 0; |
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3676 |
|
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3677 |
if (aSelector != last_0) { |
2647 | 3678 |
if (aSelector != last_1) { |
3679 |
if (flip) { |
|
3680 |
pIlc = &ilc_0; |
|
3681 |
flip = 0; |
|
3682 |
last_0 = aSelector; |
|
3683 |
} else { |
|
3684 |
pIlc = &ilc_1; |
|
3685 |
flip = 1; |
|
3686 |
last_1 = aSelector; |
|
3687 |
} |
|
3688 |
pIlc->ilc_func = __SEND3ADDR__; |
|
3689 |
if (pIlc->ilc_poly) { |
|
3690 |
__flushPolyCache(pIlc->ilc_poly); |
|
3691 |
pIlc->ilc_poly = 0; |
|
3692 |
} |
|
3693 |
} else { |
|
3694 |
pIlc = &ilc_1; |
|
3695 |
} |
|
1533
179ce527e383
added a 2-slot cache to #perform: / #perform:with:* methods.
Claus Gittinger <cg@exept.de>
parents:
1528
diff
changeset
|
3696 |
} else { |
2647 | 3697 |
pIlc = &ilc_0; |
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3698 |
} |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1685
diff
changeset
|
3699 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2, arg3) ); |
1 | 3700 |
%} |
2437 | 3701 |
! |
3702 |
||
3703 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 |
|
3704 |
"send the four-arg-message aSelector to the receiver" |
|
3705 |
||
3706 |
%{ |
|
3707 |
struct inlineCache *pIlc; |
|
3708 |
static struct inlineCache ilc_0 = __ILCPERF4(0); |
|
3709 |
static struct inlineCache ilc_1 = __ILCPERF4(0); |
|
3710 |
static OBJ last_0 = nil; |
|
3711 |
static OBJ last_1 = nil; |
|
3712 |
static flip = 0; |
|
3713 |
||
3714 |
if (aSelector != last_0) { |
|
2647 | 3715 |
if (aSelector != last_1) { |
3716 |
if (flip) { |
|
3717 |
pIlc = &ilc_0; |
|
3718 |
flip = 0; |
|
3719 |
last_0 = aSelector; |
|
3720 |
} else { |
|
3721 |
pIlc = &ilc_1; |
|
3722 |
flip = 1; |
|
3723 |
last_1 = aSelector; |
|
3724 |
} |
|
3725 |
pIlc->ilc_func = __SEND4ADDR__; |
|
3726 |
if (pIlc->ilc_poly) { |
|
3727 |
__flushPolyCache(pIlc->ilc_poly); |
|
3728 |
pIlc->ilc_poly = 0; |
|
3729 |
} |
|
3730 |
} else { |
|
3731 |
pIlc = &ilc_1; |
|
3732 |
} |
|
2437 | 3733 |
} else { |
2647 | 3734 |
pIlc = &ilc_0; |
2437 | 3735 |
} |
3736 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2, arg3, arg4) ); |
|
3737 |
%} |
|
1 | 3738 |
! |
3739 |
||
3740 |
perform:aSelector withArguments:argArray |
|
3741 |
"send the message aSelector with all args taken from argArray |
|
44 | 3742 |
to the receiver." |
1 | 3743 |
|
77 | 3744 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
1 | 3745 |
|
3746 |
numberOfArgs := argArray size. |
|
3747 |
%{ |
|
3748 |
REGISTER OBJ *argP; |
|
3749 |
int nargs, i; |
|
1820
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3750 |
static OBJ last0 = nil; static struct inlineCache ilc0 = __ILCPERF0(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3751 |
static OBJ last1 = nil; static struct inlineCache ilc1 = __ILCPERF1(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3752 |
static OBJ last2 = nil; static struct inlineCache ilc2 = __ILCPERF2(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3753 |
static OBJ last3 = nil; static struct inlineCache ilc3 = __ILCPERF3(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3754 |
static OBJ last4 = nil; static struct inlineCache ilc4 = __ILCPERF4(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3755 |
static OBJ last5 = nil; static struct inlineCache ilc5 = __ILCPERF5(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3756 |
static OBJ last6 = nil; static struct inlineCache ilc6 = __ILCPERF6(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3757 |
static OBJ last7 = nil; static struct inlineCache ilc7 = __ILCPERF7(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3758 |
static OBJ last8 = nil; static struct inlineCache ilc8 = __ILCPERF8(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3759 |
static OBJ last9 = nil; static struct inlineCache ilc9 = __ILCPERF9(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3760 |
static OBJ last10 = nil; static struct inlineCache ilc10 = __ILCPERF10(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3761 |
static OBJ last11 = nil; static struct inlineCache ilc11 = __ILCPERF11(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3762 |
static OBJ last12 = nil; static struct inlineCache ilc12 = __ILCPERF12(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3763 |
static OBJ last13 = nil; static struct inlineCache ilc13 = __ILCPERF13(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3764 |
static OBJ last14 = nil; static struct inlineCache ilc14 = __ILCPERF14(0); |
f56384710f2e
need another ILC-type: ILCPERF.
Claus Gittinger <cg@exept.de>
parents:
1818
diff
changeset
|
3765 |
static OBJ last15 = nil; static struct inlineCache ilc15 = __ILCPERF15(0); |
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3766 |
OBJ l; |
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3767 |
|
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3768 |
#if defined(xxxTHIS_CONTEXT) /* not because this has a context */ |
71 | 3769 |
/* |
93 | 3770 |
* must set lineno in sender by hand here ... (because of NOCONTEXT) |
71 | 3771 |
*/ |
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3772 |
if ((l = __ILC_LNO_AS_OBJ(__pilc)) != __MKSMALLINT(0)) { |
2647 | 3773 |
_ContextInstPtr(__thisContext)->c_lineno = l; |
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3774 |
} |
71 | 3775 |
#endif |
1 | 3776 |
|
253 | 3777 |
if (__isSmallInteger(numberOfArgs)) { |
2647 | 3778 |
nargs = __intVal(numberOfArgs); |
3779 |
if (nargs == 0) { |
|
3780 |
if (aSelector != last0) { |
|
3781 |
ilc0.ilc_func = __SEND0ADDR__; |
|
3782 |
if (ilc0.ilc_poly) { |
|
3783 |
__flushPolyCache(ilc0.ilc_poly); |
|
3784 |
ilc0.ilc_poly = 0; |
|
3785 |
} |
|
3786 |
last0 = aSelector; |
|
3787 |
} |
|
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3788 |
#ifdef xxTHIS_CONTEXT /* not because this has a context */ |
2647 | 3789 |
ilc0.ilc_lineNo = __pilc->ilc_lineNo; |
44 | 3790 |
#endif |
2647 | 3791 |
RETURN ((*ilc0.ilc_func)(self, aSelector, nil, &ilc0)); |
3792 |
} |
|
3793 |
||
3794 |
if (__isArray(argArray)) { |
|
3795 |
argP = __ArrayInstPtr(argArray)->a_element; |
|
3796 |
} else { |
|
3797 |
argP = (OBJ *)(&a1); |
|
3798 |
for (i=1; i <= nargs; i++) { |
|
3799 |
*argP++ = __AT_(argArray, __MKSMALLINT(i)); |
|
3800 |
} |
|
3801 |
} |
|
3802 |
switch (nargs) { |
|
3803 |
case 1: |
|
3804 |
if (aSelector != last1) { |
|
3805 |
ilc1.ilc_func = __SEND1ADDR__; |
|
3806 |
if (ilc1.ilc_poly) { |
|
3807 |
__flushPolyCache(ilc1.ilc_poly); |
|
3808 |
ilc1.ilc_poly = 0; |
|
3809 |
} |
|
3810 |
last1 = aSelector; |
|
3811 |
} |
|
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3812 |
#ifdef xxTHIS_CONTEXT /* not because this has a context */ |
2647 | 3813 |
ilc1.ilc_lineNo = __pilc->ilc_lineNo; |
44 | 3814 |
#endif |
2647 | 3815 |
RETURN ( (*ilc1.ilc_func)(self, aSelector, nil, &ilc1, argP[0])); |
3816 |
||
3817 |
case 2: |
|
3818 |
if (aSelector != last2) { |
|
3819 |
ilc2.ilc_func = __SEND2ADDR__; |
|
3820 |
if (ilc2.ilc_poly) { |
|
3821 |
__flushPolyCache(ilc2.ilc_poly); |
|
3822 |
ilc2.ilc_poly = 0; |
|
3823 |
} |
|
3824 |
last2 = aSelector; |
|
3825 |
} |
|
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3826 |
#ifdef xxTHIS_CONTEXT /* not because this has a context */ |
2647 | 3827 |
ilc2.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3828 |
#endif |
2647 | 3829 |
RETURN ( (*ilc2.ilc_func)(self, aSelector, nil, &ilc2, |
3830 |
argP[0], argP[1])); |
|
3831 |
||
3832 |
case 3: |
|
3833 |
if (aSelector != last3) { |
|
3834 |
ilc3.ilc_func = __SEND3ADDR__; |
|
3835 |
if (ilc3.ilc_poly) { |
|
3836 |
__flushPolyCache(ilc3.ilc_poly); |
|
3837 |
ilc3.ilc_poly = 0; |
|
3838 |
} |
|
3839 |
last3 = aSelector; |
|
3840 |
} |
|
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3841 |
#ifdef xxTHIS_CONTEXT /* not because this has a context */ |
2647 | 3842 |
ilc3.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3843 |
#endif |
2647 | 3844 |
RETURN ( (*ilc3.ilc_func)(self, aSelector, nil, &ilc3, |
3845 |
argP[0], argP[1], argP[2])); |
|
3846 |
||
3847 |
case 4: |
|
3848 |
if (aSelector != last4) { |
|
3849 |
ilc4.ilc_func = __SEND4ADDR__; |
|
3850 |
if (ilc4.ilc_poly) { |
|
3851 |
__flushPolyCache(ilc4.ilc_poly); |
|
3852 |
ilc4.ilc_poly = 0; |
|
3853 |
} |
|
3854 |
last4 = aSelector; |
|
3855 |
} |
|
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3856 |
#ifdef xxTHIS_CONTEXT /* not because this has a context */ |
2647 | 3857 |
ilc4.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3858 |
#endif |
2647 | 3859 |
RETURN ( (*ilc4.ilc_func)(self, aSelector, nil, &ilc4, |
3860 |
argP[0], argP[1], argP[2], argP[3])); |
|
3861 |
||
3862 |
case 5: |
|
3863 |
if (aSelector != last5) { |
|
3864 |
ilc5.ilc_func = __SEND5ADDR__; |
|
3865 |
if (ilc5.ilc_poly) { |
|
3866 |
__flushPolyCache(ilc5.ilc_poly); |
|
3867 |
ilc5.ilc_poly = 0; |
|
3868 |
} |
|
3869 |
last5 = aSelector; |
|
3870 |
} |
|
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3871 |
#ifdef xxTHIS_CONTEXT /* not because this has a context */ |
2647 | 3872 |
ilc5.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3873 |
#endif |
2647 | 3874 |
RETURN ( (*ilc5.ilc_func)(self, aSelector, nil, &ilc5, |
3875 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
3876 |
||
3877 |
case 6: |
|
3878 |
if (aSelector != last6) { |
|
3879 |
ilc6.ilc_func = __SEND6ADDR__; |
|
3880 |
if (ilc6.ilc_poly) { |
|
3881 |
__flushPolyCache(ilc6.ilc_poly); |
|
3882 |
ilc6.ilc_poly = 0; |
|
3883 |
} |
|
3884 |
last6 = aSelector; |
|
3885 |
} |
|
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3886 |
#ifdef xxTHIS_CONTEXT /* not because this has a context */ |
2647 | 3887 |
ilc6.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3888 |
#endif |
2647 | 3889 |
RETURN ( (*ilc6.ilc_func)(self, aSelector, nil, &ilc6, |
3890 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3891 |
argP[5])); |
|
3892 |
||
3893 |
case 7: |
|
3894 |
if (aSelector != last7) { |
|
3895 |
ilc7.ilc_func = __SEND7ADDR__; |
|
3896 |
if (ilc7.ilc_poly) { |
|
3897 |
__flushPolyCache(ilc7.ilc_poly); |
|
3898 |
ilc7.ilc_poly = 0; |
|
3899 |
} |
|
3900 |
last7 = aSelector; |
|
3901 |
} |
|
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3902 |
#ifdef xxTHIS_CONTEXT /* not because this has a context */ |
2647 | 3903 |
ilc7.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3904 |
#endif |
2647 | 3905 |
RETURN ( (*ilc7.ilc_func)(self, aSelector, nil, &ilc7, |
3906 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3907 |
argP[5], argP[6])); |
|
3908 |
||
3909 |
case 8: |
|
3910 |
if (aSelector != last8) { |
|
3911 |
ilc8.ilc_func = __SEND8ADDR__; |
|
3912 |
last8 = aSelector; |
|
3913 |
} |
|
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3914 |
#ifdef xxTHIS_CONTEXT /* not because this has a context */ |
2647 | 3915 |
ilc8.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3916 |
#endif |
2647 | 3917 |
RETURN ( (*ilc8.ilc_func)(self, aSelector, nil, &ilc8, |
3918 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3919 |
argP[5], argP[6], argP[7])); |
|
3920 |
||
3921 |
case 9: |
|
3922 |
if (aSelector != last9) { |
|
3923 |
ilc9.ilc_func = __SEND9ADDR__; |
|
3924 |
last9 = aSelector; |
|
3925 |
} |
|
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3926 |
#ifdef xxTHIS_CONTEXT /* not because this has a context */ |
2647 | 3927 |
ilc9.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3928 |
#endif |
2647 | 3929 |
RETURN ( (*ilc9.ilc_func)(self, aSelector, nil, &ilc9, |
3930 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3931 |
argP[5], argP[6], argP[7], argP[8])); |
|
3932 |
||
3933 |
case 10: |
|
3934 |
if (aSelector != last10) { |
|
3935 |
ilc10.ilc_func = __SEND10ADDR__; |
|
3936 |
last10 = aSelector; |
|
3937 |
} |
|
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3938 |
#ifdef xxTHIS_CONTEXT /* not because this has a context */ |
2647 | 3939 |
ilc10.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3940 |
#endif |
2647 | 3941 |
RETURN ( (*ilc10.ilc_func)(self, aSelector, nil, &ilc10, |
3942 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3943 |
argP[5], argP[6], argP[7], argP[8], argP[9])); |
|
3944 |
||
3945 |
case 11: |
|
3946 |
if (aSelector != last11) { |
|
3947 |
ilc11.ilc_func = __SEND11ADDR__; |
|
3948 |
last11 = aSelector; |
|
3949 |
} |
|
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3950 |
#ifdef xxTHIS_CONTEXT /* not because this has a context */ |
2647 | 3951 |
ilc11.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3952 |
#endif |
2647 | 3953 |
RETURN ( (*ilc11.ilc_func)(self, aSelector, nil, &ilc11, |
3954 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3955 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
3956 |
argP[10])); |
|
3957 |
||
3958 |
case 12: |
|
3959 |
if (aSelector != last12) { |
|
3960 |
ilc12.ilc_func = __SEND12ADDR__; |
|
3961 |
last12 = aSelector; |
|
3962 |
} |
|
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3963 |
#ifdef xxTHIS_CONTEXT /* not because this has a context */ |
2647 | 3964 |
ilc12.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3965 |
#endif |
2647 | 3966 |
RETURN ( (*ilc12.ilc_func)(self, aSelector, nil, &ilc12, |
3967 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3968 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
3969 |
argP[10], argP[11])); |
|
3970 |
||
3971 |
case 13: |
|
3972 |
if (aSelector != last13) { |
|
3973 |
ilc13.ilc_func = __SEND13ADDR__; |
|
3974 |
last13 = aSelector; |
|
3975 |
} |
|
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3976 |
#ifdef xxTHIS_CONTEXT /* not because this has a context */ |
2647 | 3977 |
ilc13.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3978 |
#endif |
2647 | 3979 |
RETURN ( (*ilc13.ilc_func)(self, aSelector, nil, &ilc13, |
3980 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3981 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
3982 |
argP[10], argP[11], argP[12])); |
|
3983 |
||
3984 |
case 14: |
|
3985 |
if (aSelector != last14) { |
|
3986 |
ilc14.ilc_func = __SEND14ADDR__; |
|
3987 |
last14 = aSelector; |
|
3988 |
} |
|
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
3989 |
#ifdef xxTHIS_CONTEXT /* not because this has a context */ |
2647 | 3990 |
ilc14.ilc_lineNo = __pilc->ilc_lineNo; |
71 | 3991 |
#endif |
2647 | 3992 |
RETURN ( (*ilc14.ilc_func)(self, aSelector, nil, &ilc14, |
3993 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
3994 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
3995 |
argP[10], argP[11], argP[12], argP[13])); |
|
3996 |
||
3997 |
case 15: |
|
3998 |
if (aSelector != last15) { |
|
3999 |
ilc15.ilc_func = __SEND15ADDR__; |
|
4000 |
last15 = aSelector; |
|
4001 |
} |
|
1085
3f5ae1995e83
fixed lineNumber info with #perform (that used to work !)
Claus Gittinger <cg@exept.de>
parents:
1078
diff
changeset
|
4002 |
#ifdef xxTHIS_CONTEXT /* not because this has a context */ |
2647 | 4003 |
ilc15.ilc_lineNo = __pilc->ilc_lineNo; |
77 | 4004 |
#endif |
2647 | 4005 |
RETURN ( (*ilc15.ilc_func)(self, aSelector, nil, &ilc15, |
4006 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
4007 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
4008 |
argP[10], argP[11], argP[12], argP[13], |
|
4009 |
argP[14])); |
|
4010 |
} |
|
1 | 4011 |
} |
1626 | 4012 |
%}. |
4013 |
"/ arrive here, if bad number of arguments (too many) |
|
4014 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
4015 |
||
1 | 4016 |
^ self primitiveFailed |
4017 |
! ! |
|
4018 |
||
783 | 4019 |
!Object methodsFor:'misc'! |
4020 |
||
4021 |
-> anObject |
|
4022 |
"return an association with the receiver as key and |
|
4023 |
the argument as value" |
|
4024 |
||
4025 |
^ Association key:self value:anObject |
|
2 | 4026 |
! ! |
4027 |
||
1 | 4028 |
!Object methodsFor:'printing & storing'! |
4029 |
||
4030 |
className |
|
4031 |
"return the classname of the receivers class" |
|
4032 |
||
4033 |
^ self class name |
|
56 | 4034 |
|
293 | 4035 |
" |
4036 |
1 className |
|
4037 |
1 class className 'this may change ...' |
|
4038 |
$a className |
|
4039 |
$a class className 'this may change ...' |
|
4040 |
" |
|
1 | 4041 |
! |
4042 |
||
4043 |
classNameWithArticle |
|
71 | 4044 |
"return a string consisting of classname preceeded by an article. |
4045 |
(dont expect me to write national variants for this ... :-) |
|
4046 |
If you have special preferences, redefine it ..." |
|
1 | 4047 |
|
1391 | 4048 |
|classname cls| |
4049 |
||
4050 |
(cls := self class) == self ifTrue:[ |
|
2647 | 4051 |
^ 'a funny object' |
1391 | 4052 |
]. |
4053 |
classname := cls displayString. |
|
85 | 4054 |
^ classname article , ' ' , classname |
56 | 4055 |
|
293 | 4056 |
" |
4057 |
1 classNameWithArticle |
|
4058 |
(1->2) classNameWithArticle |
|
4059 |
XWorkstation basicNew classNameWithArticle |
|
4060 |
" |
|
1391 | 4061 |
|
4062 |
"Modified: 13.5.1996 / 12:16:14 / cg" |
|
1 | 4063 |
! |
4064 |
||
1445
c2dc94f9921b
added #displayOn: as a common fallBack
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
4065 |
displayOn:aGc |
c2dc94f9921b
added #displayOn: as a common fallBack
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
4066 |
"ST-80 Compatibility |
c2dc94f9921b
added #displayOn: as a common fallBack
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
4067 |
display the receiver in a graphicsContext at 0@0 |
c2dc94f9921b
added #displayOn: as a common fallBack
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
4068 |
- this method allows for any object to be displayed in some view |
c2dc94f9921b
added #displayOn: as a common fallBack
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
4069 |
(although the fallBack is to display its printString ...)" |
c2dc94f9921b
added #displayOn: as a common fallBack
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
4070 |
|
c2dc94f9921b
added #displayOn: as a common fallBack
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
4071 |
^ self displayOn:aGc x:0 y:0. |
c2dc94f9921b
added #displayOn: as a common fallBack
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
4072 |
|
c2dc94f9921b
added #displayOn: as a common fallBack
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
4073 |
"Created: 29.5.1996 / 16:28:58 / cg" |
c2dc94f9921b
added #displayOn: as a common fallBack
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
4074 |
! |
c2dc94f9921b
added #displayOn: as a common fallBack
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
4075 |
|
783 | 4076 |
displayOn:aGc at:aPoint |
4077 |
"ST-80 Compatibility |
|
4078 |
display the receiver in a graphicsContext - this method allows |
|
4079 |
for any object to be displayed in a ListView - for example." |
|
4080 |
||
4081 |
^ self displayOn:aGc x:(aPoint x) y:(aPoint y). |
|
56 | 4082 |
! |
4083 |
||
783 | 4084 |
displayOn:aGc x:x y:y |
4085 |
"display the receiver in a graphicsContext - this method allows |
|
1445
c2dc94f9921b
added #displayOn: as a common fallBack
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
4086 |
for any object to be displayed in a ListView - for example. |
c2dc94f9921b
added #displayOn: as a common fallBack
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
4087 |
The fallBack here shows the receivers printString." |
783 | 4088 |
|
4089 |
^ aGc displayString:(self displayString) x:x y:y. |
|
1445
c2dc94f9921b
added #displayOn: as a common fallBack
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
4090 |
|
c2dc94f9921b
added #displayOn: as a common fallBack
Claus Gittinger <cg@exept.de>
parents:
1425
diff
changeset
|
4091 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
56 | 4092 |
! |
4093 |
||
783 | 4094 |
displayString |
4095 |
"return a string used when displaying the receiver in a view; |
|
4096 |
for example an Inspector. This is usually the same as printString, |
|
4097 |
but sometimes redefined for a better look." |
|
4098 |
||
4099 |
^ self printString |
|
4100 |
||
4101 |
" |
|
4102 |
#(1 2 3) printString |
|
4103 |
#(1 2 3) displayString |
|
4104 |
#(1 2 3) storeString |
|
4105 |
" |
|
1 | 4106 |
! |
4107 |
||
783 | 4108 |
errorPrint |
4109 |
"print the receiver on the standard error stream." |
|
4110 |
||
1089
6df9414b354f
catch errors while errorPrinting (happened when controlling xterm was closed)
Claus Gittinger <cg@exept.de>
parents:
1085
diff
changeset
|
4111 |
Stream streamErrorSignal catch:[ |
2647 | 4112 |
self printOn:Stderr |
1089
6df9414b354f
catch errors while errorPrinting (happened when controlling xterm was closed)
Claus Gittinger <cg@exept.de>
parents:
1085
diff
changeset
|
4113 |
] |
6df9414b354f
catch errors while errorPrinting (happened when controlling xterm was closed)
Claus Gittinger <cg@exept.de>
parents:
1085
diff
changeset
|
4114 |
|
6df9414b354f
catch errors while errorPrinting (happened when controlling xterm was closed)
Claus Gittinger <cg@exept.de>
parents:
1085
diff
changeset
|
4115 |
"Modified: 7.3.1996 / 19:11:29 / cg" |
783 | 4116 |
! |
4117 |
||
1425 | 4118 |
errorPrintCR |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
4119 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
4120 |
|
1089
6df9414b354f
catch errors while errorPrinting (happened when controlling xterm was closed)
Claus Gittinger <cg@exept.de>
parents:
1085
diff
changeset
|
4121 |
"print the receiver followed by a cr on the standard error stream." |
6df9414b354f
catch errors while errorPrinting (happened when controlling xterm was closed)
Claus Gittinger <cg@exept.de>
parents:
1085
diff
changeset
|
4122 |
|
6df9414b354f
catch errors while errorPrinting (happened when controlling xterm was closed)
Claus Gittinger <cg@exept.de>
parents:
1085
diff
changeset
|
4123 |
Stream streamErrorSignal catch:[ |
2647 | 4124 |
self printOn:Stderr. |
4125 |
Stderr cr |
|
1089
6df9414b354f
catch errors while errorPrinting (happened when controlling xterm was closed)
Claus Gittinger <cg@exept.de>
parents:
1085
diff
changeset
|
4126 |
] |
6df9414b354f
catch errors while errorPrinting (happened when controlling xterm was closed)
Claus Gittinger <cg@exept.de>
parents:
1085
diff
changeset
|
4127 |
|
6df9414b354f
catch errors while errorPrinting (happened when controlling xterm was closed)
Claus Gittinger <cg@exept.de>
parents:
1085
diff
changeset
|
4128 |
"Modified: 7.3.1996 / 19:13:01 / cg" |
1425 | 4129 |
"Created: 20.5.1996 / 10:20:41 / cg" |
4130 |
! |
|
4131 |
||
4132 |
errorPrintNL |
|
4133 |
"{ Pragma: +optSpace }" |
|
4134 |
||
4135 |
"print the receiver followed by a cr on the standard error stream. |
|
4136 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
4137 |
||
4138 |
^ self errorPrintCR |
|
4139 |
||
4140 |
"Modified: 20.5.1996 / 10:24:45 / cg" |
|
4141 |
! |
|
4142 |
||
4143 |
errorPrintNewline |
|
4144 |
"{ Pragma: +optSpace }" |
|
4145 |
||
4146 |
"print the receiver followed by a cr on the standard error stream. |
|
4147 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
4148 |
||
4149 |
self errorPrintCR. |
|
4150 |
||
4151 |
"Modified: 20.5.1996 / 10:24:38 / cg" |
|
71 | 4152 |
! |
4153 |
||
356 | 4154 |
infoPrint |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
4155 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
4156 |
|
356 | 4157 |
"print the receiver on the standard error stream. |
4158 |
This is meant for information messages which are not warnings |
|
4159 |
or fatal messages. |
|
4160 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
4161 |
||
2114
706cf3f9019a
initialize InfoPrinting flag from VM's setting
Claus Gittinger <cg@exept.de>
parents:
2096
diff
changeset
|
4162 |
InfoPrinting == true ifTrue:[ |
706cf3f9019a
initialize InfoPrinting flag from VM's setting
Claus Gittinger <cg@exept.de>
parents:
2096
diff
changeset
|
4163 |
self errorPrint |
356 | 4164 |
] |
4165 |
! |
|
4166 |
||
1425 | 4167 |
infoPrintCR |
1119
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
4168 |
"{ Pragma: +optSpace }" |
956d62a5656c
compile seldom used methods with optSpace (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents:
1109
diff
changeset
|
4169 |
|
356 | 4170 |
"print the receiver followed by a cr on the standard error stream. |
4171 |
This is meant for information messages which are not warnings |
|
4172 |
or fatal messages. |
|
4173 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
4174 |
||
2114
706cf3f9019a
initialize InfoPrinting flag from VM's setting
Claus Gittinger <cg@exept.de>
parents:
2096
diff
changeset
|
4175 |
InfoPrinting == true ifTrue:[ |
2647 | 4176 |
self errorPrintCR |
356 | 4177 |
] |
1425 | 4178 |
|
4179 |
"Created: 20.5.1996 / 10:21:28 / cg" |
|
4180 |
! |
|
4181 |
||
4182 |
infoPrintNL |
|
4183 |
"{ Pragma: +optSpace }" |
|
4184 |
||
4185 |
"print the receiver followed by a cr on the standard error stream. |
|
4186 |
This is meant for information messages which are not warnings |
|
4187 |
or fatal messages. |
|
4188 |
These messages can be turned on/off by 'Object infoPrinting:true/false'. |
|
4189 |
||
4190 |
Please use #infoPrintCR - this method exists for backward compatibility." |
|
4191 |
||
2114
706cf3f9019a
initialize InfoPrinting flag from VM's setting
Claus Gittinger <cg@exept.de>
parents:
2096
diff
changeset
|
4192 |
^ self infoPrintCR |
1425 | 4193 |
|
4194 |
"Modified: 20.5.1996 / 10:25:07 / cg" |
|
356 | 4195 |
! |
4196 |
||
783 | 4197 |
|
1887 | 4198 |
"print the receiver on the standard output stream (which is not the Transcript)" |
783 | 4199 |
|
4200 |
self printOn:Stdout |
|
1887 | 4201 |
|
4202 |
"Modified: 4.11.1996 / 23:36:58 / cg" |
|
783 | 4203 |
! |
4204 |
||
1425 | 4205 |
printCR |
1887 | 4206 |
"print the receiver followed by a cr on the standard output stream (which is not the Transcript)" |
783 | 4207 |
|
4208 |
self printOn:Stdout. |
|
4209 |
Stdout cr |
|
1425 | 4210 |
|
4211 |
"Created: 20.5.1996 / 10:21:37 / cg" |
|
1887 | 4212 |
"Modified: 4.11.1996 / 23:37:06 / cg" |
1425 | 4213 |
! |
4214 |
||
4215 |
printNL |
|
4216 |
"print the receiver followed by a cr on the standard output stream |
|
4217 |
This exists for GNU Smalltalk compatibility - please use #printCR." |
|
4218 |
||
4219 |
^ self printCR |
|
4220 |
||
4221 |
"Modified: 20.5.1996 / 10:25:31 / cg" |
|
4222 |
! |
|
4223 |
||
4224 |
printNewline |
|
4225 |
"print the receiver followed by a cr on the standard output stream. |
|
4226 |
This exists for backward compatibility - please use #printCR." |
|
4227 |
||
4228 |
self printCR |
|
4229 |
||
4230 |
"Modified: 20.5.1996 / 10:25:46 / cg" |
|
783 | 4231 |
! |
4232 |
||
4233 |
printOn:aStream |
|
4234 |
"print the receiver on the argument-stream. |
|
4235 |
The default here is to output the receivers class name. |
|
4236 |
BUT: this method is heavily redefined for objects which |
|
4237 |
can print prettier." |
|
4238 |
||
4239 |
aStream nextPutAll:self classNameWithArticle |
|
4240 |
! |
|
4241 |
||
4242 |
printOn:aStream leftPaddedTo:size |
|
4243 |
"print the receiver on aStream, padding with spaces up to size. |
|
4244 |
padding is done on the left." |
|
4245 |
||
4246 |
self printOn:aStream leftPaddedTo:size with:(Character space) |
|
4247 |
||
4248 |
" |
|
4249 |
123 printOn:Transcript leftPaddedTo:10. Transcript cr |
|
4250 |
123 printOn:Transcript leftPaddedTo:2. Transcript cr |
|
4251 |
" |
|
71 | 4252 |
! |
4253 |
||
783 | 4254 |
printOn:aStream leftPaddedTo:size with:padCharacter |
4255 |
"print the receiver on aStream, padding with padCharacters up to size. |
|
4256 |
padding is done on the left." |
|
4257 |
||
4258 |
aStream nextPutAll:(self printStringLeftPaddedTo:size with:padCharacter) |
|
4259 |
||
4260 |
" |
|
4261 |
123 printOn:Transcript leftPaddedTo:10 with:$_ . Transcript cr |
|
4262 |
123 printOn:Transcript leftPaddedTo:10 with:$. . Transcript cr |
|
4263 |
" |
|
4264 |
! |
|
4265 |
||
4266 |
printOn:aStream paddedTo:size |
|
4267 |
"print the receiver on aStream, padding with spaces up to size." |
|
4268 |
||
4269 |
self printOn:aStream paddedTo:size with:(Character space) |
|
4270 |
||
4271 |
" |
|
4272 |
123.0 printOn:Transcript paddedTo:10. Transcript nextPut:$|. Transcript cr |
|
4273 |
" |
|
71 | 4274 |
! |
4275 |
||
783 | 4276 |
printOn:aStream paddedTo:size with:padCharacter |
4277 |
"print the receiver on aStream, padding with padCharacter up to size" |
|
4278 |
||
4279 |
aStream nextPutAll:(self printStringPaddedTo:size with:padCharacter). |
|
4280 |
||
4281 |
" |
|
4282 |
123 printOn:Transcript paddedTo:10 with:$_ . Transcript cr |
|
4283 |
123 printOn:Transcript paddedTo:10 with:$. . Transcript cr |
|
4284 |
" |
|
4285 |
! |
|
4286 |
||
4287 |
printOn:aStream zeroPaddedTo:size |
|
4288 |
"print the receiver on aStream, padding with zeros up to size. |
|
4289 |
Usually used with float numbers." |
|
4290 |
||
4291 |
self printOn:aStream paddedTo:size with:$0. |
|
4292 |
||
4293 |
" |
|
4294 |
123.0 printOn:Transcript zeroPaddedTo:10 |
|
4295 |
" |
|
4296 |
! |
|
4297 |
||
4298 |
printRightAdjustLen:size |
|
4299 |
"obsolete - just a name confusion. |
|
4300 |
This method will go away ..." |
|
4301 |
||
4302 |
(self printStringLeftPaddedTo:size) printOn:Stdout |
|
71 | 4303 |
! |
4304 |
||
4305 |
printString |
|
4306 |
"return a string for printing the receiver. |
|
4307 |
Since we now use printOn: as the basic print mechanism, |
|
4308 |
we have to create a stream and print into it." |
|
4309 |
||
4310 |
|s| |
|
4311 |
||
4312 |
s := WriteStream on:(String new:30). |
|
4313 |
self printOn:s. |
|
4314 |
^ s contents |
|
4315 |
! |
|
4316 |
||
783 | 4317 |
printStringLeftPaddedTo:size |
4318 |
"return my printString as a right-adjusted string of length size; |
|
4319 |
characters on the left are filled with spaces. |
|
4320 |
If the printString is longer than size, |
|
4321 |
it is returned unchanged (i.e. not truncated)" |
|
4322 |
||
4323 |
^ self printStringLeftPaddedTo:size with:(Character space) |
|
4324 |
||
4325 |
" |
|
4326 |
10 printStringLeftPaddedTo:10 |
|
4327 |
1 printStringLeftPaddedTo:10 |
|
4328 |
" |
|
4329 |
! |
|
4330 |
||
4331 |
printStringLeftPaddedTo:size ifLarger:alternative |
|
4332 |
"return my printString as a right-adjusted string of length size; |
|
4333 |
characters on the left are filled with spaces. |
|
4334 |
If the printString is larger than size, |
|
4335 |
return the result from evaluating alternative." |
|
4336 |
||
4337 |
^ self printStringLeftPaddedTo:size with:(Character space) ifLarger:alternative |
|
4338 |
||
4339 |
" |
|
4340 |
12 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
4341 |
123 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
4342 |
1234 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
4343 |
" |
|
4344 |
! |
|
4345 |
||
4346 |
printStringLeftPaddedTo:size with:padCharacter |
|
4347 |
"return my printString as a right-adjusted string of length size; |
|
4348 |
characters on the left are filled with padCharacter. |
|
4349 |
If the printString is longer than size, |
|
4350 |
it is returned unchanged (i.e. not truncated)" |
|
4351 |
||
4352 |
^ (self printString) leftPaddedTo:size with:padCharacter |
|
4353 |
||
4354 |
" |
|
4355 |
123 printStringLeftPaddedTo:10 with:$. |
|
4356 |
1 printStringLeftPaddedTo:10 with:$. |
|
4357 |
(Float pi) printStringLeftPaddedTo:20 with:$* |
|
4358 |
" |
|
4359 |
! |
|
4360 |
||
4361 |
printStringLeftPaddedTo:size with:padCharacter ifLarger:alternative |
|
4362 |
"return my printString as a right-adjusted string of length size; |
|
4363 |
characters on the left are filled with padCharacter. |
|
4364 |
If the printString is larger than size, |
|
369 | 4365 |
return the result from evaluating alternative." |
4366 |
||
4367 |
|s| |
|
4368 |
||
4369 |
s := self printString. |
|
4370 |
s size > size ifTrue:[^ alternative value]. |
|
783 | 4371 |
^ s leftPaddedTo:size with:padCharacter |
369 | 4372 |
|
4373 |
" |
|
783 | 4374 |
12 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
4375 |
123 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
4376 |
1234 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
293 | 4377 |
" |
13 | 4378 |
! |
4379 |
||
4380 |
printStringPaddedTo:size |
|
56 | 4381 |
"return a printed representation of the receiver, |
369 | 4382 |
padded with spaces (at the right) up to size. |
293 | 4383 |
If the printString is longer than size, |
4384 |
it is returned unchanged (i.e. not truncated)" |
|
13 | 4385 |
|
4386 |
^ self printStringPaddedTo:size with:(Character space) |
|
4387 |
||
293 | 4388 |
" |
4389 |
123 printStringPaddedTo:10 |
|
4390 |
1234567890123456 printStringPaddedTo:10 |
|
4391 |
'hello' printStringPaddedTo:10 |
|
4392 |
" |
|
2 | 4393 |
! |
4394 |
||
369 | 4395 |
printStringPaddedTo:size ifLarger:alternative |
4396 |
"return a printed representation of the receiver, |
|
4397 |
padded with spaces (at the right) up to size. |
|
4398 |
If the resulting printString is too large, |
|
4399 |
return the result from evaluating alternative." |
|
4400 |
||
4401 |
^ self printStringPaddedTo:size with:(Character space) ifLarger:alternative |
|
4402 |
||
4403 |
" |
|
4404 |
12 printStringPaddedTo:3 ifLarger:['***'] |
|
4405 |
123 printStringPaddedTo:3 ifLarger:['***'] |
|
4406 |
1234 printStringPaddedTo:3 ifLarger:['***'] |
|
4407 |
" |
|
4408 |
! |
|
4409 |
||
783 | 4410 |
printStringPaddedTo:size with:padCharacter |
4411 |
"return a printed representation of the receiver, |
|
4412 |
padded with padCharacter (at the right) up to size. |
|
4413 |
If the printString is longer than size, |
|
4414 |
it is returned unchanged (i.e. not truncated)" |
|
4415 |
||
4416 |
^ (self printString) paddedTo:size with:padCharacter |
|
4417 |
||
4418 |
" |
|
4419 |
123 printStringPaddedTo:10 with:$. |
|
4420 |
123 printStringPaddedTo:10 with:$* |
|
4421 |
123 printStringPaddedTo:3 with:$* |
|
4422 |
1234 printStringPaddedTo:3 with:$* |
|
4423 |
" |
|
4424 |
! |
|
4425 |
||
4426 |
printStringPaddedTo:size with:padCharacter ifLarger:alternative |
|
4427 |
"return a printed representation of the receiver, |
|
4428 |
padded with padCharacter (at the right) up to size. |
|
4429 |
If the resulting printString is too large, |
|
4430 |
return the result from evaluating alternative." |
|
4431 |
||
4432 |
|s| |
|
4433 |
||
4434 |
s := self printString. |
|
4435 |
s size > size ifTrue:[^ alternative value]. |
|
4436 |
^ s paddedTo:size with:padCharacter |
|
4437 |
||
4438 |
" |
|
4439 |
123 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
4440 |
12345 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
4441 |
" |
|
4442 |
! |
|
4443 |
||
4444 |
printStringRightAdjustLen:size |
|
4445 |
"obsolete - just a name confusion. |
|
4446 |
This method will go away ..." |
|
4447 |
||
4448 |
^ self printStringLeftPaddedTo:size |
|
4449 |
! |
|
4450 |
||
2 | 4451 |
printStringZeroPaddedTo:size |
71 | 4452 |
"return a printed representation of the receiver, |
369 | 4453 |
padded with zero (at the right) characters up to size. |
13 | 4454 |
Usually used with float numbers." |
2 | 4455 |
|
4456 |
^ self printStringPaddedTo:size with:$0 |
|
13 | 4457 |
|
293 | 4458 |
" |
4459 |
123.0 printStringZeroPaddedTo:10 |
|
4460 |
" |
|
2 | 4461 |
! |
4462 |
||
783 | 4463 |
store |
4464 |
"store the receiver on standard output. |
|
4465 |
this method is useless, but included for compatibility." |
|
4466 |
||
4467 |
self storeOn:Stdout |
|
71 | 4468 |
! |
4469 |
||
1425 | 4470 |
storeCR |
4471 |
"store the receiver on standard output; append a carriage return." |
|
4472 |
||
4473 |
self store. |
|
4474 |
Character cr print |
|
4475 |
||
4476 |
"Created: 20.5.1996 / 10:26:01 / cg" |
|
4477 |
"Modified: 20.5.1996 / 10:26:57 / cg" |
|
4478 |
! |
|
4479 |
||
783 | 4480 |
storeNl |
4481 |
"store the receiver on standard output; append a newline. |
|
1425 | 4482 |
This method is included for backward compatibility- use #storeCR." |
4483 |
||
4484 |
self storeCR. |
|
4485 |
||
4486 |
"Modified: 20.5.1996 / 10:26:49 / cg" |
|
460
7e058858cc3b
New Method: displayOn:aGc at:aPoint (ST80-compatibility).
Stefan Vogel <sv@exept.de>
parents:
446
diff
changeset
|
4487 |
! |
7e058858cc3b
New Method: displayOn:aGc at:aPoint (ST80-compatibility).
Stefan Vogel <sv@exept.de>
parents:
446
diff
changeset
|
4488 |
|
56 | 4489 |
storeOn:aStream |
4490 |
"store the receiver on aStream; i.e. print an expression which will |
|
293 | 4491 |
reconstruct the receiver. |
4492 |
Notice, that no self referencing or cyclic objects can be represented |
|
4493 |
in this format. |
|
4494 |
Use storeBinaryOn:, which handles these cases correctly." |
|
56 | 4495 |
|
4496 |
|myClass hasSemi sz "{ Class: SmallInteger }" | |
|
1 | 4497 |
|
25 | 4498 |
thisContext isRecursive ifTrue:[ |
2647 | 4499 |
('Object [error]: storeString of self referencing object.') errorPrintCR. |
4500 |
aStream nextPutAll:'#("recursive")'. |
|
4501 |
^ self |
|
25 | 4502 |
]. |
56 | 4503 |
|
1 | 4504 |
myClass := self class. |
56 | 4505 |
aStream nextPut:$(. |
4506 |
aStream nextPutAll:self class name. |
|
4507 |
||
1 | 4508 |
hasSemi := false. |
4509 |
myClass isVariable ifTrue:[ |
|
2647 | 4510 |
aStream nextPutAll:' basicNew:'. |
4511 |
self basicSize printOn:aStream |
|
1 | 4512 |
] ifFalse:[ |
2647 | 4513 |
aStream nextPutAll:' basicNew' |
1 | 4514 |
]. |
56 | 4515 |
|
1 | 4516 |
sz := myClass instSize. |
4517 |
1 to:sz do:[:i | |
|
2647 | 4518 |
aStream nextPutAll:' instVarAt:'. |
4519 |
i printOn:aStream. |
|
4520 |
aStream nextPutAll:' put:'. |
|
4521 |
(self instVarAt:i) storeOn:aStream. |
|
4522 |
aStream nextPut:$;. |
|
4523 |
hasSemi := true |
|
1 | 4524 |
]. |
4525 |
myClass isVariable ifTrue:[ |
|
2647 | 4526 |
sz := self basicSize. |
4527 |
1 to:sz do:[:i | |
|
4528 |
aStream nextPutAll:' basicAt:'. |
|
4529 |
i printOn:aStream. |
|
4530 |
aStream nextPutAll:' put:'. |
|
4531 |
(self basicAt:i) storeOn:aStream. |
|
4532 |
aStream nextPut:$;. |
|
4533 |
hasSemi := true |
|
4534 |
] |
|
1 | 4535 |
]. |
4536 |
hasSemi ifTrue:[ |
|
2647 | 4537 |
aStream nextPutAll:' yourself' |
1 | 4538 |
]. |
56 | 4539 |
aStream nextPut:$). |
293 | 4540 |
|
4541 |
" |
|
4542 |
|s| |
|
4543 |
||
4544 |
s := WriteStream on:(String new). |
|
4545 |
('hello' -> 'world') storeOn:s. |
|
4546 |
s := ReadStream on:(s contents). |
|
4547 |
(Object readFrom:s) inspect |
|
4548 |
" |
|
4549 |
" |
|
4550 |
|s| |
|
4551 |
||
4552 |
s := 'data' asFilename writeStream. |
|
4553 |
('hello' -> 'world') storeOn:s. |
|
4554 |
s close. |
|
4555 |
||
4556 |
s := 'data' asFilename readStream. |
|
4557 |
(Object readFrom:s) inspect |
|
4558 |
" |
|
4559 |
||
4560 |
"does not work example:" |
|
4561 |
" |
|
4562 |
|s a| |
|
4563 |
||
4564 |
a := Array new:2. |
|
4565 |
a at:1 put:a. |
|
4566 |
||
4567 |
s := 'data' asFilename writeStream. |
|
4568 |
a storeOn:s. |
|
4569 |
s close. |
|
4570 |
||
4571 |
s := 'data' asFilename readStream. |
|
4572 |
(Object readFrom:s) inspect |
|
4573 |
" |
|
1417 | 4574 |
|
2287 | 4575 |
"Modified: 28.1.1997 / 00:36:12 / cg" |
1 | 4576 |
! |
4577 |
||
56 | 4578 |
storeString |
293 | 4579 |
"return a string representing an expression to reconstruct the receiver. |
4580 |
Notice, that no self referencing or cyclic objects can be represented |
|
4581 |
in this format. |
|
4582 |
Use storeBinaryOn:, which handles these cases correctly." |
|
56 | 4583 |
|
4584 |
|s| |
|
4585 |
||
4586 |
s := WriteStream on:(String new:50). |
|
4587 |
self storeOn:s. |
|
4588 |
^ s contents |
|
783 | 4589 |
! ! |
4590 |
||
4591 |
!Object methodsFor:'queries'! |
|
4592 |
||
4593 |
basicSize |
|
4594 |
"return the number of the receivers indexed instance variables, |
|
4595 |
0 if it has none. |
|
4596 |
||
2148 | 4597 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
783 | 4598 |
|
4599 |
%{ /* NOCONTEXT */ |
|
4600 |
||
4601 |
REGISTER int nbytes; |
|
4602 |
REGISTER OBJ myClass; |
|
2209 | 4603 |
REGISTER INT flags; |
783 | 4604 |
|
4605 |
/* |
|
4606 |
* notice the missing test for self being a nonNilObject - |
|
4607 |
* this can be done since basicSize is defined both in UndefinedObject |
|
4608 |
* and SmallInteger |
|
4609 |
*/ |
|
4610 |
myClass = __qClass(self); |
|
4611 |
nbytes = __qSize(self) |
|
2647 | 4612 |
- OHDR_SIZE |
4613 |
- __OBJS2BYTES__(__intVal(__ClassInstPtr(myClass)->c_ninstvars)); |
|
1133 | 4614 |
|
2209 | 4615 |
flags = (INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK); |
783 | 4616 |
/* |
4617 |
* replaced switch by open-if; this is slightly faster since |
|
4618 |
* it avoids the range check and also checks the most common case first |
|
4619 |
*/ |
|
2209 | 4620 |
if (flags == __MASKSMALLINT(POINTERARRAY)) { |
2647 | 4621 |
RETURN ( __MKSMALLINT(__BYTES2OBJS__(nbytes)) ); |
783 | 4622 |
} |
2209 | 4623 |
if (flags == __MASKSMALLINT(BYTEARRAY)) { |
2647 | 4624 |
RETURN ( __MKSMALLINT(nbytes / sizeof(char)) ); |
783 | 4625 |
} |
2209 | 4626 |
if (flags == __MASKSMALLINT(WKPOINTERARRAY)) { |
4627 |
RETURN ( __MKSMALLINT(__BYTES2OBJS__(nbytes)) ); |
|
4628 |
} |
|
4629 |
if (flags == __MASKSMALLINT(FLOATARRAY)) { |
|
2647 | 4630 |
RETURN ( __MKSMALLINT(nbytes / sizeof(float)) ); |
783 | 4631 |
} |
2209 | 4632 |
if (flags == __MASKSMALLINT(DOUBLEARRAY)) { |
783 | 4633 |
#ifdef NEED_DOUBLE_ALIGN |
2647 | 4634 |
/* |
4635 |
* care for filler |
|
4636 |
*/ |
|
4637 |
nbytes -= sizeof(FILLTYPE); |
|
783 | 4638 |
#endif |
2647 | 4639 |
RETURN ( __MKSMALLINT(nbytes / sizeof(double)) ); |
783 | 4640 |
} |
2209 | 4641 |
if ((flags == __MASKSMALLINT(WORDARRAY)) || (flags == __MASKSMALLINT(SWORDARRAY))) { |
2647 | 4642 |
RETURN ( __MKSMALLINT(nbytes / sizeof(short)) ); |
783 | 4643 |
} |
2209 | 4644 |
if ((flags == __MASKSMALLINT(LONGARRAY)) || (flags == __MASKSMALLINT(SLONGARRAY))) { |
2647 | 4645 |
RETURN ( __MKSMALLINT(nbytes / sizeof(long)) ); |
783 | 4646 |
} |
4647 |
%}. |
|
4648 |
^ 0 |
|
1 | 4649 |
! |
4650 |
||
2575
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4651 |
byteSize |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4652 |
"return the number of bytes in the receivers indexed instance variables, |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4653 |
0 if it has none. This only returns non-zero for non-pointer indexed |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4654 |
instvars i.e. byteArrays, wordArrays etc. |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4655 |
Notice: for Strings the returned size may look strange. |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4656 |
Only useful with binary storage." |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4657 |
|
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4658 |
%{ /* NOCONTEXT */ |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4659 |
|
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4660 |
REGISTER int indx; |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4661 |
int nIndex; |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4662 |
REGISTER OBJ slf; |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4663 |
REGISTER OBJ cls; |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4664 |
|
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4665 |
slf = self; |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4666 |
if (__isNonNilObject(slf)) { |
2647 | 4667 |
cls = __qClass(slf); |
4668 |
||
4669 |
switch (__intVal(__ClassInstPtr(cls)->c_flags) & ARRAYMASK) { |
|
4670 |
case BYTEARRAY: |
|
4671 |
case WORDARRAY: |
|
4672 |
case LONGARRAY: |
|
4673 |
case SWORDARRAY: |
|
4674 |
case SLONGARRAY: |
|
4675 |
case FLOATARRAY: |
|
4676 |
case DOUBLEARRAY: |
|
4677 |
nIndex = __byteArraySize(slf); |
|
4678 |
nIndex -= __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
4679 |
RETURN ( __MKSMALLINT(nIndex) ); |
|
4680 |
} |
|
2575
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4681 |
} |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4682 |
%}. |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4683 |
^ 0 |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4684 |
|
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4685 |
" |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4686 |
Point new byteSize |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4687 |
'hello' byteSize |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4688 |
(ByteArray with:1 with:2) byteSize |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4689 |
(FloatArray with:1.5) byteSize |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4690 |
" |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4691 |
! |
797f7408e03c
added #byteSize (for binary storage)
Claus Gittinger <cg@exept.de>
parents:
2574
diff
changeset
|
4692 |
|
783 | 4693 |
class |
4694 |
"return the receivers class" |
|
4695 |
||
4696 |
%{ /* NOCONTEXT */ |
|
4697 |
||
4698 |
RETURN ( __Class(self) ); |
|
4699 |
%} |
|
4700 |
! |
|
4701 |
||
4702 |
respondsTo:aSelector |
|
4703 |
"return true, if the receiver implements a method with selector equal |
|
4704 |
to aSelector; i.e. if there is a method for aSelector in either the |
|
4705 |
receivers class or one of its superclasses. |
|
4706 |
||
4707 |
Notice, that this does not imply, that such a message can be sent without |
|
4708 |
an error being raised. For example, an implementation could send |
|
4709 |
#shouldNotImplement or #subclassResponsibility." |
|
4710 |
||
4711 |
" |
|
4712 |
should we go via the cache, or search (by class) ? |
|
4713 |
The first is faster, most of the time; while the 2nd fills |
|
4714 |
the cache with useless data if this is sent in a loop over all objects. |
|
4715 |
For now, use the cache ... |
|
4716 |
" |
|
4717 |
%{ /* NOCONTEXT */ |
|
4718 |
||
829
fc386319f41c
removed external function defs (soon no longer allowed)
Claus Gittinger <cg@exept.de>
parents:
816
diff
changeset
|
4719 |
if (__lookup(__Class(self), aSelector) == nil) { |
783 | 4720 |
RETURN ( false ); |
4721 |
} |
|
4722 |
RETURN ( true ); |
|
4723 |
%} |
|
4724 |
. |
|
4725 |
" |
|
4726 |
^ self class canUnderstand:aSelector |
|
4727 |
" |
|
4728 |
||
4729 |
"'aString' respondsTo:#+" |
|
4730 |
"'aString' respondsTo:#," |
|
4731 |
"'aString' respondsTo:#collect:" |
|
4732 |
! |
|
4733 |
||
4734 |
respondsToArithmetic |
|
4735 |
"return true, if the receiver responds to arithmetic messages. |
|
4736 |
false is returned here - the method is redefined in ArithmeticValue." |
|
4737 |
||
4738 |
^ false |
|
4739 |
! |
|
4740 |
||
4741 |
size |
|
4742 |
"return the number of the receivers indexed instance variables; |
|
4743 |
this method may be redefined in subclasses" |
|
4744 |
||
4745 |
^ self basicSize |
|
4746 |
! |
|
4747 |
||
4748 |
species |
|
4749 |
"return a class which is similar to (or the same as) the receivers class. |
|
4750 |
This is used to create an appropriate object when creating derived |
|
4751 |
copies in the collection classes (sometimes redefined)." |
|
4752 |
||
4753 |
^ self class |
|
4754 |
! |
|
4755 |
||
4756 |
yourself |
|
4757 |
"return the receiver - used for cascades to return self at the end" |
|
4758 |
||
4759 |
^ self |
|
4760 |
! ! |
|
4761 |
||
4762 |
!Object methodsFor:'secure message sending'! |
|
4763 |
||
4764 |
askFor:aSelector |
|
4765 |
"try to send the receiver the message, aSelector. |
|
4766 |
If it does not understand it, return false. Otherwise |
|
4767 |
the real value returned. |
|
4768 |
Useful to send messages such as: 'isColor' to unknown |
|
4769 |
receivers." |
|
4770 |
||
4771 |
^ self perform:aSelector ifNotUnderstood:[false] |
|
4772 |
||
4773 |
" |
|
4774 |
1 askFor:#isColor |
|
4775 |
" |
|
4776 |
! |
|
4777 |
||
4778 |
perform:aSelector ifNotUnderstood:exceptionBlock |
|
4779 |
"try to send message aSelector to the receiver. |
|
4780 |
If its understood, return the methods returned value, |
|
4781 |
otherwise return the value of the exceptionBlock" |
|
4782 |
||
4783 |
|val| |
|
4784 |
||
4785 |
MessageNotUnderstoodSignal handle:[:ex | |
|
4786 |
^ exceptionBlock value |
|
4787 |
] do:[ |
|
4788 |
val := self perform:aSelector |
|
4789 |
]. |
|
4790 |
^ val |
|
4791 |
||
4792 |
" |
|
4793 |
1.2345 perform:#foo ifNotUnderstood:['sorry'] |
|
4794 |
" |
|
1 | 4795 |
! |
4796 |
||
783 | 4797 |
perform:aSelector with:argument ifNotUnderstood:exceptionBlock |
4798 |
"try to send message aSelector to the receiver. |
|
4799 |
If its understood, return the methods returned value, |
|
4800 |
otherwise return the value of the exceptionBlock" |
|
4801 |
||
4802 |
|val| |
|
4803 |
||
4804 |
MessageNotUnderstoodSignal handle:[:ex | |
|
4805 |
^ exceptionBlock value |
|
4806 |
] do:[ |
|
4807 |
val := self perform:aSelector with:argument |
|
4808 |
]. |
|
4809 |
^ val |
|
4810 |
||
4811 |
" |
|
4812 |
|unknown| |
|
4813 |
||
4814 |
unknown := 1. |
|
4815 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
4816 |
unknown := 'high there'. |
|
4817 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
4818 |
" |
|
2506
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4819 |
! |
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4820 |
|
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4821 |
perform:aSelector withArguments:argumentArray ifNotUnderstood:exceptionBlock |
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4822 |
"try to send message aSelector to the receiver. |
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4823 |
If its understood, return the methods returned value, |
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4824 |
otherwise return the value of the exceptionBlock" |
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4825 |
|
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4826 |
|val| |
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4827 |
|
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4828 |
MessageNotUnderstoodSignal handle:[:ex | |
2647 | 4829 |
^ exceptionBlock value |
2506
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4830 |
] do:[ |
2647 | 4831 |
val := self perform:aSelector withArguments:argumentArray |
2506
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4832 |
]. |
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4833 |
^ val |
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4834 |
|
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4835 |
" |
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4836 |
|unknown| |
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4837 |
|
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4838 |
unknown := 1. |
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4839 |
(unknown perform:#+ withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4840 |
unknown := 'high there'. |
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4841 |
(unknown perform:#+ withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4842 |
" |
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4843 |
|
255c87b6fb4f
added #perform:withArguments:ifNotUnderstood:
Claus Gittinger <cg@exept.de>
parents:
2505
diff
changeset
|
4844 |
"Modified: 27.3.1997 / 14:13:16 / cg" |
783 | 4845 |
! ! |
4846 |
||
2448 | 4847 |
!Object methodsFor:'signal constants'! |
4848 |
||
4849 |
messageNotUnderstoodSignal |
|
4850 |
^ MessageNotUnderstoodSignal |
|
4851 |
||
4852 |
"Created: 6.3.1997 / 15:46:52 / cg" |
|
4853 |
! ! |
|
4854 |
||
783 | 4855 |
!Object methodsFor:'special queries'! |
4856 |
||
4857 |
allOwners |
|
4858 |
"return a collection of all objects referencing the receiver" |
|
4859 |
||
4860 |
^ ObjectMemory whoReferences:self |
|
4861 |
! |
|
4862 |
||
4863 |
references:anObject |
|
4864 |
"return true, if the receiver refers to the argument, anObject. |
|
4865 |
- for debugging only" |
|
4866 |
||
1109
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4867 |
"/ |myClass |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4868 |
"/ numInst "{ Class: SmallInteger }" | |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4869 |
|
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4870 |
%{ /* NOCONTEXT */ |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4871 |
OBJ cls, flags; |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4872 |
int nInsts, i; |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4873 |
|
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4874 |
if (! __isNonNilObject(self)) { |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4875 |
RETURN (false); |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4876 |
} |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4877 |
|
783 | 4878 |
/* |
4879 |
* a little optimization: use the fact that all old objects |
|
4880 |
* refering to a new object are on the remSet; if I am not, |
|
4881 |
* a trivial reject is possible, if anObject is a newbee |
|
4882 |
*/ |
|
1109
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4883 |
if (__isNonNilObject(anObject)) { |
783 | 4884 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
4885 |
int spc; |
|
4886 |
||
4887 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
4888 |
RETURN (false); |
|
4889 |
} |
|
4890 |
} |
|
4891 |
} |
|
1109
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4892 |
|
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4893 |
cls = __qClass(self); |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4894 |
if (cls == anObject) { |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4895 |
RETURN (true); |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4896 |
} |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4897 |
|
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4898 |
flags = __ClassInstPtr(cls)->c_flags; |
1386
a31cecccdfd8
_MASKSMALLINT -> __MASKSMALLINT;
Claus Gittinger <cg@exept.de>
parents:
1377
diff
changeset
|
4899 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
2647 | 4900 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
1109
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4901 |
} else { |
2647 | 4902 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
1109
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4903 |
} |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4904 |
if (! nInsts) { |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4905 |
RETURN (false); |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4906 |
} |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4907 |
for (i=0; i<nInsts; i++) { |
2647 | 4908 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
1109
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4909 |
RETURN (true); |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4910 |
} |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4911 |
} |
783 | 4912 |
%}. |
4913 |
||
1109
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4914 |
"/ myClass := self class. |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4915 |
"/ |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4916 |
"/ "check the class" |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4917 |
"/ (myClass == anObject) ifTrue:[^ true]. |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4918 |
"/ |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4919 |
"/ "check the instance variables" |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4920 |
"/ numInst := myClass instSize. |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4921 |
"/ 1 to:numInst do:[:i | |
2647 | 4922 |
"/ ((self instVarAt:i) == anObject) ifTrue:[^ true] |
1109
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4923 |
"/ ]. |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4924 |
"/ |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4925 |
"/ "check the indexed variables" |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4926 |
"/ myClass isVariable ifTrue:[ |
2647 | 4927 |
"/ myClass isPointers ifFalse:[ |
4928 |
"/ "/ |
|
4929 |
"/ "/ we could argue about the following unconditional return: |
|
4930 |
"/ "/ it says that a non pointer array never has a reference to the |
|
4931 |
"/ "/ corresponding object - not mimicing a reference to a copy of the |
|
4932 |
"/ "/ integer. However, it avoids useless searches in huge byteArray |
|
4933 |
"/ "/ like objects when searching for owners. If in doubt, remove it. |
|
4934 |
"/ "/ A consequence of the return below is that #[1 2 3] will say that it |
|
4935 |
"/ "/ does not refer to the number 2 (think of keeping a copy instead) |
|
1109
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4936 |
"/ |
2647 | 4937 |
"/ ^ false. |
1109
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4938 |
"/ |
2647 | 4939 |
"/ "/ alternative: |
4940 |
"/ "/ anObject isNumber ifFalse:[^ false]. |
|
4941 |
"/ ]. |
|
1109
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4942 |
"/ |
2647 | 4943 |
"/ "/ |
4944 |
"/ "/ because arrays are so common, and those have a highly tuned |
|
4945 |
"/ "/ idenitytIndex method, use it |
|
4946 |
"/ "/ |
|
4947 |
"/ myClass == Array ifTrue:[ |
|
4948 |
"/ ^ (self identityIndexOf:anObject) ~~ 0 |
|
4949 |
"/ ]. |
|
1109
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4950 |
"/ |
2647 | 4951 |
"/ "/ |
4952 |
"/ "/ otherwise, do it the slow way |
|
4953 |
"/ "/ |
|
4954 |
"/ numInst := self basicSize. |
|
4955 |
"/ 1 to:numInst do:[:i | |
|
4956 |
"/ ((self basicAt:i) == anObject) ifTrue:[^ true] |
|
4957 |
"/ ] |
|
1109
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4958 |
"/ ]. |
38956a3cd61e
speeded up #references: (needed for allOwners etc.)
Claus Gittinger <cg@exept.de>
parents:
1101
diff
changeset
|
4959 |
|
783 | 4960 |
^ false |
4961 |
||
4962 |
" |
|
4963 |
|v| |
|
4964 |
||
4965 |
v := View new initialize. |
|
4966 |
v references:Display. |
|
4967 |
" |
|
4968 |
! |
|
4969 |
||
4970 |
referencesDerivedInstanceOf:aClass |
|
4971 |
"return true, if the receiver refers to an instance of |
|
4972 |
the argument, aClass or its subclass. This method exists |
|
4973 |
to support searching for users of a class." |
|
4974 |
||
4975 |
|myClass |
|
4976 |
numInst "{ Class: SmallInteger }" | |
|
4977 |
||
4978 |
myClass := self class. |
|
4979 |
||
4980 |
"check the class" |
|
4981 |
(myClass isKindOf:aClass) ifTrue:[^ true]. |
|
4982 |
||
4983 |
"check the instance variables" |
|
4984 |
numInst := myClass instSize. |
|
4985 |
1 to:numInst do:[:i | |
|
4986 |
((self instVarAt:i) isKindOf:aClass) ifTrue:[^ true] |
|
4987 |
]. |
|
4988 |
||
4989 |
"check the indexed variables" |
|
4990 |
myClass isVariable ifTrue:[ |
|
4991 |
myClass isPointers ifFalse:[ |
|
4992 |
"no need to search in non pointer fields" |
|
4993 |
((aClass == Number) or:[aClass isSubclassOf:Number]) ifFalse:[^ false]. |
|
4994 |
]. |
|
4995 |
numInst := self basicSize. |
|
4996 |
1 to:numInst do:[:i | |
|
4997 |
((self basicAt:i) isKindOf:aClass) ifTrue:[^ true] |
|
4998 |
] |
|
4999 |
]. |
|
5000 |
^ false |
|
5001 |
||
5002 |
" |
|
5003 |
(1 @ 3.4) referencesDerivedInstanceOf:Number |
|
5004 |
(1 @ 3.4) referencesDerivedInstanceOf:Array |
|
5005 |
View new initialize referencesDerivedInstanceOf:DeviceWorkstation |
|
5006 |
" |
|
5007 |
! |
|
5008 |
||
5009 |
referencesInstanceOf:aClass |
|
5010 |
"return true, if the receiver refers to an instance of |
|
5011 |
the argument, aClass.This method exists |
|
5012 |
to support searching for users of a class." |
|
5013 |
||
5014 |
|myClass |
|
5015 |
numInst "{ Class: SmallInteger }" | |
|
5016 |
||
5017 |
myClass := self class. |
|
5018 |
||
5019 |
"check the class" |
|
5020 |
(myClass isMemberOf:aClass) ifTrue:[^ true]. |
|
5021 |
||
5022 |
"check the instance variables" |
|
5023 |
numInst := myClass instSize. |
|
5024 |
1 to:numInst do:[:i | |
|
5025 |
((self instVarAt:i) isMemberOf:aClass) ifTrue:[^ true] |
|
5026 |
]. |
|
5027 |
||
5028 |
"check the indexed variables" |
|
5029 |
myClass isVariable ifTrue:[ |
|
5030 |
myClass isPointers ifFalse:[ |
|
5031 |
"no need to search in non-pointer indexed fields" |
|
5032 |
myClass isLongs ifTrue:[ |
|
5033 |
(aClass == SmallInteger or:[aClass == LargeInteger]) ifFalse:[^ false]. |
|
5034 |
] ifFalse:[ |
|
5035 |
myClass isFloatsOrDoubles ifTrue:[^ aClass == Float]. |
|
5036 |
^ aClass == SmallInteger |
|
5037 |
] |
|
5038 |
]. |
|
5039 |
numInst := self basicSize. |
|
5040 |
1 to:numInst do:[:i | |
|
5041 |
((self basicAt:i) isMemberOf:aClass) ifTrue:[^ true] |
|
5042 |
] |
|
5043 |
]. |
|
5044 |
^ false |
|
5045 |
||
5046 |
" |
|
5047 |
(1 @ 3.4) referencesInstanceOf:Float |
|
5048 |
(1 @ 3.4) referencesInstanceOf:Fraction |
|
5049 |
View new initialize referencesInstanceOf:(Display class) |
|
5050 |
" |
|
1 | 5051 |
! ! |
783 | 5052 |
|
2295 | 5053 |
!Object methodsFor:'synchronized evaluation'! |
5054 |
||
5055 |
freeSynchronizationSemaphore |
|
5056 |
"free synchronizationSemaphore. May be used, to save memory when |
|
5057 |
an object is no longer used synchronized." |
|
5058 |
||
2342 | 5059 |
|sema| |
2295 | 5060 |
|
5061 |
sema := self synchronizationSemaphore. |
|
5062 |
sema notNil ifTrue:[ |
|
2647 | 5063 |
sema wait. "/ get lock |
5064 |
self synchronizationSemaphore:nil. |
|
2295 | 5065 |
]. |
5066 |
||
5067 |
" |
|
5068 |
self synchronized:[]. |
|
5069 |
self synchronizationSemaphore. |
|
5070 |
self freeSynchronizationSemaphore. |
|
5071 |
" |
|
5072 |
||
5073 |
"Created: 28.1.1997 / 19:31:20 / stefan" |
|
5074 |
"Modified: 28.1.1997 / 19:47:55 / stefan" |
|
5075 |
! |
|
5076 |
||
5077 |
synchronizationSemaphore |
|
5078 |
"return the synchronization semaphore for myself. |
|
5079 |
subclasses may redefine" |
|
5080 |
||
5081 |
^ SynchronizationSemaphores at:self ifAbsent:[]. |
|
5082 |
||
5083 |
" |
|
5084 |
self synchronizationSemaphore |
|
5085 |
" |
|
5086 |
||
5087 |
"Modified: 28.1.1997 / 19:47:09 / stefan" |
|
5088 |
! |
|
5089 |
||
5090 |
synchronizationSemaphore:aSemaphore |
|
5091 |
"set the synchronisationSemaphore for myself. |
|
5092 |
subclasses may redefine this method" |
|
5093 |
||
5094 |
aSemaphore isNil ifTrue:[ |
|
2647 | 5095 |
"/ remove Semaphore |
5096 |
SynchronizationSemaphores removeKey:self ifAbsent:[]. |
|
2295 | 5097 |
] ifFalse:[ |
2647 | 5098 |
SynchronizationSemaphores at:self put:aSemaphore. |
2295 | 5099 |
]. |
5100 |
||
5101 |
"Modified: 28.1.1997 / 19:37:48 / stefan" |
|
5102 |
! |
|
5103 |
||
5104 |
synchronized:aBlock |
|
5105 |
"evaluate aBlock synchronized, i.e. use a monitor for this object" |
|
5106 |
||
2412
f20a5b10e6ab
Further optim. for #synchronized.
Stefan Vogel <sv@exept.de>
parents:
2359
diff
changeset
|
5107 |
|sema blocked gotSema| |
2327 | 5108 |
|
5109 |
blocked := OperatingSystem blockInterrupts. |
|
5110 |
||
5111 |
"/ the following avoids creation of an additional |
|
5112 |
"/ block in the common case |
|
2295 | 5113 |
|
5114 |
sema := self synchronizationSemaphore. |
|
5115 |
sema isNil ifTrue:[ |
|
2647 | 5116 |
"get a locked semaphore (with count = 0)" |
5117 |
sema := Semaphore new. |
|
5118 |
self synchronizationSemaphore:sema. |
|
5119 |
blocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
5120 |
^ aBlock valueNowOrOnUnwindDo:[sema signal]. |
|
2327 | 5121 |
]. |
5122 |
||
2412
f20a5b10e6ab
Further optim. for #synchronized.
Stefan Vogel <sv@exept.de>
parents:
2359
diff
changeset
|
5123 |
" |
f20a5b10e6ab
Further optim. for #synchronized.
Stefan Vogel <sv@exept.de>
parents:
2359
diff
changeset
|
5124 |
Poll sema (never waits). |
f20a5b10e6ab
Further optim. for #synchronized.
Stefan Vogel <sv@exept.de>
parents:
2359
diff
changeset
|
5125 |
Assuming that this is the common operation, this saves the creation |
f20a5b10e6ab
Further optim. for #synchronized.
Stefan Vogel <sv@exept.de>
parents:
2359
diff
changeset
|
5126 |
of some blocks. |
f20a5b10e6ab
Further optim. for #synchronized.
Stefan Vogel <sv@exept.de>
parents:
2359
diff
changeset
|
5127 |
" |
f20a5b10e6ab
Further optim. for #synchronized.
Stefan Vogel <sv@exept.de>
parents:
2359
diff
changeset
|
5128 |
(sema waitWithTimeout:0) notNil ifTrue:[ |
2647 | 5129 |
blocked ifFalse:[OperatingSystem unblockInterrupts]. |
5130 |
^ aBlock valueNowOrOnUnwindDo:[sema signal]. |
|
2295 | 5131 |
]. |
2327 | 5132 |
|
5133 |
[ |
|
2647 | 5134 |
gotSema := sema wait. |
5135 |
blocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
5136 |
^ aBlock value. |
|
2327 | 5137 |
] valueNowOrOnUnwindDo:[ |
2647 | 5138 |
gotSema notNil ifTrue:[gotSema signal] |
2327 | 5139 |
]. |
2295 | 5140 |
|
5141 |
" |
|
5142 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'1']] fork. |
|
5143 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'2']] fork. |
|
5144 |
" |
|
5145 |
||
5146 |
"Created: 28.1.1997 / 17:52:56 / stefan" |
|
2327 | 5147 |
"Modified: 30.1.1997 / 13:38:54 / cg" |
2412
f20a5b10e6ab
Further optim. for #synchronized.
Stefan Vogel <sv@exept.de>
parents:
2359
diff
changeset
|
5148 |
"Modified: 20.2.1997 / 09:43:35 / stefan" |
2295 | 5149 |
! ! |
5150 |
||
783 | 5151 |
!Object methodsFor:'system primitives'! |
5152 |
||
1957 | 5153 |
asOop |
5154 |
"ST-80 compatibility: |
|
5155 |
ST-80 returns an OOP-identity based number here (I guess: its address |
|
5156 |
or index); since ST/X has no such thing, and the objects address cannot |
|
5157 |
be used (since its changing over time), we return the objects identityHash |
|
5158 |
key, which provides (at least) some identity indication. |
|
5159 |
However, notice that (in contrast to ST-80's #asOop), the identityHash |
|
5160 |
key of two non-identical objects may be the same. |
|
5161 |
You'd better not use it - especially do not misuse it." |
|
5162 |
||
5163 |
^ self identityHash |
|
5164 |
||
5165 |
"Created: 9.11.1996 / 19:09:56 / cg" |
|
5166 |
"Modified: 9.11.1996 / 19:16:04 / cg" |
|
5167 |
! |
|
5168 |
||
783 | 5169 |
become:anotherObject |
5170 |
"make all references to the receiver become references to anotherObject |
|
859 | 5171 |
and vice-versa. Notice the vice-versa; see #becomeSameAs: for a one-way become. |
5172 |
This can be a very dangerous operation - be warned. |
|
861 | 5173 |
In general, using #become: should be avoided if possible, since it may |
5174 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
|
5175 |
||
5176 |
This may also be an expensive (i.e. slow) operation, |
|
783 | 5177 |
since in the worst case, the whole memory has to be searched for |
5178 |
references to the two objects (although the primitive tries hard to |
|
5179 |
limit the search, for acceptable performance in most cases). |
|
5180 |
This method fails, if the receiver or the argument is a SmallInteger |
|
5181 |
or nil, or is a context of a living method (i.e. one that has not already |
|
5182 |
returned). |
|
859 | 5183 |
(notice that #become: is not used heavily by the system |
783 | 5184 |
- the Collection-classes have been rewritten to not use it.)" |
5185 |
%{ |
|
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1685
diff
changeset
|
5186 |
if (__primBecome(self, anotherObject)) { |
783 | 5187 |
RETURN ( self ); |
859 | 5188 |
} |
5189 |
%}. |
|
783 | 5190 |
self primitiveFailed |
5191 |
! |
|
5192 |
||
5193 |
becomeNil |
|
5194 |
"make all references to the receiver become nil - effectively getting |
|
859 | 5195 |
rid of the receiver. |
5196 |
This can be a very dangerous operation - be warned. |
|
5197 |
||
5198 |
This may be an expensive (i.e. slow) operation. |
|
783 | 5199 |
The receiver may not be a SmallInteger or a context of a living method." |
5200 |
||
5201 |
%{ |
|
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1685
diff
changeset
|
5202 |
if (__primBecomeNil(self)) { |
783 | 5203 |
RETURN ( nil ); |
859 | 5204 |
} |
5205 |
%}. |
|
5206 |
self primitiveFailed |
|
5207 |
! |
|
5208 |
||
5209 |
becomeSameAs:anotherObject |
|
5210 |
"make all references to the receiver become references to anotherObject |
|
861 | 5211 |
but NOT vice versa (as done in #become:). |
859 | 5212 |
This can be a very dangerous operation - be warned. |
861 | 5213 |
In general, using #become: should be avoided if possible, since it may |
5214 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
|
5215 |
||
5216 |
This may also be an expensive (i.e. slow) operation, |
|
859 | 5217 |
since in the worst case, the whole memory has to be searched for |
5218 |
references to the two objects (although the primitive tries hard to |
|
5219 |
limit the search, for acceptable performance in most cases). |
|
5220 |
This method fails, if the receiver or the argument is a SmallInteger |
|
5221 |
or nil, or is a context of a living method (i.e. one that has not already returned)." |
|
5222 |
%{ |
|
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1685
diff
changeset
|
5223 |
if (__primBecomeSameAs(self, anotherObject)) { |
859 | 5224 |
RETURN ( self ); |
5225 |
} |
|
5226 |
%}. |
|
783 | 5227 |
self primitiveFailed |
5228 |
! |
|
5229 |
||
5230 |
changeClassTo:otherClass |
|
5231 |
"changes the class of the receiver to the argument, otherClass. |
|
5232 |
This is only allowed (possible), if the receivers class and the argument |
|
5233 |
have the same structure (i.e. number of named instance variables and |
|
5234 |
type of indexed instance variables). |
|
5235 |
If the structures do not match, or any of the original class or new class |
|
5236 |
is UndefinedObject or a Smallinteger, a primitive error is triggered." |
|
5237 |
||
5238 |
|myClass ok| |
|
5239 |
||
5240 |
"check for UndefinedObject/SmallInteger receiver or newClass" |
|
5241 |
%{ |
|
1133 | 5242 |
{ |
2647 | 5243 |
OBJ other = otherClass; |
5244 |
||
5245 |
if (__isNonNilObject(self) |
|
5246 |
&& __isNonNilObject(other) |
|
5247 |
&& (other != UndefinedObject) |
|
5248 |
&& (other != SmallInteger)) { |
|
5249 |
ok = true; |
|
5250 |
} else { |
|
5251 |
ok = false; |
|
5252 |
} |
|
783 | 5253 |
} |
5254 |
%}. |
|
5255 |
ok ifTrue:[ |
|
2647 | 5256 |
ok := false. |
5257 |
myClass := self class. |
|
5258 |
myClass flags == otherClass flags ifTrue:[ |
|
5259 |
myClass instSize == otherClass instSize ifTrue:[ |
|
5260 |
"same instance layout and types: its ok to do it" |
|
5261 |
ok := true. |
|
5262 |
] ifFalse:[ |
|
5263 |
myClass isPointers ifTrue:[ |
|
5264 |
myClass isVariable ifTrue:[ |
|
5265 |
ok := true |
|
5266 |
] |
|
5267 |
] |
|
5268 |
] |
|
5269 |
] ifFalse:[ |
|
5270 |
myClass isPointers ifTrue:[ |
|
5271 |
"if newClass is a variable class, with instSize <= my instsize, |
|
5272 |
we can do it (effectively mapping additional instvars into the |
|
5273 |
variable part) - usefulness is questionable, though" |
|
5274 |
||
5275 |
otherClass isPointers ifTrue:[ |
|
5276 |
otherClass isVariable ifTrue:[ |
|
5277 |
otherClass instSize <= (myClass instSize + self basicSize) |
|
5278 |
ifTrue:[ |
|
5279 |
ok := true |
|
5280 |
] |
|
5281 |
] ifFalse:[ |
|
5282 |
otherClass instSize == (myClass instSize + self basicSize) |
|
5283 |
ifTrue:[ |
|
5284 |
ok := true |
|
5285 |
] |
|
5286 |
] |
|
5287 |
] ifFalse:[ |
|
5288 |
"it does not make sense to convert pointers to bytes ..." |
|
5289 |
] |
|
5290 |
] ifFalse:[ |
|
5291 |
"does it make sense, to convert bits ?" |
|
5292 |
"could allow byteArray->wordArray->longArray->floatArray->doubleArray here ..." |
|
5293 |
(myClass isBits and:[otherClass isBits]) ifTrue:[ |
|
5294 |
ok := true |
|
5295 |
] |
|
5296 |
] |
|
5297 |
] |
|
783 | 5298 |
]. |
5299 |
ok ifTrue:[ |
|
2647 | 5300 |
"now, change the receivers class ..." |
783 | 5301 |
%{ |
1133 | 5302 |
{ |
5303 |
OBJ me = self; |
|
5304 |
||
2647 | 5305 |
__qClass(me) = otherClass; |
5306 |
__STORE(me, otherClass); |
|
5307 |
RETURN (me); |
|
1133 | 5308 |
} |
783 | 5309 |
%}. |
5310 |
]. |
|
1022
f526a827ea1a
allow changeClass of bitObjects
Claus Gittinger <cg@exept.de>
parents:
1021
diff
changeset
|
5311 |
|
f526a827ea1a
allow changeClass of bitObjects
Claus Gittinger <cg@exept.de>
parents:
1021
diff
changeset
|
5312 |
" |
f526a827ea1a
allow changeClass of bitObjects
Claus Gittinger <cg@exept.de>
parents:
1021
diff
changeset
|
5313 |
the receiver cannot be represented as a instance of |
f526a827ea1a
allow changeClass of bitObjects
Claus Gittinger <cg@exept.de>
parents:
1021
diff
changeset
|
5314 |
the desired class. |
f526a827ea1a
allow changeClass of bitObjects
Claus Gittinger <cg@exept.de>
parents:
1021
diff
changeset
|
5315 |
For example, you cannot change a bitInstance (byteArray etc.) |
f526a827ea1a
allow changeClass of bitObjects
Claus Gittinger <cg@exept.de>
parents:
1021
diff
changeset
|
5316 |
into a pointer object and vice versa. |
f526a827ea1a
allow changeClass of bitObjects
Claus Gittinger <cg@exept.de>
parents:
1021
diff
changeset
|
5317 |
" |
783 | 5318 |
self primitiveFailed |
5319 |
! |
|
5320 |
||
5321 |
changeClassToThatOf:anObject |
|
5322 |
"changes the class of the receiver to that of the argument, anObject. |
|
5323 |
This is only allowed (possible), if the receivers class and the arguments |
|
5324 |
class have the same structure (i.e. number of named instance variables and |
|
5325 |
type of indexed instance variables). If the structures do not match, or any |
|
5326 |
of the objects is nil or a Smallinteger, a primitive error is triggered." |
|
5327 |
||
5328 |
self changeClassTo:(anObject class) |
|
5329 |
! ! |
|
5330 |
||
1867 | 5331 |
!Object methodsFor:'testing'! |
5332 |
||
5333 |
? defaultValue |
|
5334 |
"if the receiver is nil, return the defaultValue; |
|
5335 |
otherwise, return the receiver. |
|
5336 |
This method is only redefined in UndefinedObject - therefore, |
|
5337 |
the recevier is retuned here. |
|
5338 |
||
1958 | 5339 |
Thus, if foo and bar are simple variables or constants, |
2647 | 5340 |
foo ? bar |
1958 | 5341 |
is the same as: |
2647 | 5342 |
(foo isNil ifTrue:[bar] ifFalse:[foo]) |
1958 | 5343 |
|
5344 |
if they are message sends, the equivalent code is: |
|
2647 | 5345 |
[ |
5346 |
|t1 t2| |
|
5347 |
||
5348 |
t1 := foo. |
|
5349 |
t2 := bar. |
|
5350 |
t1 isNil ifTrue:[t2] ifFalse:[t1] |
|
5351 |
] value |
|
1958 | 5352 |
|
1867 | 5353 |
Can be used to provide defaultValues to variables, |
5354 |
as in: |
|
2647 | 5355 |
foo := arg ? #defaultValue |
2147 | 5356 |
|
2148 | 5357 |
Note: this method should never be redefined in classes other than UndefinedObject. |
1867 | 5358 |
" |
5359 |
||
5360 |
^ self |
|
5361 |
||
5362 |
" |
|
5363 |
1 ? #default |
|
5364 |
nil ? #default |
|
5365 |
" |
|
5366 |
||
5367 |
"Created: 4.11.1996 / 20:36:19 / cg" |
|
2148 | 5368 |
"Modified: 11.1.1997 / 14:56:47 / cg" |
1867 | 5369 |
! |
5370 |
||
5371 |
isArray |
|
5372 |
"return true, if the receiver is some kind of array (or weakArray etc); |
|
5373 |
false is returned here - the method is only redefined in Array." |
|
5374 |
||
5375 |
^ false |
|
5376 |
! |
|
5377 |
||
5378 |
isAssociation |
|
5379 |
"return true, if the receiver is some kind of association; |
|
5380 |
false is returned here - the method is only redefined in Association." |
|
5381 |
||
5382 |
^ false |
|
5383 |
||
5384 |
"Created: 14.5.1996 / 17:03:45 / cg" |
|
5385 |
! |
|
5386 |
||
5387 |
isBehavior |
|
5388 |
"return true, if the receiver is some kind of class (i.e. behavior); |
|
5389 |
false is returned here - the method is only redefined in Behavior." |
|
5390 |
||
5391 |
^ false |
|
5392 |
! |
|
5393 |
||
5394 |
isBlock |
|
5395 |
"return true, if the receiver is some kind of block; |
|
5396 |
false returned here - the method is only redefined in Block." |
|
5397 |
||
5398 |
^ false |
|
5399 |
! |
|
5400 |
||
5401 |
isCharacter |
|
5402 |
"return true, if the receiver is some kind of character; |
|
5403 |
false is returned here - the method is only redefined in Character." |
|
5404 |
||
5405 |
^ false |
|
5406 |
! |
|
5407 |
||
5408 |
isClass |
|
5409 |
"return true, if the receiver is some kind of class (real class, |
|
5410 |
not just behavior); |
|
5411 |
false is returned here - the method is only redefined in Class." |
|
5412 |
||
5413 |
^ false |
|
5414 |
! |
|
5415 |
||
5416 |
isCollection |
|
5417 |
"return true, if the receiver is some kind of collection; |
|
5418 |
false is returned here - the method is only redefined in Collection." |
|
5419 |
||
5420 |
^ false |
|
5421 |
! |
|
5422 |
||
5423 |
isColor |
|
5424 |
"return true, if the receiver is some kind of color; |
|
5425 |
false is returned here - the method is only redefined in Color." |
|
5426 |
||
5427 |
^ false |
|
5428 |
! |
|
5429 |
||
5430 |
isContext |
|
5431 |
"return true, if the receiver is some kind of context; |
|
5432 |
false returned here - the method is only redefined in Context." |
|
5433 |
||
5434 |
^ false |
|
5435 |
! |
|
5436 |
||
5437 |
isExternalStream |
|
5438 |
"return true, if the receiver is some kind of externalStream; |
|
5439 |
false is returned here - the method is only redefined in ExternalStream." |
|
5440 |
||
5441 |
^false |
|
5442 |
! |
|
5443 |
||
5444 |
isFileStream |
|
5445 |
"return true, if the receiver is some kind of fileStream; |
|
5446 |
false is returned here - the method is only redefined in FileStream." |
|
5447 |
||
5448 |
^false |
|
5449 |
! |
|
5450 |
||
1887 | 5451 |
isFixedPoint |
5452 |
"return true, if the receiver is some kind of fixedPoint number; |
|
5453 |
false is returned here - the method is only redefined in FixedPoint." |
|
5454 |
||
5455 |
^ false |
|
5456 |
||
5457 |
"Created: 5.11.1996 / 19:23:04 / cg" |
|
5458 |
! |
|
5459 |
||
1867 | 5460 |
isFixedSize |
5461 |
"return true if the receiver cannot grow easily |
|
5462 |
(i.e. a grow may be expensive, since it involves a become:)" |
|
5463 |
||
5464 |
^ true |
|
5465 |
! |
|
5466 |
||
5467 |
isForm |
|
5468 |
"return true, if the receiver is some kind of form; |
|
5469 |
false is returned here - the method is only redefined in Form." |
|
5470 |
||
5471 |
^ false |
|
5472 |
! |
|
5473 |
||
5474 |
isFraction |
|
5475 |
"return true, if the receiver is some kind of fraction; |
|
5476 |
false is returned here - the method is only redefined in Fraction." |
|
5477 |
||
5478 |
^ false |
|
5479 |
! |
|
5480 |
||
5481 |
isImage |
|
5482 |
"return true, if the receiver is some kind of image; |
|
5483 |
false is returned here - the method is only redefined in Image." |
|
5484 |
||
5485 |
^ false |
|
5486 |
! |
|
5487 |
||
5488 |
isImageOrForm |
|
5489 |
"return true, if the receiver is some kind of image or form; |
|
5490 |
false is returned here - the method is only redefined in Image and Form." |
|
5491 |
||
5492 |
^ false |
|
5493 |
! |
|
5494 |
||
2673
f514189f6096
added #isImmediate for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2655
diff
changeset
|
5495 |
isImmediate |
f514189f6096
added #isImmediate for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2655
diff
changeset
|
5496 |
"return true if this object has immediate representation" |
f514189f6096
added #isImmediate for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2655
diff
changeset
|
5497 |
|
f514189f6096
added #isImmediate for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2655
diff
changeset
|
5498 |
^ self class hasImmediateInstances |
f514189f6096
added #isImmediate for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2655
diff
changeset
|
5499 |
|
f514189f6096
added #isImmediate for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2655
diff
changeset
|
5500 |
"Created: 3.6.1997 / 12:00:18 / cg" |
f514189f6096
added #isImmediate for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2655
diff
changeset
|
5501 |
! |
f514189f6096
added #isImmediate for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
2655
diff
changeset
|
5502 |
|
1867 | 5503 |
isInteger |
5504 |
"return true, if the receiver is some kind of integer number; |
|
5505 |
false is returned here - the method is only redefined in Integer." |
|
5506 |
||
5507 |
^ false |
|
5508 |
! |
|
5509 |
||
2502
8f3bf6043968
added #isJavaObject & #isJavaClass
Claus Gittinger <cg@exept.de>
parents:
2480
diff
changeset
|
5510 |
isJavaClass |
8f3bf6043968
added #isJavaObject & #isJavaClass
Claus Gittinger <cg@exept.de>
parents:
2480
diff
changeset
|
5511 |
^ false |
8f3bf6043968
added #isJavaObject & #isJavaClass
Claus Gittinger <cg@exept.de>
parents:
2480
diff
changeset
|
5512 |
|
8f3bf6043968
added #isJavaObject & #isJavaClass
Claus Gittinger <cg@exept.de>
parents:
2480
diff
changeset
|
5513 |
"Created: 26.3.1997 / 13:34:54 / cg" |
8f3bf6043968
added #isJavaObject & #isJavaClass
Claus Gittinger <cg@exept.de>
parents:
2480
diff
changeset
|
5514 |
! |
8f3bf6043968
added #isJavaObject & #isJavaClass
Claus Gittinger <cg@exept.de>
parents:
2480
diff
changeset
|
5515 |
|
8f3bf6043968
added #isJavaObject & #isJavaClass
Claus Gittinger <cg@exept.de>
parents:
2480
diff
changeset
|
5516 |
isJavaObject |
8f3bf6043968
added #isJavaObject & #isJavaClass
Claus Gittinger <cg@exept.de>
parents:
2480
diff
changeset
|
5517 |
^ false |
8f3bf6043968
added #isJavaObject & #isJavaClass
Claus Gittinger <cg@exept.de>
parents:
2480
diff
changeset
|
5518 |
|
8f3bf6043968
added #isJavaObject & #isJavaClass
Claus Gittinger <cg@exept.de>
parents:
2480
diff
changeset
|
5519 |
"Created: 26.3.1997 / 13:34:48 / cg" |
8f3bf6043968
added #isJavaObject & #isJavaClass
Claus Gittinger <cg@exept.de>
parents:
2480
diff
changeset
|
5520 |
! |
8f3bf6043968
added #isJavaObject & #isJavaClass
Claus Gittinger <cg@exept.de>
parents:
2480
diff
changeset
|
5521 |
|
1867 | 5522 |
isKindOf:aClass |
5523 |
"return true, if the receiver is an instance of aClass or one of its |
|
5524 |
subclasses, false otherwise. |
|
5525 |
Advice: |
|
5526 |
use of this to check objects for certain attributes/protocoll should |
|
5527 |
be avoided; it limits the reusability of your classes by limiting use |
|
5528 |
to instances of certain classes and fences you into a specific inheritance |
|
5529 |
hierarchy. |
|
5530 |
Use check-methods to check an object for a certain attributes/protocol |
|
5531 |
(such as #isXXXX, #respondsTo: or #isNumber). |
|
5532 |
||
5533 |
Using #isKindOf: is considered BAD STYLE. |
|
5534 |
||
5535 |
Advice2: |
|
5536 |
Be aware, that using an #isXXX method is usually much faster than |
|
5537 |
using #isKindOf:; because isKindOf: has to walk up all the superclass |
|
5538 |
hierarchy, comparing every class on the way. |
|
5539 |
Due to caching in the VM, a call to #isXXX is normally reached via |
|
5540 |
a single function call. |
|
5541 |
" |
|
5542 |
||
5543 |
%{ /* NOCONTEXT */ |
|
5544 |
register OBJ thisClass; |
|
5545 |
||
5546 |
thisClass = __Class(self); |
|
5547 |
while (thisClass != nil) { |
|
5548 |
if (thisClass == aClass) { |
|
5549 |
RETURN ( true ); |
|
5550 |
} |
|
5551 |
thisClass = __ClassInstPtr(thisClass)->c_superclass; |
|
5552 |
} |
|
5553 |
%} |
|
5554 |
. |
|
5555 |
"/ |
|
5556 |
"/ the above code is equivalent to: |
|
5557 |
"/ |
|
5558 |
"/ thisClass := self class. |
|
5559 |
"/ [thisClass notNil] whileTrue:[ |
|
5560 |
"/ thisClass == aClass ifTrue:[^ true]. |
|
5561 |
"/ thisClass := thisClass superclass |
|
5562 |
"/ ] |
|
5563 |
"/ |
|
5564 |
^ false |
|
5565 |
! |
|
5566 |
||
5567 |
isLayout |
|
5568 |
"return true, if the receiver is some kind of layout; |
|
5569 |
false is returned here - the method is only redefined in Layout." |
|
5570 |
||
5571 |
^ false |
|
5572 |
! |
|
5573 |
||
5574 |
isLiteral |
|
5575 |
"return true, if the receiver can be represented as a constant in ST syntax; |
|
5576 |
false is returned here - the method is redefined in some classes." |
|
5577 |
||
5578 |
^ false |
|
5579 |
! |
|
5580 |
||
5581 |
isMemberOf:aClass |
|
5582 |
"return true, if the receiver is an instance of aClass, false otherwise. |
|
5583 |
Advice: |
|
5584 |
use of this to check objects for certain attributes/protocoll should |
|
5585 |
be avoided; it limits the reusability of your classes by limiting use |
|
5586 |
to instances of a certain class. |
|
5587 |
Use check-methods to check an object for a certain attributes/protocol |
|
5588 |
(such as #isXXX, #respondsTo: or #isNumber); |
|
5589 |
||
5590 |
Using #isMemberOf: is considered BAD STYLE." |
|
5591 |
||
5592 |
^ (self class) == aClass |
|
5593 |
! |
|
5594 |
||
5595 |
isMeta |
|
5596 |
"return true, if the receiver is some kind of metaclass; |
|
5597 |
false is returned here - the method is only redefined in Metaclass." |
|
5598 |
||
5599 |
^ false |
|
5600 |
! |
|
5601 |
||
5602 |
isMethod |
|
5603 |
"return true, if the receiver is some kind of method; |
|
5604 |
false returned here - the method is only redefined in Method." |
|
5605 |
||
5606 |
^ false |
|
5607 |
! |
|
5608 |
||
5609 |
isNamespace |
|
5610 |
^ false |
|
5611 |
||
5612 |
"Created: 11.10.1996 / 18:08:56 / cg" |
|
5613 |
! |
|
5614 |
||
5615 |
isNumber |
|
5616 |
"return true, if the receiver is some kind of number; |
|
5617 |
false is returned here - the method is only redefined in Number." |
|
5618 |
||
5619 |
^ false |
|
5620 |
! |
|
5621 |
||
5622 |
isPoint |
|
5623 |
"return true, if the receiver is some kind of point; |
|
5624 |
false is returned here - the method is only redefined in Point." |
|
5625 |
||
5626 |
^ false |
|
5627 |
! |
|
5628 |
||
5629 |
isReal |
|
5630 |
"return true, if the receiver is some kind of real number; |
|
5631 |
false is returned here - the method is only redefined in LimitedPrecisionReal." |
|
5632 |
||
5633 |
^ false |
|
5634 |
! |
|
5635 |
||
5636 |
isRectangle |
|
5637 |
"return true, if the receiver is some kind of rectangle; |
|
5638 |
false is returned here - the method is only redefined in Rectangle." |
|
5639 |
||
5640 |
^ false |
|
5641 |
! |
|
5642 |
||
5643 |
isRemoteObject |
|
5644 |
"return true, if the receiver is some kind of remoteObject, |
|
5645 |
false if its local - the method is only redefined in RemoteObject." |
|
5646 |
||
5647 |
^ false |
|
5648 |
||
5649 |
"Created: 28.10.1996 / 15:18:45 / cg" |
|
5650 |
"Modified: 28.10.1996 / 15:20:57 / cg" |
|
5651 |
! |
|
5652 |
||
5653 |
isSequenceable |
|
5654 |
"return true, if the receiver is some kind of sequenceable collection; |
|
5655 |
false is returned here - the method is only redefined in SequenceableCollection." |
|
5656 |
||
5657 |
^ false |
|
5658 |
! |
|
5659 |
||
5660 |
isSequenceableCollection |
|
5661 |
"OBSOLETE: use isSequenceable for ST-80 compatibility. |
|
5662 |
This method is a historic leftover and will be removed soon ..." |
|
5663 |
||
5664 |
self obsoleteMethodWarning:'use #isSequenceable'. |
|
5665 |
^ false |
|
5666 |
! |
|
5667 |
||
5668 |
isSignal |
|
5669 |
"return true, if the receiver is some kind of signal; |
|
5670 |
false returned here - the method is only redefined in Signal." |
|
5671 |
||
5672 |
^ false |
|
5673 |
! |
|
5674 |
||
5675 |
isStream |
|
5676 |
"return true, if the receiver is some kind of stream; |
|
5677 |
false is returned here - the method is only redefined in Stream." |
|
5678 |
||
5679 |
^ false |
|
5680 |
! |
|
5681 |
||
5682 |
isString |
|
5683 |
"return true, if the receiver is some kind of string; |
|
5684 |
false is returned here - the method is only redefined in String." |
|
5685 |
||
5686 |
^ false |
|
5687 |
! |
|
5688 |
||
5689 |
isSymbol |
|
5690 |
"return true, if the receiver is some kind of symbol; |
|
5691 |
false is returned here - the method is only redefined in Symbol." |
|
5692 |
||
5693 |
^ false |
|
5694 |
! |
|
5695 |
||
5696 |
isText |
|
5697 |
"return true, if the receiver is some kind of text object; |
|
5698 |
false is returned here - the method is only redefined in Text." |
|
5699 |
||
5700 |
^ false |
|
5701 |
||
5702 |
"Created: 12.5.1996 / 10:56:50 / cg" |
|
5703 |
! |
|
5704 |
||
5705 |
isVariable |
|
5706 |
"return true if the receiver has indexed instance variables, |
|
5707 |
false otherwise." |
|
5708 |
||
5709 |
^ self class isVariable |
|
5710 |
! |
|
5711 |
||
5712 |
isView |
|
5713 |
"return true, if the receiver is some kind of view; |
|
5714 |
false is returned here - the method is only redefined in View." |
|
5715 |
||
5716 |
^ false |
|
5717 |
! ! |
|
5718 |
||
783 | 5719 |
!Object methodsFor:'user interaction & notifications'! |
5720 |
||
5721 |
activityNotification:aString |
|
5722 |
"this can be sent from deeply nested methods, which are going to perform |
|
5723 |
some long-time activity. |
|
5724 |
If there is a handler for the ActivityNotificationSignal signal, that one is raised, |
|
5725 |
passing the argument. The handler should show this message whereever it likes, |
|
5726 |
and proceed. If there is no handler, this is simply ignored. |
|
5727 |
||
5728 |
This is very useful to pass busy messages up to some higher level (typically a view) |
|
5729 |
which likes to display that message in its label or a busy-box. |
|
5730 |
It could also be put into some logfile or printed on the standard output/error." |
|
5731 |
||
5732 |
ActivityNotificationSignal isHandled ifTrue:[ |
|
861 | 5733 |
^ ActivityNotificationSignal raiseRequestWith:self errorString:aString |
783 | 5734 |
]. |
5735 |
||
5736 |
" |
|
5737 |
nil activityNotification:'hello there' |
|
5738 |
self activityNotification:'hello there' |
|
5739 |
" |
|
5740 |
||
5741 |
" |
|
5742 |
ActivityNotificationSignal handle:[:ex | |
|
861 | 5743 |
ex errorString printNL. |
5744 |
ex proceed. |
|
783 | 5745 |
] do:[ |
861 | 5746 |
'hello' printNL. |
5747 |
self activityNotification:'doing some long time computation'. |
|
5748 |
'world' printNL. |
|
783 | 5749 |
] |
5750 |
" |
|
5751 |
||
5752 |
"Modified: 16.12.1995 / 18:23:42 / cg" |
|
5753 |
! |
|
5754 |
||
5755 |
confirm:aString |
|
5756 |
"launch a confirmer, which allows user to enter yes or no. |
|
5757 |
return true for yes, false for no" |
|
5758 |
||
925
020a15fa450f
use less memory for single-dependencies;
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
5759 |
" |
020a15fa450f
use less memory for single-dependencies;
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
5760 |
on systems without GUI, or during startup, output a message |
020a15fa450f
use less memory for single-dependencies;
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
5761 |
and return true (as if yes was answered) |
020a15fa450f
use less memory for single-dependencies;
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
5762 |
Q: should we ask user by reading Stdin ? |
020a15fa450f
use less memory for single-dependencies;
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
5763 |
" |
020a15fa450f
use less memory for single-dependencies;
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
5764 |
Smalltalk isInitialized ifFalse:[ |
2647 | 5765 |
'*** confirmation requested during initialization:' printCR. |
5766 |
aString printCR. |
|
5767 |
'*** I''ll continue, assuming <yes> ...' printCR. |
|
5768 |
^ true |
|
925
020a15fa450f
use less memory for single-dependencies;
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
5769 |
]. |
020a15fa450f
use less memory for single-dependencies;
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
5770 |
|
783 | 5771 |
Dialog isNil ifTrue:[ |
2647 | 5772 |
Transcript showCR:aString. |
5773 |
Transcript showCR:'continue, assuming <yes>'. |
|
5774 |
^ true |
|
783 | 5775 |
]. |
5776 |
Dialog autoload. "in case its autoloaded" |
|
5777 |
^ Dialog confirm:aString |
|
5778 |
||
5779 |
" |
|
5780 |
nil confirm:'hello' |
|
5781 |
self confirm:'hello' |
|
5782 |
" |
|
1417 | 5783 |
|
1425 | 5784 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
783 | 5785 |
! |
5786 |
||
5787 |
errorNotify:aString |
|
5788 |
"launch a Notifier, showing top stack, telling user something |
|
2150 | 5789 |
and give user a chance to enter debugger." |
5790 |
||
5791 |
^ self |
|
2647 | 5792 |
errorNotify:aString |
5793 |
from:thisContext sender |
|
2150 | 5794 |
|
5795 |
" |
|
5796 |
nil errorNotify:'hello there' |
|
5797 |
self errorNotify:'hello there' |
|
5798 |
" |
|
5799 |
||
5800 |
"Modified: 11.1.1997 / 18:39:20 / cg" |
|
5801 |
! |
|
5802 |
||
5803 |
errorNotify:aString from:aContext |
|
5804 |
"launch a Notifier, showing top stack (above aContext), |
|
5805 |
telling user something and give user a chance to enter debugger." |
|
783 | 5806 |
|
2082 | 5807 |
|info con sender action| |
783 | 5808 |
|
891 | 5809 |
Smalltalk isInitialized ifFalse:[ |
2647 | 5810 |
'errorNotification: ' print. aString printCR. |
5811 |
^ self |
|
891 | 5812 |
]. |
5813 |
||
783 | 5814 |
Dialog isNil ifTrue:[ |
2647 | 5815 |
" |
5816 |
on systems without GUI, simply show |
|
5817 |
the message on the Transcript and abort. |
|
5818 |
" |
|
5819 |
Transcript showCR:aString. |
|
5820 |
AbortSignal raise. |
|
5821 |
^ self |
|
783 | 5822 |
]. |
2203
5899dbf1b69c
go directly into the debugger if an error occurs
Claus Gittinger <cg@exept.de>
parents:
2194
diff
changeset
|
5823 |
|
5899dbf1b69c
go directly into the debugger if an error occurs
Claus Gittinger <cg@exept.de>
parents:
2194
diff
changeset
|
5824 |
Processor activeProcessIsSystemProcess ifTrue:[ |
2647 | 5825 |
action := #debug. |
5826 |
sender := aContext. |
|
2203
5899dbf1b69c
go directly into the debugger if an error occurs
Claus Gittinger <cg@exept.de>
parents:
2194
diff
changeset
|
5827 |
] ifFalse:[ |
2647 | 5828 |
Dialog autoload. "in case its autoloaded" |
5829 |
||
5830 |
ErrorSignal handle:[:ex | |
|
5831 |
||
5832 |
"/ a recursive error - quickly enter debugger |
|
5833 |
"/ this happened, when I corrupted the Dialog class ... |
|
5834 |
||
2689 | 5835 |
('Object [error]: ' , ex errorString , ' caught in errorNotification') errorPrintCR. |
2647 | 5836 |
action := #debug. |
5837 |
ex return. |
|
5838 |
] do:[ |
|
5839 |
sender := aContext. |
|
5840 |
sender isNil ifTrue:[ |
|
5841 |
sender := thisContext sender. |
|
5842 |
"/ |
|
5843 |
"/ for your convenience: skip the emergencyHandler block |
|
2203
5899dbf1b69c
go directly into the debugger if an error occurs
Claus Gittinger <cg@exept.de>
parents:
2194
diff
changeset
|
5844 |
"/ sender isBlockContext ifTrue:[ |
5899dbf1b69c
go directly into the debugger if an error occurs
Claus Gittinger <cg@exept.de>
parents:
2194
diff
changeset
|
5845 |
"/ sender := sender sender |
5899dbf1b69c
go directly into the debugger if an error occurs
Claus Gittinger <cg@exept.de>
parents:
2194
diff
changeset
|
5846 |
"/ ]. |
2647 | 5847 |
]. |
5848 |
||
5849 |
"/ skip intermediate (signal & exception) contexts |
|
5850 |
||
5851 |
DebugView notNil ifTrue:[ |
|
5852 |
sender := DebugView interestingContextFrom:sender |
|
5853 |
]. |
|
5854 |
||
5855 |
"/ show the first 5 contexts |
|
5856 |
||
5857 |
con := sender. |
|
5858 |
info := aString , Character cr asString , Character cr asString. |
|
5859 |
1 to:5 do:[:n | |
|
5860 |
con notNil ifTrue:[ |
|
5861 |
info := info , con printString , Character cr asString. |
|
5862 |
con := con sender |
|
5863 |
] |
|
5864 |
]. |
|
5865 |
||
5866 |
action := Dialog |
|
5867 |
choose:info |
|
5868 |
label:('Exception [' , Processor activeProcess nameOrId , ']') |
|
5869 |
labels:#('proceed' 'abort' 'debug') |
|
5870 |
values:#(#proceed #abort #debug) |
|
5871 |
default:#debug. |
|
5872 |
]. |
|
2082 | 5873 |
]. |
5874 |
||
5875 |
action == #debug ifTrue:[ |
|
2647 | 5876 |
Debugger enter:sender withMessage:aString |
2082 | 5877 |
] ifFalse:[ |
2647 | 5878 |
action == #abort ifTrue:[ |
5879 |
AbortSignal raise |
|
5880 |
] |
|
783 | 5881 |
] |
5882 |
||
5883 |
" |
|
5884 |
nil errorNotify:'hello there' |
|
5885 |
self errorNotify:'hello there' |
|
5886 |
" |
|
1417 | 5887 |
|
2150 | 5888 |
"Created: 11.1.1997 / 17:53:09 / cg" |
2359
fdc5d828bb5e
add process name to exception notifyer boxes window-title
Claus Gittinger <cg@exept.de>
parents:
2342
diff
changeset
|
5889 |
"Modified: 8.2.1997 / 12:47:41 / cg" |
783 | 5890 |
! |
5891 |
||
5892 |
information:aString |
|
5893 |
"launch an InfoBox, telling user something. |
|
5894 |
These info-boxes can be suppressed by handling the |
|
5895 |
UserNotification- or InformationSignal and proceeding in the handler." |
|
5896 |
||
5897 |
InformationSignal isHandled ifTrue:[ |
|
5898 |
^ InformationSignal raiseRequestWith:self errorString:aString |
|
5899 |
]. |
|
5900 |
self notify:aString |
|
5901 |
||
5902 |
" |
|
5903 |
nil information:'hello there' |
|
5904 |
self information:'hello there' |
|
5905 |
" |
|
5906 |
||
5907 |
" |
|
5908 |
InformationSignal handle:[:ex | |
|
5909 |
'no box popped' printNL. |
|
5910 |
ex proceed. |
|
5911 |
] do:[ |
|
5912 |
'hello' printNL. |
|
5913 |
self information:'some info'. |
|
5914 |
'world' printNL. |
|
5915 |
] |
|
5916 |
" |
|
5917 |
||
5918 |
"Modified: 24.11.1995 / 22:29:49 / cg" |
|
5919 |
! |
|
5920 |
||
5921 |
notify:aString |
|
5922 |
"launch a Notifier, telling user something. |
|
5923 |
Use #information: for ignorable messages." |
|
5924 |
||
891 | 5925 |
Smalltalk isInitialized ifFalse:[ |
2647 | 5926 |
'information: ' print. aString printCR. |
5927 |
^ self |
|
891 | 5928 |
]. |
5929 |
||
783 | 5930 |
Dialog isNil ifTrue:[ |
2647 | 5931 |
" |
5932 |
on systems without GUI, simply show |
|
5933 |
the message on the Transcript. |
|
5934 |
" |
|
5935 |
Transcript showCR:aString. |
|
5936 |
^ self |
|
783 | 5937 |
]. |
5938 |
Dialog autoload. "in case its autoloaded" |
|
5939 |
Dialog information:aString |
|
5940 |
||
5941 |
" |
|
5942 |
nil notify:'hello there' |
|
5943 |
self notify:'hello there' |
|
5944 |
" |
|
1417 | 5945 |
|
1425 | 5946 |
"Modified: 20.5.1996 / 10:28:48 / cg" |
783 | 5947 |
! |
5948 |
||
5949 |
warn:aString |
|
5950 |
"launch a WarningBox, telling user something. |
|
5951 |
These warn-boxes can be suppressed by handling the |
|
5952 |
UserNotification- or WarningSignal and proceeding in the handler." |
|
5953 |
||
5954 |
WarningSignal isHandled ifTrue:[ |
|
2647 | 5955 |
^ WarningSignal raiseRequestWith:self errorString:aString |
783 | 5956 |
]. |
5957 |
||
891 | 5958 |
Smalltalk isInitialized ifFalse:[ |
2647 | 5959 |
'warning: ' print. aString printCR. |
5960 |
^ self |
|
891 | 5961 |
]. |
5962 |
||
783 | 5963 |
Dialog isNil ifTrue:[ |
2647 | 5964 |
" |
5965 |
on systems without GUI, simply show |
|
5966 |
the message on the Transcript. |
|
5967 |
" |
|
5968 |
Transcript showCR:aString. |
|
5969 |
^ self |
|
783 | 5970 |
]. |
5971 |
Dialog autoload. "in case its autoloaded" |
|
5972 |
Dialog warn:aString |
|
5973 |
||
5974 |
" |
|
5975 |
nil warn:'hello there' |
|
5976 |
self warn:'hello there' |
|
5977 |
" |
|
5978 |
||
5979 |
" |
|
5980 |
WarningSignal handle:[:ex | |
|
2647 | 5981 |
ex proceed. |
783 | 5982 |
] do:[ |
2647 | 5983 |
'hello' printNL. |
5984 |
self warn:'some info'. |
|
5985 |
'world' printNL. |
|
783 | 5986 |
] |
5987 |
" |
|
1417 | 5988 |
|
1425 | 5989 |
"Modified: 20.5.1996 / 10:28:53 / cg" |
783 | 5990 |
! ! |
5991 |
||
1788 | 5992 |
!Object class methodsFor:'documentation'! |
783 | 5993 |
|
5994 |
version |
|
2689 | 5995 |
^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.196 1997-06-16 18:20:55 cg Exp $' |
783 | 5996 |
! ! |
5997 |
Object initialize! |