author | Claus Gittinger <cg@exept.de> |
Fri, 07 Sep 2001 12:05:54 +0200 | |
changeset 5971 | 686ef746dacc |
parent 5926 | e5ce56a2bd40 |
child 5977 | 1aa80a42ed64 |
permissions | -rw-r--r-- |
5755 | 1 |
" |
2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
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 |
||
13 |
"{ Package: 'stx:libbasic' }" |
|
14 |
||
15 |
nil subclass:#Object |
|
16 |
instanceVariableNames:'' |
|
17 |
classVariableNames:'ErrorSignal HaltSignal MessageNotUnderstoodSignal |
|
18 |
UserInterruptSignal RecursionInterruptSignal |
|
19 |
ExceptionInterruptSignal SubscriptOutOfBoundsSignal |
|
20 |
IndexNotFoundSignal NonIntegerIndexSignal NotFoundSignal |
|
21 |
KeyNotFoundSignal ElementOutOfBoundsSignal UserNotificationSignal |
|
22 |
InformationSignal WarningSignal PrimitiveFailureSignal |
|
23 |
DeepCopyErrorSignal AbortSignal ErrorRecursion Dependencies |
|
24 |
InfoPrinting ActivityNotificationSignal InternalErrorSignal |
|
25 |
NonWeakDependencies SynchronizationSemaphores ObjectAttributes |
|
26 |
OSSignalInterruptSignal FinalizationLobby |
|
27 |
RecursiveStoreStringSignal AbortAllSignal' |
|
5754 | 28 |
poolDictionaries:'' |
5755 | 29 |
category:'Kernel-Objects' |
30 |
! |
|
31 |
||
32 |
!Object class methodsFor:'documentation'! |
|
3023
674376809496
general listView support (#displayOn / widthOn / heightOn)
ca
parents:
3010
diff
changeset
|
33 |
|
5754 | 34 |
copyright |
5755 | 35 |
" |
36 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
37 |
All Rights Reserved |
|
38 |
||
39 |
This software is furnished under a license and may be used |
|
40 |
only in accordance with the terms of that license and with the |
|
41 |
inclusion of the above copyright notice. This software may not |
|
42 |
be provided or otherwise made available to, or used by, any |
|
43 |
other person. No title to or ownership of the software is |
|
44 |
hereby transferred. |
|
45 |
" |
|
46 |
! |
|
47 |
||
48 |
dependencies |
|
49 |
" |
|
50 |
ST/X dependencies are slightly modified from ST-80's |
|
51 |
(we think they are better ;-). |
|
52 |
||
53 |
One problem occuring very often in ST-80 is that some object |
|
54 |
cannot be garbage collected because some dependency is present, |
|
55 |
having the object as a dependent of some other object. |
|
56 |
In ST-80, this association remains alive (because a Dictionary |
|
57 |
is used to hold dependents) - even if no other references exist to |
|
58 |
to dependent or the dependee. |
|
59 |
||
60 |
This means, that in ST-80, a #release is mandatory in order to |
|
61 |
prevent memory leaks. |
|
62 |
We think, that this is a bad solution, since after all, exactly that |
|
63 |
kind of work should be performed by a garbage collector - you should not |
|
64 |
need to care about dependencies. |
|
65 |
From a philosophical point of view, why should some object depend on |
|
66 |
something that the programmer considers a dead object ? |
|
67 |
(well - worse than that: it seems that some ST-80 code even depends on |
|
68 |
that behavior) |
|
69 |
||
70 |
In order to limit the trouble, ST-80 reimplemented the way dependents |
|
71 |
are stored in the model class - this one keeps the dependents locally, |
|
72 |
so these dependents go away, once the model is reclaimed. |
|
73 |
That may make things even more confusing: with models, no #release is |
|
74 |
needed, with general objects it is mandatory. |
|
75 |
||
76 |
||
77 |
In ST/X, dependencies are implemented using a WeakDictionary; this means, |
|
78 |
that once the dependee dies, the dependency association is removed automatically, |
|
79 |
and the dependent can be reclaimed by the garbage collector, if no other |
|
80 |
references exist to the dependent. |
|
81 |
In order to (at least) provide a mechanism for the old behavior |
|
82 |
(in case your application heavily depends on the ST-80 mechanism), complementary |
|
83 |
protocol to add nonWeak dependencies is provided |
|
84 |
(see #addNonWeakDependent / #removeNonWeakDependent). |
|
85 |
||
86 |
||
87 |
Caveat: |
|
88 |
since interests are implemented using InterestConverter (which are simply |
|
89 |
forwarding messages), these must use the nonWeak mechanism (as done in ST-80 |
|
90 |
automatically). |
|
91 |
The reason is that there are usually no direct references to the converters, |
|
92 |
and those would be reclaimed if stored in a weakDictionary. |
|
93 |
This means, that those interests MUST be removed with #retractInterest |
|
94 |
(which is bug-compatible to ST-80). |
|
95 |
We rewrite things to provide a more convenient mechanism in the future ... |
|
96 |
||
97 |
||
98 |
I like to hear comments on the above - do you think its better ? |
|
99 |
" |
|
100 |
! |
|
101 |
||
102 |
documentation |
|
103 |
" |
|
104 |
Object is the superclass of most other classes. |
|
105 |
(except for nil-subclasses, which inherit nothing, |
|
106 |
to catch any message into their #doesNotUnderstand: method) |
|
107 |
||
108 |
Protocol which is common to every object is defined here. |
|
109 |
Also some utility stuff (like notify) and error handling is implemented here. |
|
110 |
||
111 |
Object has no instance variables (and may not get any added). One reason is, that |
|
112 |
UndefinedObject and SmallInteger are also inheriting from Object - these two cannot |
|
113 |
have instance variables (due to their implementation). |
|
114 |
The other reason is that the runtime system (VM) knows about the layout of some built-in |
|
115 |
classes (think of Class, Method, Block and also Integer or Float). |
|
116 |
If you were allowed to add instance variables to Object, the VM had to be recompiled |
|
117 |
(and also rewritten in some places). |
|
118 |
||
119 |
[Class variables:] |
|
120 |
||
121 |
ErrorSignal <Signal> Signal raised for error/error: messages |
|
122 |
also, parent of all other signals. |
|
123 |
||
124 |
HaltSignal <Signal> Signal raised for halt/halt: messages |
|
125 |
||
126 |
MessageNotUnderstoodSignal Signals raised for various error conditions |
|
127 |
UserInterruptSignal |
|
128 |
RecursionInterruptSignal |
|
129 |
ExceptionInterruptSignal |
|
130 |
SubscriptOutOfBoundsSignal |
|
131 |
NonIntegerIndexSignal |
|
132 |
NotFoundSignal |
|
133 |
KeyNotFoundSignal |
|
134 |
ElementOutOfBoundsSignal |
|
135 |
InformationSignal |
|
136 |
WarningSignal |
|
137 |
DeepCopyErrorSignal |
|
138 |
InternalErrorSignal |
|
139 |
||
140 |
AbortSignal <Signal> Signal raised by debugger, to abort a computation |
|
141 |
BUT, the debugger will only raise it if it is handled. |
|
142 |
By handling the abortSignal, you can control where the |
|
143 |
debuggers abort-function resumes execution in case of |
|
144 |
an error. |
|
145 |
||
146 |
ErrorRecursion <Boolean> controls behavior when recursive errors occur (i.e. |
|
147 |
an error while handling an error). |
|
148 |
||
149 |
Dependencies <WeakDependencyDictionary> |
|
150 |
keeps track of object dependencies. |
|
151 |
||
152 |
InfoPrinting <Boolean> controls weather informational messages |
|
153 |
are printed. |
|
154 |
||
155 |
ActivityNotificationSignal <QuerySignal> |
|
156 |
raised on #activityNotification: |
|
157 |
||
158 |
NonWeakDependencies <Dictionary> keeps track of object dependencies. |
|
159 |
Dependents stay alive. |
|
160 |
||
161 |
SynchronizationSemaphores <WeakIdentityDictionary> |
|
162 |
Semaphores for per-object-monitor. |
|
163 |
||
164 |
||
165 |
[author:] |
|
166 |
Claus Gittinger |
|
167 |
||
168 |
" |
|
169 |
! ! |
|
170 |
||
171 |
!Object class methodsFor:'initialization'! |
|
172 |
||
5971 | 173 |
initSignals |
174 |
"called only once - initialize signals" |
|
175 |
||
176 |
ErrorSignal := Error. |
|
177 |
||
178 |
ControlInterrupt notifierString:'control interrupted'. |
|
179 |
||
180 |
"/ HaltSignal := ControlInterrupt newSignalMayProceed:true. |
|
181 |
"/ HaltSignal nameClass:self message:#haltSignal. |
|
182 |
HaltSignal := HaltInterrupt. |
|
183 |
HaltSignal notifierString:'halt encountered'. |
|
184 |
||
185 |
MessageNotUnderstoodSignal := ErrorSignal newSignalMayProceed:true. |
|
186 |
MessageNotUnderstoodSignal nameClass:self message:#messageNotUnderstoodSignal. |
|
187 |
MessageNotUnderstoodSignal notifierString:'message not understood'. |
|
188 |
||
189 |
PrimitiveFailureSignal := ErrorSignal newSignalMayProceed:true. |
|
190 |
PrimitiveFailureSignal nameClass:self message:#primitiveFailureSignal. |
|
191 |
PrimitiveFailureSignal notifierString:'primitive failed'. |
|
192 |
||
193 |
InternalErrorSignal := ErrorSignal newSignalMayProceed:false. |
|
194 |
InternalErrorSignal nameClass:self message:#internalErrorSignal. |
|
195 |
InternalErrorSignal notifierString:'VM internal error: '. |
|
196 |
||
197 |
"/ UserInterruptSignal := (Signal new) mayProceed:true. |
|
198 |
"/ UserInterruptSignal := ControlInterrupt newSignalMayProceed:true. |
|
199 |
"/ UserInterruptSignal nameClass:self message:#userInterruptSignal. |
|
200 |
UserInterruptSignal := UserInterrupt. |
|
201 |
UserInterruptSignal notifierString:'user Interrupt'. |
|
202 |
||
203 |
"/ RecursionInterruptSignal := ErrorSignal newSignalMayProceed:false. |
|
204 |
RecursionInterruptSignal := (Signal new) mayProceed:true. |
|
205 |
RecursionInterruptSignal nameClass:self message:#recursionInterruptSignal. |
|
206 |
RecursionInterruptSignal notifierString:'recursion limit reached'. |
|
207 |
||
208 |
ExceptionInterruptSignal := ErrorSignal newSignalMayProceed:true. |
|
209 |
ExceptionInterruptSignal nameClass:self message:#exceptionInterruptSignal. |
|
210 |
ExceptionInterruptSignal notifierString:'exception Interrupt'. |
|
211 |
||
212 |
NotFoundSignal := ErrorSignal newSignalMayProceed:true. |
|
213 |
NotFoundSignal nameClass:self message:#notFoundSignal. |
|
214 |
NotFoundSignal notifierString:'no such element'. |
|
215 |
||
216 |
IndexNotFoundSignal := NotFoundSignal newSignalMayProceed:true. |
|
217 |
IndexNotFoundSignal nameClass:self message:#indexNotFoundSignal. |
|
218 |
IndexNotFoundSignal notifierString:'bad index: '. |
|
219 |
||
220 |
SubscriptOutOfBoundsSignal := IndexNotFoundSignal newSignalMayProceed:true. |
|
221 |
SubscriptOutOfBoundsSignal nameClass:self message:#subscriptOutOfBoundsSignal. |
|
222 |
SubscriptOutOfBoundsSignal notifierString:'subscript out of bounds: '. |
|
223 |
||
224 |
ElementOutOfBoundsSignal := ErrorSignal newSignalMayProceed:false. |
|
225 |
ElementOutOfBoundsSignal nameClass:self message:#elementOutOfBoundsSignal. |
|
226 |
ElementOutOfBoundsSignal notifierString:'element not appropriate or out of bounds'. |
|
227 |
||
228 |
KeyNotFoundSignal := NotFoundSignal newSignalMayProceed:true. |
|
229 |
KeyNotFoundSignal nameClass:self message:#keyNotFoundSignal. |
|
230 |
KeyNotFoundSignal notifierString:'no such key: '. |
|
231 |
||
232 |
NonIntegerIndexSignal := IndexNotFoundSignal newSignalMayProceed:true. |
|
233 |
NonIntegerIndexSignal nameClass:self message:#nonIntegerIndexSignal. |
|
234 |
NonIntegerIndexSignal notifierString:'index must be integer'. |
|
235 |
||
236 |
UserNotificationSignal := QuerySignal new. |
|
237 |
UserNotificationSignal nameClass:self message:#userNotificationSignal. |
|
238 |
UserNotificationSignal notifierString:'user notifiaction wanted'. |
|
239 |
||
240 |
InformationSignal := UserNotificationSignal newSignalMayProceed:true. |
|
241 |
InformationSignal nameClass:self message:#informationSignal. |
|
242 |
InformationSignal notifierString:'information'. |
|
243 |
||
244 |
WarningSignal := UserNotificationSignal newSignalMayProceed:true. |
|
245 |
WarningSignal nameClass:self message:#warningSignal. |
|
246 |
WarningSignal notifierString:'warning'. |
|
247 |
||
248 |
ActivityNotificationSignal := UserNotificationSignal newSignalMayProceed:true. |
|
249 |
ActivityNotificationSignal nameClass:self message:#activityNotificationSignal. |
|
250 |
ActivityNotificationSignal notifierString:'activity'. |
|
251 |
||
252 |
DeepCopyErrorSignal := ErrorSignal newSignalMayProceed:true. |
|
253 |
DeepCopyErrorSignal nameClass:self message:#deepCopyErrorSignal. |
|
254 |
DeepCopyErrorSignal notifierString:'object cannot be deepCopy-ed'. |
|
255 |
||
256 |
" |
|
257 |
AbortSignal is not a child of ErrorSignal - |
|
258 |
this would complicate abort from within a signal handler |
|
259 |
" |
|
260 |
AbortSignal := Signal genericSignal newSignalMayProceed:true. |
|
261 |
AbortSignal nameClass:self message:#abortSignal. |
|
262 |
AbortSignal notifierString:'unhandled abort signal'. |
|
263 |
||
264 |
AbortAllSignal := Signal genericSignal newSignalMayProceed:true. |
|
265 |
AbortAllSignal nameClass:self message:#abortAllSignal. |
|
266 |
AbortAllSignal notifierString:'unhandled abortAll signal'. |
|
267 |
||
268 |
" |
|
269 |
OSSignalInterruptSignal is not a child of ErrorSignal - |
|
270 |
it requires explicit catching. |
|
271 |
If unhandled, a debugger is entered. |
|
272 |
" |
|
273 |
OSSignalInterruptSignal := Signal genericSignal newSignalMayProceed:true. |
|
274 |
OSSignalInterruptSignal nameClass:self message:#osSignalInterruptSignal. |
|
275 |
OSSignalInterruptSignal notifierString:'OS signal interrupt'. |
|
276 |
||
277 |
RecursiveStoreStringSignal := QuerySignal new. |
|
278 |
RecursiveStoreStringSignal nameClass:self message:#recursiveStoreStringSignal. |
|
279 |
RecursiveStoreStringSignal notifierString:'attempt to generate storeString of recursive object'. |
|
280 |
||
281 |
"Object initSignals" |
|
282 |
||
283 |
"Modified: / 22.1.1998 / 21:23:40 / av" |
|
284 |
"Modified: / 3.2.1998 / 18:55:09 / cg" |
|
285 |
"Modified: / 4.8.1999 / 08:54:06 / stefan" |
|
286 |
! |
|
287 |
||
5755 | 288 |
initialize |
289 |
"called only once - initialize signals" |
|
290 |
||
291 |
ErrorSignal isNil ifTrue:[ |
|
5971 | 292 |
self initSignals |
293 |
]. |
|
294 |
||
295 |
ObjectAttributes isNil ifTrue:[ |
|
296 |
ObjectAttributes := WeakIdentityDictionary new. |
|
297 |
]. |
|
298 |
Dependencies isNil ifTrue:[ |
|
299 |
Dependencies := WeakDependencyDictionary new. |
|
300 |
]. |
|
301 |
NonWeakDependencies isNil ifTrue:[ |
|
302 |
NonWeakDependencies := IdentityDictionary new. |
|
303 |
]. |
|
304 |
SynchronizationSemaphores isNil ifTrue:[ |
|
305 |
SynchronizationSemaphores := WeakIdentityDictionary new. |
|
306 |
]. |
|
5755 | 307 |
FinalizationLobby isNil ifTrue:[ |
308 |
FinalizationLobby := Registry new. |
|
309 |
]. |
|
310 |
||
311 |
"/ initialize InfoPrinting to the VM's infoPrint setting |
|
312 |
"/ (which can be turned off via a command line argument) |
|
313 |
InfoPrinting := ObjectMemory infoPrinting. |
|
314 |
||
315 |
"Object initialize" |
|
316 |
||
317 |
"Modified: / 22.1.1998 / 21:23:40 / av" |
|
318 |
"Modified: / 3.2.1998 / 18:55:09 / cg" |
|
319 |
"Modified: / 4.8.1999 / 08:54:06 / stefan" |
|
320 |
! ! |
|
321 |
||
322 |
!Object class methodsFor:'Compatibility - ST80'! |
|
323 |
||
324 |
rootError |
|
325 |
"return the signal used for error/error: - handling. |
|
326 |
Same as errorSignal for ST80 compatibility." |
|
327 |
||
328 |
^ ErrorSignal |
|
329 |
||
330 |
"Created: / 15.1.1998 / 23:47:05 / stefan" |
|
331 |
! ! |
|
332 |
||
333 |
!Object class methodsFor:'Signal constants'! |
|
334 |
||
335 |
abortAllSignal |
|
336 |
"return the signal used to abort user actions (much like AbortSignal). |
|
337 |
This signal is supposed to abort multiple operation actions, and get out of |
|
338 |
the loop (such as when confirming multiple class deletions etc.)" |
|
339 |
||
340 |
^ AbortAllSignal |
|
341 |
! |
|
342 |
||
343 |
abortSignal |
|
344 |
"return the signal used to abort user actions. This signal is only |
|
345 |
raised if caught (by the debugger), and will lead way out of the |
|
346 |
currently active doIt/printIt or inspectIt. (also some others use |
|
347 |
this for a save abort)" |
|
348 |
||
349 |
^ AbortSignal |
|
350 |
! |
|
351 |
||
352 |
activityNotificationSignal |
|
353 |
"return the signal used for activity notifications. |
|
354 |
A handler for this signal gets all #activityNotification: sends" |
|
355 |
||
356 |
^ ActivityNotificationSignal |
|
357 |
! |
|
358 |
||
359 |
deepCopyErrorSignal |
|
360 |
"return the signal raised when a deepcopy is asked for |
|
361 |
an object which cannot do this (for example, BlockClosures |
|
362 |
or Contexts)." |
|
363 |
||
364 |
^ DeepCopyErrorSignal |
|
365 |
! |
|
366 |
||
367 |
elementOutOfBoundsSignal |
|
368 |
"return the signal used for element error reporting |
|
369 |
(this signal is used for example when a value not in 0..255 is to |
|
370 |
be put into a bytearray)" |
|
371 |
||
372 |
^ ElementOutOfBoundsSignal |
|
373 |
! |
|
374 |
||
375 |
errorSignal |
|
376 |
"return the signal used for error/error: - handling" |
|
377 |
||
378 |
^ ErrorSignal |
|
379 |
! |
|
380 |
||
381 |
exceptionInterruptSignal |
|
382 |
"return the signal used for exception (display errors) error handling" |
|
383 |
||
384 |
^ ExceptionInterruptSignal |
|
385 |
! |
|
386 |
||
387 |
haltSignal |
|
388 |
"return the signal used for halt/halt: - handling" |
|
389 |
||
390 |
^ HaltSignal |
|
391 |
! |
|
392 |
||
393 |
indexNotFoundSignal |
|
394 |
"return the signal used for bad index error reporting. |
|
395 |
This is also the parentSignal of the nonIntegerIndex- and |
|
396 |
subscriptOutOfBoundsSignal" |
|
397 |
||
398 |
^ IndexNotFoundSignal |
|
399 |
||
400 |
"Created: / 8.11.1997 / 19:15:48 / cg" |
|
401 |
! |
|
402 |
||
403 |
informationSignal |
|
404 |
"return the signal used for informations. |
|
405 |
A handler for this signal gets all #information: sends" |
|
406 |
||
407 |
^ InformationSignal |
|
408 |
! |
|
409 |
||
410 |
internalErrorSignal |
|
411 |
"return the signal used to report internal (VM-) errors." |
|
412 |
||
413 |
^ InternalErrorSignal |
|
414 |
! |
|
415 |
||
416 |
keyNotFoundSignal |
|
417 |
"return the signal used for no such key error reporting" |
|
418 |
||
419 |
^ KeyNotFoundSignal |
|
420 |
! |
|
421 |
||
422 |
messageNotUnderstoodSignal |
|
423 |
"return the signal used for doesNotUnderstand: - error handling" |
|
424 |
||
425 |
^ MessageNotUnderstoodSignal |
|
426 |
! |
|
427 |
||
428 |
nonIntegerIndexSignal |
|
429 |
"return the signal used for bad subscript error reporting" |
|
430 |
||
431 |
^ NonIntegerIndexSignal |
|
432 |
! |
|
433 |
||
434 |
notFoundSignal |
|
435 |
"return the signal used for no element found error reporting" |
|
436 |
||
437 |
^ NotFoundSignal |
|
438 |
! |
|
439 |
||
440 |
osSignalInterruptSignal |
|
441 |
"return the signal used for OS-signal error reporting; |
|
442 |
This is only raised if handled - otherwise, a debugger is entered." |
|
443 |
||
444 |
^ OSSignalInterruptSignal |
|
445 |
||
446 |
"Modified: / 12.6.1998 / 16:27:26 / cg" |
|
447 |
! |
|
448 |
||
449 |
primitiveFailureSignal |
|
450 |
"return the signal used for primitiveFailed - error handling" |
|
451 |
||
452 |
^ PrimitiveFailureSignal |
|
453 |
! |
|
454 |
||
455 |
privateMethodSignal |
|
456 |
"return the signal used for privateMethod - error handling" |
|
457 |
||
458 |
^ MessageNotUnderstoodSignal |
|
459 |
! |
|
460 |
||
461 |
recursionInterruptSignal |
|
462 |
"return the signal used for recursion overflow error handling" |
|
463 |
||
464 |
^ RecursionInterruptSignal |
|
465 |
! |
|
466 |
||
467 |
recursiveStoreStringSignal |
|
468 |
"return the query signal used to report storeString generation of recursive objects" |
|
469 |
||
470 |
^ RecursiveStoreStringSignal |
|
471 |
||
472 |
" |
|
473 |
Object recursiveStoreStringSignal handle:[:ex | |
|
474 |
self halt |
|
475 |
] do:[ |
|
476 |
|a| |
|
477 |
||
478 |
a := Array new:1. |
|
479 |
a at:1 put:a. |
|
480 |
a storeOn:Transcript |
|
481 |
] |
|
482 |
" |
|
483 |
||
484 |
" |
|
485 |
|a| |
|
486 |
||
487 |
a := Array new:1. |
|
488 |
a at:1 put:a. |
|
489 |
a storeOn:Transcript |
|
490 |
" |
|
491 |
||
492 |
||
493 |
||
494 |
! |
|
495 |
||
496 |
subscriptOutOfBoundsSignal |
|
497 |
"return the signal used for subscript error reporting. |
|
498 |
(this signal is used for example when an array is accessed with an |
|
499 |
index less than 1 or greater than the array size)" |
|
500 |
||
501 |
^ SubscriptOutOfBoundsSignal |
|
502 |
! |
|
503 |
||
504 |
userInterruptSignal |
|
505 |
"return the signal used for ^C interrupts handling" |
|
506 |
||
507 |
^ UserInterruptSignal |
|
508 |
! |
|
509 |
||
510 |
userNotificationSignal |
|
511 |
"the parent signal used with information and warnings. |
|
512 |
Handling this allows handling of both information- and warning notifications." |
|
513 |
||
514 |
^ UserNotificationSignal |
|
515 |
! |
|
516 |
||
517 |
warningSignal |
|
518 |
"return the signal used for warnings. |
|
519 |
A handler for this signal gets all #warn: sends" |
|
520 |
||
521 |
^ WarningSignal |
|
522 |
! ! |
|
523 |
||
524 |
!Object class methodsFor:'info messages'! |
|
525 |
||
526 |
infoPrinting |
|
527 |
"return the flag which controls information messages." |
|
528 |
||
529 |
^ InfoPrinting |
|
530 |
! |
|
531 |
||
532 |
infoPrinting:aBoolean |
|
533 |
"{ Pragma: +optSpace }" |
|
534 |
||
535 |
"turn on/off printing of information messages. |
|
536 |
If the argument, aBoolean is false, infoPrint will not output |
|
537 |
messages. The default is true." |
|
538 |
||
539 |
InfoPrinting := aBoolean |
|
540 |
! ! |
|
541 |
||
542 |
!Object class methodsFor:'queries'! |
|
543 |
||
544 |
isBuiltInClass |
|
545 |
"return true, if this class is known by the run-time-system, |
|
546 |
i.e. you cannot add/remove instance variables without recompiling |
|
547 |
the VM. |
|
548 |
Here, true is returned for myself, false for subclasses." |
|
549 |
||
550 |
^ self == Object |
|
551 |
||
552 |
"Modified: 23.4.1996 / 16:00:07 / cg" |
|
553 |
! ! |
|
554 |
||
555 |
!Object methodsFor:'Compatibility - ST80'! |
|
556 |
||
557 |
isMetaclass |
|
558 |
^ self isMeta |
|
559 |
! ! |
|
560 |
||
561 |
!Object methodsFor:'Compatibility - Squeak'! |
|
562 |
||
563 |
as: aSimilarClass |
|
564 |
"Create an object of class aSimilarClass that has similar contents to the receiver." |
|
565 |
||
566 |
^ aSimilarClass newFrom:self |
|
567 |
||
568 |
" |
|
569 |
#[1 2 3 4] as:ByteArray |
|
570 |
" |
|
571 |
! |
|
572 |
||
573 |
asString |
|
574 |
^ self printString |
|
575 |
! |
|
576 |
||
577 |
clone |
|
578 |
^ self shallowCopy |
|
579 |
! |
|
580 |
||
581 |
currentHand |
|
5912 | 582 |
"Return a usable HandMorph -- the one associated with the object's current environment. This method will always return a hand, even if it has to conjure one up as a last resort. If a particular hand is actually handling events at the moment (such as a remote hand or a ghost hand), it will be returned." |
583 |
||
584 |
|w h| |
|
585 |
||
586 |
w := self currentWorld. |
|
587 |
h := w activeHand. |
|
588 |
h isNil ifTrue:[ |
|
589 |
h := w hands first |
|
590 |
]. |
|
591 |
^ h |
|
5755 | 592 |
! |
593 |
||
594 |
currentWorld |
|
595 |
^ Utilities currentWorld |
|
596 |
! |
|
597 |
||
598 |
newTileMorphRepresentative |
|
599 |
^ TileMorph new setLiteral: self |
|
600 |
! |
|
601 |
||
602 |
stringForReadout |
|
603 |
^ self stringRepresentation |
|
604 |
! |
|
605 |
||
606 |
stringRepresentation |
|
607 |
"Answer a string that represents the receiver. For most objects this is simply its printString, but for strings themselves, it's themselves. 6/12/96 sw" |
|
608 |
||
609 |
^ self printString |
|
610 |
! |
|
611 |
||
612 |
veryDeepCopy |
|
613 |
||
614 |
^(self deepCopyUsing:(IdentityDictionary new)) postDeepCopyFrom:self |
|
615 |
! ! |
|
616 |
||
617 |
!Object methodsFor:'accessing'! |
|
618 |
||
619 |
at:index |
|
620 |
"return the indexed instance variable with index, anInteger; |
|
621 |
this method can be redefined in subclasses." |
|
622 |
||
623 |
^ self basicAt:index |
|
624 |
! |
|
625 |
||
626 |
at:index put:anObject |
|
627 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
628 |
this method can be redefined in subclasses. Returns anObject (sigh)" |
|
629 |
||
630 |
^ self basicAt:index put:anObject |
|
631 |
||
632 |
"Modified: 19.4.1996 / 11:13:29 / cg" |
|
633 |
! |
|
634 |
||
635 |
basicAt:index |
|
636 |
"return the indexed instance variable with index, anInteger. |
|
637 |
Trigger an error if the receiver has no indexed instance variables. |
|
638 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
639 |
||
640 |
%{ /* NOCONTEXT */ |
|
641 |
||
642 |
REGISTER int nbytes, indx; |
|
643 |
OBJ myClass; |
|
644 |
REGISTER char *pFirst; |
|
645 |
#ifdef alpha64 |
|
646 |
# define int32 int |
|
647 |
#else |
|
648 |
# define int32 long |
|
649 |
#endif |
|
650 |
REGISTER int n; |
|
651 |
||
652 |
/* |
|
653 |
* notice the missing test for self being a nonNilObject - |
|
654 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
655 |
* and SmallInteger |
|
656 |
*/ |
|
657 |
if (__isSmallInteger(index)) { |
|
658 |
myClass = __qClass(self); |
|
659 |
indx = __intVal(index) - 1; |
|
660 |
n /* nInstVars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
661 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* nInstVars */); |
|
662 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
663 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
664 |
||
665 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
666 |
case __MASKSMALLINT(POINTERARRAY): |
|
667 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
668 |
/* |
|
669 |
* pointers |
|
670 |
*/ |
|
671 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
672 |
OBJ *op; |
|
673 |
||
674 |
op = (OBJ *)pFirst + indx; |
|
675 |
RETURN ( *op ); |
|
676 |
} |
|
677 |
break; |
|
678 |
||
679 |
case __MASKSMALLINT(BYTEARRAY): |
|
680 |
/* |
|
681 |
* (unsigned) bytes |
|
682 |
*/ |
|
683 |
if ((unsigned)indx < nbytes) { |
|
684 |
unsigned char *cp; |
|
685 |
||
686 |
cp = (unsigned char *)pFirst + indx; |
|
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
687 |
RETURN ( __MKSMALLINT( (INT)(*cp & 0xFF)) ); |
5755 | 688 |
} |
689 |
break; |
|
690 |
||
691 |
case __MASKSMALLINT(FLOATARRAY): |
|
692 |
/* |
|
693 |
* native floats |
|
694 |
*/ |
|
695 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
696 |
float *fp; |
|
697 |
float f; |
|
698 |
OBJ v; |
|
699 |
||
700 |
fp = (float *)pFirst + indx; |
|
701 |
f = *fp; |
|
702 |
if (f == 0.0) { |
|
703 |
v = __float0; |
|
704 |
} else { |
|
705 |
__qMKSFLOAT(v, f); |
|
706 |
} |
|
707 |
RETURN (v); |
|
708 |
} |
|
709 |
break; |
|
710 |
||
711 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
712 |
/* |
|
713 |
* native doubles |
|
714 |
*/ |
|
715 |
#ifdef __NEED_DOUBLE_ALIGN |
|
716 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
|
717 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
718 |
||
719 |
pFirst += delta; |
|
720 |
nbytes -= delta; |
|
721 |
} |
|
722 |
#endif |
|
723 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
|
724 |
double *dp; |
|
725 |
double d; |
|
726 |
OBJ v; |
|
727 |
||
728 |
dp = (double *)pFirst + indx; |
|
729 |
d = *dp; |
|
730 |
if (d == 0.0) { |
|
731 |
v = __float0; |
|
732 |
} else { |
|
733 |
__qMKFLOAT(v, d); |
|
734 |
} |
|
735 |
RETURN (v); |
|
736 |
} |
|
737 |
break; |
|
738 |
||
739 |
case __MASKSMALLINT(WORDARRAY): |
|
740 |
/* |
|
741 |
* unsigned 16bit ints |
|
742 |
*/ |
|
743 |
/* Notice: the hard coded shifts are by purpose; |
|
744 |
* it makes us independent of the short-size of the machine |
|
745 |
*/ |
|
746 |
if ((unsigned)indx < (nbytes>>1)) { |
|
747 |
unsigned short *sp; |
|
748 |
||
749 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
750 |
RETURN ( __MKSMALLINT( (INT)(*sp & 0xFFFF)) ); |
5755 | 751 |
} |
752 |
break; |
|
753 |
||
754 |
case __MASKSMALLINT(SWORDARRAY): |
|
755 |
/* |
|
756 |
* signed 16bit ints |
|
757 |
*/ |
|
758 |
/* Notice: the hard coded shifts are by purpose; |
|
759 |
* it makes us independent of the short-size of the machine |
|
760 |
*/ |
|
761 |
if ((unsigned)indx < (nbytes>>1)) { |
|
762 |
short *ssp; |
|
763 |
||
764 |
ssp = (short *)(pFirst + (indx<<1)); |
|
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
765 |
RETURN ( __MKSMALLINT( (INT)(*ssp) )); |
5755 | 766 |
} |
767 |
break; |
|
768 |
||
769 |
case __MASKSMALLINT(LONGARRAY): |
|
770 |
/* |
|
771 |
* unsigned 32bit ints |
|
772 |
*/ |
|
773 |
/* Notice: the hard coded shifts are by purpose; |
|
774 |
* it makes us independent of the int-size of the machine |
|
775 |
*/ |
|
776 |
if ((unsigned)indx < (nbytes>>2)) { |
|
777 |
unsigned int32 ul; |
|
778 |
unsigned int32 *lp; |
|
779 |
||
780 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
781 |
ul = *lp; |
|
782 |
#ifdef alpha64 |
|
783 |
{ |
|
784 |
unsigned INT ull = (unsigned INT)ul; |
|
785 |
RETURN ( __MKSMALLINT(ull) ); |
|
786 |
} |
|
787 |
#else |
|
788 |
if (ul <= _MAX_INT) { |
|
789 |
RETURN ( __MKSMALLINT(ul) ); |
|
790 |
} |
|
791 |
RETURN ( __MKULARGEINT(ul) ); |
|
792 |
#endif |
|
793 |
} |
|
794 |
break; |
|
795 |
||
796 |
case __MASKSMALLINT(SLONGARRAY): |
|
797 |
/* |
|
798 |
* signed 32bit ints |
|
799 |
*/ |
|
800 |
/* Notice: the hard coded shifts are by purpose; |
|
801 |
* it makes us independent of the int-size of the machine |
|
802 |
*/ |
|
803 |
if ((unsigned)indx < (nbytes>>2)) { |
|
804 |
int32 *slp; |
|
805 |
int32 l; |
|
806 |
||
807 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
808 |
l = *slp; |
|
809 |
#ifdef alpha64 |
|
810 |
{ |
|
811 |
INT ll = (INT)l; |
|
812 |
RETURN ( __MKSMALLINT(ll) ); |
|
813 |
} |
|
814 |
#else |
|
815 |
if (__ISVALIDINTEGER(l)) { |
|
816 |
RETURN ( __MKSMALLINT(l) ); |
|
817 |
} |
|
818 |
RETURN ( __MKLARGEINT(l) ); |
|
819 |
#endif |
|
820 |
} |
|
821 |
break; |
|
822 |
||
823 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
824 |
/* |
|
825 |
* signed 64bit longlongs |
|
826 |
*/ |
|
827 |
#ifdef __NEED_LONGLONG_ALIGN |
|
828 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
|
829 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
830 |
||
831 |
pFirst += delta; |
|
832 |
nbytes -= delta; |
|
833 |
} |
|
834 |
#endif |
|
835 |
/* Notice: the hard coded shifts are by purpose; |
|
836 |
* it makes us independent of the long/longlong-size of the machine |
|
837 |
*/ |
|
838 |
if ((unsigned)indx < (nbytes>>3)) { |
|
839 |
#ifdef alpha64 |
|
840 |
INT *slp, ll; |
|
841 |
||
842 |
slp = (INT *)(pFirst + (indx<<3)); |
|
843 |
ll = *slp; |
|
844 |
if (__ISVALIDINTEGER(ll)) { |
|
845 |
RETURN ( __MKSMALLINT(ll) ); |
|
846 |
} |
|
847 |
RETURN ( __MKLARGEINT(ll) ); |
|
848 |
#else |
|
849 |
__int64__ *llp; |
|
850 |
extern OBJ __MKINT64(); |
|
851 |
||
852 |
llp = (__int64__ *)(pFirst + (indx<<3)); |
|
853 |
RETURN (__MKINT64(llp)); |
|
854 |
#endif |
|
855 |
} |
|
856 |
break; |
|
857 |
||
858 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
859 |
/* |
|
860 |
* unsigned 64bit longlongs |
|
861 |
*/ |
|
862 |
#ifdef __NEED_LONGLONG_ALIGN |
|
863 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
|
864 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
865 |
||
866 |
pFirst += delta; |
|
867 |
nbytes -= delta; |
|
868 |
} |
|
869 |
#endif |
|
870 |
/* Notice: the hard coded shifts are by purpose; |
|
871 |
* it makes us independent of the long/longlong-size of the machine |
|
872 |
*/ |
|
873 |
if ((unsigned)indx < (nbytes>>3)) { |
|
874 |
#ifdef alpha64 |
|
875 |
unsigned INT *ulp, ul; |
|
876 |
||
877 |
ulp = (unsigned INT *)(pFirst + (indx<<3)); |
|
878 |
ul = *ulp; |
|
879 |
if (ul <= _MAX_INT) { |
|
880 |
RETURN ( __MKSMALLINT(ul) ); |
|
881 |
} |
|
882 |
RETURN ( __MKULARGEINT(ul) ); |
|
883 |
#else |
|
884 |
__uint64__ *llp; |
|
885 |
extern OBJ __MKUINT64(); |
|
886 |
||
887 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
888 |
RETURN (__MKUINT64(llp)); |
|
889 |
#endif |
|
890 |
} |
|
891 |
break; |
|
892 |
} |
|
893 |
} |
|
894 |
||
895 |
# undef int32 |
|
896 |
||
897 |
%}. |
|
898 |
index isInteger ifFalse:[ |
|
899 |
^ self indexNotInteger |
|
900 |
]. |
|
901 |
^ self subscriptBoundsError:index |
|
902 |
! |
|
903 |
||
904 |
basicAt:index put:anObject |
|
905 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
906 |
Returns anObject (sigh). |
|
907 |
Trigger an error if the receiver has no indexed instance variables. |
|
908 |
||
909 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
910 |
||
911 |
%{ /* NOCONTEXT */ |
|
912 |
||
913 |
register int nbytes, indx; |
|
914 |
OBJ myClass; |
|
915 |
register char *pFirst; |
|
916 |
#ifdef alpha64 |
|
917 |
# define int32 int |
|
918 |
#else |
|
919 |
# define int32 long |
|
920 |
#endif |
|
921 |
/* int nInstBytes, ninstvars, flags; */ |
|
922 |
REGISTER int n; |
|
923 |
unsigned int u; |
|
924 |
int val; |
|
925 |
||
926 |
/* notice the missing test for self being a nonNilObject - |
|
927 |
this can be done since basicAt: is defined both in UndefinedObject |
|
928 |
and SmallInteger */ |
|
929 |
||
930 |
if (__isSmallInteger(index)) { |
|
931 |
indx = __intVal(index) - 1; |
|
932 |
myClass = __qClass(self); |
|
933 |
n /* ninstvars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
934 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* ninstvars */); |
|
935 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
936 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
937 |
||
938 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
939 |
case __MASKSMALLINT(POINTERARRAY): |
|
940 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
941 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
942 |
OBJ *op; |
|
943 |
||
944 |
op = (OBJ *)pFirst + indx; |
|
945 |
*op = anObject; |
|
946 |
__STORE(self, anObject); |
|
947 |
RETURN ( anObject ); |
|
948 |
} |
|
949 |
break; |
|
950 |
||
951 |
case __MASKSMALLINT(BYTEARRAY): |
|
952 |
if (__isSmallInteger(anObject)) { |
|
953 |
val = __intVal(anObject); |
|
954 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
|
955 |
if ((unsigned)indx < nbytes) { |
|
956 |
char *cp; |
|
957 |
||
958 |
cp = pFirst + indx; |
|
959 |
*cp = val; |
|
960 |
RETURN ( anObject ); |
|
961 |
} |
|
962 |
} |
|
963 |
} |
|
964 |
break; |
|
965 |
||
966 |
case __MASKSMALLINT(FLOATARRAY): |
|
967 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
|
968 |
float *fp; |
|
969 |
||
970 |
fp = (float *)pFirst + indx; |
|
971 |
if (anObject != nil) { |
|
972 |
if (! __isSmallInteger(anObject)) { |
|
973 |
if (__qIsFloatLike(anObject)) { |
|
974 |
*fp = (float)(__floatVal(anObject)); |
|
975 |
RETURN ( anObject ); |
|
976 |
} |
|
977 |
if (__qIsShortFloat(anObject)) { |
|
978 |
*fp = __shortFloatVal(anObject); |
|
979 |
RETURN ( anObject ); |
|
980 |
} |
|
981 |
} else { |
|
982 |
*fp = (float) __intVal(anObject); |
|
983 |
RETURN ( anObject ); |
|
984 |
} |
|
985 |
} |
|
986 |
} |
|
987 |
break; |
|
988 |
||
989 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
990 |
#ifdef __NEED_DOUBLE_ALIGN |
|
991 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
|
992 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
993 |
||
994 |
pFirst += delta; |
|
995 |
nbytes -= delta; |
|
996 |
} |
|
997 |
#endif |
|
998 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
|
999 |
double *dp; |
|
1000 |
||
1001 |
dp = (double *)pFirst + indx; |
|
1002 |
if (anObject != nil) { |
|
1003 |
if (! __isSmallInteger(anObject)) { |
|
1004 |
if (__qIsFloatLike(anObject)) { |
|
1005 |
*dp = __floatVal(anObject); |
|
1006 |
RETURN ( anObject ); |
|
1007 |
} |
|
1008 |
if (__qIsShortFloat(anObject)) { |
|
1009 |
*dp = (double)__shortFloatVal(anObject); |
|
1010 |
RETURN ( anObject ); |
|
1011 |
} |
|
1012 |
} else { |
|
1013 |
*dp = (double) __intVal(anObject); |
|
1014 |
RETURN ( anObject ); |
|
1015 |
} |
|
1016 |
} |
|
1017 |
} |
|
1018 |
break; |
|
1019 |
||
1020 |
case __MASKSMALLINT(WORDARRAY): |
|
1021 |
if (__isSmallInteger(anObject)) { |
|
1022 |
val = __intVal(anObject); |
|
1023 |
if ((unsigned)val <= 0xFFFF) { |
|
1024 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1025 |
unsigned short *sp; |
|
1026 |
||
1027 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
1028 |
*sp = val; |
|
1029 |
RETURN ( anObject ); |
|
1030 |
} |
|
1031 |
} |
|
1032 |
} |
|
1033 |
break; |
|
1034 |
||
1035 |
case __MASKSMALLINT(SWORDARRAY): |
|
1036 |
if (__isSmallInteger(anObject)) { |
|
1037 |
val = __intVal(anObject); |
|
1038 |
if ((val >= -32768) && (val < 32768)) { |
|
1039 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1040 |
short *ssp; |
|
1041 |
||
1042 |
ssp = (short *)(pFirst + (indx<<1)); |
|
1043 |
*ssp = val; |
|
1044 |
RETURN ( anObject ); |
|
1045 |
} |
|
1046 |
} |
|
1047 |
} |
|
1048 |
break; |
|
1049 |
||
1050 |
case __MASKSMALLINT(SLONGARRAY): |
|
1051 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1052 |
int32 *slp; |
|
1053 |
||
1054 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
1055 |
if (__isSmallInteger(anObject)) { |
|
1056 |
*slp = __intVal(anObject); |
|
1057 |
RETURN ( anObject ); |
|
1058 |
} |
|
1059 |
n = __signedLongIntVal(anObject); |
|
1060 |
/* |
|
1061 |
* zero means failure for an int larger than 4 bytes |
|
1062 |
* (would be a smallInteger) |
|
1063 |
*/ |
|
1064 |
if (n) { |
|
1065 |
*slp = n; |
|
1066 |
RETURN ( anObject ); |
|
1067 |
} |
|
1068 |
} |
|
1069 |
break; |
|
1070 |
||
1071 |
case __MASKSMALLINT(LONGARRAY): |
|
1072 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1073 |
unsigned int32 *lp; |
|
1074 |
||
1075 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
1076 |
if (anObject == __MKSMALLINT(0)) { |
|
1077 |
*lp = 0; |
|
1078 |
RETURN ( anObject ); |
|
1079 |
} |
|
1080 |
u = __longIntVal(anObject); |
|
1081 |
/* |
|
1082 |
* zero means failure for an int larger than 4 bytes |
|
1083 |
* (would be a smallInteger) |
|
1084 |
*/ |
|
1085 |
if (u) { |
|
1086 |
*lp = u; |
|
1087 |
RETURN ( anObject ); |
|
1088 |
} |
|
1089 |
} |
|
1090 |
break; |
|
1091 |
||
1092 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
1093 |
#ifdef __NEED_LONGLONG_ALIGN |
|
1094 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
|
1095 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1096 |
||
1097 |
pFirst += delta; |
|
1098 |
nbytes -= delta; |
|
1099 |
} |
|
1100 |
#endif |
|
1101 |
if ((unsigned)indx < (nbytes>>3)) { |
|
1102 |
__int64__ ll; |
|
1103 |
__int64__ *sllp; |
|
1104 |
||
1105 |
sllp = (__int64__ *)(pFirst + (indx<<3)); |
|
1106 |
||
1107 |
if (anObject == __MKSMALLINT(0)) { |
|
1108 |
ll.lo = ll.hi = 0; |
|
1109 |
*sllp = ll; |
|
1110 |
RETURN ( anObject ); |
|
1111 |
} |
|
1112 |
if (__signedLong64IntVal(anObject, &ll)) { |
|
1113 |
*sllp = ll; |
|
1114 |
RETURN ( anObject ); |
|
1115 |
} |
|
1116 |
} |
|
1117 |
break; |
|
1118 |
||
1119 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1120 |
#ifdef __NEED_LONGLONG_ALIGN |
|
1121 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
|
1122 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1123 |
||
1124 |
pFirst += delta; |
|
1125 |
nbytes -= delta; |
|
1126 |
} |
|
1127 |
#endif |
|
1128 |
if ((unsigned)indx < (nbytes>>3)) { |
|
1129 |
__uint64__ ll; |
|
1130 |
__uint64__ *llp; |
|
1131 |
||
1132 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
1133 |
if (anObject == __MKSMALLINT(0)) { |
|
1134 |
ll.lo = ll.hi = 0; |
|
1135 |
*llp = ll; |
|
1136 |
RETURN ( anObject ); |
|
1137 |
} |
|
1138 |
if (__unsignedLong64IntVal(anObject, &ll)) { |
|
1139 |
*llp = ll; |
|
1140 |
RETURN ( anObject ); |
|
1141 |
} |
|
1142 |
} |
|
1143 |
break; |
|
1144 |
} |
|
1145 |
} |
|
1146 |
||
1147 |
# undef int32 |
|
1148 |
||
1149 |
%}. |
|
1150 |
index isInteger ifFalse:[ |
|
1151 |
" |
|
1152 |
the index should be an integer number |
|
1153 |
" |
|
1154 |
^ self indexNotInteger |
|
1155 |
]. |
|
1156 |
(index between:1 and:self size) ifFalse:[ |
|
1157 |
" |
|
1158 |
the index is less than 1 or greater than the size of the |
|
1159 |
receiver collection |
|
1160 |
" |
|
1161 |
^ self subscriptBoundsError:index |
|
1162 |
]. |
|
1163 |
(self class isFloatsOrDoubles) ifTrue:[ |
|
1164 |
anObject isNumber ifTrue:[ |
|
1165 |
^ self basicAt:index put:(anObject asFloat) |
|
1166 |
] |
|
1167 |
]. |
|
1168 |
anObject isInteger ifFalse:[ |
|
1169 |
" |
|
1170 |
the object to put into the receiver collection |
|
1171 |
should be an integer number |
|
1172 |
" |
|
1173 |
^ self elementNotInteger |
|
1174 |
]. |
|
1175 |
" |
|
1176 |
the object to put into the receiver collection |
|
1177 |
is not an instance of the expected element class, |
|
1178 |
or the value is not within the elements valid range. |
|
1179 |
" |
|
1180 |
^ self elementBoundsError |
|
1181 |
||
1182 |
"Modified: 19.4.1996 / 11:14:10 / cg" |
|
1183 |
! |
|
1184 |
||
1185 |
byteAt:index |
|
1186 |
"return the byte at index. |
|
1187 |
This is only allowed for non-pointer indexed objects |
|
1188 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
1189 |
The receivers indexed instvars are treated as an uninterpreted |
|
1190 |
collection of bytes. |
|
1191 |
Only useful with binary storage." |
|
1192 |
||
1193 |
%{ /* NOCONTEXT */ |
|
1194 |
||
1195 |
REGISTER int indx; |
|
1196 |
int nIndex; |
|
1197 |
REGISTER OBJ slf; |
|
1198 |
REGISTER OBJ cls; |
|
1199 |
||
1200 |
if (__isSmallInteger(index)) { |
|
1201 |
slf = self; |
|
1202 |
if (__isNonNilObject(slf)) { |
|
1203 |
unsigned char *pFirst; |
|
1204 |
int nIndex; |
|
1205 |
||
1206 |
cls = __qClass(slf); |
|
1207 |
||
1208 |
pFirst = __ByteArrayInstPtr(slf)->ba_element; |
|
1209 |
pFirst += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1210 |
nIndex = __byteArraySize(slf); |
|
1211 |
indx = __intVal(index) - 1; |
|
1212 |
||
1213 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1214 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
1215 |
#ifdef __NEED_DOUBLE_ALIGN |
|
1216 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
|
1217 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1218 |
||
1219 |
pFirst += delta; |
|
1220 |
nIndex -= delta; |
|
1221 |
} |
|
1222 |
#endif |
|
1223 |
/* fall into */ |
|
1224 |
case __MASKSMALLINT(BYTEARRAY): |
|
1225 |
case __MASKSMALLINT(WORDARRAY): |
|
1226 |
case __MASKSMALLINT(LONGARRAY): |
|
1227 |
case __MASKSMALLINT(SWORDARRAY): |
|
1228 |
case __MASKSMALLINT(SLONGARRAY): |
|
1229 |
case __MASKSMALLINT(FLOATARRAY): |
|
1230 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
1231 |
RETURN ( __MKSMALLINT( (INT)(pFirst[indx])) ); |
5755 | 1232 |
} |
1233 |
break; |
|
1234 |
||
1235 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1236 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
1237 |
#ifdef __NEED_LONGLONG_ALIGN |
|
1238 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
|
1239 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1240 |
||
1241 |
pFirst += delta; |
|
1242 |
nIndex -= delta; |
|
1243 |
} |
|
1244 |
#endif |
|
1245 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
1246 |
RETURN ( __MKSMALLINT( (INT)(pFirst[indx])) ); |
5755 | 1247 |
} |
1248 |
break; |
|
1249 |
} |
|
1250 |
} |
|
1251 |
} |
|
1252 |
%}. |
|
1253 |
"/ index not integer or index out of range |
|
1254 |
"/ or non-byte indexable receiver |
|
1255 |
||
1256 |
^ self primitiveFailed |
|
1257 |
||
1258 |
" |
|
1259 |
Point new byteAt:1 |
|
1260 |
(ByteArray with:1 with:2) byteAt:2 |
|
1261 |
(WordArray with:1) byteAt:1 |
|
1262 |
(FloatArray with:1.0) byteAt:2 |
|
1263 |
'hello' byteAt:1 |
|
1264 |
" |
|
1265 |
! |
|
1266 |
||
1267 |
byteAt:index put:byteValue |
|
1268 |
"set the byte at index. |
|
1269 |
This is only allowed for non-pointer indexed objects |
|
1270 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
1271 |
The receivers indexed instvars are treated as an uninterpreted |
|
1272 |
collection of bytes. |
|
1273 |
Only useful with binary storage." |
|
1274 |
||
1275 |
%{ /* NOCONTEXT */ |
|
1276 |
||
1277 |
REGISTER int indx; |
|
1278 |
int val, nIndex; |
|
1279 |
REGISTER OBJ slf; |
|
1280 |
REGISTER OBJ cls; |
|
1281 |
||
1282 |
if (__bothSmallInteger(index, byteValue)) { |
|
1283 |
val = __intVal(byteValue); |
|
1284 |
if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) { |
|
1285 |
slf = self; |
|
1286 |
if (__isNonNilObject(slf)) { |
|
1287 |
cls = __qClass(slf); |
|
1288 |
||
1289 |
indx = __intVal(index) - 1; |
|
1290 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1291 |
case __MASKSMALLINT(BYTEARRAY): |
|
1292 |
case __MASKSMALLINT(WORDARRAY): |
|
1293 |
case __MASKSMALLINT(LONGARRAY): |
|
1294 |
case __MASKSMALLINT(SWORDARRAY): |
|
1295 |
case __MASKSMALLINT(SLONGARRAY): |
|
1296 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1297 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
1298 |
case __MASKSMALLINT(FLOATARRAY): |
|
1299 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
1300 |
indx += __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1301 |
nIndex = __byteArraySize(slf); |
|
1302 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1303 |
__ByteArrayInstPtr(slf)->ba_element[indx] = val; |
|
1304 |
RETURN ( byteValue ); |
|
1305 |
} |
|
1306 |
break; |
|
1307 |
} |
|
1308 |
} |
|
1309 |
} |
|
1310 |
} |
|
1311 |
%}. |
|
1312 |
"/ index not integer or index out of range |
|
1313 |
"/ or non-byte indexable receiver |
|
1314 |
||
1315 |
^ self primitiveFailed |
|
1316 |
||
1317 |
" |
|
1318 |
(ByteArray with:1 with:2) byteAt:2 put:3; yourself |
|
1319 |
'hello' copy byteAt:1 put:105; yourself |
|
1320 |
" |
|
1321 |
! |
|
1322 |
||
1323 |
instVarAt:index |
|
1324 |
"return a non-indexed instance variable; |
|
1325 |
peeking into an object this way is not very object oriented |
|
1326 |
- use with care (needed for copy, inspector etc.)" |
|
1327 |
||
1328 |
%{ /* NOCONTEXT */ |
|
1329 |
||
1330 |
OBJ myClass; |
|
1331 |
int idx, ninstvars; |
|
1332 |
||
1333 |
if (__isSmallInteger(index)) { |
|
1334 |
myClass = __Class(self); |
|
1335 |
idx = __intVal(index) - 1; |
|
1336 |
/* |
|
1337 |
* do not allow returning of non-object fields. |
|
1338 |
* if subclass did not make privisions for that, |
|
1339 |
* we wont do so here ... |
|
1340 |
*/ |
|
1341 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1342 |
if (idx == 0) { |
|
1343 |
RETURN ( nil ) |
|
1344 |
} |
|
1345 |
} |
|
1346 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1347 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1348 |
RETURN ( __InstPtr(self)->i_instvars[idx] ); |
|
1349 |
} |
|
1350 |
} |
|
1351 |
%} |
|
1352 |
. |
|
1353 |
index isInteger ifFalse:[ |
|
1354 |
^ self indexNotInteger |
|
1355 |
]. |
|
1356 |
^ self subscriptBoundsError:index |
|
1357 |
! |
|
1358 |
||
1359 |
instVarAt:index put:value |
|
1360 |
"change a non-indexed instance variable; |
|
1361 |
peeking into an object this way is not very object oriented |
|
1362 |
- use with care (needed for copy, inspector etc.)" |
|
1363 |
||
1364 |
%{ /* NOCONTEXT */ |
|
1365 |
||
1366 |
OBJ myClass; |
|
1367 |
int idx, ninstvars; |
|
1368 |
||
1369 |
if (__isSmallInteger(index)) { |
|
1370 |
myClass = __Class(self); |
|
1371 |
idx = __intVal(index) - 1; |
|
1372 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1373 |
/* |
|
1374 |
* do not allow setting of non-object fields. |
|
1375 |
* if subclass did not make privisions for that, |
|
1376 |
* we wont do so here ... |
|
1377 |
*/ |
|
1378 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1379 |
if (idx == 0) { |
|
1380 |
RETURN ( nil ) |
|
1381 |
} |
|
1382 |
} |
|
1383 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1384 |
__InstPtr(self)->i_instvars[idx] = value; |
|
1385 |
__STORE(self, value); |
|
1386 |
RETURN ( value ); |
|
1387 |
} |
|
1388 |
} |
|
1389 |
%} |
|
1390 |
. |
|
1391 |
index isInteger ifFalse:[ |
|
1392 |
^ self indexNotInteger |
|
1393 |
]. |
|
1394 |
^ self subscriptBoundsError:index |
|
1395 |
! |
|
1396 |
||
1397 |
instVarNamed:name |
|
1398 |
"return a non-indexed instance variables value by name; |
|
1399 |
peeking into an object this way is not very object oriented |
|
1400 |
- use with care if at all (provided for inspectors and memory usage monitor). |
|
1401 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1402 |
parsed ad runtime)" |
|
1403 |
||
1404 |
^ self instVarAt:(self class instVarOffsetOf:name) |
|
1405 |
||
1406 |
||
1407 |
" |
|
1408 |
|p| |
|
1409 |
||
1410 |
p := Point x:10 y:20. |
|
1411 |
p instVarNamed:'x' |
|
1412 |
" |
|
1413 |
||
1414 |
"Modified: 19.4.1996 / 11:12:39 / cg" |
|
1415 |
! |
|
1416 |
||
1417 |
instVarNamed:name ifAbsent:exceptionBlock |
|
1418 |
"return a non-indexed instance variables value by name, |
|
1419 |
or the value of exceptionBlock, if there is no such instance variable. |
|
1420 |
peeking into an object this way is not very object oriented |
|
1421 |
- use with care if at all (provided for inspectors and memory usage monitor). |
|
1422 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1423 |
parsed ad runtime)" |
|
1424 |
||
1425 |
|idx| |
|
1426 |
||
1427 |
idx := self class instVarOffsetOf:name. |
|
1428 |
idx isNil ifTrue:[^ exceptionBlock value]. |
|
1429 |
^ self instVarAt:idx |
|
1430 |
||
1431 |
||
1432 |
" |
|
1433 |
|p| |
|
1434 |
||
1435 |
p := Point x:10 y:20. |
|
1436 |
p instVarNamed:'x' |
|
1437 |
" |
|
1438 |
||
1439 |
"Created: 6.7.1996 / 23:02:49 / cg" |
|
1440 |
"Modified: 6.7.1996 / 23:03:41 / cg" |
|
1441 |
! |
|
1442 |
||
1443 |
instVarNamed:name put:value |
|
1444 |
"set a non-indexed instance variable by name; |
|
1445 |
peeking into an object this way is not very object oriented |
|
1446 |
- if at all, use with care (provided for protocol completeness). |
|
1447 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1448 |
parsed ad runtime)" |
|
1449 |
||
1450 |
^ self instVarAt:(self class instVarOffsetOf:name) put:value |
|
1451 |
||
1452 |
" |
|
1453 |
|p| |
|
1454 |
||
1455 |
p := Point x:10 y:20. |
|
1456 |
p instVarNamed:'x' put:30. |
|
1457 |
p |
|
1458 |
" |
|
1459 |
||
1460 |
"Modified: 19.4.1996 / 11:12:49 / cg" |
|
1461 |
! ! |
|
1462 |
||
1463 |
!Object methodsFor:'attributes access'! |
|
1464 |
||
1465 |
objectAttributeAt:key |
|
1466 |
"return the attribute for a given key or nil if not found" |
|
1467 |
||
1468 |
| attrs | |
|
1469 |
||
1470 |
attrs := self objectAttributes. |
|
1471 |
(attrs notNil and:[attrs size > 0]) ifTrue:[ |
|
1472 |
^ attrs at:key ifAbsent:[] |
|
1473 |
]. |
|
1474 |
^ nil |
|
1475 |
||
1476 |
"Created: / 22.1.1998 / 21:29:17 / av" |
|
1477 |
"Modified: / 3.2.1998 / 18:55:55 / cg" |
|
1478 |
! |
|
1479 |
||
1480 |
objectAttributeAt:key put:anObject |
|
1481 |
"store the attribute anObject referenced by key into the receiver" |
|
1482 |
||
1483 |
|wasBlocked| |
|
1484 |
||
1485 |
"/ must do this save from interrupts, since the attributes collection |
|
1486 |
"/ is possibly accessed from multiple threads ... |
|
1487 |
||
1488 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1489 |
[ |
|
1490 |
| attrs | |
|
1491 |
||
1492 |
attrs := self objectAttributes. |
|
1493 |
(attrs isNil or:[attrs size == 0]) ifTrue:[ |
|
1494 |
attrs := WeakIdentityDictionary new. |
|
1495 |
attrs at:key put:anObject. |
|
1496 |
self objectAttributes:attrs. |
|
1497 |
] ifFalse:[ |
|
1498 |
attrs at:key put:anObject. |
|
1499 |
]. |
|
1500 |
] valueNowOrOnUnwindDo:[ |
|
1501 |
wasBlocked ifFalse:[ |
|
1502 |
OperatingSystem unblockInterrupts |
|
1503 |
] |
|
1504 |
] |
|
1505 |
||
1506 |
"Attaching additional attributes (slots) to an arbitrary object: |
|
1507 |
||
1508 |
|p| |
|
1509 |
||
1510 |
p := Point new. |
|
1511 |
p objectAttributeAt:#color put:#green. |
|
1512 |
||
1513 |
p objectAttributeAt:#color |
|
1514 |
" |
|
1515 |
||
1516 |
"Created: / 22.1.1998 / 21:29:25 / av" |
|
1517 |
"Modified: / 3.2.1998 / 18:57:58 / cg" |
|
1518 |
! |
|
1519 |
||
1520 |
objectAttributes |
|
1521 |
"return a Collection of attributes - nil if there is none. |
|
1522 |
The default implementation here uses a global WeakDictionary to store |
|
1523 |
attributes |
|
1524 |
This may be too slow for high frequency slot access, |
|
1525 |
therefore, some classes may redefine this for better performance. |
|
1526 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
|
1527 |
||
1528 |
^ ObjectAttributes at:self ifAbsent:[nil] |
|
1529 |
||
1530 |
"Created: / 22.1.1998 / 21:29:30 / av" |
|
1531 |
"Modified: / 18.2.2000 / 11:34:16 / cg" |
|
1532 |
! |
|
1533 |
||
1534 |
objectAttributes:aCollection |
|
1535 |
"set the collection of attributes. |
|
1536 |
The default implementation here uses a global Dictionary to store |
|
1537 |
attributes which may be too slow for high frequency change&update. |
|
1538 |
Therefore, some classes may redefine this for better performance." |
|
1539 |
||
1540 |
"/ must do this save from interrupts, since the attributes collection |
|
1541 |
"/ is possibly accessed from multiple threads. |
|
1542 |
||
1543 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
1544 |
"/ the common case - already blocked |
|
1545 |
||
1546 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
1547 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1548 |
] ifFalse:[ |
|
1549 |
ObjectAttributes at:self put:aCollection |
|
1550 |
]. |
|
1551 |
^ self |
|
1552 |
]. |
|
1553 |
||
1554 |
[ |
|
1555 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
1556 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1557 |
] ifFalse:[ |
|
1558 |
ObjectAttributes at:self put:aCollection |
|
1559 |
]. |
|
1560 |
] valueNowOrOnUnwindDo:[ |
|
1561 |
OperatingSystem unblockInterrupts |
|
1562 |
] |
|
1563 |
||
1564 |
"Created: / 22.1.1998 / 21:29:35 / av" |
|
1565 |
"Modified: / 3.2.1998 / 18:58:10 / cg" |
|
1566 |
! |
|
1567 |
||
1568 |
removeObjectAttribute:anObject |
|
1569 |
"make the argument, anObject be no attribute of the receiver" |
|
1570 |
||
1571 |
|wasBlocked| |
|
1572 |
||
1573 |
"/ must do this save from interrupts, since the attributes collection |
|
1574 |
"/ is possibly accessed from multiple threads. |
|
1575 |
||
1576 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1577 |
[ |
|
1578 |
|attrs n a| |
|
1579 |
||
1580 |
attrs := self objectAttributes. |
|
1581 |
attrs size == 0 ifTrue:[ |
|
1582 |
self objectAttributes:nil |
|
1583 |
] ifFalse:[ |
|
1584 |
attrs removeKey:anObject ifAbsent:nil. |
|
1585 |
attrs size == 0 ifTrue:[ |
|
1586 |
self objectAttributes:nil |
|
1587 |
] |
|
1588 |
] |
|
1589 |
] valueNowOrOnUnwindDo:[ |
|
1590 |
wasBlocked ifFalse:[ |
|
1591 |
OperatingSystem unblockInterrupts |
|
1592 |
] |
|
1593 |
] |
|
1594 |
||
1595 |
"Created: / 22.1.1998 / 21:29:39 / av" |
|
1596 |
"Modified: / 18.2.2000 / 11:32:19 / cg" |
|
1597 |
! ! |
|
1598 |
||
1599 |
!Object methodsFor:'binary storage'! |
|
1600 |
||
1601 |
hasSpecialBinaryRepresentation |
|
1602 |
"return true, if the receiver has a special binary representation; |
|
1603 |
default here is false, but can be redefined in class which provide |
|
1604 |
their own storeBinary/readBinary methods. |
|
1605 |
||
1606 |
Normal user classes should not use this, it is meant as a hook for |
|
1607 |
special classes such as True, False, UndefinedObject or SmallInteger. |
|
1608 |
||
1609 |
If your instances should be stored in a special way, see |
|
1610 |
#representBinaryOn: and #readBinaryContentsFromdata:manager:." |
|
1611 |
||
1612 |
^ false |
|
1613 |
! |
|
1614 |
||
1615 |
readBinaryContentsFrom:stream manager:manager |
|
1616 |
"reconstruct the receivers instance variables by reading a binary |
|
1617 |
binary representation from stream. |
|
1618 |
This is a general implementation, walking over instances |
|
1619 |
and loading each recursively using manager. |
|
1620 |
Redefined by some classes to read a more compact representations |
|
1621 |
(see String, SmallInteger etc). |
|
1622 |
||
1623 |
Notice, that the object is already recreated as an empty corps |
|
1624 |
with instance variables all nil and bit-instances (bytes, words etc.) |
|
1625 |
already read and restored. |
|
1626 |
||
1627 |
Also notice: this method is not called for if a private representation |
|
1628 |
has been stored (see representBinaryOn:). |
|
1629 |
In that case, #readBinaryContentsFromData:manager: is called, which |
|
1630 |
has to be reimplemented in the objects class." |
|
1631 |
||
1632 |
|size "{ Class: SmallInteger }" |
|
1633 |
instvarArray| |
|
1634 |
||
1635 |
stream next == 1 ifTrue:[ |
|
1636 |
"/ |
|
1637 |
"/ special representation ... |
|
1638 |
"/ |
|
1639 |
instvarArray := Array new:(size := stream nextNumber:3). |
|
1640 |
1 to:size do:[:i | |
|
1641 |
instvarArray basicAt:i put:(manager nextObject) |
|
1642 |
]. |
|
1643 |
self readBinaryContentsFromData:instvarArray manager:manager. |
|
1644 |
^ self |
|
1645 |
]. |
|
1646 |
||
1647 |
"/ |
|
1648 |
"/ standard representation |
|
1649 |
"/ |
|
1650 |
size := self basicSize. |
|
1651 |
size ~~ 0 ifTrue:[ |
|
1652 |
self class isPointers ifTrue:[ |
|
1653 |
1 to:size do:[:i | |
|
1654 |
self basicAt:i put:(manager nextObject) |
|
1655 |
] |
|
1656 |
] |
|
1657 |
]. |
|
1658 |
size := self class instSize. |
|
1659 |
1 to:size do:[:i | |
|
1660 |
self instVarAt:i put:(manager nextObject) |
|
1661 |
]. |
|
1662 |
! |
|
1663 |
||
1664 |
readBinaryContentsFromData:instvarArray manager:manager |
|
1665 |
"reconstruct the receivers instance variables by filling instance |
|
1666 |
variables with values from instvarArray. This array contains the instvars |
|
1667 |
as specified in #representBinaryOn: when the object was stored. |
|
1668 |
It is the receivers responsibility to set its instance variables in the |
|
1669 |
same order from that array." |
|
1670 |
||
1671 |
^ self subclassResponsibility |
|
1672 |
||
1673 |
"typical implementation (see also comment in #representBinaryOn:) |
|
1674 |
(for an object with foo, bar and baz as instance variables, |
|
1675 |
which did not store baz and wants baz to be reinitialized to |
|
1676 |
some constant string) |
|
1677 |
||
1678 |
foo := instvarArray at:1. |
|
1679 |
bar := instvarArray at:2. |
|
1680 |
baz := 'aConstant'. |
|
1681 |
" |
|
1682 |
! |
|
1683 |
||
1684 |
representBinaryOn:manager |
|
1685 |
"this method is called by the storage manager to ask objects |
|
1686 |
if they wish to provide their own binary representation. |
|
1687 |
||
1688 |
If they want to do so, they should return an array containing all |
|
1689 |
instance variables (named & indexed pointer) to be stored. |
|
1690 |
If not redefined, this method returns nil which means that all |
|
1691 |
instance variables are to be stored. |
|
1692 |
||
1693 |
It should be redefined in objects which do not want all instance variables |
|
1694 |
to be stored (for example: objects which keep references to a view etc.). |
|
1695 |
||
1696 |
If this is redefined returning non-nil, the corresponding class needs |
|
1697 |
a redefined instance method named #readBinaryContentsFromData:manager: |
|
1698 |
which has to fill the receivers named (and optionally indexed pointer) |
|
1699 |
instance variables with corresponding values from a data array." |
|
1700 |
||
1701 |
^ nil |
|
1702 |
||
1703 |
"typical implementation: |
|
1704 |
(see also comment in #readBinaryContentsFromData:manager:) |
|
1705 |
for an object with foo, bar and baz as instance variables, |
|
1706 |
which does not want to store baz: |
|
1707 |
||
1708 |
representBinaryOn:manager |
|
1709 |
|data| |
|
1710 |
||
1711 |
data := Array new:2. |
|
1712 |
data at:1 put:foo. |
|
1713 |
data at:2 put:bar. |
|
1714 |
^ data |
|
1715 |
" |
|
1716 |
! |
|
1717 |
||
1718 |
storeBinaryDefinitionBodyOn:stream manager:manager |
|
1719 |
"append a binary representation of the receivers body onto stream. |
|
1720 |
This is a general implementation walking over instances storing |
|
1721 |
each recursively as an ID using manager. |
|
1722 |
Can be redefined in subclasses." |
|
1723 |
||
1724 |
|basicSize "{ Class: SmallInteger }" |
|
1725 |
instSize "{ Class: SmallInteger }" |
|
1726 |
specialSize "{ Class: SmallInteger }" |
|
1727 |
myClass specialRep pointers| |
|
1728 |
||
1729 |
myClass := self class. |
|
1730 |
instSize := myClass instSize. |
|
1731 |
||
1732 |
(pointers := myClass isPointers) ifTrue:[ |
|
1733 |
"/ |
|
1734 |
"/ inst size not needed - if you uncomment the line below, |
|
1735 |
"/ also uncomment the corresponding line in |
|
1736 |
"/ Object>>binaryDefinitionFrom:manager: |
|
1737 |
"/ |
|
1738 |
"/ stream nextPut:instSize. "mhmh this limits us to 255 named instvars" |
|
1739 |
||
1740 |
myClass isVariable ifTrue:[ |
|
1741 |
stream nextNumber:3 put:(basicSize := self basicSize) |
|
1742 |
] ifFalse:[ |
|
1743 |
basicSize := 0 |
|
1744 |
]. |
|
1745 |
] ifFalse: [ |
|
1746 |
stream nextNumber:4 put:(basicSize := self basicSize). |
|
1747 |
myClass isBytes ifTrue:[ |
|
1748 |
1 to:basicSize do:[:i | |
|
1749 |
stream nextPut:(self basicAt:i) |
|
1750 |
] |
|
1751 |
] ifFalse:[ |
|
1752 |
myClass isWords ifTrue:[ |
|
1753 |
1 to:basicSize do:[:i | |
|
1754 |
stream nextNumber:2 put:(self basicAt: i) |
|
1755 |
] |
|
1756 |
] ifFalse:[ |
|
1757 |
myClass isLongs ifTrue:[ |
|
1758 |
1 to:basicSize do:[:i | |
|
1759 |
stream nextNumber:4 put:(self basicAt: i) |
|
1760 |
] |
|
1761 |
] ifFalse:[ |
|
1762 |
myClass isFloats ifTrue:[ |
|
1763 |
"could do it in one big write on machines which use IEEE floats ..." |
|
1764 |
1 to:basicSize do:[:i | |
|
1765 |
Float storeBinaryIEEESingle:(self basicAt:i) on:stream |
|
1766 |
] |
|
1767 |
] ifFalse:[ |
|
1768 |
myClass isDoubles ifTrue:[ |
|
1769 |
"could do it in one big write on machines which use IEEE doubles ..." |
|
1770 |
1 to:basicSize do:[:i | |
|
1771 |
Float storeBinaryIEEEDouble:(self basicAt:i) on:stream |
|
1772 |
] |
|
1773 |
] ifFalse:[ |
|
1774 |
"/ should never be reached ... |
|
1775 |
1 to:basicSize do:[:i | |
|
1776 |
manager putIdOf:(self basicAt:i) on:stream |
|
1777 |
] |
|
1778 |
] |
|
1779 |
] |
|
1780 |
] |
|
1781 |
] |
|
1782 |
]. |
|
1783 |
]. |
|
1784 |
||
1785 |
(pointers or:[instSize ~~ 0]) ifTrue:[ |
|
1786 |
specialRep := self representBinaryOn:manager. |
|
1787 |
specialRep notNil ifTrue:[ |
|
1788 |
specialSize := specialRep basicSize. |
|
1789 |
stream nextPut:1. "/ means: private representation follows |
|
1790 |
stream nextNumber:3 put:specialSize. |
|
1791 |
||
1792 |
1 to:specialSize do:[:i | |
|
1793 |
manager putIdOf:(specialRep at:i) on:stream |
|
1794 |
]. |
|
1795 |
] ifFalse:[ |
|
1796 |
stream nextPut:0. "/ means: normal representation follows |
|
1797 |
"/ index pointers followed by named instanceVars |
|
1798 |
pointers ifTrue:[ |
|
1799 |
basicSize ~~ 0 ifTrue:[ |
|
1800 |
1 to:basicSize do:[:i | |
|
1801 |
manager putIdOf:(self basicAt:i) on:stream |
|
1802 |
]. |
|
1803 |
]. |
|
1804 |
]. |
|
1805 |
instSize ~~ 0 ifTrue:[ |
|
1806 |
1 to:instSize do:[:i | |
|
1807 |
manager putIdOf:(self instVarAt:i) on:stream |
|
1808 |
] |
|
1809 |
]. |
|
1810 |
] |
|
1811 |
] |
|
1812 |
||
1813 |
"Modified: / 2.11.1997 / 14:43:29 / cg" |
|
1814 |
! |
|
1815 |
||
1816 |
storeBinaryDefinitionOn:stream manager:manager |
|
1817 |
"append a binary representation of the receiver onto stream. |
|
1818 |
This is an internal interface for binary storage mechanism. |
|
1819 |
This method first stores the class, then the body, which is done |
|
1820 |
in a separate method to allow redefinition of the bodies format. |
|
1821 |
Can be redefined in subclasses to write more compact representations |
|
1822 |
(see String, SmallInteger etc)." |
|
1823 |
||
1824 |
manager putIdOfClass:(self class) on:stream. |
|
1825 |
self storeBinaryDefinitionBodyOn:stream manager:manager |
|
1826 |
||
1827 |
"Modified: 23.4.1996 / 09:31:12 / cg" |
|
1828 |
! |
|
1829 |
||
1830 |
storeBinaryOn:aStreamOrFilename |
|
1831 |
"Writes a description of the receiver onto aStreamOrFilename, in a way that allows |
|
1832 |
the object's structure to be reconstructed from the stream's contents" |
|
1833 |
||
1834 |
BinaryOutputManager store:self on:aStreamOrFilename |
|
1835 |
||
1836 |
" |
|
1837 |
|a s1 s2| |
|
1838 |
||
1839 |
s1 := 'hello'. |
|
1840 |
s2 := 'world'. |
|
1841 |
a := Array new:5. |
|
1842 |
a at:1 put:s1. |
|
1843 |
a at:2 put:s2. |
|
1844 |
a at:3 put:s1. |
|
1845 |
a at:4 put:s2. |
|
1846 |
a storeBinaryOn:'test.boss' |
|
1847 |
" |
|
1848 |
||
1849 |
" |
|
1850 |
(BinaryObjectStorage onOld:'test.boss' asFilename readStream) |
|
1851 |
next |
|
1852 |
inspect |
|
1853 |
" |
|
1854 |
||
1855 |
"Modified: / 1.11.1997 / 21:16:24 / cg" |
|
1856 |
! |
|
1857 |
||
1858 |
storeBinaryOn:stream manager:manager |
|
1859 |
"append a binary representation of the receiver onto stream." |
|
1860 |
||
1861 |
manager putIdOf:self on:stream |
|
1862 |
! ! |
|
1863 |
||
1864 |
!Object methodsFor:'change & update'! |
|
1865 |
||
1866 |
broadcast:aSelectorSymbol |
|
1867 |
"send a message with selector aSelectorSymbol to all my dependents" |
|
1868 |
||
1869 |
self dependentsDo:[:dependent | |
|
1870 |
dependent perform:aSelectorSymbol |
|
1871 |
] |
|
1872 |
! |
|
1873 |
||
1874 |
broadcast:aSelectorSymbol with:anArgument |
|
1875 |
"send a message with selector aSelectorSymbol with an additional |
|
1876 |
argument anArgument to all my dependents." |
|
1877 |
||
1878 |
self dependentsDo:[:dependent | |
|
1879 |
dependent perform:aSelectorSymbol with:anArgument |
|
1880 |
] |
|
1881 |
! |
|
1882 |
||
1883 |
changeRequest |
|
1884 |
"the receiver wants to change - check if all dependents |
|
1885 |
grant the request, and return true if so" |
|
1886 |
||
1887 |
self dependentsDo:[:dependent | |
|
1888 |
dependent updateRequest ifFalse:[^ false]. |
|
1889 |
]. |
|
1890 |
^ true |
|
1891 |
! |
|
1892 |
||
1893 |
changeRequest:aParameter |
|
1894 |
"the receiver wants to change - check if all dependents |
|
1895 |
grant the request, and return true if so" |
|
1896 |
||
1897 |
self dependentsDo:[:dependent | |
|
1898 |
(dependent updateRequest:aParameter) ifFalse:[^ false]. |
|
1899 |
]. |
|
1900 |
^ true |
|
1901 |
! |
|
1902 |
||
1903 |
changeRequest:aParameter from:anObject |
|
1904 |
"the receiver wants to change - check if all dependents |
|
1905 |
except anObject grant the request, and return true if so. |
|
1906 |
The argument anObject is typically going to be the one who is |
|
1907 |
about to send the change request." |
|
1908 |
||
1909 |
self dependentsDo:[:dependent | |
|
1910 |
dependent == anObject ifFalse:[ |
|
1911 |
(dependent updateRequest:aParameter) ifFalse:[^ false]. |
|
1912 |
] |
|
1913 |
]. |
|
1914 |
^ true |
|
1915 |
! |
|
1916 |
||
1917 |
changeRequestFrom:anObject |
|
1918 |
"the receiver wants to change - check if all dependents |
|
1919 |
except anObject grant the request, and return true if so. |
|
1920 |
The argument anObject is typically going to be the one who is |
|
1921 |
about to send the change request." |
|
1922 |
||
1923 |
self dependentsDo:[:dependent | |
|
1924 |
dependent == anObject ifFalse:[ |
|
1925 |
(dependent updateRequest) ifFalse:[^ false]. |
|
1926 |
] |
|
1927 |
]. |
|
1928 |
^ true |
|
1929 |
! |
|
1930 |
||
1931 |
changed |
|
1932 |
"notify all dependents that the receiver has changed. |
|
1933 |
Each dependent gets a '#update:'-message with the original |
|
1934 |
receiver as argument." |
|
1935 |
||
1936 |
self changed:nil |
|
1937 |
! |
|
1938 |
||
1939 |
changed:aParameter |
|
1940 |
"notify all dependents that the receiver has changed somehow. |
|
1941 |
Each dependent gets a '#update:'-message with aParameter |
|
1942 |
as argument." |
|
1943 |
||
1944 |
self changed:aParameter with:nil |
|
1945 |
! |
|
1946 |
||
1947 |
changed:aParameter with:anArgument |
|
1948 |
"notify all dependents that the receiver has changed somehow. |
|
1949 |
Each dependent gets a '#update:with:from:'-message, with aParameter |
|
1950 |
and anArgument as arguments." |
|
1951 |
||
1952 |
self dependentsDo:[:dependent | |
|
1953 |
dependent update:aParameter with:anArgument from:self |
|
1954 |
] |
|
1955 |
! |
|
1956 |
||
1957 |
update:aParameter |
|
1958 |
"the message is sent to a dependent, when one of the objects |
|
1959 |
on whom the receiver depends, has changed. The argument aParameter |
|
1960 |
is either the changed object or the argument to the #changed: message. |
|
1961 |
||
1962 |
Default behavior here is to do nothing" |
|
1963 |
||
1964 |
^ self |
|
1965 |
! |
|
1966 |
||
1967 |
update:aParameter with:anArgument |
|
1968 |
"dependent is notified of some change - |
|
1969 |
Default is to try update:" |
|
1970 |
||
1971 |
^ self update:aParameter |
|
1972 |
! |
|
1973 |
||
1974 |
update:aParameter with:anArgument from:sender |
|
1975 |
"dependent is notified of some change - |
|
1976 |
Default is to try update:with:" |
|
1977 |
||
1978 |
^ self update:aParameter with:anArgument |
|
1979 |
! |
|
1980 |
||
1981 |
updateRequest |
|
1982 |
"return true, if an update request is granted. |
|
1983 |
Default here is to grant updates - may be used |
|
1984 |
to lock updates if someone is making other changes |
|
1985 |
from within an update. Or if someone has locked its |
|
1986 |
state and does not want others to change things. |
|
1987 |
However, these dependents must all honor the |
|
1988 |
changeRequest - ifTrue - change protocol. I.e. they |
|
1989 |
must first ask all others via changeRequest, and only do the change |
|
1990 |
it returns true. The others must decide in updateRequest and |
|
1991 |
return true if they think a change is ok." |
|
1992 |
||
1993 |
^ true |
|
1994 |
! |
|
1995 |
||
1996 |
updateRequest:aSymbol |
|
1997 |
"return true, if an update request is granted. |
|
1998 |
Default here a simple updateRequest" |
|
1999 |
||
2000 |
^ self updateRequest |
|
2001 |
! ! |
|
2002 |
||
2003 |
!Object methodsFor:'cleanup'! |
|
2004 |
||
2005 |
lowSpaceCleanup |
|
2006 |
"ignored here - redefined in some classes to |
|
2007 |
cleanup in low-memory situations" |
|
2008 |
||
2009 |
^ self |
|
2010 |
! ! |
|
2011 |
||
2012 |
!Object methodsFor:'comparing'! |
|
2013 |
||
2014 |
= anObject |
|
2015 |
"return true, if the receiver and the arg have the same structure. |
|
2016 |
Notice: |
|
2017 |
This method is partially open coded (inlined) by the compiler(s) |
|
2018 |
identical objects are always considered equal. |
|
2019 |
redefining it may not work as expected." |
|
2020 |
||
2021 |
^ self == anObject |
|
2022 |
! |
|
2023 |
||
2024 |
== anObject |
|
2025 |
"return true, if the receiver and the arg are the same object. |
|
2026 |
Never redefine this in any class. |
|
2027 |
Notice: |
|
2028 |
This method is open coded (inlined) by the compiler(s) |
|
2029 |
- redefining it may not work as expected." |
|
2030 |
||
2031 |
%{ /* NOCONTEXT */ |
|
2032 |
||
2033 |
RETURN ( (self == anObject) ? true : false ); |
|
2034 |
%} |
|
2035 |
! |
|
2036 |
||
5814 | 2037 |
deepSameContentsAs:anObject |
2038 |
"return true, if the receiver and the arg have the same contents |
|
2039 |
in both the named instance vars and any indexed instVars. |
|
2040 |
This method descends into referenced objects, where #sameContentsAs: does not descend" |
|
2041 |
||
5821 | 2042 |
|myClass val |
5814 | 2043 |
sz "{ Class: SmallInteger }" | |
2044 |
||
2045 |
myClass := self class. |
|
2046 |
myClass isVariable ifTrue:[ |
|
2047 |
sz := self basicSize. |
|
2048 |
||
2049 |
"compare the indexed variables" |
|
2050 |
1 to:sz do:[:i | |
|
2051 |
val := self basicAt:i. |
|
2052 |
val isLiteral ifTrue:[ |
|
2053 |
val = (anObject basicAt:i) ifFalse:[^ false]. |
|
2054 |
] ifFalse:[ |
|
2055 |
(val deepSameContentsAs:(anObject basicAt:i)) ifFalse:[^ false]. |
|
2056 |
] |
|
2057 |
] |
|
2058 |
]. |
|
2059 |
||
2060 |
"compare the instance variables" |
|
2061 |
sz := myClass instSize. |
|
2062 |
1 to:sz do:[:i | |
|
2063 |
val := self instVarAt:i. |
|
2064 |
val isLiteral ifTrue:[ |
|
2065 |
val = (anObject instVarAt:i) ifFalse:[^ false]. |
|
2066 |
] ifFalse:[ |
|
2067 |
(val deepSameContentsAs:(anObject instVarAt:i)) ifFalse:[^ false]. |
|
2068 |
] |
|
2069 |
]. |
|
2070 |
||
2071 |
^ true |
|
2072 |
||
2073 |
" |
|
2074 |
#(1 2 3 4) deepSameContentsAs:#[1 2 3 4] asArray |
|
2075 |
(1@2) deepSameContentsAs:(1->2) |
|
2076 |
" |
|
2077 |
! |
|
2078 |
||
5755 | 2079 |
hash |
2080 |
"return an Integer useful as a hash key for the receiver. |
|
2081 |
This hash should return same values for objects with same |
|
2082 |
contents (i.e. use this to hash on structure)" |
|
2083 |
||
2084 |
^ self identityHash |
|
2085 |
! |
|
2086 |
||
2087 |
identityHash |
|
2088 |
"return an Integer useful as a hash key for the receiver. |
|
2089 |
This hash should return same values for the same object (i.e. use |
|
2090 |
this to hash on identity of objects). |
|
2091 |
||
2092 |
We cannot use the Objects address (as other smalltalks do) since |
|
2093 |
no object-table exists and the hashval must not change when objects |
|
2094 |
are moved by the collector. Therefore we assign each object a unique |
|
2095 |
Id in the object header itself as its hashed upon. |
|
2096 |
(luckily we have 11 bits spare to do this - unluckily its only 11 bits). |
|
2097 |
Time will show, if 11 bits are enough; if not, another entry in the |
|
2098 |
object header will be needed, adding 4 bytes to every object. Alternatively, |
|
2099 |
hashed-upon objects could add an instvar containing the hash value." |
|
2100 |
||
2101 |
%{ /* NOCONTEXT */ |
|
2102 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2103 |
REGISTER unsigned INT hash; |
5755 | 2104 |
static unsigned nextHash = 0; |
2105 |
||
2106 |
if (__isNonNilObject(self)) { |
|
2107 |
hash = __GET_HASH(self); |
|
2108 |
if (hash == 0) { |
|
2109 |
/* has no hash yet */ |
|
2110 |
||
2111 |
if (++nextHash > __MAX_HASH__) { |
|
2112 |
nextHash = 1; |
|
2113 |
} |
|
2114 |
hash = nextHash; |
|
2115 |
__SET_HASH(self, hash); |
|
2116 |
} |
|
2117 |
||
2118 |
/* |
|
2119 |
* now, we got 11 bits for hashing; |
|
2120 |
* make it as large as possible; since most hashers use the returned |
|
2121 |
* key and take it modulo some prime number, this will allow for |
|
2122 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
2123 |
*/ |
|
2124 |
hash = __MAKE_HASH__(hash); |
|
2125 |
RETURN ( __MKSMALLINT(hash) ); |
|
2126 |
} |
|
2127 |
%}. |
|
2128 |
^ 0 "never reached, since redefined in UndefinedObject and SmallInteger" |
|
2129 |
! |
|
2130 |
||
2131 |
identityHashForBinaryStore |
|
2132 |
"hash which is usable if the object does not change its class |
|
2133 |
and does not #become something else, while the hash is used. |
|
2134 |
This is only used by the binary storage mechanism, during the |
|
2135 |
object writing phase." |
|
2136 |
||
2137 |
%{ /* NOCONTEXT */ |
|
2138 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2139 |
REGISTER unsigned INT hash, hash1, hash2, sz; |
5755 | 2140 |
OBJ o; |
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2141 |
static unsigned INT nextHash = 0; |
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2142 |
static unsigned INT nextClassHash = 0; |
5755 | 2143 |
|
2144 |
if (__isNonNilObject(self)) { |
|
2145 |
/* |
|
2146 |
* my own identityHash |
|
2147 |
*/ |
|
2148 |
hash1 = __GET_HASH(self); |
|
2149 |
if (hash1 == 0) { |
|
2150 |
/* has no hash yet */ |
|
2151 |
||
2152 |
if (++nextHash > __MAX_HASH__) { |
|
2153 |
nextHash = 1; |
|
2154 |
} |
|
2155 |
hash1 = nextHash; |
|
2156 |
__SET_HASH(self, hash1); |
|
2157 |
} |
|
2158 |
/* |
|
2159 |
* my classes identityHash |
|
2160 |
*/ |
|
2161 |
o = __qClass(self); |
|
2162 |
hash2 = __GET_HASH(o); |
|
2163 |
if (hash2 == 0) { |
|
2164 |
/* has no hash yet */ |
|
2165 |
||
2166 |
if (++nextClassHash > __MAX_HASH__) { |
|
2167 |
nextClassHash = 1; |
|
2168 |
} |
|
2169 |
hash2 = nextClassHash; |
|
2170 |
__SET_HASH(o, hash2); |
|
2171 |
} |
|
2172 |
||
2173 |
/* |
|
2174 |
* some bits of my size |
|
2175 |
*/ |
|
2176 |
sz = __qSize(self); |
|
2177 |
||
2178 |
/* |
|
2179 |
* now, we got 11 + 11 + 8 bits for hashing; |
|
2180 |
* make it as large as possible; since most hashers use the returned |
|
2181 |
* key and take it modulo some prime number, this will allow for |
|
2182 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
2183 |
*/ |
|
2184 |
hash = (hash1 << 11) | hash2; /* 22 bits */ |
|
2185 |
hash = (hash << 8) | (sz & 0xFC); /* 30 bits */ |
|
2186 |
||
2187 |
while ((hash & 0x20000000) == 0) { |
|
2188 |
hash <<= 1; |
|
2189 |
} |
|
2190 |
||
2191 |
RETURN ( __MKSMALLINT(hash) ); |
|
2192 |
} |
|
2193 |
%}. |
|
2194 |
"never reached, since UndefinedObject and SmallInteger are not hashed upon in binary storage" |
|
2195 |
^ self identityHash |
|
2196 |
! |
|
2197 |
||
2198 |
isNil |
|
2199 |
"return true, if the receiver is nil. |
|
2200 |
Notice: |
|
2201 |
This method is open coded (inlined) by the compiler(s) |
|
2202 |
- redefining it may not work as expected." |
|
2203 |
||
2204 |
^ false |
|
2205 |
! |
|
2206 |
||
2207 |
notNil |
|
2208 |
"return true, if the receiver is not nil. |
|
2209 |
Notice: |
|
2210 |
This method is open coded (inlined) by the compiler(s) |
|
2211 |
- redefining it may not work as expected." |
|
2212 |
||
2213 |
^ true |
|
2214 |
! |
|
2215 |
||
2216 |
sameContentsAs:anObject |
|
2217 |
"return true, if the receiver and the arg have the same contents |
|
2218 |
in both the named instance vars and any indexed instVars." |
|
2219 |
||
5821 | 2220 |
|myClass |
5755 | 2221 |
sz "{ Class: SmallInteger }" | |
2222 |
||
2223 |
myClass := self class. |
|
2224 |
myClass isVariable ifTrue:[ |
|
2225 |
sz := self basicSize. |
|
2226 |
||
2227 |
"compare the indexed variables" |
|
2228 |
1 to:sz do:[:i | |
|
5814 | 2229 |
(self basicAt:i) == (anObject basicAt:i) ifFalse:[^ false]. |
5755 | 2230 |
] |
2231 |
]. |
|
2232 |
||
2233 |
"compare the instance variables" |
|
2234 |
sz := myClass instSize. |
|
2235 |
1 to:sz do:[:i | |
|
5814 | 2236 |
(self instVarAt:i) == (anObject instVarAt:i) ifFalse:[^ false]. |
5755 | 2237 |
]. |
2238 |
||
2239 |
^ true |
|
2240 |
||
2241 |
" |
|
5814 | 2242 |
#(1 2 3 4) sameContentsAs:#[1 2 3 4] asArray |
2243 |
(1@2) sameContentsAs:(1->2) |
|
5755 | 2244 |
" |
2245 |
||
2246 |
"Created: / 21.4.1998 / 15:56:40 / cg" |
|
2247 |
"Modified: / 21.4.1998 / 15:58:15 / cg" |
|
2248 |
! |
|
2249 |
||
2250 |
~= anObject |
|
2251 |
"return true, if the receiver and the arg do not have the same structure. |
|
2252 |
Notice: |
|
2253 |
This method is partially open coded (inlined) by the compiler(s) |
|
2254 |
identical objects are never considered unequal. |
|
2255 |
redefining it may not work as expected." |
|
2256 |
||
2257 |
^ (self = anObject) not |
|
2258 |
! |
|
2259 |
||
2260 |
~~ anObject |
|
2261 |
"return true, if the receiver and the arg are not the same object. |
|
2262 |
Never redefine this in any class. |
|
2263 |
Notice: |
|
2264 |
This method is open coded (inlined) by the compiler(s) |
|
2265 |
- redefining it may not work as expected." |
|
2266 |
||
2267 |
%{ /* NOCONTEXT */ |
|
2268 |
RETURN ( (self == anObject) ? false : true ); |
|
2269 |
%} |
|
2270 |
! ! |
|
2271 |
||
2272 |
!Object methodsFor:'converting'! |
|
2273 |
||
2274 |
-> anObject |
|
2275 |
"return an association with the receiver as key and |
|
2276 |
the argument as value" |
|
2277 |
||
2278 |
^ Association key:self value:anObject |
|
2279 |
! |
|
2280 |
||
2281 |
asCollection |
|
2282 |
"return myself as a Collection. |
|
2283 |
Redefined in collection to return themself." |
|
2284 |
||
2285 |
^ Array with:self |
|
2286 |
! |
|
2287 |
||
2288 |
asSequenceableCollection |
|
2289 |
"return myself as a SequenceableCollection. |
|
2290 |
Redefined in SequenceableCollection" |
|
2291 |
||
2292 |
^ Array with:self |
|
2293 |
! |
|
2294 |
||
2295 |
asValue |
|
2296 |
"return a valueHolder for for the receiver" |
|
2297 |
||
2298 |
^ ValueHolder with:self |
|
2299 |
! ! |
|
2300 |
||
2301 |
!Object methodsFor:'copying'! |
|
2302 |
||
2303 |
cloneFrom:anObject |
|
2304 |
"Helper for copy: |
|
2305 |
copy all instance variables from anObject into the receiver, |
|
2306 |
which should be of the same class as the argument." |
|
2307 |
||
2308 |
self cloneFrom:anObject performing:#yourself |
|
2309 |
||
2310 |
" |
|
2311 |
|x| |
|
2312 |
||
2313 |
x := Array new:3. |
|
2314 |
x cloneFrom:#(1 2 3). |
|
2315 |
" |
|
2316 |
! |
|
2317 |
||
2318 |
cloneFrom:anObject performing:aSymbol |
|
2319 |
"Helper for copy: |
|
2320 |
for each instance variables from anObject, send it aSymbol |
|
2321 |
and store the result into the receiver, |
|
2322 |
which should be of the same class as the argument." |
|
2323 |
||
2324 |
|myClass sz "{ Class: SmallInteger }" t | |
|
2325 |
||
2326 |
myClass := self class. |
|
2327 |
myClass isVariable ifTrue:[ |
|
2328 |
sz := self basicSize. |
|
2329 |
||
2330 |
"copy the indexed variables" |
|
2331 |
1 to:sz do:[:i | |
|
2332 |
t := anObject basicAt:i. |
|
2333 |
aSymbol ~~ #yourself ifTrue:[ |
|
2334 |
t := t perform:aSymbol. |
|
2335 |
]. |
|
2336 |
self basicAt:i put:t. |
|
2337 |
] |
|
2338 |
]. |
|
2339 |
||
2340 |
"copy the instance variables" |
|
2341 |
sz := myClass instSize. |
|
2342 |
1 to:sz do:[:i | |
|
2343 |
t := anObject instVarAt:i. |
|
2344 |
aSymbol ~~ #yourself ifTrue:[ |
|
2345 |
t := t perform:aSymbol |
|
2346 |
]. |
|
2347 |
self instVarAt:i put:t |
|
2348 |
]. |
|
2349 |
||
2350 |
^ self |
|
2351 |
||
2352 |
! |
|
2353 |
||
2354 |
cloneInstanceVariablesFrom:aPrototype |
|
2355 |
"Shallow copy variables from a prototype into myself. |
|
2356 |
This copies instVars by name - i.e. same-named variables are |
|
2357 |
copied, others are not. |
|
2358 |
The variable slots are copied as available |
|
2359 |
(i.e. the min of both indexed sizes is used)." |
|
2360 |
||
2361 |
|myInfo otherInfo| |
|
2362 |
||
2363 |
myInfo := self class instanceVariableOffsets. |
|
2364 |
otherInfo := aPrototype class instanceVariableOffsets. |
|
2365 |
myInfo keysAndValuesDo:[:name :index | |varIndexAssoc| |
|
2366 |
varIndexAssoc := otherInfo at:name ifAbsent:[]. |
|
2367 |
varIndexAssoc notNil ifTrue:[ |
|
2368 |
self instVarAt:index put:(aPrototype instVarAt:(varIndexAssoc value)) |
|
2369 |
] |
|
2370 |
]. |
|
2371 |
self isVariable ifTrue:[ |
|
2372 |
1 to:(self basicSize min:aPrototype basicSize) do:[:index | |
|
2373 |
self basicAt:index put:(aPrototype basicAt:index) |
|
2374 |
]. |
|
2375 |
]. |
|
2376 |
||
2377 |
" |
|
2378 |
Class withoutUpdatingChangesDo:[ |
|
2379 |
Point subclass:#Point3D |
|
2380 |
instanceVariableNames:'z' |
|
2381 |
classVariableNames:'' |
|
2382 |
poolDictionaries:'' |
|
2383 |
category:'testing'. |
|
2384 |
(Point3D new cloneInstanceVariablesFrom:1@2) inspect. |
|
2385 |
] |
|
2386 |
" |
|
2387 |
||
2388 |
" |
|
2389 |
Class withoutUpdatingChangesDo:[ |
|
2390 |
Point variableSubclass:#Point3D |
|
2391 |
instanceVariableNames:'z' |
|
2392 |
classVariableNames:'' |
|
2393 |
poolDictionaries:'' |
|
2394 |
category:'testing'. |
|
2395 |
((Point3D new:2) cloneInstanceVariablesFrom:#(1 2 3)) inspect. |
|
2396 |
] |
|
2397 |
" |
|
2398 |
||
2399 |
" |
|
2400 |
|someObject| |
|
2401 |
||
2402 |
Class withoutUpdatingChangesDo:[ |
|
2403 |
Object subclass:#TestClass1 |
|
2404 |
instanceVariableNames:'foo bar' |
|
2405 |
classVariableNames:'' |
|
2406 |
poolDictionaries:'' |
|
2407 |
category:'testing'. |
|
2408 |
someObject := TestClass1 new. |
|
2409 |
someObject instVarAt:1 put:'foo'; instVarAt:2 put:'bar'. |
|
2410 |
Object subclass:#TestClass2 |
|
2411 |
instanceVariableNames:'bar foo' |
|
2412 |
classVariableNames:'' |
|
2413 |
poolDictionaries:'' |
|
2414 |
category:'testing'. |
|
2415 |
(TestClass2 new cloneInstanceVariablesFrom:someObject) inspect. |
|
2416 |
] |
|
2417 |
" |
|
2418 |
||
2419 |
" |
|
2420 |
|top b b1| |
|
2421 |
||
2422 |
top := StandardSystemView new. |
|
2423 |
top extent:100@100. |
|
2424 |
||
2425 |
b := Button in:top. |
|
2426 |
b label:'hello'. |
|
2427 |
||
2428 |
b1 := ArrowButton new cloneInstanceVariablesFrom:b. |
|
2429 |
||
2430 |
top open. |
|
2431 |
b1 inspect |
|
2432 |
" |
|
2433 |
! |
|
2434 |
||
2435 |
copy |
|
2436 |
"return a copy of the receiver - defaults to shallowcopy here. |
|
2437 |
Notice, that copy does not copy dependents." |
|
2438 |
||
2439 |
^ self shallowCopy postCopy |
|
2440 |
! |
|
2441 |
||
2442 |
deepCopy |
|
2443 |
"return a copy of the object with all subobjects also copied. |
|
2444 |
This method DOES handle cycles/self-refs and preserves object identity; |
|
2445 |
however the receivers class is not copied (to avoid the 'total' copy). |
|
2446 |
||
2447 |
This deepCopy is a bit slower than the old (unsecure) one, since it |
|
2448 |
keeps track of already copied objects. If you are sure, that your |
|
2449 |
copied object does not include duplicates (or you do not care) and |
|
2450 |
no cycles are involved, you can use the old simpleDeepCopy, |
|
2451 |
which avoids this overhead (but may run into trouble). |
|
2452 |
Notice, that deepCopy does not copy dependents." |
|
2453 |
||
2454 |
^ (self deepCopyUsing:(IdentityDictionary new)) postDeepCopyFrom:self |
|
2455 |
||
2456 |
"an example which is not handled by the old deepCopy: |
|
2457 |
||
2458 |
|a| |
|
2459 |
a := Array new:3. |
|
2460 |
a at:3 put:a. |
|
2461 |
a deepCopy inspect |
|
2462 |
" |
|
2463 |
||
2464 |
" |
|
2465 |
|a| |
|
2466 |
a := Color black onDevice:Screen current. |
|
2467 |
a deepCopy inspect |
|
2468 |
" |
|
2469 |
||
2470 |
"Modified: 27.3.1996 / 16:31:20 / stefan" |
|
2471 |
! |
|
2472 |
||
2473 |
deepCopyError |
|
2474 |
"{ Pragma: +optSpace }" |
|
2475 |
||
2476 |
"raise a signal, that deepCopy is not allowed for this object" |
|
2477 |
||
2478 |
^ DeepCopyErrorSignal raise |
|
2479 |
! |
|
2480 |
||
2481 |
deepCopyUsing:aDictionary |
|
2482 |
"a helper for deepCopy; return a copy of the object with |
|
2483 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
2484 |
use the value found there. The class of the receiver is not copied. |
|
2485 |
This method DOES handle cycles/self references." |
|
2486 |
||
2487 |
|myClass aCopy |
|
2488 |
sz "{ Class: SmallInteger }" |
|
2489 |
iOrig iCopy| |
|
2490 |
||
2491 |
myClass := self class. |
|
2492 |
myClass isVariable ifTrue:[ |
|
2493 |
sz := self basicSize. |
|
2494 |
aCopy := myClass basicNew:sz. |
|
2495 |
] ifFalse:[ |
|
2496 |
sz := 0. |
|
2497 |
aCopy := myClass basicNew |
|
2498 |
]. |
|
2499 |
aCopy setHashFrom:self. |
|
2500 |
||
2501 |
aDictionary at:self put:aCopy. |
|
2502 |
||
2503 |
" |
|
2504 |
copy indexed instvars - if any |
|
2505 |
" |
|
2506 |
sz ~~ 0 ifTrue:[ |
|
2507 |
myClass isBits ifTrue:[ |
|
2508 |
"block-copy indexed instvars" |
|
2509 |
aCopy replaceFrom:1 to:sz with:self startingAt:1 |
|
2510 |
] ifFalse:[ |
|
2511 |
"individual deep copy the indexed variables" |
|
2512 |
1 to:sz do:[:i | |
|
2513 |
iOrig := self basicAt:i. |
|
2514 |
iOrig notNil ifTrue:[ |
|
2515 |
(aDictionary includesKey:iOrig) ifTrue:[ |
|
2516 |
iCopy := aDictionary at:iOrig |
|
2517 |
] ifFalse:[ |
|
2518 |
iCopy := (iOrig deepCopyUsing:aDictionary) postDeepCopy |
|
2519 |
]. |
|
2520 |
aCopy basicAt:i put:iCopy |
|
2521 |
] |
|
2522 |
] |
|
2523 |
] |
|
2524 |
]. |
|
2525 |
||
2526 |
" |
|
2527 |
copy the instance variables |
|
2528 |
" |
|
2529 |
sz := myClass instSize. |
|
2530 |
1 to:sz do:[:i | |
|
2531 |
(self skipInstvarIndexInDeepCopy:i) ifFalse:[ |
|
2532 |
iOrig := self instVarAt:i. |
|
2533 |
iOrig notNil ifTrue:[ |
|
2534 |
(aDictionary includesKey:iOrig) ifTrue:[ |
|
2535 |
iCopy := aDictionary at:iOrig |
|
2536 |
] ifFalse:[ |
|
2537 |
iCopy := (iOrig deepCopyUsing:aDictionary) postDeepCopy |
|
2538 |
]. |
|
2539 |
aCopy instVarAt:i put:iCopy |
|
2540 |
] |
|
2541 |
] |
|
2542 |
]. |
|
2543 |
^ aCopy |
|
2544 |
||
2545 |
" |
|
2546 |
|a b c copyOfC| |
|
2547 |
||
2548 |
a := Array with:'hello' with:'world' with:nil. |
|
2549 |
b := 99 @ 999. |
|
2550 |
a at:3 put:b. |
|
2551 |
c := Array with:a with:b with:a. |
|
2552 |
||
2553 |
Transcript showCR: (c at:1) == (c at:3). |
|
2554 |
copyOfC := c deepCopy. |
|
2555 |
Transcript showCR: (copyOfC at:1) == (copyOfC at:3) |
|
2556 |
" |
|
2557 |
! |
|
2558 |
||
2559 |
postCopy |
|
2560 |
"this is for compatibility with ST-80 code, which uses postCopy for |
|
2561 |
cleanup after copying, while ST/X passes the original in postCopyFrom: |
|
2562 |
(see there)" |
|
2563 |
||
2564 |
^ self |
|
2565 |
! |
|
2566 |
||
2567 |
postDeepCopy |
|
2568 |
"allows for cleanup after deep copying" |
|
2569 |
||
2570 |
^ self postCopy |
|
2571 |
! |
|
2572 |
||
2573 |
postDeepCopyFrom:aSource |
|
2574 |
"allows for cleanup after deep copying" |
|
2575 |
||
2576 |
^ self postDeepCopy |
|
2577 |
! |
|
2578 |
||
2579 |
setHashFrom:anObject |
|
2580 |
"set my identity-hash key to be the same as anObjects hash key. |
|
2581 |
This is an ST/X speciality, which is NOT available in other (especially OT based) |
|
2582 |
Smalltalks, and may not be available in future ST/X versions. |
|
2583 |
DO NEVER use this for normal application code." |
|
2584 |
||
2585 |
%{ /* NOCONTEXT */ |
|
2586 |
||
2587 |
REGISTER unsigned h; |
|
2588 |
||
2589 |
if (__isNonNilObject(self) && __isNonNilObject(anObject)) { |
|
2590 |
h = __GET_HASH(anObject); |
|
2591 |
__SET_HASH(self, h); |
|
2592 |
RETURN (self); |
|
2593 |
} |
|
2594 |
%}. |
|
2595 |
self primitiveFailed "neither receiver not arg may be nil or SmallInteger" |
|
2596 |
! |
|
2597 |
||
2598 |
shallowCopy |
|
2599 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2600 |
i.e. the copy shares referenced instvars with its original." |
|
2601 |
||
2602 |
%{ /* NOCONTEXT */ |
|
2603 |
int ninsts, spc; |
|
2604 |
int sz; |
|
2605 |
OBJ theCopy; |
|
2606 |
OBJ cls; |
|
2607 |
int flags; |
|
2608 |
||
2609 |
cls = __qClass(self); |
|
2610 |
flags = __intVal(__ClassInstPtr(cls)->c_flags); |
|
2611 |
||
2612 |
/* |
|
2613 |
* bail out for special objects .. |
|
2614 |
*/ |
|
2615 |
if (((flags & ~ARRAYMASK) == 0) |
|
2616 |
&& ((flags & ARRAYMASK) != WKPOINTERARRAY)) { |
|
2617 |
sz = __qSize(self); |
|
2618 |
__PROTECT__(self); |
|
2619 |
__qNew(theCopy, sz); /* OBJECT ALLOCATION */ |
|
2620 |
__UNPROTECT__(self); |
|
2621 |
if (theCopy) { |
|
2622 |
cls = __qClass(self); |
|
2623 |
spc = __qSpace(theCopy); |
|
2624 |
||
2625 |
theCopy->o_class = cls; __STORE_SPC(theCopy, cls, spc); |
|
2626 |
||
2627 |
sz = sz - OHDR_SIZE; |
|
2628 |
if (sz) { |
|
2629 |
char *src, *dst; |
|
2630 |
||
2631 |
src = (char *)(__InstPtr(self)->i_instvars); |
|
2632 |
dst = (char *)(__InstPtr(theCopy)->i_instvars); |
|
2633 |
#ifdef bcopy4 |
|
2634 |
{ |
|
2635 |
/* care for odd-number of longs */ |
|
2636 |
int nW = sz >> 2; |
|
2637 |
||
2638 |
if (sz & 3) { |
|
2639 |
nW++; |
|
2640 |
} |
|
2641 |
||
2642 |
bcopy4(src, dst, nW); |
|
2643 |
} |
|
2644 |
#else |
|
2645 |
bcopy(src, dst, sz); |
|
2646 |
#endif |
|
2647 |
||
2648 |
flags &= ARRAYMASK; |
|
2649 |
if (flags == POINTERARRAY) { |
|
2650 |
ninsts = __BYTES2OBJS__(sz); |
|
2651 |
} else { |
|
2652 |
ninsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
2653 |
} |
|
2654 |
if (ninsts) { |
|
2655 |
do { |
|
2656 |
OBJ el; |
|
2657 |
||
2658 |
el = __InstPtr(theCopy)->i_instvars[ninsts-1]; |
|
2659 |
__STORE_SPC(theCopy, el, spc); |
|
2660 |
} while (--ninsts); |
|
2661 |
} |
|
2662 |
} |
|
2663 |
RETURN (theCopy); |
|
2664 |
} |
|
2665 |
} |
|
2666 |
%}. |
|
2667 |
"/ fallBack for special objects & memoryAllocation failure case |
|
2668 |
||
2669 |
^ self slowShallowCopy |
|
2670 |
! |
|
2671 |
||
2672 |
shallowCopyForFinalization |
|
2673 |
"this is used to aquire a copy to be used for finalization - |
|
2674 |
(the copy will get a dispose-notification; see the documentation in the Registry class) |
|
2675 |
This method can be redefined for more efficient copying - especially for large objects." |
|
2676 |
||
2677 |
"/ going to be obsoleted by executor |
|
2678 |
^ self shallowCopy |
|
2679 |
||
2680 |
"Modified: / 5.8.1999 / 14:07:16 / cg" |
|
2681 |
! |
|
2682 |
||
2683 |
simpleDeepCopy |
|
2684 |
"return a copy of the object with all subobjects also copied. |
|
2685 |
This method does NOT handle cycles - but is included to allow this |
|
2686 |
slightly faster copy in situations where it is known that |
|
2687 |
no recursive references occur (LargeIntegers for example). |
|
2688 |
NOTICE: you will run into trouble, when trying this with recursive |
|
2689 |
objects (usually recursionInterrupt or memory-alert). |
|
2690 |
This method corresponds to the 'traditional' deepCopy found in |
|
2691 |
the Blue book." |
|
2692 |
||
2693 |
|myClass aCopy| |
|
2694 |
||
2695 |
(myClass := self class) isVariable ifTrue:[ |
|
2696 |
aCopy := myClass basicNew:(self basicSize). |
|
2697 |
] ifFalse:[ |
|
2698 |
aCopy := myClass basicNew |
|
2699 |
]. |
|
2700 |
||
2701 |
"copy the instance variables" |
|
2702 |
aCopy cloneFrom:self performing:#simpleDeepCopy. |
|
2703 |
^ aCopy |
|
2704 |
||
2705 |
"a bad example (but ST/X should survive ...)" |
|
2706 |
" |
|
2707 |
|a| |
|
2708 |
a := Array new:3. |
|
2709 |
a at:3 put:a. |
|
2710 |
a simpleDeepCopy |
|
2711 |
" |
|
2712 |
! |
|
2713 |
||
2714 |
skipInstvarIndexInDeepCopy:index |
|
2715 |
"a helper for deepCopy; only indices for which this method returns |
|
2716 |
false are copied in a deep copy. |
|
2717 |
The default is false here - which means that everything is copied. |
|
2718 |
Can be redefined in subclasses for partial copies" |
|
2719 |
||
2720 |
^ false |
|
2721 |
! |
|
2722 |
||
2723 |
slowShallowCopy |
|
2724 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2725 |
i.e. the copy shares referenced instvars with its original. |
|
2726 |
This method is only invoked as a fallback from #shallowCopy." |
|
2727 |
||
2728 |
|myClass aCopy| |
|
2729 |
||
2730 |
(myClass := self class) isVariable ifTrue:[ |
|
2731 |
aCopy := myClass basicNew:(self basicSize). |
|
2732 |
] ifFalse:[ |
|
2733 |
aCopy := myClass basicNew |
|
2734 |
]. |
|
2735 |
||
2736 |
"copy the instance variables" |
|
2737 |
aCopy cloneFrom:self performing:#yourself. |
|
2738 |
^ aCopy |
|
2739 |
! ! |
|
2740 |
||
2741 |
!Object methodsFor:'debugging'! |
|
2742 |
||
2743 |
basicInspect |
|
2744 |
"{ Pragma: +optSpace }" |
|
2745 |
||
2746 |
"launch an inspector on the receiver. |
|
2747 |
this method should NOT be redefined in subclasses." |
|
2748 |
||
2749 |
Inspector isNil ifTrue:[ |
|
2750 |
" |
|
2751 |
for systems without GUI |
|
2752 |
" |
|
2753 |
Transcript showCR:'no Inspector' |
|
2754 |
] ifFalse:[ |
|
2755 |
Inspector openOn:self |
|
2756 |
] |
|
2757 |
||
2758 |
"Modified: 18.5.1996 / 15:43:25 / cg" |
|
2759 |
! |
|
2760 |
||
2761 |
inspect |
|
2762 |
"{ Pragma: +optSpace }" |
|
2763 |
||
2764 |
"launch an inspector on the receiver. |
|
2765 |
this method (or better: inspectorClass) can be redefined in subclasses |
|
2766 |
to start special inspectors." |
|
2767 |
||
2768 |
|cls| |
|
2769 |
||
2770 |
cls := self inspectorClass. |
|
2771 |
cls isNil ifTrue:[ |
|
2772 |
^ self basicInspect |
|
2773 |
]. |
|
2774 |
cls openOn:self |
|
2775 |
||
2776 |
" |
|
2777 |
Object new inspect |
|
2778 |
(1 @ 2) inspect |
|
2779 |
Smalltalk inspect |
|
2780 |
#(1 2 3) asOrderedCollection inspect |
|
2781 |
(Color red) inspect |
|
2782 |
(Image fromFile:'bitmaps/garfield.gif') inspect |
|
2783 |
" |
|
2784 |
! |
|
2785 |
||
2786 |
inspectorClass |
|
2787 |
"{ Pragma: +optSpace }" |
|
2788 |
||
2789 |
"return the class to use for inspect. |
|
2790 |
Can (should) be redefined in classes for which a better inspector is available" |
|
2791 |
||
2792 |
^ Inspector |
|
2793 |
! |
|
2794 |
||
2795 |
mustBeBoolean |
|
2796 |
"this message is sent by the VM, if a non-Boolean receiver is encountered |
|
2797 |
in an if* or while* message. |
|
2798 |
Caveat: for now, this is only sent by the interpreter; |
|
2799 |
both the JIT and the stc compiler treat it as undefined." |
|
2800 |
||
2801 |
self error:'Non boolean receiver - proceed for truth' mayProceed:true. |
|
2802 |
^ true |
|
2803 |
! |
|
2804 |
||
2805 |
mustBeKindOf:aClass |
|
2806 |
"for compatibility & debugging support: |
|
2807 |
check if the receiver isKindOf:aClass and raise an error if not. |
|
2808 |
Notice: |
|
2809 |
it is VERY questionable, if it makes sense to add manual |
|
2810 |
type checks to a dynamically typed language like smalltalk. |
|
2811 |
It will, at least, slow down performance, |
|
2812 |
make your code less reusable and clutter your code with stupid sends |
|
2813 |
of this selector. Also, read the comment in isKindOf:, regarding the |
|
2814 |
use of isXXX check methods. |
|
2815 |
You see: The author does not like this at all ..." |
|
2816 |
||
2817 |
(self isKindOf:aClass) ifFalse:[ |
|
2818 |
self error:'argument is not of expected type' |
|
2819 |
] |
|
2820 |
! |
|
2821 |
||
2822 |
obsoleteMethodWarning |
|
2823 |
"{ Pragma: +optSpace }" |
|
2824 |
||
2825 |
"in methods which are going to be obsoleted, a self send to |
|
2826 |
this method is used to tell programmers that a method is |
|
2827 |
used which is going to be removed in later ST/X versions. |
|
2828 |
Find all methods which will be obsolete soon by looking at senders |
|
2829 |
of this message. |
|
2830 |
Hopefully, this warning message is annoying enough for you to |
|
2831 |
change the code ... ;-)" |
|
2832 |
||
2833 |
self obsoleteMethodWarning:nil from:thisContext sender |
|
2834 |
! |
|
2835 |
||
2836 |
obsoleteMethodWarning:message |
|
2837 |
"{ Pragma: +optSpace }" |
|
2838 |
||
2839 |
"in methods which are going to be obsoleted, a self send to |
|
2840 |
this method is used to tell programmers that a method is |
|
2841 |
used which is going to be removed in later ST/X versions. |
|
2842 |
Find all methods which will be obsolete soon by looking at senders |
|
2843 |
of this message. |
|
2844 |
Hopefully, this warning message is annoying enough for you to |
|
2845 |
change the code ... ;-)" |
|
2846 |
||
2847 |
self obsoleteMethodWarning:message from:thisContext sender |
|
5879
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2848 |
! |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2849 |
|
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2850 |
obsoleteMethodWarning:message from:aContext |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2851 |
"{ Pragma: +optSpace }" |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2852 |
|
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2853 |
"in methods which are going to be obsoleted, a self-send to |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2854 |
this method is used to tell programmers that a method is |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2855 |
used which is going to be removed in later ST/X versions. |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2856 |
Find all methods which will be obsolete soon by looking at senders |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2857 |
of this message. |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2858 |
Hopefully, this warning message is annoying enough for you to |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2859 |
change the code ... ;-)" |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2860 |
|
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2861 |
|spec| |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2862 |
|
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2863 |
spec := aContext methodPrintString. |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2864 |
('WARNING: the ''' , spec , ''' method is obsolete.') errorPrintCR. |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2865 |
(' And may not be present in future ST/X versions.') errorPrintCR. |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2866 |
(' called from ' , aContext sender printString) errorPrintCR. |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2867 |
message notNil ifTrue:[ |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2868 |
'------> ' errorPrint. message errorPrintCR |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2869 |
] |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2870 |
|
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2871 |
" |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2872 |
Object obsoleteMethodWarning:'foo' from:thisContext sender sender |
1fbb9035e1cf
stefan: careful - do not check in corrupt classes !!!!
Claus Gittinger <cg@exept.de>
parents:
5869
diff
changeset
|
2873 |
" |
5755 | 2874 |
! ! |
2875 |
||
2876 |
!Object methodsFor:'dependents access'! |
|
2877 |
||
2878 |
addDependent:anObject |
|
2879 |
"make the argument, anObject be a dependent of the receiver" |
|
2880 |
||
2881 |
|wasBlocked| |
|
2882 |
||
2883 |
"/ must do this save from interrupts, since the dependents collection |
|
2884 |
"/ is possibly accessed from multiple threads. |
|
2885 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
2886 |
"/ faster execution. |
|
2887 |
||
2888 |
wasBlocked := OperatingSystem blockInterrupts. |
|
2889 |
[ |
|
2890 |
|deps dep| |
|
2891 |
||
2892 |
deps := self dependents. |
|
2893 |
||
2894 |
"/ to save a fair amount of memory in case of |
|
2895 |
"/ many dependencies, we store a single dependent in |
|
2896 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
2897 |
"/ added. |
|
2898 |
||
2899 |
(deps isNil or:[deps size == 0]) ifTrue:[ |
|
2900 |
self dependents:(WeakArray with:anObject) |
|
2901 |
] ifFalse:[ |
|
2902 |
deps class == WeakArray ifTrue:[ |
|
2903 |
dep := deps at:1. |
|
2904 |
dep ~~ anObject ifTrue:[ |
|
2905 |
(dep isNil or:[dep == 0]) ifTrue:[ |
|
2906 |
deps at:1 put:anObject |
|
2907 |
] ifFalse:[ |
|
2908 |
self dependents:(WeakIdentitySet with:dep with:anObject) |
|
2909 |
] |
|
2910 |
] |
|
2911 |
] ifFalse:[ |
|
2912 |
deps add:anObject |
|
2913 |
] |
|
2914 |
] |
|
2915 |
] valueNowOrOnUnwindDo:[ |
|
2916 |
wasBlocked ifFalse:[ |
|
2917 |
OperatingSystem unblockInterrupts |
|
2918 |
] |
|
2919 |
] |
|
2920 |
||
2921 |
"Modified: / 27.10.1997 / 19:35:52 / cg" |
|
2922 |
! |
|
2923 |
||
2924 |
breakDependents |
|
2925 |
"remove all dependencies from the receiver" |
|
2926 |
||
2927 |
self dependents:nil. |
|
2928 |
self nonWeakDependents:nil |
|
2929 |
||
2930 |
"Modified: / 19.4.1996 / 10:55:36 / cg" |
|
2931 |
"Created: / 27.2.1998 / 11:26:11 / stefan" |
|
2932 |
! |
|
2933 |
||
2934 |
dependents |
|
2935 |
"return a Collection of dependents. |
|
2936 |
The default implementation here uses a global WeakDictionary to store |
|
2937 |
dependents |
|
2938 |
This may be too slow for high frequency change&update, |
|
2939 |
therefore, some classes (Model) redefine this for better performance. |
|
2940 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
|
2941 |
||
2942 |
|deps| |
|
2943 |
||
2944 |
(deps := Dependencies at:self ifAbsent:nil) isNil ifTrue:[ |
|
2945 |
^ #(). |
|
2946 |
]. |
|
2947 |
^ deps |
|
2948 |
||
2949 |
"Modified: / 26.1.1998 / 11:18:15 / cg" |
|
2950 |
! |
|
2951 |
||
2952 |
dependents:aCollection |
|
2953 |
"set the collection of dependents. |
|
2954 |
The default implementation here uses a global Dictionary to store |
|
2955 |
dependents which may be too slow for high frequency change&update. |
|
2956 |
Therefore, some classes (Model) redefine this for better performance." |
|
2957 |
||
2958 |
"/ must do this save from interrupts, since the dependents collection |
|
2959 |
"/ is possibly accessed from multiple threads. |
|
2960 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
2961 |
"/ faster execution (and to avoid creation of garbage blocks). |
|
2962 |
||
2963 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
2964 |
"/ the common case - already blocked |
|
2965 |
||
2966 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
2967 |
Dependencies removeKey:self ifAbsent:nil |
|
2968 |
] ifFalse:[ |
|
2969 |
Dependencies at:self put:aCollection |
|
2970 |
]. |
|
2971 |
^ self |
|
2972 |
]. |
|
2973 |
||
2974 |
[ |
|
2975 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
2976 |
Dependencies removeKey:self ifAbsent:nil |
|
2977 |
] ifFalse:[ |
|
2978 |
Dependencies at:self put:aCollection |
|
2979 |
]. |
|
2980 |
] valueNowOrOnUnwindDo:[ |
|
2981 |
OperatingSystem unblockInterrupts |
|
2982 |
] |
|
2983 |
||
2984 |
"Modified: 30.1.1997 / 21:22:10 / cg" |
|
2985 |
! |
|
2986 |
||
2987 |
dependentsDo:aBlock |
|
2988 |
"evaluate aBlock for all of my dependents" |
|
2989 |
||
2990 |
|deps nwDeps| |
|
2991 |
||
2992 |
deps := self dependents. |
|
2993 |
deps size ~~ 0 ifTrue:[ |
|
2994 |
deps do:[:d | |
|
2995 |
(d notNil and:[d ~~ 0]) ifTrue:[ |
|
2996 |
aBlock value:d |
|
2997 |
] |
|
2998 |
] |
|
2999 |
]. |
|
3000 |
nwDeps := self nonWeakDependents. |
|
3001 |
(nwDeps ~~ deps and:[nwDeps size ~~ 0]) ifTrue:[ |
|
3002 |
nwDeps do:aBlock |
|
3003 |
]. |
|
3004 |
||
3005 |
"Modified: / 30.1.1998 / 14:03:40 / cg" |
|
3006 |
! |
|
3007 |
||
3008 |
myDependents |
|
3009 |
"same as dependents - ST-80 compatibility" |
|
3010 |
||
3011 |
^ self dependents |
|
3012 |
! |
|
3013 |
||
3014 |
release |
|
3015 |
"remove all references to objects that may refer to self. |
|
3016 |
Subclasses may redefine this method but should do a 'super release'." |
|
3017 |
||
3018 |
self breakDependents |
|
3019 |
||
3020 |
"Modified: / 27.2.1998 / 11:29:35 / stefan" |
|
3021 |
! |
|
3022 |
||
3023 |
removeDependent:anObject |
|
3024 |
"make the argument, anObject be independent of the receiver" |
|
3025 |
||
3026 |
|wasBlocked| |
|
3027 |
||
3028 |
"/ must do this save from interrupts, since the dependents collection |
|
3029 |
"/ is possibly accessed from multiple threads. |
|
3030 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3031 |
"/ faster execution. |
|
3032 |
||
3033 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3034 |
[ |
|
3035 |
|deps n d| |
|
3036 |
||
3037 |
deps := self dependents. |
|
3038 |
deps size ~~ 0 ifTrue:[ |
|
3039 |
||
3040 |
"/ to save a fair amount of memory in case of |
|
3041 |
"/ many dependencies, we store a single dependent in |
|
3042 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3043 |
"/ added. Here we have to do the inverse ... |
|
3044 |
||
3045 |
deps class == WeakArray ifTrue:[ |
|
3046 |
((d := deps at:1) == anObject |
|
3047 |
or:[d isNil |
|
3048 |
or:[d == 0]]) ifTrue:[ |
|
3049 |
self dependents:nil |
|
3050 |
] |
|
3051 |
] ifFalse:[ |
|
3052 |
deps remove:anObject ifAbsent:[]. |
|
3053 |
(n := deps size) == 0 ifTrue:[ |
|
3054 |
self dependents:nil |
|
3055 |
] ifFalse:[ |
|
3056 |
n == 1 ifTrue:[ |
|
3057 |
d := deps firstIfEmpty:nil. |
|
3058 |
d notNil ifTrue:[ |
|
3059 |
deps := WeakArray with:d |
|
3060 |
] ifFalse:[ |
|
3061 |
deps := nil |
|
3062 |
]. |
|
3063 |
self dependents:deps. |
|
3064 |
] |
|
3065 |
] |
|
3066 |
] |
|
3067 |
] |
|
3068 |
] valueNowOrOnUnwindDo:[ |
|
3069 |
wasBlocked ifFalse:[ |
|
3070 |
OperatingSystem unblockInterrupts |
|
3071 |
] |
|
3072 |
] |
|
3073 |
||
3074 |
"Modified: / 26.1.1998 / 19:51:50 / cg" |
|
3075 |
! ! |
|
3076 |
||
3077 |
!Object methodsFor:'dependents access (nonWeak)'! |
|
3078 |
||
3079 |
addNonWeakDependent:anObject |
|
3080 |
"make the argument, anObject be a nonWeak dependent of the receiver. |
|
3081 |
Be careful: this nonWeakDependency will prevent the dependent from being |
|
3082 |
garbage collected unless the dependency is removed. |
|
3083 |
This is a private mechanism, for directed dependencies." |
|
3084 |
||
3085 |
|wasBlocked| |
|
3086 |
||
3087 |
"/ must do this save from interrupts, since the dependents collection |
|
3088 |
"/ is possibly accessed from multiple threads. |
|
3089 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3090 |
"/ faster execution. |
|
3091 |
||
3092 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3093 |
[ |
|
3094 |
|deps dep| |
|
3095 |
||
3096 |
deps := self nonWeakDependents. |
|
3097 |
||
3098 |
"/ to save a fair amount of memory in case of |
|
3099 |
"/ many dependencies, we store a single dependent in |
|
3100 |
"/ an Array, and switch to a Set if more dependents are |
|
3101 |
"/ added. |
|
3102 |
||
3103 |
deps size == 0 ifTrue:[ |
|
3104 |
self nonWeakDependents:(Array with:anObject) |
|
3105 |
] ifFalse:[ |
|
3106 |
deps class == Array ifTrue:[ |
|
3107 |
dep := deps at:1. |
|
3108 |
dep ~~ anObject ifTrue:[ |
|
3109 |
self nonWeakDependents:(IdentitySet with:dep with:anObject) |
|
3110 |
] |
|
3111 |
] ifFalse:[ |
|
3112 |
deps add:anObject |
|
3113 |
] |
|
3114 |
] |
|
3115 |
] valueNowOrOnUnwindDo:[ |
|
3116 |
wasBlocked ifFalse:[ |
|
3117 |
OperatingSystem unblockInterrupts |
|
3118 |
] |
|
3119 |
] |
|
3120 |
||
3121 |
"Created: / 19.4.1996 / 10:54:08 / cg" |
|
3122 |
"Modified: / 30.1.1998 / 14:03:08 / cg" |
|
3123 |
! |
|
3124 |
||
3125 |
nonWeakDependents |
|
3126 |
"return a Collection of nonWeakDependents - empty if there is none. |
|
3127 |
This is a private mechanism for directed dependencies." |
|
3128 |
||
3129 |
NonWeakDependencies isNil ifTrue:[^ #()]. |
|
3130 |
^ NonWeakDependencies at:self ifAbsent:#() |
|
3131 |
||
3132 |
"Created: / 19.4.1996 / 10:55:06 / cg" |
|
3133 |
"Modified: / 30.1.1998 / 14:06:47 / cg" |
|
3134 |
! |
|
3135 |
||
3136 |
nonWeakDependents:aCollection |
|
3137 |
"set the collection of nonWeak dependents. |
|
3138 |
This is a private helper for directed dependencies." |
|
3139 |
||
3140 |
[ |
|
3141 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
3142 |
NonWeakDependencies removeKey:self ifAbsent:nil |
|
3143 |
] ifFalse:[ |
|
3144 |
NonWeakDependencies at:self put:aCollection |
|
3145 |
] |
|
3146 |
] valueUninterruptably |
|
3147 |
||
3148 |
"Created: 19.4.1996 / 11:07:47 / cg" |
|
3149 |
! |
|
3150 |
||
3151 |
removeNonWeakDependent:anObject |
|
3152 |
"remove a nonWeak dependency from the receiver to the argument, anObject. |
|
3153 |
(i.e. make it independent of the receiver)" |
|
3154 |
||
3155 |
|wasBlocked| |
|
3156 |
||
3157 |
"/ must do this save from interrupts, since the dependents collection |
|
3158 |
"/ is possibly accessed from multiple threads. |
|
3159 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3160 |
"/ faster execution. |
|
3161 |
||
3162 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3163 |
[ |
|
3164 |
|deps n| |
|
3165 |
||
3166 |
deps := self nonWeakDependents. |
|
3167 |
deps size ~~ 0 ifTrue:[ |
|
3168 |
deps class == Array ifTrue:[ |
|
3169 |
(deps at:1) == anObject ifTrue:[ |
|
3170 |
self nonWeakDependents:nil |
|
3171 |
] |
|
3172 |
] ifFalse:[ |
|
3173 |
deps remove:anObject ifAbsent:[]. |
|
3174 |
(n := deps size) == 0 ifTrue:[ |
|
3175 |
self nonWeakDependents:nil |
|
3176 |
] ifFalse:[ |
|
3177 |
n == 1 ifTrue:[ |
|
3178 |
self nonWeakDependents:(Array with:(deps first)) |
|
3179 |
] |
|
3180 |
] |
|
3181 |
] |
|
3182 |
] |
|
3183 |
] valueNowOrOnUnwindDo:[ |
|
3184 |
wasBlocked ifFalse:[ |
|
3185 |
OperatingSystem unblockInterrupts |
|
3186 |
] |
|
3187 |
] |
|
3188 |
||
3189 |
"Created: / 19.4.1996 / 11:44:44 / cg" |
|
3190 |
"Modified: / 30.1.1998 / 14:04:01 / cg" |
|
3191 |
! ! |
|
3192 |
||
3193 |
!Object methodsFor:'displaying'! |
|
3194 |
||
3195 |
displayOn:aGC |
|
3196 |
"ST-80 Compatibility |
|
3197 |
display the receiver in a graphicsContext at 0@0 |
|
3198 |
- this method allows for any object to be displayed in some view |
|
3199 |
(although the fallBack is to display its printString ...)" |
|
3200 |
||
3201 |
^ self displayOn:aGC x:0 y:0. |
|
3202 |
||
3203 |
"Created: 29.5.1996 / 16:28:58 / cg" |
|
3204 |
! |
|
3205 |
||
3206 |
displayOn:aGC at:aPoint |
|
3207 |
"ST-80 Compatibility |
|
3208 |
display the receiver in a graphicsContext - this method allows |
|
3209 |
for any object to be displayed in a ListView - for example." |
|
3210 |
||
3211 |
^ self displayOn:aGC x:(aPoint x) y:(aPoint y). |
|
3212 |
! |
|
3213 |
||
3214 |
displayOn:aGC x:x y:y |
|
3215 |
"display the receiver in a graphicsContext - this method allows |
|
3216 |
for any object to be displayed in a ListView - for example." |
|
3217 |
||
3218 |
self displayOn:aGC x:x y:y opaque:false |
|
3219 |
||
3220 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3221 |
! |
|
3222 |
||
3223 |
displayOn:aGc x:x y:y opaque:opaque |
|
3224 |
"display the receiver in a graphicsContext - this method allows |
|
3225 |
for any object to be displayed in a ListView - for example. |
|
3226 |
The fallBack here shows the receivers displayString." |
|
3227 |
||
3228 |
|s yBaseline| |
|
3229 |
||
3230 |
s := self displayString. |
|
3231 |
"/ although correct, this breaks DataSet, and it must be fixed |
|
3232 |
"/ there first ... |
|
3233 |
yBaseline := y + aGc font ascent. |
|
3234 |
yBaseline := y "+ aGc font ascent". |
|
3235 |
opaque ifTrue:[ |
|
3236 |
aGc displayOpaqueString:s x:x y:yBaseline. |
|
3237 |
] ifFalse:[ |
|
3238 |
aGc displayString:s x:x y:yBaseline. |
|
3239 |
]. |
|
3240 |
||
3241 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3242 |
! |
|
3243 |
||
3244 |
displayOpaqueOn:aGC x:x y:y |
|
3245 |
"display the receiver in a graphicsContext - this method allows |
|
3246 |
for any object to be displayed in a ListView - for example." |
|
3247 |
||
3248 |
self displayOn:aGC x:x y:y opaque:true |
|
3249 |
||
3250 |
"Modified: / 29.5.1996 / 16:29:38 / cg" |
|
3251 |
"Created: / 26.10.1997 / 15:01:36 / cg" |
|
3252 |
! |
|
3253 |
||
3254 |
displayString |
|
3255 |
"return a string used when displaying the receiver in a view; |
|
3256 |
for example an Inspector. This is usually the same as printString, |
|
3257 |
but sometimes redefined for a better look." |
|
3258 |
||
3259 |
^ self printString |
|
3260 |
||
3261 |
" |
|
3262 |
#(1 2 3) printString |
|
3263 |
#(1 2 3) displayString |
|
3264 |
#(1 2 3) storeString |
|
3265 |
" |
|
3266 |
! |
|
3267 |
||
3268 |
heightOn:aGC |
|
3269 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
3270 |
||
3271 |
^ (aGC font onDevice:aGC device) heightOf:(self displayString) |
|
3272 |
! |
|
3273 |
||
3274 |
widthOn:aGC |
|
3275 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3276 |
||
3277 |
^ (aGC font onDevice:aGC device) widthOf:(self displayString) |
|
3278 |
! ! |
|
3279 |
||
3280 |
!Object methodsFor:'encoding & decoding'! |
|
3281 |
||
3282 |
decodeAsLiteralArray |
|
3283 |
^ self |
|
3284 |
! |
|
3285 |
||
3286 |
encodeOn:anEncoder with:aParameter |
|
3287 |
"double-dispatch onto an ObjectEncoder. |
|
3288 |
Subclasses redefine this" |
|
3289 |
||
3290 |
anEncoder encodeObject:self with:aParameter |
|
3291 |
||
3292 |
||
3293 |
! |
|
3294 |
||
3295 |
fromLiteralArrayEncoding:aSpecArray |
|
3296 |
"read my attributes from aSpecArray |
|
3297 |
" |
|
3298 |
|sel val |
|
3299 |
stop "{ Class:SmallInteger }" | |
|
3300 |
||
3301 |
stop := aSpecArray size. |
|
3302 |
||
3303 |
2 to:stop by:2 do:[:i| |
|
3304 |
sel := aSpecArray at:i. |
|
3305 |
val := aSpecArray at:i + 1. |
|
3306 |
||
3307 |
(self respondsTo:sel) ifTrue:[ |
|
3308 |
self perform:sel with:(val decodeAsLiteralArray) |
|
3309 |
] ifFalse:[ |
|
3310 |
Transcript show:self class name; show:': unhandled literalArrayEncoding attribute: '. |
|
3311 |
Transcript showCR:sel. |
|
3312 |
] |
|
3313 |
] |
|
3314 |
||
3315 |
||
3316 |
! |
|
3317 |
||
3318 |
literalArrayEncoding |
|
3319 |
"generate a literalArrayEncoding array for myself. |
|
3320 |
This uses #literalArrayEncodingSlotOrder which defines the slots and |
|
3321 |
order and #skippedInLiteralEncoding which defines slots to skip. |
|
3322 |
For most subclasses, there is no need to redefine those." |
|
3323 |
||
3324 |
|names encoding cls skipped| |
|
3325 |
||
3326 |
self isLiteral ifTrue:[ |
|
3327 |
^ self |
|
3328 |
]. |
|
3329 |
||
3330 |
skipped := self skippedInLiteralEncoding. |
|
3331 |
cls := self class. |
|
3332 |
names := cls allInstVarNames. |
|
3333 |
encoding := OrderedCollection with:(cls name). |
|
3334 |
||
3335 |
(self literalArrayEncodingSlotOrder) do:[:instSlot | |
|
3336 |
|value nm| |
|
3337 |
||
3338 |
nm := names at:instSlot. |
|
3339 |
||
3340 |
(skipped includes:nm) ifFalse:[ |
|
3341 |
(value := self instVarAt:instSlot) notNil ifTrue:[ |
|
3342 |
encoding add:(nm , ':') asSymbol. |
|
3343 |
encoding add:value literalArrayEncoding |
|
3344 |
] |
|
3345 |
] |
|
3346 |
]. |
|
3347 |
^ encoding asArray |
|
3348 |
||
3349 |
||
3350 |
! |
|
3351 |
||
3352 |
literalArrayEncodingSlotOrder |
|
3353 |
"define the order in which inst-slots are saved when generating |
|
3354 |
a literalArrayEncoding |
|
3355 |
" |
|
3356 |
^ 1 to:self class instSize |
|
3357 |
||
3358 |
! |
|
3359 |
||
3360 |
skippedInLiteralEncoding |
|
3361 |
"return a Collection with it's elements are slots for skipping |
|
3362 |
" |
|
3363 |
^ #() |
|
3364 |
||
3365 |
! ! |
|
3366 |
||
3367 |
!Object methodsFor:'error handling'! |
|
3368 |
||
3369 |
appropriateDebugger:aSelector |
|
3370 |
"{ Pragma: +optSpace }" |
|
3371 |
||
3372 |
"return an appropriate debugger to use. |
|
3373 |
If there is already a debugger active on the stack, and it is |
|
3374 |
the DebugView, return MiniDebugger (as a last chance) otherwise abort." |
|
3375 |
||
3376 |
|context| |
|
3377 |
||
3378 |
"DebugView cannot run without system processes" |
|
3379 |
||
3380 |
(Processor isNil |
|
3381 |
or:[Processor activeProcessIsSystemProcess |
|
3382 |
or:[Smalltalk isInitialized not]]) ifTrue:[ |
|
3383 |
^ MiniDebugger |
|
3384 |
]. |
|
3385 |
(Screen isNil or:[Screen default isNil]) ifTrue:[ |
|
3386 |
Debugger isNil ifTrue:[^ Debugger]. |
|
3387 |
^ MiniDebugger |
|
3388 |
]. |
|
3389 |
||
3390 |
context := thisContext. |
|
3391 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
3392 |
[context notNil] whileTrue:[ |
|
3393 |
((context receiver class == Debugger) |
|
3394 |
and:[context selector == aSelector]) ifTrue:[ |
|
3395 |
"we are already in some Debugger" |
|
3396 |
(Debugger == MiniDebugger) ifTrue:[ |
|
3397 |
"we are already in the MiniDebugger" |
|
3398 |
ErrorRecursion ifFalse:[ |
|
3399 |
Smalltalk fatalAbort:'recursive error ...' |
|
3400 |
] |
|
3401 |
]. |
|
3402 |
MiniDebugger isNil ifTrue:[ |
|
3403 |
Smalltalk fatalAbort:'no debugger' |
|
3404 |
]. |
|
3405 |
||
3406 |
"ok, an error occured while in the graphical debugger; |
|
3407 |
lets try MiniDebugger" |
|
3408 |
^ MiniDebugger |
|
3409 |
]. |
|
3410 |
context := context findNextContextWithSelector:aSelector or:nil or:nil. |
|
3411 |
]. |
|
3412 |
"not within Debugger - no problem" |
|
3413 |
^ Debugger |
|
3414 |
||
3415 |
"Modified: / 23.9.1996 / 12:14:52 / stefan" |
|
3416 |
"Modified: / 19.5.1999 / 18:05:00 / cg" |
|
3417 |
! |
|
3418 |
||
3419 |
cannotSendMessage:aMessage to:someReceiver |
|
3420 |
"this message is sent by the runtime system (VM), |
|
3421 |
when a message is sent to some object, whose class is not |
|
3422 |
a valid behavior (see documentation in Behavior)." |
|
3423 |
||
3424 |
^ InternalErrorSignal |
|
3425 |
raiseWith:someReceiver |
|
3426 |
errorString:('bad class in send of #' , aMessage selector) |
|
3427 |
||
3428 |
"Modified: 23.1.1997 / 00:05:39 / cg" |
|
3429 |
! |
|
3430 |
||
3431 |
doesNotUnderstand:aMessage |
|
3432 |
"this message is sent by the runtime system (VM) when |
|
3433 |
a message is not understood by some object (i.e. there |
|
3434 |
is no method for that selector). The original message has |
|
3435 |
been packed into aMessage (i.e. the receiver, selector and |
|
3436 |
any arguments) and the original receiver is then sent the |
|
3437 |
#doesNotUnderstand: message. |
|
3438 |
Here, we raise another signal which usually enters the debugger. |
|
3439 |
You can of course redefine #doesNotUnderstand: in your classes |
|
3440 |
to implement message delegation, |
|
3441 |
or handle the MessageNotUnderstoodSignal gracefully." |
|
3442 |
||
3443 |
<context: #return> |
|
3444 |
||
5821 | 3445 |
|sel selStr errorString cls| |
5755 | 3446 |
|
3447 |
sel := aMessage selector. |
|
3448 |
selStr := sel printString. |
|
3449 |
||
3450 |
"/ Although sel should always be a symbol, |
|
3451 |
"/ always use printStrings in the code below. |
|
3452 |
"/ Non-symbol selector may happen when things go mad in a primitive, |
|
3453 |
"/ or a method has been called by valueWithReceiver: with a wrong arg. |
|
3454 |
||
3455 |
"/ handle the case of an error during early startup |
|
3456 |
"/ (output streams not yet initialized) |
|
3457 |
||
3458 |
Stdout isNil ifTrue:[ |
|
3459 |
Smalltalk fatalAbort:'error during init: ' , selStr , ' not understood'. |
|
3460 |
]. |
|
3461 |
||
3462 |
"/ |
|
3463 |
"/ extract the class that should have implemented the message. |
|
3464 |
"/ (in case of a super-send, this is not the receivers class) |
|
3465 |
"/ |
|
3466 |
cls := thisContext sender searchClass. |
|
3467 |
cls isNil ifTrue:[ |
|
3468 |
"it was NOT a super or directed send ..." |
|
3469 |
cls := self class |
|
3470 |
]. |
|
3471 |
||
3472 |
cls notNil ifTrue:[ |
|
3473 |
"/ |
|
3474 |
"/ displayString is better than 'cls name', |
|
3475 |
"/ since it appends (obsolete) for outdated classes. |
|
3476 |
"/ (this happens if you send messages to old instances |
|
3477 |
"/ after changing a classes definition) |
|
3478 |
"/ |
|
3479 |
errorString := cls displayString. |
|
3480 |
] ifFalse:[ |
|
3481 |
errorString := '(** nil-class **)' |
|
3482 |
]. |
|
3483 |
sel class ~~ Symbol ifTrue:[ |
|
3484 |
errorString := errorString , ' nonSymbol selector: ' , selStr , ' not understood'. |
|
3485 |
] ifFalse:[ |
|
3486 |
errorString := errorString , ' does not understand: ' , selStr. |
|
3487 |
]. |
|
3488 |
||
3489 |
"/ |
|
3490 |
"/ this only happens, when YOU play around with my classvars ... |
|
3491 |
"/ (or an error occurs during very early startup, when signals are not yet set) |
|
3492 |
"/ |
|
3493 |
MessageNotUnderstoodSignal isNil ifTrue:[ |
|
3494 |
^ MiniDebugger |
|
3495 |
enterWithMessage:'oops - MessageNotUnderstoodSignal is gone (nil)' |
|
3496 |
mayProceed:true. |
|
3497 |
]. |
|
3498 |
||
3499 |
"/ |
|
3500 |
"/ thats where we end up normally - raise a signal which (if unhandled) opens a debugger |
|
3501 |
"/ |
|
3502 |
^ MessageNotUnderstoodSignal |
|
3503 |
raiseRequestWith:aMessage |
|
3504 |
errorString:errorString |
|
3505 |
||
3506 |
"Modified: / 9.6.1999 / 17:46:17 / cg" |
|
3507 |
! |
|
3508 |
||
3509 |
elementBoundsError |
|
3510 |
"{ Pragma: +optSpace }" |
|
3511 |
||
3512 |
"report an error that badElement is out of bounds |
|
3513 |
(i.e. cannot be put into that collection). |
|
3514 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
3515 |
||
3516 |
^ ElementOutOfBoundsSignal raise |
|
3517 |
||
3518 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
|
3519 |
! |
|
3520 |
||
3521 |
elementNotCharacter |
|
3522 |
"{ Pragma: +optSpace }" |
|
3523 |
||
3524 |
"report an error that object to be stored is no Character. |
|
3525 |
(usually when storing into Strings). |
|
3526 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
3527 |
||
3528 |
^ ElementOutOfBoundsSignal raise |
|
3529 |
||
3530 |
"Modified: 8.5.1996 / 09:12:49 / cg" |
|
3531 |
! |
|
3532 |
||
3533 |
elementNotInteger |
|
3534 |
"{ Pragma: +optSpace }" |
|
3535 |
||
3536 |
"report an error that object to be stored is not Integer. |
|
3537 |
(in collections that store integers only). |
|
3538 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
3539 |
||
3540 |
^ ElementOutOfBoundsSignal raise |
|
3541 |
||
3542 |
"Modified: 8.5.1996 / 09:12:51 / cg" |
|
3543 |
! |
|
3544 |
||
3545 |
error |
|
3546 |
"{ Pragma: +optSpace }" |
|
3547 |
||
3548 |
<context: #return> |
|
3549 |
||
3550 |
"report error that an error occured. |
|
3551 |
The error is reported by raising the Error exception, |
|
3552 |
which is non-proceedable. |
|
3553 |
If no handler has been setup, a debugger is entered." |
|
3554 |
||
3555 |
Error raiseWith:#error: |
|
3556 |
||
3557 |
" |
|
3558 |
nil error |
|
3559 |
" |
|
3560 |
||
3561 |
"Modified: / 8.5.1996 / 09:13:01 / cg" |
|
3562 |
"Modified: / 2.8.1999 / 17:00:19 / stefan" |
|
3563 |
! |
|
3564 |
||
3565 |
error:aString |
|
3566 |
"{ Pragma: +optSpace }" |
|
3567 |
||
3568 |
<context: #return> |
|
3569 |
||
3570 |
"Raise an error with error message aString. |
|
3571 |
The error is reported by raising the Error exception, |
|
3572 |
which is non-proceedable. |
|
3573 |
If no handler has been setup, a debugger is entered." |
|
3574 |
||
3575 |
Error raiseWith:#error: errorString:aString |
|
3576 |
||
3577 |
" |
|
3578 |
nil error:' bad bad bad' |
|
3579 |
" |
|
3580 |
||
3581 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
3582 |
! |
|
3583 |
||
3584 |
error:aString mayProceed:mayProceed |
|
3585 |
"{ Pragma: +optSpace }" |
|
3586 |
||
3587 |
"enter debugger with error-message aString. |
|
3588 |
The error is reported by raising either the |
|
3589 |
non-proceedable Error exception, |
|
3590 |
or the ProceedableError exception." |
|
3591 |
||
3592 |
mayProceed ifTrue:[ |
|
3593 |
^ ProceedableError raiseRequestWith:#error: errorString:aString |
|
3594 |
]. |
|
3595 |
||
3596 |
Error raiseWith:#error: errorString:aString |
|
3597 |
||
3598 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
3599 |
! |
|
3600 |
||
3601 |
errorKeyNotFound:aKey |
|
3602 |
"{ Pragma: +optSpace }" |
|
3603 |
||
3604 |
"report an error that a key was not found in a collection. |
|
3605 |
The error is reported by raising the KeyNotFoundSignal exception." |
|
3606 |
||
3607 |
^ KeyNotFoundSignal raiseRequestWith:aKey |
|
3608 |
||
3609 |
" |
|
3610 |
#(1 2) at:3 |
|
3611 |
" |
|
3612 |
! |
|
3613 |
||
3614 |
errorNotFound |
|
3615 |
"{ Pragma: +optSpace }" |
|
3616 |
||
3617 |
"report an error that no element was found in a collection. |
|
3618 |
The error is reported by raising the NotFoundSignal exception." |
|
3619 |
||
3620 |
^ NotFoundSignal raiseRequestWith:nil |
|
3621 |
||
3622 |
"Modified: / 8.5.1996 / 09:13:11 / cg" |
|
3623 |
"Modified: / 26.7.1999 / 10:51:50 / stefan" |
|
3624 |
! |
|
3625 |
||
3626 |
errorSignal |
|
3627 |
^ self class errorSignal |
|
3628 |
||
3629 |
"Created: / 19.6.1998 / 02:32:32 / cg" |
|
3630 |
! |
|
3631 |
||
3632 |
halt |
|
3633 |
"{ Pragma: +optSpace }" |
|
3634 |
||
3635 |
"enter debugger with halt-message. |
|
3636 |
The error is reported by raising the HaltSignal exception." |
|
3637 |
||
3638 |
^ HaltSignal raiseRequestWith:#halt |
|
3639 |
||
3640 |
"Modified: / 8.5.1996 / 09:12:38 / cg" |
|
3641 |
"Modified: / 2.8.1999 / 17:00:29 / stefan" |
|
3642 |
! |
|
3643 |
||
3644 |
halt:aString |
|
3645 |
"{ Pragma: +optSpace }" |
|
3646 |
||
3647 |
"enter debugger with halt-message. |
|
3648 |
The error is reported by raising the HaltSignal exception." |
|
3649 |
||
3650 |
^ HaltSignal raiseRequestWith:#halt: errorString:aString |
|
3651 |
||
3652 |
"Modified: 8.5.1996 / 09:13:23 / cg" |
|
3653 |
! |
|
3654 |
||
3655 |
implementedBySubclass |
|
3656 |
"{ Pragma: +optSpace }" |
|
3657 |
||
3658 |
"this is sent by ST/V code - its the same as #subclassResponsibility" |
|
3659 |
||
3660 |
^ self subclassResponsibility |
|
3661 |
! |
|
3662 |
||
3663 |
indexNotInteger |
|
3664 |
"{ Pragma: +optSpace }" |
|
3665 |
||
3666 |
"report an error that index is not an Integer. |
|
3667 |
(when accessing collections indexed by an integer key). |
|
3668 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
3669 |
||
3670 |
^ NonIntegerIndexSignal raiseRequestWith:nil |
|
3671 |
||
3672 |
"Modified: / 8.5.1996 / 09:13:37 / cg" |
|
3673 |
"Modified: / 26.7.1999 / 10:57:43 / stefan" |
|
3674 |
! |
|
3675 |
||
3676 |
indexNotInteger:anIndex |
|
3677 |
"{ Pragma: +optSpace }" |
|
3678 |
||
3679 |
"report an error that index is not an Integer. |
|
3680 |
(when accessing collections indexed by an integer key). |
|
3681 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
3682 |
||
3683 |
^ NonIntegerIndexSignal raiseRequestWith:anIndex |
|
3684 |
||
3685 |
"Created: / 16.5.1998 / 19:39:41 / cg" |
|
3686 |
! |
|
3687 |
||
3688 |
integerCheckError |
|
3689 |
"{ Pragma: +optSpace }" |
|
3690 |
||
3691 |
"generated when a variable declared with an integer type gets a bad |
|
3692 |
value assigned" |
|
3693 |
||
3694 |
^ self error:'bad assign of ' , self printString , |
|
3695 |
' (' , self class name , ') to integer-typed variable' |
|
3696 |
! |
|
3697 |
||
3698 |
invalidCodeObject |
|
3699 |
"{ Pragma: +optSpace }" |
|
3700 |
||
3701 |
self error:'not an executable code object' |
|
3702 |
||
3703 |
"Created: 1.8.1997 / 00:16:44 / cg" |
|
3704 |
! |
|
3705 |
||
3706 |
invalidMessage |
|
3707 |
"{ Pragma: +optSpace }" |
|
3708 |
||
3709 |
"this is sent by ST/V code - its the same as #shouldNotImplement" |
|
3710 |
||
3711 |
^ self shouldNotImplement |
|
3712 |
! |
|
3713 |
||
3714 |
mustBeRectangle |
|
3715 |
"{ Pragma: +optSpace }" |
|
3716 |
||
3717 |
"report an argument-not-rectangle-error" |
|
3718 |
||
3719 |
^ self error:'argument must be a Rectangle' |
|
3720 |
! |
|
3721 |
||
3722 |
mustBeString |
|
3723 |
"{ Pragma: +optSpace }" |
|
3724 |
||
3725 |
"report an argument-not-string-error" |
|
3726 |
||
3727 |
^ self error:'argument must be a String' |
|
3728 |
! |
|
3729 |
||
3730 |
notIndexed |
|
3731 |
"{ Pragma: +optSpace }" |
|
3732 |
||
3733 |
<context: #return> |
|
3734 |
||
3735 |
"report an error that receiver has no indexed instance variables. |
|
3736 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
3737 |
||
3738 |
^ SubscriptOutOfBoundsSignal |
|
3739 |
raiseErrorString:'receiver has no indexed variables' |
|
3740 |
||
3741 |
"Modified: 26.7.1996 / 16:43:13 / cg" |
|
3742 |
! |
|
3743 |
||
3744 |
openDebuggerOnException:ex |
|
3745 |
"{ Pragma: +optSpace }" |
|
3746 |
||
3747 |
"enter the debugger on some unhandled exception" |
|
3748 |
||
3749 |
|msgString debugger| |
|
3750 |
||
3751 |
msgString := ex errorString. |
|
3752 |
||
3753 |
" |
|
3754 |
if there is no debugger, |
|
3755 |
ask for ignore or exit. Exit will terminate the applciation. |
|
3756 |
ignore will raise an abortSignal. |
|
3757 |
" |
|
3758 |
Debugger isNil ifTrue:[ |
|
3759 |
msgString := 'error: ' , msgString. |
|
3760 |
||
3761 |
Smalltalk isStandAloneApp ifTrue:[ |
|
3762 |
Dialog notNil ifTrue:[ |
|
3763 |
(Dialog |
|
3764 |
confirm:msgString |
|
3765 |
title:(Smalltalk commandName) |
|
3766 |
yesLabel:'ignore' noLabel:'exit' |
|
3767 |
) ifTrue:[ |
|
3768 |
^ AbortSignal raise |
|
3769 |
] |
|
3770 |
]. |
|
3771 |
msgString errorPrintCR. |
|
3772 |
OperatingSystem exit:1 |
|
3773 |
]. |
|
3774 |
||
3775 |
msgString errorPrintCR. |
|
3776 |
Smalltalk fatalAbort:'no Debugger defined' |
|
3777 |
]. |
|
3778 |
||
3779 |
" |
|
3780 |
find an appropriate debugger to use |
|
3781 |
" |
|
3782 |
debugger := self appropriateDebugger:(thisContext selector). |
|
3783 |
debugger isNil ifTrue:[ |
|
3784 |
^ AbortSignal raise |
|
3785 |
]. |
|
3786 |
||
3787 |
^ debugger |
|
3788 |
enter:ex suspendedContext |
|
3789 |
withMessage:msgString |
|
3790 |
mayProceed:(ex mayProceed). |
|
3791 |
||
3792 |
"Modified: 24.7.1997 / 10:09:20 / cg" |
|
3793 |
||
3794 |
! |
|
3795 |
||
3796 |
primitiveFailed |
|
3797 |
"{ Pragma: +optSpace }" |
|
3798 |
||
3799 |
"report an error that some primitive code failed. |
|
3800 |
The error is reported by raising the PrimitiveFailureSignal exception." |
|
3801 |
||
3802 |
^ PrimitiveFailureSignal raiseRequestWith:nil |
|
3803 |
||
3804 |
"Modified: / 8.5.1996 / 09:14:07 / cg" |
|
3805 |
"Modified: / 26.7.1999 / 10:58:08 / stefan" |
|
3806 |
! |
|
3807 |
||
3808 |
shouldNotImplement |
|
3809 |
"{ Pragma: +optSpace }" |
|
3810 |
||
3811 |
"report an error that this message should not be implemented" |
|
3812 |
||
3813 |
^ self error:'method not appropriate for this class' |
|
3814 |
||
3815 |
"Modified: 8.5.1996 / 09:09:44 / cg" |
|
3816 |
! |
|
3817 |
||
3818 |
subclassResponsibility |
|
3819 |
"{ Pragma: +optSpace }" |
|
3820 |
||
3821 |
"report an error that this message should have been reimplemented in a |
|
3822 |
subclass" |
|
3823 |
||
3824 |
^ self error:'method must be reimplemented in subclass' mayProceed:true |
|
3825 |
||
3826 |
"Modified: 8.5.1996 / 09:09:26 / cg" |
|
3827 |
! |
|
3828 |
||
3829 |
subscriptBoundsError |
|
3830 |
"{ Pragma: +optSpace }" |
|
3831 |
||
3832 |
"report an error that some index is out of bounds. |
|
3833 |
(when accessing indexable collections). |
|
3834 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
3835 |
||
3836 |
^ SubscriptOutOfBoundsSignal raiseRequestWith:nil |
|
3837 |
||
3838 |
"Modified: / 26.7.1996 / 16:45:42 / cg" |
|
3839 |
"Modified: / 26.7.1999 / 10:58:27 / stefan" |
|
3840 |
! |
|
3841 |
||
3842 |
subscriptBoundsError:anIndex |
|
3843 |
"{ Pragma: +optSpace }" |
|
3844 |
||
3845 |
"report an error that anIndex is out of bounds. |
|
3846 |
(when accessing indexable collections). |
|
3847 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
3848 |
||
3849 |
^ SubscriptOutOfBoundsSignal |
|
3850 |
raiseRequestWith:anIndex |
|
3851 |
errorString:('subscript (' , anIndex printString , ') out of bounds') |
|
3852 |
||
3853 |
"Modified: 8.5.1996 / 09:14:34 / cg" |
|
3854 |
! |
|
3855 |
||
3856 |
typeCheckError |
|
3857 |
"{ Pragma: +optSpace }" |
|
3858 |
||
3859 |
"generated when a variable declared with a type hint gets a bad |
|
3860 |
value assigned" |
|
3861 |
||
3862 |
^ self error:'bad assign of ' , self printString , |
|
3863 |
' (' , self class name , ') to typed variable' |
|
3864 |
! ! |
|
3865 |
||
3866 |
!Object methodsFor:'evaluation'! |
|
3867 |
||
3868 |
value |
|
3869 |
"return the receiver itself. |
|
3870 |
This allows every object to be used where blocks or valueHolders |
|
3871 |
are typically used, and allows for valueHolders and blocks to be |
|
3872 |
used interchangably in some situations. |
|
3873 |
||
3874 |
Time will show, if this is a good idea or leads to sloppy programming |
|
3875 |
style ... (the idea was borrowed from the Self language). |
|
3876 |
||
3877 |
WARNING: dont 'optimize' away ifXXX: blocks |
|
3878 |
(i.e. do NOT replace |
|
3879 |
foo ifTrue:[var1] ifFalse:[var2] |
|
3880 |
by: |
|
3881 |
foo ifTrue:var1 ifFalse:var2 |
|
3882 |
) |
|
3883 |
- the compilers will only generate inline code for the if, |
|
3884 |
iff the argument(s) are blocks - otherwise, a true send is |
|
3885 |
generated. |
|
3886 |
This 'oprimization' will work semantically correct, |
|
3887 |
but execute SLOWER instead." |
|
3888 |
||
3889 |
^ self |
|
3890 |
||
3891 |
" |
|
3892 |
#(1 2 3 4) indexOf:5 ifAbsent:0 |
|
3893 |
#(1 2 3 4) indexOf:5 ifAbsent:[0] |
|
3894 |
1 > 2 ifTrue:['yes'] ifFalse:['no'] |
|
3895 |
1 > 2 ifTrue:'yes' ifFalse:'no' |
|
3896 |
" |
|
3897 |
||
3898 |
"DO NOT DO THIS (its slower) |
|
3899 |
(1 > 4) ifTrue:'oops' ifFalse:'ok' |
|
3900 |
||
3901 |
USE (the compiler optimizes blocks in if/while): |
|
3902 |
(1 > 4) ifTrue:['oops'] ifFalse:['ok'] |
|
3903 |
" |
|
3904 |
||
3905 |
"Modified: 3.5.1996 / 11:57:08 / cg" |
|
3906 |
! ! |
|
3907 |
||
3908 |
!Object methodsFor:'finalization'! |
|
3909 |
||
3910 |
disposed |
|
3911 |
"this is invoked for objects which have been registered |
|
3912 |
in a Registry, when the original object dies. |
|
3913 |
Subclasses may redefine this method" |
|
3914 |
||
3915 |
^ self |
|
3916 |
||
3917 |
"Created: / 4.3.1998 / 10:40:30 / stefan" |
|
3918 |
! |
|
3919 |
||
3920 |
executor |
|
3921 |
"for VW & Squeak compatibility. |
|
3922 |
Return the object which does the finalization for me." |
|
3923 |
||
3924 |
^ self shallowCopyForFinalization |
|
3925 |
||
3926 |
"Created: / 5.8.1999 / 14:06:19 / cg" |
|
3927 |
! |
|
3928 |
||
3929 |
finalize |
|
3930 |
"For ST80 compatibility; ST/X uses #disposed when registered |
|
3931 |
objects are finalized. This may change." |
|
3932 |
||
3933 |
^ self |
|
3934 |
||
3935 |
"Created: / 4.3.1998 / 10:40:30 / stefan" |
|
3936 |
! |
|
3937 |
||
3938 |
reRegisterForFinalization |
|
3939 |
"re-register mySelf for later finalization. |
|
3940 |
This will create a new executor, which will receive a #disposed message when |
|
3941 |
the receiver is garbage collected." |
|
3942 |
||
3943 |
FinalizationLobby isNil ifTrue:[ |
|
3944 |
FinalizationLobby := Registry new. |
|
3945 |
]. |
|
3946 |
FinalizationLobby registerChange:self |
|
3947 |
||
3948 |
! |
|
3949 |
||
3950 |
registerForFinalization |
|
3951 |
"register mySelf for later finalization. |
|
3952 |
Once registered, the executor of the receiver will receive a #disposed message when |
|
3953 |
the receiver is garbage collected." |
|
3954 |
||
3955 |
FinalizationLobby isNil ifTrue:[ |
|
3956 |
FinalizationLobby := Registry new. |
|
3957 |
]. |
|
3958 |
FinalizationLobby register:self |
|
3959 |
||
3960 |
! |
|
3961 |
||
3962 |
unregisterForFinalization |
|
3963 |
"unregister mySelf from later finalization" |
|
3964 |
||
3965 |
FinalizationLobby notNil ifTrue:[ |
|
3966 |
FinalizationLobby unregister:self |
|
3967 |
] |
|
3968 |
! ! |
|
3969 |
||
3970 |
!Object methodsFor:'initialization'! |
|
3971 |
||
3972 |
initialize |
|
3973 |
"just to ignore initialize to objects which do not need it" |
|
3974 |
||
3975 |
^ self |
|
3976 |
! ! |
|
3977 |
||
3978 |
!Object methodsFor:'interest'! |
|
3979 |
||
3980 |
addInterest:anInterest |
|
3981 |
"install an interest forwarder. |
|
3982 |
Here, we use the nonWeakDependencies." |
|
3983 |
||
3984 |
self addNonWeakDependent:anInterest |
|
3985 |
||
3986 |
"Created: 14.10.1996 / 22:27:34 / stefan" |
|
3987 |
! |
|
3988 |
||
3989 |
expressInterestIn:aspect for:anObject sendBack:aSelector |
|
3990 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
3991 |
changes aspect." |
|
3992 |
||
3993 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
3994 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
3995 |
||
3996 |
self addInterest:(InterestConverter |
|
3997 |
destination:anObject |
|
3998 |
selector:aSelector |
|
3999 |
aspect:aspect) |
|
4000 |
||
4001 |
" |
|
4002 |
|p b| |
|
4003 |
||
4004 |
b := [Transcript showCR:' -> the point changed']. |
|
4005 |
||
4006 |
p := Point new. |
|
4007 |
Transcript showCR:'interest in #foo:'. |
|
4008 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
4009 |
p x:1. |
|
4010 |
Transcript showCR:'now changing #bar ... (expect no notification)'. |
|
4011 |
p changed:#bar. |
|
4012 |
Transcript cr. |
|
4013 |
||
4014 |
Delay waitForSeconds:1. |
|
4015 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
|
4016 |
p changed:#foo. |
|
4017 |
Transcript cr. |
|
4018 |
||
4019 |
Delay waitForSeconds:1. |
|
4020 |
Transcript showCR:'no more interest in #foo:'. |
|
4021 |
p retractInterestIn:#foo for:b. |
|
4022 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
4023 |
p changed:#foo. |
|
4024 |
Transcript cr. |
|
4025 |
||
4026 |
Delay waitForSeconds:1. |
|
4027 |
Transcript showCR:'interest in #bar now:'. |
|
4028 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
4029 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
4030 |
p changed:#foo. |
|
4031 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
|
4032 |
p changed:#bar. |
|
4033 |
Transcript cr. |
|
4034 |
||
4035 |
Delay waitForSeconds:1. |
|
4036 |
Transcript showCR:'interest in #foo now:'. |
|
4037 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
4038 |
Transcript showCR:'now changing #foo ... (expect notification)'. |
|
4039 |
p changed:#foo. |
|
4040 |
Transcript showCR:'now changing #bar ... (expect notification)'. |
|
4041 |
p changed:#bar. |
|
4042 |
Transcript cr. |
|
4043 |
||
4044 |
Delay waitForSeconds:1. |
|
4045 |
Transcript showCR:'no more interests:'. |
|
4046 |
p retractInterestsFor:b. |
|
4047 |
Transcript showCR:'now changing #foo ... (expect no notification)'. |
|
4048 |
p changed:#foo. |
|
4049 |
Transcript showCR:'now changing #bar... (expect no notification)'. |
|
4050 |
p changed:#bar. |
|
4051 |
Transcript cr. |
|
4052 |
||
4053 |
p release. |
|
4054 |
" |
|
4055 |
||
4056 |
"Created: 19.4.1996 / 10:26:22 / cg" |
|
4057 |
"Modified: 19.4.1996 / 12:34:08 / cg" |
|
4058 |
"Modified: 14.10.1996 / 22:28:20 / stefan" |
|
4059 |
! |
|
4060 |
||
4061 |
interests |
|
4062 |
"return a Collection of interests - empty if there is none. |
|
4063 |
Here, we use the nonWeakDependents for interests." |
|
4064 |
||
4065 |
^ self nonWeakDependents |
|
4066 |
||
4067 |
"Created: / 14.10.1996 / 22:20:51 / stefan" |
|
4068 |
"Modified: / 30.1.1998 / 14:07:35 / cg" |
|
4069 |
! |
|
4070 |
||
4071 |
interestsFor:someOne |
|
4072 |
"return a collection of interests of someOne - empty if there is none." |
|
4073 |
||
4074 |
|coll deps| |
|
4075 |
||
4076 |
deps := self interests. |
|
4077 |
deps size == 0 ifTrue:[^ #()]. |
|
4078 |
||
4079 |
coll := IdentitySet new. |
|
4080 |
||
4081 |
deps do:[:dep | |
|
4082 |
(dep isMemberOf:InterestConverter) ifTrue:[ |
|
4083 |
dep destination == someOne ifTrue:[ |
|
4084 |
coll add:dep. |
|
4085 |
] |
|
4086 |
] |
|
4087 |
]. |
|
4088 |
^ coll |
|
4089 |
||
4090 |
"Created: / 30.1.1998 / 14:02:26 / cg" |
|
4091 |
"Modified: / 30.1.1998 / 14:08:24 / cg" |
|
4092 |
! |
|
4093 |
||
4094 |
onChangeEvaluate:aBlock |
|
4095 |
"arrange for aBlock to be evaluated whenever the receiver changes." |
|
4096 |
||
4097 |
^ self onChangeSend:#value to:aBlock |
|
4098 |
||
4099 |
"Created: / 29.1.1999 / 16:01:22 / cg" |
|
4100 |
! |
|
4101 |
||
4102 |
onChangeSend:aSelector to:anObject |
|
4103 |
"arrange for aSelector to be sent to anObject whenever the receiver |
|
4104 |
changes." |
|
4105 |
||
4106 |
"/ for now, use an interestConverter, which is somewhat less efficient. |
|
4107 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
4108 |
||
4109 |
self addInterest:(InterestConverter |
|
4110 |
destination:anObject |
|
4111 |
selector:aSelector) |
|
4112 |
||
4113 |
" |
|
4114 |
|p b| |
|
4115 |
||
4116 |
b := [Transcript showCR:'the point changed']. |
|
4117 |
||
4118 |
p := Point new. |
|
4119 |
p onChangeSend:#value to:b. |
|
4120 |
p x:1. |
|
4121 |
Transcript showCR:'now changing'. |
|
4122 |
p changed. |
|
4123 |
Transcript cr. |
|
4124 |
||
4125 |
Delay waitForSeconds:1. |
|
4126 |
Transcript showCR:'now changing'. |
|
4127 |
p changed. |
|
4128 |
Transcript cr. |
|
4129 |
||
4130 |
Delay waitForSeconds:1. |
|
4131 |
Transcript showCR:'no more interest'. |
|
4132 |
p retractInterestsFor:b. |
|
4133 |
Transcript showCR:'now changing again'. |
|
4134 |
p changed. |
|
4135 |
Transcript cr. |
|
4136 |
||
4137 |
Delay waitForSeconds:1. |
|
4138 |
Transcript showCR:'interest again'. |
|
4139 |
p onChangeSend:#value to:b. |
|
4140 |
Transcript showCR:'now changing again'. |
|
4141 |
p changed. |
|
4142 |
Transcript cr. |
|
4143 |
" |
|
4144 |
||
4145 |
"Created: 19.4.1996 / 10:26:38 / cg" |
|
4146 |
"Modified: 19.4.1996 / 12:34:26 / cg" |
|
4147 |
"Modified: 14.10.1996 / 22:28:27 / stefan" |
|
4148 |
! |
|
4149 |
||
4150 |
removeInterest:anInterest |
|
4151 |
"remove an interest forwarder. |
|
4152 |
Here, we use the nonWeakDependencies." |
|
4153 |
||
4154 |
self removeNonWeakDependent:anInterest |
|
4155 |
||
4156 |
"Created: 14.10.1996 / 22:21:59 / stefan" |
|
4157 |
! |
|
4158 |
||
4159 |
retractInterestIn:aspect for:someOne |
|
4160 |
"remove the interest of someOne in the receiver changing aspect |
|
4161 |
(as installed with #expressInterestIn:for:sendBack:)." |
|
4162 |
||
4163 |
"/ for now, remove the interestConverter. |
|
4164 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
4165 |
||
4166 |
"/ cannot removeDependent within the loop - the collection rehashes |
|
4167 |
||
4168 |
|deps coll| |
|
4169 |
||
4170 |
deps := self interests. |
|
4171 |
deps size ~~ 0 ifTrue:[ |
|
4172 |
coll := IdentitySet new. |
|
4173 |
||
4174 |
deps do:[:dep | |
|
4175 |
(dep isMemberOf:InterestConverter) ifTrue:[ |
|
4176 |
dep destination == someOne ifTrue:[ |
|
4177 |
dep aspect == aspect ifTrue:[ |
|
4178 |
self removeInterest:dep. |
|
4179 |
^ self |
|
4180 |
] |
|
4181 |
] |
|
4182 |
] |
|
4183 |
]. |
|
4184 |
coll do:[:dep | |
|
4185 |
self removeInterest:dep. |
|
4186 |
]. |
|
4187 |
]. |
|
4188 |
||
4189 |
||
4190 |
" |
|
4191 |
|p b| |
|
4192 |
||
4193 |
b := [Transcript showCR:'the point changed']. |
|
4194 |
||
4195 |
p := Point new. |
|
4196 |
Transcript showCR:'interest in #foo'. |
|
4197 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
4198 |
p x:1. |
|
4199 |
Transcript showCR:'now changing #bar'. |
|
4200 |
p changed:#bar. |
|
4201 |
Transcript cr. |
|
4202 |
||
4203 |
Delay waitForSeconds:1. |
|
4204 |
Transcript showCR:'now changing #foo'. |
|
4205 |
p changed:#foo. |
|
4206 |
Transcript cr. |
|
4207 |
||
4208 |
Delay waitForSeconds:1. |
|
4209 |
Transcript showCR:'no more interest in #foo'. |
|
4210 |
p retractInterestIn:#foo for:b. |
|
4211 |
Transcript showCR:'now changing #foo'. |
|
4212 |
p changed:#foo. |
|
4213 |
Transcript cr. |
|
4214 |
||
4215 |
Delay waitForSeconds:1. |
|
4216 |
Transcript showCR:'interest in #bar now'. |
|
4217 |
p expressInterestIn:#bar for:b sendBack:#value. |
|
4218 |
Transcript showCR:'now changing #foo'. |
|
4219 |
p changed:#foo. |
|
4220 |
Transcript showCR:'now changing #bar'. |
|
4221 |
p changed:#bar. |
|
4222 |
Transcript cr. |
|
4223 |
||
4224 |
Delay waitForSeconds:1. |
|
4225 |
Transcript showCR:'interest in #foo now'. |
|
4226 |
p expressInterestIn:#foo for:b sendBack:#value. |
|
4227 |
Transcript showCR:'now changing #foo'. |
|
4228 |
p changed:#foo. |
|
4229 |
Transcript showCR:'now changing #bar'. |
|
4230 |
p changed:#bar. |
|
4231 |
Transcript cr. |
|
4232 |
||
4233 |
Delay waitForSeconds:1. |
|
4234 |
Transcript showCR:'no more interests'. |
|
4235 |
p retractInterestsFor:b. |
|
4236 |
Transcript showCR:'now changing #foo'. |
|
4237 |
p changed:#foo. |
|
4238 |
Transcript showCR:'now changing #bar'. |
|
4239 |
p changed:#bar. |
|
4240 |
Transcript cr. |
|
4241 |
" |
|
4242 |
||
4243 |
"Created: / 19.4.1996 / 10:27:11 / cg" |
|
4244 |
"Modified: / 14.10.1996 / 22:21:19 / stefan" |
|
4245 |
"Modified: / 30.1.1998 / 14:05:34 / cg" |
|
4246 |
! |
|
4247 |
||
4248 |
retractInterestsFor:someOne |
|
4249 |
"remove the interest of someOne in the receiver |
|
4250 |
(as installed with #onChangeSend:to:)." |
|
4251 |
||
4252 |
"/ for now, remove the interestConverter. |
|
4253 |
"/ In the future, a more intelligent DependencyCollection class is planned for |
|
4254 |
||
4255 |
|coll deps| |
|
4256 |
||
4257 |
"/ cannot removeDependent within the loop - the collection rehashes |
|
4258 |
||
4259 |
deps := self interests. |
|
4260 |
deps size ~~ 0 ifTrue:[ |
|
4261 |
coll := IdentitySet new. |
|
4262 |
||
4263 |
deps do:[:dep | |
|
4264 |
(dep isMemberOf:InterestConverter) ifTrue:[ |
|
4265 |
dep destination == someOne ifTrue:[ |
|
4266 |
coll add:dep. |
|
4267 |
] |
|
4268 |
] |
|
4269 |
]. |
|
4270 |
coll do:[:dep | |
|
4271 |
self removeInterest:dep. |
|
4272 |
]. |
|
4273 |
]. |
|
4274 |
||
4275 |
||
4276 |
||
4277 |
" |
|
4278 |
|p b| |
|
4279 |
||
4280 |
b := [Transcript showCR:'the point changed']. |
|
4281 |
||
4282 |
p := Point new. |
|
4283 |
p onChangeSend:#value to:b. |
|
4284 |
p x:1. |
|
4285 |
Transcript showCR:'now changing'. |
|
4286 |
p changed. |
|
4287 |
Transcript cr. |
|
4288 |
||
4289 |
Delay waitForSeconds:1. |
|
4290 |
Transcript showCR:'now changing'. |
|
4291 |
p changed. |
|
4292 |
Transcript cr. |
|
4293 |
||
4294 |
Delay waitForSeconds:1. |
|
4295 |
Transcript showCR:'no more interest'. |
|
4296 |
p retractInterestsFor:b. |
|
4297 |
Transcript showCR:'now changing again'. |
|
4298 |
p changed. |
|
4299 |
Transcript cr. |
|
4300 |
||
4301 |
Delay waitForSeconds:1. |
|
4302 |
Transcript showCR:'interest again'. |
|
4303 |
p onChangeSend:#value to:b. |
|
4304 |
Transcript showCR:'now changing again'. |
|
4305 |
p changed. |
|
4306 |
Transcript cr. |
|
4307 |
" |
|
4308 |
||
4309 |
"Created: / 19.4.1996 / 10:23:46 / cg" |
|
4310 |
"Modified: / 14.10.1996 / 22:21:25 / stefan" |
|
4311 |
"Modified: / 30.1.1998 / 14:04:52 / cg" |
|
4312 |
! ! |
|
4313 |
||
4314 |
!Object methodsFor:'interrupt handling'! |
|
4315 |
||
4316 |
childSignalInterrupt |
|
4317 |
"death of a child process (unix process) - do nothing" |
|
4318 |
||
4319 |
^ self |
|
4320 |
! |
|
4321 |
||
4322 |
customInterrupt |
|
4323 |
"{ Pragma: +optSpace }" |
|
4324 |
||
4325 |
"a custom interrupt - but no handler has defined" |
|
4326 |
||
4327 |
self error:'custom interrupt' mayProceed:true |
|
4328 |
! |
|
4329 |
||
4330 |
errorInterrupt:errorID with:aParameter |
|
4331 |
"subsystem error. The arguments errorID and aParameter are the values passed |
|
4332 |
to the 'errorInterruptWithIDAndParameter(id, param)' function, |
|
4333 |
which can be called from C subsystems to raise an (asynchronous) |
|
4334 |
error exception. |
|
4335 |
||
4336 |
Currently, this is used to map XErrors to smalltalk errors, but can be |
|
4337 |
used from other C subsystems too, to upcast errors. |
|
4338 |
Especially, for subsystems which call errorHandler functions asynchronously. |
|
4339 |
IDs (currently) used: |
|
4340 |
#DisplayError ..... x-error interrupt |
|
4341 |
#XtError ..... xt-error interrupt (Xt interface is not yet published) |
|
4342 |
" |
|
4343 |
||
4344 |
|handler| |
|
4345 |
||
4346 |
handler := ObjectMemory registeredErrorInterruptHandlers at:errorID ifAbsent:nil. |
|
4347 |
handler notNil ifTrue:[ |
|
4348 |
"/ |
|
4349 |
"/ handler found; let it do whatever it wants ... |
|
4350 |
"/ |
|
4351 |
handler errorInterrupt:errorID with:aParameter. |
|
4352 |
^ self |
|
4353 |
]. |
|
4354 |
||
4355 |
"/ |
|
4356 |
"/ no handler - raise errorSignal passing the errorId as parameter |
|
4357 |
"/ |
|
4358 |
^ ErrorSignal |
|
4359 |
raiseRequestWith:errorID |
|
4360 |
errorString:('Subsystem error. ErrorID = ' , errorID printString) |
|
4361 |
! |
|
4362 |
||
4363 |
exceptionInterrupt |
|
4364 |
"{ Pragma: +optSpace }" |
|
4365 |
||
4366 |
"exception interrupt - enter debugger" |
|
4367 |
||
4368 |
self error:'exception Interrupt' mayProceed:true |
|
4369 |
! |
|
4370 |
||
4371 |
fpExceptionInterrupt |
|
4372 |
"{ Pragma: +optSpace }" |
|
4373 |
||
4374 |
"a floating point exception occured - this one |
|
4375 |
has to be handled differently since it comes asynchronous |
|
4376 |
on some machines (for example, on machines with a separate FPU |
|
4377 |
or superscalar architectures. Also, errors from within primitive code |
|
4378 |
(or library functions such as GL) are sent via the Unix-signal |
|
4379 |
mechanism this way." |
|
4380 |
||
4381 |
|where rec| |
|
4382 |
||
4383 |
where := thisContext sender. |
|
4384 |
rec := where receiver. |
|
4385 |
rec isNumber ifTrue:[ |
|
4386 |
^ rec class |
|
4387 |
raise:#domainErrorSignal |
|
4388 |
receiver:rec |
|
4389 |
selector:where selector |
|
4390 |
arguments:(where args asArray) |
|
4391 |
errorString:'floating point exception' |
|
4392 |
]. |
|
4393 |
||
4394 |
"/ could be in some C-library ... |
|
4395 |
^ Float domainErrorSignal raise |
|
4396 |
! |
|
4397 |
||
4398 |
internalError:msg |
|
4399 |
"{ Pragma: +optSpace }" |
|
4400 |
||
4401 |
"this is triggered, when VM hits some bad error, |
|
4402 |
such as corrupted class, corrupted method/selector array |
|
4403 |
etc. The argument string gives some more information on what happened. |
|
4404 |
(for example, if you set an objects class to a non-behavior, nil etc.). |
|
4405 |
Its not guaranteed, that the system is in a working condition once |
|
4406 |
this error occurred ...." |
|
4407 |
||
4408 |
InternalErrorSignal raiseWith:self errorString:msg |
|
4409 |
! |
|
4410 |
||
4411 |
ioInterrupt |
|
4412 |
"{ Pragma: +optSpace }" |
|
4413 |
||
4414 |
"I/O (SIGIO/SIGPOLL) interrupt (supposed to be sent to Processor). |
|
4415 |
If we arrive here, there is either no handler (ObjMem>>ioInterruptHandler) |
|
4416 |
or it does not understand the ioInterrupt message. |
|
4417 |
In any case, this is a sign of some big trouble. Enter debugger." |
|
4418 |
||
4419 |
self error:'I/O Interrupt - but no handler' mayProceed:true |
|
4420 |
! |
|
4421 |
||
4422 |
memoryInterrupt |
|
4423 |
"{ Pragma: +optSpace }" |
|
4424 |
||
4425 |
"out-of-memory interrupt and no handler - enter debugger" |
|
4426 |
||
4427 |
self error:'almost out of memory' mayProceed:true |
|
4428 |
! |
|
4429 |
||
4430 |
recursionInterrupt |
|
4431 |
"{ Pragma: +optSpace }" |
|
4432 |
||
4433 |
"recursion limit (actually: stack overflow) interrupt. |
|
4434 |
This interrupt is triggered, when a process stack grows above |
|
4435 |
its stackLimit - usually, this leads into the debugger, but |
|
4436 |
could be caught and the stackLimit increased in the handler. |
|
4437 |
At the time we arrive here, the system has still some stack |
|
4438 |
as a reserve so we can continue to do some useful work or cleanup or |
|
4439 |
debugging for a while. |
|
4440 |
If the signal is ignored, and the stack continues to grow, there |
|
4441 |
will be a few more chances (and more interrupts) before the VM |
|
4442 |
hard-terminates the process." |
|
4443 |
||
4444 |
|con remaining| |
|
4445 |
||
4446 |
(con := thisContext) isRecursive ifFalse:[ |
|
4447 |
"/ Processor activeProcess usedStackSize < Processor activeProcess maximumStackSize ifTrue:[ |
|
4448 |
"/ "/ mhmh - it hit me, but I am not responsible ... |
|
4449 |
"/ 'Stray recursionInterrupt ...' infoPrintCR. |
|
4450 |
"/ ^ self |
|
4451 |
"/ ]. |
|
4452 |
'Object [info]: recursionInterrupt from:' printCR. |
|
4453 |
con := con sender. |
|
4454 |
remaining := 50. |
|
4455 |
[con notNil and:[remaining > 0]] whileTrue:[ |
|
4456 |
'| ' print. con fullPrint. |
|
4457 |
con := con sender. |
|
4458 |
remaining := remaining - 1 |
|
4459 |
]. |
|
4460 |
^ RecursionInterruptSignal raise |
|
4461 |
] |
|
4462 |
||
4463 |
"Modified: / 25.9.1999 / 18:28:11 / cg" |
|
4464 |
! |
|
4465 |
||
4466 |
schedulerInterrupt |
|
4467 |
"{ Pragma: +optSpace }" |
|
4468 |
||
4469 |
"scheduler interrupt (supposed to be sent to Processor). |
|
4470 |
If we arrive here, either the Processor does not understand it, |
|
4471 |
or it has been set to nil. In any case, this is a sign of some |
|
4472 |
big trouble. Enter debugger." |
|
4473 |
||
4474 |
self error:'schedulerInterrupt - but no Processor' mayProceed:true |
|
4475 |
! |
|
4476 |
||
4477 |
signalInterrupt:signalNumber |
|
4478 |
"{ Pragma: +optSpace }" |
|
4479 |
||
4480 |
"unix signal occured - some signals are handled as Smalltalk Exceptions |
|
4481 |
(SIGPIPE), others (SIGBUS) are rather fatal ... |
|
4482 |
In any case, IF a smalltalk-signal has been connected to the OS signal, |
|
4483 |
that one is raised. |
|
4484 |
Otherwise, a dialog is shown, asking the user on how to handle the |
|
4485 |
signal. |
|
4486 |
TODO: add another argument, giving more detailed signal info (PC, VADDR, |
|
4487 |
exact cause etc.). This helps if segvs occur in primitive code. |
|
4488 |
Currently (temporary kludge), these are passed as global variables." |
|
4489 |
||
4490 |
|box name here sig ignorable titles actions badContext msg pc addr |
|
4491 |
action title| |
|
4492 |
||
4493 |
" |
|
4494 |
special case - since SIGPIPE has an ST-signal associated |
|
4495 |
" |
|
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4496 |
(signalNumber == 13 "OperatingSystem sigPIPE") ifTrue:[ |
5755 | 4497 |
"SIGPIPE - write on a pipe with no one to read" |
4498 |
||
4499 |
^ PipeStream brokenPipeSignal raise. |
|
4500 |
]. |
|
4501 |
||
4502 |
"if there has been an ST-signal installed, use it ..." |
|
4503 |
||
4504 |
sig := OperatingSystem operatingSystemSignal:signalNumber. |
|
4505 |
sig notNil ifTrue:[ |
|
4506 |
^ sig raise |
|
4507 |
]. |
|
4508 |
||
4509 |
"/ if handled, raise OSSignalInterruptSignal |
|
4510 |
||
4511 |
OSSignalInterruptSignal isHandled ifTrue:[ |
|
4512 |
^ OSSignalInterruptSignal raiseWith:signalNumber |
|
4513 |
]. |
|
4514 |
||
4515 |
" |
|
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4516 |
special case - SIGPWR/SIGHUP: write a crash image |
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4517 |
" |
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4518 |
((signalNumber == 30 "OperatingSystem sigPWR") |
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4519 |
or:[signalNumber == 1 "OperatingSystem sigHUP"]) ifTrue:[ |
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4520 |
ObjectMemory snapShotOn:'crash.img'. |
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4521 |
^ self. |
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4522 |
]. |
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4523 |
|
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4524 |
" |
5755 | 4525 |
... otherwise , bring up a box asking for what to do ... |
4526 |
" |
|
4527 |
name := OperatingSystem nameForSignal:signalNumber. |
|
4528 |
here := thisContext. |
|
4529 |
||
4530 |
" |
|
4531 |
the context, in which the signal occurred: |
|
4532 |
" |
|
4533 |
badContext := here sender. |
|
4534 |
||
4535 |
" |
|
4536 |
ungrab - in case it happened in a box/popupview |
|
4537 |
otherwise display stays locked |
|
4538 |
" |
|
4539 |
"/ Display notNil ifTrue:[ |
|
4540 |
"/ Display ungrabPointer. |
|
4541 |
"/ Display ungrabKeyboard. |
|
4542 |
"/ ]. |
|
4543 |
Screen notNil ifTrue:[ |
|
4544 |
Screen allScreens do:[:aScreen | |
|
4545 |
aScreen ungrabPointer. |
|
4546 |
aScreen ungrabKeyboard. |
|
4547 |
] |
|
4548 |
]. |
|
4549 |
||
4550 |
" |
|
4551 |
SIGBUS, SIGSEGV and SIGILL do not make sense to ignore (i.e. continue) |
|
4552 |
since the system will retry the faulty instruction, which leads to |
|
4553 |
another signal - to avoid frustration, better not offer this option. |
|
4554 |
" |
|
4555 |
ignorable := (signalNumber ~~ OperatingSystem sigBUS) |
|
4556 |
and:[signalNumber ~~ OperatingSystem sigILL |
|
4557 |
and:[signalNumber ~~ OperatingSystem sigSEGV]]. |
|
4558 |
||
4559 |
ignorable ifFalse:[ |
|
4560 |
here isRecursive ifTrue:[ |
|
4561 |
'Object [hard error]: signal ' errorPrint. signalNumber errorPrintCR. |
|
4562 |
MiniDebugger |
|
4563 |
enterWithMessage:'recursive signal' |
|
4564 |
mayProceed:true. |
|
4565 |
^ self |
|
4566 |
]. |
|
4567 |
" |
|
4568 |
a hard signal - go into debugger immediately |
|
4569 |
" |
|
4570 |
msg := 'OS-signal: ', name. |
|
4571 |
||
4572 |
"/ the IRQ-PC is passed as low-hi, to avoid the need |
|
4573 |
"/ to allocate a LargeInteger in the VM during signal |
|
4574 |
"/ time. I know, this is ugly. |
|
4575 |
||
4576 |
InterruptPcLow notNil ifTrue:[ |
|
4577 |
pc := InterruptPcLow + (InterruptPcHi bitShift:(SmallInteger maxBits + 1 // 2)). |
|
4578 |
pc ~~ 0 ifTrue:[ |
|
4579 |
msg := msg , ' PC=' , (pc printStringRadix:16) |
|
4580 |
]. |
|
4581 |
]. |
|
4582 |
InterruptAddrLow notNil ifTrue:[ |
|
4583 |
addr := InterruptAddrLow + (InterruptAddrHi bitShift:(SmallInteger maxBits + 1 // 2)). |
|
4584 |
addr ~~ 0 ifTrue:[ |
|
4585 |
msg := msg , ' ADDR=' , (addr printStringRadix:16) |
|
4586 |
]. |
|
4587 |
]. |
|
4588 |
Debugger enter:here withMessage:msg mayProceed:true. |
|
4589 |
badContext return. |
|
4590 |
^ nil. |
|
4591 |
]. |
|
4592 |
||
4593 |
OptionBox isNil ifTrue:[ |
|
4594 |
" |
|
4595 |
a system without GUI ... |
|
4596 |
go into minidebugger (if there is one) |
|
4597 |
" |
|
4598 |
MiniDebugger isNil ifTrue:[ |
|
4599 |
" |
|
4600 |
a system without debugging facilities |
|
4601 |
(i.e. a standalone system) |
|
4602 |
output a message and exit. |
|
4603 |
" |
|
4604 |
('Object [error]: exit due to Signal ' , name , ' - and no debugger.') errorPrintCR. |
|
4605 |
Smalltalk exit. |
|
4606 |
]. |
|
4607 |
MiniDebugger |
|
4608 |
enterWithMessage:'Signal caught (' , name, ')' |
|
4609 |
mayProceed:true. |
|
4610 |
^ self |
|
4611 |
]. |
|
4612 |
||
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4613 |
titles := #('save crash image' 'dump core' 'exit ST/X'). |
5755 | 4614 |
actions := Array |
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4615 |
with:[ObjectMemory snapShotOn:'crash.img'] |
5755 | 4616 |
with:[Smalltalk fatalAbort] |
4617 |
with:[Smalltalk exit]. |
|
4618 |
||
4619 |
action := nil. |
|
4620 |
title := 'OS Signal caught (' , name, ')'. |
|
4621 |
title := (title , '\[in ST-process: ' , Processor activeProcess nameOrId ,']') withCRs. |
|
4622 |
||
4623 |
"/ if cought while in the scheduler or event dispatcher, |
|
4624 |
"/ a modal dialog is not possible ... |
|
4625 |
"/ (therefore, debug & return make no sense) |
|
4626 |
||
4627 |
Processor activeProcess isSystemProcess ifFalse:[ |
|
4628 |
titles := #('abort' 'debug') , titles. |
|
4629 |
actions := (Array |
|
4630 |
with:[action := #abort] |
|
4631 |
with:[action := #debug]) , actions. |
|
4632 |
||
4633 |
badContext canReturn ifTrue:[ |
|
4634 |
titles := #('return') , titles. |
|
4635 |
actions := (Array with:[action := #return]) , actions. |
|
4636 |
]. |
|
4637 |
]. |
|
4638 |
||
4639 |
ignorable ifTrue:[ |
|
4640 |
titles := titles, #('ignore'). |
|
4641 |
actions := actions , (Array with:[action := #ignore]). |
|
4642 |
]. |
|
4643 |
||
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
4644 |
box := OptionBox title:title numberOfOptions:actions size. |
5755 | 4645 |
ignorable ifTrue:[ |
4646 |
box defaultButtonIndex:(actions size) |
|
4647 |
]. |
|
4648 |
box buttonTitles:titles. |
|
4649 |
box actions:actions. |
|
4650 |
box showAtPointer. |
|
4651 |
||
4652 |
action == #return ifTrue:[ |
|
4653 |
badContext return |
|
4654 |
]. |
|
4655 |
||
4656 |
action == #abort ifTrue:[ |
|
4657 |
AbortSignal raise. |
|
4658 |
]. |
|
4659 |
||
4660 |
action == #debug ifTrue:[ |
|
4661 |
Debugger enter:here withMessage:('Signal ', name) mayProceed:true. |
|
4662 |
]. |
|
4663 |
||
4664 |
"Modified: / 4.5.1998 / 20:39:16 / cg" |
|
4665 |
! |
|
4666 |
||
4667 |
spyInterrupt |
|
4668 |
"{ Pragma: +optSpace }" |
|
4669 |
||
4670 |
"spy interrupt and no handler - enter debugger" |
|
4671 |
||
4672 |
self error:'spy Interrupt - but no handler' mayProceed:true |
|
4673 |
! |
|
4674 |
||
4675 |
timerInterrupt |
|
4676 |
"{ Pragma: +optSpace }" |
|
4677 |
||
4678 |
"timer interrupt and no handler - enter debugger" |
|
4679 |
||
4680 |
self error:'timer Interrupt - but no handler' mayProceed:true |
|
4681 |
! |
|
4682 |
||
4683 |
userInterrupt |
|
4684 |
"{ Pragma: +optSpace }" |
|
4685 |
||
4686 |
"user (^c) interrupt. |
|
4687 |
This is typically sent by the VM, when a ctrl-C is typed at the |
|
4688 |
controlling tty (i.e. in the xterm)." |
|
4689 |
||
4690 |
UserInterruptSignal raise |
|
4691 |
! |
|
4692 |
||
4693 |
userInterruptIn:aContext |
|
4694 |
"{ Pragma: +optSpace }" |
|
4695 |
||
4696 |
"user (^c) interrupt - enter debugger, but show aContext |
|
4697 |
as top-context. |
|
4698 |
This is used to hide any intermediate scheduler contexts, |
|
4699 |
in case of an interrupted process. Typically, this is sent by |
|
4700 |
the WindowGroup, when a keyboardEvent for the ctrl-C key is |
|
4701 |
processed." |
|
4702 |
||
4703 |
<context: #return> |
|
4704 |
||
4705 |
UserInterruptSignal raiseRequestWith:nil errorString:nil in:aContext |
|
4706 |
||
4707 |
"Created: / 18.10.1996 / 20:46:04 / cg" |
|
4708 |
"Modified: / 20.10.1996 / 13:06:38 / cg" |
|
4709 |
"Modified: / 26.7.1999 / 10:58:49 / stefan" |
|
4710 |
! ! |
|
4711 |
||
4712 |
!Object methodsFor:'message sending'! |
|
4713 |
||
4714 |
perform:aSelector |
|
4715 |
"send the message aSelector to the receiver" |
|
4716 |
||
4717 |
%{ |
|
4718 |
REGISTER OBJ sel = aSelector; |
|
4719 |
||
4720 |
if (InterruptPending == nil) { |
|
4721 |
struct inlineCache *pIlc; |
|
4722 |
static struct inlineCache ilc_0 = __ILCPERF0(@line); |
|
4723 |
static struct inlineCache ilc_1 = __ILCPERF0(@line); |
|
4724 |
static struct inlineCache ilc_2 = __ILCPERF0(@line); |
|
4725 |
static struct inlineCache ilc_3 = __ILCPERF0(@line); |
|
4726 |
static struct inlineCache ilc_4 = __ILCPERF0(@line); |
|
4727 |
static OBJ last_0 = nil; |
|
4728 |
static OBJ last_1 = nil; |
|
4729 |
static OBJ last_2 = nil; |
|
4730 |
static OBJ last_3 = nil; |
|
4731 |
static OBJ last_4 = nil; |
|
4732 |
static flip = 0; |
|
4733 |
||
4734 |
if (sel == last_0) { |
|
4735 |
pIlc = &ilc_0; |
|
4736 |
} else if (sel == last_1) { |
|
4737 |
pIlc = &ilc_1; |
|
4738 |
} else if (sel == last_2) { |
|
4739 |
pIlc = &ilc_2; |
|
4740 |
} else if (sel == last_3) { |
|
4741 |
pIlc = &ilc_3; |
|
4742 |
} else if (sel == last_4) { |
|
4743 |
pIlc = &ilc_4; |
|
4744 |
} else { |
|
4745 |
if (flip == 0) { |
|
4746 |
pIlc = &ilc_0; |
|
4747 |
flip = 1; |
|
4748 |
last_0 = sel; |
|
4749 |
} else if (flip == 1) { |
|
4750 |
pIlc = &ilc_1; |
|
4751 |
flip = 2; |
|
4752 |
last_1 = sel; |
|
4753 |
} else if (flip == 2) { |
|
4754 |
pIlc = &ilc_2; |
|
4755 |
flip = 3; |
|
4756 |
last_2 = sel; |
|
4757 |
} else if (flip == 3) { |
|
4758 |
pIlc = &ilc_3; |
|
4759 |
flip = 4; |
|
4760 |
last_3 = sel; |
|
4761 |
} else { |
|
4762 |
pIlc = &ilc_4; |
|
4763 |
flip = 0; |
|
4764 |
last_4 = sel; |
|
4765 |
} |
|
4766 |
pIlc->ilc_func = __SEND0ADDR__; |
|
4767 |
if (pIlc->ilc_poly) { |
|
4768 |
__flushPolyCache(pIlc->ilc_poly); |
|
4769 |
pIlc->ilc_poly = 0; |
|
4770 |
} |
|
4771 |
} |
|
4772 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc) ); |
|
4773 |
} else { |
|
4774 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
4775 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
4776 |
} |
|
4777 |
%}. |
|
4778 |
^ self perform:aSelector withArguments:#() |
|
4779 |
! |
|
4780 |
||
4781 |
perform:aSelector inClass:aClass withArguments:argArray |
|
4782 |
"send the message aSelector with all args taken from argArray |
|
4783 |
to the receiver as a super-send message. |
|
4784 |
This is actually more flexible than the normal super-send, since it allows |
|
4785 |
to execute a method in ANY superclass of the receiver (not just the |
|
4786 |
immediate superclass). |
|
4787 |
Thus, it is (theoretically) possible to do |
|
4788 |
'5 perform:#< inClass:Magnitude withArguments:#(6)' |
|
4789 |
and evaluate Magnitudes compare method even if there was one in Number. |
|
4790 |
This method is used by the interpreter to evaluate super sends |
|
4791 |
and could be used for very special behavior (language extension ?). |
|
4792 |
||
4793 |
WARNING: this is an ST/X feature - probably not found in other smalltalks." |
|
4794 |
||
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
4795 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 myClass| |
5755 | 4796 |
|
4797 |
" |
|
4798 |
check, if aClass is really a superclass of the receiver |
|
4799 |
" |
|
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
4800 |
myClass := self class. |
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
4801 |
(myClass == aClass or:[myClass isSubclassOf:aClass]) ifFalse:[ |
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
4802 |
self error:'lookup-class argument is not a superclass of the receiver'. |
5755 | 4803 |
^ nil |
4804 |
]. |
|
4805 |
%{ |
|
4806 |
REGISTER OBJ *argP; |
|
4807 |
int nargs, i; |
|
4808 |
||
4809 |
if (__isArray(argArray)) { |
|
4810 |
nargs = __arraySize(argArray); |
|
4811 |
argP = __ArrayInstPtr(argArray)->a_element; |
|
4812 |
} else { |
|
4813 |
if (__isNonNilObject(argArray)) { |
|
4814 |
static struct inlineCache ilcSize = __ILC0(@line+1); |
|
4815 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
4816 |
if (!__isSmallInteger(numberOfArgs)) |
|
4817 |
goto bad; |
|
4818 |
nargs = __intVal(numberOfArgs); |
|
4819 |
argP = (OBJ *)(&a1); |
|
4820 |
for (i=1; i <= nargs; i++) { |
|
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
4821 |
*argP++ = __AT_(argArray, __MKSMALLINT((INT)i)); |
5755 | 4822 |
} |
4823 |
argP = (OBJ *)(&a1); |
|
4824 |
} else { |
|
4825 |
nargs = 0; |
|
4826 |
} |
|
4827 |
} |
|
4828 |
switch (nargs) { |
|
4829 |
case 0: |
|
4830 |
{ |
|
4831 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
4832 |
RETURN ( _SEND0(self, aSelector, aClass, &ilc0)); |
|
4833 |
} |
|
4834 |
||
4835 |
case 1: |
|
4836 |
{ |
|
4837 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
4838 |
RETURN ( _SEND1(self, aSelector, aClass, &ilc1, argP[0])); |
|
4839 |
} |
|
4840 |
||
4841 |
case 2: |
|
4842 |
{ |
|
4843 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
4844 |
RETURN ( _SEND2(self, aSelector, aClass, &ilc2, argP[0], argP[1])); |
|
4845 |
} |
|
4846 |
||
4847 |
case 3: |
|
4848 |
{ |
|
4849 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
4850 |
RETURN ( _SEND3(self, aSelector, aClass, &ilc3, |
|
4851 |
argP[0], argP[1], argP[2])); |
|
4852 |
} |
|
4853 |
||
4854 |
case 4: |
|
4855 |
{ |
|
4856 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
|
4857 |
RETURN ( _SEND4(self, aSelector, aClass, &ilc4, |
|
4858 |
argP[0], argP[1], argP[2], argP[3])); |
|
4859 |
} |
|
4860 |
||
4861 |
case 5: |
|
4862 |
{ |
|
4863 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
|
4864 |
RETURN ( _SEND5(self, aSelector, aClass, &ilc5, |
|
4865 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
4866 |
} |
|
4867 |
||
4868 |
case 6: |
|
4869 |
{ |
|
4870 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
|
4871 |
RETURN ( _SEND6(self, aSelector, aClass, &ilc6, |
|
4872 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5])); |
|
4873 |
} |
|
4874 |
||
4875 |
case 7: |
|
4876 |
{ |
|
4877 |
static struct inlineCache ilc7 = __DUMMYILCSELF7(@line+1); |
|
4878 |
RETURN ( _SEND7(self, aSelector, aClass, &ilc7, |
|
4879 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
4880 |
argP[6])); |
|
4881 |
} |
|
4882 |
||
4883 |
case 8: |
|
4884 |
{ |
|
4885 |
static struct inlineCache ilc8 = __DUMMYILCSELF8(@line+1); |
|
4886 |
RETURN ( _SEND8(self, aSelector, aClass, &ilc8, |
|
4887 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
4888 |
argP[6], argP[7])); |
|
4889 |
} |
|
4890 |
||
4891 |
case 9: |
|
4892 |
{ |
|
4893 |
static struct inlineCache ilc9 = __DUMMYILCSELF9(@line+1); |
|
4894 |
RETURN ( _SEND9(self, aSelector, aClass, &ilc9, |
|
4895 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
4896 |
argP[6], argP[7], argP[8])); |
|
4897 |
} |
|
4898 |
||
4899 |
case 10: |
|
4900 |
{ |
|
4901 |
static struct inlineCache ilc10 = __DUMMYILCSELF10(@line+1); |
|
4902 |
RETURN ( _SEND10(self, aSelector, aClass, &ilc10, |
|
4903 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
4904 |
argP[6], argP[7], argP[8], argP[9])); |
|
4905 |
} |
|
4906 |
||
4907 |
case 11: |
|
4908 |
{ |
|
4909 |
static struct inlineCache ilc11 = __DUMMYILCSELF11(@line+1); |
|
4910 |
RETURN ( _SEND11(self, aSelector, aClass, &ilc11, |
|
4911 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
4912 |
argP[6], argP[7], argP[8], argP[9], argP[10])); |
|
4913 |
} |
|
4914 |
||
4915 |
case 12: |
|
4916 |
{ |
|
4917 |
static struct inlineCache ilc12 = __DUMMYILCSELF12(@line+1); |
|
4918 |
RETURN ( _SEND12(self, aSelector, aClass, &ilc12, |
|
4919 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
4920 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
4921 |
argP[11])); |
|
4922 |
} |
|
4923 |
||
4924 |
case 13: |
|
4925 |
{ |
|
4926 |
static struct inlineCache ilc13 = __DUMMYILCSELF13(@line+1); |
|
4927 |
RETURN ( _SEND13(self, aSelector, aClass, &ilc13, |
|
4928 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
4929 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
4930 |
argP[11], argP[12])); |
|
4931 |
} |
|
4932 |
||
4933 |
case 14: |
|
4934 |
{ |
|
4935 |
static struct inlineCache ilc14 = __DUMMYILCSELF14(@line+1); |
|
4936 |
RETURN ( _SEND14(self, aSelector, aClass, &ilc14, |
|
4937 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
4938 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
4939 |
argP[11], argP[12], argP[13])); |
|
4940 |
} |
|
4941 |
||
4942 |
case 15: |
|
4943 |
{ |
|
4944 |
static struct inlineCache ilc15 = __DUMMYILCSELF15(@line+1); |
|
4945 |
RETURN ( _SEND15(self, aSelector, aClass, &ilc15, |
|
4946 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
4947 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
4948 |
argP[11], argP[12], argP[13], argP[14])); |
|
4949 |
} |
|
4950 |
||
4951 |
#ifdef _SEND16 |
|
4952 |
case 16: |
|
4953 |
{ |
|
4954 |
static struct inlineCache ilc16 = __DUMMYILCSELF16(@line+1); |
|
4955 |
RETURN ( _SEND16(self, aSelector, aClass, &ilc15, |
|
4956 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
4957 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
4958 |
argP[11], argP[12], argP[13], argP[14], argP[15])); |
|
4959 |
} |
|
4960 |
#endif |
|
4961 |
#ifdef _SEND17 |
|
4962 |
case 17: |
|
4963 |
{ |
|
4964 |
static struct inlineCache ilc17 = __DUMMYILCSELF17(@line+1); |
|
4965 |
RETURN ( _SEND17(self, aSelector, aClass, &ilc15, |
|
4966 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
4967 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
4968 |
argP[11], argP[12], argP[13], argP[14], argP[15], argP[16])); |
|
4969 |
} |
|
4970 |
#endif |
|
4971 |
||
4972 |
||
4973 |
} |
|
4974 |
bad:; |
|
4975 |
%}. |
|
4976 |
"/ arrive here, if bad number of arguments (too many) |
|
4977 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
4978 |
||
4979 |
^ self primitiveFailed |
|
4980 |
! |
|
4981 |
||
4982 |
perform:aSelector with:arg |
|
4983 |
"send the one-arg-message aSelector to the receiver" |
|
4984 |
||
4985 |
%{ |
|
4986 |
REGISTER OBJ sel = aSelector; |
|
4987 |
||
4988 |
if (InterruptPending == nil) { |
|
4989 |
struct inlineCache *pIlc; |
|
4990 |
static struct inlineCache ilc_0 = __ILCPERF1(@line); |
|
4991 |
static struct inlineCache ilc_1 = __ILCPERF1(@line); |
|
4992 |
static struct inlineCache ilc_2 = __ILCPERF1(@line); |
|
4993 |
static struct inlineCache ilc_3 = __ILCPERF1(@line); |
|
4994 |
static struct inlineCache ilc_4 = __ILCPERF1(@line); |
|
4995 |
static OBJ last_0 = nil; |
|
4996 |
static OBJ last_1 = nil; |
|
4997 |
static OBJ last_2 = nil; |
|
4998 |
static OBJ last_3 = nil; |
|
4999 |
static OBJ last_4 = nil; |
|
5000 |
static flip = 0; |
|
5001 |
||
5002 |
if (sel == last_0) { |
|
5003 |
pIlc = &ilc_0; |
|
5004 |
} else if (sel == last_1) { |
|
5005 |
pIlc = &ilc_1; |
|
5006 |
} else if (sel == last_2) { |
|
5007 |
pIlc = &ilc_2; |
|
5008 |
} else if (sel == last_3) { |
|
5009 |
pIlc = &ilc_3; |
|
5010 |
} else if (sel == last_4) { |
|
5011 |
pIlc = &ilc_4; |
|
5012 |
} else { |
|
5013 |
if (flip == 0) { |
|
5014 |
pIlc = &ilc_0; |
|
5015 |
flip = 1; |
|
5016 |
last_0 = sel; |
|
5017 |
} else if (flip == 1) { |
|
5018 |
pIlc = &ilc_1; |
|
5019 |
flip = 2; |
|
5020 |
last_1 = sel; |
|
5021 |
} else if (flip == 2) { |
|
5022 |
pIlc = &ilc_2; |
|
5023 |
flip = 3; |
|
5024 |
last_2 = sel; |
|
5025 |
} else if (flip == 3) { |
|
5026 |
pIlc = &ilc_3; |
|
5027 |
flip = 4; |
|
5028 |
last_3 = sel; |
|
5029 |
} else { |
|
5030 |
pIlc = &ilc_4; |
|
5031 |
flip = 0; |
|
5032 |
last_4 = sel; |
|
5033 |
} |
|
5034 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5035 |
if (pIlc->ilc_poly) { |
|
5036 |
__flushPolyCache(pIlc->ilc_poly); |
|
5037 |
pIlc->ilc_poly = 0; |
|
5038 |
} |
|
5039 |
} |
|
5040 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc, arg) ); |
|
5041 |
} else { |
|
5042 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5043 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, arg)); |
|
5044 |
} |
|
5045 |
%}. |
|
5046 |
^ self perform:aSelector withArguments:(Array with:arg) |
|
5047 |
||
5048 |
! |
|
5049 |
||
5050 |
perform:aSelector with:arg1 with:arg2 |
|
5051 |
"send the two-arg-message aSelector to the receiver" |
|
5052 |
||
5053 |
%{ |
|
5054 |
struct inlineCache *pIlc; |
|
5055 |
||
5056 |
if (InterruptPending == nil) { |
|
5057 |
static struct inlineCache ilc_0 = __ILCPERF2(@line); |
|
5058 |
static struct inlineCache ilc_1 = __ILCPERF2(@line); |
|
5059 |
static OBJ last_0 = nil; |
|
5060 |
static OBJ last_1 = nil; |
|
5061 |
static flip = 0; |
|
5062 |
||
5063 |
if (aSelector == last_0) { |
|
5064 |
pIlc = &ilc_0; |
|
5065 |
} else if (aSelector == last_1) { |
|
5066 |
pIlc = &ilc_1; |
|
5067 |
} else { |
|
5068 |
if (flip == 0) { |
|
5069 |
pIlc = &ilc_0; |
|
5070 |
flip = 1; |
|
5071 |
last_0 = aSelector; |
|
5072 |
} else { |
|
5073 |
pIlc = &ilc_1; |
|
5074 |
flip = 0; |
|
5075 |
last_1 = aSelector; |
|
5076 |
} |
|
5077 |
pIlc->ilc_func = __SEND2ADDR__; |
|
5078 |
if (pIlc->ilc_poly) { |
|
5079 |
__flushPolyCache(pIlc->ilc_poly); |
|
5080 |
pIlc->ilc_poly = 0; |
|
5081 |
} |
|
5082 |
} |
|
5083 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2) ); |
|
5084 |
} else { |
|
5085 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
5086 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, arg1, arg2)); |
|
5087 |
} |
|
5088 |
%}. |
|
5089 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2) |
|
5090 |
||
5091 |
! |
|
5092 |
||
5093 |
perform:aSelector with:arg1 with:arg2 with:arg3 |
|
5094 |
"send the three-arg-message aSelector to the receiver" |
|
5095 |
||
5096 |
%{ |
|
5097 |
struct inlineCache *pIlc; |
|
5098 |
static struct inlineCache ilc_0 = __ILCPERF3(@line); |
|
5099 |
static struct inlineCache ilc_1 = __ILCPERF3(@line); |
|
5100 |
static OBJ last_0 = nil; |
|
5101 |
static OBJ last_1 = nil; |
|
5102 |
static flip = 0; |
|
5103 |
||
5104 |
if (InterruptPending == nil) { |
|
5105 |
if (aSelector != last_0) { |
|
5106 |
if (aSelector != last_1) { |
|
5107 |
if (flip) { |
|
5108 |
pIlc = &ilc_0; |
|
5109 |
flip = 0; |
|
5110 |
last_0 = aSelector; |
|
5111 |
} else { |
|
5112 |
pIlc = &ilc_1; |
|
5113 |
flip = 1; |
|
5114 |
last_1 = aSelector; |
|
5115 |
} |
|
5116 |
pIlc->ilc_func = __SEND3ADDR__; |
|
5117 |
if (pIlc->ilc_poly) { |
|
5118 |
__flushPolyCache(pIlc->ilc_poly); |
|
5119 |
pIlc->ilc_poly = 0; |
|
5120 |
} |
|
5121 |
} else { |
|
5122 |
pIlc = &ilc_1; |
|
5123 |
} |
|
5124 |
} else { |
|
5125 |
pIlc = &ilc_0; |
|
5126 |
} |
|
5127 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2, arg3) ); |
|
5128 |
} else { |
|
5129 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
5130 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, arg1, arg2, arg3)); |
|
5131 |
} |
|
5132 |
%}. |
|
5133 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3) |
|
5134 |
||
5135 |
! |
|
5136 |
||
5137 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 |
|
5138 |
"send the four-arg-message aSelector to the receiver" |
|
5139 |
||
5140 |
%{ |
|
5141 |
struct inlineCache *pIlc; |
|
5142 |
static struct inlineCache ilc_0 = __ILCPERF4(@line); |
|
5143 |
static struct inlineCache ilc_1 = __ILCPERF4(@line); |
|
5144 |
static OBJ last_0 = nil; |
|
5145 |
static OBJ last_1 = nil; |
|
5146 |
static flip = 0; |
|
5147 |
||
5148 |
if (InterruptPending == nil) { |
|
5149 |
if (aSelector != last_0) { |
|
5150 |
if (aSelector != last_1) { |
|
5151 |
if (flip) { |
|
5152 |
pIlc = &ilc_0; |
|
5153 |
flip = 0; |
|
5154 |
last_0 = aSelector; |
|
5155 |
} else { |
|
5156 |
pIlc = &ilc_1; |
|
5157 |
flip = 1; |
|
5158 |
last_1 = aSelector; |
|
5159 |
} |
|
5160 |
pIlc->ilc_func = __SEND4ADDR__; |
|
5161 |
if (pIlc->ilc_poly) { |
|
5162 |
__flushPolyCache(pIlc->ilc_poly); |
|
5163 |
pIlc->ilc_poly = 0; |
|
5164 |
} |
|
5165 |
} else { |
|
5166 |
pIlc = &ilc_1; |
|
5167 |
} |
|
5168 |
} else { |
|
5169 |
pIlc = &ilc_0; |
|
5170 |
} |
|
5171 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5172 |
arg1, arg2, arg3, arg4) ); |
|
5173 |
} else { |
|
5174 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
|
5175 |
RETURN (_SEND4(self, aSelector, nil, &ilc4, |
|
5176 |
arg1, arg2, arg3, arg4)); |
|
5177 |
} |
|
5178 |
%}. |
|
5179 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
5180 |
||
5181 |
! |
|
5182 |
||
5183 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
5184 |
"send the five-arg-message aSelector to the receiver" |
|
5185 |
||
5186 |
%{ |
|
5187 |
struct inlineCache *pIlc; |
|
5188 |
static struct inlineCache ilc_0 = __ILCPERF5(@line); |
|
5189 |
static struct inlineCache ilc_1 = __ILCPERF5(@line); |
|
5190 |
static OBJ last_0 = nil; |
|
5191 |
static OBJ last_1 = nil; |
|
5192 |
static flip = 0; |
|
5193 |
||
5194 |
if (InterruptPending == nil) { |
|
5195 |
if (aSelector != last_0) { |
|
5196 |
if (aSelector != last_1) { |
|
5197 |
if (flip) { |
|
5198 |
pIlc = &ilc_0; |
|
5199 |
flip = 0; |
|
5200 |
last_0 = aSelector; |
|
5201 |
} else { |
|
5202 |
pIlc = &ilc_1; |
|
5203 |
flip = 1; |
|
5204 |
last_1 = aSelector; |
|
5205 |
} |
|
5206 |
pIlc->ilc_func = __SEND5ADDR__; |
|
5207 |
if (pIlc->ilc_poly) { |
|
5208 |
__flushPolyCache(pIlc->ilc_poly); |
|
5209 |
pIlc->ilc_poly = 0; |
|
5210 |
} |
|
5211 |
} else { |
|
5212 |
pIlc = &ilc_1; |
|
5213 |
} |
|
5214 |
} else { |
|
5215 |
pIlc = &ilc_0; |
|
5216 |
} |
|
5217 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5218 |
arg1, arg2, arg3, arg4, arg5) ); |
|
5219 |
} else { |
|
5220 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
|
5221 |
RETURN (_SEND5(self, aSelector, nil, &ilc5, |
|
5222 |
arg1, arg2, arg3, arg4, arg5)); |
|
5223 |
} |
|
5224 |
%}. |
|
5225 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
5226 |
with:arg5) |
|
5227 |
||
5228 |
! |
|
5229 |
||
5230 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
|
5231 |
"send the six-arg-message aSelector to the receiver" |
|
5232 |
||
5233 |
%{ |
|
5234 |
struct inlineCache *pIlc; |
|
5235 |
static struct inlineCache ilc_0 = __ILCPERF6(@line); |
|
5236 |
static struct inlineCache ilc_1 = __ILCPERF6(@line); |
|
5237 |
static OBJ last_0 = nil; |
|
5238 |
static OBJ last_1 = nil; |
|
5239 |
static flip = 0; |
|
5240 |
||
5241 |
if (InterruptPending == nil) { |
|
5242 |
if (aSelector != last_0) { |
|
5243 |
if (aSelector != last_1) { |
|
5244 |
if (flip) { |
|
5245 |
pIlc = &ilc_0; |
|
5246 |
flip = 0; |
|
5247 |
last_0 = aSelector; |
|
5248 |
} else { |
|
5249 |
pIlc = &ilc_1; |
|
5250 |
flip = 1; |
|
5251 |
last_1 = aSelector; |
|
5252 |
} |
|
5253 |
pIlc->ilc_func = __SEND6ADDR__; |
|
5254 |
if (pIlc->ilc_poly) { |
|
5255 |
__flushPolyCache(pIlc->ilc_poly); |
|
5256 |
pIlc->ilc_poly = 0; |
|
5257 |
} |
|
5258 |
} else { |
|
5259 |
pIlc = &ilc_1; |
|
5260 |
} |
|
5261 |
} else { |
|
5262 |
pIlc = &ilc_0; |
|
5263 |
} |
|
5264 |
||
5265 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
5266 |
arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
5267 |
} else { |
|
5268 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
|
5269 |
RETURN (_SEND6(self, aSelector, nil, &ilc6, |
|
5270 |
arg1, arg2, arg3, arg4, arg5, arg6)); |
|
5271 |
} |
|
5272 |
%}. |
|
5273 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
5274 |
with:arg5 with:arg6) |
|
5275 |
||
5276 |
! |
|
5277 |
||
5278 |
perform:aSelector withArguments:argArray |
|
5279 |
"send the message aSelector with all args taken from argArray |
|
5280 |
to the receiver." |
|
5281 |
||
5282 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
|
5283 |
||
5284 |
%{ |
|
5285 |
REGISTER OBJ *argP; |
|
5286 |
int nargs; |
|
5287 |
OBJ l; |
|
5288 |
||
5289 |
if (__isArray(argArray)) { |
|
5290 |
nargs = __arraySize(argArray); |
|
5291 |
argP = __ArrayInstPtr(argArray)->a_element; |
|
5292 |
} else { |
|
5293 |
if (__isNonNilObject(argArray)) { |
|
5294 |
static struct inlineCache ilcSize = __ILC0(@line); |
|
5295 |
int i; |
|
5296 |
||
5297 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
5298 |
if (!__isSmallInteger(numberOfArgs)) |
|
5299 |
goto bad; |
|
5300 |
nargs = __intVal(numberOfArgs); |
|
5301 |
argP = (OBJ *)(&a1); |
|
5302 |
for (i=1; i <= nargs; i++) { |
|
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
5303 |
*argP++ = __AT_(argArray, __MKSMALLINT((INT)i)); |
5755 | 5304 |
} |
5305 |
argP = (OBJ *)(&a1); |
|
5306 |
} else { |
|
5307 |
nargs = 0; |
|
5308 |
} |
|
5309 |
} |
|
5310 |
switch (nargs) { |
|
5311 |
case 0: |
|
5312 |
if (InterruptPending == nil) { |
|
5313 |
static OBJ last0_0 = nil; static struct inlineCache ilc0_0 = __ILCPERF0(@line); |
|
5314 |
static OBJ last0_1 = nil; static struct inlineCache ilc0_1 = __ILCPERF0(@line); |
|
5315 |
static OBJ last0_2 = nil; static struct inlineCache ilc0_2 = __ILCPERF0(@line); |
|
5316 |
static OBJ last0_3 = nil; static struct inlineCache ilc0_3 = __ILCPERF0(@line); |
|
5317 |
static int flip0 = 0; |
|
5318 |
struct inlineCache *pIlc; |
|
5319 |
||
5320 |
if (aSelector == last0_0) { |
|
5321 |
pIlc = &ilc0_0; |
|
5322 |
} else if (aSelector == last0_1) { |
|
5323 |
pIlc = &ilc0_1; |
|
5324 |
} else if (aSelector == last0_2) { |
|
5325 |
pIlc = &ilc0_2; |
|
5326 |
} else if (aSelector == last0_3) { |
|
5327 |
pIlc = &ilc0_3; |
|
5328 |
} else { |
|
5329 |
if (flip0 == 0) { |
|
5330 |
pIlc = &ilc0_0; |
|
5331 |
flip0 = 1; |
|
5332 |
last0_0 = aSelector; |
|
5333 |
} else if (flip0 == 1) { |
|
5334 |
pIlc = &ilc0_1; |
|
5335 |
flip0 = 2; |
|
5336 |
last0_1 = aSelector; |
|
5337 |
} else if (flip0 == 2) { |
|
5338 |
pIlc = &ilc0_2; |
|
5339 |
flip0 = 3; |
|
5340 |
last0_2 = aSelector; |
|
5341 |
} else { |
|
5342 |
pIlc = &ilc0_3; |
|
5343 |
flip0 = 0; |
|
5344 |
last0_3 = aSelector; |
|
5345 |
} |
|
5346 |
||
5347 |
pIlc->ilc_func = __SEND0ADDR__; |
|
5348 |
if (pIlc->ilc_poly) { |
|
5349 |
__flushPolyCache(pIlc->ilc_poly); |
|
5350 |
pIlc->ilc_poly = 0; |
|
5351 |
} |
|
5352 |
} |
|
5353 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc)); |
|
5354 |
} else { |
|
5355 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5356 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5357 |
} |
|
5358 |
||
5359 |
case 1: |
|
5360 |
if (InterruptPending == nil) { |
|
5361 |
static OBJ last1_0 = nil; static struct inlineCache ilc1_0 = __ILCPERF1(@line); |
|
5362 |
static OBJ last1_1 = nil; static struct inlineCache ilc1_1 = __ILCPERF1(@line); |
|
5363 |
static OBJ last1_2 = nil; static struct inlineCache ilc1_2 = __ILCPERF1(@line); |
|
5364 |
static OBJ last1_3 = nil; static struct inlineCache ilc1_3 = __ILCPERF1(@line); |
|
5365 |
static int flip1 = 0; |
|
5366 |
struct inlineCache *pIlc; |
|
5367 |
||
5368 |
if (aSelector == last1_0) { |
|
5369 |
pIlc = &ilc1_0; |
|
5370 |
} else if (aSelector == last1_1) { |
|
5371 |
pIlc = &ilc1_1; |
|
5372 |
} else if (aSelector == last1_2) { |
|
5373 |
pIlc = &ilc1_2; |
|
5374 |
} else if (aSelector == last1_3) { |
|
5375 |
pIlc = &ilc1_3; |
|
5376 |
} else { |
|
5377 |
if (flip1 == 0) { |
|
5378 |
pIlc = &ilc1_0; |
|
5379 |
flip1 = 1; |
|
5380 |
last1_0 = aSelector; |
|
5381 |
} else if (flip1 == 1) { |
|
5382 |
pIlc = &ilc1_1; |
|
5383 |
flip1 = 2; |
|
5384 |
last1_1 = aSelector; |
|
5385 |
} else if (flip1 == 2) { |
|
5386 |
pIlc = &ilc1_2; |
|
5387 |
flip1 = 3; |
|
5388 |
last1_2 = aSelector; |
|
5389 |
} else { |
|
5390 |
pIlc = &ilc1_3; |
|
5391 |
flip1 = 0; |
|
5392 |
last1_3 = aSelector; |
|
5393 |
} |
|
5394 |
||
5395 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5396 |
if (pIlc->ilc_poly) { |
|
5397 |
__flushPolyCache(pIlc->ilc_poly); |
|
5398 |
pIlc->ilc_poly = 0; |
|
5399 |
} |
|
5400 |
} |
|
5401 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0])); |
|
5402 |
} else { |
|
5403 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5404 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, argP[0])); |
|
5405 |
} |
|
5406 |
||
5407 |
case 2: |
|
5408 |
if (InterruptPending == nil) { |
|
5409 |
static OBJ last2_0 = nil; static struct inlineCache ilc2_0 = __ILCPERF2(@line); |
|
5410 |
static OBJ last2_1 = nil; static struct inlineCache ilc2_1 = __ILCPERF2(@line); |
|
5411 |
static int flip2 = 0; |
|
5412 |
struct inlineCache *pIlc; |
|
5413 |
||
5414 |
if (aSelector == last2_0) { |
|
5415 |
pIlc = &ilc2_0; |
|
5416 |
} else if (aSelector == last2_1) { |
|
5417 |
pIlc = &ilc2_1; |
|
5418 |
} else { |
|
5419 |
if (flip2 == 0) { |
|
5420 |
pIlc = &ilc2_0; |
|
5421 |
flip2 = 1; |
|
5422 |
last2_0 = aSelector; |
|
5423 |
} else { |
|
5424 |
pIlc = &ilc2_1; |
|
5425 |
flip2 = 0; |
|
5426 |
last2_1 = aSelector; |
|
5427 |
} |
|
5428 |
||
5429 |
pIlc->ilc_func = __SEND2ADDR__; |
|
5430 |
if (pIlc->ilc_poly) { |
|
5431 |
__flushPolyCache(pIlc->ilc_poly); |
|
5432 |
pIlc->ilc_poly = 0; |
|
5433 |
} |
|
5434 |
} |
|
5435 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1])); |
|
5436 |
} else { |
|
5437 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
5438 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, argP[0], argP[1])); |
|
5439 |
} |
|
5440 |
||
5441 |
case 3: |
|
5442 |
if (InterruptPending == nil) { |
|
5443 |
static OBJ last3_0 = nil; static struct inlineCache ilc3_0 = __ILCPERF3(@line); |
|
5444 |
static OBJ last3_1 = nil; static struct inlineCache ilc3_1 = __ILCPERF3(@line); |
|
5445 |
static int flip3 = 0; |
|
5446 |
struct inlineCache *pIlc; |
|
5447 |
||
5448 |
if (aSelector == last3_0) { |
|
5449 |
pIlc = &ilc3_0; |
|
5450 |
} else if (aSelector == last3_1) { |
|
5451 |
pIlc = &ilc3_1; |
|
5452 |
} else { |
|
5453 |
if (flip3 == 0) { |
|
5454 |
pIlc = &ilc3_0; |
|
5455 |
flip3 = 1; |
|
5456 |
last3_0 = aSelector; |
|
5457 |
} else { |
|
5458 |
pIlc = &ilc3_1; |
|
5459 |
flip3 = 0; |
|
5460 |
last3_1 = aSelector; |
|
5461 |
} |
|
5462 |
||
5463 |
pIlc->ilc_func = __SEND3ADDR__; |
|
5464 |
if (pIlc->ilc_poly) { |
|
5465 |
__flushPolyCache(pIlc->ilc_poly); |
|
5466 |
pIlc->ilc_poly = 0; |
|
5467 |
} |
|
5468 |
} |
|
5469 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1], argP[2])); |
|
5470 |
} else { |
|
5471 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
5472 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, argP[0], argP[1], argP[2])); |
|
5473 |
} |
|
5474 |
||
5475 |
case 4: |
|
5476 |
{ |
|
5477 |
static OBJ last4 = nil; static struct inlineCache ilc4 = __ILCPERF4(@line); |
|
5478 |
||
5479 |
if ((InterruptPending != nil) || (aSelector != last4)) { |
|
5480 |
ilc4.ilc_func = __SEND4ADDR__; |
|
5481 |
if (ilc4.ilc_poly) { |
|
5482 |
__flushPolyCache(ilc4.ilc_poly); |
|
5483 |
ilc4.ilc_poly = 0; |
|
5484 |
} |
|
5485 |
last4 = aSelector; |
|
5486 |
} |
|
5487 |
RETURN ( (*ilc4.ilc_func)(self, aSelector, nil, &ilc4, |
|
5488 |
argP[0], argP[1], argP[2], argP[3])); |
|
5489 |
} |
|
5490 |
||
5491 |
case 5: |
|
5492 |
{ |
|
5493 |
static OBJ last5 = nil; static struct inlineCache ilc5 = __ILCPERF5(@line); |
|
5494 |
||
5495 |
if ((InterruptPending != nil) || (aSelector != last5)) { |
|
5496 |
ilc5.ilc_func = __SEND5ADDR__; |
|
5497 |
if (ilc5.ilc_poly) { |
|
5498 |
__flushPolyCache(ilc5.ilc_poly); |
|
5499 |
ilc5.ilc_poly = 0; |
|
5500 |
} |
|
5501 |
last5 = aSelector; |
|
5502 |
} |
|
5503 |
RETURN ( (*ilc5.ilc_func)(self, aSelector, nil, &ilc5, |
|
5504 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
5505 |
} |
|
5506 |
||
5507 |
case 6: |
|
5508 |
{ |
|
5509 |
static OBJ last6 = nil; static struct inlineCache ilc6 = __ILCPERF6(@line); |
|
5510 |
||
5511 |
if ((InterruptPending != nil) || (aSelector != last6)) { |
|
5512 |
ilc6.ilc_func = __SEND6ADDR__; |
|
5513 |
if (ilc6.ilc_poly) { |
|
5514 |
__flushPolyCache(ilc6.ilc_poly); |
|
5515 |
ilc6.ilc_poly = 0; |
|
5516 |
} |
|
5517 |
last6 = aSelector; |
|
5518 |
} |
|
5519 |
RETURN ( (*ilc6.ilc_func)(self, aSelector, nil, &ilc6, |
|
5520 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5521 |
argP[5])); |
|
5522 |
} |
|
5523 |
||
5524 |
case 7: |
|
5525 |
{ |
|
5526 |
static OBJ last7 = nil; static struct inlineCache ilc7 = __ILCPERF7(@line); |
|
5527 |
||
5528 |
if ((InterruptPending != nil) || (aSelector != last7)) { |
|
5529 |
ilc7.ilc_func = __SEND7ADDR__; |
|
5530 |
if (ilc7.ilc_poly) { |
|
5531 |
__flushPolyCache(ilc7.ilc_poly); |
|
5532 |
ilc7.ilc_poly = 0; |
|
5533 |
} |
|
5534 |
last7 = aSelector; |
|
5535 |
} |
|
5536 |
RETURN ( (*ilc7.ilc_func)(self, aSelector, nil, &ilc7, |
|
5537 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5538 |
argP[5], argP[6])); |
|
5539 |
} |
|
5540 |
||
5541 |
case 8: |
|
5542 |
{ |
|
5543 |
static OBJ last8 = nil; static struct inlineCache ilc8 = __ILCPERF8(@line); |
|
5544 |
||
5545 |
if ((InterruptPending != nil) || (aSelector != last8)) { |
|
5546 |
ilc8.ilc_func = __SEND8ADDR__; |
|
5547 |
if (ilc8.ilc_poly) { |
|
5548 |
__flushPolyCache(ilc8.ilc_poly); |
|
5549 |
ilc8.ilc_poly = 0; |
|
5550 |
} |
|
5551 |
last8 = aSelector; |
|
5552 |
} |
|
5553 |
RETURN ( (*ilc8.ilc_func)(self, aSelector, nil, &ilc8, |
|
5554 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5555 |
argP[5], argP[6], argP[7])); |
|
5556 |
} |
|
5557 |
||
5558 |
case 9: |
|
5559 |
{ |
|
5560 |
static OBJ last9 = nil; static struct inlineCache ilc9 = __ILCPERF9(@line); |
|
5561 |
||
5562 |
if ((InterruptPending != nil) || (aSelector != last9)) { |
|
5563 |
ilc9.ilc_func = __SEND9ADDR__; |
|
5564 |
if (ilc9.ilc_poly) { |
|
5565 |
__flushPolyCache(ilc9.ilc_poly); |
|
5566 |
ilc9.ilc_poly = 0; |
|
5567 |
} |
|
5568 |
last9 = aSelector; |
|
5569 |
} |
|
5570 |
RETURN ( (*ilc9.ilc_func)(self, aSelector, nil, &ilc9, |
|
5571 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5572 |
argP[5], argP[6], argP[7], argP[8])); |
|
5573 |
} |
|
5574 |
||
5575 |
case 10: |
|
5576 |
{ |
|
5577 |
static OBJ last10 = nil; static struct inlineCache ilc10 = __ILCPERF10(@line); |
|
5578 |
||
5579 |
if ((InterruptPending != nil) || (aSelector != last10)) { |
|
5580 |
ilc10.ilc_func = __SEND10ADDR__; |
|
5581 |
if (ilc10.ilc_poly) { |
|
5582 |
__flushPolyCache(ilc10.ilc_poly); |
|
5583 |
ilc10.ilc_poly = 0; |
|
5584 |
} |
|
5585 |
last10 = aSelector; |
|
5586 |
} |
|
5587 |
RETURN ( (*ilc10.ilc_func)(self, aSelector, nil, &ilc10, |
|
5588 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5589 |
argP[5], argP[6], argP[7], argP[8], argP[9])); |
|
5590 |
} |
|
5591 |
||
5592 |
case 11: |
|
5593 |
{ |
|
5594 |
static OBJ last11 = nil; static struct inlineCache ilc11 = __ILCPERF11(@line); |
|
5595 |
||
5596 |
if ((InterruptPending != nil) || (aSelector != last11)) { |
|
5597 |
ilc11.ilc_func = __SEND11ADDR__; |
|
5598 |
if (ilc11.ilc_poly) { |
|
5599 |
__flushPolyCache(ilc11.ilc_poly); |
|
5600 |
ilc11.ilc_poly = 0; |
|
5601 |
} |
|
5602 |
last11 = aSelector; |
|
5603 |
} |
|
5604 |
RETURN ( (*ilc11.ilc_func)(self, aSelector, nil, &ilc11, |
|
5605 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5606 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
5607 |
argP[10])); |
|
5608 |
} |
|
5609 |
||
5610 |
case 12: |
|
5611 |
{ |
|
5612 |
static OBJ last12 = nil; static struct inlineCache ilc12 = __ILCPERF12(@line); |
|
5613 |
||
5614 |
if ((InterruptPending != nil) || (aSelector != last12)) { |
|
5615 |
ilc12.ilc_func = __SEND12ADDR__; |
|
5616 |
if (ilc12.ilc_poly) { |
|
5617 |
__flushPolyCache(ilc12.ilc_poly); |
|
5618 |
ilc12.ilc_poly = 0; |
|
5619 |
} |
|
5620 |
last12 = aSelector; |
|
5621 |
} |
|
5622 |
RETURN ( (*ilc12.ilc_func)(self, aSelector, nil, &ilc12, |
|
5623 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5624 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
5625 |
argP[10], argP[11])); |
|
5626 |
} |
|
5627 |
||
5628 |
case 13: |
|
5629 |
{ |
|
5630 |
static OBJ last13 = nil; static struct inlineCache ilc13 = __ILCPERF13(@line); |
|
5631 |
||
5632 |
if ((InterruptPending != nil) || (aSelector != last13)) { |
|
5633 |
ilc13.ilc_func = __SEND13ADDR__; |
|
5634 |
if (ilc13.ilc_poly) { |
|
5635 |
__flushPolyCache(ilc13.ilc_poly); |
|
5636 |
ilc13.ilc_poly = 0; |
|
5637 |
} |
|
5638 |
last13 = aSelector; |
|
5639 |
} |
|
5640 |
RETURN ( (*ilc13.ilc_func)(self, aSelector, nil, &ilc13, |
|
5641 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5642 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
5643 |
argP[10], argP[11], argP[12])); |
|
5644 |
} |
|
5645 |
||
5646 |
case 14: |
|
5647 |
{ |
|
5648 |
static OBJ last14 = nil; static struct inlineCache ilc14 = __ILCPERF14(@line); |
|
5649 |
||
5650 |
if ((InterruptPending != nil) || (aSelector != last14)) { |
|
5651 |
ilc14.ilc_func = __SEND14ADDR__; |
|
5652 |
if (ilc14.ilc_poly) { |
|
5653 |
__flushPolyCache(ilc14.ilc_poly); |
|
5654 |
ilc14.ilc_poly = 0; |
|
5655 |
} |
|
5656 |
last14 = aSelector; |
|
5657 |
} |
|
5658 |
RETURN ( (*ilc14.ilc_func)(self, aSelector, nil, &ilc14, |
|
5659 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5660 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
5661 |
argP[10], argP[11], argP[12], argP[13])); |
|
5662 |
} |
|
5663 |
||
5664 |
case 15: |
|
5665 |
{ |
|
5666 |
static OBJ last15 = nil; static struct inlineCache ilc15 = __ILCPERF15(@line); |
|
5667 |
||
5668 |
if ((InterruptPending != nil) || (aSelector != last15)) { |
|
5669 |
ilc15.ilc_func = __SEND15ADDR__; |
|
5670 |
if (ilc15.ilc_poly) { |
|
5671 |
__flushPolyCache(ilc15.ilc_poly); |
|
5672 |
ilc15.ilc_poly = 0; |
|
5673 |
} |
|
5674 |
last15 = aSelector; |
|
5675 |
} |
|
5676 |
RETURN ( (*ilc15.ilc_func)(self, aSelector, nil, &ilc15, |
|
5677 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
5678 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
5679 |
argP[10], argP[11], argP[12], argP[13], |
|
5680 |
argP[14])); |
|
5681 |
} |
|
5682 |
} |
|
5683 |
bad:; |
|
5684 |
%}. |
|
5685 |
||
5686 |
"/ arrive here, if bad number of arguments (too many) |
|
5687 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
5688 |
||
5689 |
^ self primitiveFailed |
|
5690 |
! |
|
5691 |
||
5692 |
performMethod:aMethod |
|
5693 |
"invoke aMethod on the receiver. |
|
5694 |
The method should be a zero-argument method. |
|
5695 |
This is a non-object-oriented entry, applying a method |
|
5696 |
in a functional way on a receiver. |
|
5697 |
Warning: |
|
5698 |
Take care for the method to be appropriate for the |
|
5699 |
receiver - no checking is done by the VM." |
|
5700 |
||
5701 |
^ aMethod valueWithReceiver:self arguments:#() |
|
5702 |
||
5703 |
" |
|
5704 |
|mthd| |
|
5705 |
||
5706 |
mthd := SmallInteger compiledMethodAt:#negated. |
|
5707 |
Transcript showCR:(1 performMethod:mthd) |
|
5708 |
" |
|
5709 |
||
5710 |
"BAD USE example: |
|
5711 |
||
5712 |
|mthd| |
|
5713 |
||
5714 |
mthd := Point compiledMethodAt:#x. |
|
5715 |
Transcript showCR:((1->2) performMethod:mthd) |
|
5716 |
" |
|
5717 |
||
5718 |
"Modified: 31.7.1997 / 17:41:50 / cg" |
|
5719 |
! |
|
5720 |
||
5721 |
performMethod:aMethod arguments:argumentArray |
|
5722 |
"invoke aMethod on the receiver, passing an argumentArray. |
|
5723 |
The size of the argumentArray should match the number of args |
|
5724 |
expected by the method. |
|
5725 |
This is a non-object-oriented entry, applying a method |
|
5726 |
in a functional way on a receiver. |
|
5727 |
Warning: |
|
5728 |
Take care for the method to be appropriate for the |
|
5729 |
receiver - no checking is done by the VM." |
|
5730 |
||
5731 |
^ aMethod valueWithReceiver:self arguments:argumentArray |
|
5732 |
||
5733 |
" |
|
5734 |
|mthd| |
|
5735 |
||
5736 |
mthd := SmallInteger compiledMethodAt:#+. |
|
5737 |
Transcript showCR:(1 performMethod:mthd arguments:#(2)) |
|
5738 |
" |
|
5739 |
||
5740 |
"Created: 31.7.1997 / 17:46:31 / cg" |
|
5741 |
! |
|
5742 |
||
5743 |
performMethod:aMethod with:arg |
|
5744 |
"invoke aMethod on the receiver, passing an argument. |
|
5745 |
The method should be a one-argument method. |
|
5746 |
This is a non-object-oriented entry, applying a method |
|
5747 |
in a functional way on a receiver. |
|
5748 |
Warning: |
|
5749 |
Take care for the method to be appropriate for the |
|
5750 |
receiver - no checking is done by the VM." |
|
5751 |
||
5752 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg) |
|
5753 |
||
5754 |
" |
|
5755 |
|mthd| |
|
5756 |
||
5757 |
mthd := SmallInteger compiledMethodAt:#+. |
|
5758 |
Transcript showCR:(1 performMethod:mthd with:2) |
|
5759 |
" |
|
5760 |
||
5761 |
"Modified: 31.7.1997 / 17:42:32 / cg" |
|
5762 |
! |
|
5763 |
||
5764 |
performMethod:aMethod with:arg1 with:arg2 |
|
5765 |
"invoke aMethod on the receiver, passing two arguments. |
|
5766 |
The method should be a two-argument method. |
|
5767 |
This is a non-object-oriented entry, applying a method |
|
5768 |
in a functional way on a receiver. |
|
5769 |
Warning: |
|
5770 |
Take care for the method to be appropriate for the |
|
5771 |
receiver - no checking is done by the VM." |
|
5772 |
||
5773 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2) |
|
5774 |
||
5775 |
" |
|
5776 |
|mthd arr| |
|
5777 |
||
5778 |
arr := Array new:1. |
|
5779 |
mthd := Array compiledMethodAt:#basicAt:put:. |
|
5780 |
arr performMethod:mthd with:1 with:'foo'. |
|
5781 |
Transcript showCR:arr |
|
5782 |
" |
|
5783 |
||
5784 |
"Modified: 31.7.1997 / 17:44:54 / cg" |
|
5785 |
! |
|
5786 |
||
5787 |
performMethod:aMethod with:arg1 with:arg2 with:arg3 |
|
5788 |
"invoke aMethod on the receiver, passing three arguments. |
|
5789 |
The method should be a three-argument method. |
|
5790 |
This is a non-object-oriented entry, applying a method |
|
5791 |
in a functional way on a receiver. |
|
5792 |
Warning: |
|
5793 |
Take care for the method to be appropriate for the |
|
5794 |
receiver - no checking is done by the VM." |
|
5795 |
||
5796 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3) |
|
5797 |
||
5798 |
"Created: 31.7.1997 / 17:45:20 / cg" |
|
5799 |
! ! |
|
5800 |
||
5801 |
!Object methodsFor:'printing & storing'! |
|
5802 |
||
5803 |
className |
|
5804 |
"return the classname of the receivers class" |
|
5805 |
||
5806 |
^ self class name |
|
5807 |
||
5808 |
" |
|
5809 |
1 className |
|
5810 |
1 class className 'this may change ...' |
|
5811 |
$a className |
|
5812 |
$a class className 'this may change ...' |
|
5813 |
" |
|
5814 |
! |
|
5815 |
||
5816 |
classNameWithArticle |
|
5817 |
"return a string consisting of classname preceeded by an article. |
|
5818 |
(dont expect me to write national variants for this ... :-) |
|
5819 |
If you have special preferences, redefine it ..." |
|
5820 |
||
5821 |
|classname cls| |
|
5822 |
||
5823 |
(cls := self class) == self ifTrue:[ |
|
5824 |
^ 'a funny object' |
|
5825 |
]. |
|
5826 |
classname := cls displayString. |
|
5827 |
^ classname article , ' ' , classname |
|
5828 |
||
5829 |
" |
|
5830 |
1 classNameWithArticle |
|
5831 |
(1->2) classNameWithArticle |
|
5832 |
XWorkstation basicNew classNameWithArticle |
|
5833 |
" |
|
5834 |
||
5835 |
"Modified: 13.5.1996 / 12:16:14 / cg" |
|
5836 |
! |
|
5837 |
||
5838 |
errorPrint |
|
5839 |
"print the receiver on the standard error stream." |
|
5840 |
||
5841 |
Stream streamErrorSignal catch:[ |
|
5842 |
self printOn:Stderr |
|
5843 |
] |
|
5844 |
||
5845 |
"Modified: 7.3.1996 / 19:11:29 / cg" |
|
5846 |
! |
|
5847 |
||
5848 |
errorPrintCR |
|
5849 |
"{ Pragma: +optSpace }" |
|
5850 |
||
5851 |
"print the receiver followed by a cr on the standard error stream." |
|
5852 |
||
5853 |
Stream streamErrorSignal catch:[ |
|
5854 |
self printOn:Stderr. |
|
5855 |
Stderr cr |
|
5856 |
] |
|
5857 |
||
5858 |
"Modified: 7.3.1996 / 19:13:01 / cg" |
|
5859 |
"Created: 20.5.1996 / 10:20:41 / cg" |
|
5860 |
! |
|
5861 |
||
5862 |
errorPrintNL |
|
5863 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
5864 |
<resource:#obsolete> |
5755 | 5865 |
|
5866 |
"print the receiver followed by a cr on the standard error stream. |
|
5867 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
5868 |
||
5869 |
^ self errorPrintCR |
|
5870 |
||
5871 |
"Modified: 20.5.1996 / 10:24:45 / cg" |
|
5872 |
! |
|
5873 |
||
5874 |
errorPrintNewline |
|
5875 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
5876 |
<resource:#obsolete> |
5755 | 5877 |
|
5878 |
"print the receiver followed by a cr on the standard error stream. |
|
5879 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
5880 |
||
5881 |
self errorPrintCR. |
|
5882 |
||
5883 |
"Modified: 20.5.1996 / 10:24:38 / cg" |
|
5884 |
! |
|
5885 |
||
5886 |
infoPrint |
|
5887 |
"{ Pragma: +optSpace }" |
|
5888 |
||
5889 |
"print the receiver on the standard error stream. |
|
5890 |
This is meant for information messages which are not warnings |
|
5891 |
or fatal messages. |
|
5892 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
5893 |
||
5894 |
InfoPrinting == true ifTrue:[ |
|
5895 |
self errorPrint |
|
5896 |
] |
|
5897 |
! |
|
5898 |
||
5899 |
infoPrintCR |
|
5900 |
"{ Pragma: +optSpace }" |
|
5901 |
||
5902 |
"print the receiver followed by a cr on the standard error stream. |
|
5903 |
This is meant for information messages which are not warnings |
|
5904 |
or fatal messages. |
|
5905 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
|
5906 |
||
5907 |
InfoPrinting == true ifTrue:[ |
|
5908 |
self errorPrintCR |
|
5909 |
] |
|
5910 |
||
5911 |
"Created: 20.5.1996 / 10:21:28 / cg" |
|
5912 |
! |
|
5913 |
||
5914 |
infoPrintNL |
|
5915 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
5916 |
<resource:#obsolete> |
5755 | 5917 |
|
5918 |
"print the receiver followed by a cr on the standard error stream. |
|
5919 |
Please use #infoPrintCR - this method exists for backward compatibility." |
|
5920 |
||
5921 |
^ self infoPrintCR |
|
5922 |
! |
|
5923 |
||
5924 |
||
5925 |
"print the receiver on the standard output stream (which is not the Transcript)" |
|
5926 |
||
5927 |
"/ the following allows printCR to be used during |
|
5928 |
"/ the early init-phase, when no Stdout has been set up. |
|
5929 |
"/ (depends on string to respond to #print) |
|
5930 |
||
5931 |
Stdout isNil ifTrue:[ |
|
5932 |
self printString print. |
|
5933 |
^ self |
|
5934 |
]. |
|
5935 |
self printOn:Stdout |
|
5936 |
||
5937 |
"Modified: 4.11.1996 / 23:36:58 / cg" |
|
5938 |
! |
|
5939 |
||
5940 |
printCR |
|
5941 |
"print the receiver followed by a cr on the standard output stream (which is not the Transcript)" |
|
5942 |
||
5943 |
"/ the following allows printCR to be used during |
|
5944 |
"/ the early init-phase, when no Stdout has been set up. |
|
5945 |
"/ (depends on string to respond to #printCR) |
|
5946 |
||
5947 |
Stdout isNil ifTrue:[ |
|
5948 |
self printString printCR. |
|
5949 |
^ self |
|
5950 |
]. |
|
5951 |
self printOn:Stdout. |
|
5952 |
Stdout cr |
|
5953 |
||
5954 |
"Created: 20.5.1996 / 10:21:37 / cg" |
|
5955 |
"Modified: 4.11.1996 / 23:37:06 / cg" |
|
5956 |
! |
|
5957 |
||
5958 |
printNL |
|
5959 |
"print the receiver followed by a cr on the standard output stream |
|
5960 |
This exists for GNU Smalltalk compatibility - please use #printCR." |
|
5961 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
5962 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
5963 |
|
5755 | 5964 |
^ self printCR |
5965 |
||
5966 |
"Modified: 20.5.1996 / 10:25:31 / cg" |
|
5967 |
! |
|
5968 |
||
5969 |
printNewline |
|
5970 |
"print the receiver followed by a cr on the standard output stream. |
|
5971 |
This exists for backward compatibility - please use #printCR." |
|
5972 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
5973 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
5974 |
|
5755 | 5975 |
self printCR |
5976 |
||
5977 |
"Modified: 20.5.1996 / 10:25:46 / cg" |
|
5978 |
! |
|
5979 |
||
5980 |
printOn:aStream |
|
5981 |
"append a user printed representation of the receiver to aStream. |
|
5982 |
The format is suitable for a human - not meant to be read back. |
|
5983 |
||
5984 |
The default here is to output the receivers class name. |
|
5985 |
BUT: this method is heavily redefined for objects which |
|
5986 |
can print prettier." |
|
5987 |
||
5988 |
aStream nextPutAll:self classNameWithArticle |
|
5989 |
! |
|
5990 |
||
5991 |
printOn:aStream leftPaddedTo:size |
|
5992 |
"print the receiver on aStream, padding with spaces up to size. |
|
5993 |
padding is done on the left." |
|
5994 |
||
5995 |
self printOn:aStream leftPaddedTo:size with:(Character space) |
|
5996 |
||
5997 |
" |
|
5998 |
123 printOn:Transcript leftPaddedTo:10. Transcript cr |
|
5999 |
123 printOn:Transcript leftPaddedTo:2. Transcript cr |
|
6000 |
" |
|
6001 |
! |
|
6002 |
||
6003 |
printOn:aStream leftPaddedTo:size with:padCharacter |
|
6004 |
"print the receiver on aStream, padding with padCharacters up to size. |
|
6005 |
padding is done on the left." |
|
6006 |
||
6007 |
aStream nextPutAll:(self printStringLeftPaddedTo:size with:padCharacter) |
|
6008 |
||
6009 |
" |
|
6010 |
123 printOn:Transcript leftPaddedTo:10 with:$_ . Transcript cr |
|
6011 |
123 printOn:Transcript leftPaddedTo:10 with:$. . Transcript cr |
|
6012 |
" |
|
6013 |
! |
|
6014 |
||
6015 |
printOn:aStream paddedTo:size |
|
6016 |
"print the receiver on aStream, padding with spaces up to size." |
|
6017 |
||
6018 |
self printOn:aStream paddedTo:size with:(Character space) |
|
6019 |
||
6020 |
" |
|
6021 |
123.0 printOn:Transcript paddedTo:10. Transcript nextPut:$|. Transcript cr |
|
6022 |
" |
|
6023 |
! |
|
6024 |
||
6025 |
printOn:aStream paddedTo:size with:padCharacter |
|
6026 |
"print the receiver on aStream, padding with padCharacter up to size" |
|
6027 |
||
6028 |
aStream nextPutAll:(self printStringPaddedTo:size with:padCharacter). |
|
6029 |
||
6030 |
" |
|
6031 |
123 printOn:Transcript paddedTo:10 with:$_ . Transcript cr |
|
6032 |
123 printOn:Transcript paddedTo:10 with:$. . Transcript cr |
|
6033 |
" |
|
6034 |
! |
|
6035 |
||
6036 |
printOn:aStream zeroPaddedTo:size |
|
6037 |
"print the receiver on aStream, padding with zeros up to size. |
|
6038 |
Usually used with float numbers." |
|
6039 |
||
6040 |
self printOn:aStream paddedTo:size with:$0. |
|
6041 |
||
6042 |
" |
|
6043 |
123.0 printOn:Transcript zeroPaddedTo:10 |
|
6044 |
" |
|
6045 |
! |
|
6046 |
||
6047 |
printRightAdjustLen:size |
|
6048 |
"obsolete - just a name confusion. |
|
6049 |
This method will go away ..." |
|
6050 |
||
6051 |
(self printStringLeftPaddedTo:size) printOn:Stdout |
|
6052 |
! |
|
6053 |
||
6054 |
printString |
|
6055 |
"return a string for printing the receiver. |
|
6056 |
Since we now use printOn: as the basic print mechanism, |
|
6057 |
we have to create a stream and print into it." |
|
6058 |
||
6059 |
|s| |
|
6060 |
||
6061 |
s := WriteStream on:(String new:30). |
|
6062 |
self printOn:s. |
|
6063 |
^ s contents |
|
6064 |
! |
|
6065 |
||
6066 |
printStringLeftPaddedTo:size |
|
6067 |
"return my printString as a right-adjusted string of length size; |
|
6068 |
characters on the left are filled with spaces. |
|
6069 |
If the printString is longer than size, |
|
6070 |
it is returned unchanged (i.e. not truncated)" |
|
6071 |
||
6072 |
^ self printStringLeftPaddedTo:size with:(Character space) |
|
6073 |
||
6074 |
" |
|
6075 |
10 printStringLeftPaddedTo:10 |
|
6076 |
1 printStringLeftPaddedTo:10 |
|
6077 |
" |
|
6078 |
! |
|
6079 |
||
6080 |
printStringLeftPaddedTo:size ifLarger:alternative |
|
6081 |
"return my printString as a right-adjusted string of length size; |
|
6082 |
characters on the left are filled with spaces. |
|
6083 |
If the printString is larger than size, |
|
6084 |
return the result from evaluating alternative." |
|
6085 |
||
6086 |
^ self printStringLeftPaddedTo:size with:(Character space) ifLarger:alternative |
|
6087 |
||
6088 |
" |
|
6089 |
12 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6090 |
123 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6091 |
1234 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
6092 |
" |
|
6093 |
! |
|
6094 |
||
6095 |
printStringLeftPaddedTo:size with:padCharacter |
|
6096 |
"return my printString as a right-adjusted string of length size; |
|
6097 |
characters on the left are filled with padCharacter. |
|
6098 |
If the printString is longer than size, |
|
6099 |
it is returned unchanged (i.e. not truncated)" |
|
6100 |
||
6101 |
^ (self printString) leftPaddedTo:size with:padCharacter |
|
6102 |
||
6103 |
" |
|
6104 |
123 printStringLeftPaddedTo:10 with:$. |
|
6105 |
1 printStringLeftPaddedTo:10 with:$. |
|
6106 |
(Float pi) printStringLeftPaddedTo:20 with:$* |
|
6107 |
" |
|
6108 |
! |
|
6109 |
||
6110 |
printStringLeftPaddedTo:size with:padCharacter ifLarger:alternative |
|
6111 |
"return my printString as a right-adjusted string of length size; |
|
6112 |
characters on the left are filled with padCharacter. |
|
6113 |
If the printString is larger than size, |
|
6114 |
return the result from evaluating alternative." |
|
6115 |
||
6116 |
|s| |
|
6117 |
||
6118 |
s := self printString. |
|
6119 |
s size > size ifTrue:[^ alternative value]. |
|
6120 |
^ s leftPaddedTo:size with:padCharacter |
|
6121 |
||
6122 |
" |
|
6123 |
12 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6124 |
123 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6125 |
1234 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
6126 |
" |
|
6127 |
! |
|
6128 |
||
6129 |
printStringOnError:exceptionBlock |
|
6130 |
"return a string for printing the receiver; if any error occurs, return the result from |
|
6131 |
evaluating exceptionBlock. Useful to print something in an exceptionHandler or other |
|
6132 |
cleanup code." |
|
6133 |
||
6134 |
|rslt| |
|
6135 |
||
6136 |
Error handle:[:ex | |
|
6137 |
rslt := exceptionBlock value |
|
6138 |
] do:[ |
|
6139 |
rslt := self printString |
|
6140 |
]. |
|
6141 |
^ rslt |
|
6142 |
! |
|
6143 |
||
6144 |
printStringPaddedTo:size |
|
6145 |
"return a printed representation of the receiver, |
|
6146 |
padded with spaces (at the right) up to size. |
|
6147 |
If the printString is longer than size, |
|
6148 |
it is returned unchanged (i.e. not truncated)" |
|
6149 |
||
6150 |
^ self printStringPaddedTo:size with:(Character space) |
|
6151 |
||
6152 |
" |
|
6153 |
123 printStringPaddedTo:10 |
|
6154 |
1234567890123456 printStringPaddedTo:10 |
|
6155 |
'hello' printStringPaddedTo:10 |
|
6156 |
" |
|
6157 |
! |
|
6158 |
||
6159 |
printStringPaddedTo:size ifLarger:alternative |
|
6160 |
"return a printed representation of the receiver, |
|
6161 |
padded with spaces (at the right) up to size. |
|
6162 |
If the resulting printString is too large, |
|
6163 |
return the result from evaluating alternative." |
|
6164 |
||
6165 |
^ self printStringPaddedTo:size with:(Character space) ifLarger:alternative |
|
6166 |
||
6167 |
" |
|
6168 |
12 printStringPaddedTo:3 ifLarger:['***'] |
|
6169 |
123 printStringPaddedTo:3 ifLarger:['***'] |
|
6170 |
1234 printStringPaddedTo:3 ifLarger:['***'] |
|
6171 |
" |
|
6172 |
! |
|
6173 |
||
6174 |
printStringPaddedTo:size with:padCharacter |
|
6175 |
"return a printed representation of the receiver, |
|
6176 |
padded with padCharacter (at the right) up to size. |
|
6177 |
If the printString is longer than size, |
|
6178 |
it is returned unchanged (i.e. not truncated)" |
|
6179 |
||
6180 |
^ (self printString) paddedTo:size with:padCharacter |
|
6181 |
||
6182 |
" |
|
6183 |
123 printStringPaddedTo:10 with:$. |
|
6184 |
123 printStringPaddedTo:10 with:$* |
|
6185 |
123 printStringPaddedTo:3 with:$* |
|
6186 |
1234 printStringPaddedTo:3 with:$* |
|
6187 |
" |
|
6188 |
! |
|
6189 |
||
6190 |
printStringPaddedTo:size with:padCharacter ifLarger:alternative |
|
6191 |
"return a printed representation of the receiver, |
|
6192 |
padded with padCharacter (at the right) up to size. |
|
6193 |
If the resulting printString is too large, |
|
6194 |
return the result from evaluating alternative." |
|
6195 |
||
6196 |
|s| |
|
6197 |
||
6198 |
s := self printString. |
|
6199 |
s size > size ifTrue:[^ alternative value]. |
|
6200 |
^ s paddedTo:size with:padCharacter |
|
6201 |
||
6202 |
" |
|
6203 |
123 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
6204 |
12345 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
6205 |
" |
|
6206 |
! |
|
6207 |
||
6208 |
printStringRightAdjustLen:size |
|
6209 |
"obsolete - just a name confusion. |
|
6210 |
This method will go away ..." |
|
6211 |
||
6212 |
^ self printStringLeftPaddedTo:size |
|
6213 |
! |
|
6214 |
||
6215 |
printStringZeroPaddedTo:size |
|
6216 |
"return a printed representation of the receiver, |
|
6217 |
padded with zero (at the right) characters up to size. |
|
6218 |
Usually used with float numbers." |
|
6219 |
||
6220 |
^ self printStringPaddedTo:size with:$0 |
|
6221 |
||
6222 |
" |
|
6223 |
123.0 printStringZeroPaddedTo:10 |
|
6224 |
" |
|
6225 |
! |
|
6226 |
||
6227 |
store |
|
6228 |
"store the receiver on standard output. |
|
6229 |
this method is useless, but included for compatibility." |
|
6230 |
||
6231 |
self storeOn:Stdout |
|
6232 |
! |
|
6233 |
||
6234 |
storeCR |
|
6235 |
"store the receiver on standard output; append a carriage return." |
|
6236 |
||
6237 |
self store. |
|
6238 |
Character cr print |
|
6239 |
||
6240 |
"Created: 20.5.1996 / 10:26:01 / cg" |
|
6241 |
"Modified: 20.5.1996 / 10:26:57 / cg" |
|
6242 |
! |
|
6243 |
||
6244 |
storeNl |
|
6245 |
"store the receiver on standard output; append a newline. |
|
6246 |
This method is included for backward compatibility- use #storeCR." |
|
6247 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6248 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
6249 |
|
5755 | 6250 |
self storeCR. |
6251 |
||
6252 |
"Modified: 20.5.1996 / 10:26:49 / cg" |
|
6253 |
! |
|
6254 |
||
6255 |
storeOn:aStream |
|
6256 |
"store the receiver on aStream; i.e. print an expression which will |
|
6257 |
reconstruct the receiver. |
|
6258 |
Notice, that no self referencing or cyclic objects can be represented |
|
6259 |
in this format. |
|
6260 |
Use storeBinaryOn:, which handles these cases correctly." |
|
6261 |
||
6262 |
|myClass hasSemi sz "{ Class: SmallInteger }" | |
|
6263 |
||
6264 |
thisContext isRecursive ifTrue:[ |
|
6265 |
Object recursiveStoreStringSignal raiseRequestWith:self. |
|
6266 |
('Object [error]: storeString of self referencing object.') errorPrintCR. |
|
6267 |
aStream nextPutAll:'#("recursive")'. |
|
6268 |
^ self |
|
6269 |
]. |
|
6270 |
||
6271 |
myClass := self class. |
|
6272 |
aStream nextPut:$(. |
|
6273 |
aStream nextPutAll:self class name. |
|
6274 |
||
6275 |
hasSemi := false. |
|
6276 |
myClass isVariable ifTrue:[ |
|
6277 |
aStream nextPutAll:' basicNew:'. |
|
6278 |
self basicSize printOn:aStream |
|
6279 |
] ifFalse:[ |
|
6280 |
aStream nextPutAll:' basicNew' |
|
6281 |
]. |
|
6282 |
||
6283 |
sz := myClass instSize. |
|
6284 |
1 to:sz do:[:i | |
|
6285 |
aStream nextPutAll:' instVarAt:'. |
|
6286 |
i printOn:aStream. |
|
6287 |
aStream nextPutAll:' put:'. |
|
6288 |
(self instVarAt:i) storeOn:aStream. |
|
6289 |
aStream nextPut:$;. |
|
6290 |
hasSemi := true |
|
6291 |
]. |
|
6292 |
myClass isVariable ifTrue:[ |
|
6293 |
sz := self basicSize. |
|
6294 |
1 to:sz do:[:i | |
|
6295 |
aStream nextPutAll:' basicAt:'. |
|
6296 |
i printOn:aStream. |
|
6297 |
aStream nextPutAll:' put:'. |
|
6298 |
(self basicAt:i) storeOn:aStream. |
|
6299 |
aStream nextPut:$;. |
|
6300 |
hasSemi := true |
|
6301 |
] |
|
6302 |
]. |
|
6303 |
hasSemi ifTrue:[ |
|
6304 |
aStream nextPutAll:' yourself' |
|
6305 |
]. |
|
6306 |
aStream nextPut:$). |
|
6307 |
||
6308 |
" |
|
6309 |
|s| |
|
6310 |
||
6311 |
s := WriteStream on:(String new). |
|
6312 |
('hello' -> 'world') storeOn:s. |
|
6313 |
s := ReadStream on:(s contents). |
|
6314 |
(Object readFrom:s) inspect |
|
6315 |
" |
|
6316 |
" |
|
6317 |
|s| |
|
6318 |
||
6319 |
s := 'data' asFilename writeStream. |
|
6320 |
('hello' -> 'world') storeOn:s. |
|
6321 |
s close. |
|
6322 |
||
6323 |
s := 'data' asFilename readStream. |
|
6324 |
(Object readFrom:s) inspect |
|
6325 |
" |
|
6326 |
||
6327 |
"does not work example:" |
|
6328 |
" |
|
6329 |
|s a| |
|
6330 |
||
6331 |
a := Array new:2. |
|
6332 |
a at:1 put:a. |
|
6333 |
||
6334 |
s := 'data' asFilename writeStream. |
|
6335 |
a storeOn:s. |
|
6336 |
s close. |
|
6337 |
||
6338 |
s := 'data' asFilename readStream. |
|
6339 |
(Object readFrom:s) inspect |
|
6340 |
" |
|
6341 |
||
6342 |
"Modified: 28.1.1997 / 00:36:12 / cg" |
|
6343 |
! |
|
6344 |
||
6345 |
storeString |
|
6346 |
"return a string representing an expression to reconstruct the receiver. |
|
6347 |
Notice, that no self referencing or cyclic objects can be represented |
|
6348 |
in this format. |
|
6349 |
Use storeBinaryOn:, which handles these cases correctly." |
|
6350 |
||
6351 |
|s| |
|
6352 |
||
6353 |
s := WriteStream on:(String new:50). |
|
6354 |
self storeOn:s. |
|
6355 |
^ s contents |
|
6356 |
! ! |
|
6357 |
||
6358 |
!Object methodsFor:'private'! |
|
6359 |
||
6360 |
isHierarchicalItem |
|
6361 |
"used to decide if the parent is a hierarchical item |
|
6362 |
or the model |
|
6363 |
" |
|
6364 |
^ false |
|
6365 |
! ! |
|
6366 |
||
6367 |
!Object methodsFor:'queries'! |
|
6368 |
||
6369 |
basicSize |
|
6370 |
"return the number of the receivers indexed instance variables, |
|
6371 |
0 if it has none. |
|
6372 |
||
6373 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
6374 |
||
6375 |
%{ /* NOCONTEXT */ |
|
6376 |
||
6377 |
REGISTER int nbytes; |
|
6378 |
REGISTER OBJ myClass; |
|
6379 |
int nInstBytes; |
|
6380 |
||
6381 |
/* |
|
6382 |
* notice the missing test for self being a nonNilObject - |
|
6383 |
* this can be done since basicSize is defined both in UndefinedObject |
|
6384 |
* and SmallInteger |
|
6385 |
*/ |
|
6386 |
myClass = __qClass(self); |
|
6387 |
nbytes = __qSize(self); |
|
6388 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__( __intVal(__ClassInstPtr(myClass)->c_ninstvars) ); |
|
6389 |
||
6390 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
6391 |
case __MASKSMALLINT(POINTERARRAY): |
|
6392 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
6393 |
nbytes -= nInstBytes; |
|
6394 |
RETURN ( __MKSMALLINT(__BYTES2OBJS__(nbytes)) ); |
|
6395 |
||
6396 |
case __MASKSMALLINT(BYTEARRAY): |
|
6397 |
nbytes -= nInstBytes; |
|
6398 |
RETURN ( __MKSMALLINT(nbytes / sizeof(char)) ); |
|
6399 |
||
6400 |
case __MASKSMALLINT(FLOATARRAY): |
|
6401 |
nbytes -= nInstBytes; |
|
6402 |
RETURN ( __MKSMALLINT(nbytes / sizeof(float)) ); |
|
6403 |
||
6404 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
6405 |
#ifdef __NEED_DOUBLE_ALIGN |
|
6406 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
|
6407 |
#endif |
|
6408 |
nbytes -= nInstBytes; |
|
6409 |
RETURN ( __MKSMALLINT(nbytes / sizeof(double)) ); |
|
6410 |
||
6411 |
case __MASKSMALLINT(WORDARRAY): |
|
6412 |
case __MASKSMALLINT(SWORDARRAY): |
|
6413 |
nbytes -= nInstBytes; |
|
6414 |
RETURN ( __MKSMALLINT(nbytes>>1) ); /* notice the hardcoded 2 here - not sizeof(short) */ |
|
6415 |
||
6416 |
case __MASKSMALLINT(LONGARRAY): |
|
6417 |
case __MASKSMALLINT(SLONGARRAY): |
|
6418 |
nbytes -= nInstBytes; |
|
6419 |
RETURN ( __MKSMALLINT(nbytes>>2) ); /* notice the hardcoded 4 here - not sizeof(int) */ |
|
6420 |
||
6421 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
6422 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
6423 |
#ifdef __NEED_LONGLONG_ALIGN |
|
6424 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
|
6425 |
#endif |
|
6426 |
nbytes -= nInstBytes; |
|
6427 |
RETURN ( __MKSMALLINT(nbytes>>3) ); /* notice the hardcoded 8 here - not sizeof(long long) */ |
|
6428 |
} |
|
6429 |
%}. |
|
6430 |
^ 0 |
|
6431 |
! |
|
6432 |
||
6433 |
byteSize |
|
6434 |
"return the number of bytes in the receivers indexed instance variables, |
|
6435 |
0 if it has none. This only returns non-zero for non-pointer indexed |
|
6436 |
instvars i.e. byteArrays, wordArrays etc. |
|
6437 |
Notice: for Strings the returned size may look strange. |
|
6438 |
Only useful with binary storage." |
|
6439 |
||
6440 |
|myClass| |
|
6441 |
||
6442 |
myClass := self class. |
|
6443 |
myClass isVariable ifTrue:[ |
|
6444 |
myClass isPointers ifFalse:[ |
|
6445 |
myClass isBytes ifTrue:[ |
|
6446 |
^ self basicSize. |
|
6447 |
]. |
|
6448 |
myClass isWords ifTrue:[ |
|
6449 |
^ self basicSize * 2. |
|
6450 |
]. |
|
6451 |
myClass isSignedWords ifTrue:[ |
|
6452 |
^ self basicSize * 2. |
|
6453 |
]. |
|
6454 |
myClass isLongs ifTrue:[ |
|
6455 |
^ self basicSize * 4. |
|
6456 |
]. |
|
6457 |
myClass isSignedLongs ifTrue:[ |
|
6458 |
^ self basicSize * 4. |
|
6459 |
]. |
|
6460 |
myClass isLongLongs ifTrue:[ |
|
6461 |
^ self basicSize * 8. |
|
6462 |
]. |
|
6463 |
myClass isSignedLongLongs ifTrue:[ |
|
6464 |
^ self basicSize * 8. |
|
6465 |
]. |
|
6466 |
myClass isFloats ifTrue:[ |
|
6467 |
^ self basicSize * (ExternalBytes sizeofFloat) |
|
6468 |
]. |
|
6469 |
myClass isDoubles ifTrue:[ |
|
6470 |
^ self basicSize * (ExternalBytes sizeofDouble) |
|
6471 |
]. |
|
6472 |
self halt:'oops'. |
|
6473 |
] |
|
6474 |
]. |
|
6475 |
^ 0 |
|
6476 |
||
6477 |
" |
|
6478 |
Point new byteSize |
|
6479 |
'hello' byteSize |
|
6480 |
(ByteArray with:1 with:2) byteSize |
|
6481 |
(FloatArray with:1.5) byteSize |
|
6482 |
(DoubleArray with:1.5) byteSize |
|
6483 |
(WordArray with:1 with:2) byteSize |
|
6484 |
" |
|
6485 |
! |
|
6486 |
||
6487 |
class |
|
6488 |
"return the receivers class" |
|
6489 |
||
6490 |
%{ /* NOCONTEXT */ |
|
6491 |
||
6492 |
RETURN ( __Class(self) ); |
|
6493 |
%} |
|
6494 |
! |
|
6495 |
||
6496 |
respondsTo:aSelector |
|
6497 |
"return true, if the receiver implements a method with selector equal |
|
6498 |
to aSelector; i.e. if there is a method for aSelector in either the |
|
6499 |
receivers class or one of its superclasses. |
|
6500 |
||
6501 |
Notice, that this does not imply, that such a message can be sent without |
|
6502 |
an error being raised. For example, an implementation could send |
|
6503 |
#shouldNotImplement or #subclassResponsibility." |
|
6504 |
||
6505 |
" |
|
6506 |
should we go via the cache, or search (by class) ? |
|
6507 |
The first is faster, most of the time; while the 2nd fills |
|
6508 |
the cache with useless data if this is sent in a loop over all objects. |
|
6509 |
For now, use the cache ... |
|
6510 |
" |
|
6511 |
%{ /* NOCONTEXT */ |
|
6512 |
||
6513 |
if (__lookup(__Class(self), aSelector) == nil) { |
|
6514 |
RETURN ( false ); |
|
6515 |
} |
|
6516 |
RETURN ( true ); |
|
6517 |
%} |
|
6518 |
. |
|
6519 |
^ self class canUnderstand:aSelector |
|
6520 |
||
6521 |
||
6522 |
"'aString' respondsTo:#+" |
|
6523 |
"'aString' respondsTo:#," |
|
6524 |
"'aString' respondsTo:#collect:" |
|
6525 |
! |
|
6526 |
||
6527 |
respondsToArithmetic |
|
6528 |
"return true, if the receiver responds to arithmetic messages. |
|
6529 |
false is returned here - the method is redefined in ArithmeticValue." |
|
6530 |
||
6531 |
^ false |
|
6532 |
! |
|
6533 |
||
6534 |
size |
|
6535 |
"return the number of the receivers indexed instance variables; |
|
6536 |
this method may be redefined in subclasses" |
|
6537 |
||
6538 |
^ self basicSize |
|
6539 |
! |
|
6540 |
||
6541 |
species |
|
6542 |
"return a class which is similar to (or the same as) the receivers class. |
|
6543 |
This is used to create an appropriate object when creating derived |
|
6544 |
copies in the collection classes (sometimes redefined)." |
|
6545 |
||
6546 |
^ self class |
|
6547 |
! |
|
6548 |
||
6549 |
yourself |
|
6550 |
"return the receiver - used for cascades to return self at the end" |
|
6551 |
||
6552 |
^ self |
|
6553 |
! ! |
|
6554 |
||
6555 |
!Object methodsFor:'secure message sending'! |
|
6556 |
||
6557 |
askFor:aSelector |
|
6558 |
"try to send the receiver the message, aSelector. |
|
6559 |
If it does not understand it, return false. |
|
6560 |
Otherwise the real value returned. |
|
6561 |
Useful to send messages such as: #isColor to unknown |
|
6562 |
receivers." |
|
6563 |
||
6564 |
^ self perform:aSelector ifNotUnderstood:[false] |
|
6565 |
||
6566 |
" |
|
6567 |
1 askFor:#isColor |
|
6568 |
Color red askFor:#isColor |
|
6569 |
||
6570 |
1 askFor:#isFoo |
|
6571 |
Color red askFor:#isFoo |
|
6572 |
" |
|
6573 |
! |
|
6574 |
||
6575 |
perform:aSelector ifNotUnderstood:exceptionBlock |
|
6576 |
"try to send message aSelector to the receiver. |
|
6577 |
If its understood, return the methods returned value, |
|
6578 |
otherwise return the value of the exceptionBlock" |
|
6579 |
||
6580 |
|val ok| |
|
6581 |
||
6582 |
MessageNotUnderstoodSignal handle:[:ex | |
|
6583 |
"/ reject, if the bad message is not the one |
|
6584 |
"/ we have sent originally |
|
6585 |
ex parameter selector == aSelector ifFalse:[ |
|
6586 |
ex reject |
|
6587 |
] |
|
6588 |
] do:[ |
|
6589 |
val := self perform:aSelector. |
|
6590 |
ok := true. |
|
6591 |
]. |
|
6592 |
ok isNil ifTrue:[ |
|
6593 |
^ exceptionBlock value |
|
6594 |
]. |
|
6595 |
^ val |
|
6596 |
||
6597 |
" |
|
6598 |
1.2345 perform:#foo ifNotUnderstood:['sorry'] |
|
6599 |
1.2345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
6600 |
12345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
6601 |
" |
|
6602 |
! |
|
6603 |
||
6604 |
perform:aSelector with:argument ifNotUnderstood:exceptionBlock |
|
6605 |
"try to send message aSelector to the receiver. |
|
6606 |
If its understood, return the methods returned value, |
|
6607 |
otherwise return the value of the exceptionBlock" |
|
6608 |
||
6609 |
|val ok| |
|
6610 |
||
6611 |
MessageNotUnderstoodSignal handle:[:ex | |
|
6612 |
"/ reject, if the bad message is not the one |
|
6613 |
"/ we have sent originally |
|
6614 |
ex parameter selector == aSelector ifFalse:[ |
|
6615 |
ex reject |
|
6616 |
] |
|
6617 |
] do:[ |
|
6618 |
val := self perform:aSelector with:argument. |
|
6619 |
ok := true. |
|
6620 |
]. |
|
6621 |
ok isNil ifTrue:[ |
|
6622 |
^ exceptionBlock value |
|
6623 |
]. |
|
6624 |
^ val |
|
6625 |
||
6626 |
" |
|
6627 |
|unknown| |
|
6628 |
||
6629 |
unknown := 1. |
|
6630 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
6631 |
unknown := 'high there'. |
|
6632 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
6633 |
" |
|
6634 |
! |
|
6635 |
||
5926 | 6636 |
perform:aSelector with:arg1 with:arg2 ifNotUnderstood:exceptionBlock |
6637 |
"try to send message aSelector to the receiver. |
|
6638 |
If its understood, return the methods returned value, |
|
6639 |
otherwise return the value of the exceptionBlock" |
|
6640 |
||
6641 |
|val ok| |
|
6642 |
||
6643 |
MessageNotUnderstoodSignal handle:[:ex | |
|
6644 |
"/ reject, if the bad message is not the one |
|
6645 |
"/ we have sent originally |
|
6646 |
ex parameter selector == aSelector ifFalse:[ |
|
6647 |
ex reject |
|
6648 |
] |
|
6649 |
] do:[ |
|
6650 |
val := self perform:aSelector with:arg1 with:arg2. |
|
6651 |
ok := true. |
|
6652 |
]. |
|
6653 |
ok isNil ifTrue:[ |
|
6654 |
^ exceptionBlock value |
|
6655 |
]. |
|
6656 |
^ val |
|
6657 |
||
6658 |
" |
|
6659 |
|unknown| |
|
6660 |
||
6661 |
unknown := 1. |
|
6662 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
6663 |
unknown := 'high there'. |
|
6664 |
(unknown perform:#+ with:2 ifNotUnderstood:['sorry']) printNewline. |
|
6665 |
" |
|
6666 |
! |
|
6667 |
||
5755 | 6668 |
perform:aSelector withArguments:argumentArray ifNotUnderstood:exceptionBlock |
6669 |
"try to send message aSelector to the receiver. |
|
6670 |
If its understood, return the methods returned value, |
|
6671 |
otherwise return the value of the exceptionBlock" |
|
6672 |
||
6673 |
|val ok| |
|
6674 |
||
6675 |
MessageNotUnderstoodSignal handle:[:ex | |
|
6676 |
"/ reject, if the bad message is not the one |
|
6677 |
"/ we have sent originally |
|
6678 |
ex parameter selector == aSelector ifFalse:[ |
|
6679 |
ex reject |
|
6680 |
] |
|
6681 |
] do:[ |
|
6682 |
val := self perform:aSelector withArguments:argumentArray. |
|
6683 |
ok := true. |
|
6684 |
]. |
|
6685 |
ok isNil ifTrue:[ |
|
6686 |
^ exceptionBlock value |
|
6687 |
]. |
|
6688 |
^ val |
|
6689 |
||
6690 |
" |
|
6691 |
|unknown| |
|
6692 |
||
6693 |
unknown := 1. |
|
6694 |
(unknown perform:#+ withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
|
6695 |
unknown := 'high there'. |
|
6696 |
(unknown perform:#+ withArguments:#(2) ifNotUnderstood:['sorry']) printNewline. |
|
6697 |
" |
|
6698 |
||
6699 |
"Modified: 27.3.1997 / 14:13:16 / cg" |
|
6700 |
! ! |
|
6701 |
||
6702 |
!Object methodsFor:'signal constants'! |
|
6703 |
||
6704 |
messageNotUnderstoodSignal |
|
6705 |
^ MessageNotUnderstoodSignal |
|
6706 |
||
6707 |
"Created: 6.3.1997 / 15:46:52 / cg" |
|
6708 |
! ! |
|
6709 |
||
6710 |
!Object methodsFor:'special queries'! |
|
6711 |
||
6712 |
allOwners |
|
6713 |
"return a collection of all objects referencing the receiver" |
|
6714 |
||
6715 |
^ ObjectMemory whoReferences:self |
|
6716 |
! |
|
6717 |
||
6718 |
references:anObject |
|
6719 |
"return true, if the receiver refers to the argument, anObject. |
|
6720 |
- for debugging only" |
|
6721 |
||
6722 |
%{ /* NOCONTEXT */ |
|
6723 |
OBJ cls, flags; |
|
6724 |
int nInsts, i; |
|
6725 |
||
6726 |
if (! __isNonNilObject(self)) { |
|
6727 |
RETURN (false); |
|
6728 |
} |
|
6729 |
||
6730 |
/* |
|
6731 |
* a little optimization: use the fact that all old objects |
|
6732 |
* refering to a new object are on the remSet; if I am not, |
|
6733 |
* a trivial reject is possible, if anObject is a newbee |
|
6734 |
*/ |
|
6735 |
if (__isNonNilObject(anObject)) { |
|
6736 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
|
6737 |
int spc; |
|
6738 |
||
6739 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
6740 |
RETURN (false); |
|
6741 |
} |
|
6742 |
} |
|
6743 |
} |
|
6744 |
||
6745 |
cls = __qClass(self); |
|
6746 |
if (cls == anObject) { |
|
6747 |
RETURN (true); |
|
6748 |
} |
|
6749 |
||
6750 |
flags = __ClassInstPtr(cls)->c_flags; |
|
6751 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
|
6752 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
6753 |
} else { |
|
6754 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
6755 |
} |
|
6756 |
if (! nInsts) { |
|
6757 |
RETURN (false); |
|
6758 |
} |
|
6759 |
#if defined(memsrch4) |
|
6760 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
|
6761 |
RETURN (true); |
|
6762 |
} |
|
6763 |
#else |
|
6764 |
for (i=0; i<nInsts; i++) { |
|
6765 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
|
6766 |
RETURN (true); |
|
6767 |
} |
|
6768 |
} |
|
6769 |
#endif /* memsrch4 */ |
|
6770 |
||
6771 |
%}. |
|
6772 |
||
6773 |
"/ |myClass |
|
6774 |
"/ numInst "{ Class: SmallInteger }" | |
|
6775 |
"/ |
|
6776 |
"/ myClass := self class. |
|
6777 |
"/ |
|
6778 |
"/ "check the class" |
|
6779 |
"/ (myClass == anObject) ifTrue:[^ true]. |
|
6780 |
"/ |
|
6781 |
"/ "check the instance variables" |
|
6782 |
"/ numInst := myClass instSize. |
|
6783 |
"/ 1 to:numInst do:[:i | |
|
6784 |
"/ ((self instVarAt:i) == anObject) ifTrue:[^ true] |
|
6785 |
"/ ]. |
|
6786 |
"/ |
|
6787 |
"/ "check the indexed variables" |
|
6788 |
"/ myClass isVariable ifTrue:[ |
|
6789 |
"/ myClass isPointers ifFalse:[ |
|
6790 |
"/ "/ |
|
6791 |
"/ "/ we could argue about the following unconditional return: |
|
6792 |
"/ "/ it says that a non pointer array never has a reference to the |
|
6793 |
"/ "/ corresponding object - not mimicing a reference to a copy of the |
|
6794 |
"/ "/ integer. However, it avoids useless searches in huge byteArray |
|
6795 |
"/ "/ like objects when searching for owners. If in doubt, remove it. |
|
6796 |
"/ "/ A consequence of the return below is that #[1 2 3] will say that it |
|
6797 |
"/ "/ does not refer to the number 2 (think of keeping a copy instead) |
|
6798 |
"/ |
|
6799 |
"/ ^ false. |
|
6800 |
"/ |
|
6801 |
"/ "/ alternative: |
|
6802 |
"/ "/ anObject isNumber ifFalse:[^ false]. |
|
6803 |
"/ ]. |
|
6804 |
"/ |
|
6805 |
"/ "/ |
|
6806 |
"/ "/ because arrays are so common, and those have a highly tuned |
|
6807 |
"/ "/ idenitytIndex method, use it |
|
6808 |
"/ "/ |
|
6809 |
"/ myClass == Array ifTrue:[ |
|
6810 |
"/ ^ (self identityIndexOf:anObject) ~~ 0 |
|
6811 |
"/ ]. |
|
6812 |
"/ |
|
6813 |
"/ "/ |
|
6814 |
"/ "/ otherwise, do it the slow way |
|
6815 |
"/ "/ |
|
6816 |
"/ numInst := self basicSize. |
|
6817 |
"/ 1 to:numInst do:[:i | |
|
6818 |
"/ ((self basicAt:i) == anObject) ifTrue:[^ true] |
|
6819 |
"/ ] |
|
6820 |
"/ ]. |
|
6821 |
||
6822 |
^ false |
|
6823 |
||
6824 |
" |
|
6825 |
|v| |
|
6826 |
||
6827 |
v := View new initialize. |
|
6828 |
v references:Display. |
|
6829 |
" |
|
6830 |
! |
|
6831 |
||
6832 |
referencesAny:aCollection |
|
6833 |
"return true, if the receiver refers to any object from |
|
6834 |
the argument, aCollection. |
|
6835 |
- for debugging only" |
|
6836 |
||
6837 |
%{ |
|
6838 |
OBJ cls, flags; |
|
6839 |
int nInsts, inst; |
|
6840 |
||
6841 |
if (! __isNonNilObject(self)) { |
|
6842 |
RETURN (false); |
|
6843 |
} |
|
6844 |
||
6845 |
if (__isArray(aCollection)) { |
|
6846 |
int nObjs = __arraySize(aCollection); |
|
6847 |
char *minAddr = 0, *maxAddr = 0; |
|
6848 |
||
6849 |
if (nObjs == 0) { |
|
6850 |
RETURN (false); |
|
6851 |
} |
|
6852 |
||
6853 |
/* |
|
6854 |
* a little optimization: use the fact that all old objects |
|
6855 |
* refering to a new object are on the remSet; if I am not, |
|
6856 |
* a trivial reject is possible, if all objects are newbees. |
|
6857 |
* as a side effect, gather min/max addresses |
|
6858 |
*/ |
|
6859 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
|
6860 |
int allNewBees = 1; |
|
6861 |
int i; |
|
6862 |
||
6863 |
minAddr = (char *)(__ArrayInstPtr(aCollection)->a_element[0]); |
|
6864 |
maxAddr = minAddr; |
|
6865 |
||
6866 |
for (i=0; i<nObjs; i++) { |
|
6867 |
OBJ anObject; |
|
6868 |
||
6869 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
6870 |
||
6871 |
if (__isNonNilObject(anObject)) { |
|
6872 |
int spc; |
|
6873 |
||
6874 |
if (((spc = __qSpace(anObject)) != NEWSPACE) && (spc != SURVSPACE)) { |
|
6875 |
allNewBees = 0; |
|
6876 |
} |
|
6877 |
} |
|
6878 |
||
6879 |
if ((char *)anObject < minAddr) { |
|
6880 |
minAddr = (char *)anObject; |
|
6881 |
} else if ((char *)anObject > maxAddr) { |
|
6882 |
maxAddr = (char *)anObject; |
|
6883 |
} |
|
6884 |
} |
|
6885 |
if (allNewBees) { |
|
6886 |
RETURN (false); |
|
6887 |
} |
|
6888 |
} |
|
6889 |
||
6890 |
/* |
|
6891 |
* fetch min/max in searchList (if not already done) |
|
6892 |
*/ |
|
6893 |
if (minAddr == 0) { |
|
6894 |
int i; |
|
6895 |
||
6896 |
for (i=0; i<nObjs; i++) { |
|
6897 |
OBJ anObject; |
|
6898 |
||
6899 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
6900 |
if ((char *)anObject < minAddr) { |
|
6901 |
minAddr = (char *)anObject; |
|
6902 |
} else if ((char *)anObject > maxAddr) { |
|
6903 |
maxAddr = (char *)anObject; |
|
6904 |
} |
|
6905 |
} |
|
6906 |
} |
|
6907 |
||
6908 |
cls = __qClass(self); |
|
6909 |
if (((char *)cls >= minAddr) && ((char *)cls <= maxAddr)) { |
|
6910 |
#if defined(memsrch4) |
|
6911 |
if (memsrch4(__ArrayInstPtr(aCollection)->a_element, (INT)cls, nObjs)) { |
|
6912 |
RETURN (true); |
|
6913 |
} |
|
6914 |
#else |
|
6915 |
int i; |
|
6916 |
||
6917 |
for (i=0; i<nObjs; i++) { |
|
6918 |
OBJ anObject; |
|
6919 |
||
6920 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
6921 |
if (cls == anObject) { |
|
6922 |
RETURN (true); |
|
6923 |
} |
|
6924 |
} |
|
6925 |
#endif /* memsrch4 */ |
|
6926 |
} |
|
6927 |
||
6928 |
flags = __ClassInstPtr(cls)->c_flags; |
|
6929 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
|
6930 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
6931 |
} else { |
|
6932 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
6933 |
} |
|
6934 |
if (! nInsts) { |
|
6935 |
RETURN (false); |
|
6936 |
} |
|
6937 |
||
6938 |
if (nObjs == 1) { |
|
6939 |
/* better reverse the loop */ |
|
6940 |
OBJ anObject; |
|
6941 |
||
6942 |
anObject = __ArrayInstPtr(aCollection)->a_element[0]; |
|
6943 |
#if defined(memsrch4) |
|
6944 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
|
6945 |
RETURN (true); |
|
6946 |
} |
|
6947 |
#else |
|
6948 |
for (inst=0; inst<nInsts; inst++) { |
|
6949 |
if ((__InstPtr(self)->i_instvars[inst]) == anObject) { |
|
6950 |
RETURN (true); |
|
6951 |
} |
|
6952 |
} |
|
6953 |
#endif |
|
6954 |
RETURN (false); |
|
6955 |
} |
|
6956 |
||
6957 |
for (inst=0; inst<nInsts; inst++) { |
|
6958 |
OBJ instVar = __InstPtr(self)->i_instvars[inst]; |
|
6959 |
int i; |
|
6960 |
||
6961 |
if (((char *)instVar >= minAddr) && ((char *)instVar <= maxAddr)) { |
|
6962 |
#if defined(memsrch4) |
|
6963 |
if (memsrch4(__ArrayInstPtr(aCollection)->a_element, (INT)instVar, nObjs)) { |
|
6964 |
RETURN (true); |
|
6965 |
} |
|
6966 |
#else |
|
6967 |
for (i=0; i<nObjs; i++) { |
|
6968 |
OBJ anObject; |
|
6969 |
||
6970 |
anObject = __ArrayInstPtr(aCollection)->a_element[i]; |
|
6971 |
if (instVar == anObject) { |
|
6972 |
RETURN (true); |
|
6973 |
} |
|
6974 |
} |
|
6975 |
#endif /* memsrch4 */ |
|
6976 |
} |
|
6977 |
} |
|
6978 |
RETURN (false); |
|
6979 |
} |
|
6980 |
%}. |
|
6981 |
||
6982 |
aCollection do:[:el | |
|
6983 |
(self references:el) ifTrue:[^ true]. |
|
6984 |
]. |
|
6985 |
^ false |
|
6986 |
! |
|
6987 |
||
6988 |
referencesDerivedInstanceOf:aClass |
|
6989 |
"return true, if the receiver refers to an instance of |
|
6990 |
the argument, aClass or its subclass. This method exists |
|
6991 |
to support searching for users of a class." |
|
6992 |
||
6993 |
|myClass |
|
6994 |
numInst "{ Class: SmallInteger }" | |
|
6995 |
||
6996 |
myClass := self class. |
|
6997 |
||
6998 |
"check the class" |
|
6999 |
(myClass isKindOf:aClass) ifTrue:[^ true]. |
|
7000 |
||
7001 |
"check the instance variables" |
|
7002 |
numInst := myClass instSize. |
|
7003 |
1 to:numInst do:[:i | |
|
7004 |
((self instVarAt:i) isKindOf:aClass) ifTrue:[^ true] |
|
7005 |
]. |
|
7006 |
||
7007 |
"check the indexed variables" |
|
7008 |
myClass isVariable ifTrue:[ |
|
7009 |
myClass isPointers ifFalse:[ |
|
7010 |
"no need to search in non pointer fields" |
|
7011 |
((aClass == Number) or:[aClass isSubclassOf:Number]) ifFalse:[^ false]. |
|
7012 |
]. |
|
7013 |
numInst := self basicSize. |
|
7014 |
1 to:numInst do:[:i | |
|
7015 |
((self basicAt:i) isKindOf:aClass) ifTrue:[^ true] |
|
7016 |
] |
|
7017 |
]. |
|
7018 |
^ false |
|
7019 |
||
7020 |
" |
|
7021 |
(1 @ 3.4) referencesDerivedInstanceOf:Number |
|
7022 |
(1 @ 3.4) referencesDerivedInstanceOf:Array |
|
7023 |
View new initialize referencesDerivedInstanceOf:DeviceWorkstation |
|
7024 |
" |
|
7025 |
! |
|
7026 |
||
7027 |
referencesInstanceOf:aClass |
|
7028 |
"return true, if the receiver refers to an instance of |
|
7029 |
the argument, aClass.This method exists |
|
7030 |
to support searching for users of a class." |
|
7031 |
||
7032 |
|myClass |
|
7033 |
numInst "{ Class: SmallInteger }" | |
|
7034 |
||
7035 |
myClass := self class. |
|
7036 |
||
7037 |
"check the class" |
|
7038 |
(myClass isMemberOf:aClass) ifTrue:[^ true]. |
|
7039 |
||
7040 |
"check the instance variables" |
|
7041 |
numInst := myClass instSize. |
|
7042 |
1 to:numInst do:[:i | |
|
7043 |
((self instVarAt:i) isMemberOf:aClass) ifTrue:[^ true] |
|
7044 |
]. |
|
7045 |
||
7046 |
"check the indexed variables" |
|
7047 |
myClass isVariable ifTrue:[ |
|
7048 |
myClass isPointers ifFalse:[ |
|
7049 |
"no need to search in non-pointer indexed fields" |
|
7050 |
myClass isLongs ifTrue:[ |
|
7051 |
(aClass == SmallInteger or:[aClass == LargeInteger]) ifFalse:[^ false]. |
|
7052 |
] ifFalse:[ |
|
7053 |
myClass isFloatsOrDoubles ifTrue:[^ aClass == Float]. |
|
7054 |
^ aClass == SmallInteger |
|
7055 |
] |
|
7056 |
]. |
|
7057 |
numInst := self basicSize. |
|
7058 |
1 to:numInst do:[:i | |
|
7059 |
((self basicAt:i) isMemberOf:aClass) ifTrue:[^ true] |
|
7060 |
] |
|
7061 |
]. |
|
7062 |
^ false |
|
7063 |
||
7064 |
" |
|
7065 |
(1 @ 3.4) referencesInstanceOf:Float |
|
7066 |
(1 @ 3.4) referencesInstanceOf:Fraction |
|
7067 |
View new initialize referencesInstanceOf:(Display class) |
|
7068 |
" |
|
7069 |
! ! |
|
7070 |
||
7071 |
!Object methodsFor:'synchronized evaluation'! |
|
7072 |
||
7073 |
freeSynchronizationSemaphore |
|
7074 |
"free synchronizationSemaphore. May be used, to save memory when |
|
7075 |
an object is no longer used synchronized." |
|
7076 |
||
7077 |
|sema| |
|
7078 |
||
7079 |
sema := self synchronizationSemaphore. |
|
7080 |
sema notNil ifTrue:[ |
|
7081 |
sema wait. "/ get lock |
|
7082 |
self synchronizationSemaphore:nil. |
|
7083 |
]. |
|
7084 |
||
7085 |
" |
|
7086 |
self synchronized:[]. |
|
7087 |
self synchronizationSemaphore. |
|
7088 |
self freeSynchronizationSemaphore. |
|
7089 |
" |
|
7090 |
||
7091 |
"Created: 28.1.1997 / 19:31:20 / stefan" |
|
7092 |
"Modified: 28.1.1997 / 19:47:55 / stefan" |
|
7093 |
! |
|
7094 |
||
7095 |
synchronizationSemaphore |
|
7096 |
"return the synchronization semaphore for myself. |
|
7097 |
subclasses may redefine" |
|
7098 |
||
7099 |
^ SynchronizationSemaphores at:self ifAbsent:[]. |
|
7100 |
||
7101 |
" |
|
7102 |
self synchronizationSemaphore |
|
7103 |
" |
|
7104 |
||
7105 |
"Modified: 28.1.1997 / 19:47:09 / stefan" |
|
7106 |
! |
|
7107 |
||
7108 |
synchronizationSemaphore:aSemaphore |
|
7109 |
"set the synchronisationSemaphore for myself. |
|
7110 |
subclasses may redefine this method" |
|
7111 |
||
7112 |
aSemaphore isNil ifTrue:[ |
|
7113 |
"/ remove Semaphore |
|
7114 |
SynchronizationSemaphores removeKey:self ifAbsent:nil. |
|
7115 |
] ifFalse:[ |
|
7116 |
SynchronizationSemaphores at:self put:aSemaphore. |
|
7117 |
]. |
|
7118 |
||
7119 |
"Modified: 28.1.1997 / 19:37:48 / stefan" |
|
7120 |
! |
|
7121 |
||
7122 |
synchronized:aBlock |
|
7123 |
"evaluate aBlock synchronized, i.e. use a monitor for this object" |
|
7124 |
||
7125 |
|sema blocked gotSema| |
|
7126 |
||
7127 |
blocked := OperatingSystem blockInterrupts. |
|
7128 |
||
7129 |
"/ the following avoids creation of an additional |
|
7130 |
"/ block in the common case |
|
7131 |
||
7132 |
sema := self synchronizationSemaphore. |
|
7133 |
sema isNil ifTrue:[ |
|
7134 |
"get a locked semaphore (with count = 0)" |
|
7135 |
sema := Semaphore new. |
|
7136 |
self synchronizationSemaphore:sema. |
|
7137 |
blocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
7138 |
^ aBlock valueNowOrOnUnwindDo:[sema signal]. |
|
7139 |
]. |
|
7140 |
||
7141 |
" |
|
7142 |
Poll sema (never waits). |
|
7143 |
Assuming that this is the common operation, this saves the creation |
|
7144 |
of some blocks. |
|
7145 |
" |
|
7146 |
(sema waitWithTimeout:0) notNil ifTrue:[ |
|
7147 |
blocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
7148 |
^ aBlock valueNowOrOnUnwindDo:[sema signal]. |
|
7149 |
]. |
|
7150 |
||
7151 |
[ |
|
7152 |
gotSema := sema wait. |
|
7153 |
blocked ifFalse:[OperatingSystem unblockInterrupts]. |
|
7154 |
^ aBlock value. |
|
7155 |
] valueNowOrOnUnwindDo:[ |
|
7156 |
gotSema notNil ifTrue:[gotSema signal] |
|
7157 |
]. |
|
7158 |
||
7159 |
" |
|
7160 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'1']] fork. |
|
7161 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'2']] fork. |
|
7162 |
" |
|
7163 |
||
7164 |
"Created: 28.1.1997 / 17:52:56 / stefan" |
|
7165 |
"Modified: 30.1.1997 / 13:38:54 / cg" |
|
7166 |
"Modified: 20.2.1997 / 09:43:35 / stefan" |
|
7167 |
! ! |
|
7168 |
||
7169 |
!Object methodsFor:'system primitives'! |
|
7170 |
||
7171 |
asOop |
|
7172 |
"ST-80 compatibility: |
|
7173 |
ST-80 returns an OOP-identity based number here (I guess: its address |
|
7174 |
or index); since ST/X has no such thing, and the objects address cannot |
|
7175 |
be used (since its changing over time), we return the objects identityHash |
|
7176 |
key, which provides (at least) some identity indication. |
|
7177 |
However, notice that (in contrast to ST-80's #asOop), the identityHash |
|
7178 |
key of two non-identical objects may be the same. |
|
7179 |
You'd better not use it - especially do not misuse it." |
|
7180 |
||
7181 |
^ self identityHash |
|
7182 |
||
7183 |
"Created: 9.11.1996 / 19:09:56 / cg" |
|
7184 |
"Modified: 9.11.1996 / 19:16:04 / cg" |
|
7185 |
! |
|
7186 |
||
7187 |
become:anotherObject |
|
7188 |
"make all references to the receiver become references to anotherObject |
|
7189 |
and vice-versa. Notice the vice-versa; see #becomeSameAs: for a one-way become. |
|
7190 |
This can be a very dangerous operation - be warned. |
|
7191 |
In general, using #become: should be avoided if possible, since it may |
|
7192 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
|
7193 |
||
7194 |
This may also be an expensive (i.e. slow) operation, |
|
7195 |
since in the worst case, the whole memory has to be searched for |
|
7196 |
references to the two objects (although the primitive tries hard to |
|
7197 |
limit the search, for acceptable performance in most cases). |
|
7198 |
This method fails, if the receiver or the argument is a SmallInteger |
|
7199 |
or nil, or is a context of a living method (i.e. one that has not already |
|
7200 |
returned). |
|
7201 |
(notice that #become: is not used heavily by the system |
|
7202 |
- the Collection-classes have been rewritten to not use it.)" |
|
7203 |
%{ |
|
7204 |
if (__primBecome(self, anotherObject)) { |
|
7205 |
RETURN ( self ); |
|
7206 |
} |
|
7207 |
%}. |
|
7208 |
self primitiveFailed |
|
7209 |
! |
|
7210 |
||
7211 |
becomeNil |
|
7212 |
"make all references to the receiver become nil - effectively getting |
|
7213 |
rid of the receiver. |
|
7214 |
This can be a very dangerous operation - be warned. |
|
7215 |
||
7216 |
This may be an expensive (i.e. slow) operation. |
|
7217 |
The receiver may not be a SmallInteger or a context of a living method." |
|
7218 |
||
7219 |
%{ |
|
7220 |
if (__primBecomeNil(self)) { |
|
7221 |
RETURN ( nil ); |
|
7222 |
} |
|
7223 |
%}. |
|
7224 |
self primitiveFailed |
|
7225 |
! |
|
7226 |
||
7227 |
becomeSameAs:anotherObject |
|
7228 |
"make all references to the receiver become references to anotherObject |
|
7229 |
but NOT vice versa (as done in #become:). |
|
7230 |
This can be a very dangerous operation - be warned. |
|
7231 |
In general, using #become: should be avoided if possible, since it may |
|
7232 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
|
7233 |
||
7234 |
This may also be an expensive (i.e. slow) operation, |
|
7235 |
since in the worst case, the whole memory has to be searched for |
|
7236 |
references to the two objects (although the primitive tries hard to |
|
7237 |
limit the search, for acceptable performance in most cases). |
|
7238 |
This method fails, if the receiver or the argument is a SmallInteger |
|
7239 |
or nil, or is a context of a living method (i.e. one that has not already returned)." |
|
7240 |
%{ |
|
7241 |
if (__primBecomeSameAs(self, anotherObject)) { |
|
7242 |
RETURN ( self ); |
|
7243 |
} |
|
7244 |
%}. |
|
7245 |
self primitiveFailed |
|
7246 |
! |
|
7247 |
||
7248 |
changeClassTo:otherClass |
|
7249 |
"changes the class of the receiver to the argument, otherClass. |
|
7250 |
This is only allowed (possible), if the receivers class and the argument |
|
7251 |
have the same structure (i.e. number of named instance variables and |
|
7252 |
type of indexed instance variables). |
|
7253 |
If the structures do not match, or any of the original class or new class |
|
7254 |
is UndefinedObject or a Smallinteger, a primitive error is triggered." |
|
7255 |
||
7256 |
|myClass ok| |
|
7257 |
||
7258 |
"check for UndefinedObject/SmallInteger receiver or newClass" |
|
7259 |
%{ |
|
7260 |
{ |
|
7261 |
OBJ other = otherClass; |
|
7262 |
||
7263 |
if (__isNonNilObject(self) |
|
7264 |
&& __isNonNilObject(other) |
|
7265 |
&& (other != UndefinedObject) |
|
7266 |
&& (other != SmallInteger)) { |
|
7267 |
ok = true; |
|
7268 |
} else { |
|
7269 |
ok = false; |
|
7270 |
} |
|
7271 |
} |
|
7272 |
%}. |
|
7273 |
ok ifTrue:[ |
|
7274 |
ok := false. |
|
7275 |
myClass := self class. |
|
7276 |
myClass flags == otherClass flags ifTrue:[ |
|
7277 |
myClass instSize == otherClass instSize ifTrue:[ |
|
7278 |
"same instance layout and types: its ok to do it" |
|
7279 |
ok := true. |
|
7280 |
] ifFalse:[ |
|
7281 |
myClass isPointers ifTrue:[ |
|
7282 |
myClass isVariable ifTrue:[ |
|
7283 |
ok := true |
|
7284 |
] |
|
7285 |
] |
|
7286 |
] |
|
7287 |
] ifFalse:[ |
|
7288 |
myClass isPointers ifTrue:[ |
|
7289 |
"if newClass is a variable class, with instSize <= my instsize, |
|
7290 |
we can do it (effectively mapping additional instvars into the |
|
7291 |
variable part) - usefulness is questionable, though" |
|
7292 |
||
7293 |
otherClass isPointers ifTrue:[ |
|
7294 |
otherClass isVariable ifTrue:[ |
|
7295 |
otherClass instSize <= (myClass instSize + self basicSize) |
|
7296 |
ifTrue:[ |
|
7297 |
ok := true |
|
7298 |
] |
|
7299 |
] ifFalse:[ |
|
7300 |
otherClass instSize == (myClass instSize + self basicSize) |
|
7301 |
ifTrue:[ |
|
7302 |
ok := true |
|
7303 |
] |
|
7304 |
] |
|
7305 |
] ifFalse:[ |
|
7306 |
"it does not make sense to convert pointers to bytes ..." |
|
7307 |
] |
|
7308 |
] ifFalse:[ |
|
7309 |
"does it make sense, to convert bits ?" |
|
7310 |
"could allow byteArray->wordArray->longArray->floatArray->doubleArray here ..." |
|
7311 |
(myClass isBitsExtended and:[otherClass isBitsExtended]) ifTrue:[ |
|
7312 |
ok := true |
|
7313 |
] |
|
7314 |
] |
|
7315 |
] |
|
7316 |
]. |
|
7317 |
ok ifTrue:[ |
|
7318 |
"now, change the receivers class ..." |
|
7319 |
%{ |
|
7320 |
{ |
|
7321 |
OBJ me = self; |
|
7322 |
||
7323 |
__qClass(me) = otherClass; |
|
7324 |
__STORE(me, otherClass); |
|
7325 |
RETURN (me); |
|
7326 |
} |
|
7327 |
%}. |
|
7328 |
]. |
|
7329 |
||
7330 |
" |
|
7331 |
the receiver cannot be represented as a instance of |
|
7332 |
the desired class. |
|
7333 |
For example, you cannot change a bitInstance (byteArray etc.) |
|
7334 |
into a pointer object and vice versa. |
|
7335 |
" |
|
7336 |
self primitiveFailed |
|
7337 |
! |
|
7338 |
||
7339 |
changeClassToThatOf:anObject |
|
7340 |
"changes the class of the receiver to that of the argument, anObject. |
|
7341 |
This is only allowed (possible), if the receivers class and the arguments |
|
7342 |
class have the same structure (i.e. number of named instance variables and |
|
7343 |
type of indexed instance variables). If the structures do not match, or any |
|
7344 |
of the objects is nil or a Smallinteger, a primitive error is triggered." |
|
7345 |
||
7346 |
self changeClassTo:(anObject class) |
|
7347 |
! ! |
|
7348 |
||
7349 |
!Object methodsFor:'testing'! |
|
7350 |
||
7351 |
? defaultValue |
|
7352 |
"a syntactic shugar-piece: |
|
7353 |
if the receiver is nil, return the defaultValue; |
|
7354 |
otherwise, return the receiver. |
|
7355 |
This method is only redefined in UndefinedObject - therefore, |
|
7356 |
the recevier is retuned here. |
|
7357 |
||
7358 |
Thus, if foo and bar are simple variables or constants, |
|
7359 |
foo ? bar |
|
7360 |
is the same as: |
|
7361 |
(foo isNil ifTrue:[bar] ifFalse:[foo]) |
|
7362 |
||
7363 |
if they are message sends, the equivalent code is: |
|
7364 |
[ |
|
7365 |
|t1 t2| |
|
7366 |
||
7367 |
t1 := foo. |
|
7368 |
t2 := bar. |
|
7369 |
t1 isNil ifTrue:[t2] ifFalse:[t1] |
|
7370 |
] value |
|
7371 |
||
7372 |
Can be used to provide defaultValues to variables, |
|
7373 |
as in: |
|
7374 |
foo := arg ? #defaultValue |
|
7375 |
||
7376 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
7377 |
Notice: |
|
7378 |
This method is open coded (inlined) by the compiler(s) |
|
7379 |
- redefining it may not work as expected." |
|
7380 |
||
7381 |
^ self |
|
7382 |
||
7383 |
" |
|
7384 |
1 ? #default |
|
7385 |
nil ? #default |
|
7386 |
" |
|
7387 |
||
7388 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
7389 |
"Modified: / 19.5.1998 / 17:39:56 / cg" |
|
7390 |
! |
|
7391 |
||
7392 |
?? defaultValue |
|
7393 |
"a syntactic shugar-piece: |
|
7394 |
much like ?, but sends #value to the argument if required. |
|
7395 |
(i.e. its the same as #ifNil:) |
|
7396 |
If the receiver is nil, return the defaultValues value; |
|
7397 |
otherwise, return the receiver. |
|
7398 |
This method is only redefined in UndefinedObject - therefore, |
|
7399 |
the recevier is retuned here. |
|
7400 |
||
7401 |
Thus, if foo and bar are simple variables or constants, |
|
7402 |
foo ?? bar |
|
7403 |
is the same as: |
|
7404 |
(foo isNil ifTrue:[bar value] ifFalse:[foo]) |
|
7405 |
||
7406 |
if they are message sends, the equivalent code is: |
|
7407 |
[ |
|
7408 |
|t t2| |
|
7409 |
||
7410 |
t := foo. |
|
7411 |
t isNil ifTrue:[bar value] ifFalse:[t] |
|
7412 |
] value |
|
7413 |
||
7414 |
Can be used to provide defaultValues to variables, |
|
7415 |
as in: |
|
7416 |
foo := arg ?? [ self computeDefault ] |
|
7417 |
||
7418 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
7419 |
" |
|
7420 |
||
7421 |
^ self |
|
7422 |
||
7423 |
" |
|
7424 |
1 ?? #default |
|
7425 |
nil ?? #default |
|
7426 |
1 ?? [ self halt. 1 + 2 ] |
|
7427 |
nil ?? [ self halt. 1 + 2 ] |
|
7428 |
" |
|
7429 |
||
7430 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
7431 |
"Modified: / 19.5.1998 / 17:42:56 / cg" |
|
7432 |
! |
|
7433 |
||
7434 |
ifNil:aBlockOrValue |
|
7435 |
"return myself, or the result from evaluating the argument, if I am nil. |
|
7436 |
This is much like #?, but sends #value to the argument in case of a nil |
|
7437 |
receiver. |
|
7438 |
Notice: |
|
7439 |
This method is open coded (inlined) by the compiler(s) |
|
7440 |
- redefining it may not work as expected." |
|
7441 |
||
7442 |
^ self |
|
7443 |
! |
|
7444 |
||
7445 |
ifNil:nilBlockOrValue ifNotNil:notNilBlockOrValue |
|
7446 |
"return the value of the first arg, if I am nil, |
|
7447 |
the result from evaluating the 2nd argument, if I am not nil. |
|
7448 |
Notice: |
|
7449 |
This method is open coded (inlined) by the compiler(s) |
|
7450 |
- redefining it may not work as expected." |
|
7451 |
||
7452 |
^ notNilBlockOrValue value |
|
7453 |
||
7454 |
! |
|
7455 |
||
7456 |
ifNotNil:aBlockOrValue |
|
7457 |
"return myself if nil, or the result from evaluating the argument, |
|
7458 |
if I am not nil. |
|
7459 |
Notice: |
|
7460 |
This method is open coded (inlined) by the compiler(s) |
|
7461 |
- redefining it may not work as expected." |
|
7462 |
||
7463 |
^ aBlockOrValue value |
|
7464 |
||
7465 |
! |
|
7466 |
||
7467 |
ifNotNil:notNilBlockOrValue ifNil:nilBlockOrValue |
|
7468 |
"return the value of the 2nd arg, if I am nil, |
|
7469 |
the result from evaluating the 1st argument, if I am not nil. |
|
7470 |
Notice: |
|
7471 |
This method is open coded (inlined) by the compiler(s) |
|
7472 |
- redefining it may not work as expected." |
|
7473 |
||
7474 |
^ notNilBlockOrValue value |
|
7475 |
||
7476 |
||
7477 |
! |
|
7478 |
||
7479 |
isArray |
|
7480 |
"return true, if the receiver is some kind of array (or weakArray etc); |
|
7481 |
false is returned here - the method is only redefined in Array." |
|
7482 |
||
7483 |
^ false |
|
7484 |
! |
|
7485 |
||
7486 |
isAssociation |
|
7487 |
"return true, if the receiver is some kind of association; |
|
7488 |
false is returned here - the method is only redefined in Association." |
|
7489 |
||
7490 |
^ false |
|
7491 |
||
7492 |
"Created: 14.5.1996 / 17:03:45 / cg" |
|
7493 |
! |
|
7494 |
||
7495 |
isBehavior |
|
7496 |
"return true, if the receiver is some kind of class (i.e. behavior); |
|
7497 |
false is returned here - the method is only redefined in Behavior." |
|
7498 |
||
7499 |
^ false |
|
7500 |
! |
|
7501 |
||
7502 |
isBlock |
|
7503 |
"return true, if the receiver is some kind of block; |
|
7504 |
false returned here - the method is only redefined in Block." |
|
7505 |
||
7506 |
^ false |
|
7507 |
! |
|
7508 |
||
5824 | 7509 |
isBoolean |
7510 |
"return true, if the receiver is a boolean; |
|
7511 |
false is returned here - the method is only redefined in Boolean." |
|
7512 |
||
7513 |
^ false |
|
7514 |
! |
|
7515 |
||
5755 | 7516 |
isByteArray |
7517 |
"return true, if the receiver is some kind of bytearray; |
|
7518 |
false is returned here - the method is only redefined in ByteArray." |
|
7519 |
||
7520 |
^ false |
|
7521 |
! |
|
7522 |
||
7523 |
isCharacter |
|
7524 |
"return true, if the receiver is some kind of character; |
|
7525 |
false is returned here - the method is only redefined in Character." |
|
7526 |
||
7527 |
^ false |
|
7528 |
! |
|
7529 |
||
7530 |
isClass |
|
7531 |
"return true, if the receiver is some kind of class (real class, |
|
7532 |
not just behavior); |
|
7533 |
false is returned here - the method is only redefined in Class." |
|
7534 |
||
7535 |
^ false |
|
7536 |
! |
|
7537 |
||
7538 |
isCollection |
|
7539 |
"return true, if the receiver is some kind of collection; |
|
7540 |
false is returned here - the method is only redefined in Collection." |
|
7541 |
||
7542 |
^ false |
|
7543 |
! |
|
7544 |
||
7545 |
isColor |
|
7546 |
"return true, if the receiver is some kind of color; |
|
7547 |
false is returned here - the method is only redefined in Color." |
|
7548 |
||
7549 |
^ false |
|
7550 |
! |
|
7551 |
||
7552 |
isContext |
|
7553 |
"return true, if the receiver is some kind of context; |
|
7554 |
false returned here - the method is only redefined in Context." |
|
7555 |
||
7556 |
^ false |
|
7557 |
! |
|
7558 |
||
7559 |
isExternalStream |
|
7560 |
"return true, if the receiver is some kind of externalStream; |
|
7561 |
false is returned here - the method is only redefined in ExternalStream." |
|
7562 |
||
7563 |
^false |
|
7564 |
! |
|
7565 |
||
7566 |
isFileStream |
|
7567 |
"return true, if the receiver is some kind of fileStream; |
|
7568 |
false is returned here - the method is only redefined in FileStream." |
|
7569 |
||
7570 |
^false |
|
7571 |
! |
|
7572 |
||
7573 |
isFilename |
|
7574 |
"return true, if the receiver is some kind of filename; |
|
7575 |
false is returned here - the method is only redefined in Filename." |
|
7576 |
||
7577 |
^false |
|
7578 |
! |
|
7579 |
||
7580 |
isFixedPoint |
|
7581 |
"return true, if the receiver is some kind of fixedPoint number; |
|
7582 |
false is returned here - the method is only redefined in FixedPoint." |
|
7583 |
||
7584 |
^ false |
|
7585 |
||
7586 |
"Created: 5.11.1996 / 19:23:04 / cg" |
|
7587 |
! |
|
7588 |
||
7589 |
isFixedSize |
|
7590 |
"return true if the receiver cannot grow easily |
|
7591 |
(i.e. a grow may be expensive, since it involves a become:)" |
|
7592 |
||
7593 |
^ true |
|
7594 |
! |
|
7595 |
||
7596 |
isForm |
|
7597 |
"return true, if the receiver is some kind of form; |
|
7598 |
false is returned here - the method is only redefined in Form." |
|
7599 |
||
7600 |
^ false |
|
7601 |
! |
|
7602 |
||
7603 |
isFraction |
|
7604 |
"return true, if the receiver is some kind of fraction; |
|
7605 |
false is returned here - the method is only redefined in Fraction." |
|
7606 |
||
7607 |
^ false |
|
7608 |
! |
|
7609 |
||
7610 |
isImage |
|
7611 |
"return true, if the receiver is some kind of image; |
|
7612 |
false is returned here - the method is only redefined in Image." |
|
7613 |
||
7614 |
^ false |
|
7615 |
! |
|
7616 |
||
7617 |
isImageOrForm |
|
7618 |
"return true, if the receiver is some kind of image or form; |
|
7619 |
false is returned here - the method is only redefined in Image and Form." |
|
7620 |
||
7621 |
^ false |
|
7622 |
! |
|
7623 |
||
7624 |
isImmediate |
|
7625 |
"return true if I am an immediate object |
|
7626 |
i.e. I am represented in the pointer itself and |
|
7627 |
no real object header/storage is used me. |
|
7628 |
(currently, only SmallIntegers, some characters and nil return true)" |
|
7629 |
||
7630 |
^ self class hasImmediateInstances |
|
7631 |
||
7632 |
"Created: 3.6.1997 / 12:00:18 / cg" |
|
7633 |
! |
|
7634 |
||
7635 |
isInteger |
|
7636 |
"return true, if the receiver is some kind of integer number; |
|
7637 |
false is returned here - the method is only redefined in Integer." |
|
7638 |
||
7639 |
^ false |
|
7640 |
! |
|
7641 |
||
7642 |
isJavaClass |
|
7643 |
"return true, if this is a javaClass. |
|
7644 |
false is returned here - the method is only redefined in JavaClass." |
|
7645 |
||
7646 |
^ false |
|
7647 |
||
7648 |
"Created: / 26.3.1997 / 13:34:54 / cg" |
|
7649 |
"Modified: / 8.5.1998 / 21:25:21 / cg" |
|
7650 |
! |
|
7651 |
||
7652 |
isJavaClassRef |
|
7653 |
"return true, if this is a JavaClassRef. |
|
7654 |
false is returned here - the method is only redefined in JavaClassRef." |
|
7655 |
||
7656 |
^ false |
|
7657 |
||
7658 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
7659 |
"Created: / 24.12.1999 / 01:46:28 / cg" |
|
7660 |
! |
|
7661 |
||
7662 |
isJavaContext |
|
7663 |
"return true, if this is a javaContext. |
|
7664 |
false is returned here - the method is only redefined in JavaContext." |
|
7665 |
||
7666 |
^ false |
|
7667 |
||
7668 |
"Created: / 8.5.1998 / 21:24:27 / cg" |
|
7669 |
"Modified: / 8.5.1998 / 21:25:35 / cg" |
|
7670 |
! |
|
7671 |
||
7672 |
isJavaMethod |
|
7673 |
"return true, if this is a JavaMethod. |
|
7674 |
false is returned here - the method is only redefined in JavaMethod." |
|
7675 |
||
7676 |
^ false |
|
7677 |
||
7678 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
7679 |
"Created: / 25.9.1999 / 23:26:12 / cg" |
|
7680 |
! |
|
7681 |
||
7682 |
isJavaMethodRef |
|
7683 |
"return true, if this is a JavaMethodRef. |
|
7684 |
false is returned here - the method is only redefined in JavaMethodRef." |
|
7685 |
||
7686 |
^ false |
|
7687 |
||
7688 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
7689 |
"Created: / 23.12.1999 / 19:44:51 / cg" |
|
7690 |
! |
|
7691 |
||
7692 |
isJavaObject |
|
7693 |
"return true, if this is a javaObject. |
|
7694 |
false is returned here - the method is only redefined in JavaObject." |
|
7695 |
||
7696 |
^ false |
|
7697 |
||
7698 |
"Created: / 26.3.1997 / 13:34:48 / cg" |
|
7699 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
7700 |
! |
|
7701 |
||
7702 |
isJavaScriptClass |
|
7703 |
"return true, if this is a javaScriptClass. |
|
7704 |
false is returned here - the method is only redefined in JavaScriptClass." |
|
7705 |
||
7706 |
^ false |
|
7707 |
! |
|
7708 |
||
7709 |
isKindOf:aClass |
|
7710 |
"return true, if the receiver is an instance of aClass or one of its |
|
7711 |
subclasses, false otherwise. |
|
7712 |
Advice: |
|
7713 |
use of this to check objects for certain attributes/protocoll should |
|
7714 |
be avoided; it limits the reusability of your classes by limiting use |
|
7715 |
to instances of certain classes and fences you into a specific inheritance |
|
7716 |
hierarchy. |
|
7717 |
Use check-methods to check an object for a certain attributes/protocol |
|
7718 |
(such as #isXXXX, #respondsTo: or #isNumber). |
|
7719 |
||
7720 |
Using #isKindOf: is considered BAD STYLE. |
|
7721 |
||
7722 |
Advice2: |
|
7723 |
Be aware, that using an #isXXX method is usually much faster than |
|
7724 |
using #isKindOf:; because isKindOf: has to walk up all the superclass |
|
7725 |
hierarchy, comparing every class on the way. |
|
7726 |
Due to caching in the VM, a call to #isXXX is normally reached via |
|
7727 |
a single function call. |
|
7728 |
" |
|
7729 |
||
7730 |
%{ /* NOCONTEXT */ |
|
7731 |
register OBJ thisClass; |
|
7732 |
||
7733 |
thisClass = __Class(self); |
|
7734 |
while (thisClass != nil) { |
|
7735 |
if (thisClass == aClass) { |
|
7736 |
RETURN ( true ); |
|
7737 |
} |
|
7738 |
thisClass = __ClassInstPtr(thisClass)->c_superclass; |
|
7739 |
} |
|
7740 |
RETURN ( false ); |
|
7741 |
%} |
|
7742 |
||
7743 |
"/ |
|
7744 |
"/ the above code is equivalent to: |
|
7745 |
"/ |
|
7746 |
"/ thisClass := self class. |
|
7747 |
"/ [thisClass notNil] whileTrue:[ |
|
7748 |
"/ thisClass == aClass ifTrue:[^ true]. |
|
7749 |
"/ thisClass := thisClass superclass |
|
7750 |
"/ ]. |
|
7751 |
"/ ^ false |
|
7752 |
"/ |
|
7753 |
||
7754 |
! |
|
7755 |
||
7756 |
isLayout |
|
7757 |
"return true, if the receiver is some kind of layout; |
|
7758 |
false is returned here - the method is only redefined in Layout." |
|
7759 |
||
7760 |
^ false |
|
7761 |
! |
|
7762 |
||
7763 |
isList |
|
7764 |
"return true, if the receiver is some kind of list collection; |
|
7765 |
false is returned here - the method is only redefined in List." |
|
7766 |
||
7767 |
^ false |
|
7768 |
||
7769 |
"Created: / 11.2.2000 / 01:37:05 / cg" |
|
7770 |
! |
|
7771 |
||
7772 |
isLiteral |
|
7773 |
"return true, if the receiver can be represented as a literal constant in ST syntax; |
|
7774 |
false is returned here - the method is redefined in some classes." |
|
7775 |
||
7776 |
^ false |
|
7777 |
! |
|
7778 |
||
7779 |
isMemberOf:aClass |
|
7780 |
"return true, if the receiver is an instance of aClass, false otherwise. |
|
7781 |
Advice: |
|
7782 |
use of this to check objects for certain attributes/protocoll should |
|
7783 |
be avoided; it limits the reusability of your classes by limiting use |
|
7784 |
to instances of a certain class. |
|
7785 |
Use check-methods to check an object for a certain attributes/protocol |
|
7786 |
(such as #isXXX, #respondsTo: or #isNumber); |
|
7787 |
||
7788 |
Using #isMemberOf: is considered BAD STYLE. |
|
7789 |
Notice: |
|
7790 |
This method is open coded (inlined) by the compiler(s) |
|
7791 |
- redefining it may not work as expected." |
|
7792 |
||
7793 |
^ (self class) == aClass |
|
7794 |
! |
|
7795 |
||
7796 |
isMeta |
|
7797 |
"return true, if the receiver is some kind of metaclass; |
|
7798 |
false is returned here - the method is only redefined in Metaclass." |
|
7799 |
||
7800 |
^ false |
|
7801 |
! |
|
7802 |
||
7803 |
isMethod |
|
7804 |
"return true, if the receiver is some kind of method; |
|
7805 |
false returned here - the method is only redefined in Method." |
|
7806 |
||
7807 |
^ false |
|
7808 |
! |
|
7809 |
||
7810 |
isMorph |
|
7811 |
"return true, if the receiver is some kind of morph; |
|
7812 |
false is returned here - the method is only redefined in Morph." |
|
7813 |
||
7814 |
^ false |
|
7815 |
! |
|
7816 |
||
7817 |
isNameSpace |
|
7818 |
"return true, if this is a nameSpace. |
|
7819 |
false is returned here - the method is only redefined in Namespace." |
|
7820 |
||
7821 |
^ false |
|
7822 |
||
7823 |
"Created: / 11.10.1996 / 18:08:56 / cg" |
|
7824 |
"Modified: / 8.5.1998 / 21:26:05 / cg" |
|
7825 |
! |
|
7826 |
||
7827 |
isNamespace |
|
7828 |
"return true, if this is a nameSpace. |
|
7829 |
false is returned here - the method is only redefined in Namespace." |
|
7830 |
||
5869 | 7831 |
<resource:#obsolete> |
7832 |
||
5755 | 7833 |
self obsoleteMethodWarning:'use #isNameSpace'. |
7834 |
^ false |
|
7835 |
! |
|
7836 |
||
7837 |
isNumber |
|
7838 |
"return true, if the receiver is some kind of number; |
|
7839 |
false is returned here - the method is only redefined in Number." |
|
7840 |
||
7841 |
^ false |
|
7842 |
! |
|
7843 |
||
7844 |
isOrderedCollection |
|
7845 |
"return true, if the receiver is some kind of ordered collection (or list etc); |
|
7846 |
false is returned here - the method is only redefined in OrderedCollection." |
|
7847 |
||
7848 |
^ false |
|
7849 |
! |
|
7850 |
||
7851 |
isPoint |
|
7852 |
"return true, if the receiver is some kind of point; |
|
7853 |
false is returned here - the method is only redefined in Point." |
|
7854 |
||
7855 |
^ false |
|
7856 |
! |
|
7857 |
||
7858 |
isReal |
|
7859 |
"return true, if the receiver is some kind of real number; |
|
7860 |
false is returned here - the method is only redefined in LimitedPrecisionReal." |
|
7861 |
||
7862 |
^ false |
|
7863 |
! |
|
7864 |
||
7865 |
isRectangle |
|
7866 |
"return true, if the receiver is some kind of rectangle; |
|
7867 |
false is returned here - the method is only redefined in Rectangle." |
|
7868 |
||
7869 |
^ false |
|
7870 |
! |
|
7871 |
||
7872 |
isRemoteObject |
|
7873 |
"return true, if the receiver is some kind of remoteObject, |
|
7874 |
false if its local - the method is only redefined in RemoteObject." |
|
7875 |
||
7876 |
^ false |
|
7877 |
||
7878 |
"Created: 28.10.1996 / 15:18:45 / cg" |
|
7879 |
"Modified: 28.10.1996 / 15:20:57 / cg" |
|
7880 |
! |
|
7881 |
||
7882 |
isSequenceable |
|
7883 |
"return true, if the receiver is some kind of sequenceable collection; |
|
7884 |
false is returned here - the method is only redefined in SequenceableCollection." |
|
7885 |
||
7886 |
^ false |
|
7887 |
! |
|
7888 |
||
7889 |
isSequenceableCollection |
|
7890 |
"OBSOLETE: use isSequenceable for ST-80 compatibility. |
|
7891 |
This method is a historic leftover and will be removed soon ... |
|
7892 |
(although its name is much better than #isSequenceable - sigh)" |
|
7893 |
||
5869 | 7894 |
<resource:#obsolete> |
7895 |
||
5755 | 7896 |
self obsoleteMethodWarning:'use #isSequenceable'. |
7897 |
^ false |
|
7898 |
! |
|
7899 |
||
7900 |
isSignal |
|
7901 |
"return true, if the receiver is some kind of signal; |
|
7902 |
false returned here - the method is only redefined in Signal." |
|
7903 |
||
7904 |
^ false |
|
7905 |
! |
|
7906 |
||
7907 |
isStream |
|
7908 |
"return true, if the receiver is some kind of stream; |
|
7909 |
false is returned here - the method is only redefined in Stream." |
|
7910 |
||
7911 |
^ false |
|
7912 |
! |
|
7913 |
||
7914 |
isString |
|
7915 |
"return true, if the receiver is some kind of string; |
|
7916 |
false is returned here - the method is only redefined in CharacterArray." |
|
7917 |
||
7918 |
^ false |
|
7919 |
! |
|
7920 |
||
7921 |
isStringCollection |
|
7922 |
"return true, if the receiver is some kind of stringCollection; |
|
7923 |
false is returned here - the method is only redefined in StringCollection." |
|
7924 |
||
7925 |
^ false |
|
7926 |
! |
|
7927 |
||
7928 |
isSymbol |
|
7929 |
"return true, if the receiver is some kind of symbol; |
|
7930 |
false is returned here - the method is only redefined in Symbol." |
|
7931 |
||
7932 |
^ false |
|
7933 |
! |
|
7934 |
||
7935 |
isText |
|
7936 |
"return true, if the receiver is some kind of text object; |
|
7937 |
false is returned here - the method is only redefined in Text." |
|
7938 |
||
7939 |
^ false |
|
7940 |
||
7941 |
"Created: 12.5.1996 / 10:56:50 / cg" |
|
7942 |
! |
|
7943 |
||
7944 |
isValueModel |
|
7945 |
"return true, if the receiver is some kind of valueModel; |
|
7946 |
false is returned here - the method is only redefined in ValueModel." |
|
7947 |
||
7948 |
^ false |
|
7949 |
||
7950 |
! |
|
7951 |
||
7952 |
isVariable |
|
7953 |
"return true if the receiver has indexed instance variables, |
|
7954 |
false otherwise." |
|
7955 |
||
7956 |
^ self class isVariable |
|
7957 |
! |
|
7958 |
||
7959 |
isVariableBinding |
|
7960 |
"return true, if this is a binding for a variable. |
|
7961 |
false is returned here - the method is only redefined in Binding." |
|
7962 |
||
7963 |
^ false |
|
7964 |
||
7965 |
"Created: / 19.6.1997 / 17:38:44 / cg" |
|
7966 |
"Modified: / 8.5.1998 / 21:26:55 / cg" |
|
7967 |
! |
|
7968 |
||
7969 |
isView |
|
7970 |
"return true, if the receiver is some kind of view; |
|
7971 |
false is returned here - the method is only redefined in View." |
|
7972 |
||
7973 |
^ false |
|
7974 |
! ! |
|
7975 |
||
7976 |
!Object methodsFor:'tracing'! |
|
7977 |
||
7978 |
traceInto:aRequestor level:level from:referrer |
|
7979 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
7980 |
||
7981 |
^ aRequestor traceObject:self level:level from:referrer |
|
7982 |
||
7983 |
"Created: / 2.9.1999 / 09:05:17 / stefan" |
|
7984 |
! ! |
|
7985 |
||
7986 |
!Object methodsFor:'user interaction & notifications'! |
|
7987 |
||
7988 |
activityNotification:aString |
|
7989 |
"this can be sent from deeply nested methods, which are going to perform |
|
7990 |
some long-time activity. |
|
7991 |
If there is a handler for the ActivityNotificationSignal signal, that one is raised, |
|
7992 |
passing the argument. The handler should show this message whereever it likes, |
|
7993 |
and proceed. If there is no handler, this is simply ignored. |
|
7994 |
||
7995 |
This is very useful to pass busy messages up to some higher level (typically a view) |
|
7996 |
which likes to display that message in its label or a busy-box. |
|
7997 |
It could also be put into some logfile or printed on the standard output/error." |
|
7998 |
||
7999 |
ActivityNotificationSignal isHandled ifTrue:[ |
|
8000 |
^ ActivityNotificationSignal raiseRequestWith:self errorString:aString |
|
8001 |
]. |
|
8002 |
||
8003 |
" |
|
8004 |
nil activityNotification:'hello there' |
|
8005 |
self activityNotification:'hello there' |
|
8006 |
" |
|
8007 |
||
8008 |
" |
|
8009 |
ActivityNotificationSignal handle:[:ex | |
|
8010 |
ex errorString printNL. |
|
8011 |
ex proceed. |
|
8012 |
] do:[ |
|
8013 |
'hello' printNL. |
|
8014 |
self activityNotification:'doing some long time computation'. |
|
8015 |
'world' printNL. |
|
8016 |
] |
|
8017 |
" |
|
8018 |
||
8019 |
"Modified: 16.12.1995 / 18:23:42 / cg" |
|
8020 |
! |
|
8021 |
||
8022 |
confirm:aString |
|
8023 |
"launch a confirmer, which allows user to enter yes or no. |
|
8024 |
return true for yes, false for no. |
|
8025 |
If no GUI is present (headless applications), true is returned." |
|
8026 |
||
8027 |
" |
|
8028 |
on systems without GUI, or during startup, output a message |
|
8029 |
and return true (as if yes was answered) |
|
8030 |
Q: should we ask user by reading Stdin ? |
|
8031 |
" |
|
8032 |
Smalltalk isInitialized ifFalse:[ |
|
8033 |
'*** confirmation requested during initialization:' errorPrintCR. |
|
8034 |
aString errorPrintCR. |
|
8035 |
'*** I''ll continue, assuming <yes> ...' errorPrintCR. |
|
8036 |
^ true |
|
8037 |
]. |
|
8038 |
||
8039 |
(Dialog isNil |
|
8040 |
or:[Screen isNil |
|
8041 |
or:[Screen current isNil |
|
8042 |
or:[Screen current isOpen not]]]) ifTrue:[ |
|
8043 |
'confirm: ' infoPrint. |
|
8044 |
aString infoPrintCR. |
|
8045 |
'continue, assuming <yes>' infoPrintCR. |
|
8046 |
^ true |
|
8047 |
]. |
|
8048 |
||
8049 |
Dialog autoload. "in case its autoloaded" |
|
8050 |
^ Dialog confirm:aString |
|
8051 |
||
8052 |
" |
|
8053 |
nil confirm:'hello' |
|
8054 |
self confirm:'hello' |
|
8055 |
" |
|
8056 |
||
8057 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
8058 |
! |
|
8059 |
||
8060 |
confirm:aString orCancel:cancelBlock |
|
8061 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
8062 |
return true for yes, false for no, or the value from cancelBlock for cancel. |
|
8063 |
If no GUI is present (headless applications), cancelBlock is returned." |
|
8064 |
||
8065 |
|answer| |
|
8066 |
||
8067 |
answer := self confirmWithCancel:aString. |
|
8068 |
answer isNil ifTrue:[ |
|
8069 |
^ cancelBlock value |
|
8070 |
]. |
|
8071 |
^ answer |
|
8072 |
||
8073 |
" |
|
8074 |
self confirm:'hello' orCancel:[self halt] |
|
8075 |
" |
|
8076 |
||
8077 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
8078 |
! |
|
8079 |
||
8080 |
confirmWithCancel:aString |
|
8081 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
8082 |
return true for yes, false for no, nil for cancel. |
|
8083 |
If no GUI is present (headless applications), nil is returned." |
|
8084 |
||
8085 |
" |
|
8086 |
on systems without GUI, or during startup, output a message |
|
8087 |
and return true (as if yes was answered) |
|
8088 |
Q: should we ask user by reading Stdin ? |
|
8089 |
" |
|
8090 |
Smalltalk isInitialized ifFalse:[ |
|
8091 |
'*** confirmation requested during initialization:' errorPrintCR. |
|
8092 |
aString errorPrintCR. |
|
8093 |
'*** I''ll continue, assuming <cancel> ...' errorPrintCR. |
|
8094 |
^ nil |
|
8095 |
]. |
|
8096 |
||
8097 |
(Dialog isNil |
|
8098 |
or:[Screen isNil |
|
8099 |
or:[Screen current isNil |
|
8100 |
or:[Screen current isOpen not]]]) ifTrue:[ |
|
8101 |
'confirm: ' infoPrint. |
|
8102 |
aString infoPrintCR. |
|
8103 |
'continue, assuming <cancel>' infoPrintCR. |
|
8104 |
^ nil |
|
8105 |
]. |
|
8106 |
||
8107 |
Dialog autoload. "in case its autoloaded" |
|
8108 |
^ Dialog confirmWithCancel:aString |
|
8109 |
||
8110 |
" |
|
8111 |
nil confirmWithCancel:'hello' |
|
8112 |
self confirmWithCancel:'hello' |
|
8113 |
" |
|
8114 |
||
8115 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
8116 |
! |
|
8117 |
||
8118 |
errorNotify:aString |
|
8119 |
"launch a Notifier, showing top stack, telling user something |
|
8120 |
and give user a chance to enter debugger." |
|
8121 |
||
8122 |
^ self |
|
8123 |
errorNotify:aString |
|
8124 |
from:thisContext sender |
|
8125 |
||
8126 |
" |
|
8127 |
nil errorNotify:'hello there' |
|
8128 |
self errorNotify:'hello there' |
|
8129 |
" |
|
8130 |
||
8131 |
"Modified: 11.1.1997 / 18:39:20 / cg" |
|
8132 |
! |
|
8133 |
||
8134 |
errorNotify:aString from:aContext |
|
8135 |
"launch a Notifier, showing top stack (above aContext), |
|
8136 |
telling user something and give user a chance to enter debugger." |
|
8137 |
||
8138 |
^ self errorNotify:aString from:aContext allowDebug:true |
|
8139 |
||
8140 |
"Modified: / 17.8.1998 / 10:09:27 / cg" |
|
8141 |
! |
|
8142 |
||
8143 |
errorNotify:aString from:aContext allowDebug:allowDebug |
|
8144 |
"launch a Notifier, showing top stack (above aContext), |
|
8145 |
telling user something and optionally give the user a chance to enter debugger." |
|
8146 |
||
8147 |
|info con sender action| |
|
8148 |
||
8149 |
Smalltalk isInitialized ifFalse:[ |
|
8150 |
'errorNotification: ' print. aString printCR. |
|
8151 |
^ self |
|
8152 |
]. |
|
8153 |
(Dialog isNil |
|
8154 |
or:[Screen isNil |
|
8155 |
or:[Screen current isNil |
|
8156 |
or:[Screen current isOpen not]]]) ifTrue:[ |
|
8157 |
" |
|
8158 |
on systems without GUI, simply show |
|
8159 |
the message on the Transcript and abort. |
|
8160 |
" |
|
8161 |
Transcript showCR:aString. |
|
8162 |
AbortSignal raise. |
|
8163 |
^ self |
|
8164 |
]. |
|
8165 |
||
8166 |
Processor activeProcessIsSystemProcess ifTrue:[ |
|
8167 |
action := #debug. |
|
8168 |
sender := aContext. |
|
8169 |
Debugger isNil ifTrue:[ |
|
8170 |
'****************** Cought Error while in SystemProcess ****************' errorPrintCR. |
|
8171 |
thisContext fullPrintAll. |
|
8172 |
action := #abort. |
|
8173 |
]. |
|
8174 |
] ifFalse:[ |
|
8175 |
Dialog autoload. "in case its autoloaded" |
|
8176 |
||
8177 |
ErrorSignal handle:[:ex | |
|
8178 |
||
8179 |
"/ a recursive error - quickly enter debugger |
|
8180 |
"/ this happened, when I corrupted the Dialog class ... |
|
8181 |
||
8182 |
('Object [error]: ' , ex errorString , ' caught in errorNotification') errorPrintCR. |
|
8183 |
action := #debug. |
|
8184 |
ex return. |
|
8185 |
] do:[ |
|
8186 |
sender := aContext. |
|
8187 |
sender isNil ifTrue:[ |
|
8188 |
sender := thisContext sender. |
|
8189 |
"/ |
|
8190 |
"/ for your convenience: skip the emergencyHandler block |
|
8191 |
"/ sender isBlockContext ifTrue:[ |
|
8192 |
"/ sender := sender sender |
|
8193 |
"/ ]. |
|
8194 |
]. |
|
8195 |
||
8196 |
"/ skip intermediate (signal & exception) contexts |
|
8197 |
||
8198 |
DebugView notNil ifTrue:[ |
|
8199 |
sender := DebugView interestingContextFrom:sender |
|
8200 |
]. |
|
8201 |
||
8202 |
"/ show the first 5 contexts |
|
8203 |
||
8204 |
con := sender. |
|
8205 |
info := aString , Character cr asString , Character cr asString. |
|
8206 |
1 to:15 do:[:n | |
|
8207 |
con notNil ifTrue:[ |
|
8208 |
info := info , con printString , Character cr asString. |
|
8209 |
con := con sender |
|
8210 |
] |
|
8211 |
]. |
|
8212 |
||
8213 |
(allowDebug and:[Debugger notNil]) ifTrue:[ |
|
8214 |
action := Dialog |
|
8215 |
choose:info |
|
8216 |
label:('Exception [' , Processor activeProcess nameOrId , ']') |
|
8217 |
labels:#('proceed' 'abort' 'debug') |
|
8218 |
values:#(#proceed #abort #debug) |
|
8219 |
default:#debug. |
|
8220 |
] ifFalse:[ |
|
8221 |
action := Dialog |
|
8222 |
choose:info |
|
8223 |
label:('Exception [' , Processor activeProcess nameOrId , ']') |
|
8224 |
labels:#('proceed' 'abort') |
|
8225 |
values:#(#proceed #abort) |
|
8226 |
default:#abort. |
|
8227 |
] |
|
8228 |
]. |
|
8229 |
]. |
|
8230 |
||
8231 |
action == #debug ifTrue:[ |
|
8232 |
Debugger enter:sender withMessage:aString mayProceed:true |
|
8233 |
] ifFalse:[ |
|
8234 |
action == #abort ifTrue:[ |
|
8235 |
AbortSignal raise |
|
8236 |
] |
|
8237 |
] |
|
8238 |
||
8239 |
" |
|
8240 |
nil errorNotify:'hello there' |
|
8241 |
self errorNotify:'hello there' |
|
8242 |
" |
|
8243 |
||
8244 |
"Modified: / 8.2.1997 / 12:47:41 / cg" |
|
8245 |
"Created: / 17.8.1998 / 10:09:26 / cg" |
|
8246 |
! |
|
8247 |
||
8248 |
information:aString |
|
8249 |
"launch an InfoBox, telling user something. |
|
8250 |
These info-boxes can be suppressed by handling the |
|
8251 |
UserNotification- or InformationSignal and proceeding in the handler." |
|
8252 |
||
8253 |
InformationSignal isHandled ifTrue:[ |
|
8254 |
^ InformationSignal raiseRequestWith:self errorString:aString |
|
8255 |
]. |
|
8256 |
self notify:aString |
|
8257 |
||
8258 |
" |
|
8259 |
nil information:'hello there' |
|
8260 |
self information:'hello there' |
|
8261 |
" |
|
8262 |
||
8263 |
" |
|
8264 |
InformationSignal handle:[:ex | |
|
8265 |
'no box popped' printNL. |
|
8266 |
ex proceed. |
|
8267 |
] do:[ |
|
8268 |
'hello' printNL. |
|
8269 |
self information:'some info'. |
|
8270 |
'world' printNL. |
|
8271 |
] |
|
8272 |
" |
|
8273 |
||
8274 |
"Modified: 24.11.1995 / 22:29:49 / cg" |
|
8275 |
! |
|
8276 |
||
8277 |
notify:aString |
|
8278 |
"launch a Notifier, telling user something. |
|
8279 |
Use #information: for ignorable messages." |
|
8280 |
||
8281 |
Smalltalk isInitialized ifFalse:[ |
|
8282 |
'information: ' print. aString printCR. |
|
8283 |
^ self |
|
8284 |
]. |
|
8285 |
||
8286 |
(Smalltalk isInitialized not |
|
8287 |
or:[Dialog isNil |
|
8288 |
or:[Screen isNil |
|
8289 |
or:[Screen current isNil |
|
8290 |
or:[Screen current isOpen not]]]]) ifTrue:[ |
|
8291 |
" |
|
8292 |
on systems without GUI, simply show |
|
8293 |
the message on the Transcript and abort. |
|
8294 |
" |
|
8295 |
Transcript show:'notification: '; showCR:aString. |
|
8296 |
^ self |
|
8297 |
]. |
|
8298 |
||
8299 |
Dialog autoload. "in case its autoloaded" |
|
8300 |
Dialog information:aString |
|
8301 |
||
8302 |
" |
|
8303 |
nil notify:'hello there' |
|
8304 |
self notify:'hello there' |
|
8305 |
" |
|
8306 |
||
8307 |
"Modified: 20.5.1996 / 10:28:48 / cg" |
|
8308 |
! |
|
8309 |
||
8310 |
warn:aString |
|
8311 |
"launch a WarningBox, telling user something. |
|
8312 |
These warn-boxes can be suppressed by handling the |
|
8313 |
UserNotification- or WarningSignal and proceeding in the handler." |
|
8314 |
||
8315 |
WarningSignal isHandled ifTrue:[ |
|
8316 |
^ WarningSignal raiseRequestWith:self errorString:aString |
|
8317 |
]. |
|
8318 |
||
8319 |
(Smalltalk isInitialized not |
|
8320 |
or:[Dialog isNil |
|
8321 |
or:[Screen isNil |
|
8322 |
or:[Screen current isNil |
|
8323 |
or:[Screen current isOpen not]]]]) ifTrue:[ |
|
8324 |
" |
|
8325 |
on systems without GUI, simply show |
|
8326 |
the message on the Transcript and abort. |
|
8327 |
" |
|
8328 |
Transcript show:'warning: '; showCR:aString. |
|
8329 |
^ self |
|
8330 |
]. |
|
8331 |
||
8332 |
Dialog autoload. "in case its autoloaded" |
|
8333 |
Dialog warn:aString |
|
8334 |
||
8335 |
" |
|
8336 |
nil warn:'hello there' |
|
8337 |
self warn:'hello there' |
|
8338 |
" |
|
8339 |
||
8340 |
" |
|
8341 |
WarningSignal handle:[:ex | |
|
8342 |
ex proceed. |
|
8343 |
] do:[ |
|
8344 |
'hello' printNL. |
|
8345 |
self warn:'some info'. |
|
8346 |
'world' printNL. |
|
8347 |
] |
|
8348 |
" |
|
8349 |
||
8350 |
"Modified: 20.5.1996 / 10:28:53 / cg" |
|
8351 |
! ! |
|
8352 |
||
8353 |
!Object class methodsFor:'documentation'! |
|
1 | 8354 |
|
5754 | 8355 |
version |
5971 | 8356 |
^ '$Header: /cvs/stx/stx/libbasic/Object.st,v 1.363 2001-09-07 10:05:54 cg Exp $' |
1 | 8357 |
! ! |
5755 | 8358 |
Object initialize! |