author | Claus Gittinger <cg@exept.de> |
Thu, 13 Jul 2017 14:29:22 +0200 | |
changeset 22008 | fa021caa35e0 |
parent 21810 | b66021c7e3b1 |
child 22011 | 4feefa83e27c |
permissions | -rw-r--r-- |
5755 | 1 |
" |
2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
20535 | 3 |
All Rights Reserved |
5755 | 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 |
"{ Package: 'stx:libbasic' }" |
|
13 |
||
17261 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
5755 | 16 |
nil subclass:#Object |
21317 | 17 |
instanceVariableNames:'' |
18 |
classVariableNames:'AbortAllSignal AbortSignal ActivityNotificationSignal |
|
19 |
DebuggerHooks DeepCopyErrorSignal Dependencies |
|
20 |
ElementOutOfBoundsSignal EnabledBreakPoints ErrorRecursion |
|
21 |
ErrorSignal FinalizationLobby HaltSignal IndexNotFoundSignal |
|
22 |
InfoPrinting InformationSignal InternalErrorSignal |
|
23 |
KeyNotFoundSignal MessageNotUnderstoodSignal |
|
24 |
NonIntegerIndexSignal NonWeakDependencies NotFoundSignal |
|
25 |
OSSignalInterruptSignal ObjectAttributes |
|
26 |
ObjectAttributesAccessLock PartialErrorPrintLine |
|
27 |
PartialInfoPrintLine PrimitiveFailureSignal |
|
28 |
RecursionInterruptSignal RecursiveStoreStringSignal |
|
29 |
SubscriptOutOfBoundsSignal SynchronizationSemaphores |
|
30 |
UserInterruptSignal UserNotificationSignal WarningSignal' |
|
31 |
poolDictionaries:'' |
|
32 |
category:'Kernel-Objects' |
|
5755 | 33 |
! |
34 |
||
35 |
!Object class methodsFor:'documentation'! |
|
3023
674376809496
general listView support (#displayOn / widthOn / heightOn)
ca
parents:
3010
diff
changeset
|
36 |
|
5754 | 37 |
copyright |
5755 | 38 |
" |
39 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
20535 | 40 |
All Rights Reserved |
5755 | 41 |
|
42 |
This software is furnished under a license and may be used |
|
43 |
only in accordance with the terms of that license and with the |
|
44 |
inclusion of the above copyright notice. This software may not |
|
45 |
be provided or otherwise made available to, or used by, any |
|
46 |
other person. No title to or ownership of the software is |
|
47 |
hereby transferred. |
|
48 |
" |
|
49 |
! |
|
50 |
||
51 |
dependencies |
|
52 |
" |
|
10460 | 53 |
ST/X dependencies are slightly modified from ST-80's |
5755 | 54 |
(we think they are better ;-). |
55 |
||
56 |
One problem occuring very often in ST-80 is that some object |
|
57 |
cannot be garbage collected because some dependency is present, |
|
58 |
having the object as a dependent of some other object. |
|
59 |
In ST-80, this association remains alive (because a Dictionary |
|
60 |
is used to hold dependents) - even if no other references exist to |
|
61 |
to dependent or the dependee. |
|
62 |
||
63 |
This means, that in ST-80, a #release is mandatory in order to |
|
64 |
prevent memory leaks. |
|
65 |
We think, that this is a bad solution, since after all, exactly that |
|
66 |
kind of work should be performed by a garbage collector - you should not |
|
67 |
need to care about dependencies. |
|
10460 | 68 |
From a philosophical point of view, why should some object depend on |
5755 | 69 |
something that the programmer considers a dead object ? |
70 |
(well - worse than that: it seems that some ST-80 code even depends on |
|
71 |
that behavior) |
|
72 |
||
73 |
In order to limit the trouble, ST-80 reimplemented the way dependents |
|
74 |
are stored in the model class - this one keeps the dependents locally, |
|
75 |
so these dependents go away, once the model is reclaimed. |
|
76 |
That may make things even more confusing: with models, no #release is |
|
77 |
needed, with general objects it is mandatory. |
|
78 |
||
79 |
||
80 |
In ST/X, dependencies are implemented using a WeakDictionary; this means, |
|
81 |
that once the dependee dies, the dependency association is removed automatically, |
|
82 |
and the dependent can be reclaimed by the garbage collector, if no other |
|
83 |
references exist to the dependent. |
|
84 |
In order to (at least) provide a mechanism for the old behavior |
|
85 |
(in case your application heavily depends on the ST-80 mechanism), complementary |
|
10460 | 86 |
protocol to add nonWeak dependencies is provided |
5755 | 87 |
(see #addNonWeakDependent / #removeNonWeakDependent). |
88 |
||
89 |
||
90 |
Caveat: |
|
91 |
since interests are implemented using InterestConverter (which are simply |
|
92 |
forwarding messages), these must use the nonWeak mechanism (as done in ST-80 |
|
93 |
automatically). |
|
94 |
The reason is that there are usually no direct references to the converters, |
|
95 |
and those would be reclaimed if stored in a weakDictionary. |
|
96 |
This means, that those interests MUST be removed with #retractInterest |
|
10460 | 97 |
(which is bug-compatible to ST-80). |
5755 | 98 |
We rewrite things to provide a more convenient mechanism in the future ... |
99 |
||
100 |
||
101 |
I like to hear comments on the above - do you think its better ? |
|
102 |
" |
|
103 |
! |
|
104 |
||
105 |
documentation |
|
106 |
" |
|
10460 | 107 |
Object is the superclass of most other classes. |
5755 | 108 |
(except for nil-subclasses, which inherit nothing, |
109 |
to catch any message into their #doesNotUnderstand: method) |
|
110 |
||
111 |
Protocol which is common to every object is defined here. |
|
112 |
Also some utility stuff (like notify) and error handling is implemented here. |
|
113 |
||
114 |
Object has no instance variables (and may not get any added). One reason is, that |
|
10460 | 115 |
UndefinedObject and SmallInteger are also inheriting from Object - these two cannot |
116 |
have instance variables (due to their implementation). |
|
117 |
The other reason is that the runtime system (VM) knows about the layout of some built-in |
|
118 |
classes (think of Class, Method, Block and also Integer or Float). |
|
119 |
If you were allowed to add instance variables to Object, the VM had to be recompiled |
|
5755 | 120 |
(and also rewritten in some places). |
121 |
||
122 |
[Class variables:] |
|
123 |
||
20535 | 124 |
ErrorSignal <Signal> Signal raised for error/error: messages |
125 |
also, parent of all other signals. |
|
126 |
||
127 |
HaltSignal <Signal> Signal raised for halt/halt: messages |
|
128 |
||
129 |
MessageNotUnderstoodSignal Signals raised for various error conditions |
|
130 |
UserInterruptSignal |
|
131 |
RecursionInterruptSignal |
|
132 |
ExceptionInterruptSignal |
|
133 |
SubscriptOutOfBoundsSignal |
|
134 |
NonIntegerIndexSignal |
|
135 |
NotFoundSignal |
|
136 |
KeyNotFoundSignal |
|
137 |
ElementOutOfBoundsSignal |
|
138 |
InformationSignal |
|
139 |
WarningSignal |
|
140 |
DeepCopyErrorSignal |
|
141 |
InternalErrorSignal |
|
142 |
||
143 |
AbortSignal <Signal> Signal raised by debugger, to abort a computation |
|
144 |
BUT, the debugger will only raise it if it is handled. |
|
145 |
By handling the abortSignal, you can control where the |
|
146 |
debuggers abort-function resumes execution in case of |
|
147 |
an error. |
|
148 |
||
149 |
ErrorRecursion <Boolean> controls behavior when recursive errors occur (i.e. |
|
150 |
an error while handling an error). |
|
151 |
||
152 |
Dependencies <WeakDependencyDictionary> |
|
153 |
keeps track of object dependencies. |
|
154 |
||
155 |
InfoPrinting <Boolean> controls weather informational messages |
|
156 |
are printed. |
|
157 |
||
158 |
ActivityNotificationSignal <QuerySignal> |
|
159 |
raised on #activityNotification: |
|
160 |
||
161 |
NonWeakDependencies <Dictionary> keeps track of object dependencies. |
|
162 |
Dependents stay alive. |
|
163 |
||
164 |
SynchronizationSemaphores <WeakIdentityDictionary> |
|
165 |
Semaphores for per-object-monitor. |
|
10460 | 166 |
|
5755 | 167 |
|
168 |
[author:] |
|
20535 | 169 |
Claus Gittinger |
5755 | 170 |
|
171 |
" |
|
172 |
! ! |
|
173 |
||
174 |
!Object class methodsFor:'initialization'! |
|
175 |
||
5971 | 176 |
initSignals |
177 |
"called only once - initialize signals" |
|
178 |
||
15193 | 179 |
"/ notice: the class variables here are a leftover from times |
180 |
"/ when errors where signal-instance, not class based. |
|
181 |
"/ then, signal instances where created here and kept as class vars, |
|
182 |
"/ to be fetched from the class var or via signal-getter methods. |
|
15586 | 183 |
"/ Nowadays, we use class based exceptions, where the exception class |
15193 | 184 |
"/ is directly referenced. |
185 |
"/ the classvars here are kept for backward compatibility, but they now |
|
186 |
"/ simply alias the corresponding exception class. |
|
187 |
"/ Old code should be rewritten to access the error class. |
|
188 |
||
5971 | 189 |
ErrorSignal := Error. |
190 |
HaltSignal := HaltInterrupt. |
|
5977 | 191 |
MessageNotUnderstoodSignal := MessageNotUnderstood. |
6000 | 192 |
PrimitiveFailureSignal := PrimitiveFailure. |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
193 |
InternalErrorSignal := VMInternalError. |
5971 | 194 |
UserInterruptSignal := UserInterrupt. |
6146 | 195 |
RecursionInterruptSignal := RecursionError. |
5977 | 196 |
NotFoundSignal := NotFoundError. |
197 |
IndexNotFoundSignal := IndexNotFoundError. |
|
198 |
SubscriptOutOfBoundsSignal := SubscriptOutOfBoundsError. |
|
199 |
NonIntegerIndexSignal := NonIntegerIndexError. |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
200 |
KeyNotFoundSignal := KeyNotFoundError. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
201 |
ElementOutOfBoundsSignal := ElementBoundsError. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
202 |
UserNotificationSignal := UserNotification. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
203 |
WarningSignal := Warning. |
7035
1d049fb7ae5a
Make UserInformation a class based exception
Stefan Vogel <sv@exept.de>
parents:
7033
diff
changeset
|
204 |
InformationSignal := UserInformation. |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
205 |
ActivityNotificationSignal := ActivityNotification. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
206 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
207 |
DeepCopyErrorSignal := DeepCopyError. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
208 |
|
6203
d39d75849383
class based exceptions - abortSignal
Claus Gittinger <cg@exept.de>
parents:
6199
diff
changeset
|
209 |
AbortSignal := AbortOperationRequest. |
6877
ab4e7d42f9f8
AbortAllOperation - now class based
Claus Gittinger <cg@exept.de>
parents:
6874
diff
changeset
|
210 |
AbortAllSignal := AbortAllOperationRequest. |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
211 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
212 |
OSSignalInterruptSignal := OSSignalInterrupt. |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
213 |
RecursiveStoreStringSignal := RecursiveStoreError. |
5971 | 214 |
|
5980 | 215 |
" |
216 |
Object initSignals |
|
217 |
" |
|
5971 | 218 |
|
219 |
"Modified: / 22.1.1998 / 21:23:40 / av" |
|
220 |
"Modified: / 4.8.1999 / 08:54:06 / stefan" |
|
6203
d39d75849383
class based exceptions - abortSignal
Claus Gittinger <cg@exept.de>
parents:
6199
diff
changeset
|
221 |
"Modified: / 16.11.2001 / 16:30:08 / cg" |
5971 | 222 |
! |
223 |
||
5755 | 224 |
initialize |
225 |
"called only once - initialize signals" |
|
226 |
||
227 |
ErrorSignal isNil ifTrue:[ |
|
20535 | 228 |
self initSignals. |
229 |
ErrorRecursion := true. |
|
5971 | 230 |
]. |
231 |
||
232 |
ObjectAttributes isNil ifTrue:[ |
|
20535 | 233 |
ObjectAttributes := WeakIdentityDictionary new. |
234 |
ObjectAttributesAccessLock := RecursionLock new. |
|
5971 | 235 |
]. |
236 |
Dependencies isNil ifTrue:[ |
|
20535 | 237 |
Dependencies := WeakDependencyDictionary new. |
5971 | 238 |
]. |
239 |
NonWeakDependencies isNil ifTrue:[ |
|
20535 | 240 |
NonWeakDependencies := IdentityDictionary new. |
5971 | 241 |
]. |
242 |
SynchronizationSemaphores isNil ifTrue:[ |
|
20535 | 243 |
SynchronizationSemaphores := WeakIdentityDictionary new. |
5971 | 244 |
]. |
5755 | 245 |
FinalizationLobby isNil ifTrue:[ |
20535 | 246 |
FinalizationLobby := Registry new. |
5755 | 247 |
]. |
248 |
||
249 |
"/ initialize InfoPrinting to the VM's infoPrint setting |
|
250 |
"/ (which can be turned off via a command line argument) |
|
251 |
InfoPrinting := ObjectMemory infoPrinting. |
|
252 |
||
253 |
"Object initialize" |
|
254 |
||
255 |
"Modified: / 22.1.1998 / 21:23:40 / av" |
|
256 |
"Modified: / 3.2.1998 / 18:55:09 / cg" |
|
257 |
"Modified: / 4.8.1999 / 08:54:06 / stefan" |
|
258 |
! ! |
|
259 |
||
21389 | 260 |
|
7303 | 261 |
!Object class methodsFor:'Compatibility-ST80'! |
5755 | 262 |
|
263 |
rootError |
|
264 |
"return the signal used for error/error: - handling. |
|
265 |
Same as errorSignal for ST80 compatibility." |
|
266 |
||
7094
617eeaf2f8ba
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7081
diff
changeset
|
267 |
^ Error |
5755 | 268 |
|
269 |
"Created: / 15.1.1998 / 23:47:05 / stefan" |
|
270 |
! ! |
|
271 |
||
272 |
!Object class methodsFor:'Signal constants'! |
|
273 |
||
10460 | 274 |
abortAllSignal |
5755 | 275 |
"return the signal used to abort user actions (much like AbortSignal). |
276 |
This signal is supposed to abort multiple operation actions, and get out of |
|
277 |
the loop (such as when confirming multiple class deletions etc.)" |
|
278 |
||
15903
7de2ea21e054
AbortSignal -> AbortOperationRequest
Stefan Vogel <sv@exept.de>
parents:
15891
diff
changeset
|
279 |
^ AbortAllOperationRequest |
5755 | 280 |
! |
281 |
||
10460 | 282 |
abortSignal |
5755 | 283 |
"return the signal used to abort user actions. This signal is only |
284 |
raised if caught (by the debugger), and will lead way out of the |
|
285 |
currently active doIt/printIt or inspectIt. (also some others use |
|
286 |
this for a save abort)" |
|
287 |
||
8521 | 288 |
^ AbortOperationRequest |
5755 | 289 |
! |
290 |
||
291 |
activityNotificationSignal |
|
292 |
"return the signal used for activity notifications. |
|
293 |
A handler for this signal gets all #activityNotification: sends" |
|
294 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
295 |
^ ActivityNotification |
5755 | 296 |
! |
297 |
||
13416 | 298 |
ambiguousMessageSignal |
299 |
"return the signal used for ambiguousMessage: - error handling" |
|
300 |
||
301 |
^ AmbiguousMessage |
|
302 |
||
303 |
"Created: / 21-07-2010 / 15:39:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
304 |
! |
|
305 |
||
11132
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
306 |
conversionErrorSignal |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
307 |
"return the signal used for conversion error handling" |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
308 |
|
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
309 |
^ ConversionError |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
310 |
! |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
311 |
|
10460 | 312 |
deepCopyErrorSignal |
5755 | 313 |
"return the signal raised when a deepcopy is asked for |
314 |
an object which cannot do this (for example, BlockClosures |
|
315 |
or Contexts)." |
|
316 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
317 |
^ DeepCopyError |
5755 | 318 |
! |
319 |
||
320 |
elementOutOfBoundsSignal |
|
321 |
"return the signal used for element error reporting |
|
322 |
(this signal is used for example when a value not in 0..255 is to |
|
323 |
be put into a bytearray)" |
|
324 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
325 |
^ ElementBoundsError |
5755 | 326 |
! |
327 |
||
328 |
errorSignal |
|
329 |
"return the signal used for error/error: - handling" |
|
330 |
||
7094
617eeaf2f8ba
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
7081
diff
changeset
|
331 |
^ Error |
5755 | 332 |
! |
333 |
||
334 |
haltSignal |
|
335 |
"return the signal used for halt/halt: - handling" |
|
336 |
||
337 |
^ HaltSignal |
|
338 |
! |
|
339 |
||
340 |
indexNotFoundSignal |
|
341 |
"return the signal used for bad index error reporting. |
|
342 |
This is also the parentSignal of the nonIntegerIndex- and |
|
343 |
subscriptOutOfBoundsSignal" |
|
344 |
||
345 |
^ IndexNotFoundSignal |
|
346 |
||
347 |
"Created: / 8.11.1997 / 19:15:48 / cg" |
|
348 |
! |
|
349 |
||
10460 | 350 |
informationSignal |
351 |
"return the signal used for informations. |
|
5755 | 352 |
A handler for this signal gets all #information: sends" |
353 |
||
354 |
^ InformationSignal |
|
355 |
! |
|
356 |
||
357 |
internalErrorSignal |
|
358 |
"return the signal used to report internal (VM-) errors." |
|
359 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
360 |
^ VMInternalError |
5755 | 361 |
! |
362 |
||
10460 | 363 |
keyNotFoundSignal |
5755 | 364 |
"return the signal used for no such key error reporting" |
365 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
366 |
^ KeyNotFoundError |
5755 | 367 |
! |
368 |
||
369 |
messageNotUnderstoodSignal |
|
370 |
"return the signal used for doesNotUnderstand: - error handling" |
|
371 |
||
15193 | 372 |
^ MessageNotUnderstood |
5755 | 373 |
! |
374 |
||
10460 | 375 |
nonIntegerIndexSignal |
5755 | 376 |
"return the signal used for bad subscript error reporting" |
377 |
||
378 |
^ NonIntegerIndexSignal |
|
379 |
! |
|
380 |
||
10460 | 381 |
notFoundSignal |
5755 | 382 |
"return the signal used for no element found error reporting" |
383 |
||
384 |
^ NotFoundSignal |
|
385 |
! |
|
386 |
||
7644
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
387 |
notifySignal |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
388 |
"return the parent of all notification signals." |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
389 |
|
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
390 |
^ Notification |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
391 |
! |
211762a9a39f
added notifySignal for VW compatibility
Claus Gittinger <cg@exept.de>
parents:
7621
diff
changeset
|
392 |
|
10460 | 393 |
osSignalInterruptSignal |
5755 | 394 |
"return the signal used for OS-signal error reporting; |
395 |
This is only raised if handled - otherwise, a debugger is entered." |
|
396 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
397 |
^ OSSignalInterrupt |
5755 | 398 |
|
399 |
"Modified: / 12.6.1998 / 16:27:26 / cg" |
|
400 |
! |
|
401 |
||
402 |
primitiveFailureSignal |
|
403 |
"return the signal used for primitiveFailed - error handling" |
|
404 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
405 |
^ PrimitiveFailure |
5755 | 406 |
! |
407 |
||
408 |
privateMethodSignal |
|
409 |
"return the signal used for privateMethod - error handling" |
|
410 |
||
411 |
^ MessageNotUnderstoodSignal |
|
412 |
! |
|
413 |
||
10460 | 414 |
recursionInterruptSignal |
5755 | 415 |
"return the signal used for recursion overflow error handling" |
416 |
||
417 |
^ RecursionInterruptSignal |
|
418 |
! |
|
419 |
||
420 |
recursiveStoreStringSignal |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
421 |
"return the notification used to report storeString generation of recursive objects" |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
422 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
423 |
^ RecursiveStoreError |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
424 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
425 |
" |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
426 |
RecursiveStoreError handle:[:ex | |
20535 | 427 |
self halt |
5755 | 428 |
] do:[ |
20535 | 429 |
|a| |
430 |
||
431 |
a := Array new:1. |
|
432 |
a at:1 put:a. |
|
433 |
a storeOn:Transcript |
|
5755 | 434 |
] |
435 |
" |
|
436 |
||
437 |
" |
|
438 |
|a| |
|
439 |
||
440 |
a := Array new:1. |
|
441 |
a at:1 put:a. |
|
442 |
a storeOn:Transcript |
|
443 |
" |
|
444 |
! |
|
445 |
||
5980 | 446 |
subclassResponsibilitySignal |
447 |
"return the signal used for subclassResponsibility error reporting. |
|
6652
4cfba8cb0652
typo and undo renaming of #/#cons:
Stefan Vogel <sv@exept.de>
parents:
6647
diff
changeset
|
448 |
(this signal is used to signal incomplete subclasses - i.e. a programmers error)" |
5980 | 449 |
|
450 |
^ SubclassResponsibilityError |
|
451 |
! |
|
452 |
||
5755 | 453 |
subscriptOutOfBoundsSignal |
454 |
"return the signal used for subscript error reporting. |
|
455 |
(this signal is used for example when an array is accessed with an |
|
456 |
index less than 1 or greater than the array size)" |
|
457 |
||
458 |
^ SubscriptOutOfBoundsSignal |
|
459 |
! |
|
460 |
||
461 |
userInterruptSignal |
|
462 |
"return the signal used for ^C interrupts handling" |
|
463 |
||
464 |
^ UserInterruptSignal |
|
465 |
! |
|
466 |
||
467 |
userNotificationSignal |
|
468 |
"the parent signal used with information and warnings. |
|
469 |
Handling this allows handling of both information- and warning notifications." |
|
470 |
||
471 |
^ UserNotificationSignal |
|
472 |
! |
|
473 |
||
10460 | 474 |
warningSignal |
5755 | 475 |
"return the signal used for warnings. |
476 |
A handler for this signal gets all #warn: sends" |
|
477 |
||
478 |
^ WarningSignal |
|
479 |
! ! |
|
480 |
||
481 |
!Object class methodsFor:'info messages'! |
|
482 |
||
483 |
infoPrinting |
|
484 |
"return the flag which controls information messages." |
|
485 |
||
486 |
^ InfoPrinting |
|
487 |
! |
|
488 |
||
489 |
infoPrinting:aBoolean |
|
490 |
"{ Pragma: +optSpace }" |
|
491 |
||
492 |
"turn on/off printing of information messages. |
|
493 |
If the argument, aBoolean is false, infoPrint will not output |
|
494 |
messages. The default is true." |
|
495 |
||
496 |
InfoPrinting := aBoolean |
|
497 |
! ! |
|
498 |
||
21389 | 499 |
|
5755 | 500 |
!Object class methodsFor:'queries'! |
501 |
||
8892 | 502 |
isAbstract |
11221 | 503 |
"Return if this class is an abstract class. |
504 |
True is returned for Object here; false for subclasses. |
|
19451 | 505 |
Abstract subclasses must redefine this again." |
11221 | 506 |
|
8892 | 507 |
^ self == Object |
508 |
! |
|
509 |
||
5755 | 510 |
isBuiltInClass |
20214 | 511 |
"return true if this class is known by the run-time-system, |
5755 | 512 |
i.e. you cannot add/remove instance variables without recompiling |
513 |
the VM. |
|
514 |
Here, true is returned for myself, false for subclasses." |
|
515 |
||
516 |
^ self == Object |
|
517 |
||
518 |
"Modified: 23.4.1996 / 16:00:07 / cg" |
|
519 |
! ! |
|
520 |
||
14296 | 521 |
|
21272 | 522 |
|
21389 | 523 |
|
524 |
||
22008 | 525 |
|
14682 | 526 |
!Object methodsFor:'Compatibility-GNU'! |
527 |
||
528 |
display |
|
529 |
"print the receiver on the standard output stream (which is not the Transcript). |
|
530 |
Added for GNU-ST compatibility" |
|
531 |
||
532 |
self print |
|
533 |
! |
|
534 |
||
535 |
displayNl |
|
536 |
"print the receiver followed by a cr on the standard output stream (which is not the Transcript). |
|
537 |
Added for GNU-ST compatibility" |
|
538 |
||
539 |
self printCR |
|
540 |
! ! |
|
541 |
||
7261 | 542 |
!Object methodsFor:'Compatibility-ST80'! |
5755 | 543 |
|
544 |
isMetaclass |
|
21317 | 545 |
"same as isMeta for ST80/Squeak and VW compatibility. |
546 |
kept in the libbasic package, because it is used often" |
|
547 |
||
5755 | 548 |
^ self isMeta |
549 |
! ! |
|
550 |
||
7261 | 551 |
!Object methodsFor:'Compatibility-Squeak'! |
5755 | 552 |
|
553 |
clone |
|
554 |
^ self shallowCopy |
|
555 |
! |
|
556 |
||
6146 | 557 |
copyTwoLevel |
558 |
"one more level than a shallowCopy" |
|
559 |
||
560 |
^ self copyToLevel:2 |
|
561 |
||
562 |
" |
|
563 |
|original copy elL1 elL2 elL3 copyOfElL1| |
|
564 |
||
565 |
original := Array new:3. |
|
566 |
original at:1 put:1234. |
|
567 |
original at:2 put:'hello'. |
|
568 |
original at:3 put:(elL1 := Array new:3). |
|
569 |
||
570 |
elL1 at:1 put:1234. |
|
571 |
elL1 at:2 put:'hello'. |
|
572 |
elL1 at:3 put:(elL2 := Array new:3). |
|
573 |
||
574 |
elL2 at:1 put:1234. |
|
575 |
elL2 at:2 put:'hello'. |
|
576 |
elL2 at:3 put:(elL3 := Array new:3). |
|
577 |
||
578 |
elL3 at:1 put:1234. |
|
579 |
elL3 at:2 put:'hello'. |
|
580 |
elL3 at:3 put:(Array new:3). |
|
581 |
||
582 |
copy := original copyTwoLevel. |
|
14534 | 583 |
self assert:((original at:2) ~~ (copy at:2)). |
584 |
self assert:((original at:3) ~~ (copy at:3)). |
|
6146 | 585 |
|
586 |
copyOfElL1 := copy at:3. |
|
14534 | 587 |
self assert:((elL1 at:2) == (copyOfElL1 at:2)). |
588 |
self assert:((elL1 at:3) == (copyOfElL1 at:3)). |
|
6146 | 589 |
" |
590 |
! |
|
591 |
||
16021 | 592 |
isCompiledMethod |
593 |
"same as isMethod - for squeak compatibility" |
|
594 |
||
21317 | 595 |
"/ left in libbasic package, because it is used by refactory code |
596 |
^ false |
|
5755 | 597 |
! |
598 |
||
599 |
veryDeepCopy |
|
8383 | 600 |
^ self deepCopyUsing:(IdentityDictionary new) |
5755 | 601 |
! ! |
602 |
||
7567 | 603 |
!Object methodsFor:'Compatibility-VW'! |
604 |
||
8637 | 605 |
isCharacters |
21317 | 606 |
"true, if the receiver is a string-like thing. |
607 |
added for visual works compatibility" |
|
608 |
||
609 |
"/ kept in libbasic package, because it is used in libjava and imap-implementation |
|
8637 | 610 |
^ false |
611 |
! |
|
612 |
||
18151 | 613 |
isSignalledException |
614 |
"VW compatibility" |
|
615 |
||
616 |
^ self isException |
|
617 |
! |
|
618 |
||
7567 | 619 |
keyNotFoundError:aKey |
620 |
"VW compatibility" |
|
621 |
||
21317 | 622 |
"/ kept in libbasic package, because it is used by the refactory code |
7567 | 623 |
self errorKeyNotFound:aKey. |
624 |
! ! |
|
625 |
||
21389 | 626 |
|
5755 | 627 |
!Object methodsFor:'accessing'! |
628 |
||
13320 | 629 |
_at:index |
630 |
"experimental: |
|
631 |
this is a synthetic selector, generated by the compiler, |
|
632 |
if a construct of the form expr[idx...] is parsed. |
|
633 |
I.e. |
|
20535 | 634 |
v[n] |
13320 | 635 |
generates |
20535 | 636 |
v _at: n |
13320 | 637 |
" |
638 |
||
639 |
^ self at:index |
|
640 |
||
641 |
"Created: / 21-03-2011 / 14:07:57 / cg" |
|
642 |
! |
|
643 |
||
644 |
_at:index put:value |
|
645 |
"experimental: |
|
646 |
this is a synthetic selector, generated by the compiler, |
|
647 |
if a construct of the form expr[idx...] is parsed. |
|
648 |
I.e. |
|
20535 | 649 |
v[n] |
13320 | 650 |
generates |
20535 | 651 |
v _at: n |
13320 | 652 |
" |
653 |
||
654 |
^ self at:index put:value |
|
655 |
||
656 |
"Created: / 21-03-2011 / 14:10:12 / cg" |
|
657 |
! |
|
658 |
||
14705 | 659 |
addSlot: slotName |
660 |
"dynamically add a new slot to the receiver. |
|
661 |
The receiver must be a real object, not nil or a smallInteger" |
|
662 |
||
663 |
|classGetter myClass anonCls newObj| |
|
664 |
||
665 |
myClass := self class. |
|
666 |
classGetter := ('%__get_',slotName,'__') asSymbol. |
|
667 |
||
668 |
anonCls := self perform:classGetter ifNotUnderstood:nil. |
|
669 |
anonCls isNil ifTrue:[ |
|
20535 | 670 |
anonCls := myClass |
671 |
subclass:(myClass name,'+',slotName) asSymbol |
|
672 |
instanceVariableNames:slotName |
|
673 |
classVariableNames:'' |
|
674 |
poolDictionaries:'' category:nil |
|
675 |
inEnvironment:nil. |
|
676 |
anonCls compile:('%1 ^ %1' bindWith:slotName). |
|
677 |
anonCls compile:('%1:v %1 := v' bindWith:slotName). |
|
678 |
Class withoutUpdatingChangesDo:[ |
|
679 |
|m| |
|
680 |
m := Compiler compile:('__get_',slotName,' ^ #fooBar' bindWith:slotName) forClass:myClass install:false. |
|
681 |
m literalAt:(m literals indexOf:#fooBar) put:anonCls. |
|
682 |
myClass addSelector:classGetter withMethod:m. |
|
683 |
]. |
|
14705 | 684 |
]. |
685 |
newObj := anonCls cloneFrom:self. |
|
686 |
self become:newObj. |
|
687 |
||
688 |
" |
|
689 |
|p1 p2 p3| |
|
690 |
||
691 |
p1 := Point x:10 y:20. |
|
692 |
p2 := Point x:100 y:200. |
|
693 |
Transcript show:'p1 is '; showCR:p1. |
|
694 |
Transcript show:'p2 is '; showCR:p2. |
|
695 |
p1 addSlot:'z'. |
|
696 |
p1 z:30. |
|
697 |
Transcript show:'p1 is '; showCR:p1. |
|
698 |
Transcript show:'p2 is '; showCR:p2. |
|
699 |
ObjectMemory dumpObject:p1. |
|
700 |
ObjectMemory dumpObject:p2. |
|
701 |
||
702 |
p1 addSlot:'t'. |
|
703 |
p1 t:30. |
|
704 |
Transcript show:'p1 is '; showCR:p1. |
|
705 |
ObjectMemory dumpObject:p1. |
|
706 |
||
707 |
p3 := Point x:110 y:120. |
|
708 |
p3 addSlot:'z'. |
|
709 |
p3 addSlot:'t'. |
|
710 |
p1 inspect. |
|
711 |
p2 inspect. |
|
712 |
p3 inspect. |
|
713 |
" |
|
714 |
! |
|
715 |
||
5755 | 716 |
at:index |
717 |
"return the indexed instance variable with index, anInteger; |
|
718 |
this method can be redefined in subclasses." |
|
719 |
||
720 |
^ self basicAt:index |
|
721 |
! |
|
722 |
||
723 |
at:index put:anObject |
|
724 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
725 |
this method can be redefined in subclasses. Returns anObject (sigh)" |
|
726 |
||
727 |
^ self basicAt:index put:anObject |
|
728 |
||
729 |
"Modified: 19.4.1996 / 11:13:29 / cg" |
|
730 |
! |
|
731 |
||
732 |
basicAt:index |
|
733 |
"return the indexed instance variable with index, anInteger. |
|
734 |
Trigger an error if the receiver has no indexed instance variables. |
|
735 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
736 |
||
737 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
738 |
#ifdef __SCHTEAM__ |
18215 | 739 |
{ |
20535 | 740 |
int idx1Based = index.intValue(); // st index is 1 based |
741 |
return context._RETURN( self.basicAt( idx1Based )); |
|
18215 | 742 |
} |
743 |
/* NOTREACHED */ |
|
744 |
#else |
|
5755 | 745 |
REGISTER int nbytes, indx; |
746 |
OBJ myClass; |
|
747 |
REGISTER char *pFirst; |
|
748 |
REGISTER int n; |
|
749 |
||
750 |
/* |
|
751 |
* notice the missing test for self being a nonNilObject - |
|
752 |
* this can be done since basicAt: is defined both in UndefinedObject |
|
753 |
* and SmallInteger |
|
754 |
*/ |
|
755 |
if (__isSmallInteger(index)) { |
|
20535 | 756 |
myClass = __qClass(self); |
757 |
indx = __intVal(index) - 1; |
|
758 |
n /* nInstVars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
759 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* nInstVars */); |
|
760 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
761 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
762 |
||
763 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
764 |
case __MASKSMALLINT(POINTERARRAY): |
|
765 |
/* |
|
766 |
* pointers |
|
767 |
*/ |
|
768 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
769 |
OBJ *op; |
|
770 |
||
771 |
op = (OBJ *)pFirst + indx; |
|
772 |
RETURN ( *op ); |
|
773 |
} |
|
774 |
break; |
|
775 |
||
776 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
777 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
778 |
OBJ *op; |
|
779 |
OBJ el; |
|
780 |
||
781 |
op = (OBJ *)pFirst + indx; |
|
782 |
el = *op; |
|
783 |
el = __WEAK_READ__(self, el); |
|
784 |
RETURN ( el ); |
|
785 |
} |
|
786 |
break; |
|
787 |
||
788 |
case __MASKSMALLINT(BYTEARRAY): |
|
789 |
/* |
|
790 |
* (unsigned) bytes |
|
791 |
*/ |
|
792 |
if ((unsigned)indx < nbytes) { |
|
793 |
unsigned char *cp; |
|
794 |
||
795 |
cp = (unsigned char *)pFirst + indx; |
|
796 |
RETURN ( __mkSmallInteger( (*cp & 0xFF)) ); |
|
797 |
} |
|
798 |
break; |
|
799 |
||
800 |
case __MASKSMALLINT(FLOATARRAY): |
|
801 |
/* |
|
802 |
* native floats |
|
803 |
*/ |
|
20303
060fea1cfebe
fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents:
20253
diff
changeset
|
804 |
# ifdef __NEED_FLOATARRAY_ALIGN |
20535 | 805 |
if ((INT)pFirst & (__FLOATARRAY_ALIGN-1)) { |
806 |
int delta = __FLOATARRAY_ALIGN - ((INT)pFirst & (__FLOATARRAY_ALIGN-1)); |
|
807 |
||
808 |
pFirst += delta; |
|
809 |
nbytes -= delta; |
|
810 |
} |
|
20303
060fea1cfebe
fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents:
20253
diff
changeset
|
811 |
# endif |
20535 | 812 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
813 |
float *fp; |
|
814 |
float f; |
|
815 |
OBJ v; |
|
816 |
||
817 |
fp = (float *)pFirst + indx; |
|
818 |
f = *fp; |
|
819 |
if (f == 0.0) { |
|
820 |
v = STX__float0; |
|
821 |
} else { |
|
822 |
__qMKSFLOAT(v, f); |
|
823 |
} |
|
824 |
RETURN (v); |
|
825 |
} |
|
826 |
break; |
|
827 |
||
828 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
829 |
/* |
|
830 |
* native doubles |
|
831 |
*/ |
|
18215 | 832 |
# ifdef __NEED_DOUBLE_ALIGN |
20535 | 833 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
834 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
835 |
||
836 |
pFirst += delta; |
|
837 |
nbytes -= delta; |
|
838 |
} |
|
18215 | 839 |
# endif |
20535 | 840 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
841 |
double *dp; |
|
842 |
double d; |
|
843 |
OBJ v; |
|
844 |
||
845 |
dp = (double *)pFirst + indx; |
|
846 |
d = *dp; |
|
847 |
if (d == 0.0) { |
|
848 |
v = STX__float0; |
|
849 |
} else { |
|
850 |
__qMKFLOAT(v, d); |
|
851 |
} |
|
852 |
RETURN (v); |
|
853 |
} |
|
854 |
break; |
|
855 |
||
856 |
case __MASKSMALLINT(WORDARRAY): |
|
857 |
/* |
|
858 |
* unsigned 16bit ints |
|
859 |
*/ |
|
860 |
/* Notice: the hard coded shifts are by purpose; |
|
861 |
* it makes us independent of the short-size of the machine |
|
862 |
*/ |
|
863 |
if ((unsigned)indx < (nbytes>>1)) { |
|
864 |
unsigned short *sp; |
|
865 |
||
866 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
867 |
RETURN ( __mkSmallInteger( (*sp & 0xFFFF)) ); |
|
868 |
} |
|
869 |
break; |
|
870 |
||
871 |
case __MASKSMALLINT(SWORDARRAY): |
|
872 |
/* |
|
873 |
* signed 16bit ints |
|
874 |
*/ |
|
875 |
/* Notice: the hard coded shifts are by purpose; |
|
876 |
* it makes us independent of the short-size of the machine |
|
877 |
*/ |
|
878 |
if ((unsigned)indx < (nbytes>>1)) { |
|
879 |
short *ssp; |
|
880 |
||
881 |
ssp = (short *)(pFirst + (indx<<1)); |
|
882 |
RETURN ( __mkSmallInteger( (*ssp) )); |
|
883 |
} |
|
884 |
break; |
|
885 |
||
886 |
case __MASKSMALLINT(LONGARRAY): |
|
887 |
/* |
|
888 |
* unsigned 32bit ints |
|
889 |
*/ |
|
890 |
/* Notice: the hard coded shifts are by purpose; |
|
891 |
* it makes us independent of the int-size of the machine |
|
892 |
*/ |
|
893 |
if ((unsigned)indx < (nbytes>>2)) { |
|
894 |
unsigned int32 ul; |
|
895 |
unsigned int32 *lp; |
|
896 |
||
897 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
898 |
ul = *lp; |
|
18215 | 899 |
# if __POINTER_SIZE__ == 8 |
20535 | 900 |
{ |
901 |
unsigned INT ull = (unsigned INT)ul; |
|
902 |
RETURN ( __mkSmallInteger(ull) ); |
|
903 |
} |
|
18215 | 904 |
# else |
20535 | 905 |
if (ul <= _MAX_INT) { |
906 |
RETURN ( __mkSmallInteger(ul) ); |
|
907 |
} |
|
908 |
RETURN ( __MKULARGEINT(ul) ); |
|
18215 | 909 |
# endif |
20535 | 910 |
} |
911 |
break; |
|
912 |
||
913 |
case __MASKSMALLINT(SLONGARRAY): |
|
914 |
/* |
|
915 |
* signed 32bit ints |
|
916 |
*/ |
|
917 |
/* Notice: the hard coded shifts are by purpose; |
|
918 |
* it makes us independent of the int-size of the machine |
|
919 |
*/ |
|
920 |
if ((unsigned)indx < (nbytes>>2)) { |
|
921 |
int32 *slp; |
|
922 |
int32 l; |
|
923 |
||
924 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
925 |
l = *slp; |
|
18215 | 926 |
# if __POINTER_SIZE__ == 8 |
20535 | 927 |
{ |
928 |
INT ll = (INT)l; |
|
929 |
RETURN ( __mkSmallInteger(ll) ); |
|
930 |
} |
|
18215 | 931 |
# else |
20535 | 932 |
if (__ISVALIDINTEGER(l)) { |
933 |
RETURN ( __mkSmallInteger(l) ); |
|
934 |
} |
|
935 |
RETURN ( __MKLARGEINT(l) ); |
|
18215 | 936 |
# endif |
20535 | 937 |
} |
938 |
break; |
|
939 |
||
940 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
941 |
/* |
|
942 |
* signed 64bit longlongs |
|
943 |
*/ |
|
18215 | 944 |
# ifdef __NEED_LONGLONG_ALIGN |
20535 | 945 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
946 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
947 |
||
948 |
pFirst += delta; |
|
949 |
nbytes -= delta; |
|
950 |
} |
|
18215 | 951 |
# endif |
20535 | 952 |
/* Notice: the hard coded shifts are by purpose; |
953 |
* it makes us independent of the long/longlong-size of the machine |
|
954 |
*/ |
|
955 |
if ((unsigned)indx < (nbytes>>3)) { |
|
18215 | 956 |
# if __POINTER_SIZE__ == 8 |
20535 | 957 |
INT *slp, ll; |
958 |
||
959 |
slp = (INT *)(pFirst + (indx<<3)); |
|
960 |
ll = *slp; |
|
961 |
if (__ISVALIDINTEGER(ll)) { |
|
962 |
RETURN ( __mkSmallInteger(ll) ); |
|
963 |
} |
|
964 |
RETURN ( __MKLARGEINT(ll) ); |
|
18215 | 965 |
# else |
20535 | 966 |
__int64__ *llp; |
967 |
||
968 |
llp = (__int64__ *)(pFirst + (indx<<3)); |
|
969 |
RETURN (__MKINT64(llp)); |
|
18215 | 970 |
# endif |
20535 | 971 |
} |
972 |
break; |
|
973 |
||
974 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
975 |
/* |
|
976 |
* unsigned 64bit longlongs |
|
977 |
*/ |
|
18215 | 978 |
# ifdef __NEED_LONGLONG_ALIGN |
20535 | 979 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
980 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
981 |
||
982 |
pFirst += delta; |
|
983 |
nbytes -= delta; |
|
984 |
} |
|
18215 | 985 |
# endif |
20535 | 986 |
/* Notice: the hard coded shifts are by purpose; |
987 |
* it makes us independent of the long/longlong-size of the machine |
|
988 |
*/ |
|
989 |
if ((unsigned)indx < (nbytes>>3)) { |
|
18215 | 990 |
# if __POINTER_SIZE__ == 8 |
20535 | 991 |
unsigned INT *ulp, ul; |
992 |
||
993 |
ulp = (unsigned INT *)(pFirst + (indx<<3)); |
|
994 |
ul = *ulp; |
|
995 |
if (ul <= _MAX_INT) { |
|
996 |
RETURN ( __mkSmallInteger(ul) ); |
|
997 |
} |
|
998 |
RETURN ( __MKULARGEINT(ul) ); |
|
18215 | 999 |
# else |
20535 | 1000 |
__uint64__ *llp; |
1001 |
||
1002 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
1003 |
RETURN (__MKUINT64(llp)); |
|
18215 | 1004 |
# endif |
20535 | 1005 |
} |
1006 |
break; |
|
1007 |
} |
|
5755 | 1008 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
1009 |
#endif /* ! __SCHTEAM__ */ |
5755 | 1010 |
%}. |
7216 | 1011 |
^ self indexNotIntegerOrOutOfBounds:index |
5755 | 1012 |
! |
1013 |
||
1014 |
basicAt:index put:anObject |
|
1015 |
"store the 2nd arg, anObject as indexed instvar with index, anInteger. |
|
1016 |
Returns anObject (sigh). |
|
1017 |
Trigger an error if the receiver has no indexed instance variables. |
|
1018 |
||
1019 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
1020 |
||
1021 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
1022 |
#ifdef __SCHTEAM__ |
18215 | 1023 |
{ |
20535 | 1024 |
int idx1Based = index.intValue(); // st index is 1 based |
1025 |
||
1026 |
self.basicAt_put(idx1Based, anObject ); |
|
1027 |
return context._RETURN( anObject ); |
|
18215 | 1028 |
} |
1029 |
/* NOTREACHED */ |
|
1030 |
#else |
|
5755 | 1031 |
register int nbytes, indx; |
1032 |
OBJ myClass; |
|
1033 |
register char *pFirst; |
|
18215 | 1034 |
/* int nInstBytes, ninstvars, flags; */ |
5755 | 1035 |
REGISTER int n; |
1036 |
unsigned int u; |
|
1037 |
int val; |
|
1038 |
||
1039 |
/* notice the missing test for self being a nonNilObject - |
|
1040 |
this can be done since basicAt: is defined both in UndefinedObject |
|
1041 |
and SmallInteger */ |
|
1042 |
||
1043 |
if (__isSmallInteger(index)) { |
|
20535 | 1044 |
indx = __intVal(index) - 1; |
1045 |
myClass = __qClass(self); |
|
1046 |
n /* ninstvars */ = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1047 |
n /* nInstBytes */ = OHDR_SIZE + __OBJS2BYTES__(n /* ninstvars */); |
|
1048 |
nbytes = __qSize(self) - n /* nInstBytes */; |
|
1049 |
pFirst = (char *)(__InstPtr(self)) + n /* nInstBytes */; |
|
1050 |
||
1051 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1052 |
case __MASKSMALLINT(POINTERARRAY): |
|
1053 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
1054 |
OBJ *op; |
|
1055 |
||
1056 |
op = (OBJ *)pFirst + indx; |
|
1057 |
*op = anObject; |
|
1058 |
__STORE(self, anObject); |
|
1059 |
RETURN ( anObject ); |
|
1060 |
} |
|
1061 |
break; |
|
1062 |
||
1063 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
1064 |
if ((unsigned)indx < (__BYTES2OBJS__(nbytes))) { |
|
1065 |
OBJ *op; |
|
1066 |
||
1067 |
op = (OBJ *)pFirst + indx; |
|
1068 |
*op = anObject; |
|
1069 |
__STORE(self, anObject); |
|
1070 |
__WEAK_WRITE__(self, anObject); |
|
1071 |
RETURN ( anObject ); |
|
1072 |
} |
|
1073 |
break; |
|
1074 |
||
1075 |
case __MASKSMALLINT(BYTEARRAY): |
|
1076 |
if (__isSmallInteger(anObject)) { |
|
1077 |
val = __intVal(anObject); |
|
1078 |
if ((val & ~0xFF) == 0 /* i.e. (val >= 0) && (val <= 255) */) { |
|
1079 |
if ((unsigned)indx < nbytes) { |
|
1080 |
char *cp; |
|
1081 |
||
1082 |
cp = pFirst + indx; |
|
1083 |
*cp = val; |
|
1084 |
RETURN ( anObject ); |
|
1085 |
} |
|
1086 |
} |
|
1087 |
} |
|
1088 |
break; |
|
1089 |
||
1090 |
case __MASKSMALLINT(FLOATARRAY): |
|
20303
060fea1cfebe
fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents:
20253
diff
changeset
|
1091 |
# ifdef __NEED_FLOATARRAY_ALIGN |
20535 | 1092 |
if ((INT)pFirst & (__FLOATARRAY_ALIGN-1)) { |
1093 |
int delta = __FLOATARRAY_ALIGN - ((INT)pFirst & (__FLOATARRAY_ALIGN-1)); |
|
1094 |
||
1095 |
pFirst += delta; |
|
1096 |
nbytes -= delta; |
|
1097 |
} |
|
20303
060fea1cfebe
fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents:
20253
diff
changeset
|
1098 |
# endif |
20535 | 1099 |
if ((unsigned)indx < (nbytes / sizeof(float))) { |
1100 |
float *fp; |
|
1101 |
||
1102 |
fp = (float *)pFirst + indx; |
|
1103 |
if (anObject != nil) { |
|
1104 |
if (! __isSmallInteger(anObject)) { |
|
1105 |
if (__qIsFloatLike(anObject)) { |
|
1106 |
*fp = (float)(__floatVal(anObject)); |
|
1107 |
RETURN ( anObject ); |
|
1108 |
} |
|
1109 |
if (__qIsShortFloat(anObject)) { |
|
1110 |
*fp = __shortFloatVal(anObject); |
|
1111 |
RETURN ( anObject ); |
|
1112 |
} |
|
1113 |
} else { |
|
1114 |
*fp = (float) __intVal(anObject); |
|
1115 |
RETURN ( anObject ); |
|
1116 |
} |
|
1117 |
} |
|
1118 |
} |
|
1119 |
break; |
|
1120 |
||
1121 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
18215 | 1122 |
# ifdef __NEED_DOUBLE_ALIGN |
20535 | 1123 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1124 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1125 |
||
1126 |
pFirst += delta; |
|
1127 |
nbytes -= delta; |
|
1128 |
} |
|
18215 | 1129 |
# endif |
20535 | 1130 |
if ((unsigned)indx < (nbytes / sizeof(double))) { |
1131 |
double *dp; |
|
1132 |
||
1133 |
dp = (double *)pFirst + indx; |
|
1134 |
if (anObject != nil) { |
|
1135 |
if (! __isSmallInteger(anObject)) { |
|
1136 |
if (__qIsFloatLike(anObject)) { |
|
1137 |
*dp = __floatVal(anObject); |
|
1138 |
RETURN ( anObject ); |
|
1139 |
} |
|
1140 |
if (__qIsShortFloat(anObject)) { |
|
1141 |
*dp = (double)__shortFloatVal(anObject); |
|
1142 |
RETURN ( anObject ); |
|
1143 |
} |
|
1144 |
} else { |
|
1145 |
*dp = (double) __intVal(anObject); |
|
1146 |
RETURN ( anObject ); |
|
1147 |
} |
|
1148 |
} |
|
1149 |
} |
|
1150 |
break; |
|
1151 |
||
1152 |
case __MASKSMALLINT(WORDARRAY): |
|
1153 |
if (__isSmallInteger(anObject)) { |
|
1154 |
val = __intVal(anObject); |
|
1155 |
if ((unsigned)val <= 0xFFFF) { |
|
1156 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1157 |
unsigned short *sp; |
|
1158 |
||
1159 |
sp = (unsigned short *)(pFirst + (indx<<1)); |
|
1160 |
*sp = val; |
|
1161 |
RETURN ( anObject ); |
|
1162 |
} |
|
1163 |
} |
|
1164 |
} |
|
1165 |
break; |
|
1166 |
||
1167 |
case __MASKSMALLINT(SWORDARRAY): |
|
1168 |
if (__isSmallInteger(anObject)) { |
|
1169 |
val = __intVal(anObject); |
|
1170 |
if ((val >= -32768) && (val < 32768)) { |
|
1171 |
if ((unsigned)indx < (nbytes>>1)) { |
|
1172 |
short *ssp; |
|
1173 |
||
1174 |
ssp = (short *)(pFirst + (indx<<1)); |
|
1175 |
*ssp = val; |
|
1176 |
RETURN ( anObject ); |
|
1177 |
} |
|
1178 |
} |
|
1179 |
} |
|
1180 |
break; |
|
1181 |
||
1182 |
case __MASKSMALLINT(SLONGARRAY): |
|
1183 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1184 |
int32 *slp; |
|
1185 |
||
1186 |
slp = (int32 *)(pFirst + (indx<<2)); |
|
1187 |
if (__isSmallInteger(anObject)) { |
|
1188 |
*slp = __intVal(anObject); |
|
1189 |
RETURN ( anObject ); |
|
1190 |
} |
|
1191 |
n = __signedLongIntVal(anObject); |
|
1192 |
/* |
|
1193 |
* zero means failure for an int larger than INT-size bytes |
|
1194 |
* (would be a smallInteger) |
|
1195 |
*/ |
|
1196 |
if (n) { |
|
18215 | 1197 |
# if __POINTER_SIZE__ == 8 |
20535 | 1198 |
if ((n >= -0x80000000) && (n < 0x80000000)) |
18215 | 1199 |
# endif |
20535 | 1200 |
{ |
1201 |
*slp = n; |
|
1202 |
RETURN ( anObject ); |
|
1203 |
} |
|
1204 |
} |
|
1205 |
} |
|
1206 |
break; |
|
1207 |
||
1208 |
case __MASKSMALLINT(LONGARRAY): |
|
1209 |
if ((unsigned)indx < (nbytes>>2)) { |
|
1210 |
unsigned int32 *lp; |
|
1211 |
||
1212 |
lp = (unsigned int32 *)(pFirst + (indx<<2)); |
|
1213 |
if (anObject == __mkSmallInteger(0)) { |
|
1214 |
*lp = 0; |
|
1215 |
RETURN ( anObject ); |
|
1216 |
} |
|
1217 |
u = __longIntVal(anObject); |
|
1218 |
/* |
|
1219 |
* zero means failure for an int larger than 4 bytes |
|
1220 |
* (would be a smallInteger) |
|
1221 |
*/ |
|
1222 |
if (u) { |
|
18215 | 1223 |
# if __POINTER_SIZE__ == 8 |
20535 | 1224 |
if (u <= 0xFFFFFFFF) |
18215 | 1225 |
# endif |
20535 | 1226 |
{ |
1227 |
*lp = u; |
|
1228 |
RETURN ( anObject ); |
|
1229 |
} |
|
1230 |
} |
|
1231 |
} |
|
1232 |
break; |
|
1233 |
||
1234 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
18215 | 1235 |
# ifdef __NEED_LONGLONG_ALIGN |
20535 | 1236 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1237 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1238 |
||
1239 |
pFirst += delta; |
|
1240 |
nbytes -= delta; |
|
1241 |
} |
|
18215 | 1242 |
# endif |
20535 | 1243 |
if ((unsigned)indx < (nbytes>>3)) { |
1244 |
__int64__ ll; |
|
1245 |
__int64__ *sllp; |
|
1246 |
||
1247 |
sllp = (__int64__ *)(pFirst + (indx<<3)); |
|
14632 | 1248 |
|
18215 | 1249 |
# if __POINTER_SIZE__ == 8 |
20535 | 1250 |
if (__isSmallInteger(anObject)) { |
1251 |
*sllp = __intVal(anObject); |
|
1252 |
RETURN ( anObject ); |
|
1253 |
} |
|
1254 |
n = __signedLongIntVal(anObject); |
|
1255 |
if (n) { |
|
1256 |
*sllp = n; |
|
1257 |
RETURN ( anObject ); |
|
1258 |
} |
|
18215 | 1259 |
# else |
20535 | 1260 |
if (anObject == __mkSmallInteger(0)) { |
1261 |
ll.lo = ll.hi = 0; |
|
1262 |
*sllp = ll; |
|
1263 |
RETURN ( anObject ); |
|
1264 |
} |
|
1265 |
if (__signedLong64IntVal(anObject, &ll)) { |
|
1266 |
*sllp = ll; |
|
1267 |
RETURN ( anObject ); |
|
1268 |
} |
|
18215 | 1269 |
# endif |
20535 | 1270 |
} |
1271 |
break; |
|
1272 |
||
1273 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
18215 | 1274 |
# ifdef __NEED_LONGLONG_ALIGN |
20535 | 1275 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1276 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1277 |
||
1278 |
pFirst += delta; |
|
1279 |
nbytes -= delta; |
|
1280 |
} |
|
18215 | 1281 |
# endif |
20535 | 1282 |
if ((unsigned)indx < (nbytes>>3)) { |
1283 |
__uint64__ ll; |
|
1284 |
__uint64__ *llp; |
|
1285 |
||
1286 |
llp = (__uint64__ *)(pFirst + (indx<<3)); |
|
18215 | 1287 |
# if __POINTER_SIZE__ == 8 |
20535 | 1288 |
if (__isSmallInteger(anObject)) { |
1289 |
*llp = __intVal(anObject); |
|
1290 |
RETURN ( anObject ); |
|
1291 |
} |
|
1292 |
ll = __longIntVal(anObject); |
|
1293 |
if (ll) { |
|
1294 |
*llp = ll; |
|
1295 |
RETURN ( anObject ); |
|
1296 |
} |
|
18215 | 1297 |
# else |
20535 | 1298 |
if (anObject == __mkSmallInteger(0)) { |
1299 |
ll.lo = ll.hi = 0; |
|
1300 |
*llp = ll; |
|
1301 |
RETURN ( anObject ); |
|
1302 |
} |
|
1303 |
if (__unsignedLong64IntVal(anObject, &ll)) { |
|
1304 |
*llp = ll; |
|
1305 |
RETURN ( anObject ); |
|
1306 |
} |
|
18215 | 1307 |
# endif |
20535 | 1308 |
} |
1309 |
break; |
|
1310 |
} |
|
5755 | 1311 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
1312 |
#endif /* ! __SCHTEAM__ */ |
5755 | 1313 |
%}. |
1314 |
index isInteger ifFalse:[ |
|
20535 | 1315 |
" |
1316 |
the index should be an integer number |
|
1317 |
" |
|
1318 |
^ self indexNotInteger:index |
|
5755 | 1319 |
]. |
1320 |
(index between:1 and:self size) ifFalse:[ |
|
20535 | 1321 |
" |
1322 |
the index is less than 1 or greater than the size of the |
|
1323 |
receiver collection |
|
1324 |
" |
|
1325 |
^ self subscriptBoundsError:index |
|
5755 | 1326 |
]. |
1327 |
(self class isFloatsOrDoubles) ifTrue:[ |
|
20535 | 1328 |
anObject isNumber ifTrue:[ |
1329 |
^ self basicAt:index put:(anObject asFloat) |
|
1330 |
] |
|
5755 | 1331 |
]. |
1332 |
anObject isInteger ifFalse:[ |
|
20535 | 1333 |
" |
1334 |
the object to put into the receiver collection |
|
1335 |
should be an integer number |
|
1336 |
" |
|
1337 |
^ self elementNotInteger |
|
5755 | 1338 |
]. |
1339 |
" |
|
1340 |
the object to put into the receiver collection |
|
1341 |
is not an instance of the expected element class, |
|
1342 |
or the value is not within the elements valid range. |
|
1343 |
" |
|
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
1344 |
^ self elementBoundsError:anObject |
5755 | 1345 |
|
1346 |
"Modified: 19.4.1996 / 11:14:10 / cg" |
|
1347 |
! |
|
1348 |
||
1349 |
byteAt:index |
|
10460 | 1350 |
"return the byte at index. |
5755 | 1351 |
This is only allowed for non-pointer indexed objects |
1352 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
19451 | 1353 |
The receiver's indexed instvars are treated as an uninterpreted |
5755 | 1354 |
collection of bytes. |
1355 |
Only useful with binary storage." |
|
1356 |
||
1357 |
%{ /* NOCONTEXT */ |
|
1358 |
||
1359 |
if (__isSmallInteger(index)) { |
|
20535 | 1360 |
OBJ slf = self; |
1361 |
if (__isNonNilObject(slf)) { |
|
1362 |
OBJ cls = __qClass(slf); |
|
1363 |
INT indx = __intVal(index) - 1; |
|
1364 |
INT nIndex = __byteArraySize(slf); |
|
1365 |
unsigned char *pFirst = __byteArrayVal(slf) + __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1366 |
||
1367 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1368 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
5755 | 1369 |
#ifdef __NEED_DOUBLE_ALIGN |
20535 | 1370 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
1371 |
int delta = __DOUBLE_ALIGN - ((INT)pFirst & (__DOUBLE_ALIGN-1)); |
|
1372 |
||
1373 |
pFirst += delta; |
|
1374 |
nIndex -= delta; |
|
1375 |
} |
|
20303
060fea1cfebe
fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents:
20253
diff
changeset
|
1376 |
#endif |
20535 | 1377 |
goto common; |
1378 |
||
1379 |
case __MASKSMALLINT(FLOATARRAY): |
|
20303
060fea1cfebe
fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents:
20253
diff
changeset
|
1380 |
#ifdef __NEED_FLOATARRY_ALIGN |
20535 | 1381 |
if ((INT)pFirst & (__FLOATARRY_ALIGN-1)) { |
1382 |
int delta = __FLOATARRY_ALIGN - ((INT)pFirst & (__FLOATARRY_ALIGN-1)); |
|
1383 |
||
1384 |
pFirst += delta; |
|
1385 |
nIndex -= delta; |
|
1386 |
} |
|
5755 | 1387 |
#endif |
20535 | 1388 |
goto common; |
1389 |
||
1390 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1391 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
5755 | 1392 |
#ifdef __NEED_LONGLONG_ALIGN |
20535 | 1393 |
if ((INT)pFirst & (__LONGLONG_ALIGN-1)) { |
1394 |
int delta = __LONGLONG_ALIGN - ((INT)pFirst & (__LONGLONG_ALIGN-1)); |
|
1395 |
||
1396 |
pFirst += delta; |
|
1397 |
nIndex -= delta; |
|
1398 |
} |
|
5755 | 1399 |
#endif |
20535 | 1400 |
goto common; |
1401 |
||
1402 |
case __MASKSMALLINT(BYTEARRAY): |
|
1403 |
case __MASKSMALLINT(WORDARRAY): |
|
1404 |
case __MASKSMALLINT(LONGARRAY): |
|
1405 |
case __MASKSMALLINT(SWORDARRAY): |
|
1406 |
case __MASKSMALLINT(SLONGARRAY): |
|
1407 |
common: |
|
1408 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1409 |
RETURN ( __mkSmallInteger( (INT)(pFirst[indx])) ); |
|
1410 |
} |
|
1411 |
break; |
|
1412 |
||
1413 |
} |
|
1414 |
} |
|
5755 | 1415 |
} |
1416 |
%}. |
|
1417 |
"/ index not integer or index out of range |
|
1418 |
"/ or non-byte indexable receiver |
|
1419 |
||
1420 |
^ self primitiveFailed |
|
1421 |
||
1422 |
" |
|
1423 |
Point new byteAt:1 |
|
1424 |
(ByteArray with:1 with:2) byteAt:2 |
|
10460 | 1425 |
(WordArray with:1) byteAt:1 |
19841 | 1426 |
(WordArray with:1) byteAt:2 |
10460 | 1427 |
(FloatArray with:1.0) byteAt:2 |
1428 |
'hello' byteAt:1 |
|
5755 | 1429 |
" |
1430 |
! |
|
1431 |
||
1432 |
byteAt:index put:byteValue |
|
10460 | 1433 |
"set the byte at index. |
5755 | 1434 |
This is only allowed for non-pointer indexed objects |
1435 |
(i.e. byteArrays, wordArrays, floatArrays etc.). |
|
19451 | 1436 |
The receiver's indexed instvars are treated as an uninterpreted |
5755 | 1437 |
collection of bytes. |
1438 |
Only useful with binary storage." |
|
1439 |
||
1440 |
%{ /* NOCONTEXT */ |
|
1441 |
||
1442 |
REGISTER int indx; |
|
1443 |
int val, nIndex; |
|
1444 |
REGISTER OBJ slf; |
|
1445 |
REGISTER OBJ cls; |
|
1446 |
||
1447 |
if (__bothSmallInteger(index, byteValue)) { |
|
20535 | 1448 |
val = __intVal(byteValue); |
1449 |
if ((unsigned)(val) <= 0xFF /* i.e. (val >= 0) && (val <= 255) */) { |
|
1450 |
slf = self; |
|
1451 |
if (__isNonNilObject(slf)) { |
|
1452 |
int nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1453 |
cls = __qClass(slf); |
|
1454 |
||
1455 |
indx = __intVal(index) - 1; |
|
1456 |
switch ((INT)(__ClassInstPtr(cls)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
1457 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
20303
060fea1cfebe
fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents:
20253
diff
changeset
|
1458 |
# ifdef __NEED_DOUBLE_ALIGN |
20535 | 1459 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
20303
060fea1cfebe
fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents:
20253
diff
changeset
|
1460 |
# endif |
20535 | 1461 |
goto common; |
1462 |
||
1463 |
case __MASKSMALLINT(FLOATARRAY): |
|
20303
060fea1cfebe
fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents:
20253
diff
changeset
|
1464 |
# ifdef __NEED_FLOATARRAY_ALIGN |
20535 | 1465 |
nInstBytes = (nInstBytes-1+__FLOATARRAY_ALIGN) &~ (__FLOATARRAY_ALIGN-1); |
20303
060fea1cfebe
fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents:
20253
diff
changeset
|
1466 |
# endif |
20535 | 1467 |
goto common; |
1468 |
||
1469 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
1470 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
20303
060fea1cfebe
fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents:
20253
diff
changeset
|
1471 |
# ifdef __NEED_LONGLONG_ALIGN |
20535 | 1472 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
20303
060fea1cfebe
fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents:
20253
diff
changeset
|
1473 |
# endif |
20535 | 1474 |
goto common; |
1475 |
||
1476 |
case __MASKSMALLINT(BYTEARRAY): |
|
1477 |
case __MASKSMALLINT(WORDARRAY): |
|
1478 |
case __MASKSMALLINT(LONGARRAY): |
|
1479 |
case __MASKSMALLINT(SWORDARRAY): |
|
1480 |
case __MASKSMALLINT(SLONGARRAY): |
|
1481 |
common: |
|
1482 |
indx += nInstBytes; |
|
1483 |
nIndex = __byteArraySize(slf); |
|
1484 |
if ((unsigned)indx < (unsigned)nIndex) { |
|
1485 |
__ByteArrayInstPtr(slf)->ba_element[indx] = val; |
|
1486 |
RETURN ( byteValue ); |
|
1487 |
} |
|
1488 |
break; |
|
1489 |
} |
|
1490 |
} |
|
1491 |
} |
|
5755 | 1492 |
} |
1493 |
%}. |
|
1494 |
"/ index not integer or index out of range |
|
1495 |
"/ or non-byte indexable receiver |
|
1496 |
||
1497 |
^ self primitiveFailed |
|
1498 |
||
1499 |
" |
|
1500 |
(ByteArray with:1 with:2) byteAt:2 put:3; yourself |
|
10460 | 1501 |
'hello' copy byteAt:1 put:105; yourself |
5755 | 1502 |
" |
1503 |
! |
|
1504 |
||
1505 |
instVarAt:index |
|
1506 |
"return a non-indexed instance variable; |
|
10460 | 1507 |
peeking into an object this way is not very object oriented |
5755 | 1508 |
- use with care (needed for copy, inspector etc.)" |
1509 |
||
1510 |
%{ /* NOCONTEXT */ |
|
18254 | 1511 |
#ifdef __SCHTEAM__ |
1512 |
return context._RETURN( self.instVarAt(index.intValue()-1) ); |
|
1513 |
#else |
|
5755 | 1514 |
OBJ myClass; |
1515 |
int idx, ninstvars; |
|
1516 |
||
1517 |
if (__isSmallInteger(index)) { |
|
20535 | 1518 |
myClass = __Class(self); |
1519 |
idx = __intVal(index) - 1; |
|
1520 |
/* |
|
1521 |
* do not allow returning of non-object fields. |
|
1522 |
* if subclass did not make provisions for that, |
|
1523 |
* we won't do so here ... |
|
1524 |
*/ |
|
1525 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1526 |
if (idx == 0) { |
|
1527 |
RETURN ( nil ) |
|
1528 |
} |
|
1529 |
} |
|
1530 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1531 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1532 |
// do not trust the ninstvars slot - verify |
|
1533 |
if ((__OBJS2BYTES__(ninstvars) + OHDR_SIZE) <= __qSize(self)) { |
|
1534 |
RETURN ( __InstPtr(self)->i_instvars[idx] ); |
|
1535 |
} |
|
1536 |
console_printf("[VM] warning: bad ninsts in class\n"); |
|
1537 |
} |
|
5755 | 1538 |
} |
18254 | 1539 |
#endif /* not SCHTEAM */ |
7216 | 1540 |
%}. |
1541 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1542 |
! |
1543 |
||
1544 |
instVarAt:index put:value |
|
1545 |
"change a non-indexed instance variable; |
|
10460 | 1546 |
peeking into an object this way is not very object oriented |
5755 | 1547 |
- use with care (needed for copy, inspector etc.)" |
1548 |
||
1549 |
%{ /* NOCONTEXT */ |
|
18254 | 1550 |
#ifdef __SCHTEAM__ |
1551 |
self.instVarAt_put(index.intValue()-1, value); |
|
1552 |
return context._RETURN( value ); |
|
1553 |
#else |
|
5755 | 1554 |
OBJ myClass; |
1555 |
int idx, ninstvars; |
|
1556 |
||
1557 |
if (__isSmallInteger(index)) { |
|
20535 | 1558 |
myClass = __Class(self); |
1559 |
idx = __intVal(index) - 1; |
|
1560 |
ninstvars = __intVal(__ClassInstPtr(myClass)->c_ninstvars); |
|
1561 |
/* |
|
1562 |
* do not allow setting of non-object fields. |
|
1563 |
* if subclass did not make provisions for that, |
|
1564 |
* we won't do so here ... |
|
1565 |
*/ |
|
1566 |
if (((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(NONOBJECT_INSTS))) { |
|
1567 |
if (idx == 0) { |
|
1568 |
RETURN ( nil ) |
|
1569 |
} |
|
1570 |
} |
|
1571 |
if ((idx >= 0) && (idx < ninstvars)) { |
|
1572 |
// do not trust the ninstvars slot - verify |
|
1573 |
if ((__OBJS2BYTES__(ninstvars) + OHDR_SIZE) <= __qSize(self)) { |
|
1574 |
__InstPtr(self)->i_instvars[idx] = value; |
|
1575 |
__STORE(self, value); |
|
1576 |
RETURN ( value ); |
|
1577 |
} |
|
1578 |
console_printf("[VM] warning: bad ninsts in class\n"); |
|
1579 |
} |
|
5755 | 1580 |
} |
18254 | 1581 |
#endif /* not SCHTEAM */ |
7216 | 1582 |
%}. |
1583 |
^ self indexNotIntegerOrOutOfBounds:index |
|
5755 | 1584 |
! |
1585 |
||
10460 | 1586 |
instVarNamed:name |
5755 | 1587 |
"return a non-indexed instance variables value by name; |
10460 | 1588 |
peeking into an object this way is not very object oriented |
5755 | 1589 |
- use with care if at all (provided for inspectors and memory usage monitor). |
1590 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1591 |
parsed ad runtime)" |
|
1592 |
||
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1593 |
|idx| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1594 |
|
15449 | 1595 |
idx := self class instVarIndexFor:name. |
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1596 |
idx isNil ifTrue:[ |
20535 | 1597 |
^ self errorKeyNotFound:name. |
11335 | 1598 |
]. |
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1599 |
^ self instVarAt:idx. |
5755 | 1600 |
|
1601 |
||
1602 |
" |
|
1603 |
|p| |
|
1604 |
||
1605 |
p := Point x:10 y:20. |
|
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1606 |
p instVarNamed:'cx' |
5755 | 1607 |
" |
1608 |
||
1609 |
"Modified: 19.4.1996 / 11:12:39 / cg" |
|
1610 |
! |
|
1611 |
||
1612 |
instVarNamed:name ifAbsent:exceptionBlock |
|
1613 |
"return a non-indexed instance variables value by name, |
|
1614 |
or the value of exceptionBlock, if there is no such instance variable. |
|
10460 | 1615 |
peeking into an object this way is not very object oriented |
5755 | 1616 |
- use with care if at all (provided for inspectors and memory usage monitor). |
1617 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1618 |
parsed ad runtime)" |
|
1619 |
||
1620 |
|idx| |
|
1621 |
||
15449 | 1622 |
idx := self class instVarIndexFor:name. |
5755 | 1623 |
idx isNil ifTrue:[^ exceptionBlock value]. |
1624 |
^ self instVarAt:idx |
|
1625 |
||
1626 |
||
1627 |
" |
|
1628 |
|p| |
|
1629 |
||
1630 |
p := Point x:10 y:20. |
|
10460 | 1631 |
p instVarNamed:'x' |
5755 | 1632 |
" |
1633 |
||
1634 |
"Created: 6.7.1996 / 23:02:49 / cg" |
|
1635 |
"Modified: 6.7.1996 / 23:03:41 / cg" |
|
1636 |
! |
|
1637 |
||
1638 |
instVarNamed:name put:value |
|
1639 |
"set a non-indexed instance variable by name; |
|
10460 | 1640 |
peeking into an object this way is not very object oriented |
5755 | 1641 |
- if at all, use with care (provided for protocol completeness). |
1642 |
Notice, this access is very slow (because the classes instVar-description has to be |
|
1643 |
parsed ad runtime)" |
|
1644 |
||
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1645 |
|idx| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1646 |
|
15449 | 1647 |
idx := self class instVarIndexFor:name. |
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1648 |
idx isNil ifTrue:[ |
20535 | 1649 |
^ self errorKeyNotFound:name. |
11335 | 1650 |
]. |
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1651 |
^ self instVarAt:idx put:value. |
5755 | 1652 |
|
1653 |
" |
|
1654 |
|p| |
|
1655 |
||
1656 |
p := Point x:10 y:20. |
|
1657 |
p instVarNamed:'x' put:30. |
|
10460 | 1658 |
p |
5755 | 1659 |
" |
1660 |
||
1661 |
"Modified: 19.4.1996 / 11:12:49 / cg" |
|
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1662 |
! |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1663 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1664 |
instVarNamed:name put:anObject ifAbsent:exceptionBlock |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1665 |
"return a non-indexed instance variables value by name, |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1666 |
or the value of exceptionBlock, if there is no such instance variable. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1667 |
peeking into an object this way is not very object oriented |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1668 |
- use with care if at all (provided for inspectors and memory usage monitor). |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1669 |
Notice, this access is very slow (because the classes instVar-description has to be |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1670 |
parsed ad runtime)" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1671 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1672 |
|idx| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1673 |
|
15449 | 1674 |
idx := self class instVarIndexFor:name. |
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1675 |
idx isNil ifTrue:[^ exceptionBlock value]. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1676 |
^ self instVarAt:idx put:anObject. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1677 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1678 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1679 |
" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1680 |
|p| |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1681 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1682 |
p := Point x:10 y:20. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1683 |
p instVarNamed:'x' put:4711 ifAbsent:[self halt:'no such instvar']. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1684 |
p instVarNamed:'bla' put:4712 ifAbsent:[self halt:'no such instvar']. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1685 |
p inspect. |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1686 |
" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1687 |
|
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1688 |
"Created: 6.7.1996 / 23:02:49 / cg" |
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
1689 |
"Modified: 6.7.1996 / 23:03:41 / cg" |
16125 | 1690 |
! |
1691 |
||
1692 |
nilAllInstvars |
|
18254 | 1693 |
"overwrite all inst vars of the object with nil. |
1694 |
Used by the crypto package to clear objects with |
|
1695 |
keys when no longer in use." |
|
16230 | 1696 |
|
16125 | 1697 |
%{ /* NOCONTEXT */ |
1698 |
int flags; |
|
1699 |
||
1700 |
if (!__isNonNilObject(self)) { |
|
20535 | 1701 |
RETURN(self); |
16125 | 1702 |
} |
1703 |
/* |
|
1704 |
* bail out for special (weak) objects .. |
|
1705 |
*/ |
|
1706 |
flags = __intVal(__ClassInstPtr(__qClass(self))->c_flags); |
|
1707 |
if (((flags & ~ARRAYMASK) == 0) |
|
20535 | 1708 |
&& ((flags & ARRAYMASK) != WKPOINTERARRAY) |
16125 | 1709 |
) { |
20535 | 1710 |
bzero((void *)__InstPtr(self)->i_instvars, __qSize(self)-OHDR_SIZE); |
1711 |
RETURN(self); |
|
16125 | 1712 |
} |
1713 |
%}. |
|
1714 |
"/ fail for special objects |
|
1715 |
^ self primitiveFailed |
|
1716 |
||
1717 |
" |
|
1718 |
'abcdef' copy nilAllInstvars |
|
1719 |
100 factorial nilAllInstvars |
|
1720 |
" |
|
5755 | 1721 |
! ! |
1722 |
||
21389 | 1723 |
|
1724 |
||
5755 | 1725 |
!Object methodsFor:'attributes access'! |
1726 |
||
10460 | 1727 |
objectAttributeAt:attributeKey |
22008 | 1728 |
"return the attribute for a given key or nil if not found. |
1729 |
Such attributes behave like dynamically addable slots in languages like JavaScript. |
|
1730 |
They are much more expensive though, because they are not a ''natural'' mechanism in Smalltalk, |
|
1731 |
but instead simulated via an additional objectAttributes collection mechanism, which |
|
1732 |
defaults to using a dictionary holding per instance attributes. |
|
1733 |
So only use it for seldom needed/seldom assigned attributes, |
|
1734 |
and only if it is not easy to add an instance variable or class-private mechanism for that." |
|
5755 | 1735 |
|
1736 |
| attrs | |
|
1737 |
||
1738 |
attrs := self objectAttributes. |
|
17174 | 1739 |
attrs size ~~ 0 ifTrue:[ |
20535 | 1740 |
^ attrs at:attributeKey ifAbsent:[] |
5755 | 1741 |
]. |
1742 |
^ nil |
|
1743 |
||
22008 | 1744 |
"Created: / 22-01-1998 / 21:29:17 / av" |
1745 |
"Modified: / 03-02-1998 / 18:55:55 / cg" |
|
1746 |
"Modified (comment): / 13-07-2017 / 14:26:38 / cg" |
|
5755 | 1747 |
! |
1748 |
||
6323 | 1749 |
objectAttributeAt:attributeKey put:anObject |
22008 | 1750 |
"store the attribute anObject referenced by key into the receiver. |
1751 |
Such attributes behave like dynamically addable slots in languages like JavaScript. |
|
1752 |
They are much more expensive though, because they are not a ''natural'' mechanism in Smalltalk, |
|
1753 |
but instead simulated via an additional objectAttributes collection mechanism, which |
|
1754 |
defaults to using a dictionary holding per instance attributes. |
|
1755 |
So only use it for seldom needed/seldom assigned attributes, |
|
1756 |
and only if it is not easy to add an instance variable or class-private mechanism for that." |
|
5755 | 1757 |
|
16291 | 1758 |
"/ must do this save from being reentered, since the attributes collection |
1759 |
"/ is possibly accessed from multiple threads... |
|
1760 |
ObjectAttributesAccessLock critical:[ |
|
20535 | 1761 |
| attrs | |
1762 |
||
1763 |
attrs := self objectAttributes. |
|
1764 |
"/ only need a WeakIdentityDictionary, if there are any non-symbol keys in |
|
1765 |
"/ it. Start with a regular IDDict, and migrate to WeakIDDict if ever required. |
|
1766 |
"/ Typically, this never happens (but does in the UIPainter!!) |
|
1767 |
attrs isEmptyOrNil ifTrue:[ |
|
1768 |
attributeKey isSymbol ifTrue:[ |
|
1769 |
attrs := IdentityDictionary new. |
|
1770 |
] ifFalse:[ |
|
1771 |
attrs := WeakIdentityDictionary new. |
|
1772 |
]. |
|
1773 |
attrs at:attributeKey put:anObject. |
|
1774 |
self objectAttributes:attrs. |
|
1775 |
] ifFalse:[ |
|
1776 |
attributeKey isSymbol ifFalse:[ |
|
1777 |
attrs isWeakCollection ifFalse:[ |
|
1778 |
"first non-symbol attributeKey - convert to WeakIdentityDictionary" |
|
1779 |
attrs := WeakIdentityDictionary new declareAllFrom:attrs. |
|
1780 |
self objectAttributes:attrs. |
|
1781 |
]. |
|
1782 |
]. |
|
1783 |
attrs at:attributeKey put:anObject. |
|
1784 |
]. |
|
16291 | 1785 |
] |
5755 | 1786 |
|
1787 |
"Attaching additional attributes (slots) to an arbitrary object: |
|
1788 |
||
1789 |
|p| |
|
1790 |
||
1791 |
p := Point new. |
|
1792 |
p objectAttributeAt:#color put:#green. |
|
1793 |
||
1794 |
p objectAttributeAt:#color |
|
1795 |
" |
|
1796 |
||
22008 | 1797 |
"Created: / 22-01-1998 / 21:29:25 / av" |
1798 |
"Modified: / 03-02-1998 / 18:57:58 / cg" |
|
1799 |
"Modified (comment): / 13-07-2017 / 14:28:44 / cg" |
|
5755 | 1800 |
! |
1801 |
||
1802 |
objectAttributes |
|
1803 |
"return a Collection of attributes - nil if there is none. |
|
22008 | 1804 |
|
1805 |
The default implementation here uses a global WeakDictionary to store attributes |
|
5755 | 1806 |
This may be too slow for high frequency slot access, |
22008 | 1807 |
therefore, some classes may redefine this for better performance. |
5755 | 1808 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
1809 |
||
1810 |
^ ObjectAttributes at:self ifAbsent:[nil] |
|
1811 |
||
22008 | 1812 |
"Created: / 22-01-1998 / 21:29:30 / av" |
1813 |
"Modified: / 18-02-2000 / 11:34:16 / cg" |
|
1814 |
"Modified (comment): / 13-07-2017 / 14:28:53 / cg" |
|
5755 | 1815 |
! |
1816 |
||
1817 |
objectAttributes:aCollection |
|
1818 |
"set the collection of attributes. |
|
22008 | 1819 |
|
5755 | 1820 |
The default implementation here uses a global Dictionary to store |
1821 |
attributes which may be too slow for high frequency change&update. |
|
1822 |
Therefore, some classes may redefine this for better performance." |
|
1823 |
||
16291 | 1824 |
"/ must do this save from being reentered, since the attributes collection |
5755 | 1825 |
"/ is possibly accessed from multiple threads. |
1826 |
||
16291 | 1827 |
ObjectAttributesAccessLock critical:[ |
20535 | 1828 |
aCollection isEmptyOrNil ifTrue:[ |
1829 |
ObjectAttributes removeKey:self ifAbsent:nil |
|
1830 |
] ifFalse:[ |
|
1831 |
ObjectAttributes at:self put:aCollection |
|
1832 |
]. |
|
5755 | 1833 |
] |
1834 |
||
22008 | 1835 |
"Created: / 22-01-1998 / 21:29:35 / av" |
1836 |
"Modified: / 03-02-1998 / 18:58:10 / cg" |
|
1837 |
"Modified (comment): / 13-07-2017 / 14:28:58 / cg" |
|
5755 | 1838 |
! |
1839 |
||
6323 | 1840 |
removeObjectAttribute:attributeKey |
19846 | 1841 |
"remove an object attribute; |
1842 |
return the value previously stored there, or nil. |
|
1843 |
(make the argument, anObject be no longer an attribute of the receiver)" |
|
1844 |
||
16291 | 1845 |
"/ must do this save from being reentered, since the attributes collection |
5755 | 1846 |
"/ is possibly accessed from multiple threads. |
21646 | 1847 |
^ ObjectAttributesAccessLock critical:[ |
1848 |
|attrs oldVal| |
|
20535 | 1849 |
|
1850 |
attrs := self objectAttributes. |
|
1851 |
attrs notNil ifTrue:[ |
|
21646 | 1852 |
attrs notEmpty ifTrue:[ |
20535 | 1853 |
oldVal := attrs removeKey:attributeKey ifAbsent:nil. |
1854 |
]. |
|
21646 | 1855 |
attrs isEmpty ifTrue:[ |
20535 | 1856 |
self objectAttributes:nil |
1857 |
]. |
|
21646 | 1858 |
]. |
1859 |
oldVal |
|
1860 |
]. |
|
1861 |
||
1862 |
"Created: / 22-01-1998 / 21:29:39 / av" |
|
1863 |
"Modified: / 18-02-2000 / 11:32:19 / cg" |
|
1864 |
"Modified: / 15-03-2017 / 17:25:12 / stefan" |
|
5755 | 1865 |
! ! |
1866 |
||
13500 | 1867 |
|
21389 | 1868 |
|
1869 |
||
5755 | 1870 |
!Object methodsFor:'change & update'! |
1871 |
||
1872 |
broadcast:aSelectorSymbol |
|
1873 |
"send a message with selector aSelectorSymbol to all my dependents" |
|
1874 |
||
10460 | 1875 |
self dependentsDo:[:dependent | |
20535 | 1876 |
dependent perform:aSelectorSymbol |
5755 | 1877 |
] |
1878 |
! |
|
1879 |
||
1880 |
broadcast:aSelectorSymbol with:anArgument |
|
1881 |
"send a message with selector aSelectorSymbol with an additional |
|
1882 |
argument anArgument to all my dependents." |
|
1883 |
||
10460 | 1884 |
self dependentsDo:[:dependent | |
20535 | 1885 |
dependent perform:aSelectorSymbol with:anArgument |
5755 | 1886 |
] |
1887 |
! |
|
1888 |
||
1889 |
changeRequest |
|
1890 |
"the receiver wants to change - check if all dependents |
|
1891 |
grant the request, and return true if so" |
|
1892 |
||
10460 | 1893 |
self dependentsDo:[:dependent | |
20535 | 1894 |
dependent updateRequest ifFalse:[^ false]. |
5755 | 1895 |
]. |
1896 |
^ true |
|
1897 |
! |
|
1898 |
||
11551 | 1899 |
changeRequest:aSymbol |
5755 | 1900 |
"the receiver wants to change - check if all dependents |
1901 |
grant the request, and return true if so" |
|
1902 |
||
10460 | 1903 |
self dependentsDo:[:dependent | |
20535 | 1904 |
(dependent updateRequest:aSymbol) ifFalse:[^ false]. |
5755 | 1905 |
]. |
1906 |
^ true |
|
1907 |
! |
|
1908 |
||
11551 | 1909 |
changeRequest:aSymbol from:anObject |
1910 |
"the receiver wants to change - check if all dependents |
|
1911 |
except anObject grant the request, and return true if so. |
|
1912 |
The argument anObject is typically going to be the one who is |
|
1913 |
about to send the change request." |
|
1914 |
||
1915 |
^ self changeRequest:aSymbol with:nil from:anObject |
|
1916 |
! |
|
1917 |
||
1918 |
changeRequest:aSymbol with:aParameter |
|
1919 |
"the receiver wants to change - check if all dependents |
|
1920 |
grant the request, and return true if so" |
|
1921 |
||
11573 | 1922 |
^ self changeRequest:aSymbol with:aParameter from:self |
11551 | 1923 |
! |
1924 |
||
1925 |
changeRequest:aSymbol with:aParameter from:anObject |
|
5755 | 1926 |
"the receiver wants to change - check if all dependents |
1927 |
except anObject grant the request, and return true if so. |
|
1928 |
The argument anObject is typically going to be the one who is |
|
1929 |
about to send the change request." |
|
1930 |
||
10460 | 1931 |
self dependentsDo:[:dependent | |
20535 | 1932 |
dependent == anObject ifFalse:[ |
1933 |
(dependent updateRequest:aSymbol with:aParameter from:anObject) ifFalse:[^ false]. |
|
1934 |
] |
|
5755 | 1935 |
]. |
1936 |
^ true |
|
1937 |
! |
|
1938 |
||
1939 |
changeRequestFrom:anObject |
|
1940 |
"the receiver wants to change - check if all dependents |
|
1941 |
except anObject grant the request, and return true if so. |
|
1942 |
The argument anObject is typically going to be the one who is |
|
1943 |
about to send the change request." |
|
1944 |
||
10460 | 1945 |
self dependentsDo:[:dependent | |
20535 | 1946 |
dependent == anObject ifFalse:[ |
1947 |
(dependent updateRequest) ifFalse:[^ false]. |
|
1948 |
] |
|
5755 | 1949 |
]. |
1950 |
^ true |
|
1951 |
! |
|
1952 |
||
1953 |
changed |
|
1954 |
"notify all dependents that the receiver has changed. |
|
1955 |
Each dependent gets a '#update:'-message with the original |
|
1956 |
receiver as argument." |
|
1957 |
||
1958 |
self changed:nil |
|
1959 |
! |
|
1960 |
||
1961 |
changed:aParameter |
|
1962 |
"notify all dependents that the receiver has changed somehow. |
|
1963 |
Each dependent gets a '#update:'-message with aParameter |
|
1964 |
as argument." |
|
1965 |
||
1966 |
self changed:aParameter with:nil |
|
1967 |
! |
|
1968 |
||
1969 |
changed:aParameter with:anArgument |
|
1970 |
"notify all dependents that the receiver has changed somehow. |
|
19583 | 1971 |
Each dependent gets an '#update:with:from:'-message, with aParameter |
5755 | 1972 |
and anArgument as arguments." |
1973 |
||
10460 | 1974 |
self dependentsDo:[:dependent | |
20535 | 1975 |
dependent update:aParameter with:anArgument from:self |
5755 | 1976 |
] |
1977 |
! |
|
1978 |
||
1979 |
update:aParameter |
|
1980 |
"the message is sent to a dependent, when one of the objects |
|
1981 |
on whom the receiver depends, has changed. The argument aParameter |
|
1982 |
is either the changed object or the argument to the #changed: message. |
|
1983 |
||
1984 |
Default behavior here is to do nothing" |
|
1985 |
||
1986 |
^ self |
|
1987 |
! |
|
1988 |
||
1989 |
update:aParameter with:anArgument |
|
1990 |
"dependent is notified of some change - |
|
1991 |
Default is to try update:" |
|
1992 |
||
1993 |
^ self update:aParameter |
|
1994 |
! |
|
1995 |
||
1996 |
update:aParameter with:anArgument from:sender |
|
1997 |
"dependent is notified of some change - |
|
1998 |
Default is to try update:with:" |
|
1999 |
||
2000 |
^ self update:aParameter with:anArgument |
|
2001 |
! |
|
2002 |
||
2003 |
updateRequest |
|
20214 | 2004 |
"return true if an update request is granted. |
5755 | 2005 |
Default here is to grant updates - may be used |
2006 |
to lock updates if someone is making other changes |
|
2007 |
from within an update. Or if someone has locked its |
|
2008 |
state and does not want others to change things. |
|
2009 |
However, these dependents must all honor the |
|
2010 |
changeRequest - ifTrue - change protocol. I.e. they |
|
2011 |
must first ask all others via changeRequest, and only do the change |
|
2012 |
it returns true. The others must decide in updateRequest and |
|
2013 |
return true if they think a change is ok." |
|
2014 |
||
2015 |
^ true |
|
2016 |
! |
|
2017 |
||
2018 |
updateRequest:aSymbol |
|
20214 | 2019 |
"return true if an update request is granted. |
5755 | 2020 |
Default here a simple updateRequest" |
2021 |
||
2022 |
^ self updateRequest |
|
7177 | 2023 |
! |
2024 |
||
11551 | 2025 |
updateRequest:aSymbol with:aParameter |
20214 | 2026 |
"return true if an update request is granted. |
11551 | 2027 |
Default here a simple updateRequest" |
2028 |
||
2029 |
^ self updateRequest:aSymbol |
|
2030 |
! |
|
2031 |
||
2032 |
updateRequest:aSymbol with:aParameter from:sender |
|
20214 | 2033 |
"return true if an update request is granted. |
11551 | 2034 |
Default here a simple updateRequest" |
2035 |
||
2036 |
^ self updateRequest:aSymbol with:aParameter |
|
2037 |
! |
|
2038 |
||
7177 | 2039 |
withoutUpdating:someone do:aBlock |
2040 |
"evaluate a block but remove someone from my dependents temporarily" |
|
2041 |
||
2042 |
(self dependents includesIdentical:someone) |
|
2043 |
ifFalse:[ |
|
20535 | 2044 |
^ aBlock value. |
7177 | 2045 |
]. |
2046 |
self removeDependent:someone. |
|
2047 |
^ aBlock ensure:[ self addDependent:someone ] |
|
5755 | 2048 |
! ! |
2049 |
||
21389 | 2050 |
|
5755 | 2051 |
!Object methodsFor:'comparing'! |
2052 |
||
14975 | 2053 |
= anObject |
20214 | 2054 |
"return true if the receiver and the arg have the same structure. |
14975 | 2055 |
Notice: |
20535 | 2056 |
This method is partially open coded (inlined) by the compiler(s) |
2057 |
identical objects are always considered equal. |
|
2058 |
redefining it may not work as expected." |
|
14975 | 2059 |
|
2060 |
^ self == anObject |
|
2061 |
! |
|
2062 |
||
5755 | 2063 |
== anObject |
20214 | 2064 |
"return true if the receiver and the arg are the same object. |
5755 | 2065 |
Never redefine this in any class. |
2066 |
Notice: |
|
20535 | 2067 |
This method is open coded (inlined) by the compiler(s) |
2068 |
- redefining it may not work as expected." |
|
5755 | 2069 |
|
2070 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
2071 |
#ifdef __SCHTEAM__ |
18361 | 2072 |
return context._RETURN( (self == anObject) ? STObject.True : STObject.False ); |
18231 | 2073 |
#else |
5755 | 2074 |
RETURN ( (self == anObject) ? true : false ); |
18231 | 2075 |
#endif |
5755 | 2076 |
%} |
2077 |
! |
|
2078 |
||
5814 | 2079 |
deepSameContentsAs:anObject |
20214 | 2080 |
"return true if the receiver and the arg have the same contents |
5814 | 2081 |
in both the named instance vars and any indexed instVars. |
2082 |
This method descends into referenced objects, where #sameContentsAs: does not descend" |
|
2083 |
||
5821 | 2084 |
|myClass val |
5814 | 2085 |
sz "{ Class: SmallInteger }" | |
2086 |
||
2087 |
myClass := self class. |
|
2088 |
myClass isVariable ifTrue:[ |
|
20535 | 2089 |
sz := self basicSize. |
2090 |
||
2091 |
"compare the indexed variables" |
|
2092 |
1 to:sz do:[:i | |
|
2093 |
val := self basicAt:i. |
|
2094 |
val isLiteral ifTrue:[ |
|
2095 |
val = (anObject basicAt:i) ifFalse:[^ false]. |
|
2096 |
] ifFalse:[ |
|
2097 |
(val deepSameContentsAs:(anObject basicAt:i)) ifFalse:[^ false]. |
|
2098 |
] |
|
2099 |
] |
|
5814 | 2100 |
]. |
2101 |
||
2102 |
"compare the instance variables" |
|
2103 |
sz := myClass instSize. |
|
10460 | 2104 |
1 to:sz do:[:i | |
20535 | 2105 |
val := self instVarAt:i. |
2106 |
val isLiteral ifTrue:[ |
|
2107 |
val = (anObject instVarAt:i) ifFalse:[^ false]. |
|
2108 |
] ifFalse:[ |
|
2109 |
(val deepSameContentsAs:(anObject instVarAt:i)) ifFalse:[^ false]. |
|
2110 |
] |
|
5814 | 2111 |
]. |
2112 |
||
2113 |
^ true |
|
2114 |
||
2115 |
" |
|
10460 | 2116 |
#(1 2 3 4) deepSameContentsAs:#[1 2 3 4] asArray |
5814 | 2117 |
(1@2) deepSameContentsAs:(1->2) |
2118 |
" |
|
2119 |
! |
|
2120 |
||
5755 | 2121 |
hash |
2122 |
"return an Integer useful as a hash key for the receiver. |
|
2123 |
This hash should return same values for objects with same |
|
2124 |
contents (i.e. use this to hash on structure)" |
|
2125 |
||
2126 |
^ self identityHash |
|
2127 |
! |
|
2128 |
||
2129 |
identityHash |
|
2130 |
"return an Integer useful as a hash key for the receiver. |
|
2131 |
This hash should return same values for the same object (i.e. use |
|
2132 |
this to hash on identity of objects). |
|
2133 |
||
2134 |
We cannot use the Objects address (as other smalltalks do) since |
|
2135 |
no object-table exists and the hashval must not change when objects |
|
2136 |
are moved by the collector. Therefore we assign each object a unique |
|
2137 |
Id in the object header itself as its hashed upon. |
|
2138 |
(luckily we have 11 bits spare to do this - unluckily its only 11 bits). |
|
2139 |
Time will show, if 11 bits are enough; if not, another entry in the |
|
2140 |
object header will be needed, adding 4 bytes to every object. Alternatively, |
|
2141 |
hashed-upon objects could add an instvar containing the hash value." |
|
2142 |
||
2143 |
%{ /* NOCONTEXT */ |
|
2144 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2145 |
REGISTER unsigned INT hash; |
5755 | 2146 |
static unsigned nextHash = 0; |
2147 |
||
2148 |
if (__isNonNilObject(self)) { |
|
20535 | 2149 |
hash = __GET_HASH(self); |
2150 |
if (hash == 0) { |
|
2151 |
/* has no hash yet */ |
|
2152 |
||
2153 |
if (++nextHash > __MAX_HASH__) { |
|
2154 |
nextHash = 1; |
|
2155 |
} |
|
2156 |
hash = nextHash; |
|
2157 |
__SET_HASH(self, hash); |
|
2158 |
} |
|
2159 |
||
2160 |
/* |
|
2161 |
* now, we got 11 bits for hashing; |
|
2162 |
* make it as large as possible; since most hashers use the returned |
|
2163 |
* key and take it modulo some prime number, this will allow for |
|
2164 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
2165 |
*/ |
|
2166 |
hash = __MAKE_HASH__(hash); |
|
2167 |
RETURN ( __mkSmallInteger(hash) ); |
|
5755 | 2168 |
} |
2169 |
%}. |
|
2170 |
^ 0 "never reached, since redefined in UndefinedObject and SmallInteger" |
|
2171 |
! |
|
2172 |
||
2173 |
identityHashForBinaryStore |
|
2174 |
"hash which is usable if the object does not change its class |
|
2175 |
and does not #become something else, while the hash is used. |
|
2176 |
This is only used by the binary storage mechanism, during the |
|
2177 |
object writing phase." |
|
2178 |
||
2179 |
%{ /* NOCONTEXT */ |
|
2180 |
||
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2181 |
REGISTER unsigned INT hash, hash1, hash2, sz; |
5755 | 2182 |
OBJ o; |
5806
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2183 |
static unsigned INT nextHash = 0; |
a7361ebe686a
avoid warnings on alpha (int-size)
Claus Gittinger <cg@exept.de>
parents:
5769
diff
changeset
|
2184 |
static unsigned INT nextClassHash = 0; |
5755 | 2185 |
|
2186 |
if (__isNonNilObject(self)) { |
|
20535 | 2187 |
/* |
2188 |
* my own identityHash |
|
2189 |
*/ |
|
2190 |
hash1 = __GET_HASH(self); |
|
2191 |
if (hash1 == 0) { |
|
2192 |
/* has no hash yet */ |
|
2193 |
||
2194 |
if (++nextHash > __MAX_HASH__) { |
|
2195 |
nextHash = 1; |
|
2196 |
} |
|
2197 |
hash1 = nextHash; |
|
2198 |
__SET_HASH(self, hash1); |
|
2199 |
} |
|
2200 |
/* |
|
2201 |
* my classes identityHash |
|
2202 |
*/ |
|
2203 |
o = __qClass(self); |
|
2204 |
hash2 = __GET_HASH(o); |
|
2205 |
if (hash2 == 0) { |
|
2206 |
/* has no hash yet */ |
|
2207 |
||
2208 |
if (++nextClassHash > __MAX_HASH__) { |
|
2209 |
nextClassHash = 1; |
|
2210 |
} |
|
2211 |
hash2 = nextClassHash; |
|
2212 |
__SET_HASH(o, hash2); |
|
2213 |
} |
|
2214 |
||
2215 |
/* |
|
2216 |
* some bits of my size |
|
2217 |
*/ |
|
2218 |
sz = __qSize(self); |
|
2219 |
||
2220 |
/* |
|
2221 |
* now, we got 11 + 11 + 8 bits for hashing; |
|
2222 |
* make it as large as possible; since most hashers use the returned |
|
2223 |
* key and take it modulo some prime number, this will allow for |
|
2224 |
* better distribution (i.e. bigger empty spaces) in hashed collection. |
|
2225 |
*/ |
|
2226 |
hash = (hash1 << 11) | hash2; /* 22 bits */ |
|
2227 |
hash = (hash << 8) | (sz & 0xFC); /* 30 bits */ |
|
2228 |
||
2229 |
while ((hash & 0x20000000) == 0) { |
|
2230 |
hash <<= 1; |
|
2231 |
} |
|
2232 |
||
2233 |
RETURN ( __mkSmallInteger(hash) ); |
|
5755 | 2234 |
} |
2235 |
%}. |
|
2236 |
"never reached, since UndefinedObject and SmallInteger are not hashed upon in binary storage" |
|
2237 |
^ self identityHash |
|
2238 |
! |
|
2239 |
||
2240 |
sameContentsAs:anObject |
|
20214 | 2241 |
"return true if the receiver and the arg have the same contents |
7121 | 2242 |
in both the named instance vars and any indexed instVars. |
2243 |
The code here only checks if values present in the receiver are also |
|
2244 |
present in the arg, not vice versa. |
|
2245 |
I.e. the argument may be bigger and/or have more instance variables." |
|
5755 | 2246 |
|
5821 | 2247 |
|myClass |
5755 | 2248 |
sz "{ Class: SmallInteger }" | |
2249 |
||
2250 |
myClass := self class. |
|
2251 |
myClass isVariable ifTrue:[ |
|
20535 | 2252 |
sz := self basicSize. |
2253 |
anObject basicSize >= sz ifFalse:[^ false]. |
|
2254 |
||
2255 |
"compare the indexed variables" |
|
2256 |
1 to:sz do:[:i | |
|
2257 |
(self basicAt:i) == (anObject basicAt:i) ifFalse:[^ false]. |
|
2258 |
] |
|
5755 | 2259 |
]. |
2260 |
||
2261 |
"compare the instance variables" |
|
2262 |
sz := myClass instSize. |
|
12997 | 2263 |
anObject class instSize >= sz ifFalse:[^ false]. |
7121 | 2264 |
|
10460 | 2265 |
1 to:sz do:[:i | |
20535 | 2266 |
(self instVarAt:i) == (anObject instVarAt:i) ifFalse:[^ false]. |
5755 | 2267 |
]. |
2268 |
||
2269 |
^ true |
|
2270 |
||
2271 |
" |
|
10460 | 2272 |
#(1 2 3 4) sameContentsAs:#[1 2 3 4] asArray |
5814 | 2273 |
(1@2) sameContentsAs:(1->2) |
5755 | 2274 |
" |
2275 |
||
12997 | 2276 |
"Created: / 21-04-1998 / 15:56:40 / cg" |
2277 |
"Modified: / 05-08-2010 / 16:44:09 / sr" |
|
5755 | 2278 |
! |
2279 |
||
2280 |
~= anObject |
|
20214 | 2281 |
"return true if the receiver and the arg do not have the same structure. |
5755 | 2282 |
Notice: |
20535 | 2283 |
This method is partially open coded (inlined) by the compiler(s) |
2284 |
identical objects are never considered unequal. |
|
2285 |
redefining it may not work as expected." |
|
5755 | 2286 |
|
2287 |
^ (self = anObject) not |
|
2288 |
! |
|
2289 |
||
2290 |
~~ anObject |
|
20214 | 2291 |
"return true if the receiver and the arg are not the same object. |
5755 | 2292 |
Never redefine this in any class. |
2293 |
Notice: |
|
20535 | 2294 |
This method is open coded (inlined) by the compiler(s) |
2295 |
- redefining it may not work as expected." |
|
5755 | 2296 |
|
2297 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
2298 |
#ifdef __SCHTEAM__ |
18361 | 2299 |
return context._RETURN( (self == anObject) ? STObject.False : STObject.True ); |
18231 | 2300 |
#else |
5755 | 2301 |
RETURN ( (self == anObject) ? false : true ); |
18231 | 2302 |
#endif |
5755 | 2303 |
%} |
2304 |
! ! |
|
2305 |
||
2306 |
!Object methodsFor:'converting'! |
|
2307 |
||
2308 |
-> anObject |
|
2309 |
"return an association with the receiver as key and |
|
2310 |
the argument as value" |
|
2311 |
||
2312 |
^ Association key:self value:anObject |
|
2313 |
! |
|
2314 |
||
10062 | 2315 |
as:aSimilarClass |
16052 | 2316 |
"If the receiver's class is not aSimilarClass, |
2317 |
create and return an instance of aSimilarClass that has the same contents |
|
10062 | 2318 |
as the receiver. |
2319 |
Otherwise, return the receiver." |
|
2320 |
||
2321 |
self class == aSimilarClass ifTrue:[^ self]. |
|
2322 |
^ aSimilarClass newFrom:self |
|
2323 |
||
2324 |
" |
|
2325 |
#[1 2 3 4] as:ByteArray |
|
2326 |
#[1 2 3 4] as:Array |
|
10539 | 2327 |
#[81 82 83 84] as:String |
2328 |
#[81 82 83 84] as:Symbol |
|
16052 | 2329 |
'hello' as:Unicode16String |
10062 | 2330 |
" |
2331 |
! |
|
2332 |
||
5755 | 2333 |
asCollection |
2334 |
"return myself as a Collection. |
|
2335 |
Redefined in collection to return themself." |
|
2336 |
||
2337 |
^ Array with:self |
|
2338 |
! |
|
2339 |
||
21214 | 2340 |
asCollectionDo:aBlock |
2341 |
"enumerate myself as a Collection. |
|
2342 |
Redefined in collection." |
|
2343 |
||
2344 |
^ aBlock value:self |
|
2345 |
! |
|
2346 |
||
17261 | 2347 |
asLink |
2348 |
"return a valueLink for the receiver. |
|
2349 |
Used to make sure the receiver can be added to a linked list" |
|
2350 |
||
2351 |
^ ValueLink value:self |
|
2352 |
! |
|
2353 |
||
5755 | 2354 |
asSequenceableCollection |
2355 |
"return myself as a SequenceableCollection. |
|
2356 |
Redefined in SequenceableCollection" |
|
2357 |
||
2358 |
^ Array with:self |
|
2359 |
! |
|
2360 |
||
14355 | 2361 |
asString |
2362 |
^ self printString |
|
2363 |
! |
|
2364 |
||
5755 | 2365 |
asValue |
20381 | 2366 |
"return a valueHolder for the receiver" |
5755 | 2367 |
|
2368 |
^ ValueHolder with:self |
|
2369 |
! ! |
|
2370 |
||
2371 |
!Object methodsFor:'copying'! |
|
2372 |
||
10460 | 2373 |
cloneFrom:anObject |
5755 | 2374 |
"Helper for copy: |
2375 |
copy all instance variables from anObject into the receiver, |
|
2376 |
which should be of the same class as the argument." |
|
2377 |
||
2378 |
self cloneFrom:anObject performing:#yourself |
|
2379 |
||
2380 |
" |
|
2381 |
|x| |
|
2382 |
||
2383 |
x := Array new:3. |
|
2384 |
x cloneFrom:#(1 2 3). |
|
2385 |
" |
|
2386 |
! |
|
2387 |
||
2388 |
cloneFrom:anObject performing:aSymbol |
|
2389 |
"Helper for copy: |
|
8383 | 2390 |
for each instance variable from anObject, send it aSymbol |
5755 | 2391 |
and store the result into the receiver, |
2392 |
which should be of the same class as the argument." |
|
2393 |
||
2394 |
|myClass sz "{ Class: SmallInteger }" t | |
|
2395 |
||
2396 |
myClass := self class. |
|
14532 | 2397 |
|
2398 |
"process the named instance variables" |
|
2399 |
sz := myClass instSize. |
|
2400 |
1 to:sz do:[:i | |
|
20535 | 2401 |
t := anObject instVarAt:i. |
2402 |
aSymbol ~~ #yourself ifTrue:[ |
|
2403 |
t := t perform:aSymbol |
|
2404 |
]. |
|
2405 |
self instVarAt:i put:t |
|
14532 | 2406 |
]. |
2407 |
||
5755 | 2408 |
myClass isVariable ifTrue:[ |
20535 | 2409 |
sz := self basicSize. |
2410 |
||
2411 |
"process the indexed instance variables" |
|
2412 |
1 to:sz do:[:i | |
|
2413 |
t := anObject basicAt:i. |
|
2414 |
aSymbol ~~ #yourself ifTrue:[ |
|
2415 |
t := t perform:aSymbol. |
|
2416 |
]. |
|
2417 |
self basicAt:i put:t. |
|
2418 |
] |
|
5755 | 2419 |
]. |
2420 |
! |
|
2421 |
||
2422 |
cloneInstanceVariablesFrom:aPrototype |
|
2423 |
"Shallow copy variables from a prototype into myself. |
|
2424 |
This copies instVars by name - i.e. same-named variables are |
|
2425 |
copied, others are not. |
|
10460 | 2426 |
The variable slots are copied as available |
5755 | 2427 |
(i.e. the min of both indexed sizes is used)." |
10460 | 2428 |
|
20214 | 2429 |
|myClass prototypesClass myInfo prototypesInfo |
19272 | 2430 |
sz "{ Class: SmallInteger }"| |
14676 | 2431 |
|
2432 |
myClass := self class. |
|
2433 |
prototypesClass := aPrototype class. |
|
2434 |
(myClass == prototypesClass |
|
19272 | 2435 |
or:[myClass isSubclassOf:prototypesClass]) ifTrue:[ |
20535 | 2436 |
"/ can do better, if my class is a subclass of the prototype's class |
2437 |
sz := prototypesClass instSize. |
|
2438 |
1 to: sz do:[:index | |
|
2439 |
self instVarAt:index put:(aPrototype instVarAt:index) |
|
2440 |
] |
|
14676 | 2441 |
] ifFalse:[ |
20535 | 2442 |
"/ map instvars by name |
2443 |
myInfo := myClass instanceVariableOffsets. |
|
2444 |
prototypesInfo := prototypesClass instanceVariableOffsets. |
|
2445 |
myInfo keysAndValuesDo:[:name :index | |varIndexAssoc| |
|
2446 |
varIndexAssoc := prototypesInfo at:name ifAbsent:[]. |
|
2447 |
varIndexAssoc notNil ifTrue:[ |
|
2448 |
self instVarAt:index put:(aPrototype instVarAt:(varIndexAssoc value)) |
|
2449 |
] |
|
2450 |
] |
|
14676 | 2451 |
]. |
2452 |
myClass isVariable ifTrue:[ |
|
20535 | 2453 |
prototypesClass isVariable ifTrue:[ |
2454 |
sz := self basicSize min:aPrototype basicSize. |
|
2455 |
1 to:sz do:[:index | |
|
2456 |
self basicAt:index put:(aPrototype basicAt:index) |
|
2457 |
]. |
|
2458 |
]. |
|
5755 | 2459 |
]. |
2460 |
||
2461 |
" |
|
2462 |
Class withoutUpdatingChangesDo:[ |
|
20535 | 2463 |
|point3D| |
2464 |
||
2465 |
point3D := Point subclass:#Point3D |
|
2466 |
instanceVariableNames:'z' |
|
2467 |
classVariableNames:'' |
|
2468 |
poolDictionaries:'' |
|
2469 |
category:'testing' |
|
2470 |
inEnvironment:nil. |
|
2471 |
(point3D new cloneInstanceVariablesFrom:1@2) inspect. |
|
5755 | 2472 |
] |
2473 |
" |
|
2474 |
||
2475 |
" |
|
2476 |
Class withoutUpdatingChangesDo:[ |
|
20535 | 2477 |
Point variableSubclass:#Point3D_test |
2478 |
instanceVariableNames:'z' |
|
2479 |
classVariableNames:'' |
|
2480 |
poolDictionaries:'' |
|
2481 |
category:'testing'. |
|
2482 |
(((Smalltalk at:#Point3D_test) new:2) cloneInstanceVariablesFrom:#(1 2 3)) inspect. |
|
5755 | 2483 |
] |
2484 |
" |
|
2485 |
||
2486 |
" |
|
2487 |
|someObject| |
|
2488 |
||
2489 |
Class withoutUpdatingChangesDo:[ |
|
20535 | 2490 |
Object subclass:#TestClass1 |
2491 |
instanceVariableNames:'foo bar' |
|
2492 |
classVariableNames:'' |
|
2493 |
poolDictionaries:'' |
|
2494 |
category:'testing'. |
|
2495 |
someObject := TestClass1 new. |
|
2496 |
someObject instVarAt:1 put:'foo'; instVarAt:2 put:'bar'. |
|
2497 |
Object subclass:#TestClass2 |
|
2498 |
instanceVariableNames:'bar foo' |
|
2499 |
classVariableNames:'' |
|
2500 |
poolDictionaries:'' |
|
2501 |
category:'testing'. |
|
2502 |
(TestClass2 new cloneInstanceVariablesFrom:someObject) inspect. |
|
5755 | 2503 |
] |
2504 |
" |
|
2505 |
||
2506 |
" |
|
2507 |
|top b b1| |
|
2508 |
||
2509 |
top := StandardSystemView new. |
|
2510 |
top extent:100@100. |
|
2511 |
||
2512 |
b := Button in:top. |
|
2513 |
b label:'hello'. |
|
2514 |
||
2515 |
b1 := ArrowButton new cloneInstanceVariablesFrom:b. |
|
2516 |
||
2517 |
top open. |
|
2518 |
b1 inspect |
|
2519 |
" |
|
2520 |
! |
|
2521 |
||
2522 |
copy |
|
2523 |
"return a copy of the receiver - defaults to shallowcopy here. |
|
2524 |
Notice, that copy does not copy dependents." |
|
2525 |
||
2526 |
^ self shallowCopy postCopy |
|
2527 |
! |
|
2528 |
||
6146 | 2529 |
copyToLevel:level |
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2530 |
"a controlled deepCopy, where the number of levels can be specified. |
10460 | 2531 |
Notice: |
20535 | 2532 |
This method DOES NOT handle cycles/self-refs and does NOT preserve object identity; |
2533 |
i.e. identical references in the source are copied multiple times into the copy." |
|
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2534 |
|
14534 | 2535 |
|newObject newLevel class sz "{Class: SmallInteger}" newInst| |
2536 |
||
2537 |
newObject := self copy. |
|
2538 |
newObject == self ifTrue: [^ self]. "copy of nil, true, false, ... is self" |
|
2539 |
level == 1 ifTrue:[^ newObject]. |
|
2540 |
newLevel := level - 1. |
|
2541 |
||
2542 |
class := newObject class. |
|
2543 |
||
2544 |
"process the named instance variables" |
|
2545 |
sz := class instSize. |
|
2546 |
1 to:sz do:[:i | |
|
20535 | 2547 |
newInst := newObject instVarAt:i. |
2548 |
newInst notNil ifTrue:[ |
|
2549 |
newObject instVarAt:i put:(newInst copyToLevel:newLevel). |
|
2550 |
]. |
|
14534 | 2551 |
]. |
2552 |
||
10460 | 2553 |
class isVariable ifTrue:[ |
20535 | 2554 |
sz := newObject basicSize. |
2555 |
||
2556 |
"process the indexed instance variables" |
|
2557 |
1 to:sz do:[:i | |
|
2558 |
newInst := newObject basicAt:i. |
|
2559 |
newInst notNil ifTrue:[ |
|
2560 |
newObject basicAt:i put:(newInst copyToLevel:newLevel). |
|
2561 |
]. |
|
2562 |
] |
|
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2563 |
]. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2564 |
^ newObject |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2565 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2566 |
" |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2567 |
|a b| |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2568 |
|
10460 | 2569 |
a := #( |
20535 | 2570 |
'1.1' |
2571 |
'1.2' |
|
2572 |
'1.3' |
|
2573 |
( |
|
2574 |
'1.41' |
|
2575 |
'1.42' |
|
2576 |
'1.43' |
|
2577 |
( |
|
2578 |
'1.441' |
|
2579 |
'1.442' |
|
2580 |
'1.443' |
|
2581 |
( '1.4441' '1.4442' '1.4443' ) |
|
2582 |
'1.445' |
|
2583 |
) |
|
2584 |
'1.45' |
|
2585 |
) |
|
2586 |
'1.5' |
|
2587 |
). |
|
6962
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2588 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2589 |
b := a copyToLevel:1. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2590 |
self assert: ( (a at:1) == (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2591 |
self assert: ( (a at:4) == (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2592 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2593 |
b := a copyToLevel:2. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2594 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2595 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2596 |
self assert: ( ((a at:4) at:1) == ((b at:4) at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2597 |
self assert: ( ((a at:4) at:4) == ((b at:4) at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2598 |
|
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2599 |
b := a copyToLevel:3. |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2600 |
self assert: ( (a at:1) ~~ (b at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2601 |
self assert: ( (a at:4) ~~ (b at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2602 |
self assert: ( ((a at:4) at:1) ~~ ((b at:4) at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2603 |
self assert: ( ((a at:4) at:4) ~~ ((b at:4) at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2604 |
self assert: ( (((a at:4) at:4) at:1) == (((b at:4) at:4)at:1) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2605 |
self assert: ( (((a at:4) at:4) at:4) == (((b at:4) at:4)at:4) ). |
eab0d4c42375
copyToLevel: example and comment
Claus Gittinger <cg@exept.de>
parents:
6961
diff
changeset
|
2606 |
" |
6146 | 2607 |
! |
2608 |
||
5755 | 2609 |
deepCopy |
2610 |
"return a copy of the object with all subobjects also copied. |
|
10460 | 2611 |
This method DOES handle cycles/self-refs and preserves object identity; |
19451 | 2612 |
however the receiver's class is not copied (to avoid the 'total' copy). |
5755 | 2613 |
|
2614 |
This deepCopy is a bit slower than the old (unsecure) one, since it |
|
2615 |
keeps track of already copied objects. If you are sure, that your |
|
2616 |
copied object does not include duplicates (or you do not care) and |
|
10460 | 2617 |
no cycles are involved, you can use the old simpleDeepCopy, |
5755 | 2618 |
which avoids this overhead (but may run into trouble). |
2619 |
Notice, that deepCopy does not copy dependents." |
|
2620 |
||
8383 | 2621 |
^ self deepCopyUsing:(IdentityDictionary new) |
5755 | 2622 |
|
2623 |
"an example which is not handled by the old deepCopy: |
|
10460 | 2624 |
|
5755 | 2625 |
|a| |
2626 |
a := Array new:3. |
|
2627 |
a at:3 put:a. |
|
2628 |
a deepCopy inspect |
|
2629 |
" |
|
2630 |
||
2631 |
" |
|
2632 |
|a| |
|
2633 |
a := Color black onDevice:Screen current. |
|
2634 |
a deepCopy inspect |
|
2635 |
" |
|
2636 |
||
2637 |
"Modified: 27.3.1996 / 16:31:20 / stefan" |
|
2638 |
! |
|
2639 |
||
2640 |
deepCopyError |
|
2641 |
"{ Pragma: +optSpace }" |
|
2642 |
||
2643 |
"raise a signal, that deepCopy is not allowed for this object" |
|
2644 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
2645 |
^ DeepCopyError raise |
5755 | 2646 |
! |
2647 |
||
2648 |
deepCopyUsing:aDictionary |
|
10460 | 2649 |
"a helper for deepCopy; return a copy of the object with |
2650 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
5755 | 2651 |
use the value found there. The class of the receiver is not copied. |
2652 |
This method DOES handle cycles/self references." |
|
2653 |
||
10941 | 2654 |
^ self deepCopyUsing:aDictionary postCopySelector:#postDeepCopyFrom:. |
2655 |
||
5755 | 2656 |
|
2657 |
" |
|
2658 |
|a b c copyOfC| |
|
2659 |
||
2660 |
a := Array with:'hello' with:'world' with:nil. |
|
2661 |
b := 99 @ 999. |
|
2662 |
a at:3 put:b. |
|
2663 |
c := Array with:a with:b with:a. |
|
2664 |
||
2665 |
Transcript showCR: (c at:1) == (c at:3). |
|
2666 |
copyOfC := c deepCopy. |
|
2667 |
Transcript showCR: (copyOfC at:1) == (copyOfC at:3) |
|
2668 |
" |
|
2669 |
! |
|
2670 |
||
10954 | 2671 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
11335 | 2672 |
"a helper for deepCopy; return a copy of the object with |
2673 |
all subobjects also copied. If the to-be-copied object is in the dictionary, |
|
10954 | 2674 |
use the value found there. The class of the receiver is not copied. |
2675 |
This method DOES handle cycles/self references." |
|
2676 |
||
2677 |
|myClass aCopy |
|
14527 | 2678 |
basicSize "{ Class: SmallInteger }" |
2679 |
instSize "{ Class: SmallInteger }" |
|
10954 | 2680 |
iOrig iCopy| |
2681 |
||
2682 |
myClass := self class. |
|
2683 |
myClass isVariable ifTrue:[ |
|
20535 | 2684 |
basicSize := self basicSize. |
2685 |
aCopy := self speciesForCopy basicNew:basicSize. |
|
10954 | 2686 |
] ifFalse:[ |
20535 | 2687 |
basicSize := 0. |
2688 |
aCopy := self speciesForCopy basicNew |
|
10954 | 2689 |
]. |
2690 |
aCopy setHashFrom:self. |
|
2691 |
aDictionary at:self put:aCopy. |
|
2692 |
||
2693 |
" |
|
14527 | 2694 |
copy the instance variables |
2695 |
" |
|
2696 |
instSize := myClass instSize. |
|
2697 |
1 to:instSize do:[:i | |
|
20535 | 2698 |
(self skipInstvarIndexInDeepCopy:i) ifFalse:[ |
2699 |
iOrig := self instVarAt:i. |
|
2700 |
iOrig notNil ifTrue:[ |
|
2701 |
iCopy := aDictionary at:iOrig ifAbsent:nil. |
|
2702 |
iCopy isNil ifTrue:[ |
|
2703 |
iCopy := iOrig deepCopyUsing:aDictionary postCopySelector:postCopySelector |
|
2704 |
]. |
|
2705 |
aCopy instVarAt:i put:iCopy |
|
2706 |
] |
|
2707 |
] |
|
14527 | 2708 |
]. |
2709 |
||
2710 |
" |
|
10954 | 2711 |
copy indexed instvars - if any |
2712 |
" |
|
14527 | 2713 |
basicSize ~~ 0 ifTrue:[ |
20535 | 2714 |
myClass isBits ifTrue:[ |
2715 |
"block-copy indexed instvars" |
|
2716 |
aCopy replaceFrom:1 to:basicSize with:self startingAt:1 |
|
2717 |
] ifFalse:[ |
|
2718 |
"individual deep copy the indexed variables" |
|
2719 |
1 to:basicSize do:[:i | |
|
2720 |
iOrig := self basicAt:i. |
|
2721 |
iOrig notNil ifTrue:[ |
|
2722 |
"/ used to be dict-includesKey-ifTrue[dict-at:], |
|
2723 |
"/ changed to use dict-at:ifAbsent:, to avoid double lookup in dictionary |
|
2724 |
iCopy := aDictionary at:iOrig ifAbsent:nil. |
|
2725 |
iCopy isNil ifTrue:[ |
|
2726 |
iCopy := iOrig deepCopyUsing:aDictionary postCopySelector:postCopySelector |
|
2727 |
]. |
|
2728 |
aCopy basicAt:i put:iCopy |
|
2729 |
] |
|
2730 |
] |
|
2731 |
] |
|
10954 | 2732 |
]. |
2733 |
||
13515
2c1e968842cb
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13500
diff
changeset
|
2734 |
aCopy perform:postCopySelector withOptionalArgument:self and:aDictionary. |
10954 | 2735 |
^ aCopy |
13515
2c1e968842cb
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13500
diff
changeset
|
2736 |
|
2c1e968842cb
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13500
diff
changeset
|
2737 |
"Modified: / 21-07-2011 / 13:30:52 / cg" |
10954 | 2738 |
! |
2739 |
||
5755 | 2740 |
postCopy |
2741 |
"this is for compatibility with ST-80 code, which uses postCopy for |
|
2742 |
cleanup after copying, while ST/X passes the original in postCopyFrom: |
|
2743 |
(see there)" |
|
2744 |
||
2745 |
^ self |
|
2746 |
! |
|
2747 |
||
2748 |
postDeepCopy |
|
8930
edd42af66c0a
deepCopy should not invoke postCopy
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
2749 |
"allows for cleanup after deep copying. |
edd42af66c0a
deepCopy should not invoke postCopy
Claus Gittinger <cg@exept.de>
parents:
8913
diff
changeset
|
2750 |
To be redefined in subclasses." |
5755 | 2751 |
! |
2752 |
||
2753 |
postDeepCopyFrom:aSource |
|
2754 |
"allows for cleanup after deep copying" |
|
2755 |
||
2756 |
^ self postDeepCopy |
|
2757 |
! |
|
2758 |
||
2759 |
setHashFrom:anObject |
|
10460 | 2760 |
"set my identity-hash key to be the same as anObjects hash key. |
2761 |
This is an ST/X speciality, which is NOT available in other (especially OT based) |
|
5755 | 2762 |
Smalltalks, and may not be available in future ST/X versions. |
2763 |
DO NEVER use this for normal application code." |
|
2764 |
||
2765 |
%{ /* NOCONTEXT */ |
|
2766 |
||
2767 |
REGISTER unsigned h; |
|
2768 |
||
2769 |
if (__isNonNilObject(self) && __isNonNilObject(anObject)) { |
|
20535 | 2770 |
h = __GET_HASH(anObject); |
2771 |
__SET_HASH(self, h); |
|
2772 |
RETURN (self); |
|
5755 | 2773 |
} |
2774 |
%}. |
|
2775 |
self primitiveFailed "neither receiver not arg may be nil or SmallInteger" |
|
2776 |
! |
|
2777 |
||
2778 |
shallowCopy |
|
2779 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2780 |
i.e. the copy shares referenced instvars with its original." |
|
2781 |
||
2782 |
%{ /* NOCONTEXT */ |
|
2783 |
int ninsts, spc; |
|
2784 |
int sz; |
|
2785 |
OBJ theCopy; |
|
2786 |
OBJ cls; |
|
2787 |
int flags; |
|
2788 |
||
2789 |
cls = __qClass(self); |
|
2790 |
flags = __intVal(__ClassInstPtr(cls)->c_flags); |
|
2791 |
||
2792 |
/* |
|
2793 |
* bail out for special objects .. |
|
2794 |
*/ |
|
2795 |
if (((flags & ~ARRAYMASK) == 0) |
|
2796 |
&& ((flags & ARRAYMASK) != WKPOINTERARRAY)) { |
|
20535 | 2797 |
sz = __qSize(self); |
2798 |
__PROTECT__(self); |
|
2799 |
__qNew(theCopy, sz); /* OBJECT ALLOCATION */ |
|
2800 |
__UNPROTECT__(self); |
|
2801 |
if (theCopy) { |
|
2802 |
cls = __qClass(self); |
|
2803 |
spc = __qSpace(theCopy); |
|
2804 |
||
2805 |
theCopy->o_class = cls; __STORE_SPC(theCopy, cls, spc); |
|
2806 |
||
2807 |
sz = sz - OHDR_SIZE; |
|
2808 |
if (sz) { |
|
2809 |
char *src, *dst; |
|
2810 |
||
2811 |
src = (char *)(__InstPtr(self)->i_instvars); |
|
2812 |
dst = (char *)(__InstPtr(theCopy)->i_instvars); |
|
5755 | 2813 |
#ifdef bcopy4 |
20535 | 2814 |
{ |
2815 |
/* care for odd-number of longs */ |
|
2816 |
int nW = sz >> 2; |
|
2817 |
||
2818 |
if (sz & 3) { |
|
2819 |
nW++; |
|
2820 |
} |
|
2821 |
||
2822 |
bcopy4(src, dst, nW); |
|
2823 |
} |
|
5755 | 2824 |
#else |
20535 | 2825 |
bcopy(src, dst, sz); |
5755 | 2826 |
#endif |
2827 |
||
20535 | 2828 |
flags &= ARRAYMASK; |
2829 |
if (flags == POINTERARRAY) { |
|
2830 |
ninsts = __BYTES2OBJS__(sz); |
|
2831 |
} else { |
|
2832 |
ninsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
2833 |
} |
|
2834 |
if (ninsts) { |
|
2835 |
do { |
|
2836 |
OBJ el; |
|
2837 |
||
2838 |
el = __InstPtr(theCopy)->i_instvars[ninsts-1]; |
|
2839 |
__STORE_SPC(theCopy, el, spc); |
|
2840 |
} while (--ninsts); |
|
2841 |
} |
|
2842 |
} |
|
2843 |
RETURN (theCopy); |
|
2844 |
} |
|
5755 | 2845 |
} |
2846 |
%}. |
|
2847 |
"/ fallBack for special objects & memoryAllocation failure case |
|
2848 |
||
2849 |
^ self slowShallowCopy |
|
2850 |
! |
|
2851 |
||
2852 |
simpleDeepCopy |
|
2853 |
"return a copy of the object with all subobjects also copied. |
|
10460 | 2854 |
This method does NOT handle cycles - but is included to allow this |
5755 | 2855 |
slightly faster copy in situations where it is known that |
2856 |
no recursive references occur (LargeIntegers for example). |
|
2857 |
NOTICE: you will run into trouble, when trying this with recursive |
|
2858 |
objects (usually recursionInterrupt or memory-alert). |
|
8383 | 2859 |
This method corresponds to the 'traditional' deepCopy found in the Blue book." |
5755 | 2860 |
|
2861 |
|myClass aCopy| |
|
2862 |
||
2863 |
(myClass := self class) isVariable ifTrue:[ |
|
20535 | 2864 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2865 |
] ifFalse:[ |
20535 | 2866 |
aCopy := myClass basicNew |
5755 | 2867 |
]. |
2868 |
||
2869 |
"copy the instance variables" |
|
2870 |
aCopy cloneFrom:self performing:#simpleDeepCopy. |
|
2871 |
^ aCopy |
|
2872 |
||
2873 |
"a bad example (but ST/X should survive ...)" |
|
2874 |
" |
|
2875 |
|a| |
|
2876 |
a := Array new:3. |
|
2877 |
a at:3 put:a. |
|
2878 |
a simpleDeepCopy |
|
2879 |
" |
|
2880 |
! |
|
2881 |
||
2882 |
skipInstvarIndexInDeepCopy:index |
|
2883 |
"a helper for deepCopy; only indices for which this method returns |
|
2884 |
false are copied in a deep copy. |
|
2885 |
The default is false here - which means that everything is copied. |
|
2886 |
Can be redefined in subclasses for partial copies" |
|
2887 |
||
2888 |
^ false |
|
2889 |
! |
|
2890 |
||
2891 |
slowShallowCopy |
|
2892 |
"return a copy of the object with shared subobjects (a shallow copy) |
|
2893 |
i.e. the copy shares referenced instvars with its original. |
|
2894 |
This method is only invoked as a fallback from #shallowCopy." |
|
2895 |
||
2896 |
|myClass aCopy| |
|
2897 |
||
2898 |
(myClass := self class) isVariable ifTrue:[ |
|
20535 | 2899 |
aCopy := myClass basicNew:(self basicSize). |
5755 | 2900 |
] ifFalse:[ |
20535 | 2901 |
aCopy := myClass basicNew |
5755 | 2902 |
]. |
2903 |
||
2904 |
"copy the instance variables" |
|
2905 |
aCopy cloneFrom:self performing:#yourself. |
|
2906 |
^ aCopy |
|
2907 |
! ! |
|
2908 |
||
2909 |
!Object methodsFor:'debugging'! |
|
2910 |
||
7621 | 2911 |
assert:aBooleanOrBlock |
13800 | 2912 |
"fail and report an error, if the argument does not evaluate to true" |
6964 | 2913 |
|
11662 | 2914 |
"{ Pragma: +optSpace }" |
2915 |
||
11021 | 2916 |
<resource: #skipInDebuggersWalkBack> |
2917 |
||
8876 | 2918 |
aBooleanOrBlock == true ifTrue:[^ self]. |
17437 | 2919 |
(Smalltalk ignoreAssertions) ifTrue:[^ self]. |
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
2920 |
|
8876 | 2921 |
"/ could still be a block or false. |
11662 | 2922 |
(aBooleanOrBlock value) ifFalse:[ |
20535 | 2923 |
AssertionFailedError |
2924 |
raiseRequestWith:self |
|
2925 |
errorString:('Assertion failed in ', |
|
2926 |
thisContext methodHome sender printString, |
|
2927 |
'[', thisContext methodHome sender lineNumber printString,']') |
|
11662 | 2928 |
]. |
2929 |
||
2930 |
" |
|
2931 |
self assert:false |
|
2932 |
" |
|
13039 | 2933 |
|
2934 |
"Modified: / 20-08-2010 / 17:13:06 / cg" |
|
7621 | 2935 |
! |
2936 |
||
19287 | 2937 |
assert:aBooleanOrBlock description:messageIfFailing |
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
2938 |
"fail, if the argument does not evaluate to true and report an error" |
6961 | 2939 |
|
2940 |
"{ Pragma: +optSpace }" |
|
2941 |
||
11021 | 2942 |
<resource: #skipInDebuggersWalkBack> |
2943 |
||
11141
b96ed3ac5825
assertions can be globally disabled
Claus Gittinger <cg@exept.de>
parents:
11132
diff
changeset
|
2944 |
aBooleanOrBlock == true ifTrue:[^ self]. |
17437 | 2945 |
(Smalltalk ignoreAssertions) ifTrue:[^ self]. |
2946 |
||
2947 |
"/ could still be a block or false. |
|
7621 | 2948 |
(aBooleanOrBlock value) ifFalse:[ |
20535 | 2949 |
AssertionFailedError |
2950 |
raiseRequestWith:self |
|
2951 |
errorString:(messageIfFailing, ' {',thisContext methodHome sender "methodHome" printString,' }') |
|
19287 | 2952 |
]. |
2953 |
||
2954 |
" |
|
2955 |
self assert:false description:'xxx' |
|
2956 |
" |
|
2957 |
||
2958 |
"Modified (comment): / 06-03-2012 / 11:26:48 / cg" |
|
2959 |
! |
|
2960 |
||
2961 |
assert:aBooleanOrBlock message:messageIfFailing |
|
2962 |
"fail, if the argument does not evaluate to true and report an error" |
|
2963 |
||
2964 |
"{ Pragma: +optSpace }" |
|
2965 |
||
2966 |
<resource: #skipInDebuggersWalkBack> |
|
2967 |
||
2968 |
^ self assert: aBooleanOrBlock description: messageIfFailing |
|
11662 | 2969 |
|
2970 |
" |
|
2971 |
self assert:false message:'xxx' |
|
10651 | 2972 |
" |
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2973 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
2974 |
"Modified (comment): / 06-03-2012 / 11:26:48 / cg" |
6961 | 2975 |
! |
2976 |
||
5755 | 2977 |
basicInspect |
2978 |
"{ Pragma: +optSpace }" |
|
2979 |
||
2980 |
"launch an inspector on the receiver. |
|
2981 |
this method should NOT be redefined in subclasses." |
|
2982 |
||
2983 |
Inspector isNil ifTrue:[ |
|
20535 | 2984 |
" |
2985 |
for systems without GUI |
|
2986 |
" |
|
2987 |
self warn:'No Inspector defined (Inspector is nil).' |
|
5755 | 2988 |
] ifFalse:[ |
20535 | 2989 |
Inspector openOn:self |
5755 | 2990 |
] |
2991 |
||
2992 |
"Modified: 18.5.1996 / 15:43:25 / cg" |
|
2993 |
! |
|
2994 |
||
11025 | 2995 |
breakPoint:someKey |
6954 | 2996 |
"{ Pragma: +optSpace }" |
2997 |
||
2998 |
"Like halt, but disabled by default. |
|
2999 |
Can be easily enabled. |
|
3000 |
Can be filtered on the arguments value (typically: a symbol). |
|
3001 |
Code with breakpoints may be even checked into the source repository" |
|
3002 |
||
3003 |
"Example: nil breakPoint:#stefan" |
|
3004 |
||
11025 | 3005 |
<resource: #skipInDebuggersWalkBack> |
3006 |
||
20807 | 3007 |
"/ don't send #breakPoint:info: here - ask cg why. |
11048 | 3008 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
20535 | 3009 |
^ HaltSignal |
3010 |
raiseRequestWith:someKey |
|
3011 |
errorString:('Breakpoint encountered: %1' bindWith:someKey) |
|
11048 | 3012 |
]. |
11025 | 3013 |
|
3014 |
" |
|
3015 |
nil breakPoint:#stefan |
|
3016 |
nil breakPoint:#stefan info:'Hello' |
|
3017 |
Smalltalk enableBreakPoint:#stefan. |
|
3018 |
Smalltalk disableBreakPoint:#stefan. |
|
11048 | 3019 |
|
3020 |
EncounteredBreakPoints. |
|
3021 |
Smalltalk enableBreakPoint:#cg. |
|
3022 |
Smalltalk disableBreakPoint:#cg. |
|
11025 | 3023 |
" |
3024 |
! |
|
3025 |
||
3026 |
breakPoint:someKey info:infoString |
|
3027 |
"{ Pragma: +optSpace }" |
|
3028 |
||
3029 |
"Like halt, but disabled by default. |
|
3030 |
Can be easily enabled. |
|
3031 |
Can be filtered on the arguments value (typically: a symbol). |
|
3032 |
Code with breakpoints may be even checked into the source repository" |
|
3033 |
||
3034 |
"Example: nil breakPoint:#stefan" |
|
3035 |
||
3036 |
<resource: #skipInDebuggersWalkBack> |
|
3037 |
||
3038 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
20535 | 3039 |
^ HaltSignal |
3040 |
raiseRequestWith:someKey |
|
3041 |
errorString:(infoString bindWith:someKey) |
|
11025 | 3042 |
]. |
6954 | 3043 |
! |
3044 |
||
11244 | 3045 |
debuggingCodeFor:someKey is:aBlock |
3046 |
"{ Pragma: +optSpace }" |
|
3047 |
||
3048 |
"aBlock is evaluated if breakPoints for somekey are enabled. |
|
3049 |
Allows for debugging code to be enabled/disabled via the breakpoint browser. |
|
3050 |
Can be easily enabled. |
|
3051 |
Can be filtered on the arguments value (typically: a symbol). |
|
3052 |
Code with breakpoints may be even checked into the source repository" |
|
3053 |
||
3054 |
"Example: nil debuggingCodeFor:#cg is:[ self halt ]" |
|
3055 |
||
3056 |
<resource: #skipInDebuggersWalkBack> |
|
3057 |
||
3058 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
20535 | 3059 |
aBlock value |
11244 | 3060 |
]. |
3061 |
||
3062 |
" |
|
3063 |
Smalltalk disableBreakPoint:#cg. |
|
12340
e9ea989ffe01
comment/format in: #debuggingCodeFor:is:
Claus Gittinger <cg@exept.de>
parents:
12328
diff
changeset
|
3064 |
nil debuggingCodeFor:#cg is:[ Transcript showCR:'here is some debug message for cg' ]. |
e9ea989ffe01
comment/format in: #debuggingCodeFor:is:
Claus Gittinger <cg@exept.de>
parents:
12328
diff
changeset
|
3065 |
nil debuggingCodeFor:#stefan is:[ Transcript showCR:'here is some debug message for sv' ]. |
11244 | 3066 |
Smalltalk enableBreakPoint:#cg. |
12340
e9ea989ffe01
comment/format in: #debuggingCodeFor:is:
Claus Gittinger <cg@exept.de>
parents:
12328
diff
changeset
|
3067 |
nil debuggingCodeFor:#cg is:[ Transcript showCR:'here is some debug message for cg' ]. |
e9ea989ffe01
comment/format in: #debuggingCodeFor:is:
Claus Gittinger <cg@exept.de>
parents:
12328
diff
changeset
|
3068 |
nil debuggingCodeFor:#stefan is:[ Transcript showCR:'here is some debug message for sv' ]. |
11244 | 3069 |
Smalltalk disableBreakPoint:#cg. |
3070 |
||
3071 |
" |
|
3072 |
! |
|
3073 |
||
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3074 |
disableAllBreakPoints |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3075 |
"disable all parametrized breakPoints (with any key as parameter)" |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3076 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3077 |
EnabledBreakPoints := nil |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3078 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3079 |
" |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3080 |
nil enableBreakPoint:#cg. |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3081 |
nil breakPoint:#cg. |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3082 |
nil disableAllBreakPoints. |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3083 |
nil breakPoint:#cg. |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3084 |
" |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3085 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3086 |
"Created: / 06-03-2012 / 15:32:28 / cg" |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3087 |
! |
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3088 |
|
11025 | 3089 |
disableBreakPoint:someKey |
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3090 |
"disable parametrized breakPoints with someKey as parameter" |
11025 | 3091 |
|
3092 |
"{ Pragma: +optSpace }" |
|
3093 |
||
3094 |
EnabledBreakPoints notNil ifTrue:[ |
|
20535 | 3095 |
EnabledBreakPoints remove:someKey ifAbsent:[]. |
3096 |
EnabledBreakPoints := EnabledBreakPoints asNilIfEmpty. |
|
11025 | 3097 |
]. |
3098 |
||
3099 |
" |
|
3100 |
nil enableBreakPoint:#cg. |
|
3101 |
nil breakPoint:#cg. |
|
3102 |
nil disableBreakPoint:#cg |
|
3103 |
nil breakPoint:#cg. |
|
3104 |
" |
|
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3105 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3106 |
"Modified (comment): / 06-03-2012 / 15:31:51 / cg" |
11025 | 3107 |
! |
3108 |
||
3109 |
enableBreakPoint:someKey |
|
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3110 |
"enable parametrized breakPoints with someKey as parameter" |
11025 | 3111 |
|
3112 |
"{ Pragma: +optSpace }" |
|
3113 |
||
3114 |
EnabledBreakPoints isNil ifTrue:[ |
|
20535 | 3115 |
EnabledBreakPoints := Set new. |
11025 | 3116 |
]. |
3117 |
EnabledBreakPoints add:someKey. |
|
3118 |
||
3119 |
" |
|
3120 |
nil enableBreakPoint:#cg. |
|
3121 |
nil breakPoint:#cg. |
|
3122 |
nil disableBreakPoint:#cg |
|
3123 |
nil breakPoint:#cg. |
|
3124 |
" |
|
14046
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3125 |
|
541f46216cb4
added: #disableAllBreakPoints
Claus Gittinger <cg@exept.de>
parents:
13990
diff
changeset
|
3126 |
"Modified (comment): / 06-03-2012 / 15:31:47 / cg" |
11025 | 3127 |
! |
3128 |
||
11048 | 3129 |
halt |
3130 |
"{ Pragma: +optSpace }" |
|
3131 |
||
3132 |
"enter debugger with halt-message. |
|
3133 |
The error is reported by raising the HaltSignal exception." |
|
3134 |
||
3135 |
<resource: #skipInDebuggersWalkBack> |
|
3136 |
||
13136 | 3137 |
Smalltalk ignoreHalt ifTrue:[^ self]. |
14830 | 3138 |
"/ don't send #halt: here - ask cg why. |
14974 | 3139 |
HaltInterrupt raiseRequestWith:#halt. |
3140 |
^ self |
|
3141 |
||
3142 |
" |
|
20535 | 3143 |
(3 halt * 5) |
14974 | 3144 |
" |
11048 | 3145 |
|
13136 | 3146 |
"Modified: / 02-08-1999 / 17:00:29 / stefan" |
3147 |
"Modified: / 18-11-2010 / 11:21:51 / cg" |
|
11048 | 3148 |
! |
3149 |
||
3150 |
halt:aString |
|
3151 |
"{ Pragma: +optSpace }" |
|
3152 |
||
3153 |
"enter debugger with halt-message. |
|
3154 |
The error is reported by raising the HaltSignal exception." |
|
3155 |
||
3156 |
<resource: #skipInDebuggersWalkBack> |
|
3157 |
||
13136 | 3158 |
Smalltalk ignoreHalt ifTrue:[^ self]. |
14974 | 3159 |
HaltInterrupt raiseRequestWith:#halt: errorString:aString. |
3160 |
^ self |
|
11048 | 3161 |
|
13136 | 3162 |
"Modified: / 18-11-2010 / 11:22:16 / cg" |
11048 | 3163 |
! |
3164 |
||
11025 | 3165 |
isBreakPointEnabled:someKey |
3166 |
"{ Pragma: +optSpace }" |
|
3167 |
||
3168 |
"controls which breakpoints to be enabled." |
|
3169 |
||
3170 |
"/ something = OperatingSystem getLoginName ifTrue:[^ true]. |
|
3171 |
"/ something = 'testThis' ifTrue:[^ true]. |
|
11044
fa13d9423e71
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11025
diff
changeset
|
3172 |
EncounteredBreakPoints notNil ifTrue:[ |
20535 | 3173 |
EncounteredBreakPoints add:someKey |
11335 | 3174 |
]. |
3175 |
||
3176 |
^ (EnabledBreakPoints notNil and:[ EnabledBreakPoints includes:someKey ]) |
|
11025 | 3177 |
|
3178 |
" |
|
3179 |
nil enableBreakPoint:#cg. |
|
3180 |
nil breakPoint:#cg. |
|
3181 |
nil disableBreakPoint:#cg |
|
3182 |
nil breakPoint:#cg. |
|
11045
85315d8893e4
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11044
diff
changeset
|
3183 |
|
85315d8893e4
allow for encounteredBreakPoints to be monitored
Claus Gittinger <cg@exept.de>
parents:
11044
diff
changeset
|
3184 |
EncounteredBreakPoints := Set new. |
11025 | 3185 |
" |
3186 |
! |
|
3187 |
||
5755 | 3188 |
mustBeBoolean |
3189 |
"this message is sent by the VM, if a non-Boolean receiver is encountered |
|
3190 |
in an if* or while* message. |
|
3191 |
Caveat: for now, this is only sent by the interpreter; |
|
3192 |
both the JIT and the stc compiler treat it as undefined." |
|
3193 |
||
11021 | 3194 |
<resource: #skipInDebuggersWalkBack> |
3195 |
||
5755 | 3196 |
self error:'Non boolean receiver - proceed for truth' mayProceed:true. |
3197 |
^ true |
|
3198 |
! |
|
3199 |
||
3200 |
mustBeKindOf:aClass |
|
10460 | 3201 |
"for compatibility & debugging support: |
5755 | 3202 |
check if the receiver isKindOf:aClass and raise an error if not. |
3203 |
Notice: |
|
20535 | 3204 |
it is VERY questionable, if it makes sense to add manual |
3205 |
type checks to a dynamically typed language like smalltalk. |
|
3206 |
It will, at least, slow down performance, |
|
3207 |
make your code less reusable and clutter your code with stupid sends |
|
3208 |
of this selector. Also, read the comment in isKindOf:, regarding the |
|
3209 |
use of isXXX check methods. |
|
5755 | 3210 |
You see: The author does not like this at all ..." |
3211 |
||
11021 | 3212 |
<resource: #skipInDebuggersWalkBack> |
3213 |
||
5755 | 3214 |
(self isKindOf:aClass) ifFalse:[ |
20535 | 3215 |
self error:'argument is not of expected type' |
5755 | 3216 |
] |
3217 |
! |
|
3218 |
||
6950 | 3219 |
obsoleteFeatureWarning |
3220 |
"{ Pragma: +optSpace }" |
|
3221 |
||
3222 |
"in methods which are going to be changed, a send to |
|
3223 |
this method is used to tell programmers that some feature/semantics is |
|
3224 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3225 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)." |
6950 | 3226 |
|
3227 |
self obsoleteFeatureWarning:nil from:thisContext sender |
|
3228 |
! |
|
3229 |
||
3230 |
obsoleteFeatureWarning:message |
|
3231 |
"{ Pragma: +optSpace }" |
|
3232 |
||
3233 |
"in methods which are going to be changed, a send to |
|
3234 |
this method is used to tell programmers that some feature/semantics is |
|
3235 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3236 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
3237 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 3238 |
|
3239 |
self obsoleteFeatureWarning:message from:thisContext sender |
|
3240 |
! |
|
3241 |
||
3242 |
obsoleteFeatureWarning:message from:aContext |
|
3243 |
"{ Pragma: +optSpace }" |
|
3244 |
||
3245 |
"in methods which are going to be changed, a send to |
|
3246 |
this method is used to tell programmers that some feature/semantics is |
|
3247 |
used which is going to be changed in later ST/X versions. |
|
6963 | 3248 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
3249 |
This message is intended for application developers, so its printed as info message." |
|
6950 | 3250 |
|
11527 | 3251 |
|spec sender| |
6950 | 3252 |
|
3253 |
spec := aContext methodPrintString. |
|
11527 | 3254 |
sender := aContext sender. |
3255 |
||
6950 | 3256 |
('WARNING: the ''' , spec , ''' semantics will be changed.') infoPrintCR. |
3257 |
(' Its behavior may be different in future ST/X versions.') infoPrintCR. |
|
11527 | 3258 |
(' called from ' , sender printString) infoPrintCR. |
3259 |
((sender selector ? '') startsWith:'perform:') ifTrue:[ |
|
3260 |
(' called from ' , sender sender printString) infoPrintCR. |
|
7204 | 3261 |
]. |
6950 | 3262 |
message notNil ifTrue:[ |
20535 | 3263 |
'------> ' infoPrint. message infoPrintCR |
6950 | 3264 |
] |
3265 |
||
3266 |
" |
|
3267 |
Object obsoleteFeatureWarning:'foo' from:thisContext sender sender |
|
3268 |
" |
|
3269 |
! |
|
3270 |
||
5755 | 3271 |
obsoleteMethodWarning |
3272 |
"{ Pragma: +optSpace }" |
|
3273 |
||
3274 |
"in methods which are going to be obsoleted, a self send to |
|
3275 |
this method is used to tell programmers that a method is |
|
3276 |
used which is going to be removed in later ST/X versions. |
|
6963 | 3277 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3278 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 3279 |
|
3280 |
self obsoleteMethodWarning:nil from:thisContext sender |
|
3281 |
! |
|
3282 |
||
3283 |
obsoleteMethodWarning:message |
|
3284 |
"{ Pragma: +optSpace }" |
|
3285 |
||
3286 |
"in methods which are going to be obsoleted, a self send to |
|
3287 |
this method is used to tell programmers that a method is |
|
3288 |
used which is going to be removed in later ST/X versions. |
|
6963 | 3289 |
Find all methods which will be obsolete soon by looking at senders of this message. |
3290 |
Hopefully, this warning message is annoying enough for you to change the code... ;-)" |
|
5755 | 3291 |
|
3292 |
self obsoleteMethodWarning:message from:thisContext sender |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3293 |
! |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3294 |
|
16470 | 3295 |
obsoleteMethodWarning:messageOrNil from:aContext |
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3296 |
"{ Pragma: +optSpace }" |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3297 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3298 |
"in methods which are going to be obsoleted, a self-send to |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3299 |
this method is used to tell programmers that a method is |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3300 |
used which is going to be removed in later ST/X versions. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3301 |
Find all methods which will be obsolete soon by looking at senders of this message. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3302 |
Hopefully, this warning message is annoying enough for you to change the code... ;-). |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3303 |
This message is intended for application developers, so its printed as info message." |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3304 |
|
16470 | 3305 |
|spec sender message| |
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3306 |
|
9509 | 3307 |
Smalltalk isSmalltalkDevelopmentSystem ifFalse:[ |
20535 | 3308 |
"ignore in production systems" |
3309 |
^ self. |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3310 |
]. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3311 |
|
16470 | 3312 |
message := messageOrNil ? 'Obsolete method called'. |
3313 |
||
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3314 |
spec := aContext methodPrintString. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3315 |
sender := aContext sender. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3316 |
('WARNING: the ''' , spec , ''' method is obsolete.') infoPrintCR. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3317 |
(' And may not be present in future ST/X versions.') infoPrintCR. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3318 |
(' called from ' , sender printString) infoPrintCR. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3319 |
(sender selector startsWith:'perform:') ifTrue:[ |
20535 | 3320 |
sender := sender sender. |
3321 |
(sender selector startsWith:'perform:') ifTrue:[ |
|
3322 |
sender := sender sender. |
|
3323 |
]. |
|
3324 |
(' called from ' , sender printString) infoPrintCR. |
|
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3325 |
]. |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3326 |
message notNil ifTrue:[ |
20535 | 3327 |
'------> ' infoPrint. message infoPrintCR |
16383 | 3328 |
]. |
3329 |
||
3330 |
"CG: care for standalone non-GUI progs, which have no userPreferences class" |
|
3331 |
(Smalltalk isInitialized |
|
3332 |
and:[ UserPreferences notNil |
|
3333 |
and:[ UserPreferences current haltInObsoleteMethod]]) ifTrue:[ |
|
20535 | 3334 |
"/ cg: nice try, stefan, but I don't want halts in system processes (fly by help and others) |
3335 |
Processor activeProcess isSystemProcess ifTrue:[ |
|
3336 |
(message , ' - please fix this now (no halt in system process)') infoPrintCR |
|
3337 |
] ifFalse:[ |
|
3338 |
"/ please check for the sender of the obsoleteMethodWarning, |
|
3339 |
"/ and fix the code there. |
|
3340 |
ObsoleteMethodCallWarning raiseRequestErrorString:(message , ' - please fix this now!!') |
|
3341 |
]. |
|
15716 | 3342 |
]. |
8829
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3343 |
|
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3344 |
" |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3345 |
Object obsoleteMethodWarning:'foo' from:thisContext sender sender |
9e640b6c0679
No obsolete messages in standalone apps
Stefan Vogel <sv@exept.de>
parents:
8827
diff
changeset
|
3346 |
" |
9509 | 3347 |
|
3348 |
"Modified: / 10-08-2006 / 13:13:11 / cg" |
|
10558 | 3349 |
! |
3350 |
||
12341 | 3351 |
todo |
21278 | 3352 |
"used to mark code pieces that have to be implemented. |
3353 |
Halts when reached in development mode; |
|
3354 |
ignored in deployed production code." |
|
12341 | 3355 |
|
3356 |
<resource: #skipInDebuggersWalkBack> |
|
3357 |
||
3358 |
self halt:'more work needed here'. |
|
3359 |
||
3360 |
" |
|
3361 |
example: |
|
3362 |
||
20535 | 3363 |
... |
3364 |
self todo. |
|
3365 |
... |
|
12341 | 3366 |
" |
3367 |
! |
|
3368 |
||
10558 | 3369 |
todo:aBlock |
21278 | 3370 |
"used to mark code pieces that have to be implemented. |
3371 |
The coe in aBlock is ignored." |
|
10558 | 3372 |
|
12341 | 3373 |
<resource: #skipInDebuggersWalkBack> |
3374 |
||
10558 | 3375 |
"/ self halt. |
3376 |
"/ aBlock value. |
|
3377 |
||
3378 |
" |
|
3379 |
example: |
|
3380 |
||
20535 | 3381 |
... |
3382 |
self todo:[ |
|
3383 |
code which needs more work ... |
|
3384 |
]. |
|
3385 |
... |
|
10558 | 3386 |
" |
3387 |
||
3388 |
"Created: / 25-05-2007 / 21:34:39 / cg" |
|
3389 |
"Modified: / 29-05-2007 / 12:11:33 / cg" |
|
15683 | 3390 |
! |
3391 |
||
3392 |
tracePoint:someKey |
|
3393 |
"{ Pragma: +optSpace }" |
|
3394 |
||
3395 |
"Like transcript show, but disabled by default. |
|
3396 |
Can be easily enabled. |
|
3397 |
Can be filtered on the arguments value (typically: a symbol). |
|
3398 |
Code with tracepoints may be even checked into the source repository" |
|
3399 |
||
3400 |
"Example: nil tracePoint:#stefan" |
|
3401 |
||
3402 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
20535 | 3403 |
^ Transcript showCR:('Tracepoint (at %1 for %3 from %2)' |
3404 |
bindWith:(Timestamp now printString) |
|
3405 |
with:(thisContext sender printString) |
|
3406 |
with:someKey) |
|
15683 | 3407 |
]. |
3408 |
||
3409 |
" |
|
3410 |
nil tracePoint:#stefan |
|
3411 |
nil tracePoint:#stefan message:'Hello' |
|
3412 |
Smalltalk enableBreakPoint:#stefan. |
|
3413 |
Smalltalk disableBreakPoint:#stefan. |
|
3414 |
" |
|
15723 | 3415 |
|
3416 |
"Modified: / 28-08-2013 / 21:41:54 / cg" |
|
15683 | 3417 |
! |
3418 |
||
15804 | 3419 |
tracePoint:someKey message:messageBlockOrString |
15683 | 3420 |
"{ Pragma: +optSpace }" |
3421 |
||
3422 |
"Like transcript show, but disabled by default. |
|
3423 |
Can be easily enabled. |
|
3424 |
Can be filtered on the arguments value (typically: a symbol). |
|
3425 |
Code with tracepoints may be even checked into the source repository" |
|
3426 |
||
3427 |
"Example: nil tracePoint:#stefan" |
|
3428 |
||
3429 |
(self isBreakPointEnabled:someKey) ifTrue:[ |
|
20535 | 3430 |
Transcript showCR:('Tracepoint: %4 (at %1 for %3 from %2)' |
3431 |
bindWith:(Timestamp now printString) |
|
3432 |
with:(thisContext sender printString) |
|
3433 |
with:someKey |
|
3434 |
with:messageBlockOrString value) |
|
15804 | 3435 |
]. |
3436 |
||
3437 |
" |
|
15683 | 3438 |
Smalltalk enableBreakPoint:#stefan. |
15804 | 3439 |
nil tracePoint:#stefan. |
3440 |
nil tracePoint:#stefan message:'Hello'. |
|
3441 |
nil tracePoint:#stefan message:['Hello from block']. |
|
15683 | 3442 |
Smalltalk disableBreakPoint:#stefan. |
3443 |
" |
|
15723 | 3444 |
|
3445 |
"Modified: / 28-08-2013 / 21:41:47 / cg" |
|
5755 | 3446 |
! ! |
3447 |
||
3448 |
!Object methodsFor:'dependents access'! |
|
3449 |
||
3450 |
addDependent:anObject |
|
3451 |
"make the argument, anObject be a dependent of the receiver" |
|
3452 |
||
3453 |
|wasBlocked| |
|
3454 |
||
3455 |
"/ must do this save from interrupts, since the dependents collection |
|
3456 |
"/ is possibly accessed from multiple threads. |
|
3457 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3458 |
"/ faster execution. |
|
3459 |
||
3460 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3461 |
[ |
|
20535 | 3462 |
|deps dep| |
3463 |
||
3464 |
deps := self dependents. |
|
3465 |
||
3466 |
"/ to save a fair amount of memory in case of |
|
3467 |
"/ many dependencies, we store a single dependent in |
|
3468 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3469 |
"/ added. |
|
3470 |
||
21646 | 3471 |
(deps isNil or:[deps isEmpty]) ifTrue:[ |
20535 | 3472 |
self dependents:(WeakArray with:anObject) |
3473 |
] ifFalse:[ |
|
3474 |
deps class == WeakArray ifTrue:[ |
|
3475 |
dep := deps at:1. |
|
3476 |
dep ~~ anObject ifTrue:[ |
|
3477 |
(dep isNil or:[dep class == SmallInteger]) ifTrue:[ |
|
3478 |
deps at:1 put:anObject |
|
3479 |
] ifFalse:[ |
|
3480 |
self dependents:(WeakIdentitySet with:dep with:anObject) |
|
3481 |
] |
|
3482 |
] |
|
3483 |
] ifFalse:[ |
|
3484 |
deps add:anObject |
|
3485 |
] |
|
3486 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3487 |
] ensure:[ |
20535 | 3488 |
wasBlocked ifFalse:[ |
3489 |
OperatingSystem unblockInterrupts |
|
3490 |
] |
|
5755 | 3491 |
] |
3492 |
||
21646 | 3493 |
"Modified: / 27-10-1997 / 19:35:52 / cg" |
3494 |
"Modified: / 15-03-2017 / 17:17:44 / stefan" |
|
5755 | 3495 |
! |
3496 |
||
3497 |
breakDependents |
|
3498 |
"remove all dependencies from the receiver" |
|
3499 |
||
3500 |
self dependents:nil. |
|
3501 |
self nonWeakDependents:nil |
|
3502 |
||
3503 |
"Modified: / 19.4.1996 / 10:55:36 / cg" |
|
3504 |
"Created: / 27.2.1998 / 11:26:11 / stefan" |
|
3505 |
! |
|
3506 |
||
8542 | 3507 |
breakDependentsRecursively |
10460 | 3508 |
"remove all dependencies from the receiver and |
8542 | 3509 |
recursively from all objects referred to by the receiver." |
3510 |
||
3511 |
self breakDependents. |
|
10460 | 3512 |
1 to:self class instSize do:[:idx | |
20535 | 3513 |
(self instVarAt:idx) breakDependentsRecursively. |
10460 | 3514 |
]. |
3515 |
1 to:self basicSize do:[:idx | |
|
20535 | 3516 |
(self basicAt:idx) breakDependentsRecursively. |
8542 | 3517 |
] |
3518 |
! |
|
3519 |
||
5755 | 3520 |
dependents |
3521 |
"return a Collection of dependents. |
|
3522 |
The default implementation here uses a global WeakDictionary to store |
|
10460 | 3523 |
dependents |
5755 | 3524 |
This may be too slow for high frequency change&update, |
3525 |
therefore, some classes (Model) redefine this for better performance. |
|
3526 |
Notice the mentioning of a WeakDictionary - read the classes documentation." |
|
3527 |
||
3528 |
|deps| |
|
3529 |
||
3530 |
(deps := Dependencies at:self ifAbsent:nil) isNil ifTrue:[ |
|
20535 | 3531 |
^ #(). |
5755 | 3532 |
]. |
3533 |
^ deps |
|
3534 |
||
3535 |
"Modified: / 26.1.1998 / 11:18:15 / cg" |
|
3536 |
! |
|
3537 |
||
3538 |
dependents:aCollection |
|
3539 |
"set the collection of dependents. |
|
3540 |
The default implementation here uses a global Dictionary to store |
|
3541 |
dependents which may be too slow for high frequency change&update. |
|
3542 |
Therefore, some classes (Model) redefine this for better performance." |
|
3543 |
||
3544 |
"/ must do this save from interrupts, since the dependents collection |
|
3545 |
"/ is possibly accessed from multiple threads. |
|
3546 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3547 |
"/ faster execution (and to avoid creation of garbage blocks). |
|
3548 |
||
3549 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
20535 | 3550 |
"/ the common case - already blocked |
3551 |
||
3552 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
|
3553 |
Dependencies removeKey:self ifAbsent:nil |
|
3554 |
] ifFalse:[ |
|
3555 |
Dependencies at:self put:aCollection |
|
3556 |
]. |
|
3557 |
^ self |
|
5755 | 3558 |
]. |
3559 |
||
3560 |
[ |
|
20535 | 3561 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3562 |
Dependencies removeKey:self ifAbsent:nil |
|
3563 |
] ifFalse:[ |
|
3564 |
Dependencies at:self put:aCollection |
|
3565 |
]. |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3566 |
] ensure:[ |
20535 | 3567 |
OperatingSystem unblockInterrupts |
5755 | 3568 |
] |
3569 |
||
3570 |
"Modified: 30.1.1997 / 21:22:10 / cg" |
|
3571 |
! |
|
3572 |
||
3573 |
dependentsDo:aBlock |
|
3574 |
"evaluate aBlock for all of my dependents" |
|
3575 |
||
3576 |
|deps nwDeps| |
|
3577 |
||
3578 |
deps := self dependents. |
|
21646 | 3579 |
deps notNil ifTrue:[ |
20535 | 3580 |
deps do:[:d | |
3581 |
(d notNil and:[d class ~~ SmallInteger]) ifTrue:[ |
|
3582 |
aBlock value:d |
|
3583 |
] |
|
3584 |
] |
|
5755 | 3585 |
]. |
3586 |
nwDeps := self nonWeakDependents. |
|
21646 | 3587 |
(nwDeps ~~ deps and:[nwDeps notNil]) ifTrue:[ |
20535 | 3588 |
nwDeps do:aBlock |
5755 | 3589 |
]. |
3590 |
||
21646 | 3591 |
"Modified: / 30-01-1998 / 14:03:40 / cg" |
3592 |
"Modified: / 15-03-2017 / 17:15:09 / stefan" |
|
5755 | 3593 |
! |
3594 |
||
3595 |
myDependents |
|
3596 |
"same as dependents - ST-80 compatibility" |
|
3597 |
||
3598 |
^ self dependents |
|
3599 |
! |
|
3600 |
||
3601 |
release |
|
3602 |
"remove all references to objects that may refer to self. |
|
3603 |
Subclasses may redefine this method but should do a 'super release'." |
|
3604 |
||
21382 | 3605 |
<modifier: #super> "must be called if redefined" |
3606 |
||
5755 | 3607 |
self breakDependents |
3608 |
||
21382 | 3609 |
"Modified: / 27-02-1998 / 11:29:35 / stefan" |
3610 |
"Modified: / 08-02-2017 / 00:23:42 / cg" |
|
5755 | 3611 |
! |
3612 |
||
3613 |
removeDependent:anObject |
|
3614 |
"make the argument, anObject be independent of the receiver" |
|
3615 |
||
3616 |
|wasBlocked| |
|
3617 |
||
3618 |
"/ must do this save from interrupts, since the dependents collection |
|
3619 |
"/ is possibly accessed from multiple threads. |
|
3620 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3621 |
"/ faster execution. |
|
3622 |
||
3623 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3624 |
[ |
|
20954 | 3625 |
|deps n dep| |
20535 | 3626 |
|
3627 |
deps := self dependents. |
|
21646 | 3628 |
deps notEmptyOrNil ifTrue:[ |
20535 | 3629 |
"/ to save a fair amount of memory in case of |
3630 |
"/ many dependencies, we store a single dependent in |
|
3631 |
"/ a WeakArray, and switch to a WeakSet if more dependents are |
|
3632 |
"/ added. Here we have to do the inverse ... |
|
3633 |
||
3634 |
((deps class == WeakArray) or:[deps class == Array]) ifTrue:[ |
|
20954 | 3635 |
((dep := deps at:1) == anObject |
21646 | 3636 |
or:[dep isNil |
3637 |
or:[dep class == SmallInteger]]) ifTrue:[ |
|
20535 | 3638 |
self dependents:nil |
3639 |
] |
|
3640 |
] ifFalse:[ |
|
20954 | 3641 |
dep := deps remove:anObject ifAbsent:[]. |
3642 |
"if dep is nil, nothing has changed" |
|
3643 |
dep notNil ifTrue:[ |
|
3644 |
(n := deps size) == 0 ifTrue:[ |
|
3645 |
self dependents:nil |
|
3646 |
] ifFalse:[ |
|
3647 |
n == 1 ifTrue:[ |
|
3648 |
dep := deps firstIfEmpty:nil. |
|
3649 |
dep notNil ifTrue:[ |
|
3650 |
deps := (deps isWeakCollection ifTrue:[WeakArray] ifFalse:[Array]) with:dep |
|
3651 |
] ifFalse:[ |
|
3652 |
deps := nil |
|
3653 |
]. |
|
3654 |
self dependents:deps. |
|
3655 |
] |
|
3656 |
]. |
|
3657 |
]. |
|
20535 | 3658 |
] |
3659 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3660 |
] ensure:[ |
20535 | 3661 |
wasBlocked ifFalse:[ |
3662 |
OperatingSystem unblockInterrupts |
|
3663 |
] |
|
5755 | 3664 |
] |
3665 |
||
13500 | 3666 |
"Modified: / 05-07-2011 / 22:49:31 / cg" |
21646 | 3667 |
"Modified (format): / 15-03-2017 / 17:20:23 / stefan" |
5755 | 3668 |
! ! |
3669 |
||
7266 | 3670 |
!Object methodsFor:'dependents access (non weak)'! |
5755 | 3671 |
|
3672 |
addNonWeakDependent:anObject |
|
3673 |
"make the argument, anObject be a nonWeak dependent of the receiver. |
|
10460 | 3674 |
Be careful: this nonWeakDependency will prevent the dependent from being |
5755 | 3675 |
garbage collected unless the dependency is removed. |
3676 |
This is a private mechanism, for directed dependencies." |
|
3677 |
||
3678 |
|wasBlocked| |
|
3679 |
||
3680 |
"/ must do this save from interrupts, since the dependents collection |
|
3681 |
"/ is possibly accessed from multiple threads. |
|
3682 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3683 |
"/ faster execution. |
|
3684 |
||
3685 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3686 |
[ |
|
20535 | 3687 |
|deps dep| |
3688 |
||
3689 |
deps := self nonWeakDependents. |
|
3690 |
||
3691 |
"/ to save a fair amount of memory in case of |
|
3692 |
"/ many dependencies, we store a single dependent in |
|
3693 |
"/ an Array, and switch to a Set if more dependents are |
|
3694 |
"/ added. |
|
3695 |
||
21646 | 3696 |
deps isEmptyOrNil ifTrue:[ |
20535 | 3697 |
anObject notNil ifTrue:[ |
3698 |
self nonWeakDependents:(Array with:anObject). |
|
3699 |
] ifFalse:[ |
|
3700 |
"adding nil causes problems when adding the next one |
|
3701 |
(see below: trying to add nil to IdentitySet)" |
|
9442 | 3702 |
"/ self halt:'try to add nil to list of dependents'. |
20535 | 3703 |
]. |
3704 |
] ifFalse:[ |
|
3705 |
deps class == Array ifTrue:[ |
|
3706 |
dep := deps at:1. |
|
3707 |
dep ~~ anObject ifTrue:[ |
|
3708 |
self nonWeakDependents:(IdentitySet with:dep with:anObject) |
|
3709 |
] |
|
3710 |
] ifFalse:[ |
|
3711 |
deps add:anObject |
|
3712 |
] |
|
3713 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3714 |
] ensure:[ |
20535 | 3715 |
wasBlocked ifFalse:[ |
3716 |
OperatingSystem unblockInterrupts |
|
3717 |
] |
|
5755 | 3718 |
] |
3719 |
||
21646 | 3720 |
"Created: / 19-04-1996 / 10:54:08 / cg" |
3721 |
"Modified: / 30-01-1998 / 14:03:08 / cg" |
|
3722 |
"Modified: / 15-03-2017 / 17:18:11 / stefan" |
|
5755 | 3723 |
! |
3724 |
||
3725 |
nonWeakDependents |
|
3726 |
"return a Collection of nonWeakDependents - empty if there is none. |
|
3727 |
This is a private mechanism for directed dependencies." |
|
3728 |
||
3729 |
NonWeakDependencies isNil ifTrue:[^ #()]. |
|
3730 |
^ NonWeakDependencies at:self ifAbsent:#() |
|
3731 |
||
3732 |
"Created: / 19.4.1996 / 10:55:06 / cg" |
|
3733 |
"Modified: / 30.1.1998 / 14:06:47 / cg" |
|
3734 |
! |
|
3735 |
||
3736 |
nonWeakDependents:aCollection |
|
3737 |
"set the collection of nonWeak dependents. |
|
3738 |
This is a private helper for directed dependencies." |
|
3739 |
||
3740 |
[ |
|
20535 | 3741 |
(aCollection isNil or:[aCollection isEmpty]) ifTrue:[ |
3742 |
NonWeakDependencies removeKey:self ifAbsent:nil |
|
3743 |
] ifFalse:[ |
|
3744 |
NonWeakDependencies at:self put:aCollection |
|
3745 |
] |
|
5755 | 3746 |
] valueUninterruptably |
3747 |
||
3748 |
"Created: 19.4.1996 / 11:07:47 / cg" |
|
3749 |
! |
|
3750 |
||
3751 |
removeNonWeakDependent:anObject |
|
3752 |
"remove a nonWeak dependency from the receiver to the argument, anObject. |
|
3753 |
(i.e. make it independent of the receiver)" |
|
3754 |
||
3755 |
|wasBlocked| |
|
3756 |
||
3757 |
"/ must do this save from interrupts, since the dependents collection |
|
3758 |
"/ is possibly accessed from multiple threads. |
|
3759 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
|
3760 |
"/ faster execution. |
|
3761 |
||
3762 |
wasBlocked := OperatingSystem blockInterrupts. |
|
3763 |
[ |
|
20535 | 3764 |
|deps n| |
3765 |
||
3766 |
deps := self nonWeakDependents. |
|
21646 | 3767 |
deps notEmptyOrNil ifTrue:[ |
20535 | 3768 |
deps class == Array ifTrue:[ |
3769 |
(deps at:1) == anObject ifTrue:[ |
|
3770 |
self nonWeakDependents:nil |
|
3771 |
] |
|
3772 |
] ifFalse:[ |
|
3773 |
deps remove:anObject ifAbsent:[]. |
|
3774 |
(n := deps size) == 0 ifTrue:[ |
|
3775 |
self nonWeakDependents:nil |
|
3776 |
] ifFalse:[ |
|
3777 |
n == 1 ifTrue:[ |
|
3778 |
self nonWeakDependents:(Array with:(deps first)) |
|
3779 |
] |
|
3780 |
] |
|
3781 |
] |
|
3782 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6418
diff
changeset
|
3783 |
] ensure:[ |
20535 | 3784 |
wasBlocked ifFalse:[ |
3785 |
OperatingSystem unblockInterrupts |
|
3786 |
] |
|
5755 | 3787 |
] |
3788 |
||
21646 | 3789 |
"Created: / 19-04-1996 / 11:44:44 / cg" |
3790 |
"Modified: / 30-01-1998 / 14:04:01 / cg" |
|
3791 |
"Modified: / 15-03-2017 / 17:19:38 / stefan" |
|
5755 | 3792 |
! ! |
3793 |
||
9279 | 3794 |
|
3795 |
||
5755 | 3796 |
!Object methodsFor:'displaying'! |
3797 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3798 |
ascentOn:aGC |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3799 |
"when displayed via displayOn:, some objects assume that the given y coordinate |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3800 |
is the baseline (strings, text etc. do), while others assume that the topY |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3801 |
coordinate is given by y. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3802 |
In other words: some draw above the given y coordinate. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3803 |
This method returns the number of pixels by which the receiver will draw above |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3804 |
the given y coordinate." |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3805 |
|
11065
17c01b01000f
Simplify (and speed up) #ascentOn:
Stefan Vogel <sv@exept.de>
parents:
11048
diff
changeset
|
3806 |
^ aGC fontAscent |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3807 |
! |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3808 |
|
6900 | 3809 |
displayOn:aGCOrStream |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3810 |
"Compatibility |
21525 | 3811 |
append a printed desription on some stream (Dolphin, Squeak) |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3812 |
OR: |
21525 | 3813 |
display the receiver in a graphicsContext at 0@0 (ST80). |
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3814 |
This method allows for any object to be displayed in some view |
5755 | 3815 |
(although the fallBack is to display its printString ...)" |
3816 |
||
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3817 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
21528 | 3818 |
"/ old ST80 means: draw-yourself on a GC. |
14292
1cbc2d35aa17
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14272
diff
changeset
|
3819 |
aGCOrStream isStream ifTrue:[ |
20535 | 3820 |
self printOn:aGCOrStream. |
3821 |
^ self |
|
6900 | 3822 |
]. |
21528 | 3823 |
self obsoleteFeatureWarning:'displayOn: should not be used to display objects in a GC'. |
6900 | 3824 |
^ self displayOn:aGCOrStream x:0 y:0. |
5755 | 3825 |
|
21525 | 3826 |
"Created: / 29-05-1996 / 16:28:58 / cg" |
21528 | 3827 |
"Modified (format): / 22-02-2017 / 17:03:14 / cg" |
5755 | 3828 |
! |
3829 |
||
3830 |
displayOn:aGC at:aPoint |
|
3831 |
"ST-80 Compatibility |
|
3832 |
display the receiver in a graphicsContext - this method allows |
|
3833 |
for any object to be displayed in a ListView - for example." |
|
3834 |
||
3835 |
^ self displayOn:aGC x:(aPoint x) y:(aPoint y). |
|
3836 |
! |
|
3837 |
||
3838 |
displayOn:aGC x:x y:y |
|
3839 |
"display the receiver in a graphicsContext - this method allows |
|
3840 |
for any object to be displayed in a ListView - for example." |
|
3841 |
||
3842 |
self displayOn:aGC x:x y:y opaque:false |
|
3843 |
||
3844 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3845 |
! |
|
3846 |
||
3847 |
displayOn:aGc x:x y:y opaque:opaque |
|
3848 |
"display the receiver in a graphicsContext - this method allows |
|
3849 |
for any object to be displayed in a ListView - for example. |
|
19451 | 3850 |
The fallBack here shows the receiver's displayString. |
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3851 |
Notice, that the string is displayed on the baseLine; |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3852 |
ask using #ascentOn: if required" |
5755 | 3853 |
|
3854 |
|s yBaseline| |
|
3855 |
||
15368 | 3856 |
s := self isString ifTrue:[self] ifFalse:[self displayString]. |
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
3857 |
yBaseline := y "+ aGc font ascent". |
5755 | 3858 |
opaque ifTrue:[ |
20535 | 3859 |
aGc displayOpaqueString:s x:x y:yBaseline. |
5755 | 3860 |
] ifFalse:[ |
20535 | 3861 |
aGc displayString:s x:x y:yBaseline. |
5755 | 3862 |
]. |
3863 |
||
3864 |
"Modified: 29.5.1996 / 16:29:38 / cg" |
|
3865 |
! |
|
3866 |
||
3867 |
displayOpaqueOn:aGC x:x y:y |
|
3868 |
"display the receiver in a graphicsContext - this method allows |
|
3869 |
for any object to be displayed in a ListView - for example." |
|
3870 |
||
3871 |
self displayOn:aGC x:x y:y opaque:true |
|
3872 |
||
3873 |
"Modified: / 29.5.1996 / 16:29:38 / cg" |
|
3874 |
"Created: / 26.10.1997 / 15:01:36 / cg" |
|
3875 |
! |
|
3876 |
||
3877 |
displayString |
|
3878 |
"return a string used when displaying the receiver in a view; |
|
3879 |
for example an Inspector. This is usually the same as printString, |
|
14292
1cbc2d35aa17
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14272
diff
changeset
|
3880 |
but sometimes redefined for a better look. |
1cbc2d35aa17
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14272
diff
changeset
|
3881 |
|
1cbc2d35aa17
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14272
diff
changeset
|
3882 |
Note: the base method (used by the inspector) is #displayOn:. |
20535 | 3883 |
So you should implement #displayOn: instead of #displayString in subclasses." |
5755 | 3884 |
|
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3885 |
|s| |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3886 |
|
15942
a76da2251215
handle weak objects (with instances or non-WeakArray)
Claus Gittinger <cg@exept.de>
parents:
15932
diff
changeset
|
3887 |
"/ attention: TextStream is not present in ultra-mini standalone apps |
15932
61bf45ec26c9
fixed displayString for systems without libbasic2
Claus Gittinger <cg@exept.de>
parents:
15931
diff
changeset
|
3888 |
s := TextStream isNil |
20535 | 3889 |
ifTrue:['' writeStream] |
3890 |
ifFalse:[TextStream on:(String new:32)]. |
|
7081
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3891 |
self displayOn:s. |
4e1ae4a0b3c1
added ascentOn: (display-ascent);
Claus Gittinger <cg@exept.de>
parents:
7048
diff
changeset
|
3892 |
^ s contents |
5755 | 3893 |
|
3894 |
" |
|
10460 | 3895 |
#(1 2 3) printString |
3896 |
#(1 2 3) displayString |
|
5755 | 3897 |
#(1 2 3) storeString |
3898 |
" |
|
3899 |
! |
|
3900 |
||
3901 |
heightOn:aGC |
|
3902 |
"return the height of the receiver, if it is to be displayed on aGC" |
|
3903 |
||
20222 | 3904 |
^ aGC deviceFont heightOf:(self displayString) |
5755 | 3905 |
! |
3906 |
||
16010 | 3907 |
printStringForPrintIt |
3908 |
"for compatibility (used to be displayString), now the printIt menu function now sends this message" |
|
3909 |
||
3910 |
^ self displayString |
|
3911 |
||
3912 |
" |
|
3913 |
#(1 2 3) printString |
|
3914 |
#(1 2 3) printStringForPrintIt |
|
3915 |
#(1 2 3) storeString |
|
3916 |
" |
|
3917 |
! |
|
3918 |
||
6654 | 3919 |
widthFrom:startIndex to:endIndex on:aGC |
3920 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3921 |
||
20222 | 3922 |
^ aGC deviceFont widthOf:(self displayString) from:startIndex to:endIndex |
6654 | 3923 |
! |
3924 |
||
5755 | 3925 |
widthOn:aGC |
3926 |
"return the width of the receiver, if it is to be displayed on aGC" |
|
3927 |
||
20222 | 3928 |
^ aGC deviceFont widthOf:(self displayString) |
5755 | 3929 |
! ! |
3930 |
||
7359 | 3931 |
!Object methodsFor:'double dispatching'! |
3932 |
||
3933 |
equalFromComplex:aComplex |
|
3934 |
"adding this method here allows for any non-number to be compared to a complex |
|
3935 |
and return false from this comparison. |
|
3936 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3937 |
which uses #= (i.e. a Set or Dictionary)." |
|
3938 |
||
3939 |
^ false |
|
3940 |
! |
|
3941 |
||
3942 |
equalFromFixedPoint:aFixedPoint |
|
3943 |
"adding this method here allows for any non-number to be compared to a fixedPoint |
|
3944 |
and return false from this comparison. |
|
3945 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3946 |
which uses #= (i.e. a Set or Dictionary)." |
|
3947 |
||
3948 |
^ false |
|
3949 |
! |
|
3950 |
||
3951 |
equalFromFloat:aFloat |
|
3952 |
"adding this method here allows for any non-number to be compared to a float |
|
3953 |
and return false from this comparison. |
|
3954 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3955 |
which uses #= (i.e. a Set or Dictionary)." |
|
3956 |
||
3957 |
^ false |
|
3958 |
! |
|
3959 |
||
3960 |
equalFromFraction:aFraction |
|
3961 |
"adding this method here allows for any non-number to be compared to a fraction |
|
3962 |
and return false from this comparison. |
|
3963 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3964 |
which uses #= (i.e. a Set or Dictionary)." |
|
3965 |
||
3966 |
^ false |
|
3967 |
! |
|
3968 |
||
3969 |
equalFromInteger:anInteger |
|
3970 |
"adding this method here allows for any non-number to be compared to an integer |
|
3971 |
and return false from this comparison. |
|
3972 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3973 |
which uses #= (i.e. a Set or Dictionary)." |
|
3974 |
||
3975 |
^ false |
|
3976 |
! |
|
3977 |
||
7455 | 3978 |
equalFromLargeFloat:aLargeFloat |
3979 |
"adding this method here allows for any non-number to be compared to a largeFloat |
|
3980 |
and return false from this comparison. |
|
3981 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3982 |
which uses #= (i.e. a Set or Dictionary)." |
|
3983 |
||
3984 |
^ false |
|
3985 |
! |
|
3986 |
||
7359 | 3987 |
equalFromLongFloat:aLongFloat |
3988 |
"adding this method here allows for any non-number to be compared to a longFloat |
|
3989 |
and return false from this comparison. |
|
3990 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
3991 |
which uses #= (i.e. a Set or Dictionary)." |
|
3992 |
||
3993 |
^ false |
|
3994 |
! |
|
3995 |
||
3996 |
equalFromShortFloat:aShortFloat |
|
3997 |
"adding this method here allows for any non-number to be compared to a shortFloat |
|
3998 |
and return false from this comparison. |
|
3999 |
Reason: we want to be able to put both numbers and non-numbers into a collection |
|
4000 |
which uses #= (i.e. a Set or Dictionary)." |
|
4001 |
||
4002 |
^ false |
|
4003 |
! ! |
|
4004 |
||
5755 | 4005 |
!Object methodsFor:'encoding & decoding'! |
4006 |
||
4007 |
decodeAsLiteralArray |
|
8832 | 4008 |
"given a literalEncoding in the receiver, |
4009 |
create & return the corresponding object. |
|
4010 |
The inverse operation to #literalArrayEncoding." |
|
4011 |
||
5755 | 4012 |
^ self |
4013 |
! |
|
4014 |
||
4015 |
encodeOn:anEncoder with:aParameter |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4016 |
"not used any longer. Kept for backward comaptibility" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4017 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4018 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4019 |
|
8404 | 4020 |
self acceptVisitor:anEncoder with:aParameter |
6718 | 4021 |
! |
4022 |
||
4023 |
encodingVectorForInstanceVariables |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4024 |
"OBSOLETE, use elementDescriptorForInstanceVariables" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4025 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4026 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4027 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4028 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | true]. |
6718 | 4029 |
|
4030 |
" |
|
4031 |
#(1 2 3 nil true symbol) encodingVectorForInstanceVariables |
|
4032 |
Dictionary new encodingVectorForInstanceVariables |
|
4033 |
(5 @ nil) encodingVectorForInstanceVariables |
|
4034 |
" |
|
4035 |
! |
|
4036 |
||
4037 |
encodingVectorForNonNilInstanceVariables |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4038 |
"OBSOLETE, use elementDescriptorForNonNilInstanceVariables" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4039 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4040 |
<resource: #obsolete> |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4041 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4042 |
^ self elementDescriptorForInstanceVariablesMatching:[:varVal | varVal notNil]. |
6718 | 4043 |
|
4044 |
" |
|
4045 |
#(1 2 3 nil true symbol) encodingVectorForNonNilInstanceVariables |
|
4046 |
(5 @ nil) encodingVectorForNonNilInstanceVariables |
|
4047 |
" |
|
4048 |
! |
|
4049 |
||
5755 | 4050 |
fromLiteralArrayEncoding:aSpecArray |
8798 | 4051 |
"read my attributes from aSpecArray. |
4052 |
Recursively decodes arguments." |
|
4053 |
||
19802 | 4054 |
|sel litVal val msg ex |
5755 | 4055 |
stop "{ Class:SmallInteger }" | |
4056 |
||
4057 |
stop := aSpecArray size. |
|
4058 |
||
4059 |
2 to:stop by:2 do:[:i| |
|
20535 | 4060 |
sel := aSpecArray at:i. |
4061 |
litVal := aSpecArray at:i + 1. |
|
4062 |
||
4063 |
(self respondsTo:sel) ifTrue:[ |
|
4064 |
val := litVal decodeAsLiteralArray. |
|
4065 |
self perform:sel with:val |
|
4066 |
] ifFalse:[ |
|
4067 |
"/ that's a debug halt, |
|
4068 |
"/ it should probably be removed (to simply ignore unhandled attributes)... |
|
4069 |
"/ for now, it is left in, in order to easily find incompatibilities between |
|
4070 |
"/ VW and ST/X. |
|
4071 |
self breakPoint:#cg. |
|
4072 |
||
4073 |
msg := '%1: unhandled literalArrayEncoding attribute:' |
|
4074 |
bindWith:self class name |
|
4075 |
with:sel. |
|
4076 |
UnhandledAttributeInLiteralArrayErrorSignal isHandled ifTrue:[ |
|
4077 |
ex := UnhandledAttributeInLiteralArrayErrorSignal new. |
|
4078 |
ex badLiteralArray:self. |
|
4079 |
ex parameter:sel. |
|
4080 |
ex notify:msg. |
|
4081 |
] ifFalse:[ |
|
4082 |
msg infoPrintCR. |
|
4083 |
]. |
|
4084 |
] |
|
5755 | 4085 |
] |
4086 |
! |
|
4087 |
||
4088 |
literalArrayEncoding |
|
4089 |
"generate a literalArrayEncoding array for myself. |
|
4090 |
This uses #literalArrayEncodingSlotOrder which defines the slots and |
|
4091 |
order and #skippedInLiteralEncoding which defines slots to skip. |
|
4092 |
For most subclasses, there is no need to redefine those." |
|
4093 |
||
8832 | 4094 |
|names encoding cls skipped slots| |
5755 | 4095 |
|
4096 |
self isLiteral ifTrue:[ |
|
20535 | 4097 |
^ self |
5755 | 4098 |
]. |
4099 |
||
8832 | 4100 |
slots := self literalArrayEncodingSlotOrder. |
5755 | 4101 |
skipped := self skippedInLiteralEncoding. |
4102 |
cls := self class. |
|
4103 |
names := cls allInstVarNames. |
|
8832 | 4104 |
encoding := OrderedCollection new:(1 + (2 * (slots size - skipped size))). |
8839
c4471cb2799f
stefan: bitte vor Einchecken Testen !
Claus Gittinger <cg@exept.de>
parents:
8833
diff
changeset
|
4105 |
encoding add:cls name. |
8832 | 4106 |
|
4107 |
slots do:[:instSlot | |
|
20535 | 4108 |
|value nm| |
4109 |
||
4110 |
nm := names at:instSlot. |
|
4111 |
(skipped includes:nm) ifFalse:[ |
|
4112 |
(value := self instVarAt:instSlot) notNil ifTrue:[ |
|
4113 |
encoding add:(nm asMutator). |
|
4114 |
encoding add:value literalArrayEncoding |
|
4115 |
] |
|
4116 |
] |
|
5755 | 4117 |
]. |
4118 |
^ encoding asArray |
|
8841 | 4119 |
|
4120 |
" |
|
20535 | 4121 |
(1 -> 2) literalArrayEncoding |
4122 |
DebugView menuSpec decodeAsLiteralArray literalArrayEncoding = |
|
4123 |
DebugView menuSpec |
|
8841 | 4124 |
" |
5755 | 4125 |
! |
4126 |
||
4127 |
literalArrayEncodingSlotOrder |
|
4128 |
"define the order in which inst-slots are saved when generating |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4129 |
a literalArrayEncoding" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4130 |
|
5755 | 4131 |
^ 1 to:self class instSize |
4132 |
! |
|
4133 |
||
7112 | 4134 |
postDecodeFrom:aDecoder aspect:aspectSymbol |
4135 |
"invoked by xmlDecoder (and others in the future), after an |
|
4136 |
object has been decoded (i.e. its instance variables have been restored)" |
|
4137 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4138 |
^ self |
7112 | 4139 |
! |
4140 |
||
5755 | 4141 |
skippedInLiteralEncoding |
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4142 |
"return a Collection with it's elements are slots for skipping" |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
4143 |
|
5755 | 4144 |
^ #() |
4145 |
! ! |
|
4146 |
||
4147 |
!Object methodsFor:'error handling'! |
|
4148 |
||
16012 | 4149 |
abortOperation |
4150 |
"{ Pragma: +optSpace }" |
|
4151 |
||
4152 |
"raise the AbortOperationRequest signal. |
|
4153 |
This will unwind and bring the current thread back to the event-handling loop, |
|
4154 |
effectively aborting any current menu, user, doIt, printIt or other operation." |
|
4155 |
||
4156 |
<resource: #skipInDebuggersWalkBack> |
|
4157 |
||
4158 |
^ AbortOperationRequest raise |
|
4159 |
! |
|
4160 |
||
13416 | 4161 |
ambiguousMessage:aMessage |
4162 |
"this message is sent by the system in case that it |
|
4163 |
is not clear which method to execute in response to |
|
14632 | 4164 |
aMessage. |
13416 | 4165 |
Such situation may occur when a current selector namespace |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4166 |
imports two namespaces and both define a method with the |
13416 | 4167 |
requested selector." |
4168 |
||
4169 |
<context: #return> |
|
4170 |
<resource: #skipInDebuggersWalkBack> |
|
4171 |
||
4172 |
^ AmbiguousMessage raiseRequestWith:aMessage |
|
4173 |
||
4174 |
"Created: / 21-07-2010 / 15:44:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4175 |
"Modified (comment): / 02-11-2012 / 10:14:42 / cg" |
13416 | 4176 |
! |
4177 |
||
5755 | 4178 |
cannotSendMessage:aMessage to:someReceiver |
4179 |
"this message is sent by the runtime system (VM), |
|
4180 |
when a message is sent to some object, whose class is not |
|
4181 |
a valid behavior (see documentation in Behavior)." |
|
4182 |
||
11021 | 4183 |
<resource: #skipInDebuggersWalkBack> |
4184 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4185 |
^ VMInternalError |
20535 | 4186 |
raiseWith:someReceiver |
4187 |
errorString:('bad class in send of #' , aMessage selector) |
|
5755 | 4188 |
|
4189 |
"Modified: 23.1.1997 / 00:05:39 / cg" |
|
4190 |
! |
|
4191 |
||
11132
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4192 |
conversionErrorSignal |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4193 |
"return the signal used for conversion error handling" |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4194 |
|
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4195 |
^ self class conversionErrorSignal |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4196 |
! |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4197 |
|
5755 | 4198 |
doesNotUnderstand:aMessage |
4199 |
"this message is sent by the runtime system (VM) when |
|
4200 |
a message is not understood by some object (i.e. there |
|
4201 |
is no method for that selector). The original message has |
|
4202 |
been packed into aMessage (i.e. the receiver, selector and |
|
4203 |
any arguments) and the original receiver is then sent the |
|
4204 |
#doesNotUnderstand: message. |
|
4205 |
Here, we raise another signal which usually enters the debugger. |
|
4206 |
You can of course redefine #doesNotUnderstand: in your classes |
|
10460 | 4207 |
to implement message delegation, |
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
8481
diff
changeset
|
4208 |
or handle the MessageNotUnderstood exception gracefully." |
5755 | 4209 |
|
4210 |
<context: #return> |
|
11021 | 4211 |
<resource: #skipInDebuggersWalkBack> |
5755 | 4212 |
|
8500
10d47cede03c
Speed up MessageNotUnderstood exception sending by layz computation
Stefan Vogel <sv@exept.de>
parents:
8481
diff
changeset
|
4213 |
^ MessageNotUnderstood raiseRequestWith:aMessage |
5755 | 4214 |
! |
4215 |
||
4216 |
elementBoundsError |
|
4217 |
"{ Pragma: +optSpace }" |
|
4218 |
||
10460 | 4219 |
"report an error that badElement is out of bounds |
5755 | 4220 |
(i.e. cannot be put into that collection). |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4221 |
The error is reported by raising the ElementBoundsError exception." |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4222 |
|
11021 | 4223 |
<resource: #skipInDebuggersWalkBack> |
4224 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4225 |
^ ElementBoundsError raise |
5755 | 4226 |
|
4227 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
|
4228 |
! |
|
4229 |
||
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4230 |
elementBoundsError:aValue |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4231 |
"{ Pragma: +optSpace }" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4232 |
|
10460 | 4233 |
"report an error that aValue is not valid as element |
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4234 |
(i.e. cannot be put into that collection). |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4235 |
The error is reported by raising the ElementBoundsError exception." |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4236 |
|
11021 | 4237 |
<resource: #skipInDebuggersWalkBack> |
4238 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4239 |
^ ElementBoundsError raiseWith:aValue |
7215
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4240 |
|
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4241 |
"Modified: 8.5.1996 / 09:12:45 / cg" |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4242 |
! |
733294e1a8cc
correct use of ascentOn: for display
Claus Gittinger <cg@exept.de>
parents:
7211
diff
changeset
|
4243 |
|
5755 | 4244 |
elementNotCharacter |
4245 |
"{ Pragma: +optSpace }" |
|
4246 |
||
4247 |
"report an error that object to be stored is no Character. |
|
4248 |
(usually when storing into Strings). |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4249 |
The error is reported by raising the ElementBoundsError exception." |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4250 |
|
11021 | 4251 |
<resource: #skipInDebuggersWalkBack> |
4252 |
||
21375 | 4253 |
^ ElementBoundsError raiseErrorString:' - element must be a character' |
4254 |
||
4255 |
"Modified: / 08-05-1996 / 09:12:49 / cg" |
|
4256 |
"Modified: / 07-02-2017 / 20:09:42 / stefan" |
|
5755 | 4257 |
! |
4258 |
||
4259 |
elementNotInteger |
|
4260 |
"{ Pragma: +optSpace }" |
|
4261 |
||
4262 |
"report an error that object to be stored is not Integer. |
|
4263 |
(in collections that store integers only). |
|
4264 |
The error is reported by raising the ElementOutOfBoundsSignal exception." |
|
4265 |
||
11021 | 4266 |
<resource: #skipInDebuggersWalkBack> |
4267 |
||
21375 | 4268 |
^ ElementBoundsError raiseErrorString:' - element must be an integer' |
4269 |
||
4270 |
"Modified: / 08-05-1996 / 09:12:51 / cg" |
|
4271 |
"Modified: / 07-02-2017 / 20:09:58 / stefan" |
|
5755 | 4272 |
! |
4273 |
||
4274 |
error |
|
4275 |
"{ Pragma: +optSpace }" |
|
4276 |
||
20253 | 4277 |
"report error that an error occurred. |
5755 | 4278 |
The error is reported by raising the Error exception, |
4279 |
which is non-proceedable. |
|
4280 |
If no handler has been setup, a debugger is entered." |
|
4281 |
||
11021 | 4282 |
<context: #return> |
4283 |
<resource: #skipInDebuggersWalkBack> |
|
4284 |
||
5755 | 4285 |
Error raiseWith:#error: |
4286 |
||
4287 |
" |
|
4288 |
nil error |
|
4289 |
" |
|
4290 |
||
4291 |
"Modified: / 8.5.1996 / 09:13:01 / cg" |
|
4292 |
"Modified: / 2.8.1999 / 17:00:19 / stefan" |
|
4293 |
! |
|
4294 |
||
4295 |
error:aString |
|
4296 |
"{ Pragma: +optSpace }" |
|
4297 |
||
4298 |
"Raise an error with error message aString. |
|
4299 |
The error is reported by raising the Error exception, |
|
4300 |
which is non-proceedable. |
|
4301 |
If no handler has been setup, a debugger is entered." |
|
4302 |
||
11021 | 4303 |
<context: #return> |
4304 |
<resource: #skipInDebuggersWalkBack> |
|
4305 |
||
10460 | 4306 |
Error raiseWith:#error: errorString:aString |
5755 | 4307 |
|
4308 |
" |
|
4309 |
nil error:' bad bad bad' |
|
4310 |
" |
|
4311 |
||
4312 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
4313 |
! |
|
4314 |
||
4315 |
error:aString mayProceed:mayProceed |
|
4316 |
"{ Pragma: +optSpace }" |
|
4317 |
||
4318 |
"enter debugger with error-message aString. |
|
10460 | 4319 |
The error is reported by raising either the |
5755 | 4320 |
non-proceedable Error exception, |
4321 |
or the ProceedableError exception." |
|
4322 |
||
11021 | 4323 |
<resource: #skipInDebuggersWalkBack> |
4324 |
||
5755 | 4325 |
mayProceed ifTrue:[ |
20535 | 4326 |
^ ProceedableError raiseRequestWith:#error: errorString:aString |
10460 | 4327 |
]. |
4328 |
||
4329 |
Error raiseWith:#error: errorString:aString |
|
5755 | 4330 |
|
4331 |
"Modified: 8.5.1996 / 09:13:04 / cg" |
|
4332 |
! |
|
4333 |
||
6900 | 4334 |
errorInvalidFormat |
4335 |
"{ Pragma: +optSpace }" |
|
4336 |
||
4337 |
"report an error that some conversion to/from string representation failed |
|
4338 |
typically when converting numbers, date, time etc." |
|
4339 |
||
11021 | 4340 |
<context: #return> |
4341 |
<resource: #skipInDebuggersWalkBack> |
|
4342 |
||
6900 | 4343 |
^ ConversionError raiseErrorString:'invalid format' |
4344 |
! |
|
4345 |
||
5755 | 4346 |
errorKeyNotFound:aKey |
4347 |
"{ Pragma: +optSpace }" |
|
4348 |
||
4349 |
"report an error that a key was not found in a collection. |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4350 |
The error is reported by raising the KeyNotFoundError exception." |
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4351 |
|
11021 | 4352 |
<resource: #skipInDebuggersWalkBack> |
4353 |
||
10918
a4635305501e
#instVarNamed* - raise KeyNotFoundError if an instaver does not exist
Stefan Vogel <sv@exept.de>
parents:
10877
diff
changeset
|
4354 |
^ KeyNotFoundError raiseRequestWith:aKey errorString:(' ', aKey printString) |
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4355 |
|
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
4356 |
" |
18685 | 4357 |
Dictionary new at:#nonExistentElement |
5755 | 4358 |
" |
4359 |
! |
|
4360 |
||
4361 |
errorNotFound |
|
4362 |
"{ Pragma: +optSpace }" |
|
4363 |
||
4364 |
"report an error that no element was found in a collection. |
|
4365 |
The error is reported by raising the NotFoundSignal exception." |
|
4366 |
||
11021 | 4367 |
<resource: #skipInDebuggersWalkBack> |
4368 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4369 |
^ NotFoundError raiseRequestWith:nil |
5755 | 4370 |
|
4371 |
"Modified: / 8.5.1996 / 09:13:11 / cg" |
|
4372 |
"Modified: / 26.7.1999 / 10:51:50 / stefan" |
|
4373 |
! |
|
4374 |
||
6874 | 4375 |
errorNotFound:errorString |
4376 |
"{ Pragma: +optSpace }" |
|
4377 |
||
4378 |
"report an error that no element was found in a collection. |
|
4379 |
The error is reported by raising the NotFoundSignal exception." |
|
4380 |
||
11021 | 4381 |
<resource: #skipInDebuggersWalkBack> |
4382 |
||
10837
63d19c75d762
changed #errorNotFound: raise it proceedable
Stefan Vogel <sv@exept.de>
parents:
10834
diff
changeset
|
4383 |
^ NotFoundError raiseRequestErrorString:errorString |
6874 | 4384 |
! |
4385 |
||
5755 | 4386 |
errorSignal |
11132
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4387 |
"return the signal used for error/error: handling" |
e5bd3a66ca80
conversion errors (specific error classes)
Claus Gittinger <cg@exept.de>
parents:
11068
diff
changeset
|
4388 |
|
5755 | 4389 |
^ self class errorSignal |
4390 |
||
4391 |
"Created: / 19.6.1998 / 02:32:32 / cg" |
|
4392 |
! |
|
4393 |
||
7322
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4394 |
handlerForSignal:exceptionHandler context:theContext originator:originator |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4395 |
" should never be invoked for non-blocks/non-exceptions/non-signals" |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4396 |
|
7566 | 4397 |
thisContext isRecursive ifTrue:[^ nil]. |
4398 |
||
7322
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4399 |
'Warning: handlerForSignal invoked for: ' print. self printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4400 |
' context: ' print. theContext printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4401 |
' originator: ' print. originator printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4402 |
' sender: ' print. thisContext sender printCR. |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4403 |
|
7566 | 4404 |
"/ MiniDebugger enter:thisContext withMessage:'oops' mayProceed:true. |
4405 |
self error:'this method should only be invoked for blocks, exceptions and signals'. |
|
7322
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4406 |
! |
178e33c2a376
catch non-block/non-signal/non-exception being
Claus Gittinger <cg@exept.de>
parents:
7320
diff
changeset
|
4407 |
|
5755 | 4408 |
implementedBySubclass |
4409 |
"{ Pragma: +optSpace }" |
|
4410 |
||
4411 |
"this is sent by ST/V code - its the same as #subclassResponsibility" |
|
4412 |
||
11021 | 4413 |
<resource: #skipInDebuggersWalkBack> |
4414 |
||
12322 | 4415 |
^ SubclassResponsibilityError raiseRequestErrorString:'method must be reimplemented in ST/V subclass' |
5755 | 4416 |
! |
4417 |
||
4418 |
indexNotInteger |
|
4419 |
"{ Pragma: +optSpace }" |
|
4420 |
||
4421 |
"report an error that index is not an Integer. |
|
4422 |
(when accessing collections indexed by an integer key). |
|
4423 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
4424 |
||
11021 | 4425 |
<resource: #skipInDebuggersWalkBack> |
4426 |
||
6946
905fcfc8699b
signal-classVars replaced by error-class access
Claus Gittinger <cg@exept.de>
parents:
6932
diff
changeset
|
4427 |
^ NonIntegerIndexError raiseRequestWith:nil |
5755 | 4428 |
|
4429 |
"Modified: / 8.5.1996 / 09:13:37 / cg" |
|
4430 |
"Modified: / 26.7.1999 / 10:57:43 / stefan" |
|
4431 |
! |
|
4432 |
||
4433 |
indexNotInteger:anIndex |
|
4434 |
"{ Pragma: +optSpace }" |
|
4435 |
||
4436 |
"report an error that index is not an Integer. |
|
4437 |
(when accessing collections indexed by an integer key). |
|
4438 |
The error is reported by raising the NonIntegerIndexSignal exception." |
|
4439 |
||
11021 | 4440 |
<resource: #skipInDebuggersWalkBack> |
4441 |
||
10460 | 4442 |
^ NonIntegerIndexError raiseRequestWith:anIndex |
5755 | 4443 |
|
4444 |
"Created: / 16.5.1998 / 19:39:41 / cg" |
|
4445 |
! |
|
4446 |
||
7216 | 4447 |
indexNotIntegerOrOutOfBounds:index |
4448 |
"{ Pragma: +optSpace }" |
|
4449 |
||
4450 |
"report an error that index is either non-integral or out of bounds" |
|
4451 |
||
11021 | 4452 |
<resource: #skipInDebuggersWalkBack> |
4453 |
||
7216 | 4454 |
index isInteger ifFalse:[ |
20535 | 4455 |
^ self indexNotInteger:index |
7216 | 4456 |
]. |
4457 |
^ self subscriptBoundsError:index |
|
4458 |
! |
|
4459 |
||
5755 | 4460 |
integerCheckError |
4461 |
"{ Pragma: +optSpace }" |
|
4462 |
||
12321 | 4463 |
"generated when a variable declared with an integer type gets a bad value assigned" |
5755 | 4464 |
|
11021 | 4465 |
<resource: #skipInDebuggersWalkBack> |
4466 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4467 |
"/ ^ self error:'bad assign of ' , self printString , |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4468 |
"/ ' (' , self class name , ') to integer-typed variable' |
14632 | 4469 |
^ InvalidTypeError |
20535 | 4470 |
raiseRequestErrorString:( |
4471 |
'bad assign of ' , self printString , |
|
4472 |
' (' , self class name , ') to integer-typed variable') |
|
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4473 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4474 |
"Modified: / 02-11-2012 / 10:25:36 / cg" |
5755 | 4475 |
! |
4476 |
||
4477 |
invalidCodeObject |
|
4478 |
"{ Pragma: +optSpace }" |
|
4479 |
||
12321 | 4480 |
"this is sent by VM if it encounters some non-method for execution" |
4481 |
||
11021 | 4482 |
<resource: #skipInDebuggersWalkBack> |
4483 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4484 |
"/ self error:'not an executable code object' |
14632 | 4485 |
^ ExecutionError |
20535 | 4486 |
raiseRequestErrorString:'not an executable code object' |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4487 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4488 |
"Created: / 01-08-1997 / 00:16:44 / cg" |
5755 | 4489 |
! |
4490 |
||
10460 | 4491 |
invalidMessage |
5755 | 4492 |
"{ Pragma: +optSpace }" |
4493 |
||
20214 | 4494 |
"this is sent by ST/V code - it is the same as #shouldNotImplement" |
5755 | 4495 |
|
11021 | 4496 |
<resource: #skipInDebuggersWalkBack> |
4497 |
||
5755 | 4498 |
^ self shouldNotImplement |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4499 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4500 |
"Modified (comment): / 02-11-2012 / 10:11:18 / cg" |
5755 | 4501 |
! |
4502 |
||
4503 |
mustBeRectangle |
|
4504 |
"{ Pragma: +optSpace }" |
|
4505 |
||
4506 |
"report an argument-not-rectangle-error" |
|
4507 |
||
11021 | 4508 |
<resource: #skipInDebuggersWalkBack> |
4509 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4510 |
"/ ^ self error:'argument must be a Rectangle' |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4511 |
^ InvalidTypeError |
20535 | 4512 |
raiseRequestErrorString:'argument must be a Rectangle' |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4513 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4514 |
"Modified: / 02-11-2012 / 10:24:53 / cg" |
5755 | 4515 |
! |
4516 |
||
4517 |
mustBeString |
|
4518 |
"{ Pragma: +optSpace }" |
|
4519 |
||
4520 |
"report an argument-not-string-error" |
|
4521 |
||
11021 | 4522 |
<resource: #skipInDebuggersWalkBack> |
4523 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4524 |
"/ ^ self error:'argument must be a String' |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4525 |
^ InvalidTypeError |
20535 | 4526 |
raiseRequestErrorString:'argument must be a String' |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4527 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4528 |
"Modified: / 02-11-2012 / 10:24:35 / cg" |
5755 | 4529 |
! |
4530 |
||
4531 |
notIndexed |
|
4532 |
"{ Pragma: +optSpace }" |
|
4533 |
||
4534 |
"report an error that receiver has no indexed instance variables. |
|
4535 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4536 |
||
11021 | 4537 |
<context: #return> |
4538 |
<resource: #skipInDebuggersWalkBack> |
|
4539 |
||
10460 | 4540 |
^ SubscriptOutOfBoundsError |
20535 | 4541 |
raiseRequestErrorString:'receiver has no indexed variables' |
5755 | 4542 |
|
14539 | 4543 |
" |
4544 |
1234 at:4 |
|
4545 |
" |
|
4546 |
||
5755 | 4547 |
"Modified: 26.7.1996 / 16:43:13 / cg" |
4548 |
! |
|
4549 |
||
12050 | 4550 |
notYetImplemented |
4551 |
"{ Pragma: +optSpace }" |
|
4552 |
||
12321 | 4553 |
"report an error that some functionality is not yet implemented. |
4554 |
This is here only for compatibility - it has the same meaning as shouldImplement." |
|
12050 | 4555 |
|
4556 |
<resource: #skipInDebuggersWalkBack> |
|
4557 |
||
15891 | 4558 |
|sender| |
4559 |
||
4560 |
sender := thisContext sender. |
|
4561 |
||
4562 |
^ UnimplementedFunctionalityError |
|
20535 | 4563 |
raiseRequestWith:(Message selector:sender selector arguments:sender args) |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4564 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4565 |
"Modified: / 02-11-2012 / 10:24:12 / cg" |
12050 | 4566 |
! |
4567 |
||
5755 | 4568 |
primitiveFailed |
4569 |
"{ Pragma: +optSpace }" |
|
4570 |
||
4571 |
"report an error that some primitive code failed. |
|
14539 | 4572 |
The error is reported by raising the PrimitiveFailure exception. |
4573 |
Sorry for the code duplication: it avoids the extra frame in the debugger." |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4574 |
|
11021 | 4575 |
<resource: #skipInDebuggersWalkBack> |
4576 |
||
15891 | 4577 |
|sender selector| |
4578 |
||
4579 |
"do loop to take care of super sends" |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4580 |
sender := thisContext sender. |
15891 | 4581 |
[ |
20535 | 4582 |
selector := sender selector. |
4583 |
selector == #primitiveFailed: or:[selector == #primitiveFailed] |
|
15891 | 4584 |
] whileTrue:[sender := sender sender]. |
4585 |
||
4586 |
^ PrimitiveFailure raiseRequestWith:(Message selector:selector arguments:sender args) |
|
20535 | 4587 |
in:sender. |
5755 | 4588 |
|
6005 | 4589 |
" |
4590 |
1234 primitiveFailed |
|
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4591 |
|
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4592 |
[ |
20535 | 4593 |
ExternalBytes new basicAt:40 |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4594 |
] on:PrimitiveFailure do:[:ex| |
20535 | 4595 |
ex inspect |
8324
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4596 |
] |
c6e8039f0d83
Set message as parameter in #primitiveFailed
Stefan Vogel <sv@exept.de>
parents:
8322
diff
changeset
|
4597 |
" |
5755 | 4598 |
! |
4599 |
||
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4600 |
primitiveFailed:messageString |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4601 |
"{ Pragma: +optSpace }" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4602 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4603 |
"report an error that some primitive code failed. |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4604 |
The error is reported by raising the PrimitiveFailureSignal exception." |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4605 |
|
11021 | 4606 |
<resource: #skipInDebuggersWalkBack> |
4607 |
||
15891 | 4608 |
|sender selector| |
4609 |
||
4610 |
"do loop to take care of super sends" |
|
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4611 |
sender := thisContext sender. |
15891 | 4612 |
[ |
20535 | 4613 |
selector := sender selector. |
4614 |
selector == #primitiveFailed: or:[selector == #primitiveFailed] |
|
15891 | 4615 |
] whileTrue:[sender := sender sender]. |
4616 |
||
4617 |
^ PrimitiveFailure raiseRequestWith:(Message selector:selector arguments:sender args) |
|
20535 | 4618 |
errorString:messageString |
4619 |
in:sender. |
|
8977
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4620 |
|
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4621 |
" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4622 |
1234 primitiveFailed:'this is a test' |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4623 |
" |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4624 |
! |
fff5644c031d
#primitiveFailed: remember the message implementing the failure
Stefan Vogel <sv@exept.de>
parents:
8975
diff
changeset
|
4625 |
|
6815 | 4626 |
shouldImplement |
4627 |
"{ Pragma: +optSpace }" |
|
4628 |
||
12321 | 4629 |
"report an error that this message/functionality should be implemented. |
4630 |
This is send by automatically generated method bodies or inside as-yet-uncoded |
|
4631 |
branches of existing methods." |
|
6815 | 4632 |
|
11021 | 4633 |
<resource: #skipInDebuggersWalkBack> |
4634 |
||
9216
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4635 |
|sender| |
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4636 |
|
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4637 |
sender := thisContext sender. |
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4638 |
|
12841 | 4639 |
^ UnimplementedFunctionalityError |
20535 | 4640 |
raiseRequestWith:(Message selector:sender selector arguments:sender args) |
9216
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4641 |
|
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4642 |
" |
12321 | 4643 |
self shouldImplement |
4644 |
" |
|
4645 |
! |
|
4646 |
||
4647 |
shouldImplement:what |
|
4648 |
"{ Pragma: +optSpace }" |
|
4649 |
||
4650 |
"report an error that this message/functionality should be implemented. |
|
4651 |
This is send by automatically generated method bodies or inside as-yet-uncoded |
|
4652 |
branches of existing methods." |
|
4653 |
||
4654 |
<resource: #skipInDebuggersWalkBack> |
|
4655 |
||
4656 |
|sender| |
|
4657 |
||
4658 |
sender := thisContext sender. |
|
4659 |
||
12841 | 4660 |
^ UnimplementedFunctionalityError |
20535 | 4661 |
raiseRequestWith:(Message selector:sender selector arguments:sender args) |
4662 |
errorString:what |
|
12321 | 4663 |
|
4664 |
" |
|
4665 |
self shouldImplement:'foobar' |
|
9216
6396192d71c6
use UnimplementedFunctionalityError in #subclassResponsibility
Stefan Vogel <sv@exept.de>
parents:
9203
diff
changeset
|
4666 |
" |
6815 | 4667 |
! |
4668 |
||
11976 | 4669 |
shouldNeverBeReached |
12321 | 4670 |
"report an error that this point may never be reached." |
12841 | 4671 |
|
14499 | 4672 |
<resource: #skipInDebuggersWalkBack> |
4673 |
||
4674 |
^ ExecutionError |
|
20535 | 4675 |
raiseRequestErrorString:'Oops, this may never reached. Something somewhere was terribly wrong.'. |
11976 | 4676 |
|
4677 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
|
4678 |
! |
|
4679 |
||
4680 |
shouldNeverBeSent |
|
20351 | 4681 |
"report an error that this message may never be sent to the receiver" |
12841 | 4682 |
|
14499 | 4683 |
<resource: #skipInDebuggersWalkBack> |
4684 |
||
14632 | 4685 |
^ MethodNotAppropriateError |
20351 | 4686 |
raiseRequestErrorString:'This message never may be sent to me'. |
11976 | 4687 |
|
4688 |
"Modified: / 20-04-2005 / 18:59:28 / janfrog" |
|
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4689 |
"Modified: / 02-11-2012 / 10:10:42 / cg" |
11976 | 4690 |
! |
4691 |
||
5755 | 4692 |
shouldNotImplement |
4693 |
"{ Pragma: +optSpace }" |
|
4694 |
||
12841 | 4695 |
"report an error that this message should not be implemented - |
12733
48cc66ac5d52
comment/format in: #shouldNotImplement
Claus Gittinger <cg@exept.de>
parents:
12718
diff
changeset
|
4696 |
i.e. that a method is invoked which is not appropriate for the receiver." |
5755 | 4697 |
|
11021 | 4698 |
<resource: #skipInDebuggersWalkBack> |
4699 |
||
14632 | 4700 |
^ MethodNotAppropriateError |
20535 | 4701 |
raiseRequestErrorString:'method/functionality is not appropriate for class'. |
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4702 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4703 |
"Modified: / 02-11-2012 / 10:02:25 / cg" |
5755 | 4704 |
! |
4705 |
||
4706 |
subclassResponsibility |
|
4707 |
"{ Pragma: +optSpace }" |
|
4708 |
||
12321 | 4709 |
"report an error that this message should have been reimplemented in a subclass" |
5755 | 4710 |
|
11021 | 4711 |
<resource: #skipInDebuggersWalkBack> |
4712 |
||
10877
0666d48f91d1
show the affected method-selector in the subclassResponsibility
Claus Gittinger <cg@exept.de>
parents:
10856
diff
changeset
|
4713 |
^ SubclassResponsibilityError raiseRequestWith:thisContext sender selector |
5755 | 4714 |
! |
4715 |
||
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4716 |
subclassResponsibility:msg |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4717 |
"{ Pragma: +optSpace }" |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4718 |
|
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4719 |
"report an error that this message should have been reimplemented in a subclass" |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4720 |
|
11021 | 4721 |
<resource: #skipInDebuggersWalkBack> |
4722 |
||
7334 | 4723 |
^ SubclassResponsibilityError raiseRequestErrorString:msg |
6721
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4724 |
! |
e5f47c6e2f40
#subclassResponsibility & #subclassResponsibility:
Claus Gittinger <cg@exept.de>
parents:
6718
diff
changeset
|
4725 |
|
5755 | 4726 |
subscriptBoundsError |
4727 |
"{ Pragma: +optSpace }" |
|
4728 |
||
4729 |
"report an error that some index is out of bounds. |
|
4730 |
(when accessing indexable collections). |
|
4731 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4732 |
||
11021 | 4733 |
<resource: #skipInDebuggersWalkBack> |
4734 |
||
5755 | 4735 |
^ SubscriptOutOfBoundsSignal raiseRequestWith:nil |
4736 |
||
4737 |
"Modified: / 26.7.1996 / 16:45:42 / cg" |
|
4738 |
"Modified: / 26.7.1999 / 10:58:27 / stefan" |
|
4739 |
! |
|
4740 |
||
4741 |
subscriptBoundsError:anIndex |
|
4742 |
"{ Pragma: +optSpace }" |
|
4743 |
||
4744 |
"report an error that anIndex is out of bounds. |
|
4745 |
(when accessing indexable collections). |
|
4746 |
The error is reported by raising the SubscriptOutOfBoundsSignal exception." |
|
4747 |
||
11021 | 4748 |
<resource: #skipInDebuggersWalkBack> |
4749 |
||
10460 | 4750 |
^ SubscriptOutOfBoundsError |
20535 | 4751 |
raiseRequestWith:anIndex |
4752 |
errorString:('subscript (' , anIndex printString , ') out of bounds') |
|
5755 | 4753 |
|
6221 | 4754 |
"Modified: / 17.11.2001 / 22:49:56 / cg" |
5755 | 4755 |
! |
4756 |
||
4757 |
typeCheckError |
|
4758 |
"{ Pragma: +optSpace }" |
|
4759 |
||
4760 |
"generated when a variable declared with a type hint gets a bad |
|
4761 |
value assigned" |
|
4762 |
||
11021 | 4763 |
<resource: #skipInDebuggersWalkBack> |
4764 |
||
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4765 |
"/ ^ self error:'bad assign of ' , self printString , |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4766 |
"/ ' (' , self class name , ') to typed variable' |
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4767 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4768 |
^ InvalidTypeError |
20535 | 4769 |
raiseRequestErrorString: |
4770 |
('bad assign of ' , self printString , |
|
4771 |
' (' , self class name , ') to typed variable') |
|
14478
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4772 |
|
4ff5aab56d26
more specific error reporting for type errors
Claus Gittinger <cg@exept.de>
parents:
14369
diff
changeset
|
4773 |
"Modified: / 02-11-2012 / 10:19:15 / cg" |
5755 | 4774 |
! ! |
4775 |
||
16311 | 4776 |
!Object methodsFor:'error handling - debugger'! |
4777 |
||
4778 |
addDebuggerHook:aBlock |
|
4779 |
"add a debugger hook. Any registered hook is evaluated with the exception as |
|
16560 | 4780 |
argument before a real debugger is entered. |
16311 | 4781 |
Hooks can be used for two purposes: |
20535 | 4782 |
- record exception information in a log file |
4783 |
- filter exceptions and either decide to ignore them or to open an alternative |
|
4784 |
debugger (depending on the exception type, maybe)" |
|
16311 | 4785 |
|
4786 |
DebuggerHooks isNil ifTrue:[ |
|
20535 | 4787 |
DebuggerHooks := OrderedCollection new. |
16311 | 4788 |
]. |
4789 |
DebuggerHooks add:aBlock |
|
4790 |
||
4791 |
" |
|
4792 |
Object addDebuggerHook:[:ex | AbortSignal raise]. |
|
4793 |
(1 / (1-1)). |
|
4794 |
Object removeDebuggerHook:(DebuggerHooks first). |
|
4795 |
" |
|
4796 |
" |
|
4797 |
Object addDebuggerHook:[:ex | Transcript showCR:ex ]. |
|
4798 |
(1 / (1-1)). |
|
4799 |
Object removeDebuggerHook:(DebuggerHooks first). |
|
4800 |
" |
|
4801 |
" |
|
4802 |
Object addDebuggerHook:[:ex | ex suspendedContext fullPrintAllOn:Transcript ]. |
|
4803 |
(1 / (1-1)). |
|
4804 |
Object removeDebuggerHook:(DebuggerHooks first). |
|
4805 |
" |
|
4806 |
" |
|
4807 |
Object addDebuggerHook:[:ex | '/tmp/stx.log' asFilename |
|
20535 | 4808 |
appendingFileDo:[:s | |
4809 |
s nextPutLine:'----------------------'. |
|
4810 |
(Timestamp now printOn:s). s cr. |
|
4811 |
ex suspendedContext fullPrintAllOn:s |
|
4812 |
]]. |
|
16311 | 4813 |
(1 / (1-1)). |
4814 |
Object removeDebuggerHook:(DebuggerHooks first). |
|
4815 |
" |
|
4816 |
! |
|
4817 |
||
4818 |
appropriateDebugger:aSelector |
|
4819 |
"return an appropriate debugger to use. |
|
4820 |
If there is already a debugger active on the stack, and it is |
|
4821 |
the DebugView, return MiniDebugger (as a last chance) otherwise abort." |
|
4822 |
||
21646 | 4823 |
"{ Pragma: +optSpace }" |
4824 |
||
16311 | 4825 |
|context| |
4826 |
||
4827 |
(Processor isNil |
|
21646 | 4828 |
or:[Processor activeProcessIsSystemProcess |
4829 |
or:[Smalltalk isInitialized not]]) ifTrue:[ |
|
4830 |
"DebugView cannot run without system processes" |
|
20535 | 4831 |
^ MiniDebugger |
16311 | 4832 |
]. |
4833 |
(Screen isNil or:[Screen default isNil or:[Screen default isOpen not]]) ifTrue:[ |
|
20535 | 4834 |
Debugger isNil ifTrue:[^ nil]. |
4835 |
^ MiniDebugger |
|
16311 | 4836 |
]. |
4837 |
||
4838 |
context := thisContext. |
|
21646 | 4839 |
[(context := context findNextContextWithSelector:aSelector or:nil or:nil) notNil] whileTrue:[ |
20535 | 4840 |
((context receiver class == Debugger) |
4841 |
and:[context selector == aSelector]) ifTrue:[ |
|
4842 |
"we are already in some Debugger" |
|
4843 |
(Debugger == MiniDebugger) ifTrue:[ |
|
4844 |
"we are already in the MiniDebugger" |
|
4845 |
ErrorRecursion ifFalse:[ |
|
4846 |
Smalltalk fatalAbort:'recursive error ...' |
|
4847 |
] |
|
4848 |
]. |
|
4849 |
MiniDebugger isNil ifTrue:[ |
|
4850 |
Smalltalk fatalAbort:'no debugger' |
|
4851 |
]. |
|
4852 |
||
4853 |
"ok, an error occurred while in the graphical debugger; |
|
4854 |
lets try MiniDebugger" |
|
4855 |
^ MiniDebugger |
|
4856 |
]. |
|
16311 | 4857 |
]. |
4858 |
"not within Debugger - no problem" |
|
4859 |
^ Debugger |
|
4860 |
||
21646 | 4861 |
"Modified: / 19-05-1999 / 18:05:00 / cg" |
4862 |
"Modified (format): / 15-03-2017 / 17:37:08 / stefan" |
|
16311 | 4863 |
! |
4864 |
||
4865 |
openDebuggerOnException:ex |
|
4866 |
"{ Pragma: +optSpace }" |
|
4867 |
||
4868 |
"enter the debugger on some unhandled exception" |
|
4869 |
||
4870 |
|msgString debugger| |
|
4871 |
||
4872 |
msgString := ex descriptionForDebugger. |
|
4873 |
||
4874 |
" |
|
16560 | 4875 |
if there is no debugger, ask for ignore or exit. |
16311 | 4876 |
Exit will terminate the application. |
4877 |
ignore will raise an AbortOperationRequest. |
|
4878 |
" |
|
4879 |
Debugger isNil ifTrue:[ |
|
20535 | 4880 |
msgString := 'Error: ' , msgString. |
4881 |
||
4882 |
thisContext isRecursive ifTrue:[ |
|
4883 |
msgString errorPrintCR. |
|
4884 |
Smalltalk fatalAbort:'recursive unhandled exception' |
|
4885 |
]. |
|
4886 |
||
4887 |
Smalltalk isStandAloneApp ifTrue:[ |
|
4888 |
(ex creator == NoHandlerError) ifTrue:[ |
|
4889 |
(HaltInterrupt handles:ex exception) ifTrue:[ |
|
4890 |
"/ 'Halt ignored' infoPrintCR. |
|
4891 |
^ nil |
|
4892 |
]. |
|
4893 |
"don't output the message, if the exception is a UserInterrupt (CTRL-C)" |
|
4894 |
(ex exception creator == UserInterrupt) ifTrue:[ |
|
4895 |
ex description errorPrintCR. |
|
4896 |
OperatingSystem exit:130. |
|
4897 |
]. |
|
4898 |
]. |
|
4899 |
]. |
|
4900 |
||
4901 |
(Dialog notNil and:[Screen default notNil]) ifTrue:[ |
|
4902 |
self |
|
4903 |
errorNotify:msgString |
|
4904 |
from:ex suspendedContext |
|
4905 |
allowDebug:false |
|
4906 |
mayProceed:ex willProceed. |
|
4907 |
||
4908 |
"/ arrive here if proceeded... |
|
4909 |
^ nil |
|
4910 |
]. |
|
4911 |
||
4912 |
"don't output the message, if the exception is a UserInterrupt (CTRL-C)" |
|
4913 |
(ex creator == NoHandlerError |
|
4914 |
and:[ex exception creator == UserInterrupt]) ifTrue:[ |
|
4915 |
OperatingSystem exit:130. |
|
4916 |
]. |
|
20839 | 4917 |
msgString _errorPrintCR. |
4918 |
'Backtrace:' _errorPrintCR. |
|
4919 |
'' _errorPrintCR. |
|
20535 | 4920 |
thisContext fullPrintAll. |
4921 |
OperatingSystem exit:1 |
|
16311 | 4922 |
]. |
4923 |
||
4924 |
" |
|
4925 |
find an appropriate debugger to use |
|
4926 |
" |
|
4927 |
debugger := self appropriateDebugger:(thisContext selector). |
|
4928 |
debugger isNil ifTrue:[ |
|
20535 | 4929 |
^ AbortOperationRequest raiseRequest |
16311 | 4930 |
]. |
4931 |
||
4932 |
"/ call any registered debug hooks. |
|
4933 |
"/ These may record or further filter the exception. Each hook gets the exception object and may send any |
|
4934 |
"/ ex-message (ex proceed, ex return etc.) or raise an Abort signal. |
|
4935 |
"/ However, the real intent for hooks is to allow saving exceptions in a log file... |
|
4936 |
DebuggerHooks notNil ifTrue:[ |
|
20535 | 4937 |
DebuggerHooks do:[:eachHook | |
4938 |
eachHook value:ex. |
|
4939 |
]. |
|
16311 | 4940 |
]. |
4941 |
^ debugger enterException:ex. |
|
4942 |
||
4943 |
"Modified: / 05-12-2011 / 11:53:10 / cg" |
|
4944 |
! |
|
4945 |
||
4946 |
removeDebuggerHook:aBlock |
|
4947 |
"remove a debugger hook." |
|
4948 |
||
4949 |
DebuggerHooks notNil ifTrue:[ |
|
20535 | 4950 |
DebuggerHooks removeIdentical:aBlock. |
4951 |
DebuggerHooks isNil ifTrue:[ DebuggerHooks := nil ]. |
|
16311 | 4952 |
]. |
4953 |
! ! |
|
4954 |
||
5755 | 4955 |
!Object methodsFor:'evaluation'! |
4956 |
||
20061 | 4957 |
_evaluate_ |
4958 |
"return the receiver itself. |
|
4959 |
- compatibility with LazyValue" |
|
4960 |
||
4961 |
^ self |
|
4962 |
! |
|
4963 |
||
5755 | 4964 |
value |
4965 |
"return the receiver itself. |
|
4966 |
This allows every object to be used where blocks or valueHolders |
|
4967 |
are typically used, and allows for valueHolders and blocks to be |
|
4968 |
used interchangably in some situations. |
|
4969 |
||
4970 |
Time will show, if this is a good idea or leads to sloppy programming |
|
4971 |
style ... (the idea was borrowed from the Self language). |
|
4972 |
||
20807 | 4973 |
WARNING: don't 'optimize' away ifXXX: blocks |
20535 | 4974 |
(i.e. do NOT replace |
4975 |
foo ifTrue:[var1] ifFalse:[var2] |
|
4976 |
by: |
|
4977 |
foo ifTrue:var1 ifFalse:var2 |
|
4978 |
) |
|
4979 |
- the compilers will only generate inline code for the if, |
|
4980 |
iff the argument(s) are blocks - otherwise, a true send is |
|
4981 |
generated. |
|
4982 |
This 'optimization' will work semantically correct, |
|
4983 |
but execute SLOWER instead. |
|
4984 |
||
4985 |
Using constants (foo ifTrue:1 ifFalse:2) does not introduce a performance penalty." |
|
5755 | 4986 |
|
4987 |
^ self |
|
4988 |
||
4989 |
" |
|
10460 | 4990 |
#(1 2 3 4) indexOf:5 ifAbsent:0 |
4991 |
#(1 2 3 4) indexOf:5 ifAbsent:[0] |
|
4992 |
1 > 2 ifTrue:['yes'] ifFalse:['no'] |
|
4993 |
1 > 2 ifTrue:'yes' ifFalse:'no' |
|
5755 | 4994 |
" |
4995 |
||
4996 |
"DO NOT DO THIS (its slower) |
|
7458 | 4997 |
(1 > 4) ifTrue:a ifFalse:b |
5755 | 4998 |
|
4999 |
USE (the compiler optimizes blocks in if/while): |
|
7458 | 5000 |
(1 > 4) ifTrue:[a] ifFalse:[b] |
5755 | 5001 |
" |
5002 |
||
5003 |
"Modified: 3.5.1996 / 11:57:08 / cg" |
|
20184 | 5004 |
! |
5005 |
||
5006 |
valueWithPossibleArguments:argArray |
|
5007 |
"see comment in #value. |
|
20214 | 5008 |
The argArray is ignored here |
20184 | 5009 |
(equivalent to sending this message to a 0-arg Block)" |
5010 |
||
5011 |
^ self |
|
5012 |
||
5013 |
" |
|
20535 | 5014 |
[ 'abc' ] valueWithPossibleArguments:#(1 2 3) |
5015 |
'abc' valueWithPossibleArguments:#(1 2 3) |
|
20184 | 5016 |
" |
5755 | 5017 |
! ! |
5018 |
||
5019 |
!Object methodsFor:'finalization'! |
|
5020 |
||
5021 |
disposed |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5022 |
"OBSOLETE INTERFACE: use #finalize |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5023 |
this is invoked for objects which have been registered |
5755 | 5024 |
in a Registry, when the original object dies. |
5025 |
Subclasses may redefine this method" |
|
5026 |
||
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5027 |
<resource: #obsolete> |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5028 |
|
5755 | 5029 |
^ self |
5030 |
! |
|
5031 |
||
5032 |
executor |
|
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5033 |
"Return the object which does the finalization for me. |
21810 | 5034 |
This interface is also VW & Squeak compatible," |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5035 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5036 |
"for now, send #shallowCopyForFinalization, to be compatible with |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5037 |
classes designed for old ST/X versions" |
5755 | 5038 |
|
5039 |
^ self shallowCopyForFinalization |
|
21810 | 5040 |
|
5041 |
"Modified (comment): / 15-06-2017 / 01:46:54 / mawalch" |
|
5755 | 5042 |
! |
5043 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5044 |
finalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5045 |
"answer a Registry used for finalization. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5046 |
Use a generic Registry for any object. |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5047 |
Subclasses using their own Registry should redefine this" |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5048 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5049 |
^ FinalizationLobby |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5050 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5051 |
|
5755 | 5052 |
finalize |
6439
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5053 |
"this is invoked for executor objects which have been registered |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5054 |
in a Registry, when the original object dies. |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5055 |
Subclasses may redefine this method |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5056 |
This interface is also VW-compatible" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5057 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5058 |
"send #disposed for compatibility with existing classes that still |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5059 |
implement the obsolete #disposed message" |
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5060 |
|
0f841258ec4a
Use #finalize instead of #disposed
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
5061 |
^ self disposed |
5755 | 5062 |
! |
5063 |
||
5064 |
reRegisterForFinalization |
|
5065 |
"re-register mySelf for later finalization. |
|
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5066 |
This will create a new executor, which will receive a #finalize message when |
5755 | 5067 |
the receiver is garbage collected." |
5068 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5069 |
self finalizationLobby registerChange:self |
5755 | 5070 |
! |
5071 |
||
5072 |
registerForFinalization |
|
5073 |
"register mySelf for later finalization. |
|
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5074 |
Once registered, the executor of the receiver will receive a #finalize message when |
5755 | 5075 |
the receiver is garbage collected." |
5076 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5077 |
self finalizationLobby register:self |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5078 |
! |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5079 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5080 |
shallowCopyForFinalization |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5081 |
"OBSOLETE INTERFACE: use #executor. |
20121 | 5082 |
This is used to acquire a copy to be used for finalization - |
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5083 |
(the copy will be sent a #finalize message; see the documentation in the Registry class) |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5084 |
This method can be redefined for more efficient copying - especially for large objects." |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5085 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5086 |
<resource: #obsolete> |
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5087 |
|
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5088 |
^ self shallowCopy |
5755 | 5089 |
! |
5090 |
||
5091 |
unregisterForFinalization |
|
5092 |
"unregister mySelf from later finalization" |
|
5093 |
||
6461
f5efaff3457b
Allow #registerForFinalization for classes defining their own Lobby.
Stefan Vogel <sv@exept.de>
parents:
6439
diff
changeset
|
5094 |
self finalizationLobby unregister:self |
5755 | 5095 |
! ! |
5096 |
||
5097 |
!Object methodsFor:'initialization'! |
|
5098 |
||
5099 |
initialize |
|
5100 |
"just to ignore initialize to objects which do not need it" |
|
5101 |
||
5102 |
^ self |
|
5103 |
! ! |
|
5104 |
||
20317 | 5105 |
!Object methodsFor:'inspecting'! |
5106 |
||
5107 |
inspectorExtraMenuOperations |
|
5108 |
"extra operation-menu entries to be shown in an inspector. |
|
20319 | 5109 |
Answers a collection of pairs contining aString and action aBlock. |
20317 | 5110 |
aString is the label of the menu item. |
5111 |
aBlock is evaluated when the menu item is selected. |
|
5112 |
To be redefined in objects which think that it makes sense to offer |
|
5113 |
often used operations in an inspector. |
|
20318 | 5114 |
See SerialPort as an example." |
20317 | 5115 |
|
5116 |
^ OrderedCollection new. |
|
5117 |
! ! |
|
17677 | 5118 |
|
5755 | 5119 |
!Object methodsFor:'interrupt handling'! |
5120 |
||
5121 |
childSignalInterrupt |
|
5122 |
"death of a child process (unix process) - do nothing" |
|
5123 |
||
5124 |
^ self |
|
5125 |
! |
|
5126 |
||
5127 |
customInterrupt |
|
5128 |
"{ Pragma: +optSpace }" |
|
5129 |
||
5130 |
"a custom interrupt - but no handler has defined" |
|
5131 |
||
5132 |
self error:'custom interrupt' mayProceed:true |
|
5133 |
! |
|
5134 |
||
5135 |
errorInterrupt:errorID with:aParameter |
|
5136 |
"subsystem error. The arguments errorID and aParameter are the values passed |
|
10460 | 5137 |
to the 'errorInterruptWithIDAndParameter(id, param)' function, |
5755 | 5138 |
which can be called from C subsystems to raise an (asynchronous) |
5139 |
error exception. |
|
5140 |
||
5141 |
Currently, this is used to map XErrors to smalltalk errors, but can be |
|
5142 |
used from other C subsystems too, to upcast errors. |
|
5143 |
Especially, for subsystems which call errorHandler functions asynchronously. |
|
5144 |
IDs (currently) used: |
|
20535 | 5145 |
#DisplayError ..... x-error interrupt |
5146 |
#XtError ..... xt-error interrupt (Xt interface is not yet published) |
|
5755 | 5147 |
" |
5148 |
||
6263
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
5149 |
|handlers handler| |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
5150 |
|
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
5151 |
handlers := ObjectMemory registeredErrorInterruptHandlers. |
4e7a970e4cfc
errorInterrupt:with: fixed (care for nil handlers in Objmem)
Claus Gittinger <cg@exept.de>
parents:
6235
diff
changeset
|
5152 |
handlers notNil ifTrue:[ |
20535 | 5153 |
handler := handlers at:errorID ifAbsent:nil. |
5154 |
handler notNil ifTrue:[ |
|
5155 |
"/ |
|
5156 |
"/ handler found; let it do whatever it wants ... |
|
5157 |
"/ |
|
5158 |
handler errorInterrupt:errorID with:aParameter. |
|
5159 |
^ self |
|
5160 |
]. |
|
5755 | 5161 |
]. |
5162 |
||
5163 |
"/ |
|
5164 |
"/ no handler - raise errorSignal passing the errorId as parameter |
|
5165 |
"/ |
|
10460 | 5166 |
^ Error |
20535 | 5167 |
raiseRequestWith:errorID |
5168 |
errorString:('Subsystem error. ErrorID = ' , errorID printString) |
|
5755 | 5169 |
! |
5170 |
||
5171 |
exceptionInterrupt |
|
5172 |
"{ Pragma: +optSpace }" |
|
5173 |
||
5174 |
"exception interrupt - enter debugger" |
|
5175 |
||
5176 |
self error:'exception Interrupt' mayProceed:true |
|
5177 |
! |
|
5178 |
||
5179 |
fpExceptionInterrupt |
|
5180 |
"{ Pragma: +optSpace }" |
|
5181 |
||
20253 | 5182 |
"a floating point exception occurred - this one |
5755 | 5183 |
has to be handled differently since it comes asynchronous |
5184 |
on some machines (for example, on machines with a separate FPU |
|
5185 |
or superscalar architectures. Also, errors from within primitive code |
|
5186 |
(or library functions such as GL) are sent via the Unix-signal |
|
5187 |
mechanism this way." |
|
5188 |
||
5189 |
|where rec| |
|
5190 |
||
5191 |
where := thisContext sender. |
|
5192 |
rec := where receiver. |
|
5193 |
rec isNumber ifTrue:[ |
|
20535 | 5194 |
^ rec class |
5195 |
raise:#domainErrorSignal |
|
5196 |
receiver:rec |
|
5197 |
selector:where selector |
|
5198 |
arguments:(where args asArray) |
|
5199 |
errorString:'floating point exception' |
|
5755 | 5200 |
]. |
5201 |
||
5202 |
"/ could be in some C-library ... |
|
7402 | 5203 |
^ DomainError raise |
5755 | 5204 |
! |
5205 |
||
5206 |
internalError:msg |
|
5207 |
"{ Pragma: +optSpace }" |
|
5208 |
||
5209 |
"this is triggered, when VM hits some bad error, |
|
5210 |
such as corrupted class, corrupted method/selector array |
|
5211 |
etc. The argument string gives some more information on what happened. |
|
5212 |
(for example, if you set an objects class to a non-behavior, nil etc.). |
|
5213 |
Its not guaranteed, that the system is in a working condition once |
|
5214 |
this error occurred ...." |
|
5215 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
5216 |
VMInternalError raiseWith:self errorString:msg |
5755 | 5217 |
! |
5218 |
||
5219 |
ioInterrupt |
|
5220 |
"{ Pragma: +optSpace }" |
|
5221 |
||
5222 |
"I/O (SIGIO/SIGPOLL) interrupt (supposed to be sent to Processor). |
|
5223 |
If we arrive here, there is either no handler (ObjMem>>ioInterruptHandler) |
|
5224 |
or it does not understand the ioInterrupt message. |
|
5225 |
In any case, this is a sign of some big trouble. Enter debugger." |
|
5226 |
||
5227 |
self error:'I/O Interrupt - but no handler' mayProceed:true |
|
5228 |
! |
|
5229 |
||
5230 |
memoryInterrupt |
|
5231 |
"{ Pragma: +optSpace }" |
|
5232 |
||
5233 |
"out-of-memory interrupt and no handler - enter debugger" |
|
5234 |
||
5235 |
self error:'almost out of memory' mayProceed:true |
|
5236 |
! |
|
5237 |
||
5238 |
recursionInterrupt |
|
5239 |
"{ Pragma: +optSpace }" |
|
5240 |
||
5241 |
"recursion limit (actually: stack overflow) interrupt. |
|
5242 |
This interrupt is triggered, when a process stack grows above |
|
5243 |
its stackLimit - usually, this leads into the debugger, but |
|
6175
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
5244 |
could be caught. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
5245 |
Under Unix, the stackLimit may be increased in the handler, |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
5246 |
and the exception can be resumed. |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
5247 |
Sorry, but under win32, the stack cannot grow, and the exception |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
5248 |
is not proceedable. |
10460 | 5249 |
At the time we arrive here, the system has still some stack |
6175
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
5250 |
as a reserve so we can continue to do some useful work, or cleanup, |
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
5251 |
or debug for a while. |
5755 | 5252 |
If the signal is ignored, and the stack continues to grow, there |
5253 |
will be a few more chances (and more interrupts) before the VM |
|
6175
e9970db3e02f
recursionInterrupt fixes for win32 (& comment changed)
Claus Gittinger <cg@exept.de>
parents:
6157
diff
changeset
|
5254 |
terminates the process." |
5755 | 5255 |
|
21646 | 5256 |
|con remaining sender nSkipped caller level| |
5755 | 5257 |
|
5258 |
(con := thisContext) isRecursive ifFalse:[ |
|
5259 |
"/ Processor activeProcess usedStackSize < Processor activeProcess maximumStackSize ifTrue:[ |
|
5260 |
"/ "/ mhmh - it hit me, but I am not responsible ... |
|
5261 |
"/ 'Stray recursionInterrupt ...' infoPrintCR. |
|
5262 |
"/ ^ self |
|
5263 |
"/ ]. |
|
20495 | 5264 |
ObjectMemory infoPrinting ifTrue:[ |
5265 |
level := 0. |
|
5266 |
caller := thisContext sender. |
|
5267 |
[caller notNil] whileTrue:[ |
|
5268 |
level := level + 1. |
|
5269 |
caller := caller sender. |
|
5270 |
]. |
|
5271 |
||
5272 |
'Object [info]: recursionInterrupt from:' errorPrintCR. |
|
5273 |
con := con sender. |
|
5274 |
remaining := 500. |
|
5275 |
[con notNil and:[remaining > 0]] whileTrue:[ |
|
5276 |
sender := con sender. |
|
21091 | 5277 |
RecursionInterruptSignal handle:[:ex | |
5278 |
] do:[ |
|
5279 |
'| ' _errorPrint. con fullPrint. |
|
5280 |
]. |
|
20495 | 5281 |
nSkipped := 0. |
5282 |
[sender notNil and:[sender sender notNil |
|
5283 |
and:[sender selector == con selector |
|
5284 |
and:[sender sender selector == con selector |
|
5285 |
and:[sender method == con method]]]]] whileTrue:[ |
|
5286 |
nSkipped := nSkipped + 1. |
|
5287 |
con := sender. |
|
5288 |
sender := con sender. |
|
5289 |
]. |
|
5290 |
nSkipped > 0 ifTrue:[ |
|
21090 | 5291 |
'| ... ***** ' _errorPrint. nSkipped _errorPrint. ' recursive contexts skipped *****' _errorPrintCR. |
20495 | 5292 |
]. |
5293 |
con := sender. |
|
5294 |
remaining := remaining - 1 |
|
5295 |
]. |
|
5296 |
]. |
|
5297 |
^ RecursionInterruptSignal raiseSignal |
|
5755 | 5298 |
] |
5299 |
||
21646 | 5300 |
"Modified: / 10-11-2001 / 15:15:56 / cg" |
5301 |
"Modified: / 15-03-2017 / 17:26:56 / stefan" |
|
5755 | 5302 |
! |
5303 |
||
5304 |
schedulerInterrupt |
|
5305 |
"{ Pragma: +optSpace }" |
|
5306 |
||
5307 |
"scheduler interrupt (supposed to be sent to Processor). |
|
5308 |
If we arrive here, either the Processor does not understand it, |
|
5309 |
or it has been set to nil. In any case, this is a sign of some |
|
5310 |
big trouble. Enter debugger." |
|
5311 |
||
5312 |
self error:'schedulerInterrupt - but no Processor' mayProceed:true |
|
5313 |
! |
|
5314 |
||
5315 |
signalInterrupt:signalNumber |
|
5316 |
"{ Pragma: +optSpace }" |
|
5317 |
||
20253 | 5318 |
"unix signal occurred - some signals are handled as Smalltalk Exceptions |
10016 | 5319 |
(SIGPIPE), others (SIGBUS) are rather fatal... |
11236
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
5320 |
In any case, IF a smalltalk-signal has been connected to the OS signal, that one is raised. |
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
5321 |
Otherwise, a dialog is shown, asking the user on how to handle the signal. |
5755 | 5322 |
TODO: add another argument, giving more detailed signal info (PC, VADDR, |
5323 |
exact cause etc.). This helps if segvs occur in primitive code. |
|
5324 |
Currently (temporary kludge), these are passed as global variables." |
|
5325 |
||
6537
7906825ad5c3
Do not allow to proceed in debugger on SIGSEGV
Stefan Vogel <sv@exept.de>
parents:
6533
diff
changeset
|
5326 |
|name here sig fatal titles actions badContext msg pc addr |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5327 |
action title screen| |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5328 |
|
13254 | 5329 |
thisContext isRecursive ifTrue:[ |
21150 | 5330 |
'Severe error: signalInterrupt while processing a signalInterrupt.' _errorPrintCR. |
5331 |
'Terminating process ' _errorPrint. Processor activeProcess _errorPrintCR. |
|
13710 | 5332 |
"/ GenericException handle:[:ex | |
5333 |
"/ "/ ignore any error during termination |
|
5334 |
"/ ] do:[ |
|
5335 |
"/ Processor activeProcess terminate. |
|
5336 |
"/ ]. |
|
20383 | 5337 |
MiniDebugger enter. |
5338 |
Processor activeProcess terminateNoSignal. |
|
13254 | 5339 |
]. |
5340 |
||
5755 | 5341 |
"if there has been an ST-signal installed, use it ..." |
5342 |
sig := OperatingSystem operatingSystemSignal:signalNumber. |
|
5343 |
sig notNil ifTrue:[ |
|
20383 | 5344 |
sig raiseSignalWith:signalNumber. |
5345 |
^ self. |
|
5755 | 5346 |
]. |
5347 |
||
5348 |
"/ if handled, raise OSSignalInterruptSignal |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
5349 |
OSSignalInterrupt isHandled ifTrue:[ |
20383 | 5350 |
OSSignalInterrupt raiseRequestWith:signalNumber. |
5351 |
^ self. |
|
10460 | 5352 |
]. |
5353 |
||
5354 |
" |
|
5355 |
special cases |
|
20383 | 5356 |
- SIGPWR: power failure - write a crash image and continue |
5357 |
- SIGHUP: hang up - write a crash image and exit |
|
10922 | 5358 |
" |
5359 |
(signalNumber == OperatingSystem sigPWR) ifTrue:[ |
|
20383 | 5360 |
SnapshotError ignoreIn:[ObjectMemory writeCrashImage]. |
5361 |
^ self. |
|
10922 | 5362 |
]. |
5363 |
(signalNumber == OperatingSystem sigHUP) ifTrue:[ |
|
20383 | 5364 |
SnapshotError ignoreIn:[ObjectMemory writeCrashImage]. |
5365 |
'Object [info]: exit due to hangup signal.' errorPrintCR. |
|
5366 |
Smalltalk exit:1. |
|
7031 | 5367 |
]. |
5856
6d3df9ad361e
save crash image when sigPWR or sigHUP arrives
Claus Gittinger <cg@exept.de>
parents:
5824
diff
changeset
|
5368 |
|
5755 | 5369 |
name := OperatingSystem nameForSignal:signalNumber. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5370 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5371 |
"if there is no screen at all, bring up a mini debugger" |
10460 | 5372 |
(Screen isNil |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5373 |
or:[(screen := Screen current) isNil |
6778
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
5374 |
or:[(screen := Screen default) isNil |
87e2d95ce8a4
Raise #drawingOnClosedDeviceSignal instead of #error
Stefan Vogel <sv@exept.de>
parents:
6764
diff
changeset
|
5375 |
or:[screen isOpen not]]]) ifTrue:[ |
20383 | 5376 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5377 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5378 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5379 |
"ungrab - in case it happened in a box/popupview |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5380 |
otherwise display stays locked" |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5381 |
screen ungrabPointer; ungrabKeyboard. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5382 |
|
7031 | 5383 |
here := thisContext. |
5384 |
badContext := here sender. "the context, in which the signal occurred" |
|
5385 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5386 |
"there is a screen. use it to bring up a box asking for what to do ..." |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5387 |
Screen currentScreenQuerySignal answer:screen do:[ |
20383 | 5388 |
" |
5389 |
SIGBUS, SIGSEGV and SIGILL do not make sense to ignore (i.e. continue) |
|
5390 |
since the system will retry the faulty instruction, which leads to |
|
5391 |
another signal - to avoid frustration, better not offer this option. |
|
5392 |
" |
|
5393 |
fatal := OperatingSystem isFatalSignal:signalNumber. |
|
5394 |
fatal ifTrue:[ |
|
5395 |
(Debugger isNil or:[here isRecursive]) ifTrue:[ |
|
5396 |
'Object [hard error]: signal ' errorPrint. signalNumber errorPrintCR. |
|
5397 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
|
5398 |
]. |
|
5399 |
" |
|
5400 |
a hard signal - go into debugger immediately |
|
5401 |
" |
|
5402 |
msg := 'OS-signal: ', name. |
|
5403 |
||
5404 |
"/ the IRQ-PC is passed as low-hi, to avoid the need |
|
5405 |
"/ to allocate a LargeInteger in the VM during signal |
|
5406 |
"/ time. I know, this is ugly. |
|
5407 |
||
5408 |
InterruptPcLow notNil ifTrue:[ |
|
5409 |
pc := InterruptPcLow + (InterruptPcHi bitShift:((SmallInteger maxBits + 1) // 2)). |
|
5410 |
pc ~~ 0 ifTrue:[ |
|
5411 |
msg := msg , ' PC=' , (pc printStringRadix:16) |
|
5412 |
]. |
|
5413 |
]. |
|
5414 |
InterruptAddrLow notNil ifTrue:[ |
|
5415 |
addr := InterruptAddrLow + (InterruptAddrHi bitShift:((SmallInteger maxBits + 1) // 2)). |
|
5416 |
addr ~~ 0 ifTrue:[ |
|
5417 |
msg := msg , ' ADDR=' , (addr printStringRadix:16) |
|
5418 |
]. |
|
5419 |
]. |
|
5420 |
Debugger enter:here withMessage:msg mayProceed:false. |
|
5421 |
"unreachable" |
|
5422 |
^ nil. |
|
5423 |
]. |
|
5424 |
||
5425 |
"if possible, open an option box asking the user what do. |
|
5426 |
Otherwise, start a debugger" |
|
5427 |
Dialog notNil ifTrue:[ |
|
5428 |
OperatingSystem isOSXlike ifTrue:[ |
|
5429 |
titles := #('Save crash image' 'Dump core' 'GDB' 'Exit ST/X' 'Debug'). |
|
5430 |
actions := #(save core gdb exit debug). |
|
5431 |
] ifFalse:[ |
|
5432 |
titles := #('Save crash image' 'Dump core' 'Exit ST/X' 'Debug'). |
|
5433 |
actions := #(save core exit debug). |
|
5434 |
]. |
|
5435 |
action := nil. |
|
5436 |
title := 'OS Signal caught (' , name, ')'. |
|
5437 |
title := (title , '\[in ST-process: ' , Processor activeProcess nameOrId ,']') withCRs. |
|
5438 |
||
5439 |
"/ if caught while in the scheduler or event dispatcher, |
|
5440 |
"/ a modal dialog is not possible ... |
|
5441 |
"/ (therefore, abort & return does not makes sense) |
|
5442 |
||
5443 |
Processor activeProcess isSystemProcess ifFalse:[ |
|
5444 |
titles := #('Abort') , titles. |
|
5445 |
actions := #(abort), actions. |
|
5446 |
||
5447 |
badContext canReturn ifTrue:[ |
|
5448 |
titles := #('Return') , titles. |
|
5449 |
actions := #(return), actions. |
|
5450 |
]. |
|
5451 |
]. |
|
5452 |
||
5453 |
fatal ifFalse:[ |
|
5454 |
titles := titles, #('Ignore'). |
|
5455 |
actions := actions , #(ignore). |
|
5456 |
]. |
|
5457 |
action := Dialog choose:title |
|
5458 |
labels:titles |
|
5459 |
values:actions |
|
5460 |
default:(fatal ifTrue:[nil] ifFalse:[#ignore]). |
|
5461 |
||
5462 |
"Dialog may fail (if system process), default action is debug" |
|
5463 |
action isEmptyOrNil ifTrue:[action := #debug]. |
|
5464 |
] ifFalse:[ |
|
5465 |
action := #debug. |
|
5466 |
]. |
|
5467 |
||
5468 |
action == #save ifTrue:[ |
|
5469 |
ObjectMemory writeCrashImage |
|
5470 |
]. |
|
5471 |
action == #gdb ifTrue:[ |
|
5472 |
OperatingSystem openTerminalWithCommand:('gdb -p %1' bindWith:OperatingSystem getProcessId) inBackground:true. |
|
5473 |
MiniDebugger enter. "/ to stop, so gdb can show where we are |
|
5474 |
AbortOperationRequest raise. |
|
5475 |
]. |
|
5476 |
action == #core ifTrue:[ |
|
5477 |
Smalltalk fatalAbort |
|
5478 |
]. |
|
5479 |
action == #exit ifTrue:[ |
|
5480 |
Smalltalk exit:10. |
|
5481 |
]. |
|
5482 |
action == #return ifTrue:[ |
|
5483 |
badContext return |
|
5484 |
]. |
|
5485 |
action == #abort ifTrue:[ |
|
5486 |
AbortOperationRequest raise. |
|
5487 |
]. |
|
5488 |
||
5489 |
action == #debug ifTrue:[ |
|
5490 |
Debugger isNil ifTrue:[ |
|
5491 |
^ self startMiniDebuggerOrExit:'OS-Signal (' , name, ')'. |
|
5492 |
]. |
|
5493 |
Debugger enter:here withMessage:('OS-Signal ', name) mayProceed:true. |
|
5494 |
]. |
|
5495 |
"action == #ignore" |
|
13261 | 5496 |
]. |
5497 |
||
13710 | 5498 |
"Modified: / 15-09-2011 / 16:38:14 / cg" |
5755 | 5499 |
! |
5500 |
||
5501 |
spyInterrupt |
|
5502 |
"{ Pragma: +optSpace }" |
|
5503 |
||
5504 |
"spy interrupt and no handler - enter debugger" |
|
5505 |
||
5506 |
self error:'spy Interrupt - but no handler' mayProceed:true |
|
5507 |
! |
|
5508 |
||
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5509 |
startMiniDebuggerOrExit:text |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5510 |
"some critical condition happened. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5511 |
Start a mini debugger or exit if none is present" |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5512 |
|
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5513 |
MiniDebugger isNil ifTrue:[ |
20535 | 5514 |
"a system without debugging facilities (i.e. a standalone system) |
5515 |
output a message and exit." |
|
5516 |
('Object [error]: exit due to ', text, ' - and no debugger.') errorPrintCR. |
|
5517 |
OperatingSystem exit:99. |
|
6388
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5518 |
]. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5519 |
MiniDebugger enterWithMessage:text mayProceed:true. |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5520 |
! |
41396e0cc89f
Fix #signalInterrupt: for multi-display and headless.
Stefan Vogel <sv@exept.de>
parents:
6328
diff
changeset
|
5521 |
|
5755 | 5522 |
timerInterrupt |
5523 |
"{ Pragma: +optSpace }" |
|
5524 |
||
5525 |
"timer interrupt and no handler - enter debugger" |
|
5526 |
||
5527 |
self error:'timer Interrupt - but no handler' mayProceed:true |
|
5528 |
! |
|
5529 |
||
5530 |
userInterrupt |
|
5531 |
"{ Pragma: +optSpace }" |
|
5532 |
||
5533 |
"user (^c) interrupt. |
|
5534 |
This is typically sent by the VM, when a ctrl-C is typed at the |
|
5535 |
controlling tty (i.e. in the xterm)." |
|
5536 |
||
20027 | 5537 |
UserInterrupt raiseRequest |
5538 |
! |
|
5539 |
||
5540 |
userInterruptIn:aContext from:originator |
|
5755 | 5541 |
"{ Pragma: +optSpace }" |
5542 |
||
5543 |
"user (^c) interrupt - enter debugger, but show aContext |
|
10460 | 5544 |
as top-context. |
5545 |
This is used to hide any intermediate scheduler contexts, |
|
5755 | 5546 |
in case of an interrupted process. Typically, this is sent by |
5547 |
the WindowGroup, when a keyboardEvent for the ctrl-C key is |
|
20027 | 5548 |
processed. |
20214 | 5549 |
Set the originator to distinguish UserInterrupts from controlling tty vs. |
20027 | 5550 |
UserInterrupt from a view." |
5755 | 5551 |
|
5552 |
<context: #return> |
|
5553 |
||
20027 | 5554 |
UserInterrupt raiseRequestWith:originator errorString:nil in:aContext |
5755 | 5555 |
|
5556 |
"Created: / 18.10.1996 / 20:46:04 / cg" |
|
5557 |
"Modified: / 20.10.1996 / 13:06:38 / cg" |
|
5558 |
"Modified: / 26.7.1999 / 10:58:49 / stefan" |
|
5559 |
! ! |
|
5560 |
||
5561 |
!Object methodsFor:'message sending'! |
|
5562 |
||
5563 |
perform:aSelector |
|
5564 |
"send the message aSelector to the receiver" |
|
5565 |
||
11335 | 5566 |
<resource: #skipInDebuggersWalkBack> |
5567 |
||
5755 | 5568 |
%{ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
5569 |
#ifdef __SCHTEAM__ |
18238 | 5570 |
return context.PERFORM(self, aSelector); |
18231 | 5571 |
#else |
5755 | 5572 |
REGISTER OBJ sel = aSelector; |
16588
eb24b473a3ba
Fix for bug in Object>>perform(with:(with:)) - care for nil or SmallInteger selectors.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16583
diff
changeset
|
5573 |
int hash0; |
5755 | 5574 |
|
5575 |
if (InterruptPending == nil) { |
|
20535 | 5576 |
struct inlineCache *pIlc; |
16169
5a4e80279be4
Object>>#perform:(with:(with:)): more performant implementation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16126
diff
changeset
|
5577 |
|
18231 | 5578 |
# define nways 2 |
5579 |
# define nilcs 131 |
|
5580 |
||
5581 |
# define SEL_AND_ILC_INIT_1(l) { { nil, nil } , { __ILCPERF0(l) , __ILCPERF0(l) } , 0 } |
|
5582 |
# define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
|
5583 |
# define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
|
5584 |
# define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
|
5585 |
# define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
|
5586 |
# define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5587 |
# define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5588 |
# define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
|
5589 |
# define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
|
5590 |
# define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
|
5591 |
||
5592 |
# define SEL_AND_ILC_INIT_131(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_1(l) |
|
16169
5a4e80279be4
Object>>#perform:(with:(with:)): more performant implementation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16126
diff
changeset
|
5593 |
|
20535 | 5594 |
static struct { OBJ sel[nways]; struct inlineCache ilc[nways]; int flip; } sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_131(@line) }; |
13416 | 5595 |
|
18231 | 5596 |
# undef SEL_AND_ILC_INIT_1 |
5597 |
# undef SEL_AND_ILC_INIT_2 |
|
5598 |
# undef SEL_AND_ILC_INIT_4 |
|
5599 |
# undef SEL_AND_ILC_INIT_8 |
|
5600 |
# undef SEL_AND_ILC_INIT_16 |
|
5601 |
# undef SEL_AND_ILC_INIT_32 |
|
5602 |
# undef SEL_AND_ILC_INIT_64 |
|
5603 |
# undef SEL_AND_ILC_INIT_128 |
|
5604 |
# undef SEL_AND_ILC_INIT_256 |
|
5605 |
||
5606 |
# undef SEL_AND_ILC_INIT_131 |
|
5607 |
# undef SEL_AND_ILC_INIT_257 |
|
5608 |
||
5609 |
# define TRY(n) \ |
|
20535 | 5610 |
if (sel == sel_and_ilc[hash0].sel[n]) { \ |
5611 |
pIlc = &sel_and_ilc[hash0].ilc[n]; \ |
|
5612 |
goto perform0_send_and_return; \ |
|
5613 |
} |
|
5614 |
||
5615 |
if (__isNonNilObject(sel)) { |
|
5616 |
hash0 = __MAKE_HASH__(__GET_HASH(sel)) % nilcs; |
|
5617 |
} else { |
|
5618 |
/* sel is either nil or smallint, use its value as hash */ |
|
5619 |
hash0 = (INT)sel % nilcs; |
|
5620 |
} |
|
5621 |
||
5622 |
TRY(0); |
|
5623 |
TRY(1); |
|
16169
5a4e80279be4
Object>>#perform:(with:(with:)): more performant implementation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16126
diff
changeset
|
5624 |
|
18231 | 5625 |
# undef TRY |
20535 | 5626 |
/*printf("Object >> #perform: #%s --> no PIC found\n", __symbolVal(aSelector));*/ |
5627 |
||
5628 |
pIlc = &sel_and_ilc[hash0].ilc[sel_and_ilc[hash0].flip]; |
|
5629 |
sel_and_ilc[hash0].sel[sel_and_ilc[hash0].flip] = sel; |
|
5630 |
sel_and_ilc[hash0].flip = (sel_and_ilc[hash0].flip + 1) % nways; |
|
5631 |
pIlc->ilc_func = __SEND0ADDR__; |
|
5632 |
if (pIlc->ilc_poly) { |
|
5633 |
__flushPolyCache(pIlc->ilc_poly); |
|
5634 |
pIlc->ilc_poly = 0; |
|
5635 |
} |
|
13416 | 5636 |
perform0_send_and_return: |
20535 | 5637 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc) ); |
5755 | 5638 |
} else { |
20535 | 5639 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
5640 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
5755 | 5641 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
5642 |
#endif /* not __SCHTEAM__ */ |
5755 | 5643 |
%}. |
5644 |
^ self perform:aSelector withArguments:#() |
|
5645 |
! |
|
5646 |
||
5647 |
perform:aSelector inClass:aClass withArguments:argArray |
|
10460 | 5648 |
"send the message aSelector with all args taken from argArray |
5755 | 5649 |
to the receiver as a super-send message. |
5650 |
This is actually more flexible than the normal super-send, since it allows |
|
5651 |
to execute a method in ANY superclass of the receiver (not just the |
|
5652 |
immediate superclass). |
|
10460 | 5653 |
Thus, it is (theoretically) possible to do |
20535 | 5654 |
'5 perform:#< inClass:Magnitude withArguments:#(6)' |
5755 | 5655 |
and evaluate Magnitudes compare method even if there was one in Number. |
5656 |
This method is used by the interpreter to evaluate super sends |
|
5657 |
and could be used for very special behavior (language extension ?). |
|
5658 |
||
5659 |
WARNING: this is an ST/X feature - probably not found in other smalltalks." |
|
5660 |
||
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5661 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 myClass| |
5755 | 5662 |
|
5663 |
" |
|
5664 |
check, if aClass is really a superclass of the receiver |
|
5665 |
" |
|
5769
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5666 |
myClass := self class. |
8f874be55bc9
lookup-class check in #perform:inClass was too strong.
Claus Gittinger <cg@exept.de>
parents:
5755
diff
changeset
|
5667 |
(myClass == aClass or:[myClass isSubclassOf:aClass]) ifFalse:[ |
20535 | 5668 |
self error:'lookup-class argument is not a superclass of the receiver'. |
5669 |
^ nil |
|
5755 | 5670 |
]. |
5671 |
%{ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
5672 |
#ifdef __SCHTEAM__ |
18231 | 5673 |
#else |
5755 | 5674 |
REGISTER OBJ *argP; |
5675 |
int nargs, i; |
|
5676 |
||
8934 | 5677 |
if (__isArrayLike(argArray)) { |
20535 | 5678 |
nargs = __arraySize(argArray); |
5679 |
argP = __arrayVal(argArray); |
|
5755 | 5680 |
} else { |
20535 | 5681 |
if (__isNonNilObject(argArray)) { |
5682 |
static struct inlineCache ilcSize = __ILC0(@line+1); |
|
5683 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
5684 |
if (!__isSmallInteger(numberOfArgs)) |
|
5685 |
goto bad; |
|
5686 |
nargs = __intVal(numberOfArgs); |
|
5687 |
argP = (OBJ *)(&a1); |
|
5688 |
for (i=1; i <= nargs; i++) { |
|
5689 |
*argP++ = __AT_(argArray, __mkSmallInteger(i)); |
|
5690 |
} |
|
5691 |
argP = (OBJ *)(&a1); |
|
5692 |
} else { |
|
5693 |
nargs = 0; |
|
5694 |
} |
|
5755 | 5695 |
} |
5696 |
switch (nargs) { |
|
20535 | 5697 |
case 0: |
5698 |
{ |
|
5699 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
5700 |
RETURN ( _SEND0(self, aSelector, aClass, &ilc0)); |
|
5701 |
} |
|
5702 |
||
5703 |
case 1: |
|
5704 |
{ |
|
5705 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
5706 |
RETURN ( _SEND1(self, aSelector, aClass, &ilc1, argP[0])); |
|
5707 |
} |
|
5708 |
||
5709 |
case 2: |
|
5710 |
{ |
|
5711 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
5712 |
RETURN ( _SEND2(self, aSelector, aClass, &ilc2, argP[0], argP[1])); |
|
5713 |
} |
|
5714 |
||
5715 |
case 3: |
|
5716 |
{ |
|
5717 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
5718 |
RETURN ( _SEND3(self, aSelector, aClass, &ilc3, |
|
5719 |
argP[0], argP[1], argP[2])); |
|
5720 |
} |
|
5721 |
||
5722 |
case 4: |
|
5723 |
{ |
|
5724 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
|
5725 |
RETURN ( _SEND4(self, aSelector, aClass, &ilc4, |
|
5726 |
argP[0], argP[1], argP[2], argP[3])); |
|
5727 |
} |
|
5728 |
||
5729 |
case 5: |
|
5730 |
{ |
|
5731 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
|
5732 |
RETURN ( _SEND5(self, aSelector, aClass, &ilc5, |
|
5733 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
5734 |
} |
|
5735 |
||
5736 |
case 6: |
|
5737 |
{ |
|
5738 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
|
5739 |
RETURN ( _SEND6(self, aSelector, aClass, &ilc6, |
|
5740 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5])); |
|
5741 |
} |
|
5742 |
||
5743 |
case 7: |
|
5744 |
{ |
|
5745 |
static struct inlineCache ilc7 = __DUMMYILCSELF7(@line+1); |
|
5746 |
RETURN ( _SEND7(self, aSelector, aClass, &ilc7, |
|
5747 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5748 |
argP[6])); |
|
5749 |
} |
|
5750 |
||
5751 |
case 8: |
|
5752 |
{ |
|
5753 |
static struct inlineCache ilc8 = __DUMMYILCSELF8(@line+1); |
|
5754 |
RETURN ( _SEND8(self, aSelector, aClass, &ilc8, |
|
5755 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5756 |
argP[6], argP[7])); |
|
5757 |
} |
|
5758 |
||
5759 |
case 9: |
|
5760 |
{ |
|
5761 |
static struct inlineCache ilc9 = __DUMMYILCSELF9(@line+1); |
|
5762 |
RETURN ( _SEND9(self, aSelector, aClass, &ilc9, |
|
5763 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5764 |
argP[6], argP[7], argP[8])); |
|
5765 |
} |
|
5766 |
||
5767 |
case 10: |
|
5768 |
{ |
|
5769 |
static struct inlineCache ilc10 = __DUMMYILCSELF10(@line+1); |
|
5770 |
RETURN ( _SEND10(self, aSelector, aClass, &ilc10, |
|
5771 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5772 |
argP[6], argP[7], argP[8], argP[9])); |
|
5773 |
} |
|
5774 |
||
5775 |
case 11: |
|
5776 |
{ |
|
5777 |
static struct inlineCache ilc11 = __DUMMYILCSELF11(@line+1); |
|
5778 |
RETURN ( _SEND11(self, aSelector, aClass, &ilc11, |
|
5779 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5780 |
argP[6], argP[7], argP[8], argP[9], argP[10])); |
|
5781 |
} |
|
5782 |
||
5783 |
case 12: |
|
5784 |
{ |
|
5785 |
static struct inlineCache ilc12 = __DUMMYILCSELF12(@line+1); |
|
5786 |
RETURN ( _SEND12(self, aSelector, aClass, &ilc12, |
|
5787 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5788 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5789 |
argP[11])); |
|
5790 |
} |
|
5791 |
||
5792 |
case 13: |
|
5793 |
{ |
|
5794 |
static struct inlineCache ilc13 = __DUMMYILCSELF13(@line+1); |
|
5795 |
RETURN ( _SEND13(self, aSelector, aClass, &ilc13, |
|
5796 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5797 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5798 |
argP[11], argP[12])); |
|
5799 |
} |
|
5800 |
||
5801 |
case 14: |
|
5802 |
{ |
|
5803 |
static struct inlineCache ilc14 = __DUMMYILCSELF14(@line+1); |
|
5804 |
RETURN ( _SEND14(self, aSelector, aClass, &ilc14, |
|
5805 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5806 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5807 |
argP[11], argP[12], argP[13])); |
|
5808 |
} |
|
5809 |
||
5810 |
case 15: |
|
5811 |
{ |
|
5812 |
static struct inlineCache ilc15 = __DUMMYILCSELF15(@line+1); |
|
5813 |
RETURN ( _SEND15(self, aSelector, aClass, &ilc15, |
|
5814 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5815 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5816 |
argP[11], argP[12], argP[13], argP[14])); |
|
5817 |
} |
|
5755 | 5818 |
|
18231 | 5819 |
# ifdef _SEND16 |
20535 | 5820 |
case 16: |
5821 |
{ |
|
5822 |
static struct inlineCache ilc16 = __DUMMYILCSELF16(@line+1); |
|
5823 |
RETURN ( _SEND16(self, aSelector, aClass, &ilc15, |
|
5824 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5825 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5826 |
argP[11], argP[12], argP[13], argP[14], argP[15])); |
|
5827 |
} |
|
18231 | 5828 |
# endif |
5829 |
# ifdef _SEND17 |
|
20535 | 5830 |
case 17: |
5831 |
{ |
|
5832 |
static struct inlineCache ilc17 = __DUMMYILCSELF17(@line+1); |
|
5833 |
RETURN ( _SEND17(self, aSelector, aClass, &ilc15, |
|
5834 |
argP[0], argP[1], argP[2], argP[3], argP[4], argP[5], |
|
5835 |
argP[6], argP[7], argP[8], argP[9], argP[10], |
|
5836 |
argP[11], argP[12], argP[13], argP[14], argP[15], argP[16])); |
|
5837 |
} |
|
18231 | 5838 |
# endif |
5755 | 5839 |
|
5840 |
||
5841 |
} |
|
5842 |
bad:; |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
5843 |
#endif /* not __SCHTEAM__ */ |
5755 | 5844 |
%}. |
5845 |
"/ arrive here, if bad number of arguments (too many) |
|
5846 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
5847 |
||
5848 |
^ self primitiveFailed |
|
5849 |
! |
|
5850 |
||
5851 |
perform:aSelector with:arg |
|
5852 |
"send the one-arg-message aSelector to the receiver" |
|
5853 |
||
5854 |
%{ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
5855 |
#ifdef __SCHTEAM__ |
18238 | 5856 |
return context.PERFORM_WITH(self, aSelector, arg); |
18231 | 5857 |
#else |
5755 | 5858 |
REGISTER OBJ sel = aSelector; |
16588
eb24b473a3ba
Fix for bug in Object>>perform(with:(with:)) - care for nil or SmallInteger selectors.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16583
diff
changeset
|
5859 |
int hash0; |
5755 | 5860 |
|
5861 |
if (InterruptPending == nil) { |
|
20535 | 5862 |
struct inlineCache *pIlc; |
18231 | 5863 |
# undef nways |
5864 |
# define nways 2 |
|
5865 |
# undef nilcs |
|
5866 |
# define nilcs 131 |
|
5867 |
||
5868 |
# define SEL_AND_ILC_INIT_1(l) { { nil, nil } , { __ILCPERF1(l) , __ILCPERF1(l) } , 0 } |
|
5869 |
# define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
|
5870 |
# define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
|
5871 |
# define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
|
5872 |
# define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
|
5873 |
# define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5874 |
# define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5875 |
# define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
|
5876 |
# define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
|
5877 |
# define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
|
5878 |
||
5879 |
# define SEL_AND_ILC_INIT_131(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_1(l) |
|
16169
5a4e80279be4
Object>>#perform:(with:(with:)): more performant implementation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16126
diff
changeset
|
5880 |
|
20535 | 5881 |
static struct { OBJ sel[nways]; struct inlineCache ilc[nways]; int flip; } sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_131(@line) }; |
13416 | 5882 |
|
18231 | 5883 |
# undef SEL_AND_ILC_INIT_1 |
5884 |
# undef SEL_AND_ILC_INIT_2 |
|
5885 |
# undef SEL_AND_ILC_INIT_4 |
|
5886 |
# undef SEL_AND_ILC_INIT_8 |
|
5887 |
# undef SEL_AND_ILC_INIT_16 |
|
5888 |
# undef SEL_AND_ILC_INIT_32 |
|
5889 |
# undef SEL_AND_ILC_INIT_64 |
|
5890 |
# undef SEL_AND_ILC_INIT_128 |
|
5891 |
# undef SEL_AND_ILC_INIT_256 |
|
5892 |
||
5893 |
# undef SEL_AND_ILC_INIT_131 |
|
5894 |
# undef SEL_AND_ILC_INIT_257 |
|
5895 |
||
5896 |
# define TRY(n) \ |
|
20535 | 5897 |
if (sel == sel_and_ilc[hash0].sel[n]) { \ |
5898 |
pIlc = &sel_and_ilc[hash0].ilc[n]; \ |
|
5899 |
goto perform1_send_and_return; \ |
|
5900 |
} |
|
5901 |
||
5902 |
if (__isNonNilObject(sel)) { |
|
5903 |
hash0 = __MAKE_HASH__(__GET_HASH(sel)) % nilcs; |
|
5904 |
} else { |
|
5905 |
/* sel is either nil or smallint, use its value as hash */ |
|
5906 |
hash0 = (INT)sel % nilcs; |
|
5907 |
} |
|
5908 |
||
5909 |
TRY(0); |
|
5910 |
TRY(1); |
|
16169
5a4e80279be4
Object>>#perform:(with:(with:)): more performant implementation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16126
diff
changeset
|
5911 |
|
18231 | 5912 |
# undef TRY |
20535 | 5913 |
/*printf("Object >> #perform: #%s --> no PIC found\n", __symbolVal(aSelector));*/ |
5914 |
||
5915 |
pIlc = &sel_and_ilc[hash0].ilc[sel_and_ilc[hash0].flip]; |
|
5916 |
sel_and_ilc[hash0].sel[sel_and_ilc[hash0].flip] = sel; |
|
5917 |
sel_and_ilc[hash0].flip = (sel_and_ilc[hash0].flip + 1) % nways; |
|
5918 |
pIlc->ilc_func = __SEND1ADDR__; |
|
5919 |
if (pIlc->ilc_poly) { |
|
5920 |
__flushPolyCache(pIlc->ilc_poly); |
|
5921 |
pIlc->ilc_poly = 0; |
|
5922 |
} |
|
16169
5a4e80279be4
Object>>#perform:(with:(with:)): more performant implementation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16126
diff
changeset
|
5923 |
|
13416 | 5924 |
perform1_send_and_return: |
20535 | 5925 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc, arg) ); |
5755 | 5926 |
} else { |
20535 | 5927 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
5928 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, arg)); |
|
5755 | 5929 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
5930 |
#endif /* not __SCHTEAM__ */ |
5755 | 5931 |
%}. |
5932 |
^ self perform:aSelector withArguments:(Array with:arg) |
|
5933 |
! |
|
5934 |
||
5935 |
perform:aSelector with:arg1 with:arg2 |
|
5936 |
"send the two-arg-message aSelector to the receiver" |
|
5937 |
||
5938 |
%{ |
|
18263 | 5939 |
#ifdef __SCHTEAM__ |
5940 |
return context.PERFORM_WITH2(self, aSelector, arg1, arg2); |
|
5941 |
#else |
|
13416 | 5942 |
REGISTER OBJ sel = aSelector; |
5755 | 5943 |
struct inlineCache *pIlc; |
16588
eb24b473a3ba
Fix for bug in Object>>perform(with:(with:)) - care for nil or SmallInteger selectors.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16583
diff
changeset
|
5944 |
int hash0; |
5755 | 5945 |
|
5946 |
if (InterruptPending == nil) { |
|
18231 | 5947 |
# undef nways |
5948 |
# define nways 2 |
|
5949 |
# undef nilcs |
|
5950 |
# define nilcs 131 |
|
5951 |
||
5952 |
# define SEL_AND_ILC_INIT_1(l) { { nil, nil } , { __ILCPERF2(l) , __ILCPERF2(l) } , 0 } |
|
5953 |
# define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
|
5954 |
# define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
|
5955 |
# define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
|
5956 |
# define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
|
5957 |
# define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5958 |
# define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
5959 |
# define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
|
5960 |
# define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
|
5961 |
# define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
|
5962 |
||
5963 |
# define SEL_AND_ILC_INIT_131(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_1(l) |
|
16169
5a4e80279be4
Object>>#perform:(with:(with:)): more performant implementation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16126
diff
changeset
|
5964 |
|
20535 | 5965 |
static struct { OBJ sel[nways]; struct inlineCache ilc[nways]; int flip; } sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_131(@line) }; |
13416 | 5966 |
|
18231 | 5967 |
# undef SEL_AND_ILC_INIT_1 |
5968 |
# undef SEL_AND_ILC_INIT_2 |
|
5969 |
# undef SEL_AND_ILC_INIT_4 |
|
5970 |
# undef SEL_AND_ILC_INIT_8 |
|
5971 |
# undef SEL_AND_ILC_INIT_16 |
|
5972 |
# undef SEL_AND_ILC_INIT_32 |
|
5973 |
# undef SEL_AND_ILC_INIT_64 |
|
5974 |
# undef SEL_AND_ILC_INIT_128 |
|
5975 |
# undef SEL_AND_ILC_INIT_256 |
|
5976 |
||
5977 |
# undef SEL_AND_ILC_INIT_131 |
|
5978 |
# undef SEL_AND_ILC_INIT_257 |
|
5979 |
||
5980 |
# define TRY(n) \ |
|
20535 | 5981 |
if (sel == sel_and_ilc[hash0].sel[n]) { \ |
5982 |
pIlc = &sel_and_ilc[hash0].ilc[n]; \ |
|
5983 |
goto perform2_send_and_return; \ |
|
5984 |
} |
|
5985 |
||
5986 |
if (__isNonNilObject(sel)) { |
|
5987 |
hash0 = __MAKE_HASH__(__GET_HASH(sel)) % nilcs; |
|
5988 |
} else { |
|
5989 |
/* sel is either nil or smallint, use its value as hash */ |
|
5990 |
hash0 = (INT)sel % nilcs; |
|
5991 |
} |
|
5992 |
||
5993 |
TRY(0); |
|
5994 |
TRY(1); |
|
16169
5a4e80279be4
Object>>#perform:(with:(with:)): more performant implementation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16126
diff
changeset
|
5995 |
|
18231 | 5996 |
# undef TRY |
20535 | 5997 |
/*printf("Object >> #perform: #%s --> no PIC found\n", __symbolVal(aSelector));*/ |
5998 |
||
5999 |
pIlc = &sel_and_ilc[hash0].ilc[sel_and_ilc[hash0].flip]; |
|
6000 |
sel_and_ilc[hash0].sel[sel_and_ilc[hash0].flip] = sel; |
|
6001 |
sel_and_ilc[hash0].flip = (sel_and_ilc[hash0].flip + 1) % nways; |
|
6002 |
pIlc->ilc_func = __SEND2ADDR__; |
|
6003 |
if (pIlc->ilc_poly) { |
|
6004 |
__flushPolyCache(pIlc->ilc_poly); |
|
6005 |
pIlc->ilc_poly = 0; |
|
6006 |
} |
|
16169
5a4e80279be4
Object>>#perform:(with:(with:)): more performant implementation
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16126
diff
changeset
|
6007 |
|
13416 | 6008 |
perform2_send_and_return: |
20535 | 6009 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2) ); |
5755 | 6010 |
} else { |
20535 | 6011 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
6012 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, arg1, arg2)); |
|
5755 | 6013 |
} |
18263 | 6014 |
#endif /* not SCHTEAM */ |
5755 | 6015 |
%}. |
6016 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2) |
|
6017 |
! |
|
6018 |
||
6019 |
perform:aSelector with:arg1 with:arg2 with:arg3 |
|
6020 |
"send the three-arg-message aSelector to the receiver" |
|
6021 |
||
6022 |
%{ |
|
18263 | 6023 |
#ifdef __SCHTEAM__ |
6024 |
return context.PERFORM_WITH3(self, aSelector, arg1, arg2, arg3); |
|
6025 |
#else |
|
5755 | 6026 |
struct inlineCache *pIlc; |
6027 |
static struct inlineCache ilc_0 = __ILCPERF3(@line); |
|
6028 |
static struct inlineCache ilc_1 = __ILCPERF3(@line); |
|
6029 |
static OBJ last_0 = nil; |
|
6030 |
static OBJ last_1 = nil; |
|
18185 | 6031 |
static int flip = 0; |
5755 | 6032 |
|
6033 |
if (InterruptPending == nil) { |
|
20535 | 6034 |
if (aSelector != last_0) { |
6035 |
if (aSelector != last_1) { |
|
6036 |
if (flip) { |
|
6037 |
pIlc = &ilc_0; |
|
6038 |
flip = 0; |
|
6039 |
last_0 = aSelector; |
|
6040 |
} else { |
|
6041 |
pIlc = &ilc_1; |
|
6042 |
flip = 1; |
|
6043 |
last_1 = aSelector; |
|
6044 |
} |
|
6045 |
pIlc->ilc_func = __SEND3ADDR__; |
|
6046 |
if (pIlc->ilc_poly) { |
|
6047 |
__flushPolyCache(pIlc->ilc_poly); |
|
6048 |
pIlc->ilc_poly = 0; |
|
6049 |
} |
|
6050 |
} else { |
|
6051 |
pIlc = &ilc_1; |
|
6052 |
} |
|
6053 |
} else { |
|
6054 |
pIlc = &ilc_0; |
|
6055 |
} |
|
6056 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, arg1, arg2, arg3) ); |
|
5755 | 6057 |
} else { |
20535 | 6058 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
6059 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, arg1, arg2, arg3)); |
|
5755 | 6060 |
} |
18263 | 6061 |
#endif /* not SCHTEAM */ |
5755 | 6062 |
%}. |
6063 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3) |
|
6064 |
||
6065 |
! |
|
6066 |
||
6067 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 |
|
6068 |
"send the four-arg-message aSelector to the receiver" |
|
6069 |
||
6070 |
%{ |
|
6071 |
struct inlineCache *pIlc; |
|
6072 |
static struct inlineCache ilc_0 = __ILCPERF4(@line); |
|
6073 |
static struct inlineCache ilc_1 = __ILCPERF4(@line); |
|
6074 |
static OBJ last_0 = nil; |
|
6075 |
static OBJ last_1 = nil; |
|
18185 | 6076 |
static int flip = 0; |
5755 | 6077 |
|
6078 |
if (InterruptPending == nil) { |
|
20535 | 6079 |
if (aSelector != last_0) { |
6080 |
if (aSelector != last_1) { |
|
6081 |
if (flip) { |
|
6082 |
pIlc = &ilc_0; |
|
6083 |
flip = 0; |
|
6084 |
last_0 = aSelector; |
|
6085 |
} else { |
|
6086 |
pIlc = &ilc_1; |
|
6087 |
flip = 1; |
|
6088 |
last_1 = aSelector; |
|
6089 |
} |
|
6090 |
pIlc->ilc_func = __SEND4ADDR__; |
|
6091 |
if (pIlc->ilc_poly) { |
|
6092 |
__flushPolyCache(pIlc->ilc_poly); |
|
6093 |
pIlc->ilc_poly = 0; |
|
6094 |
} |
|
6095 |
} else { |
|
6096 |
pIlc = &ilc_1; |
|
6097 |
} |
|
6098 |
} else { |
|
6099 |
pIlc = &ilc_0; |
|
6100 |
} |
|
6101 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
6102 |
arg1, arg2, arg3, arg4) ); |
|
5755 | 6103 |
} else { |
20535 | 6104 |
static struct inlineCache ilc4 = __DUMMYILCSELF4(@line+1); |
6105 |
RETURN (_SEND4(self, aSelector, nil, &ilc4, |
|
6106 |
arg1, arg2, arg3, arg4)); |
|
5755 | 6107 |
} |
6108 |
%}. |
|
6109 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
6110 |
||
6111 |
! |
|
6112 |
||
6113 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 |
|
6114 |
"send the five-arg-message aSelector to the receiver" |
|
6115 |
||
6116 |
%{ |
|
6117 |
struct inlineCache *pIlc; |
|
6118 |
static struct inlineCache ilc_0 = __ILCPERF5(@line); |
|
6119 |
static struct inlineCache ilc_1 = __ILCPERF5(@line); |
|
6120 |
static OBJ last_0 = nil; |
|
6121 |
static OBJ last_1 = nil; |
|
18185 | 6122 |
static int flip = 0; |
5755 | 6123 |
|
6124 |
if (InterruptPending == nil) { |
|
20535 | 6125 |
if (aSelector != last_0) { |
6126 |
if (aSelector != last_1) { |
|
6127 |
if (flip) { |
|
6128 |
pIlc = &ilc_0; |
|
6129 |
flip = 0; |
|
6130 |
last_0 = aSelector; |
|
6131 |
} else { |
|
6132 |
pIlc = &ilc_1; |
|
6133 |
flip = 1; |
|
6134 |
last_1 = aSelector; |
|
6135 |
} |
|
6136 |
pIlc->ilc_func = __SEND5ADDR__; |
|
6137 |
if (pIlc->ilc_poly) { |
|
6138 |
__flushPolyCache(pIlc->ilc_poly); |
|
6139 |
pIlc->ilc_poly = 0; |
|
6140 |
} |
|
6141 |
} else { |
|
6142 |
pIlc = &ilc_1; |
|
6143 |
} |
|
6144 |
} else { |
|
6145 |
pIlc = &ilc_0; |
|
6146 |
} |
|
6147 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
6148 |
arg1, arg2, arg3, arg4, arg5) ); |
|
5755 | 6149 |
} else { |
20535 | 6150 |
static struct inlineCache ilc5 = __DUMMYILCSELF5(@line+1); |
6151 |
RETURN (_SEND5(self, aSelector, nil, &ilc5, |
|
6152 |
arg1, arg2, arg3, arg4, arg5)); |
|
5755 | 6153 |
} |
6154 |
%}. |
|
6155 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
20535 | 6156 |
with:arg5) |
5755 | 6157 |
|
6158 |
! |
|
6159 |
||
6160 |
perform:aSelector with:arg1 with:arg2 with:arg3 with:arg4 with:arg5 with:arg6 |
|
6161 |
"send the six-arg-message aSelector to the receiver" |
|
6162 |
||
6163 |
%{ |
|
6164 |
struct inlineCache *pIlc; |
|
6165 |
static struct inlineCache ilc_0 = __ILCPERF6(@line); |
|
6166 |
static struct inlineCache ilc_1 = __ILCPERF6(@line); |
|
6167 |
static OBJ last_0 = nil; |
|
6168 |
static OBJ last_1 = nil; |
|
18185 | 6169 |
static int flip = 0; |
5755 | 6170 |
|
6171 |
if (InterruptPending == nil) { |
|
20535 | 6172 |
if (aSelector != last_0) { |
6173 |
if (aSelector != last_1) { |
|
6174 |
if (flip) { |
|
6175 |
pIlc = &ilc_0; |
|
6176 |
flip = 0; |
|
6177 |
last_0 = aSelector; |
|
6178 |
} else { |
|
6179 |
pIlc = &ilc_1; |
|
6180 |
flip = 1; |
|
6181 |
last_1 = aSelector; |
|
6182 |
} |
|
6183 |
pIlc->ilc_func = __SEND6ADDR__; |
|
6184 |
if (pIlc->ilc_poly) { |
|
6185 |
__flushPolyCache(pIlc->ilc_poly); |
|
6186 |
pIlc->ilc_poly = 0; |
|
6187 |
} |
|
6188 |
} else { |
|
6189 |
pIlc = &ilc_1; |
|
6190 |
} |
|
6191 |
} else { |
|
6192 |
pIlc = &ilc_0; |
|
6193 |
} |
|
6194 |
||
6195 |
RETURN ( (*(pIlc->ilc_func))(self, aSelector, nil, pIlc, |
|
6196 |
arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
5755 | 6197 |
} else { |
20535 | 6198 |
static struct inlineCache ilc6 = __DUMMYILCSELF6(@line+1); |
6199 |
RETURN (_SEND6(self, aSelector, nil, &ilc6, |
|
6200 |
arg1, arg2, arg3, arg4, arg5, arg6)); |
|
5755 | 6201 |
} |
6202 |
%}. |
|
6203 |
^ self perform:aSelector withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4 |
|
20535 | 6204 |
with:arg5 with:arg6) |
5755 | 6205 |
|
6206 |
! |
|
6207 |
||
6208 |
perform:aSelector withArguments:argArray |
|
10460 | 6209 |
"send the message aSelector with all args taken from argArray |
5755 | 6210 |
to the receiver." |
6211 |
||
6212 |
|numberOfArgs a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
|
6213 |
||
6214 |
%{ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
6215 |
#ifdef __SCHTEAM__ |
18238 | 6216 |
return context.PERFORM_WITH_ARGUMENTS(self, aSelector, argArray); |
6217 |
#else |
|
5755 | 6218 |
REGISTER OBJ *argP; |
6219 |
int nargs; |
|
6220 |
OBJ l; |
|
6221 |
||
8934 | 6222 |
if (__isArrayLike(argArray)) { |
20535 | 6223 |
nargs = __arraySize(argArray); |
6224 |
argP = __arrayVal(argArray); |
|
5755 | 6225 |
} else { |
20535 | 6226 |
if (__isNonNilObject(argArray)) { |
6227 |
static struct inlineCache ilcSize = __ILC0(@line); |
|
6228 |
int i; |
|
6229 |
||
6230 |
numberOfArgs = (*ilcSize.ilc_func)(argArray, @symbol(size), nil, &ilcSize); |
|
6231 |
if (!__isSmallInteger(numberOfArgs)) |
|
6232 |
goto bad; |
|
6233 |
nargs = __intVal(numberOfArgs); |
|
6234 |
argP = (OBJ *)(&a1); |
|
6235 |
for (i=1; i <= nargs; i++) { |
|
6236 |
*argP++ = __AT_(argArray, __mkSmallInteger(i)); |
|
6237 |
} |
|
6238 |
argP = (OBJ *)(&a1); |
|
6239 |
} else { |
|
6240 |
nargs = 0; |
|
6241 |
} |
|
5755 | 6242 |
} |
6243 |
switch (nargs) { |
|
20535 | 6244 |
case 0: |
6245 |
if (InterruptPending == nil) { |
|
6246 |
static OBJ last0_0 = nil; static struct inlineCache ilc0_0 = __ILCPERF0(@line); |
|
6247 |
static OBJ last0_1 = nil; static struct inlineCache ilc0_1 = __ILCPERF0(@line); |
|
6248 |
static OBJ last0_2 = nil; static struct inlineCache ilc0_2 = __ILCPERF0(@line); |
|
6249 |
static OBJ last0_3 = nil; static struct inlineCache ilc0_3 = __ILCPERF0(@line); |
|
6250 |
static int flip0 = 0; |
|
6251 |
struct inlineCache *pIlc; |
|
6252 |
||
6253 |
if (aSelector == last0_0) { |
|
6254 |
pIlc = &ilc0_0; |
|
6255 |
} else if (aSelector == last0_1) { |
|
6256 |
pIlc = &ilc0_1; |
|
6257 |
} else if (aSelector == last0_2) { |
|
6258 |
pIlc = &ilc0_2; |
|
6259 |
} else if (aSelector == last0_3) { |
|
6260 |
pIlc = &ilc0_3; |
|
6261 |
} else { |
|
6262 |
if (flip0 == 0) { |
|
6263 |
pIlc = &ilc0_0; |
|
6264 |
flip0 = 1; |
|
6265 |
last0_0 = aSelector; |
|
6266 |
} else if (flip0 == 1) { |
|
6267 |
pIlc = &ilc0_1; |
|
6268 |
flip0 = 2; |
|
6269 |
last0_1 = aSelector; |
|
6270 |
} else if (flip0 == 2) { |
|
6271 |
pIlc = &ilc0_2; |
|
6272 |
flip0 = 3; |
|
6273 |
last0_2 = aSelector; |
|
6274 |
} else { |
|
6275 |
pIlc = &ilc0_3; |
|
6276 |
flip0 = 0; |
|
6277 |
last0_3 = aSelector; |
|
6278 |
} |
|
6279 |
||
6280 |
pIlc->ilc_func = __SEND0ADDR__; |
|
6281 |
if (pIlc->ilc_poly) { |
|
6282 |
__flushPolyCache(pIlc->ilc_poly); |
|
6283 |
pIlc->ilc_poly = 0; |
|
6284 |
} |
|
6285 |
} |
|
6286 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc)); |
|
6287 |
} else { |
|
6288 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
|
6289 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
6290 |
} |
|
6291 |
||
6292 |
case 1: |
|
6293 |
if (InterruptPending == nil) { |
|
6294 |
static OBJ last1_0 = nil; static struct inlineCache ilc1_0 = __ILCPERF1(@line); |
|
6295 |
static OBJ last1_1 = nil; static struct inlineCache ilc1_1 = __ILCPERF1(@line); |
|
6296 |
static OBJ last1_2 = nil; static struct inlineCache ilc1_2 = __ILCPERF1(@line); |
|
6297 |
static OBJ last1_3 = nil; static struct inlineCache ilc1_3 = __ILCPERF1(@line); |
|
6298 |
static int flip1 = 0; |
|
6299 |
struct inlineCache *pIlc; |
|
6300 |
||
6301 |
if (aSelector == last1_0) { |
|
6302 |
pIlc = &ilc1_0; |
|
6303 |
} else if (aSelector == last1_1) { |
|
6304 |
pIlc = &ilc1_1; |
|
6305 |
} else if (aSelector == last1_2) { |
|
6306 |
pIlc = &ilc1_2; |
|
6307 |
} else if (aSelector == last1_3) { |
|
6308 |
pIlc = &ilc1_3; |
|
6309 |
} else { |
|
6310 |
if (flip1 == 0) { |
|
6311 |
pIlc = &ilc1_0; |
|
6312 |
flip1 = 1; |
|
6313 |
last1_0 = aSelector; |
|
6314 |
} else if (flip1 == 1) { |
|
6315 |
pIlc = &ilc1_1; |
|
6316 |
flip1 = 2; |
|
6317 |
last1_1 = aSelector; |
|
6318 |
} else if (flip1 == 2) { |
|
6319 |
pIlc = &ilc1_2; |
|
6320 |
flip1 = 3; |
|
6321 |
last1_2 = aSelector; |
|
6322 |
} else { |
|
6323 |
pIlc = &ilc1_3; |
|
6324 |
flip1 = 0; |
|
6325 |
last1_3 = aSelector; |
|
6326 |
} |
|
6327 |
||
6328 |
pIlc->ilc_func = __SEND1ADDR__; |
|
6329 |
if (pIlc->ilc_poly) { |
|
6330 |
__flushPolyCache(pIlc->ilc_poly); |
|
6331 |
pIlc->ilc_poly = 0; |
|
6332 |
} |
|
6333 |
} |
|
6334 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0])); |
|
6335 |
} else { |
|
6336 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
|
6337 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, argP[0])); |
|
6338 |
} |
|
6339 |
||
6340 |
case 2: |
|
6341 |
if (InterruptPending == nil) { |
|
6342 |
static OBJ last2_0 = nil; static struct inlineCache ilc2_0 = __ILCPERF2(@line); |
|
6343 |
static OBJ last2_1 = nil; static struct inlineCache ilc2_1 = __ILCPERF2(@line); |
|
6344 |
static int flip2 = 0; |
|
6345 |
struct inlineCache *pIlc; |
|
6346 |
||
6347 |
if (aSelector == last2_0) { |
|
6348 |
pIlc = &ilc2_0; |
|
6349 |
} else if (aSelector == last2_1) { |
|
6350 |
pIlc = &ilc2_1; |
|
6351 |
} else { |
|
6352 |
if (flip2 == 0) { |
|
6353 |
pIlc = &ilc2_0; |
|
6354 |
flip2 = 1; |
|
6355 |
last2_0 = aSelector; |
|
6356 |
} else { |
|
6357 |
pIlc = &ilc2_1; |
|
6358 |
flip2 = 0; |
|
6359 |
last2_1 = aSelector; |
|
6360 |
} |
|
6361 |
||
6362 |
pIlc->ilc_func = __SEND2ADDR__; |
|
6363 |
if (pIlc->ilc_poly) { |
|
6364 |
__flushPolyCache(pIlc->ilc_poly); |
|
6365 |
pIlc->ilc_poly = 0; |
|
6366 |
} |
|
6367 |
} |
|
6368 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1])); |
|
6369 |
} else { |
|
6370 |
static struct inlineCache ilc2 = __DUMMYILCSELF2(@line+1); |
|
6371 |
RETURN (_SEND2(self, aSelector, nil, &ilc2, argP[0], argP[1])); |
|
6372 |
} |
|
6373 |
||
6374 |
case 3: |
|
6375 |
if (InterruptPending == nil) { |
|
6376 |
static OBJ last3_0 = nil; static struct inlineCache ilc3_0 = __ILCPERF3(@line); |
|
6377 |
static OBJ last3_1 = nil; static struct inlineCache ilc3_1 = __ILCPERF3(@line); |
|
6378 |
static int flip3 = 0; |
|
6379 |
struct inlineCache *pIlc; |
|
6380 |
||
6381 |
if (aSelector == last3_0) { |
|
6382 |
pIlc = &ilc3_0; |
|
6383 |
} else if (aSelector == last3_1) { |
|
6384 |
pIlc = &ilc3_1; |
|
6385 |
} else { |
|
6386 |
if (flip3 == 0) { |
|
6387 |
pIlc = &ilc3_0; |
|
6388 |
flip3 = 1; |
|
6389 |
last3_0 = aSelector; |
|
6390 |
} else { |
|
6391 |
pIlc = &ilc3_1; |
|
6392 |
flip3 = 0; |
|
6393 |
last3_1 = aSelector; |
|
6394 |
} |
|
6395 |
||
6396 |
pIlc->ilc_func = __SEND3ADDR__; |
|
6397 |
if (pIlc->ilc_poly) { |
|
6398 |
__flushPolyCache(pIlc->ilc_poly); |
|
6399 |
pIlc->ilc_poly = 0; |
|
6400 |
} |
|
6401 |
} |
|
6402 |
RETURN ((*pIlc->ilc_func)(self, aSelector, nil, pIlc, argP[0], argP[1], argP[2])); |
|
6403 |
} else { |
|
6404 |
static struct inlineCache ilc3 = __DUMMYILCSELF3(@line+1); |
|
6405 |
RETURN (_SEND3(self, aSelector, nil, &ilc3, argP[0], argP[1], argP[2])); |
|
6406 |
} |
|
6407 |
||
6408 |
case 4: |
|
6409 |
{ |
|
6410 |
static OBJ last4 = nil; static struct inlineCache ilc4 = __ILCPERF4(@line); |
|
6411 |
||
6412 |
if ((InterruptPending != nil) || (aSelector != last4)) { |
|
6413 |
ilc4.ilc_func = __SEND4ADDR__; |
|
6414 |
if (ilc4.ilc_poly) { |
|
6415 |
__flushPolyCache(ilc4.ilc_poly); |
|
6416 |
ilc4.ilc_poly = 0; |
|
6417 |
} |
|
6418 |
last4 = aSelector; |
|
6419 |
} |
|
6420 |
RETURN ( (*ilc4.ilc_func)(self, aSelector, nil, &ilc4, |
|
6421 |
argP[0], argP[1], argP[2], argP[3])); |
|
6422 |
} |
|
6423 |
||
6424 |
case 5: |
|
6425 |
{ |
|
6426 |
static OBJ last5 = nil; static struct inlineCache ilc5 = __ILCPERF5(@line); |
|
6427 |
||
6428 |
if ((InterruptPending != nil) || (aSelector != last5)) { |
|
6429 |
ilc5.ilc_func = __SEND5ADDR__; |
|
6430 |
if (ilc5.ilc_poly) { |
|
6431 |
__flushPolyCache(ilc5.ilc_poly); |
|
6432 |
ilc5.ilc_poly = 0; |
|
6433 |
} |
|
6434 |
last5 = aSelector; |
|
6435 |
} |
|
6436 |
RETURN ( (*ilc5.ilc_func)(self, aSelector, nil, &ilc5, |
|
6437 |
argP[0], argP[1], argP[2], argP[3], argP[4])); |
|
6438 |
} |
|
6439 |
||
6440 |
case 6: |
|
6441 |
{ |
|
6442 |
static OBJ last6 = nil; static struct inlineCache ilc6 = __ILCPERF6(@line); |
|
6443 |
||
6444 |
if ((InterruptPending != nil) || (aSelector != last6)) { |
|
6445 |
ilc6.ilc_func = __SEND6ADDR__; |
|
6446 |
if (ilc6.ilc_poly) { |
|
6447 |
__flushPolyCache(ilc6.ilc_poly); |
|
6448 |
ilc6.ilc_poly = 0; |
|
6449 |
} |
|
6450 |
last6 = aSelector; |
|
6451 |
} |
|
6452 |
RETURN ( (*ilc6.ilc_func)(self, aSelector, nil, &ilc6, |
|
6453 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6454 |
argP[5])); |
|
6455 |
} |
|
6456 |
||
6457 |
case 7: |
|
6458 |
{ |
|
6459 |
static OBJ last7 = nil; static struct inlineCache ilc7 = __ILCPERF7(@line); |
|
6460 |
||
6461 |
if ((InterruptPending != nil) || (aSelector != last7)) { |
|
6462 |
ilc7.ilc_func = __SEND7ADDR__; |
|
6463 |
if (ilc7.ilc_poly) { |
|
6464 |
__flushPolyCache(ilc7.ilc_poly); |
|
6465 |
ilc7.ilc_poly = 0; |
|
6466 |
} |
|
6467 |
last7 = aSelector; |
|
6468 |
} |
|
6469 |
RETURN ( (*ilc7.ilc_func)(self, aSelector, nil, &ilc7, |
|
6470 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6471 |
argP[5], argP[6])); |
|
6472 |
} |
|
6473 |
||
6474 |
case 8: |
|
6475 |
{ |
|
6476 |
static OBJ last8 = nil; static struct inlineCache ilc8 = __ILCPERF8(@line); |
|
6477 |
||
6478 |
if ((InterruptPending != nil) || (aSelector != last8)) { |
|
6479 |
ilc8.ilc_func = __SEND8ADDR__; |
|
6480 |
if (ilc8.ilc_poly) { |
|
6481 |
__flushPolyCache(ilc8.ilc_poly); |
|
6482 |
ilc8.ilc_poly = 0; |
|
6483 |
} |
|
6484 |
last8 = aSelector; |
|
6485 |
} |
|
6486 |
RETURN ( (*ilc8.ilc_func)(self, aSelector, nil, &ilc8, |
|
6487 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6488 |
argP[5], argP[6], argP[7])); |
|
6489 |
} |
|
6490 |
||
6491 |
case 9: |
|
6492 |
{ |
|
6493 |
static OBJ last9 = nil; static struct inlineCache ilc9 = __ILCPERF9(@line); |
|
6494 |
||
6495 |
if ((InterruptPending != nil) || (aSelector != last9)) { |
|
6496 |
ilc9.ilc_func = __SEND9ADDR__; |
|
6497 |
if (ilc9.ilc_poly) { |
|
6498 |
__flushPolyCache(ilc9.ilc_poly); |
|
6499 |
ilc9.ilc_poly = 0; |
|
6500 |
} |
|
6501 |
last9 = aSelector; |
|
6502 |
} |
|
6503 |
RETURN ( (*ilc9.ilc_func)(self, aSelector, nil, &ilc9, |
|
6504 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6505 |
argP[5], argP[6], argP[7], argP[8])); |
|
6506 |
} |
|
6507 |
||
6508 |
case 10: |
|
6509 |
{ |
|
6510 |
static OBJ last10 = nil; static struct inlineCache ilc10 = __ILCPERF10(@line); |
|
6511 |
||
6512 |
if ((InterruptPending != nil) || (aSelector != last10)) { |
|
6513 |
ilc10.ilc_func = __SEND10ADDR__; |
|
6514 |
if (ilc10.ilc_poly) { |
|
6515 |
__flushPolyCache(ilc10.ilc_poly); |
|
6516 |
ilc10.ilc_poly = 0; |
|
6517 |
} |
|
6518 |
last10 = aSelector; |
|
6519 |
} |
|
6520 |
RETURN ( (*ilc10.ilc_func)(self, aSelector, nil, &ilc10, |
|
6521 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6522 |
argP[5], argP[6], argP[7], argP[8], argP[9])); |
|
6523 |
} |
|
6524 |
||
6525 |
case 11: |
|
6526 |
{ |
|
6527 |
static OBJ last11 = nil; static struct inlineCache ilc11 = __ILCPERF11(@line); |
|
6528 |
||
6529 |
if ((InterruptPending != nil) || (aSelector != last11)) { |
|
6530 |
ilc11.ilc_func = __SEND11ADDR__; |
|
6531 |
if (ilc11.ilc_poly) { |
|
6532 |
__flushPolyCache(ilc11.ilc_poly); |
|
6533 |
ilc11.ilc_poly = 0; |
|
6534 |
} |
|
6535 |
last11 = aSelector; |
|
6536 |
} |
|
6537 |
RETURN ( (*ilc11.ilc_func)(self, aSelector, nil, &ilc11, |
|
6538 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6539 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6540 |
argP[10])); |
|
6541 |
} |
|
6542 |
||
6543 |
case 12: |
|
6544 |
{ |
|
6545 |
static OBJ last12 = nil; static struct inlineCache ilc12 = __ILCPERF12(@line); |
|
6546 |
||
6547 |
if ((InterruptPending != nil) || (aSelector != last12)) { |
|
6548 |
ilc12.ilc_func = __SEND12ADDR__; |
|
6549 |
if (ilc12.ilc_poly) { |
|
6550 |
__flushPolyCache(ilc12.ilc_poly); |
|
6551 |
ilc12.ilc_poly = 0; |
|
6552 |
} |
|
6553 |
last12 = aSelector; |
|
6554 |
} |
|
6555 |
RETURN ( (*ilc12.ilc_func)(self, aSelector, nil, &ilc12, |
|
6556 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6557 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6558 |
argP[10], argP[11])); |
|
6559 |
} |
|
6560 |
||
6561 |
case 13: |
|
6562 |
{ |
|
6563 |
static OBJ last13 = nil; static struct inlineCache ilc13 = __ILCPERF13(@line); |
|
6564 |
||
6565 |
if ((InterruptPending != nil) || (aSelector != last13)) { |
|
6566 |
ilc13.ilc_func = __SEND13ADDR__; |
|
6567 |
if (ilc13.ilc_poly) { |
|
6568 |
__flushPolyCache(ilc13.ilc_poly); |
|
6569 |
ilc13.ilc_poly = 0; |
|
6570 |
} |
|
6571 |
last13 = aSelector; |
|
6572 |
} |
|
6573 |
RETURN ( (*ilc13.ilc_func)(self, aSelector, nil, &ilc13, |
|
6574 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6575 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6576 |
argP[10], argP[11], argP[12])); |
|
6577 |
} |
|
6578 |
||
6579 |
case 14: |
|
6580 |
{ |
|
6581 |
static OBJ last14 = nil; static struct inlineCache ilc14 = __ILCPERF14(@line); |
|
6582 |
||
6583 |
if ((InterruptPending != nil) || (aSelector != last14)) { |
|
6584 |
ilc14.ilc_func = __SEND14ADDR__; |
|
6585 |
if (ilc14.ilc_poly) { |
|
6586 |
__flushPolyCache(ilc14.ilc_poly); |
|
6587 |
ilc14.ilc_poly = 0; |
|
6588 |
} |
|
6589 |
last14 = aSelector; |
|
6590 |
} |
|
6591 |
RETURN ( (*ilc14.ilc_func)(self, aSelector, nil, &ilc14, |
|
6592 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6593 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6594 |
argP[10], argP[11], argP[12], argP[13])); |
|
6595 |
} |
|
6596 |
||
6597 |
case 15: |
|
6598 |
{ |
|
6599 |
static OBJ last15 = nil; static struct inlineCache ilc15 = __ILCPERF15(@line); |
|
6600 |
||
6601 |
if ((InterruptPending != nil) || (aSelector != last15)) { |
|
6602 |
ilc15.ilc_func = __SEND15ADDR__; |
|
6603 |
if (ilc15.ilc_poly) { |
|
6604 |
__flushPolyCache(ilc15.ilc_poly); |
|
6605 |
ilc15.ilc_poly = 0; |
|
6606 |
} |
|
6607 |
last15 = aSelector; |
|
6608 |
} |
|
6609 |
RETURN ( (*ilc15.ilc_func)(self, aSelector, nil, &ilc15, |
|
6610 |
argP[0], argP[1], argP[2], argP[3], argP[4], |
|
6611 |
argP[5], argP[6], argP[7], argP[8], argP[9], |
|
6612 |
argP[10], argP[11], argP[12], argP[13], |
|
6613 |
argP[14])); |
|
6614 |
} |
|
5755 | 6615 |
} |
6616 |
bad:; |
|
18238 | 6617 |
#endif |
5755 | 6618 |
%}. |
6619 |
||
6620 |
"/ arrive here, if bad number of arguments (too many) |
|
6621 |
"/ ST/X (currently) only allows up to 15 method arguments |
|
6622 |
||
6623 |
^ self primitiveFailed |
|
6624 |
! |
|
6625 |
||
6316 | 6626 |
perform:aSelector withOptionalArgument:arg |
6627 |
"send aSelector-message to the receiver. |
|
6318 | 6628 |
If the message expects an argument, pass arg." |
6316 | 6629 |
|
18440 | 6630 |
aSelector argumentCount == 1 ifTrue:[ |
20535 | 6631 |
^ self perform:aSelector with:arg |
6316 | 6632 |
]. |
6633 |
^ self perform:aSelector |
|
6319 | 6634 |
|
6635 |
" |
|
6636 |
|rec sel| |
|
6637 |
||
6638 |
rec := -1. |
|
6639 |
sel := #abs. |
|
6640 |
rec perform:sel withOptionalArgument:2. |
|
6641 |
||
6642 |
sel := #max:. |
|
6643 |
rec perform:sel withOptionalArgument:2. |
|
6644 |
" |
|
6316 | 6645 |
! |
6646 |
||
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6647 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6648 |
"send aSelector-message to the receiver. |
6728 | 6649 |
Depending on the number of arguments the message expects, |
6650 |
pass either none, 1, or 2 arguments." |
|
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6651 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6652 |
|numArgs| |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6653 |
|
18440 | 6654 |
numArgs := aSelector argumentCount. |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6655 |
numArgs == 0 ifTrue:[ |
20535 | 6656 |
^ self perform:aSelector |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6657 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6658 |
numArgs == 1 ifTrue:[ |
20535 | 6659 |
^ self perform:aSelector with:optionalArg1 |
6321
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6660 |
]. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6661 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6662 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6663 |
" |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6664 |
|rec sel| |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6665 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6666 |
rec := -1. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6667 |
sel := #abs. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6668 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6669 |
|
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6670 |
sel := #max:. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6671 |
rec perform:sel withOptionalArgument:2. |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6672 |
" |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6673 |
! |
8af99331b6e8
#perform:withOptionalArgument:and:
Claus Gittinger <cg@exept.de>
parents:
6319
diff
changeset
|
6674 |
|
6728 | 6675 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 |
6676 |
"send aSelector-message to the receiver. |
|
6677 |
Depending on the number of arguments the message expects, |
|
6678 |
pass either none, 1, 2 or 3 arguments." |
|
6679 |
||
6680 |
|numArgs| |
|
6681 |
||
18440 | 6682 |
numArgs := aSelector argumentCount. |
6728 | 6683 |
numArgs == 0 ifTrue:[ |
20535 | 6684 |
^ self perform:aSelector |
6728 | 6685 |
]. |
6686 |
numArgs == 1 ifTrue:[ |
|
20535 | 6687 |
^ self perform:aSelector with:optionalArg1 |
6728 | 6688 |
]. |
6689 |
numArgs == 2 ifTrue:[ |
|
20535 | 6690 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
6728 | 6691 |
]. |
6692 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3. |
|
6693 |
||
6694 |
" |
|
6695 |
|rec sel| |
|
6696 |
||
6697 |
rec := -1. |
|
6698 |
sel := #abs. |
|
6699 |
rec perform:sel withOptionalArgument:2. |
|
6700 |
||
6701 |
sel := #max:. |
|
6702 |
rec perform:sel withOptionalArgument:2. |
|
6703 |
" |
|
6704 |
! |
|
6705 |
||
6764 | 6706 |
perform:aSelector withOptionalArgument:optionalArg1 and:optionalArg2 and:optionalArg3 and:optionalArg4 |
6707 |
"send aSelector-message to the receiver. |
|
6708 |
Depending on the number of arguments the message expects, |
|
6709 |
pass either none, 1, 2, 3 or 4 arguments." |
|
6710 |
||
6711 |
|numArgs| |
|
6712 |
||
18440 | 6713 |
numArgs := aSelector argumentCount. |
6764 | 6714 |
numArgs == 0 ifTrue:[ |
20535 | 6715 |
^ self perform:aSelector |
6764 | 6716 |
]. |
6717 |
numArgs == 1 ifTrue:[ |
|
20535 | 6718 |
^ self perform:aSelector with:optionalArg1 |
6764 | 6719 |
]. |
6720 |
numArgs == 2 ifTrue:[ |
|
20535 | 6721 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 |
6764 | 6722 |
]. |
6723 |
numArgs == 3 ifTrue:[ |
|
20535 | 6724 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 |
6764 | 6725 |
]. |
6726 |
^ self perform:aSelector with:optionalArg1 with:optionalArg2 with:optionalArg3 with:optionalArg4. |
|
6727 |
||
6728 |
" |
|
6729 |
|rec sel| |
|
6730 |
||
6731 |
rec := -1. |
|
6732 |
sel := #abs. |
|
6733 |
rec perform:sel withOptionalArgument:2. |
|
6734 |
||
6735 |
sel := #max:. |
|
6736 |
rec perform:sel withOptionalArgument:2. |
|
6737 |
" |
|
6738 |
! |
|
6739 |
||
17524 | 6740 |
performMessage:aMessage |
6741 |
"Send aMessage, an object which provides a selector and arguments to the |
|
6742 |
receiver object. |
|
6743 |
Added for Ansi compatibility" |
|
6744 |
||
6745 |
^ self perform:(aMessage selector) withArguments:(aMessage arguments). |
|
6746 |
||
6747 |
" |
|
6748 |
123 performMessage:(Message selector:#+ argument:100) |
|
6749 |
" |
|
6750 |
! |
|
6751 |
||
5755 | 6752 |
performMethod:aMethod |
6753 |
"invoke aMethod on the receiver. |
|
6754 |
The method should be a zero-argument method. |
|
6755 |
This is a non-object-oriented entry, applying a method |
|
6756 |
in a functional way on a receiver. |
|
6757 |
Warning: |
|
20535 | 6758 |
Take care for the method to be appropriate for the |
6759 |
receiver - no checking is done by the VM." |
|
5755 | 6760 |
|
6761 |
^ aMethod valueWithReceiver:self arguments:#() |
|
6762 |
||
6763 |
" |
|
6764 |
|mthd| |
|
6765 |
||
6766 |
mthd := SmallInteger compiledMethodAt:#negated. |
|
6767 |
Transcript showCR:(1 performMethod:mthd) |
|
6768 |
" |
|
6769 |
||
6770 |
"BAD USE example: |
|
6771 |
||
6772 |
|mthd| |
|
6773 |
||
6774 |
mthd := Point compiledMethodAt:#x. |
|
6775 |
Transcript showCR:((1->2) performMethod:mthd) |
|
6776 |
" |
|
6777 |
||
6778 |
"Modified: 31.7.1997 / 17:41:50 / cg" |
|
6779 |
! |
|
6780 |
||
6781 |
performMethod:aMethod arguments:argumentArray |
|
6782 |
"invoke aMethod on the receiver, passing an argumentArray. |
|
6783 |
The size of the argumentArray should match the number of args |
|
6784 |
expected by the method. |
|
6785 |
This is a non-object-oriented entry, applying a method |
|
6786 |
in a functional way on a receiver. |
|
6787 |
Warning: |
|
20535 | 6788 |
Take care for the method to be appropriate for the |
6789 |
receiver - no checking is done by the VM." |
|
5755 | 6790 |
|
6791 |
^ aMethod valueWithReceiver:self arguments:argumentArray |
|
6792 |
||
6793 |
" |
|
6794 |
|mthd| |
|
6795 |
||
6796 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6797 |
Transcript showCR:(1 performMethod:mthd arguments:#(2)) |
|
6798 |
" |
|
6799 |
||
6800 |
"Created: 31.7.1997 / 17:46:31 / cg" |
|
6801 |
! |
|
6802 |
||
6803 |
performMethod:aMethod with:arg |
|
6804 |
"invoke aMethod on the receiver, passing an argument. |
|
6805 |
The method should be a one-argument method. |
|
6806 |
This is a non-object-oriented entry, applying a method |
|
6807 |
in a functional way on a receiver. |
|
6808 |
Warning: |
|
20535 | 6809 |
Take care for the method to be appropriate for the |
6810 |
receiver - no checking is done by the VM." |
|
5755 | 6811 |
|
6812 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg) |
|
6813 |
||
6814 |
" |
|
6815 |
|mthd| |
|
6816 |
||
6817 |
mthd := SmallInteger compiledMethodAt:#+. |
|
6818 |
Transcript showCR:(1 performMethod:mthd with:2) |
|
6819 |
" |
|
6820 |
||
6821 |
"Modified: 31.7.1997 / 17:42:32 / cg" |
|
6822 |
! |
|
6823 |
||
6824 |
performMethod:aMethod with:arg1 with:arg2 |
|
6825 |
"invoke aMethod on the receiver, passing two arguments. |
|
6826 |
The method should be a two-argument method. |
|
6827 |
This is a non-object-oriented entry, applying a method |
|
6828 |
in a functional way on a receiver. |
|
6829 |
Warning: |
|
20535 | 6830 |
Take care for the method to be appropriate for the |
6831 |
receiver - no checking is done by the VM." |
|
5755 | 6832 |
|
6833 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2) |
|
6834 |
||
6835 |
" |
|
6836 |
|mthd arr| |
|
6837 |
||
6838 |
arr := Array new:1. |
|
6839 |
mthd := Array compiledMethodAt:#basicAt:put:. |
|
6840 |
arr performMethod:mthd with:1 with:'foo'. |
|
6841 |
Transcript showCR:arr |
|
6842 |
" |
|
6843 |
||
6844 |
"Modified: 31.7.1997 / 17:44:54 / cg" |
|
6845 |
! |
|
6846 |
||
6847 |
performMethod:aMethod with:arg1 with:arg2 with:arg3 |
|
6848 |
"invoke aMethod on the receiver, passing three arguments. |
|
6849 |
The method should be a three-argument method. |
|
6850 |
This is a non-object-oriented entry, applying a method |
|
6851 |
in a functional way on a receiver. |
|
6852 |
Warning: |
|
20535 | 6853 |
Take care for the method to be appropriate for the |
6854 |
receiver - no checking is done by the VM." |
|
5755 | 6855 |
|
6856 |
^ aMethod valueWithReceiver:self arguments:(Array with:arg1 with:arg2 with:arg3) |
|
6857 |
||
6858 |
"Created: 31.7.1997 / 17:45:20 / cg" |
|
15586 | 6859 |
! |
6860 |
||
6861 |
performX:aSelector |
|
18231 | 6862 |
"send the message aSelector to the receiver |
6863 |
This is the original implementation of #perform, for reference (before Jan's changes for Ruby tuning)." |
|
15586 | 6864 |
|
6865 |
<resource: #skipInDebuggersWalkBack> |
|
6866 |
||
6867 |
%{ |
|
6868 |
REGISTER OBJ sel = aSelector; |
|
6869 |
||
6870 |
if (InterruptPending == nil) { |
|
20535 | 6871 |
struct inlineCache *pIlc; |
15586 | 6872 |
|
6873 |
#define SEL_AND_ILC_INIT_1(l) { nil , __ILCPERF0(l) } |
|
6874 |
#define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
|
6875 |
#define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
|
6876 |
#define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
|
6877 |
#define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
|
6878 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
6879 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
6880 |
#define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
|
6881 |
#define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
|
6882 |
#define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
|
16230 | 6883 |
#undef nilcs |
15586 | 6884 |
#define nilcs 256 |
6885 |
||
20535 | 6886 |
static struct sel_and_ilc { |
6887 |
OBJ sel; |
|
6888 |
struct inlineCache ilc; |
|
6889 |
struct sel_and_ilc *next; |
|
6890 |
} sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_256(29) }; |
|
15586 | 6891 |
|
6892 |
#undef SEL_AND_ILC_INIT_1 |
|
6893 |
#undef SEL_AND_ILC_INIT_2 |
|
6894 |
#undef SEL_AND_ILC_INIT_4 |
|
6895 |
#undef SEL_AND_ILC_INIT_8 |
|
6896 |
#undef SEL_AND_ILC_INIT_16 |
|
6897 |
#undef SEL_AND_ILC_INIT_32 |
|
6898 |
#undef SEL_AND_ILC_INIT_64 |
|
6899 |
#undef SEL_AND_ILC_INIT_128 |
|
6900 |
#undef SEL_AND_ILC_INIT_256 |
|
6901 |
||
20535 | 6902 |
static struct sel_and_ilc *nextFree = sel_and_ilc; |
6903 |
static struct sel_and_ilc *lastUsed = 0; |
|
6904 |
int n; |
|
6905 |
struct sel_and_ilc *slot, *prev, *prevPrev; |
|
6906 |
||
6907 |
for (n=0, slot = lastUsed, prev = prevPrev = 0; slot; n++, slot = slot->next) { |
|
6908 |
if (sel == slot->sel) { |
|
15942
a76da2251215
handle weak objects (with instances or non-WeakArray)
Claus Gittinger <cg@exept.de>
parents:
15932
diff
changeset
|
6909 |
#ifdef XXDEBUG |
15586 | 6910 |
printf("cached slot %d (len=%d)\n", slot-sel_and_ilc, n); |
15942
a76da2251215
handle weak objects (with instances or non-WeakArray)
Claus Gittinger <cg@exept.de>
parents:
15932
diff
changeset
|
6911 |
#endif |
20535 | 6912 |
pIlc = &(slot->ilc); |
6913 |
// move to front |
|
6914 |
if (prev) { |
|
6915 |
prev->next = slot->next; |
|
6916 |
} |
|
6917 |
slot->next = lastUsed; |
|
6918 |
lastUsed = slot; |
|
6919 |
pIlc = &(slot->ilc); |
|
6920 |
goto perform0_send_and_return; |
|
6921 |
} |
|
6922 |
prevPrev = prev; |
|
6923 |
prev = slot; |
|
6924 |
} |
|
6925 |
// not recently used... |
|
6926 |
if (nextFree) { |
|
6927 |
// another free one |
|
6928 |
slot = nextFree; |
|
6929 |
nextFree = nextFree + 1; |
|
6930 |
if (nextFree >= &(sel_and_ilc[nilcs])) nextFree = 0; |
|
15942
a76da2251215
handle weak objects (with instances or non-WeakArray)
Claus Gittinger <cg@exept.de>
parents:
15932
diff
changeset
|
6931 |
#ifdef XXDEBUG |
15586 | 6932 |
printf("new slot %d\n", slot-sel_and_ilc); |
15942
a76da2251215
handle weak objects (with instances or non-WeakArray)
Claus Gittinger <cg@exept.de>
parents:
15932
diff
changeset
|
6933 |
#endif |
20535 | 6934 |
} else { |
6935 |
// no more for reuse - use least recently used |
|
6936 |
slot = prev; |
|
6937 |
prevPrev->next = 0; |
|
6938 |
slot->next = lastUsed; |
|
6939 |
lastUsed = slot; |
|
15942
a76da2251215
handle weak objects (with instances or non-WeakArray)
Claus Gittinger <cg@exept.de>
parents:
15932
diff
changeset
|
6940 |
#ifdef XXDEBUG |
15586 | 6941 |
printf("reuse last slot %d\n", slot-sel_and_ilc); |
15942
a76da2251215
handle weak objects (with instances or non-WeakArray)
Claus Gittinger <cg@exept.de>
parents:
15932
diff
changeset
|
6942 |
#endif |
20535 | 6943 |
} |
6944 |
||
6945 |
/*printf("Object >> #perform: #%s --> no PIC found\n", __symbolVal(aSelector));*/ |
|
6946 |
pIlc = &(slot->ilc); |
|
6947 |
slot->sel = sel; |
|
6948 |
pIlc->ilc_func = __SEND0ADDR__; |
|
6949 |
if (pIlc->ilc_poly) { |
|
6950 |
__flushPolyCache(pIlc->ilc_poly); |
|
6951 |
pIlc->ilc_poly = 0; |
|
6952 |
} |
|
15586 | 6953 |
perform0_send_and_return: |
20535 | 6954 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc) ); |
15586 | 6955 |
} else { |
20535 | 6956 |
static struct inlineCache ilc0 = __DUMMYILCSELF0(@line+1); |
6957 |
RETURN (_SEND0(self, aSelector, nil, &ilc0)); |
|
15586 | 6958 |
} |
6959 |
%}. |
|
6960 |
^ self perform:aSelector withArguments:#() |
|
15797 | 6961 |
! |
6962 |
||
6963 |
returnablePerform:aSelector with:arg |
|
6964 |
"send the one-arg-message aSelector to the receiver. |
|
6965 |
This is the same as #perform:with: but the context can return." |
|
6966 |
||
6967 |
<context: #return> |
|
6968 |
%{ |
|
6969 |
REGISTER OBJ sel = aSelector; |
|
6970 |
||
6971 |
if (InterruptPending == nil) { |
|
20535 | 6972 |
struct inlineCache *pIlc; |
15797 | 6973 |
/* JV @ 2010-22-07: To improve performance I use 256 ILCs instead |
6974 |
of default 4. For details, see comment in perform: */ |
|
6975 |
||
6976 |
#define SEL_AND_ILC_INIT_1(l) { nil , __ILCPERF1(l) } |
|
6977 |
#define SEL_AND_ILC_INIT_2(l) SEL_AND_ILC_INIT_1(l) , SEL_AND_ILC_INIT_1(l) |
|
6978 |
#define SEL_AND_ILC_INIT_4(l) SEL_AND_ILC_INIT_2(l) , SEL_AND_ILC_INIT_2(l) |
|
6979 |
#define SEL_AND_ILC_INIT_8(l) SEL_AND_ILC_INIT_4(l) , SEL_AND_ILC_INIT_4(l) |
|
6980 |
#define SEL_AND_ILC_INIT_16(l) SEL_AND_ILC_INIT_8(l) , SEL_AND_ILC_INIT_8(l) |
|
6981 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
6982 |
#define SEL_AND_ILC_INIT_32(l) SEL_AND_ILC_INIT_16(l) , SEL_AND_ILC_INIT_16(l) |
|
6983 |
#define SEL_AND_ILC_INIT_64(l) SEL_AND_ILC_INIT_32(l) , SEL_AND_ILC_INIT_32(l) |
|
6984 |
#define SEL_AND_ILC_INIT_128(l) SEL_AND_ILC_INIT_64(l) , SEL_AND_ILC_INIT_64(l) |
|
6985 |
#define SEL_AND_ILC_INIT_256(l) SEL_AND_ILC_INIT_128(l) , SEL_AND_ILC_INIT_128(l) |
|
16230 | 6986 |
#undef nilcs |
15797 | 6987 |
#define nilcs 256 |
6988 |
||
20535 | 6989 |
static struct { OBJ sel; struct inlineCache ilc; } sel_and_ilc[nilcs] = { SEL_AND_ILC_INIT_256(29) }; |
15797 | 6990 |
|
6991 |
#undef SEL_AND_ILC_INIT_1 |
|
6992 |
#undef SEL_AND_ILC_INIT_2 |
|
6993 |
#undef SEL_AND_ILC_INIT_4 |
|
6994 |
#undef SEL_AND_ILC_INIT_8 |
|
6995 |
#undef SEL_AND_ILC_INIT_16 |
|
6996 |
#undef SEL_AND_ILC_INIT_32 |
|
6997 |
#undef SEL_AND_ILC_INIT_64 |
|
6998 |
#undef SEL_AND_ILC_INIT_128 |
|
6999 |
#undef SEL_AND_ILC_INIT_256 |
|
7000 |
||
20535 | 7001 |
static int flip = 0; |
7002 |
int i; |
|
7003 |
for (i = 0; i < nilcs; i++) { |
|
7004 |
if (sel == sel_and_ilc[i].sel) { |
|
7005 |
pIlc = &sel_and_ilc[i].ilc; |
|
7006 |
goto perform1_send_and_return; |
|
7007 |
} |
|
7008 |
} |
|
7009 |
/*printf("Object >> #perform: #%s with: arg --> no PIC found\n", __symbolVal(aSelector));*/ |
|
7010 |
pIlc = &sel_and_ilc[flip].ilc; |
|
7011 |
sel_and_ilc[flip].sel = sel; |
|
7012 |
flip = (flip + 1) % nilcs; |
|
7013 |
pIlc->ilc_func = __SEND1ADDR__; |
|
7014 |
if (pIlc->ilc_poly) { |
|
7015 |
__flushPolyCache(pIlc->ilc_poly); |
|
7016 |
pIlc->ilc_poly = 0; |
|
7017 |
} |
|
15797 | 7018 |
perform1_send_and_return: |
20535 | 7019 |
RETURN ( (*(pIlc->ilc_func))(self, sel, nil, pIlc, arg) ); |
15797 | 7020 |
} else { |
20535 | 7021 |
static struct inlineCache ilc1 = __DUMMYILCSELF1(@line+1); |
7022 |
RETURN (_SEND1(self, aSelector, nil, &ilc1, arg)); |
|
15797 | 7023 |
} |
7024 |
%}. |
|
7025 |
^ self perform:aSelector withArguments:(Array with:arg) |
|
5755 | 7026 |
! ! |
7027 |
||
17677 | 7028 |
!Object methodsFor:'misc ui support'! |
7029 |
||
7030 |
browse |
|
7031 |
"open a browser on the receiver's class" |
|
7032 |
||
7033 |
self class theNonMetaclass browse |
|
7034 |
||
7035 |
" |
|
7036 |
10 browse |
|
7037 |
Collection browse |
|
7038 |
Collection class browse |
|
7039 |
" |
|
20779 | 7040 |
! |
7041 |
||
7042 |
inspect |
|
7043 |
"{ Pragma: +optSpace }" |
|
7044 |
||
7045 |
"launch an inspector on the receiver. |
|
7046 |
this method (or better: inspectorClass) can be redefined in subclasses |
|
7047 |
to start special inspectors." |
|
7048 |
||
7049 |
|cls| |
|
7050 |
||
7051 |
Inspector ~~ MiniInspector ifTrue:[ |
|
7052 |
cls := (Smalltalk classNamed: #'Tools::Inspector2'). |
|
7053 |
]. |
|
7054 |
cls isNil ifTrue:[ |
|
7055 |
cls := self inspectorClass. |
|
7056 |
cls isNil ifTrue:[ |
|
7057 |
^ self basicInspect |
|
7058 |
]. |
|
7059 |
]. |
|
7060 |
cls openOn:self |
|
7061 |
||
7062 |
" |
|
7063 |
Object new inspect |
|
7064 |
(1 @ 2) inspect |
|
7065 |
Smalltalk inspect |
|
7066 |
#(1 2 3) asOrderedCollection inspect |
|
7067 |
(Color red) inspect |
|
7068 |
(Image fromFile:'bitmaps/garfield.gif') inspect |
|
7069 |
" |
|
7070 |
! |
|
7071 |
||
7072 |
inspectorClass |
|
7073 |
"{ Pragma: +optSpace }" |
|
7074 |
||
7075 |
"return the class to use for inspect. |
|
7076 |
Can (should) be redefined in classes for which a better inspector is available" |
|
7077 |
||
7078 |
Inspector notNil ifTrue:[ |
|
7079 |
^ Inspector. |
|
7080 |
]. |
|
7081 |
^ (Smalltalk classNamed: #'InspectorView') |
|
7082 |
||
7083 |
"Modified: / 08-03-2012 / 16:09:38 / cg" |
|
17677 | 7084 |
! ! |
7085 |
||
10834 | 7086 |
!Object methodsFor:'object persistency'! |
7087 |
||
7088 |
elementDescriptorFor:anAspectSymbol |
|
7089 |
"support for persistency: |
|
7090 |
answer a collection of associations containing the |
|
7091 |
objects state to be encoded for aspect. |
|
7092 |
Association key is the instance variable name or access selector, |
|
7093 |
association value is the contents of the instance variable. |
|
7094 |
||
7095 |
The default is to return the contents of all non-nil instance variables" |
|
7096 |
||
7097 |
|ret| |
|
7098 |
||
7099 |
ret := 0. |
|
7100 |
anAspectSymbol notNil ifTrue:[ |
|
20535 | 7101 |
ret := self perform:anAspectSymbol ifNotUnderstood:[0]. |
10834 | 7102 |
]. |
7103 |
ret == 0 ifTrue:[ |
|
20535 | 7104 |
^ self elementDescriptorForNonNilInstanceVariables |
10834 | 7105 |
]. |
7106 |
^ ret. |
|
7107 |
! |
|
7108 |
||
7109 |
elementDescriptorForInstanceVariables |
|
7110 |
"return all instance variables for visiting/encoding" |
|
7111 |
||
7112 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | true]. |
|
7113 |
||
7114 |
" |
|
7115 |
#(1 2 3 nil true symbol) elementDescriptorForInstanceVariables |
|
7116 |
Dictionary new elementDescriptorForInstanceVariables |
|
7117 |
(5 @ nil) elementDescriptorForInstanceVariables |
|
7118 |
" |
|
7119 |
! |
|
7120 |
||
7121 |
elementDescriptorForInstanceVariablesMatching:aBlock |
|
7122 |
"return all instance variables which conform to aBlock, for encoding/visiting. |
|
7123 |
Indexed vars are all included." |
|
7124 |
||
7125 |
|instVarNames theClass children |
|
7126 |
instSize "{ Class: SmallInteger }" |
|
7127 |
varSize "{ Class: SmallInteger }"| |
|
7128 |
||
7129 |
theClass := self class. |
|
7130 |
||
7131 |
instSize := theClass instSize. |
|
7132 |
varSize := theClass isVariable ifTrue:[self basicSize] ifFalse:[0]. |
|
7133 |
children := OrderedCollection new:(instSize + varSize). |
|
7134 |
||
7135 |
instVarNames := theClass allInstVarNames. |
|
7136 |
1 to:instSize do:[:i | |var| |
|
20535 | 7137 |
var := self instVarAt:i. |
7138 |
(aBlock value:var) ifTrue:[ |
|
7139 |
children add:((instVarNames at:i) -> var) |
|
7140 |
] |
|
10834 | 7141 |
]. |
7142 |
||
7143 |
varSize ~~ 0 ifTrue:[ |
|
20535 | 7144 |
1 to:varSize do:[:i | |
7145 |
children add:(i -> (self basicAt:i)) |
|
7146 |
] |
|
10834 | 7147 |
]. |
7148 |
||
7149 |
^ children. |
|
7150 |
||
7151 |
" |
|
7152 |
#(1 2 3 nil true symbol) elementDescriptorForInstanceVariables |
|
7153 |
Dictionary new elementDescriptorForInstanceVariables |
|
7154 |
(5 @ nil) elementDescriptorForInstanceVariables |
|
7155 |
" |
|
7156 |
! |
|
7157 |
||
7158 |
elementDescriptorForNonNilInstanceVariables |
|
7159 |
"return all non-nil instance variables for visiting/encoding" |
|
7160 |
||
7161 |
^ self elementDescriptorForInstanceVariablesMatching:[:val | val notNil]. |
|
7162 |
||
7163 |
" |
|
7164 |
#(1 2 3 nil true symbol) elementDescriptorForNonNilInstanceVariables |
|
7165 |
Dictionary new elementDescriptorForNonNilInstanceVariables |
|
7166 |
(5 @ nil) elementDescriptorForNonNilInstanceVariables |
|
7167 |
" |
|
7168 |
! ! |
|
7169 |
||
5755 | 7170 |
!Object methodsFor:'printing & storing'! |
7171 |
||
20839 | 7172 |
_errorPrint |
7173 |
"Do not use this in user code. |
|
7174 |
Prints on stderr, regardless of any redirection to a logger. |
|
7175 |
Only to be used by the MiniDebugger, to ensure that its output is shown to a user" |
|
7176 |
||
7177 |
self asString _errorPrint. |
|
7178 |
! |
|
7179 |
||
7180 |
_errorPrintCR |
|
7181 |
"Do not use this in user code. |
|
7182 |
Prints on stderr, regardless of any redirection to a logger. |
|
7183 |
Only to be used by the MiniDebugger, to ensure that its output is shown to a user" |
|
7184 |
||
7185 |
self asString _errorPrintCR. |
|
7186 |
! |
|
7187 |
||
7188 |
_print |
|
7189 |
"Do not use this in user code. |
|
7190 |
Prints on stdout, regardless of any redirection to a logger. |
|
7191 |
Only to be used by low-level crash utilities (like MiniDebugger), |
|
7192 |
to ensure that its output is shown to a user" |
|
7193 |
||
7194 |
self asString _print. |
|
7195 |
! |
|
7196 |
||
7197 |
_printCR |
|
7198 |
"Do not use this in user code. |
|
7199 |
Prints on stdout, regardless of any redirection to a logger. |
|
7200 |
Only to be used by low-level crash utilities (like MiniDebugger), |
|
7201 |
to ensure that its output is shown to a user" |
|
7202 |
||
7203 |
self asString _printCR. |
|
7204 |
! |
|
7205 |
||
6235 | 7206 |
basicPrintOn:aStream |
19451 | 7207 |
"append the receiver's className with an article to the argument, aStream" |
6235 | 7208 |
|
7209 |
aStream nextPutAll:self classNameWithArticle |
|
7210 |
! |
|
7211 |
||
18984 | 7212 |
basicStoreString |
7213 |
"defined here for compatibility with CharacterArray, which redefines this" |
|
7214 |
||
7215 |
^ self storeString |
|
7216 |
! |
|
7217 |
||
5755 | 7218 |
className |
14368
deb662b4664b
comment/format in: #className
Claus Gittinger <cg@exept.de>
parents:
14355
diff
changeset
|
7219 |
"return the classname of the receiver's class" |
5755 | 7220 |
|
7221 |
^ self class name |
|
7222 |
||
7223 |
" |
|
7224 |
1 className |
|
10460 | 7225 |
1 class className |
5755 | 7226 |
$a className |
9105 | 7227 |
$a class className |
5755 | 7228 |
" |
7229 |
! |
|
7230 |
||
7231 |
classNameWithArticle |
|
7232 |
"return a string consisting of classname preceeded by an article. |
|
20807 | 7233 |
(don't expect me to write national variants for this ... :-) |
5755 | 7234 |
If you have special preferences, redefine it ..." |
7235 |
||
6829 | 7236 |
| cls| |
5755 | 7237 |
|
7238 |
(cls := self class) == self ifTrue:[ |
|
20535 | 7239 |
^ 'a funny object' |
5755 | 7240 |
]. |
14368
deb662b4664b
comment/format in: #className
Claus Gittinger <cg@exept.de>
parents:
14355
diff
changeset
|
7241 |
cls isNil ifTrue:[ |
20535 | 7242 |
^ 'a nil-classes object' "/ cannot happen |
14368
deb662b4664b
comment/format in: #className
Claus Gittinger <cg@exept.de>
parents:
14355
diff
changeset
|
7243 |
]. |
6829 | 7244 |
^ cls nameWithArticle |
5755 | 7245 |
|
7246 |
" |
|
10460 | 7247 |
1 classNameWithArticle |
7248 |
(1->2) classNameWithArticle |
|
5755 | 7249 |
XWorkstation basicNew classNameWithArticle |
10460 | 7250 |
XWorkstation classNameWithArticle |
5755 | 7251 |
" |
7252 |
||
7253 |
"Modified: 13.5.1996 / 12:16:14 / cg" |
|
7254 |
! |
|
7255 |
||
7256 |
errorPrint |
|
20493 | 7257 |
"if a logger has been defined, let it print the receiver when a CR is coming. |
7258 |
Otherwise, print the receiver on the Transcript and Stderr. |
|
10530
0f3d3ddd3837
#errorPrint* and #infoPrint* print to Transcript.
Stefan Vogel <sv@exept.de>
parents:
10527
diff
changeset
|
7259 |
The Transcript is directed to the standard error stream on |
0f3d3ddd3837
#errorPrint* and #infoPrint* print to Transcript.
Stefan Vogel <sv@exept.de>
parents:
10527
diff
changeset
|
7260 |
headless applications." |
5755 | 7261 |
|
20493 | 7262 |
Logger notNil ifTrue:[ |
20535 | 7263 |
PartialErrorPrintLine := (PartialErrorPrintLine ? ''), self printString string. |
20493 | 7264 |
^ self. |
7265 |
]. |
|
14165 | 7266 |
Stderr isNil ifTrue:[ |
20493 | 7267 |
"/ the following allows errorPrint to be used during |
7268 |
"/ the early init-phase, when no Stderr has been set up. |
|
7269 |
"/ (depends on string to respond to #errorPrint) |
|
7270 |
self printString utf8Encoded errorPrint. |
|
7271 |
^ self. |
|
14165 | 7272 |
]. |
7273 |
||
13350 | 7274 |
self withErrorStreamDo:[:s | self printOn:s]. |
7275 |
||
7276 |
"Modified: / 21-04-2011 / 12:46:42 / cg" |
|
5755 | 7277 |
! |
7278 |
||
7279 |
errorPrintCR |
|
7280 |
"{ Pragma: +optSpace }" |
|
7281 |
||
20493 | 7282 |
"if a logger has been defined, let it print the receiver. |
7283 |
otherwise, print the receiver followed by a cr on the error stream(s). |
|
10530
0f3d3ddd3837
#errorPrint* and #infoPrint* print to Transcript.
Stefan Vogel <sv@exept.de>
parents:
10527
diff
changeset
|
7284 |
The Transcript is directed to the standard error stream on |
0f3d3ddd3837
#errorPrint* and #infoPrint* print to Transcript.
Stefan Vogel <sv@exept.de>
parents:
10527
diff
changeset
|
7285 |
headless applications." |
5755 | 7286 |
|
20493 | 7287 |
Logger notNil ifTrue:[ |
7288 |
|fullLine| |
|
20535 | 7289 |
fullLine := (PartialErrorPrintLine ? ''), self printString string. |
20493 | 7290 |
PartialErrorPrintLine := nil. |
7291 |
Logger error:fullLine. |
|
7292 |
^ self. |
|
7293 |
]. |
|
14165 | 7294 |
Stderr isNil ifTrue:[ |
20493 | 7295 |
"/ the following allows errorPrintCR to be used during |
7296 |
"/ the early init-phase, when no Stderr has been set up. |
|
7297 |
"/ (depends on string to respond to #errorPrintCR) |
|
7298 |
self printString utf8Encoded errorPrintCR. |
|
7299 |
^ self. |
|
14165 | 7300 |
]. |
7301 |
||
13350 | 7302 |
self withErrorStreamDo:[:s | self printOn:s. s cr]. |
7303 |
||
7304 |
" |
|
7305 |
'hello' errorPrintCR |
|
7306 |
" |
|
5755 | 7307 |
|
10564
7d25403688ba
dont errorPrint on Transcript when I am a system process.
Claus Gittinger <cg@exept.de>
parents:
10558
diff
changeset
|
7308 |
"Created: / 20-05-1996 / 10:20:41 / cg" |
13350 | 7309 |
"Modified: / 21-04-2011 / 12:47:13 / cg" |
5755 | 7310 |
! |
7311 |
||
7312 |
errorPrintNL |
|
7313 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7314 |
<resource:#obsolete> |
5755 | 7315 |
|
7316 |
"print the receiver followed by a cr on the standard error stream. |
|
7317 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
7318 |
||
7319 |
^ self errorPrintCR |
|
7320 |
||
7321 |
"Modified: 20.5.1996 / 10:24:45 / cg" |
|
7322 |
! |
|
7323 |
||
7324 |
errorPrintNewline |
|
7325 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7326 |
<resource:#obsolete> |
5755 | 7327 |
|
7328 |
"print the receiver followed by a cr on the standard error stream. |
|
7329 |
Please use #errorPrintCR - this method exists for backward compatibility." |
|
7330 |
||
7331 |
self errorPrintCR. |
|
7332 |
||
7333 |
"Modified: 20.5.1996 / 10:24:38 / cg" |
|
7334 |
! |
|
7335 |
||
7336 |
infoPrint |
|
7337 |
"{ Pragma: +optSpace }" |
|
7338 |
||
20493 | 7339 |
"if a logger has been defined, let it print the receiver when a CR is coming. |
7340 |
otherwise print the receiver on the standard error stream. |
|
7341 |
This is meant for information messages which are not warnings or fatal messages. |
|
5755 | 7342 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
7343 |
||
20493 | 7344 |
Logger notNil ifTrue:[ |
20535 | 7345 |
PartialInfoPrintLine := (PartialInfoPrintLine ? ''), self printString string. |
20493 | 7346 |
^ self. |
7347 |
]. |
|
7348 |
||
5755 | 7349 |
InfoPrinting == true ifTrue:[ |
20493 | 7350 |
self errorPrint |
5755 | 7351 |
] |
20493 | 7352 |
|
7353 |
" |
|
7354 |
'hello' infoPrint. ' world' infoPrintCR. |
|
7355 |
'foo [info] hello' infoPrintCR. |
|
7356 |
" |
|
5755 | 7357 |
! |
7358 |
||
7359 |
infoPrintCR |
|
7360 |
"{ Pragma: +optSpace }" |
|
7361 |
||
20493 | 7362 |
"if a logger has been defined, let it print the receiver. |
7363 |
otherwise print the receiver followed by a cr on the standard error stream. |
|
7364 |
This is meant for information messages which are not warnings or fatal messages. |
|
5755 | 7365 |
These messages can be turned on/off by 'Object infoPrinting:true/false'" |
7366 |
||
20493 | 7367 |
Logger notNil ifTrue:[ |
7368 |
|fullLine| |
|
20535 | 7369 |
fullLine := (PartialInfoPrintLine ? ''), self printString string. |
20493 | 7370 |
PartialInfoPrintLine := nil. |
7371 |
Logger info:fullLine. |
|
7372 |
^ self. |
|
7373 |
]. |
|
5755 | 7374 |
InfoPrinting == true ifTrue:[ |
20493 | 7375 |
self errorPrintCR |
5755 | 7376 |
] |
7377 |
||
7378 |
"Created: 20.5.1996 / 10:21:28 / cg" |
|
7379 |
! |
|
7380 |
||
7381 |
infoPrintNL |
|
7382 |
"{ Pragma: +optSpace }" |
|
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7383 |
<resource:#obsolete> |
5755 | 7384 |
|
7385 |
"print the receiver followed by a cr on the standard error stream. |
|
7386 |
Please use #infoPrintCR - this method exists for backward compatibility." |
|
7387 |
||
7388 |
^ self infoPrintCR |
|
7389 |
! |
|
7390 |
||
7391 |
||
7392 |
"print the receiver on the standard output stream (which is not the Transcript)" |
|
7393 |
||
19382 | 7394 |
"/ the following allows print/printCR to be used during |
5755 | 7395 |
"/ the early init-phase, when no Stdout has been set up. |
19382 | 7396 |
"/ (depends on String to respond to #print, without recurring back to here) |
5755 | 7397 |
|
7398 |
Stdout isNil ifTrue:[ |
|
20535 | 7399 |
self printString utf8Encoded print. |
7400 |
^ self |
|
19382 | 7401 |
]. |
7402 |
self printOn:Processor activeProcess stdout |
|
5755 | 7403 |
|
7404 |
"Modified: 4.11.1996 / 23:36:58 / cg" |
|
7405 |
! |
|
7406 |
||
7407 |
printCR |
|
7408 |
"print the receiver followed by a cr on the standard output stream (which is not the Transcript)" |
|
7409 |
||
7410 |
"/ the following allows printCR to be used during |
|
7411 |
"/ the early init-phase, when no Stdout has been set up. |
|
7412 |
"/ (depends on string to respond to #printCR) |
|
7413 |
||
19382 | 7414 |
|stdout| |
7415 |
||
5755 | 7416 |
Stdout isNil ifTrue:[ |
20535 | 7417 |
self printString utf8Encoded printCR. |
7418 |
^ self |
|
19382 | 7419 |
]. |
7420 |
stdout := Processor activeProcess stdout. |
|
7421 |
self printOn:stdout. |
|
7422 |
stdout cr |
|
5755 | 7423 |
|
7424 |
"Created: 20.5.1996 / 10:21:37 / cg" |
|
7425 |
"Modified: 4.11.1996 / 23:37:06 / cg" |
|
7426 |
! |
|
7427 |
||
7428 |
printNL |
|
7429 |
"print the receiver followed by a cr on the standard output stream |
|
7430 |
This exists for GNU Smalltalk compatibility - please use #printCR." |
|
7431 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7432 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7433 |
|
5755 | 7434 |
^ self printCR |
7435 |
||
7436 |
"Modified: 20.5.1996 / 10:25:31 / cg" |
|
7437 |
! |
|
7438 |
||
7439 |
printNewline |
|
7440 |
"print the receiver followed by a cr on the standard output stream. |
|
7441 |
This exists for backward compatibility - please use #printCR." |
|
7442 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7443 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7444 |
|
5755 | 7445 |
self printCR |
7446 |
||
7447 |
"Modified: 20.5.1996 / 10:25:46 / cg" |
|
7448 |
! |
|
7449 |
||
7450 |
printOn:aStream |
|
7451 |
"append a user printed representation of the receiver to aStream. |
|
7452 |
The format is suitable for a human - not meant to be read back. |
|
7453 |
||
19451 | 7454 |
The default here is to output the receiver's class name. |
5755 | 7455 |
BUT: this method is heavily redefined for objects which |
7456 |
can print prettier." |
|
7457 |
||
6235 | 7458 |
self basicPrintOn:aStream. |
7459 |
||
7460 |
" |
|
7461 |
(1@2) printOn:Transcript |
|
7462 |
(1@2) basicPrintOn:Transcript |
|
7463 |
" |
|
5755 | 7464 |
! |
7465 |
||
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7466 |
printOn:aStream format:format |
11335 | 7467 |
"this may be redefined in subclasses. |
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7468 |
Defined here for compatibility with subclasses" |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7469 |
|
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7470 |
self printOn:aStream. |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7471 |
! |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7472 |
|
5755 | 7473 |
printOn:aStream leftPaddedTo:size |
7474 |
"print the receiver on aStream, padding with spaces up to size. |
|
7475 |
padding is done on the left." |
|
7476 |
||
7477 |
self printOn:aStream leftPaddedTo:size with:(Character space) |
|
7478 |
||
7479 |
" |
|
7480 |
123 printOn:Transcript leftPaddedTo:10. Transcript cr |
|
7481 |
123 printOn:Transcript leftPaddedTo:2. Transcript cr |
|
7482 |
" |
|
7483 |
! |
|
7484 |
||
7485 |
printOn:aStream leftPaddedTo:size with:padCharacter |
|
7486 |
"print the receiver on aStream, padding with padCharacters up to size. |
|
7487 |
padding is done on the left." |
|
7488 |
||
7489 |
aStream nextPutAll:(self printStringLeftPaddedTo:size with:padCharacter) |
|
7490 |
||
7491 |
" |
|
7492 |
123 printOn:Transcript leftPaddedTo:10 with:$_ . Transcript cr |
|
7493 |
123 printOn:Transcript leftPaddedTo:10 with:$. . Transcript cr |
|
7494 |
" |
|
7495 |
! |
|
7496 |
||
7497 |
printOn:aStream paddedTo:size |
|
7498 |
"print the receiver on aStream, padding with spaces up to size." |
|
7499 |
||
7500 |
self printOn:aStream paddedTo:size with:(Character space) |
|
7501 |
||
7502 |
" |
|
7503 |
123.0 printOn:Transcript paddedTo:10. Transcript nextPut:$|. Transcript cr |
|
7504 |
" |
|
7505 |
! |
|
7506 |
||
7507 |
printOn:aStream paddedTo:size with:padCharacter |
|
7508 |
"print the receiver on aStream, padding with padCharacter up to size" |
|
7509 |
||
7510 |
aStream nextPutAll:(self printStringPaddedTo:size with:padCharacter). |
|
7511 |
||
7512 |
" |
|
7513 |
123 printOn:Transcript paddedTo:10 with:$_ . Transcript cr |
|
7514 |
123 printOn:Transcript paddedTo:10 with:$. . Transcript cr |
|
7515 |
" |
|
7516 |
! |
|
7517 |
||
7518 |
printOn:aStream zeroPaddedTo:size |
|
7519 |
"print the receiver on aStream, padding with zeros up to size. |
|
7520 |
Usually used with float numbers." |
|
7521 |
||
7522 |
self printOn:aStream paddedTo:size with:$0. |
|
7523 |
||
7524 |
" |
|
7525 |
123.0 printOn:Transcript zeroPaddedTo:10 |
|
7526 |
" |
|
7527 |
! |
|
7528 |
||
7529 |
printRightAdjustLen:size |
|
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7530 |
<resource: #obsolete> |
5755 | 7531 |
"obsolete - just a name confusion. |
7532 |
This method will go away ..." |
|
7533 |
||
19382 | 7534 |
(self printStringLeftPaddedTo:size) print |
5755 | 7535 |
! |
7536 |
||
7537 |
printString |
|
7538 |
"return a string for printing the receiver. |
|
7539 |
Since we now use printOn: as the basic print mechanism, |
|
7540 |
we have to create a stream and print into it." |
|
7541 |
||
7542 |
|s| |
|
7543 |
||
19340 | 7544 |
"allocate at least 40 bytes for fast UUID conversion. |
7545 |
cg: who did that? If that's a bottleneck, it ought to be done in UUID, not here!!" |
|
7546 |
||
20214 | 7547 |
s := CharacterWriteStream on:(String basicNew:40). |
5755 | 7548 |
self printOn:s. |
8300
d15ead94361f
Use CharacterWriteStream in #printString (speedup)
Stefan Vogel <sv@exept.de>
parents:
8287
diff
changeset
|
7549 |
^ s contents. |
7978
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
7550 |
|
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
7551 |
" |
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
7552 |
Date today printString. |
4ce7575e1cfc
care for 16bit chars in #printString
Claus Gittinger <cg@exept.de>
parents:
7838
diff
changeset
|
7553 |
" |
5755 | 7554 |
! |
7555 |
||
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7556 |
printStringFormat:orintFormat |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7557 |
"subclasses may redefine this. |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7558 |
Defined here to avoid type checks" |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7559 |
|
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7560 |
^ self printString |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7561 |
! |
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7562 |
|
5755 | 7563 |
printStringLeftPaddedTo:size |
7564 |
"return my printString as a right-adjusted string of length size; |
|
7565 |
characters on the left are filled with spaces. |
|
10460 | 7566 |
If the printString is longer than size, |
5755 | 7567 |
it is returned unchanged (i.e. not truncated)" |
7568 |
||
7569 |
^ self printStringLeftPaddedTo:size with:(Character space) |
|
7570 |
||
7571 |
" |
|
7572 |
10 printStringLeftPaddedTo:10 |
|
7573 |
1 printStringLeftPaddedTo:10 |
|
7574 |
" |
|
7575 |
! |
|
7576 |
||
7577 |
printStringLeftPaddedTo:size ifLarger:alternative |
|
7578 |
"return my printString as a right-adjusted string of length size; |
|
7579 |
characters on the left are filled with spaces. |
|
7580 |
If the printString is larger than size, |
|
7581 |
return the result from evaluating alternative." |
|
7582 |
||
7583 |
^ self printStringLeftPaddedTo:size with:(Character space) ifLarger:alternative |
|
7584 |
||
7585 |
" |
|
7586 |
12 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
7587 |
123 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
7588 |
1234 printStringLeftPaddedTo:3 ifLarger:['***'] |
|
7589 |
" |
|
7590 |
! |
|
7591 |
||
7592 |
printStringLeftPaddedTo:size with:padCharacter |
|
7593 |
"return my printString as a right-adjusted string of length size; |
|
7594 |
characters on the left are filled with padCharacter. |
|
10460 | 7595 |
If the printString is longer than size, |
5755 | 7596 |
it is returned unchanged (i.e. not truncated)" |
7597 |
||
7598 |
^ (self printString) leftPaddedTo:size with:padCharacter |
|
7599 |
||
7600 |
" |
|
10460 | 7601 |
123 printStringLeftPaddedTo:10 with:$. |
7602 |
1 printStringLeftPaddedTo:10 with:$. |
|
5755 | 7603 |
(Float pi) printStringLeftPaddedTo:20 with:$* |
7604 |
" |
|
7605 |
! |
|
7606 |
||
7607 |
printStringLeftPaddedTo:size with:padCharacter ifLarger:alternative |
|
7608 |
"return my printString as a right-adjusted string of length size; |
|
7609 |
characters on the left are filled with padCharacter. |
|
7610 |
If the printString is larger than size, |
|
7611 |
return the result from evaluating alternative." |
|
7612 |
||
7613 |
|s| |
|
7614 |
||
7615 |
s := self printString. |
|
7616 |
s size > size ifTrue:[^ alternative value]. |
|
7617 |
^ s leftPaddedTo:size with:padCharacter |
|
7618 |
||
7619 |
" |
|
10460 | 7620 |
12 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
7621 |
123 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
7622 |
1234 printStringLeftPaddedTo:3 with:$. ifLarger:['***'] |
|
5755 | 7623 |
" |
7624 |
! |
|
7625 |
||
8576 | 7626 |
printStringLimitedTo:sizeLimit |
7627 |
"return a string for printing the receiver, but limit the result string in its size." |
|
7628 |
||
7629 |
|s| |
|
7630 |
||
7631 |
s := CharacterWriteStream on:(String basicNew:30). |
|
7632 |
s writeLimit:sizeLimit. |
|
7633 |
self printOn:s. |
|
7634 |
^ s contents. |
|
7635 |
||
7636 |
" |
|
7637 |
Date today printStringLimitedTo:5. |
|
10460 | 7638 |
'12345678901234567890' printStringLimitedTo:5. |
8576 | 7639 |
" |
7640 |
! |
|
7641 |
||
5755 | 7642 |
printStringOnError:exceptionBlock |
7643 |
"return a string for printing the receiver; if any error occurs, return the result from |
|
7644 |
evaluating exceptionBlock. Useful to print something in an exceptionHandler or other |
|
7645 |
cleanup code." |
|
7646 |
||
21389 | 7647 |
^ [self printString] on:Error do:exceptionBlock. |
7648 |
||
7649 |
"Modified: / 09-02-2017 / 10:00:59 / stefan" |
|
5755 | 7650 |
! |
7651 |
||
7652 |
printStringPaddedTo:size |
|
7653 |
"return a printed representation of the receiver, |
|
7654 |
padded with spaces (at the right) up to size. |
|
10460 | 7655 |
If the printString is longer than size, |
5755 | 7656 |
it is returned unchanged (i.e. not truncated)" |
7657 |
||
7658 |
^ self printStringPaddedTo:size with:(Character space) |
|
7659 |
||
7660 |
" |
|
10460 | 7661 |
123 printStringPaddedTo:10 |
7662 |
1234567890123456 printStringPaddedTo:10 |
|
7663 |
'hello' printStringPaddedTo:10 |
|
5755 | 7664 |
" |
7665 |
! |
|
7666 |
||
7667 |
printStringPaddedTo:size ifLarger:alternative |
|
7668 |
"return a printed representation of the receiver, |
|
7669 |
padded with spaces (at the right) up to size. |
|
10460 | 7670 |
If the resulting printString is too large, |
5755 | 7671 |
return the result from evaluating alternative." |
7672 |
||
7673 |
^ self printStringPaddedTo:size with:(Character space) ifLarger:alternative |
|
7674 |
||
7675 |
" |
|
10460 | 7676 |
12 printStringPaddedTo:3 ifLarger:['***'] |
7677 |
123 printStringPaddedTo:3 ifLarger:['***'] |
|
7678 |
1234 printStringPaddedTo:3 ifLarger:['***'] |
|
5755 | 7679 |
" |
7680 |
! |
|
7681 |
||
7682 |
printStringPaddedTo:size with:padCharacter |
|
7683 |
"return a printed representation of the receiver, |
|
7684 |
padded with padCharacter (at the right) up to size. |
|
10460 | 7685 |
If the printString is longer than size, |
5755 | 7686 |
it is returned unchanged (i.e. not truncated)" |
7687 |
||
7688 |
^ (self printString) paddedTo:size with:padCharacter |
|
7689 |
||
7690 |
" |
|
7691 |
123 printStringPaddedTo:10 with:$. |
|
7692 |
123 printStringPaddedTo:10 with:$* |
|
10460 | 7693 |
123 printStringPaddedTo:3 with:$* |
7694 |
1234 printStringPaddedTo:3 with:$* |
|
5755 | 7695 |
" |
7696 |
! |
|
7697 |
||
7698 |
printStringPaddedTo:size with:padCharacter ifLarger:alternative |
|
7699 |
"return a printed representation of the receiver, |
|
7700 |
padded with padCharacter (at the right) up to size. |
|
10460 | 7701 |
If the resulting printString is too large, |
5755 | 7702 |
return the result from evaluating alternative." |
7703 |
||
7704 |
|s| |
|
7705 |
||
7706 |
s := self printString. |
|
7707 |
s size > size ifTrue:[^ alternative value]. |
|
7708 |
^ s paddedTo:size with:padCharacter |
|
7709 |
||
7710 |
" |
|
7711 |
123 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
7712 |
12345 printStringPaddedTo:3 with:$. ifLarger:['***'] |
|
7713 |
" |
|
7714 |
! |
|
7715 |
||
7716 |
printStringRightAdjustLen:size |
|
7717 |
"obsolete - just a name confusion. |
|
7718 |
This method will go away ..." |
|
11068
a5ef673886fd
#printOn:format: and #printStringFormat for Date/Time compatibility
Stefan Vogel <sv@exept.de>
parents:
11065
diff
changeset
|
7719 |
<resource: #obsolete> |
5755 | 7720 |
|
7721 |
^ self printStringLeftPaddedTo:size |
|
7722 |
! |
|
7723 |
||
7724 |
printStringZeroPaddedTo:size |
|
10460 | 7725 |
"return a printed representation of the receiver, |
5755 | 7726 |
padded with zero (at the right) characters up to size. |
7727 |
Usually used with float numbers." |
|
7728 |
||
7729 |
^ self printStringPaddedTo:size with:$0 |
|
7730 |
||
7731 |
" |
|
10460 | 7732 |
123.0 printStringZeroPaddedTo:10 |
5755 | 7733 |
" |
7734 |
! |
|
7735 |
||
8287 | 7736 |
printfPrintString:ignoredFormat |
7737 |
"fallback to default printString |
|
7738 |
(for compatibility with float and integer-printing)" |
|
7739 |
||
7740 |
^ self printString |
|
7741 |
! |
|
7742 |
||
5755 | 7743 |
store |
7744 |
"store the receiver on standard output. |
|
7745 |
this method is useless, but included for compatibility." |
|
7746 |
||
19382 | 7747 |
self storeOn:Processor activeProcess stdout |
5755 | 7748 |
! |
7749 |
||
7600
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7750 |
storeArrayElementOn:aStream |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7751 |
"store an object as an Array element. |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7752 |
Subclasses may redefine this to omit a leading '#'" |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7753 |
|
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7754 |
^ self storeOn:aStream |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7755 |
! |
5a3fee21c032
#storeString - omit # from Symbols and Arrays that are elements of an array.
Stefan Vogel <sv@exept.de>
parents:
7576
diff
changeset
|
7756 |
|
5755 | 7757 |
storeCR |
7758 |
"store the receiver on standard output; append a carriage return." |
|
7759 |
||
19382 | 7760 |
|stdout| |
20214 | 7761 |
|
19382 | 7762 |
stdout := Processor activeProcess stdout. |
7763 |
self storeOn:stdout. |
|
7764 |
stdout cr. |
|
5755 | 7765 |
|
7766 |
"Created: 20.5.1996 / 10:26:01 / cg" |
|
7767 |
"Modified: 20.5.1996 / 10:26:57 / cg" |
|
7768 |
! |
|
7769 |
||
7770 |
storeNl |
|
7771 |
"store the receiver on standard output; append a newline. |
|
7772 |
This method is included for backward compatibility- use #storeCR." |
|
7773 |
||
5893
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7774 |
<resource:#obsolete> |
f92054b38d3c
Assign #obsolete resource to obsolete methods
Stefan Vogel <sv@exept.de>
parents:
5879
diff
changeset
|
7775 |
|
5755 | 7776 |
self storeCR. |
7777 |
||
7778 |
"Modified: 20.5.1996 / 10:26:49 / cg" |
|
7779 |
! |
|
7780 |
||
7781 |
storeOn:aStream |
|
7782 |
"store the receiver on aStream; i.e. print an expression which will |
|
7783 |
reconstruct the receiver. |
|
7784 |
Notice, that no self referencing or cyclic objects can be represented |
|
7785 |
in this format. |
|
7786 |
Use storeBinaryOn:, which handles these cases correctly." |
|
7787 |
||
7788 |
|myClass hasSemi sz "{ Class: SmallInteger }" | |
|
7789 |
||
7790 |
thisContext isRecursive ifTrue:[ |
|
20535 | 7791 |
RecursiveStoreError raiseRequestWith:self. |
7792 |
'Object [error]: storeString of self referencing object (' errorPrint. |
|
7793 |
self class name errorPrint. |
|
7794 |
')' errorPrintCR. |
|
7795 |
aStream nextPutAll:'#("recursive")'. |
|
7796 |
^ self |
|
5755 | 7797 |
]. |
7798 |
||
7799 |
myClass := self class. |
|
7800 |
aStream nextPut:$(. |
|
7801 |
aStream nextPutAll:self class name. |
|
7802 |
||
7803 |
hasSemi := false. |
|
7804 |
myClass isVariable ifTrue:[ |
|
20535 | 7805 |
aStream nextPutAll:' basicNew:'. |
7806 |
self basicSize printOn:aStream |
|
5755 | 7807 |
] ifFalse:[ |
20535 | 7808 |
aStream nextPutAll:' basicNew' |
5755 | 7809 |
]. |
7810 |
||
7811 |
sz := myClass instSize. |
|
10460 | 7812 |
1 to:sz do:[:i | |
20535 | 7813 |
|ref| |
7814 |
||
7815 |
ref := (self instVarAt:i). |
|
7816 |
"/ no need to store nil entries, because the object has been instantiated |
|
7817 |
"/ with basicNew just a moment ago (so the fields are already nil) |
|
7818 |
ref notNil ifTrue:[ |
|
7819 |
aStream nextPutAll:' instVarAt:'. |
|
7820 |
i printOn:aStream. |
|
7821 |
aStream nextPutAll:' put:'. |
|
7822 |
ref storeOn:aStream. |
|
7823 |
aStream nextPut:$;. |
|
7824 |
hasSemi := true |
|
7825 |
]. |
|
5755 | 7826 |
]. |
7827 |
myClass isVariable ifTrue:[ |
|
20535 | 7828 |
sz := self basicSize. |
7829 |
1 to:sz do:[:i | |
|
7830 |
|ref| |
|
7831 |
||
7832 |
ref := (self basicAt:i). |
|
7833 |
"/ no need to store nil entries, because the object has been instantiated |
|
7834 |
"/ with basicNew just a moment ago (so the fields are already nil) |
|
7835 |
ref notNil ifTrue:[ |
|
7836 |
aStream nextPutAll:' basicAt:'. |
|
7837 |
i printOn:aStream. |
|
7838 |
aStream nextPutAll:' put:'. |
|
7839 |
ref storeOn:aStream. |
|
7840 |
aStream nextPut:$;. |
|
7841 |
hasSemi := true |
|
7842 |
] |
|
7843 |
] |
|
5755 | 7844 |
]. |
7845 |
hasSemi ifTrue:[ |
|
20535 | 7846 |
aStream nextPutAll:' yourself' |
5755 | 7847 |
]. |
7848 |
aStream nextPut:$). |
|
7849 |
||
7850 |
" |
|
7851 |
|s| |
|
7852 |
||
7853 |
s := WriteStream on:(String new). |
|
7854 |
('hello' -> 'world') storeOn:s. |
|
7855 |
s := ReadStream on:(s contents). |
|
7856 |
(Object readFrom:s) inspect |
|
7857 |
" |
|
7858 |
" |
|
7859 |
|s| |
|
7860 |
||
7861 |
s := 'data' asFilename writeStream. |
|
7862 |
('hello' -> 'world') storeOn:s. |
|
7863 |
s close. |
|
7864 |
||
7865 |
s := 'data' asFilename readStream. |
|
7866 |
(Object readFrom:s) inspect |
|
7867 |
" |
|
7868 |
||
16590 | 7869 |
"does not work example (cyclic):" |
5755 | 7870 |
" |
7871 |
|s a| |
|
7872 |
||
7873 |
a := Array new:2. |
|
7874 |
a at:1 put:a. |
|
7875 |
||
7876 |
s := 'data' asFilename writeStream. |
|
7877 |
a storeOn:s. |
|
7878 |
s close. |
|
7879 |
||
7880 |
s := 'data' asFilename readStream. |
|
7881 |
(Object readFrom:s) inspect |
|
7882 |
" |
|
7883 |
||
13162 | 7884 |
"Modified: / 03-12-2010 / 13:27:51 / cg" |
5755 | 7885 |
! |
7886 |
||
7887 |
storeString |
|
7888 |
"return a string representing an expression to reconstruct the receiver. |
|
7889 |
Notice, that no self referencing or cyclic objects can be represented |
|
7890 |
in this format. |
|
7891 |
Use storeBinaryOn:, which handles these cases correctly." |
|
7892 |
||
7893 |
|s| |
|
7894 |
||
7895 |
s := WriteStream on:(String new:50). |
|
7896 |
self storeOn:s. |
|
7897 |
^ s contents |
|
13350 | 7898 |
! |
7899 |
||
7900 |
withErrorStreamDo:aBlock |
|
7901 |
"{ Pragma: +optSpace }" |
|
7902 |
||
16560 | 7903 |
"helper for error messages - evaluate aBlock, |
19784 | 7904 |
passing it a stream on which to put error messages. |
7905 |
Notice that the block might be called twice, |
|
7906 |
to print both on stderr and onto the Transcript" |
|
13350 | 7907 |
|
19428 | 7908 |
|stream stderr activeProcess| |
7909 |
||
7910 |
activeProcess := Processor activeProcess. |
|
7911 |
stderr := activeProcess stderr. |
|
20214 | 7912 |
|
16383 | 7913 |
"CG: care for standalone non-GUI progs, which have no userPreferences class" |
7914 |
(Smalltalk isInitialized |
|
7915 |
and:[ UserPreferences notNil |
|
7916 |
and:[ UserPreferences current sendMessagesAlsoToTranscript]]) ifTrue:[ |
|
20535 | 7917 |
stream := activeProcess isSystemProcess |
7918 |
ifTrue:[stderr] |
|
7919 |
ifFalse:[activeProcess transcript]. |
|
16378 | 7920 |
]. |
7921 |
stream notNil ifTrue:[ |
|
20535 | 7922 |
StreamError catch:[ |
7923 |
aBlock value:stream. |
|
7924 |
]. |
|
19382 | 7925 |
]. |
7926 |
stream ~~ stderr ifTrue:[ |
|
20535 | 7927 |
UserPreferences current sendMessagesOnlyToTranscript ifFalse:[ |
7928 |
aBlock value:stderr. |
|
7929 |
]. |
|
13350 | 7930 |
]. |
7931 |
||
7932 |
"Created: / 21-04-2011 / 12:46:21 / cg" |
|
5755 | 7933 |
! ! |
7934 |
||
7935 |
!Object methodsFor:'queries'! |
|
7936 |
||
7937 |
basicSize |
|
19451 | 7938 |
"return the number of the receiver's indexed instance variables, |
5755 | 7939 |
0 if it has none. |
7940 |
||
7941 |
This method should NOT be redefined in any subclass (except with great care, for tuning)" |
|
7942 |
||
7943 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
7944 |
#ifdef __SCHTEAM__ |
18404 | 7945 |
return context._RETURN( STInteger._new( self.basicSize() ) ); |
18215 | 7946 |
#else |
8909 | 7947 |
REGISTER INT nbytes; |
5755 | 7948 |
REGISTER OBJ myClass; |
7949 |
int nInstBytes; |
|
7950 |
||
7951 |
/* |
|
7952 |
* notice the missing test for self being a nonNilObject - |
|
7953 |
* this can be done since basicSize is defined both in UndefinedObject |
|
7954 |
* and SmallInteger |
|
7955 |
*/ |
|
7956 |
myClass = __qClass(self); |
|
7957 |
nbytes = __qSize(self); |
|
7958 |
nInstBytes = OHDR_SIZE + __OBJS2BYTES__( __intVal(__ClassInstPtr(myClass)->c_ninstvars) ); |
|
7959 |
||
7960 |
switch ((INT)(__ClassInstPtr(myClass)->c_flags) & __MASKSMALLINT(ARRAYMASK)) { |
|
20535 | 7961 |
case __MASKSMALLINT(POINTERARRAY): |
7962 |
case __MASKSMALLINT(WKPOINTERARRAY): |
|
7963 |
nbytes -= nInstBytes; |
|
7964 |
RETURN ( __mkSmallInteger(__BYTES2OBJS__(nbytes)) ); |
|
7965 |
||
7966 |
case __MASKSMALLINT(BYTEARRAY): |
|
7967 |
nbytes -= nInstBytes; |
|
7968 |
RETURN ( __mkSmallInteger(nbytes / sizeof(char)) ); |
|
7969 |
||
7970 |
case __MASKSMALLINT(FLOATARRAY): |
|
20303
060fea1cfebe
fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents:
20253
diff
changeset
|
7971 |
# ifdef __NEED_FLOATARRAY_ALIGN |
20535 | 7972 |
nInstBytes = (nInstBytes-1+__FLOATARRAY_ALIGN) &~ (__FLOATARRAY_ALIGN-1); |
20303
060fea1cfebe
fixes for float/doubleArray alignemnt
Claus Gittinger <cg@exept.de>
parents:
20253
diff
changeset
|
7973 |
# endif |
20535 | 7974 |
nbytes -= nInstBytes; |
7975 |
RETURN ( __mkSmallInteger(nbytes / sizeof(float)) ); |
|
7976 |
||
7977 |
case __MASKSMALLINT(DOUBLEARRAY): |
|
18215 | 7978 |
# ifdef __NEED_DOUBLE_ALIGN |
20535 | 7979 |
nInstBytes = (nInstBytes-1+__DOUBLE_ALIGN) &~ (__DOUBLE_ALIGN-1); |
18215 | 7980 |
# endif |
20535 | 7981 |
nbytes -= nInstBytes; |
7982 |
RETURN ( __mkSmallInteger(nbytes / sizeof(double)) ); |
|
7983 |
||
7984 |
case __MASKSMALLINT(WORDARRAY): |
|
7985 |
case __MASKSMALLINT(SWORDARRAY): |
|
7986 |
nbytes -= nInstBytes; |
|
7987 |
RETURN ( __mkSmallInteger(nbytes>>1) ); /* notice the hardcoded 2 here - not sizeof(short) */ |
|
7988 |
||
7989 |
case __MASKSMALLINT(LONGARRAY): |
|
7990 |
case __MASKSMALLINT(SLONGARRAY): |
|
7991 |
nbytes -= nInstBytes; |
|
7992 |
RETURN ( __mkSmallInteger(nbytes>>2) ); /* notice the hardcoded 4 here - not sizeof(int) */ |
|
7993 |
||
7994 |
case __MASKSMALLINT(LONGLONGARRAY): |
|
7995 |
case __MASKSMALLINT(SLONGLONGARRAY): |
|
18215 | 7996 |
# ifdef __NEED_LONGLONG_ALIGN |
20535 | 7997 |
nInstBytes = (nInstBytes-1+__LONGLONG_ALIGN) &~ (__LONGLONG_ALIGN-1); |
18215 | 7998 |
# endif |
20535 | 7999 |
nbytes -= nInstBytes; |
8000 |
RETURN ( __mkSmallInteger(nbytes>>3) ); /* notice the hardcoded 8 here - not sizeof(long long) */ |
|
5755 | 8001 |
} |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
8002 |
#endif /* not __SCHTEAM__ */ |
5755 | 8003 |
%}. |
8004 |
^ 0 |
|
8005 |
! |
|
8006 |
||
8007 |
byteSize |
|
19451 | 8008 |
"return the number of bytes in the receiver's indexed instance variables, |
5755 | 8009 |
0 if it has none. This only returns non-zero for non-pointer indexed |
8010 |
instvars i.e. byteArrays, wordArrays etc. |
|
8011 |
Notice: for Strings the returned size may look strange. |
|
8012 |
Only useful with binary storage." |
|
8013 |
||
8014 |
|myClass| |
|
8015 |
||
8016 |
myClass := self class. |
|
8017 |
myClass isVariable ifTrue:[ |
|
20535 | 8018 |
myClass isPointers ifFalse:[ |
8019 |
myClass isBytes ifTrue:[ |
|
8020 |
^ self basicSize. |
|
8021 |
]. |
|
8022 |
myClass isWords ifTrue:[ |
|
8023 |
^ self basicSize * 2. |
|
8024 |
]. |
|
8025 |
myClass isSignedWords ifTrue:[ |
|
8026 |
^ self basicSize * 2. |
|
8027 |
]. |
|
8028 |
myClass isLongs ifTrue:[ |
|
8029 |
^ self basicSize * 4. |
|
8030 |
]. |
|
8031 |
myClass isSignedLongs ifTrue:[ |
|
8032 |
^ self basicSize * 4. |
|
8033 |
]. |
|
8034 |
myClass isLongLongs ifTrue:[ |
|
8035 |
^ self basicSize * 8. |
|
8036 |
]. |
|
8037 |
myClass isSignedLongLongs ifTrue:[ |
|
8038 |
^ self basicSize * 8. |
|
8039 |
]. |
|
8040 |
myClass isFloats ifTrue:[ |
|
8041 |
^ self basicSize * (ExternalBytes sizeofFloat) |
|
8042 |
]. |
|
8043 |
myClass isDoubles ifTrue:[ |
|
8044 |
^ self basicSize * (ExternalBytes sizeofDouble) |
|
8045 |
]. |
|
8046 |
self error:'unknown variable size class species'. |
|
8047 |
] |
|
5755 | 8048 |
]. |
8049 |
^ 0 |
|
8050 |
||
8051 |
" |
|
10460 | 8052 |
Point new byteSize |
14632 | 8053 |
'hello' byteSize |
8054 |
'hello' asUnicode16String byteSize |
|
10460 | 8055 |
(ByteArray with:1 with:2) byteSize |
8056 |
(FloatArray with:1.5) byteSize |
|
8057 |
(DoubleArray with:1.5) byteSize |
|
8058 |
(WordArray with:1 with:2) byteSize |
|
5755 | 8059 |
" |
8060 |
! |
|
8061 |
||
8062 |
class |
|
19679 | 8063 |
"return the receiver's class" |
5755 | 8064 |
|
8065 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18238
diff
changeset
|
8066 |
#ifdef __SCHTEAM__ |
18215 | 8067 |
return context._RETURN(self.clazz()); |
8068 |
#else |
|
5755 | 8069 |
RETURN ( __Class(self) ); |
18215 | 8070 |
#endif |
5755 | 8071 |
%} |
19679 | 8072 |
|
8073 |
"Modified (comment): / 30-04-2016 / 15:51:17 / cg" |
|
5755 | 8074 |
! |
8075 |
||
8076 |
respondsTo:aSelector |
|
20214 | 8077 |
"return true if the receiver implements a method with selector equal |
5755 | 8078 |
to aSelector; i.e. if there is a method for aSelector in either the |
19451 | 8079 |
receiver's class or one of its superclasses. |
5755 | 8080 |
|
8081 |
Notice, that this does not imply, that such a message can be sent without |
|
8082 |
an error being raised. For example, an implementation could send |
|
8083 |
#shouldNotImplement or #subclassResponsibility." |
|
8084 |
||
8085 |
" |
|
8086 |
should we go via the cache, or search (by class) ? |
|
8087 |
The first is faster, most of the time; while the 2nd fills |
|
8088 |
the cache with useless data if this is sent in a loop over all objects. |
|
8089 |
For now, use the cache ... |
|
8090 |
" |
|
8091 |
%{ /* NOCONTEXT */ |
|
8092 |
||
8093 |
if (__lookup(__Class(self), aSelector) == nil) { |
|
20535 | 8094 |
RETURN ( false ); |
5755 | 8095 |
} |
8096 |
RETURN ( true ); |
|
8097 |
%} |
|
8098 |
. |
|
8099 |
^ self class canUnderstand:aSelector |
|
8100 |
||
8101 |
||
8102 |
"'aString' respondsTo:#+" |
|
8103 |
"'aString' respondsTo:#," |
|
8104 |
"'aString' respondsTo:#collect:" |
|
8105 |
! |
|
8106 |
||
8107 |
respondsToArithmetic |
|
20214 | 8108 |
"return true if the receiver responds to arithmetic messages. |
5755 | 8109 |
false is returned here - the method is redefined in ArithmeticValue." |
8110 |
||
8111 |
^ false |
|
8112 |
! |
|
8113 |
||
8114 |
size |
|
19451 | 8115 |
"return the number of the receiver's indexed instance variables; |
5755 | 8116 |
this method may be redefined in subclasses" |
8117 |
||
8118 |
^ self basicSize |
|
8119 |
! |
|
8120 |
||
8121 |
species |
|
19451 | 8122 |
"return a class which is similar to (or the same as) the receiver's class. |
5755 | 8123 |
This is used to create an appropriate object when creating derived |
8124 |
copies in the collection classes (sometimes redefined)." |
|
8125 |
||
8126 |
^ self class |
|
8127 |
! |
|
8128 |
||
16401 | 8129 |
speciesForCopy |
8130 |
"return a class which is the receiver's class, except for readonly objects, |
|
8131 |
such as immutable collections. |
|
8132 |
This is only to be used by copy methods" |
|
8133 |
||
8134 |
^ self class |
|
8135 |
! |
|
8136 |
||
5755 | 8137 |
yourself |
8138 |
"return the receiver - used for cascades to return self at the end" |
|
8139 |
||
8140 |
^ self |
|
8141 |
! ! |
|
8142 |
||
21389 | 8143 |
|
5755 | 8144 |
!Object methodsFor:'secure message sending'! |
8145 |
||
18215 | 8146 |
?:selector |
13099 | 8147 |
"try to send a message to the receiver; |
8148 |
if understood, return the value; |
|
8149 |
if not, return nil." |
|
18215 | 8150 |
|
13099 | 8151 |
^ self perform:selector ifNotUnderstood:nil |
8152 |
||
8153 |
" |
|
8154 |
ApplicationModel new masterApplication resources first - error |
|
8155 |
ApplicationModel new ?: #masterApplication ?: #resources ?: #first - nil |
|
8156 |
" |
|
8157 |
"Modified: / 20-10-2010 / 10:45:21 / cg" |
|
8158 |
! |
|
8159 |
||
5755 | 8160 |
askFor:aSelector |
8161 |
"try to send the receiver the message, aSelector. |
|
10460 | 8162 |
If it does not understand it, return false. |
5755 | 8163 |
Otherwise the real value returned. |
11398 | 8164 |
Useful to send messages such as: #isColor to unknown receivers." |
5755 | 8165 |
|
8166 |
^ self perform:aSelector ifNotUnderstood:[false] |
|
8167 |
||
8168 |
" |
|
10460 | 8169 |
1 askFor:#isColor |
8170 |
Color red askFor:#isColor |
|
8171 |
||
8172 |
1 askFor:#isFoo |
|
8173 |
Color red askFor:#isFoo |
|
5755 | 8174 |
" |
8175 |
! |
|
8176 |
||
11398 | 8177 |
askFor:aSelector with:argument |
8178 |
"try to send the receiver the message, aSelector. |
|
8179 |
If it does not understand it, return false. |
|
8180 |
Otherwise the real value returned. |
|
8181 |
Useful to send messages such as: #isXXX: to unknown receivers." |
|
8182 |
||
8183 |
^ self perform:aSelector with:argument ifNotUnderstood:[false] |
|
8184 |
! |
|
8185 |
||
11401 | 8186 |
askFor:aSelector with:arg1 with:arg2 |
8187 |
"try to send the receiver the message, aSelector. |
|
8188 |
If it does not understand it, return false. |
|
8189 |
Otherwise the real value returned. |
|
8190 |
Useful to send messages such as: #isXXX: to unknown receivers." |
|
8191 |
||
8192 |
^ self perform:aSelector with:arg1 with:arg2 ifNotUnderstood:[false] |
|
8193 |
! |
|
8194 |
||
5755 | 8195 |
perform:aSelector ifNotUnderstood:exceptionBlock |
8196 |
"try to send message aSelector to the receiver. |
|
21432 | 8197 |
If it's understood, return the method's returned value, |
12157 | 8198 |
otherwise return the value of the exceptionBlock. |
8199 |
Read this: |
|
8200 |
Many programmers do an Error-handle to perform a similar |
|
8201 |
checked-message send. However, this method is more specific, |
|
16560 | 8202 |
in that only errors for the given selector are caught - not any other |
12157 | 8203 |
doesNotUnderstand, and especially not any other error." |
5755 | 8204 |
|
21646 | 8205 |
^ [ |
8206 |
self perform:aSelector. |
|
8207 |
] on:MessageNotUnderstood do:[:ex | |
|
20535 | 8208 |
"/ reject, if the bad message is not the one |
8209 |
"/ we have sent originally |
|
8210 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
|
8211 |
ex reject |
|
8212 |
]. |
|
21646 | 8213 |
exceptionBlock value |
8214 |
]. |
|
5755 | 8215 |
|
8216 |
" |
|
10460 | 8217 |
1.2345 perform:#foo ifNotUnderstood:['sorry'] |
8218 |
1.2345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
8219 |
12345 perform:#sqrt ifNotUnderstood:['sorry'] |
|
5755 | 8220 |
" |
21432 | 8221 |
|
8222 |
"Modified (comment): / 13-02-2017 / 20:27:38 / cg" |
|
21646 | 8223 |
"Modified: / 15-03-2017 / 17:05:58 / stefan" |
5755 | 8224 |
! |
8225 |
||
8226 |
perform:aSelector with:argument ifNotUnderstood:exceptionBlock |
|
8227 |
"try to send message aSelector to the receiver. |
|
21432 | 8228 |
If it's understood, return the method's returned value, |
12157 | 8229 |
otherwise return the value of the exceptionBlock. |
8230 |
Read this: |
|
8231 |
Many programmers do an Error-handle to perform a similar |
|
8232 |
checked-message send. However, this method is more specific, |
|
16560 | 8233 |
in that only errors for the given selector are caught - not any other |
12157 | 8234 |
doesNotUnderstand, and especially not any other error." |
5755 | 8235 |
|
21646 | 8236 |
^ [ |
8237 |
self perform:aSelector with:argument. |
|
8238 |
] on:MessageNotUnderstood do:[:ex | |
|
20535 | 8239 |
"/ reject, if the bad message is not the one |
8240 |
"/ we have sent originally |
|
8241 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
|
8242 |
ex reject |
|
21646 | 8243 |
]. |
8244 |
exceptionBlock value |
|
8245 |
]. |
|
5755 | 8246 |
|
8247 |
" |
|
8248 |
|unknown| |
|
8249 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8250 |
unknown := 4. |
21646 | 8251 |
Transcript showCR:(unknown perform:#- with:2 ifNotUnderstood:['sorry']). |
5755 | 8252 |
unknown := 'high there'. |
21646 | 8253 |
Transcript showCR:(unknown perform:#- with:2 ifNotUnderstood:['sorry']) printCR. |
5755 | 8254 |
" |
21432 | 8255 |
|
8256 |
"Modified (comment): / 13-02-2017 / 20:27:41 / cg" |
|
21646 | 8257 |
"Modified (comment): / 15-03-2017 / 17:08:01 / stefan" |
5755 | 8258 |
! |
8259 |
||
5926 | 8260 |
perform:aSelector with:arg1 with:arg2 ifNotUnderstood:exceptionBlock |
8261 |
"try to send message aSelector to the receiver. |
|
21432 | 8262 |
If it's understood, return the method's returned value, |
12157 | 8263 |
otherwise return the value of the exceptionBlock. |
8264 |
Read this: |
|
8265 |
Many programmers do an Error-handle to perform a similar |
|
8266 |
checked-message send. However, this method is more specific, |
|
16560 | 8267 |
in that only errors for the given selector are caught - not any other |
12157 | 8268 |
doesNotUnderstand, and especially not any other error." |
5926 | 8269 |
|
21646 | 8270 |
^ [ |
8271 |
self perform:aSelector with:arg1 with:arg2. |
|
8272 |
] on:MessageNotUnderstood do:[:ex | |
|
20535 | 8273 |
"/ reject, if the bad message is not the one |
8274 |
"/ we have sent originally |
|
8275 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
|
8276 |
ex reject |
|
21646 | 8277 |
]. |
8278 |
exceptionBlock value |
|
8279 |
]. |
|
21432 | 8280 |
|
8281 |
"Modified (comment): / 13-02-2017 / 20:27:44 / cg" |
|
21646 | 8282 |
"Modified: / 15-03-2017 / 17:09:12 / stefan" |
5926 | 8283 |
! |
8284 |
||
5755 | 8285 |
perform:aSelector withArguments:argumentArray ifNotUnderstood:exceptionBlock |
8286 |
"try to send message aSelector to the receiver. |
|
21432 | 8287 |
If it's understood, return the method's returned value, |
12157 | 8288 |
otherwise return the value of the exceptionBlock. |
8289 |
Read this: |
|
8290 |
Many programmers do an Error-handle to perform a similar |
|
8291 |
checked-message send. However, this method is more specific, |
|
16560 | 8292 |
in that only errors for the given selector are caught - not any other |
12157 | 8293 |
doesNotUnderstand, and especially not any other error." |
5755 | 8294 |
|
21646 | 8295 |
^ [ |
8296 |
self perform:aSelector withArguments:argumentArray. |
|
8297 |
] on:MessageNotUnderstood do:[:ex | |
|
20535 | 8298 |
"/ reject, if the bad message is not the one |
21646 | 8299 |
"/ we have sent originally |
20535 | 8300 |
(ex selector == aSelector and:[ex receiver == self]) ifFalse:[ |
8301 |
ex reject |
|
21646 | 8302 |
]. |
8303 |
exceptionBlock value |
|
8304 |
]. |
|
5755 | 8305 |
|
8306 |
" |
|
8307 |
|unknown| |
|
8308 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8309 |
unknown := 4. |
21646 | 8310 |
Transcript showCR:(unknown perform:#- withArguments:#(2) ifNotUnderstood:['sorry']). |
5755 | 8311 |
unknown := 'high there'. |
21646 | 8312 |
Transcript showCR:(unknown perform:#- withArguments:#(2) ifNotUnderstood:['sorry']). |
5755 | 8313 |
" |
8314 |
||
21432 | 8315 |
"Modified: / 27-03-1997 / 14:13:16 / cg" |
8316 |
"Modified (comment): / 13-02-2017 / 20:27:46 / cg" |
|
21646 | 8317 |
"Modified: / 15-03-2017 / 17:10:27 / stefan" |
5755 | 8318 |
! ! |
8319 |
||
8320 |
!Object methodsFor:'signal constants'! |
|
8321 |
||
8322 |
messageNotUnderstoodSignal |
|
6146 | 8323 |
^ MessageNotUnderstood |
5755 | 8324 |
|
8325 |
"Created: 6.3.1997 / 15:46:52 / cg" |
|
8326 |
! ! |
|
8327 |
||
8328 |
!Object methodsFor:'special queries'! |
|
8329 |
||
8330 |
allOwners |
|
8331 |
"return a collection of all objects referencing the receiver" |
|
8332 |
||
8333 |
^ ObjectMemory whoReferences:self |
|
8334 |
! |
|
8335 |
||
8336 |
references:anObject |
|
20214 | 8337 |
"return true if the receiver refers to the argument, anObject. |
5755 | 8338 |
- for debugging only" |
8339 |
||
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8340 |
^ self referencesObject:anObject |
5755 | 8341 |
|
8342 |
" |
|
8343 |
|v| |
|
8344 |
||
8345 |
v := View new initialize. |
|
10460 | 8346 |
v references:Display. |
5755 | 8347 |
" |
8348 |
! |
|
8349 |
||
8350 |
referencesAny:aCollection |
|
20214 | 8351 |
"return true if the receiver refers to any object from |
5755 | 8352 |
the argument, aCollection. |
8353 |
- for debugging only" |
|
8354 |
||
10460 | 8355 |
%{ |
5755 | 8356 |
OBJ cls, flags; |
8357 |
int nInsts, inst; |
|
8358 |
||
8359 |
if (! __isNonNilObject(self)) { |
|
20535 | 8360 |
RETURN (false); |
5755 | 8361 |
} |
8362 |
||
8934 | 8363 |
if (__isArrayLike(aCollection)) { |
20535 | 8364 |
int nObjs = __arraySize(aCollection); |
8365 |
char *minAddr = 0, *maxAddr = 0; |
|
8366 |
||
8367 |
if (nObjs == 0) { |
|
8368 |
RETURN (false); |
|
8369 |
} |
|
8370 |
||
8371 |
cls = __qClass(self); |
|
8372 |
flags = __ClassInstPtr(cls)->c_flags; |
|
8373 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
|
8374 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
8375 |
} else { |
|
8376 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
|
8377 |
} |
|
8378 |
||
8379 |
if (nObjs == 1) { |
|
8380 |
/* better reverse the loop */ |
|
8381 |
OBJ anObject = __arrayVal(aCollection)[0]; |
|
8382 |
||
8383 |
if (anObject == cls) { |
|
8384 |
RETURN(true); |
|
8385 |
} |
|
8386 |
if (! nInsts) { |
|
8387 |
RETURN (false); |
|
8388 |
} |
|
8389 |
||
8390 |
if ((__qSpace(self) <= OLDSPACE) |
|
8391 |
&& !__isRemembered(self) |
|
8392 |
&& __isNonNilObject(anObject)) { |
|
8393 |
int spc = __qSpace(anObject); |
|
8394 |
||
8395 |
if ((spc == NEWSPACE) || (spc == SURVSPACE)) { |
|
8396 |
RETURN(false); |
|
8397 |
} |
|
8398 |
} |
|
16325 | 8399 |
|
18231 | 8400 |
# if defined(memsrch4) |
20535 | 8401 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
8402 |
RETURN (true); |
|
8403 |
} |
|
18231 | 8404 |
# else |
20535 | 8405 |
for (inst=0; inst<nInsts; inst++) { |
8406 |
if ((__InstPtr(self)->i_instvars[inst]) == anObject) { |
|
8407 |
RETURN (true); |
|
8408 |
} |
|
8409 |
} |
|
18231 | 8410 |
# endif |
20535 | 8411 |
RETURN (false); |
8412 |
} |
|
8413 |
||
8414 |
/* |
|
8415 |
* a little optimization: use the fact that all old objects |
|
8416 |
* refering to a new object are on the remSet; if I am not, |
|
8417 |
* a trivial reject is possible, if all objects are newbees. |
|
8418 |
* as a side effect, gather min/max addresses |
|
8419 |
*/ |
|
8420 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
|
8421 |
int allNewBees = 1; |
|
8422 |
int i; |
|
8423 |
||
8424 |
minAddr = (char *)(__arrayVal(aCollection)[0]); |
|
8425 |
maxAddr = minAddr; |
|
8426 |
||
8427 |
for (i=0; i<nObjs; i++) { |
|
8428 |
OBJ anObject = __arrayVal(aCollection)[i]; |
|
8429 |
||
8430 |
if (__isNonNilObject(anObject)) { |
|
8431 |
int spc = __qSpace(anObject); |
|
8432 |
||
8433 |
if ((spc != NEWSPACE) && (spc != SURVSPACE)) { |
|
8434 |
allNewBees = 0; |
|
8435 |
} |
|
8436 |
} |
|
8437 |
||
8438 |
if ((char *)anObject < minAddr) { |
|
8439 |
minAddr = (char *)anObject; |
|
8440 |
} else if ((char *)anObject > maxAddr) { |
|
8441 |
maxAddr = (char *)anObject; |
|
8442 |
} |
|
8443 |
} |
|
8444 |
if (allNewBees) { |
|
8445 |
RETURN (false); |
|
8446 |
} |
|
8447 |
} |
|
8448 |
||
8449 |
/* |
|
8450 |
* fetch min/max in searchList (if not already done above) |
|
8451 |
*/ |
|
8452 |
if (minAddr == 0) { |
|
8453 |
int i; |
|
8454 |
||
8455 |
for (i=0; i<nObjs; i++) { |
|
8456 |
char *anObject = (char *)__arrayVal(aCollection)[i]; |
|
8457 |
||
8458 |
if (anObject < minAddr) { |
|
8459 |
minAddr = anObject; |
|
8460 |
} else if (anObject > maxAddr) { |
|
8461 |
maxAddr = anObject; |
|
8462 |
} |
|
8463 |
} |
|
8464 |
} |
|
8465 |
||
8466 |
if (((char *)cls >= minAddr) && ((char *)cls <= maxAddr)) { |
|
18231 | 8467 |
# if defined(memsrch4) |
20535 | 8468 |
if (memsrch4(__arrayVal(aCollection), (INT)cls, nObjs)) { |
8469 |
RETURN (true); |
|
8470 |
} |
|
18231 | 8471 |
# else |
20535 | 8472 |
int i; |
8473 |
||
8474 |
for (i=0; i<nObjs; i++) { |
|
8475 |
if (cls == __arrayVal(aCollection)[i]) { |
|
8476 |
RETURN (true); |
|
8477 |
} |
|
8478 |
} |
|
18231 | 8479 |
# endif /* memsrch4 */ |
20535 | 8480 |
} |
8481 |
||
8482 |
for (inst=0; inst<nInsts; inst++) { |
|
8483 |
OBJ instVar = __InstPtr(self)->i_instvars[inst]; |
|
8484 |
int i; |
|
8485 |
||
8486 |
if (((char *)instVar >= minAddr) && ((char *)instVar <= maxAddr)) { |
|
18231 | 8487 |
# if defined(memsrch4) |
20535 | 8488 |
if (memsrch4(__arrayVal(aCollection), (INT)instVar, nObjs)) { |
8489 |
RETURN (true); |
|
8490 |
} |
|
18231 | 8491 |
# else |
20535 | 8492 |
for (i=0; i<nObjs; i++) { |
8493 |
if (instVar == __arrayVal(aCollection)[i]) { |
|
8494 |
RETURN (true); |
|
8495 |
} |
|
8496 |
} |
|
18231 | 8497 |
# endif /* memsrch4 */ |
20535 | 8498 |
} |
8499 |
} |
|
8500 |
RETURN (false); |
|
5755 | 8501 |
} |
8502 |
%}. |
|
8503 |
||
8504 |
aCollection do:[:el | |
|
20535 | 8505 |
(self referencesObject:el) ifTrue:[^ true]. |
5755 | 8506 |
]. |
8507 |
^ false |
|
8508 |
! |
|
8509 |
||
8510 |
referencesDerivedInstanceOf:aClass |
|
20214 | 8511 |
"return true if the receiver refers to an instance of |
5755 | 8512 |
the argument, aClass or its subclass. This method exists |
8513 |
to support searching for users of a class." |
|
8514 |
||
10460 | 8515 |
|myClass |
5755 | 8516 |
numInst "{ Class: SmallInteger }" | |
8517 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8518 |
"check the class" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8519 |
(self isKindOf:aClass) ifTrue:[^ true]. |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
8520 |
|
5755 | 8521 |
myClass := self class. |
8522 |
"check the instance variables" |
|
8523 |
numInst := myClass instSize. |
|
10460 | 8524 |
1 to:numInst do:[:i | |
20535 | 8525 |
((self instVarAt:i) isKindOf:aClass) ifTrue:[^ true] |
5755 | 8526 |
]. |
8527 |
||
8528 |
"check the indexed variables" |
|
8529 |
myClass isVariable ifTrue:[ |
|
20535 | 8530 |
myClass isPointers ifFalse:[ |
8531 |
"no need to search in non pointer fields" |
|
8532 |
((aClass == Number) or:[aClass isSubclassOf:Number]) ifFalse:[^ false]. |
|
8533 |
]. |
|
8534 |
numInst := self basicSize. |
|
8535 |
1 to:numInst do:[:i | |
|
8536 |
((self basicAt:i) isKindOf:aClass) ifTrue:[^ true] |
|
8537 |
] |
|
5755 | 8538 |
]. |
8539 |
^ false |
|
8540 |
||
8541 |
" |
|
10460 | 8542 |
(1 @ 3.4) referencesDerivedInstanceOf:Number |
8543 |
(1 @ 3.4) referencesDerivedInstanceOf:Array |
|
8544 |
View new initialize referencesDerivedInstanceOf:DeviceWorkstation |
|
5755 | 8545 |
" |
8546 |
! |
|
8547 |
||
9279 | 8548 |
referencesForWhich:checkBlock do:actionBlock |
8549 |
|myClass inst |
|
8550 |
numInst "{ Class: SmallInteger }" | |
|
8551 |
||
8552 |
myClass := self class. |
|
8553 |
"check the instance variables" |
|
8554 |
numInst := myClass instSize. |
|
10460 | 8555 |
1 to:numInst do:[:i | |
20535 | 8556 |
inst := self instVarAt:i. |
8557 |
(checkBlock value:inst) ifTrue:[actionBlock value:inst]. |
|
9279 | 8558 |
]. |
8559 |
||
8560 |
"check the indexed variables" |
|
8561 |
myClass isVariable ifTrue:[ |
|
20535 | 8562 |
myClass isPointers ifTrue:[ |
8563 |
"no need to search in non pointer fields" |
|
8564 |
||
8565 |
numInst := self basicSize. |
|
8566 |
1 to:numInst do:[:i | |
|
8567 |
inst := self basicAt:i. |
|
8568 |
(checkBlock value:inst) ifTrue:[actionBlock value:inst]. |
|
8569 |
] |
|
8570 |
] |
|
10460 | 8571 |
]. |
8572 |
||
8573 |
" |
|
8574 |
(1 @ 3.4) referencesForWhich:[:i | i isFloat] do:[:i | Transcript showCR:i] |
|
9279 | 8575 |
" |
8576 |
! |
|
8577 |
||
5755 | 8578 |
referencesInstanceOf:aClass |
20214 | 8579 |
"return true if the receiver refers to an instance of |
5755 | 8580 |
the argument, aClass.This method exists |
8581 |
to support searching for users of a class." |
|
8582 |
||
10460 | 8583 |
|myClass |
5755 | 8584 |
numInst "{ Class: SmallInteger }" | |
8585 |
||
8586 |
myClass := self class. |
|
8587 |
||
8588 |
"check the class" |
|
8589 |
(myClass isMemberOf:aClass) ifTrue:[^ true]. |
|
8590 |
||
8591 |
"check the instance variables" |
|
8592 |
numInst := myClass instSize. |
|
10460 | 8593 |
1 to:numInst do:[:i | |
20535 | 8594 |
((self instVarAt:i) isMemberOf:aClass) ifTrue:[^ true] |
5755 | 8595 |
]. |
8596 |
||
8597 |
"check the indexed variables" |
|
8598 |
myClass isVariable ifTrue:[ |
|
20535 | 8599 |
myClass isPointers ifFalse:[ |
8600 |
"no need to search in non-pointer indexed fields" |
|
8601 |
myClass isLongs ifTrue:[ |
|
8602 |
(aClass == SmallInteger or:[aClass == LargeInteger]) ifFalse:[^ false]. |
|
8603 |
] ifFalse:[ |
|
8604 |
myClass isFloatsOrDoubles ifTrue:[^ aClass == Float]. |
|
8605 |
^ aClass == SmallInteger |
|
8606 |
] |
|
8607 |
]. |
|
8608 |
numInst := self basicSize. |
|
8609 |
1 to:numInst do:[:i | |
|
8610 |
((self basicAt:i) isMemberOf:aClass) ifTrue:[^ true] |
|
8611 |
] |
|
5755 | 8612 |
]. |
8613 |
^ false |
|
8614 |
||
8615 |
" |
|
10460 | 8616 |
(1 @ 3.4) referencesInstanceOf:Float |
8617 |
(1 @ 3.4) referencesInstanceOf:Fraction |
|
8618 |
View new initialize referencesInstanceOf:(Display class) |
|
5755 | 8619 |
" |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8620 |
! |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8621 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8622 |
referencesObject:anObject |
20214 | 8623 |
"return true if the receiver refers to the argument, anObject. |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8624 |
- for debugging only" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8625 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8626 |
%{ /* NOCONTEXT */ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8627 |
OBJ cls, flags; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8628 |
int nInsts, i; |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8629 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8630 |
if (! __isNonNilObject(self)) { |
20535 | 8631 |
RETURN (false); |
16325 | 8632 |
} |
8633 |
cls = __qClass(self); |
|
8634 |
if (cls == anObject) { |
|
20535 | 8635 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8636 |
} |
16325 | 8637 |
flags = __ClassInstPtr(cls)->c_flags; |
8638 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
|
20535 | 8639 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
16325 | 8640 |
} else { |
20535 | 8641 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
16325 | 8642 |
} |
8643 |
if (! nInsts) { |
|
20535 | 8644 |
RETURN (false); |
16325 | 8645 |
} |
8646 |
||
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8647 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8648 |
/* |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8649 |
* a little optimization: use the fact that all old objects |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8650 |
* refering to a new object are on the remSet; if I am not, |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8651 |
* a trivial reject is possible, if anObject is a newbee |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8652 |
*/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8653 |
if (__isNonNilObject(anObject)) { |
20535 | 8654 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
8655 |
int spc; |
|
8656 |
||
8657 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
8658 |
RETURN (false); |
|
8659 |
} |
|
8660 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8661 |
} |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8662 |
|
18231 | 8663 |
# if defined(memsrch4) |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8664 |
if (memsrch4(__InstPtr(self)->i_instvars, (INT)anObject, nInsts)) { |
20535 | 8665 |
RETURN (true); |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8666 |
} |
18231 | 8667 |
# else |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8668 |
for (i=0; i<nInsts; i++) { |
20535 | 8669 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
8670 |
RETURN (true); |
|
8671 |
} |
|
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8672 |
} |
18231 | 8673 |
# endif /* memsrch4 */ |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8674 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8675 |
%}. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8676 |
|
10460 | 8677 |
"/ |myClass |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8678 |
"/ numInst "{ Class: SmallInteger }" | |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8679 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8680 |
"/ myClass := self class. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8681 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8682 |
"/ "check the class" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8683 |
"/ (myClass == anObject) ifTrue:[^ true]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8684 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8685 |
"/ "check the instance variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8686 |
"/ numInst := myClass instSize. |
10460 | 8687 |
"/ 1 to:numInst do:[:i | |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8688 |
"/ ((self instVarAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8689 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8690 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8691 |
"/ "check the indexed variables" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8692 |
"/ myClass isVariable ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8693 |
"/ myClass isPointers ifFalse:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8694 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8695 |
"/ "/ we could argue about the following unconditional return: |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8696 |
"/ "/ it says that a non pointer array never has a reference to the |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8697 |
"/ "/ corresponding object - not mimicing a reference to a copy of the |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8698 |
"/ "/ integer. However, it avoids useless searches in huge byteArray |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8699 |
"/ "/ like objects when searching for owners. If in doubt, remove it. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8700 |
"/ "/ A consequence of the return below is that #[1 2 3] will say that it |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8701 |
"/ "/ does not refer to the number 2 (think of keeping a copy instead) |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8702 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8703 |
"/ ^ false. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8704 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8705 |
"/ "/ alternative: |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8706 |
"/ "/ anObject isNumber ifFalse:[^ false]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8707 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8708 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8709 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8710 |
"/ "/ because arrays are so common, and those have a highly tuned |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8711 |
"/ "/ idenitytIndex method, use it |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8712 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8713 |
"/ myClass == Array ifTrue:[ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8714 |
"/ ^ (self identityIndexOf:anObject) ~~ 0 |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8715 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8716 |
"/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8717 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8718 |
"/ "/ otherwise, do it the slow way |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8719 |
"/ "/ |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8720 |
"/ numInst := self basicSize. |
10460 | 8721 |
"/ 1 to:numInst do:[:i | |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8722 |
"/ ((self basicAt:i) == anObject) ifTrue:[^ true] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8723 |
"/ ] |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8724 |
"/ ]. |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8725 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8726 |
^ false |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8727 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8728 |
" |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8729 |
|v| |
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8730 |
|
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8731 |
v := View new initialize. |
10460 | 8732 |
v references:Display. |
6074
d91c99700e3b
renamed #references: (conflict with RB's #references)
Claus Gittinger <cg@exept.de>
parents:
6069
diff
changeset
|
8733 |
" |
5755 | 8734 |
! ! |
8735 |
||
21389 | 8736 |
|
5755 | 8737 |
!Object methodsFor:'synchronized evaluation'! |
8738 |
||
10460 | 8739 |
freeSynchronizationSemaphore |
5755 | 8740 |
"free synchronizationSemaphore. May be used, to save memory when |
8741 |
an object is no longer used synchronized." |
|
8742 |
||
8743 |
|sema| |
|
8744 |
||
8745 |
sema := self synchronizationSemaphore. |
|
8746 |
sema notNil ifTrue:[ |
|
20535 | 8747 |
sema wait. "/ get lock |
8748 |
self synchronizationSemaphore:nil. |
|
5755 | 8749 |
]. |
8750 |
||
8751 |
" |
|
8752 |
self synchronized:[]. |
|
8753 |
self synchronizationSemaphore. |
|
8754 |
self freeSynchronizationSemaphore. |
|
8755 |
" |
|
8756 |
||
8757 |
"Created: 28.1.1997 / 19:31:20 / stefan" |
|
8758 |
"Modified: 28.1.1997 / 19:47:55 / stefan" |
|
8759 |
! |
|
8760 |
||
8761 |
synchronizationSemaphore |
|
8762 |
"return the synchronization semaphore for myself. |
|
8763 |
subclasses may redefine" |
|
8764 |
||
8765 |
^ SynchronizationSemaphores at:self ifAbsent:[]. |
|
8766 |
||
8767 |
" |
|
8768 |
self synchronizationSemaphore |
|
8769 |
" |
|
8770 |
||
8771 |
"Modified: 28.1.1997 / 19:47:09 / stefan" |
|
8772 |
! |
|
8773 |
||
8774 |
synchronizationSemaphore:aSemaphore |
|
8775 |
"set the synchronisationSemaphore for myself. |
|
8776 |
subclasses may redefine this method" |
|
8777 |
||
8778 |
aSemaphore isNil ifTrue:[ |
|
20535 | 8779 |
"/ remove Semaphore |
8780 |
SynchronizationSemaphores removeKey:self ifAbsent:nil. |
|
5755 | 8781 |
] ifFalse:[ |
20535 | 8782 |
SynchronizationSemaphores at:self put:aSemaphore. |
5755 | 8783 |
]. |
8784 |
||
8785 |
"Modified: 28.1.1997 / 19:37:48 / stefan" |
|
8786 |
! |
|
8787 |
||
8788 |
synchronized:aBlock |
|
8789 |
"evaluate aBlock synchronized, i.e. use a monitor for this object" |
|
8790 |
||
6600 | 8791 |
|sema wasBlocked| |
8792 |
||
8793 |
wasBlocked := OperatingSystem blockInterrupts. |
|
5755 | 8794 |
|
8795 |
sema := self synchronizationSemaphore. |
|
8796 |
sema isNil ifTrue:[ |
|
20535 | 8797 |
sema := RecursionLock new name:self className. |
8798 |
self synchronizationSemaphore:sema. |
|
5755 | 8799 |
]. |
8800 |
||
6600 | 8801 |
wasBlocked ifFalse:[OperatingSystem unblockInterrupts]. |
18799 | 8802 |
^ sema critical:aBlock. |
5755 | 8803 |
|
8804 |
" |
|
8805 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'1']] fork. |
|
8806 |
[Object synchronized:[Delay waitForSeconds:2. Transcript showCR:'2']] fork. |
|
8807 |
" |
|
8808 |
||
8809 |
"Created: 28.1.1997 / 17:52:56 / stefan" |
|
8810 |
"Modified: 30.1.1997 / 13:38:54 / cg" |
|
8811 |
"Modified: 20.2.1997 / 09:43:35 / stefan" |
|
8812 |
! ! |
|
8813 |
||
8814 |
!Object methodsFor:'system primitives'! |
|
8815 |
||
8816 |
asOop |
|
8817 |
"ST-80 compatibility: |
|
8818 |
ST-80 returns an OOP-identity based number here (I guess: its address |
|
8819 |
or index); since ST/X has no such thing, and the objects address cannot |
|
10460 | 8820 |
be used (since its changing over time), we return the objects identityHash |
5755 | 8821 |
key, which provides (at least) some identity indication. |
8822 |
However, notice that (in contrast to ST-80's #asOop), the identityHash |
|
8823 |
key of two non-identical objects may be the same. |
|
8824 |
You'd better not use it - especially do not misuse it." |
|
8825 |
||
8826 |
^ self identityHash |
|
8827 |
||
8828 |
"Created: 9.11.1996 / 19:09:56 / cg" |
|
8829 |
"Modified: 9.11.1996 / 19:16:04 / cg" |
|
8830 |
! |
|
8831 |
||
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8832 |
beImmutable |
20526 | 8833 |
"experimental - not yet usable; do not use. |
8834 |
For now the #isImmutable flag prohibits only #become*." |
|
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8835 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8836 |
%{ /* NOCONTEXT */ |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8837 |
if (! __isNonNilObject(self)) { |
20526 | 8838 |
RETURN (self); |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8839 |
} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8840 |
__beImmutable(self); |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8841 |
%} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8842 |
! |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8843 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8844 |
beMutable |
20526 | 8845 |
"experimental - not yet usable; do not use. |
8846 |
For now the #isImmutable flag prohibits only #become*." |
|
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8847 |
|
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8848 |
%{ /* NOCONTEXT */ |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8849 |
if (! __isNonNilObject(self)) { |
20526 | 8850 |
RETURN (self); |
8939
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8851 |
} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8852 |
__beMutable(self); |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8853 |
%} |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8854 |
! |
ac97eb450b97
Fix examples in #perform:*ifNotUnderstood:
Stefan Vogel <sv@exept.de>
parents:
8935
diff
changeset
|
8855 |
|
5755 | 8856 |
become:anotherObject |
8857 |
"make all references to the receiver become references to anotherObject |
|
8858 |
and vice-versa. Notice the vice-versa; see #becomeSameAs: for a one-way become. |
|
8859 |
This can be a very dangerous operation - be warned. |
|
10460 | 8860 |
In general, using #become: should be avoided if possible, since it may |
5755 | 8861 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
8862 |
||
10460 | 8863 |
This may also be an expensive (i.e. slow) operation, |
8864 |
since in the worst case, the whole memory has to be searched for |
|
5755 | 8865 |
references to the two objects (although the primitive tries hard to |
10460 | 8866 |
limit the search, for acceptable performance in most cases). |
8867 |
This method fails, if the receiver or the argument is a SmallInteger |
|
8868 |
or nil, or is a context of a living method (i.e. one that has not already |
|
5755 | 8869 |
returned). |
10460 | 8870 |
(notice that #become: is not used heavily by the system |
5755 | 8871 |
- the Collection-classes have been rewritten to not use it.)" |
8872 |
%{ |
|
8873 |
if (__primBecome(self, anotherObject)) { |
|
20526 | 8874 |
RETURN ( self ); |
5755 | 8875 |
} |
8876 |
%}. |
|
20526 | 8877 |
NoModificationError raiseRequestWith:self errorString:' - #become: failed'. |
5755 | 8878 |
! |
8879 |
||
8880 |
becomeNil |
|
8881 |
"make all references to the receiver become nil - effectively getting |
|
10460 | 8882 |
rid of the receiver. |
5755 | 8883 |
This can be a very dangerous operation - be warned. |
8884 |
||
8885 |
This may be an expensive (i.e. slow) operation. |
|
8886 |
The receiver may not be a SmallInteger or a context of a living method." |
|
8887 |
||
8888 |
%{ |
|
8889 |
if (__primBecomeNil(self)) { |
|
20526 | 8890 |
RETURN ( nil ); |
5755 | 8891 |
} |
8892 |
%}. |
|
20526 | 8893 |
NoModificationError raiseRequestWith:self errorString:' - #becomeNil failed'. |
5755 | 8894 |
! |
8895 |
||
8896 |
becomeSameAs:anotherObject |
|
8897 |
"make all references to the receiver become references to anotherObject |
|
8898 |
but NOT vice versa (as done in #become:). |
|
8899 |
This can be a very dangerous operation - be warned. |
|
10460 | 8900 |
In general, using #become: should be avoided if possible, since it may |
5755 | 8901 |
produce many strange effects (think of hashing in Sets, Dictionaries etc.). |
8902 |
||
8903 |
This may also be an expensive (i.e. slow) operation, |
|
8904 |
since in the worst case, the whole memory has to be searched for |
|
8905 |
references to the two objects (although the primitive tries hard to |
|
8906 |
limit the search, for acceptable performance in most cases). |
|
8907 |
This method fails, if the receiver or the argument is a SmallInteger |
|
8908 |
or nil, or is a context of a living method (i.e. one that has not already returned)." |
|
8909 |
%{ |
|
8910 |
if (__primBecomeSameAs(self, anotherObject)) { |
|
20526 | 8911 |
RETURN ( self ); |
5755 | 8912 |
} |
8913 |
%}. |
|
20526 | 8914 |
NoModificationError raiseRequestWith:self errorString:' - #becomeSameAs: failed'. |
5755 | 8915 |
! |
8916 |
||
8917 |
changeClassTo:otherClass |
|
8918 |
"changes the class of the receiver to the argument, otherClass. |
|
19451 | 8919 |
This is only allowed (possible), if the receiver's class and the argument |
5755 | 8920 |
have the same structure (i.e. number of named instance variables and |
10460 | 8921 |
type of indexed instance variables). |
5755 | 8922 |
If the structures do not match, or any of the original class or new class |
8923 |
is UndefinedObject or a Smallinteger, a primitive error is triggered." |
|
8924 |
||
8925 |
|myClass ok| |
|
8926 |
||
9405 | 8927 |
otherClass autoload. |
8928 |
||
5755 | 8929 |
"check for UndefinedObject/SmallInteger receiver or newClass" |
8930 |
%{ |
|
18371 | 8931 |
#ifdef __SCHTEAM__ |
8932 |
ok = (self.isSTInstance() && otherClass.isSTInstance()) |
|
20535 | 8933 |
? STObject.True : STObject.False; |
18371 | 8934 |
#else |
5755 | 8935 |
{ |
20535 | 8936 |
OBJ other = otherClass; |
8937 |
||
8938 |
if (__isNonNilObject(self) |
|
8939 |
&& __isNonNilObject(other) |
|
8940 |
&& (other != UndefinedObject) |
|
8941 |
&& (other != SmallInteger)) { |
|
8942 |
ok = true; |
|
8943 |
} else { |
|
8944 |
ok = false; |
|
8945 |
} |
|
5755 | 8946 |
} |
18371 | 8947 |
#endif /* not SCHTEAM */ |
5755 | 8948 |
%}. |
18231 | 8949 |
ok == true ifTrue:[ |
20535 | 8950 |
ok := false. |
8951 |
myClass := self class. |
|
8952 |
myClass == otherClass ifTrue:[ |
|
8953 |
"nothing to change" |
|
8954 |
^ self. |
|
8955 |
]. |
|
8956 |
myClass flags == otherClass flags ifTrue:[ |
|
8957 |
myClass instSize == otherClass instSize ifTrue:[ |
|
8958 |
"same instance layout and types: its ok to do it" |
|
8959 |
ok := true. |
|
8960 |
] ifFalse:[ |
|
8961 |
myClass isPointers ifTrue:[ |
|
8962 |
myClass isVariable ifTrue:[ |
|
8963 |
ok := true |
|
8964 |
] |
|
8965 |
] |
|
8966 |
] |
|
8967 |
] ifFalse:[ |
|
8968 |
myClass isPointers ifTrue:[ |
|
8969 |
"if newClass is a variable class, with instSize <= my instsize, |
|
8970 |
we can do it (effectively mapping additional instvars into the |
|
8971 |
variable part) - usefulness is questionable, though" |
|
8972 |
||
8973 |
otherClass isPointers ifTrue:[ |
|
8974 |
otherClass isVariable ifTrue:[ |
|
8975 |
otherClass instSize <= (myClass instSize + self basicSize) |
|
8976 |
ifTrue:[ |
|
8977 |
ok := true |
|
8978 |
] |
|
8979 |
] ifFalse:[ |
|
8980 |
otherClass instSize == (myClass instSize + self basicSize) |
|
8981 |
ifTrue:[ |
|
8982 |
ok := true |
|
8983 |
] |
|
8984 |
] |
|
8985 |
] ifFalse:[ |
|
8986 |
"it does not make sense to convert pointers to bytes ..." |
|
8987 |
] |
|
8988 |
] ifFalse:[ |
|
8989 |
"does it make sense, to convert bits ?" |
|
8990 |
"could allow byteArray->wordArray->longArray->floatArray->doubleArray here ..." |
|
8991 |
(myClass isBitsExtended and:[otherClass isBitsExtended]) ifTrue:[ |
|
8992 |
ok := true |
|
8993 |
] |
|
8994 |
] |
|
8995 |
] |
|
5755 | 8996 |
]. |
18231 | 8997 |
ok == true ifTrue:[ |
20535 | 8998 |
"now, change the receiver's class ..." |
5755 | 8999 |
%{ |
18371 | 9000 |
#ifdef __SCHTEAM__ |
20535 | 9001 |
((STInstance)self).clazz = (STClass)otherClass; |
9002 |
return __c__._RETURN(self); |
|
18371 | 9003 |
#else |
20535 | 9004 |
{ |
9005 |
OBJ me = self; |
|
9006 |
||
9007 |
// gcc4.4 does not like this: |
|
9008 |
// __qClass(me) = otherClass; |
|
9009 |
__objPtr(me)->o_class = (CLASS_OBJ)otherClass; |
|
9010 |
__STORE(me, otherClass); |
|
9011 |
RETURN (me); |
|
9012 |
} |
|
18371 | 9013 |
#endif /* not SCHTEAM */ |
5755 | 9014 |
%}. |
9015 |
]. |
|
9405 | 9016 |
|
5755 | 9017 |
" |
9018 |
the receiver cannot be represented as a instance of |
|
9019 |
the desired class. |
|
10460 | 9020 |
For example, you cannot change a bitInstance (byteArray etc.) |
5755 | 9021 |
into a pointer object and vice versa. |
9022 |
" |
|
9023 |
self primitiveFailed |
|
9024 |
! |
|
9025 |
||
9026 |
changeClassToThatOf:anObject |
|
9027 |
"changes the class of the receiver to that of the argument, anObject. |
|
19451 | 9028 |
This is only allowed (possible), if the receiver's class and the arguments |
10460 | 9029 |
class have the same structure (i.e. number of named instance variables and |
5755 | 9030 |
type of indexed instance variables). If the structures do not match, or any |
9031 |
of the objects is nil or a Smallinteger, a primitive error is triggered." |
|
9032 |
||
9033 |
self changeClassTo:(anObject class) |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9034 |
! |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9035 |
|
8935 | 9036 |
isImmutable |
20526 | 9037 |
"experimental - not yet usable; do not use. |
9038 |
For now the #isImmutable flag prohibits only #become*." |
|
9039 |
||
8935 | 9040 |
|
9041 |
%{ /* NOCONTEXT */ |
|
9042 |
if (! __isNonNilObject(self)) { |
|
20526 | 9043 |
RETURN (true); |
8935 | 9044 |
} |
19646 | 9045 |
if (__isImmutable(self)) { |
20526 | 9046 |
RETURN (true); |
19646 | 9047 |
} |
9048 |
%}. |
|
9049 |
^ false |
|
8935 | 9050 |
! |
9051 |
||
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9052 |
replaceReferencesTo:anObject with:newRef |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9053 |
"if the receiver refers to the argument, anObject, replace this reference with newRef. |
20214 | 9054 |
Return true if any reference was changed. |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9055 |
Notice: this does not change the class-reference." |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9056 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9057 |
%{ /* NOCONTEXT */ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9058 |
OBJ cls, flags, anyChange; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9059 |
int nInsts, i; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9060 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9061 |
if (! __isNonNilObject(self)) { |
20535 | 9062 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9063 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9064 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9065 |
/* |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9066 |
* a little optimization: use the fact that all old objects |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9067 |
* refering to a new object are on the remSet; if I am not, |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9068 |
* a trivial reject is possible, if anObject is a newbee |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9069 |
*/ |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9070 |
if (__isNonNilObject(anObject)) { |
20535 | 9071 |
if ((__qSpace(self) <= OLDSPACE) && !__isRemembered(self)) { |
9072 |
int spc; |
|
9073 |
||
9074 |
if (((spc = __qSpace(anObject)) == NEWSPACE) || (spc == SURVSPACE)) { |
|
9075 |
RETURN (false); |
|
9076 |
} |
|
9077 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9078 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9079 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9080 |
cls = __qClass(self); |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9081 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9082 |
flags = __ClassInstPtr(cls)->c_flags; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9083 |
if (((INT)flags & __MASKSMALLINT(ARRAYMASK)) == __MASKSMALLINT(POINTERARRAY)) { |
20535 | 9084 |
nInsts = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9085 |
} else { |
20535 | 9086 |
nInsts = __intVal(__ClassInstPtr(cls)->c_ninstvars); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9087 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9088 |
if (! nInsts) { |
20535 | 9089 |
RETURN (false); |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9090 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9091 |
anyChange = false; |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9092 |
for (i=0; i<nInsts; i++) { |
20535 | 9093 |
if (__InstPtr(self)->i_instvars[i] == anObject) { |
9094 |
__InstPtr(self)->i_instvars[i] = newRef; |
|
9095 |
__STORE(self, newRef); |
|
9096 |
// __dumpObject__(self, __LINE__); |
|
9097 |
anyChange = true; |
|
9098 |
} |
|
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9099 |
} |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9100 |
RETURN (anyChange); |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9101 |
%}. |
18231 | 9102 |
self primitiveFailed |
6033
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9103 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9104 |
" |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9105 |
|v| |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9106 |
|
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9107 |
v := Array with:1234 with:'hello' with:Array. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9108 |
v replaceReferencesTo:Array with:ByteArray. |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9109 |
v inspect |
be1b7877b425
+ #replaceReferencesTo:with:
Claus Gittinger <cg@exept.de>
parents:
6005
diff
changeset
|
9110 |
" |
15586 | 9111 |
|
9112 |
"Modified: / 30-07-2013 / 21:48:06 / cg" |
|
5755 | 9113 |
! ! |
9114 |
||
9115 |
!Object methodsFor:'testing'! |
|
9116 |
||
9117 |
? defaultValue |
|
11634 | 9118 |
"a syntactic sugar-piece: |
5755 | 9119 |
if the receiver is nil, return the defaultValue; |
9120 |
otherwise, return the receiver. |
|
9121 |
This method is only redefined in UndefinedObject - therefore, |
|
20214 | 9122 |
the receiver is returned here. |
5755 | 9123 |
|
9124 |
Thus, if foo and bar are simple variables or constants, |
|
20535 | 9125 |
foo ? bar |
5755 | 9126 |
is the same as: |
20535 | 9127 |
(foo isNil ifTrue:[bar] ifFalse:[foo]) |
5755 | 9128 |
|
9129 |
if they are message sends, the equivalent code is: |
|
20535 | 9130 |
[ |
9131 |
|t1 t2| |
|
9132 |
||
9133 |
t1 := foo. |
|
9134 |
t2 := bar. |
|
9135 |
t1 isNil ifTrue:[t2] ifFalse:[t1] |
|
9136 |
] value |
|
5755 | 9137 |
|
9138 |
Can be used to provide defaultValues to variables, |
|
9139 |
as in: |
|
20535 | 9140 |
foo := arg ? #defaultValue |
5755 | 9141 |
|
9142 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
9143 |
Notice: |
|
20535 | 9144 |
This method is open coded (inlined) by the compiler(s) |
9145 |
- redefining it may not work as expected." |
|
5755 | 9146 |
|
9147 |
^ self |
|
9148 |
||
9149 |
" |
|
9150 |
1 ? #default |
|
9151 |
nil ? #default |
|
9152 |
" |
|
9153 |
||
9154 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
9155 |
"Modified: / 19.5.1998 / 17:39:56 / cg" |
|
9156 |
! |
|
9157 |
||
16126 | 9158 |
?+ aOneArgBlock |
9159 |
"a syntactic sugar-piece: |
|
9160 |
aOneArgBlock is executed with self as argument |
|
9161 |
if self is not nil. |
|
9162 |
||
9163 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
9164 |
" |
|
9165 |
||
9166 |
^ aOneArgBlock value:self |
|
9167 |
||
9168 |
" |
|
9169 |
1 ?+ [:v| v + 5] |
|
9170 |
nil ?+ [:v| v + 5] |
|
9171 |
" |
|
9172 |
! |
|
9173 |
||
5755 | 9174 |
?? defaultValue |
11634 | 9175 |
"a syntactic sugar-piece: |
5755 | 9176 |
much like ?, but sends #value to the argument if required. |
20214 | 9177 |
(i.e. it is the same as #ifNil:) |
5755 | 9178 |
If the receiver is nil, return the defaultValues value; |
9179 |
otherwise, return the receiver. |
|
9180 |
This method is only redefined in UndefinedObject - therefore, |
|
20214 | 9181 |
the receiver is returned here. |
5755 | 9182 |
|
9183 |
Thus, if foo and bar are simple variables or constants, |
|
20535 | 9184 |
foo ?? bar |
5755 | 9185 |
is the same as: |
20535 | 9186 |
(foo isNil ifTrue:[bar value] ifFalse:[foo]) |
5755 | 9187 |
|
9188 |
if they are message sends, the equivalent code is: |
|
20535 | 9189 |
[ |
9190 |
|t t2| |
|
9191 |
||
9192 |
t := foo. |
|
9193 |
t isNil ifTrue:[bar value] ifFalse:[t] |
|
9194 |
] value |
|
5755 | 9195 |
|
9196 |
Can be used to provide defaultValues to variables, |
|
9197 |
as in: |
|
20535 | 9198 |
foo := arg ?? [ self computeDefault ] |
5755 | 9199 |
|
9200 |
Note: this method should never be redefined in classes other than UndefinedObject. |
|
9201 |
" |
|
9202 |
||
9203 |
^ self |
|
9204 |
||
9205 |
" |
|
10460 | 9206 |
1 ?? #default |
5755 | 9207 |
nil ?? #default |
10460 | 9208 |
1 ?? [ self halt. 1 + 2 ] |
9209 |
nil ?? [ self halt. 1 + 2 ] |
|
9210 |
1 ?? [Date today] |
|
9211 |
nil ?? [Date today] |
|
5755 | 9212 |
" |
9213 |
||
9214 |
"Created: / 4.11.1996 / 20:36:19 / cg" |
|
9215 |
"Modified: / 19.5.1998 / 17:42:56 / cg" |
|
9216 |
! |
|
9217 |
||
9218 |
ifNil:aBlockOrValue |
|
9219 |
"return myself, or the result from evaluating the argument, if I am nil. |
|
9220 |
This is much like #?, but sends #value to the argument in case of a nil |
|
9221 |
receiver. |
|
9222 |
Notice: |
|
20535 | 9223 |
This method is open coded (inlined) by the compiler(s) |
9224 |
- redefining it may not work as expected." |
|
5755 | 9225 |
|
9226 |
^ self |
|
9227 |
! |
|
9228 |
||
9229 |
ifNil:nilBlockOrValue ifNotNil:notNilBlockOrValue |
|
9230 |
"return the value of the first arg, if I am nil, |
|
9231 |
the result from evaluating the 2nd argument, if I am not nil. |
|
9232 |
Notice: |
|
20535 | 9233 |
This method is open coded (inlined) by the compiler(s) |
9234 |
- redefining it may not work as expected." |
|
18440 | 9235 |
|
21666 | 9236 |
(notNilBlockOrValue isBlockWithArgumentCount:1) ifTrue:[ |
20535 | 9237 |
^ notNilBlockOrValue value:self. |
15501 | 9238 |
]. |
5755 | 9239 |
^ notNilBlockOrValue value |
21661 | 9240 |
|
21666 | 9241 |
"Modified: / 18-03-2017 / 19:07:10 / stefan" |
5755 | 9242 |
! |
9243 |
||
9244 |
ifNotNil:aBlockOrValue |
|
10460 | 9245 |
"return myself if nil, or the result from evaluating the argument, |
5755 | 9246 |
if I am not nil. |
9247 |
Notice: |
|
20535 | 9248 |
This method is open coded (inlined) by the compiler(s) |
9249 |
- redefining it may not work as expected." |
|
18440 | 9250 |
|
21661 | 9251 |
(aBlockOrValue isBlockWithArgumentCount:1) ifTrue:[ |
20535 | 9252 |
^ aBlockOrValue value:self. |
15501 | 9253 |
]. |
5755 | 9254 |
^ aBlockOrValue value |
21661 | 9255 |
|
9256 |
"Modified: / 18-03-2017 / 18:09:14 / stefan" |
|
5755 | 9257 |
! |
9258 |
||
9259 |
ifNotNil:notNilBlockOrValue ifNil:nilBlockOrValue |
|
9260 |
"return the value of the 2nd arg, if I am nil, |
|
9261 |
the result from evaluating the 1st argument, if I am not nil. |
|
9262 |
Notice: |
|
20535 | 9263 |
This method is open coded (inlined) by the compiler(s) |
9264 |
- redefining it may not work as expected." |
|
18440 | 9265 |
|
21661 | 9266 |
(notNilBlockOrValue isBlockWithArgumentCount:1) ifTrue:[ |
20535 | 9267 |
^ notNilBlockOrValue value:self. |
15501 | 9268 |
]. |
5755 | 9269 |
^ notNilBlockOrValue value |
21661 | 9270 |
|
9271 |
"Modified: / 18-03-2017 / 18:26:29 / stefan" |
|
5755 | 9272 |
! |
9273 |
||
8574 | 9274 |
ifNotNilDo:aBlock |
20351 | 9275 |
"if the receiver is non-nil, return the value of aBlock, passing myself as argument. |
8574 | 9276 |
Otherwise do nothing and return nil." |
9277 |
||
9278 |
^ aBlock value:self |
|
9279 |
! |
|
9280 |
||
5755 | 9281 |
isArray |
20214 | 9282 |
"return true if the receiver is some kind of array (or weakArray etc); |
5755 | 9283 |
false is returned here - the method is only redefined in Array." |
9284 |
||
9285 |
^ false |
|
9286 |
! |
|
9287 |
||
9288 |
isAssociation |
|
20214 | 9289 |
"return true if the receiver is some kind of association; |
5755 | 9290 |
false is returned here - the method is only redefined in Association." |
9291 |
||
9292 |
^ false |
|
9293 |
||
9294 |
"Created: 14.5.1996 / 17:03:45 / cg" |
|
9295 |
! |
|
9296 |
||
9297 |
isBehavior |
|
20214 | 9298 |
"return true if the receiver is describing another object's behavior. |
9221 | 9299 |
False is returned here - the method is only redefined in Behavior." |
5755 | 9300 |
|
9301 |
^ false |
|
9302 |
! |
|
9303 |
||
9304 |
isBlock |
|
20214 | 9305 |
"return true if the receiver is some kind of block; |
5755 | 9306 |
false returned here - the method is only redefined in Block." |
9307 |
||
9308 |
^ false |
|
9309 |
! |
|
9310 |
||
21661 | 9311 |
isBlockWithArgumentCount:count |
9312 |
"return true if the receiver is some kind of block; |
|
9313 |
false returned here - the method is only redefined in Block." |
|
9314 |
||
9315 |
^ false |
|
9316 |
||
9317 |
"Created: / 18-03-2017 / 18:07:26 / stefan" |
|
9318 |
! |
|
9319 |
||
5824 | 9320 |
isBoolean |
20214 | 9321 |
"return true if the receiver is a boolean; |
5824 | 9322 |
false is returned here - the method is only redefined in Boolean." |
9323 |
||
9324 |
^ false |
|
9325 |
! |
|
9326 |
||
5755 | 9327 |
isByteArray |
20214 | 9328 |
"return true if the receiver is some kind of bytearray; |
5755 | 9329 |
false is returned here - the method is only redefined in ByteArray." |
9330 |
||
9331 |
^ false |
|
9332 |
! |
|
9333 |
||
8986 | 9334 |
isByteCollection |
20214 | 9335 |
"return true if the receiver is some kind of byte collection, |
10460 | 9336 |
i.e. #at: and #at:put: accesses a byte. This is different from 'self class isBytes', |
8986 | 9337 |
since e.g. in BitArray single bits are accessed, but it is implemented as variableBytes class. |
10460 | 9338 |
|
8986 | 9339 |
false is returned here - the method is only redefined in UninterpretedBytes." |
9340 |
||
9341 |
^ false |
|
9342 |
! |
|
9343 |
||
5755 | 9344 |
isCharacter |
20214 | 9345 |
"return true if the receiver is some kind of character; |
5755 | 9346 |
false is returned here - the method is only redefined in Character." |
9347 |
||
9348 |
^ false |
|
9349 |
! |
|
9350 |
||
9351 |
isClass |
|
20214 | 9352 |
"return true if the receiver is some kind of class |
9405 | 9353 |
(real class, not just behavior); |
5755 | 9354 |
false is returned here - the method is only redefined in Class." |
9355 |
||
9356 |
^ false |
|
9357 |
! |
|
9358 |
||
9359 |
isCollection |
|
20214 | 9360 |
"return true if the receiver is some kind of collection; |
5755 | 9361 |
false is returned here - the method is only redefined in Collection." |
9362 |
||
9363 |
^ false |
|
9364 |
! |
|
9365 |
||
9366 |
isColor |
|
20214 | 9367 |
"return true if the receiver is some kind of color; |
5755 | 9368 |
false is returned here - the method is only redefined in Color." |
9369 |
||
9370 |
^ false |
|
9371 |
! |
|
9372 |
||
6567 | 9373 |
isCons |
20214 | 9374 |
"return true if the receiver is a cons (pair); |
6567 | 9375 |
false is returned here - the method is only redefined in Cons." |
9376 |
||
9377 |
^ false |
|
9378 |
! |
|
9379 |
||
5755 | 9380 |
isContext |
20214 | 9381 |
"return true if the receiver is some kind of Context; |
5755 | 9382 |
false returned here - the method is only redefined in Context." |
9383 |
||
9384 |
^ false |
|
9385 |
! |
|
9386 |
||
15362 | 9387 |
isDictionary |
20214 | 9388 |
"return true if the receiver is some kind of dictionary; |
15362 | 9389 |
false returned here - the method is only redefined in Dictionary." |
9390 |
||
9391 |
^ false |
|
9392 |
! |
|
9393 |
||
6181 | 9394 |
isEmptyOrNil |
8833 | 9395 |
"return true if I am nil or an empty collection - return false here. |
9396 |
(from Squeak)" |
|
6181 | 9397 |
|
9398 |
^ false |
|
9399 |
||
9400 |
"Created: / 13.11.2001 / 13:17:04 / cg" |
|
6182 | 9401 |
"Modified: / 13.11.2001 / 13:28:40 / cg" |
6181 | 9402 |
! |
9403 |
||
6221 | 9404 |
isException |
15362 | 9405 |
"answer true, if this is an Exception" |
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9406 |
|
6221 | 9407 |
^ false |
9408 |
||
9409 |
"Created: / 17.11.2001 / 18:37:44 / cg" |
|
9410 |
! |
|
9411 |
||
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9412 |
isExceptionCreator |
20214 | 9413 |
"return true if the receiver can create exceptions, |
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9414 |
this includes #raise, #raiseRequest as well as the behavior of |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9415 |
an exception handler, such as the #accepts: and #handles: messages" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9416 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9417 |
^ false |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9418 |
! |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9419 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9420 |
isExceptionHandler |
20214 | 9421 |
"return true if the receiver responds to the exception handler protocol, |
6631
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9422 |
especially to the #accepts: and #handles: messages" |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9423 |
|
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9424 |
^ false |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9425 |
! |
5ffa1ce7b2cc
#isExceptionCreator instead of #isSignal
Stefan Vogel <sv@exept.de>
parents:
6600
diff
changeset
|
9426 |
|
13187 | 9427 |
isExternalAddress |
20214 | 9428 |
"return true if the receiver is some kind of externalAddress; |
13187 | 9429 |
false is returned here - the method is only redefined in ExternalAddress." |
9430 |
||
9431 |
^ false |
|
9432 |
||
9433 |
"Created: / 22-12-2010 / 17:20:36 / cg" |
|
9434 |
! |
|
9435 |
||
14079 | 9436 |
isExternalBytes |
9437 |
^ false |
|
9438 |
! |
|
9439 |
||
10480 | 9440 |
isExternalLibraryFunction |
20214 | 9441 |
"return true if the receiver is some kind of externalLibrary function; |
10480 | 9442 |
false is returned here - the method is only redefined in ExternalLibraryFunction." |
9443 |
||
9444 |
^false |
|
9445 |
! |
|
9446 |
||
5755 | 9447 |
isExternalStream |
20214 | 9448 |
"return true if the receiver is some kind of externalStream; |
5755 | 9449 |
false is returned here - the method is only redefined in ExternalStream." |
9450 |
||
9451 |
^false |
|
9452 |
! |
|
9453 |
||
19550 | 9454 |
isExternalStructure |
9455 |
^ false |
|
9456 |
! |
|
9457 |
||
5755 | 9458 |
isFileStream |
20214 | 9459 |
"return true if the receiver is some kind of fileStream; |
5755 | 9460 |
false is returned here - the method is only redefined in FileStream." |
9461 |
||
9462 |
^false |
|
9463 |
! |
|
9464 |
||
9465 |
isFilename |
|
20214 | 9466 |
"return true if the receiver is some kind of filename; |
5755 | 9467 |
false is returned here - the method is only redefined in Filename." |
9468 |
||
9469 |
^false |
|
9470 |
! |
|
9471 |
||
9472 |
isFixedPoint |
|
20214 | 9473 |
"return true if the receiver is some kind of fixedPoint number; |
5755 | 9474 |
false is returned here - the method is only redefined in FixedPoint." |
9475 |
||
9476 |
^ false |
|
9477 |
||
9478 |
"Created: 5.11.1996 / 19:23:04 / cg" |
|
9479 |
! |
|
9480 |
||
9481 |
isFixedSize |
|
10460 | 9482 |
"return true if the receiver cannot grow easily |
5755 | 9483 |
(i.e. a grow may be expensive, since it involves a become:)" |
9484 |
||
9485 |
^ true |
|
9486 |
! |
|
9487 |
||
6185 | 9488 |
isFloat |
20214 | 9489 |
"return true if the receiver is some kind of floating point number; |
6185 | 9490 |
false is returned here. |
9491 |
Same as #isLimitedPrecisionReal, but a better name ;-)" |
|
9492 |
||
9493 |
^ false |
|
9494 |
||
9495 |
"Modified: / 14.11.2001 / 14:57:46 / cg" |
|
9496 |
! |
|
9497 |
||
5755 | 9498 |
isForm |
20214 | 9499 |
"return true if the receiver is some kind of form; |
5755 | 9500 |
false is returned here - the method is only redefined in Form." |
9501 |
||
9502 |
^ false |
|
9503 |
! |
|
9504 |
||
9505 |
isFraction |
|
20214 | 9506 |
"return true if the receiver is some kind of fraction; |
5755 | 9507 |
false is returned here - the method is only redefined in Fraction." |
9508 |
||
9509 |
^ false |
|
9510 |
! |
|
9511 |
||
9293 | 9512 |
isHierarchicalItem |
9513 |
"used to decide if the parent is a hierarchical item or the model" |
|
9514 |
||
9515 |
^ false |
|
9516 |
! |
|
9517 |
||
5755 | 9518 |
isImage |
20214 | 9519 |
"return true if the receiver is some kind of image; |
5755 | 9520 |
false is returned here - the method is only redefined in Image." |
9521 |
||
9522 |
^ false |
|
9523 |
! |
|
9524 |
||
9525 |
isImageOrForm |
|
20214 | 9526 |
"return true if the receiver is some kind of image or form; |
5755 | 9527 |
false is returned here - the method is only redefined in Image and Form." |
9528 |
||
9529 |
^ false |
|
9530 |
! |
|
9531 |
||
9532 |
isImmediate |
|
9533 |
"return true if I am an immediate object |
|
9534 |
i.e. I am represented in the pointer itself and |
|
9535 |
no real object header/storage is used me. |
|
9536 |
(currently, only SmallIntegers, some characters and nil return true)" |
|
9537 |
||
9538 |
^ self class hasImmediateInstances |
|
9539 |
||
9540 |
"Created: 3.6.1997 / 12:00:18 / cg" |
|
9541 |
! |
|
9542 |
||
9543 |
isInteger |
|
20214 | 9544 |
"return true if the receiver is some kind of integer number; |
5755 | 9545 |
false is returned here - the method is only redefined in Integer." |
9546 |
||
9547 |
^ false |
|
9548 |
! |
|
9549 |
||
9279 | 9550 |
isInterestConverter |
9551 |
"return true if I am a kind of interest forwarder" |
|
9552 |
||
9553 |
^ false |
|
9554 |
! |
|
9555 |
||
10576 | 9556 |
isInternalByteStream |
9557 |
"return true, if the receiver is some kind of Stream for reading bytes; |
|
9558 |
false is returned here - the method is only redefined in PeekableStream." |
|
9559 |
||
9560 |
^false |
|
9561 |
||
9562 |
"Created: / 30-05-2007 / 16:15:33 / cg" |
|
9563 |
! |
|
9564 |
||
5755 | 9565 |
isJavaClass |
20214 | 9566 |
"return true if this is a JavaClass. |
5755 | 9567 |
false is returned here - the method is only redefined in JavaClass." |
9568 |
||
9569 |
^ false |
|
9570 |
||
9571 |
"Created: / 26.3.1997 / 13:34:54 / cg" |
|
9572 |
"Modified: / 8.5.1998 / 21:25:21 / cg" |
|
9573 |
! |
|
9574 |
||
9575 |
isJavaClassRef |
|
20214 | 9576 |
"return true if this is a JavaClassRef. |
5755 | 9577 |
false is returned here - the method is only redefined in JavaClassRef." |
9578 |
||
9579 |
^ false |
|
9580 |
||
9581 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
9582 |
"Created: / 24.12.1999 / 01:46:28 / cg" |
|
9583 |
! |
|
9584 |
||
9585 |
isJavaContext |
|
20214 | 9586 |
"return true if this is a JavaContext. |
5755 | 9587 |
false is returned here - the method is only redefined in JavaContext." |
9588 |
||
9589 |
^ false |
|
9590 |
||
9591 |
"Created: / 8.5.1998 / 21:24:27 / cg" |
|
9592 |
"Modified: / 8.5.1998 / 21:25:35 / cg" |
|
9593 |
! |
|
9594 |
||
9595 |
isJavaMethod |
|
20214 | 9596 |
"return true if this is a JavaMethod. |
5755 | 9597 |
false is returned here - the method is only redefined in JavaMethod." |
9598 |
||
9599 |
^ false |
|
9600 |
||
9601 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
9602 |
"Created: / 25.9.1999 / 23:26:12 / cg" |
|
9603 |
! |
|
9604 |
||
9605 |
isJavaMethodRef |
|
20214 | 9606 |
"return true if this is a JavaMethodRef. |
5755 | 9607 |
false is returned here - the method is only redefined in JavaMethodRef." |
9608 |
||
9609 |
^ false |
|
9610 |
||
9611 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
9612 |
"Created: / 23.12.1999 / 19:44:51 / cg" |
|
9613 |
! |
|
9614 |
||
9615 |
isJavaObject |
|
20214 | 9616 |
"return true if this is a JavaObject. |
5755 | 9617 |
false is returned here - the method is only redefined in JavaObject." |
9618 |
||
9619 |
^ false |
|
9620 |
||
9621 |
"Created: / 26.3.1997 / 13:34:48 / cg" |
|
9622 |
"Modified: / 8.5.1998 / 21:25:46 / cg" |
|
9623 |
! |
|
9624 |
||
9625 |
isJavaScriptClass |
|
20214 | 9626 |
"return true if this is a JavaScriptClass. |
5755 | 9627 |
false is returned here - the method is only redefined in JavaScriptClass." |
9628 |
||
9629 |
^ false |
|
9630 |
! |
|
9631 |
||
8935 | 9632 |
isJavaScriptMetaclass |
20214 | 9633 |
"return true if this is a JavaScript Metaclass. |
8935 | 9634 |
false is returned here - the method is only redefined in JavaScriptMetaclass." |
9635 |
||
9636 |
^ false |
|
9637 |
! |
|
9638 |
||
5755 | 9639 |
isKindOf:aClass |
20214 | 9640 |
"return true if the receiver is an instance of aClass or one of its |
5755 | 9641 |
subclasses, false otherwise. |
10460 | 9642 |
Advice: |
20535 | 9643 |
use of this to check objects for certain attributes/protocol should |
9644 |
be avoided; it limits the reusability of your classes by limiting use |
|
9645 |
to instances of certain classes and fences you into a specific inheritance |
|
9646 |
hierarchy. |
|
9647 |
Use check-methods to check an object for a certain attributes/protocol |
|
9648 |
(such as #isXXXX, #respondsTo: or #isNumber). |
|
9649 |
||
9650 |
Using #isKindOf: is considered BAD STYLE. |
|
5755 | 9651 |
|
9652 |
Advice2: |
|
20535 | 9653 |
Be aware, that using an #isXXX method is usually much faster than |
9654 |
using #isKindOf:; because isKindOf: has to walk up all the superclass |
|
9655 |
hierarchy, comparing every class on the way. |
|
9656 |
Due to caching in the VM, a call to #isXXX is normally reached via |
|
9657 |
a single function call. |
|
5755 | 9658 |
" |
9659 |
||
9660 |
%{ /* NOCONTEXT */ |
|
9661 |
register OBJ thisClass; |
|
9662 |
||
9663 |
thisClass = __Class(self); |
|
9664 |
while (thisClass != nil) { |
|
20535 | 9665 |
if (thisClass == aClass) { |
9666 |
RETURN ( true ); |
|
9667 |
} |
|
9668 |
thisClass = __ClassInstPtr(thisClass)->c_superclass; |
|
5755 | 9669 |
} |
9670 |
RETURN ( false ); |
|
9671 |
%} |
|
9672 |
||
9673 |
"/ |
|
9674 |
"/ the above code is equivalent to: |
|
9675 |
"/ |
|
9676 |
"/ thisClass := self class. |
|
9677 |
"/ [thisClass notNil] whileTrue:[ |
|
9678 |
"/ thisClass == aClass ifTrue:[^ true]. |
|
9679 |
"/ thisClass := thisClass superclass |
|
9680 |
"/ ]. |
|
9681 |
"/ ^ false |
|
9682 |
"/ |
|
9683 |
! |
|
9684 |
||
17168 | 9685 |
isLabelAndIcon |
20214 | 9686 |
"return true if the receiver is a LabelAndIcon; |
17168 | 9687 |
false is returned here - the method is only redefined in LabelAndIcon." |
9688 |
||
9689 |
^ false |
|
9690 |
! |
|
9691 |
||
5755 | 9692 |
isLayout |
20214 | 9693 |
"return true if the receiver is some kind of layout; |
5755 | 9694 |
false is returned here - the method is only redefined in Layout." |
9695 |
||
9696 |
^ false |
|
9697 |
! |
|
9698 |
||
6567 | 9699 |
isLazyValue |
9700 |
^ false |
|
9701 |
! |
|
9702 |
||
6086
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
9703 |
isLimitedPrecisionReal |
20214 | 9704 |
"return true if the receiver is some kind of floating point number; |
6086
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
9705 |
false is returned here - the method is only redefined in LimitedPrecisionReal." |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
9706 |
|
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
9707 |
^ false |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
9708 |
! |
0bd476397581
added isLimitedPrecisionReal
Claus Gittinger <cg@exept.de>
parents:
6074
diff
changeset
|
9709 |
|
5755 | 9710 |
isList |
20214 | 9711 |
"return true if the receiver is some kind of list collection; |
5755 | 9712 |
false is returned here - the method is only redefined in List." |
9713 |
||
9714 |
^ false |
|
9715 |
||
9716 |
"Created: / 11.2.2000 / 01:37:05 / cg" |
|
9717 |
! |
|
9718 |
||
9719 |
isLiteral |
|
20214 | 9720 |
"return true if the receiver can be represented as a literal constant in ST syntax; |
5755 | 9721 |
false is returned here - the method is redefined in some classes." |
9722 |
||
9723 |
^ false |
|
9724 |
! |
|
9725 |
||
9726 |
isMemberOf:aClass |
|
20214 | 9727 |
"return true if the receiver is an instance of aClass, false otherwise. |
10460 | 9728 |
Advice: |
20535 | 9729 |
use of this to check objects for certain attributes/protocol should |
9730 |
be avoided; it limits the reusability of your classes by limiting use |
|
9731 |
to instances of a certain class. |
|
9732 |
Use check-methods to check an object for a certain attributes/protocol |
|
9733 |
(such as #isXXX, #respondsTo: or #isNumber); |
|
9734 |
||
9735 |
Using #isMemberOf: is considered BAD STYLE. |
|
5755 | 9736 |
Notice: |
20535 | 9737 |
This method is open coded (inlined) by the compiler(s) |
9738 |
- redefining it may not work as expected." |
|
5755 | 9739 |
|
9740 |
^ (self class) == aClass |
|
9741 |
! |
|
9742 |
||
18319 | 9743 |
isMenuItem |
20214 | 9744 |
"return true if the receiver is a menu item inside a MenuPanel, Menu or PopUpmenu. |
18319 | 9745 |
false is returned here - the method is redefined in some classes." |
9746 |
||
9747 |
^ false |
|
9748 |
! |
|
9749 |
||
5755 | 9750 |
isMeta |
20214 | 9751 |
"return true if the receiver is some kind of metaclass; |
5755 | 9752 |
false is returned here - the method is only redefined in Metaclass." |
9753 |
||
9754 |
^ false |
|
9755 |
! |
|
9756 |
||
9757 |
isMethod |
|
20214 | 9758 |
"return true if the receiver is some kind of method; |
16021 | 9759 |
false returned here - this method is only redefined in Method." |
5755 | 9760 |
|
9761 |
^ false |
|
9762 |
! |
|
9763 |
||
9764 |
isMorph |
|
20214 | 9765 |
"return true if the receiver is some kind of morph; |
5755 | 9766 |
false is returned here - the method is only redefined in Morph." |
9767 |
||
9768 |
^ false |
|
9769 |
! |
|
9770 |
||
9771 |
isNameSpace |
|
20214 | 9772 |
"return true if the receiver is a NameSpace. |
9221 | 9773 |
False is returned here - the method is only redefined in Namespace." |
5755 | 9774 |
|
9775 |
^ false |
|
9776 |
||
9777 |
"Created: / 11.10.1996 / 18:08:56 / cg" |
|
9778 |
"Modified: / 8.5.1998 / 21:26:05 / cg" |
|
9779 |
! |
|
9780 |
||
9781 |
isNamespace |
|
20214 | 9782 |
"return true if this is a NameSpace. |
5755 | 9783 |
false is returned here - the method is only redefined in Namespace." |
9784 |
||
5869 | 9785 |
<resource:#obsolete> |
9786 |
||
5755 | 9787 |
self obsoleteMethodWarning:'use #isNameSpace'. |
6805 | 9788 |
^ self isNameSpace |
5755 | 9789 |
! |
9790 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9791 |
isNil |
20214 | 9792 |
"Return true if the receiver is nil. |
9221 | 9793 |
Because isNil is redefined in UndefinedObject, |
9794 |
the receiver is definitely not nil here, so unconditionally return false. |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9795 |
Notice: |
20535 | 9796 |
This method is open coded (inlined) by the compiler(s) |
9797 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9798 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9799 |
^ false |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9800 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9801 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9802 |
isNilOrEmptyCollection |
6182 | 9803 |
"return true if I am nil or an empty collection - false here. |
8833 | 9804 |
Obsolete, use isEmptyOrNil." |
9805 |
||
9806 |
<resource:#obsolete> |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9807 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9808 |
^ false |
6182 | 9809 |
|
9810 |
"Modified: / 13.11.2001 / 13:28:06 / cg" |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9811 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
9812 |
|
9005 | 9813 |
isNonByteCollection |
20214 | 9814 |
"return true if the receiver is some kind of collection, but not a String, ByteArray etc.; |
9005 | 9815 |
false is returned here - the method is redefined in Collection and UninterpretedBytes." |
9816 |
||
9817 |
^ false |
|
9818 |
||
9819 |
" |
|
20535 | 9820 |
21 isNonByteCollection |
9821 |
'abc' isNonByteCollection |
|
9822 |
#'abc' isNonByteCollection |
|
9823 |
#[1 2 3] isNonByteCollection |
|
9824 |
#(1 2 3) isNonByteCollection |
|
9005 | 9825 |
" |
9826 |
! |
|
9827 |
||
16907
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9828 |
isNotNil |
19781 | 9829 |
<resource: #obsolete> |
9830 |
||
20214 | 9831 |
"Return true if the receiver is not nil. |
16907
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9832 |
Because isNotNil is redefined in UndefinedObject, |
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9833 |
the receiver is definitely not nil here, so unconditionally return true." |
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9834 |
|
19781 | 9835 |
self obsoleteMethodWarning:'use #notNil'. |
16907
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9836 |
^ true |
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9837 |
|
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9838 |
"Created: / 26-10-2014 / 01:30:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9839 |
! |
402df2d3c1d7
added: Object>>isNotNil
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16828
diff
changeset
|
9840 |
|
5755 | 9841 |
isNumber |
20214 | 9842 |
"return true if the receiver is some kind of number; |
5755 | 9843 |
false is returned here - the method is only redefined in Number." |
9844 |
||
9845 |
^ false |
|
9846 |
! |
|
9847 |
||
21069 | 9848 |
isOSErrorHolder |
9849 |
^ false |
|
9850 |
! |
|
9851 |
||
5755 | 9852 |
isOrderedCollection |
20214 | 9853 |
"return true if the receiver is some kind of ordered collection (or list etc); |
5755 | 9854 |
false is returned here - the method is only redefined in OrderedCollection." |
9855 |
||
9856 |
^ false |
|
9857 |
! |
|
9858 |
||
16342 | 9859 |
isOsHandle |
9860 |
^ false |
|
9861 |
! |
|
9862 |
||
18894 | 9863 |
isPlainString |
20214 | 9864 |
"return true if the receiver is a plain string - without attributes; |
18894 | 9865 |
false is returned here - the method is redefined in CharacterArray and Text." |
9866 |
||
9867 |
^ false |
|
9868 |
! |
|
9869 |
||
5755 | 9870 |
isPoint |
20214 | 9871 |
"return true if the receiver is some kind of point; |
5755 | 9872 |
false is returned here - the method is only redefined in Point." |
9873 |
||
9874 |
^ false |
|
9875 |
! |
|
9876 |
||
10532 | 9877 |
isPrinterContext |
9878 |
||
9879 |
^false |
|
9880 |
! |
|
9881 |
||
13416 | 9882 |
isProgrammingLanguage |
20214 | 9883 |
"return true if the receiver is a programming language. |
14632 | 9884 |
False is returned here - the method is only redefined in |
13416 | 9885 |
ProgrammingLanguage." |
9886 |
||
9887 |
^ false |
|
9888 |
||
9889 |
"Created: / 21-07-2010 / 15:13:50 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
9890 |
! |
|
9891 |
||
9515 | 9892 |
isProjectDefinition |
20214 | 9893 |
"return true if the receiver is a projectDefinition. |
9515 | 9894 |
False is returned here - the method is only redefined in ProjectDefinition." |
9895 |
||
9896 |
^ false |
|
9897 |
||
9898 |
"Created: / 10-08-2006 / 16:24:53 / cg" |
|
9899 |
! |
|
9900 |
||
21074 | 9901 |
isProtoObject |
9902 |
^ false |
|
9903 |
! |
|
9904 |
||
13140 | 9905 |
isProxy |
20214 | 9906 |
"return true if the receiver is a proxy for another (lazy loaded) object. |
13140 | 9907 |
False is returned here." |
9908 |
||
9909 |
^ false |
|
9910 |
||
9911 |
"Created: / 21-11-2010 / 11:15:46 / cg" |
|
9912 |
! |
|
9913 |
||
10171 | 9914 |
isRealNameSpace |
20214 | 9915 |
"return true if the receiver is a NameSpace, but not Smalltalk (which is also a class). |
15439 | 9916 |
False is returned here - the method is redefined in Namespace and Smalltalk." |
10171 | 9917 |
|
9918 |
^ false |
|
9919 |
||
9920 |
"Created: / 10-11-2006 / 17:05:43 / cg" |
|
9921 |
! |
|
9922 |
||
5755 | 9923 |
isRectangle |
20214 | 9924 |
"return true if the receiver is some kind of rectangle; |
5755 | 9925 |
false is returned here - the method is only redefined in Rectangle." |
9926 |
||
9927 |
^ false |
|
9928 |
! |
|
9929 |
||
9930 |
isRemoteObject |
|
20214 | 9931 |
"return true if the receiver is some kind of remoteObject, |
21432 | 9932 |
false if it's local - the method is only redefined in RemoteObject." |
9933 |
||
9934 |
^ false |
|
9935 |
||
9936 |
"Created: / 28-10-1996 / 15:18:45 / cg" |
|
9937 |
"Modified (comment): / 13-02-2017 / 20:27:33 / cg" |
|
5755 | 9938 |
! |
9939 |
||
9940 |
isSequenceable |
|
20214 | 9941 |
"return true if the receiver is some kind of sequenceable collection; |
5755 | 9942 |
false is returned here - the method is only redefined in SequenceableCollection." |
9943 |
||
9944 |
^ false |
|
9945 |
! |
|
9946 |
||
9947 |
isSequenceableCollection |
|
9948 |
"OBSOLETE: use isSequenceable for ST-80 compatibility. |
|
9949 |
This method is a historic leftover and will be removed soon ... |
|
9950 |
(although its name is much better than #isSequenceable - sigh)" |
|
9951 |
||
5869 | 9952 |
<resource:#obsolete> |
9953 |
||
5755 | 9954 |
self obsoleteMethodWarning:'use #isSequenceable'. |
17365 | 9955 |
^ self isSequenceable |
5755 | 9956 |
! |
9957 |
||
10856 | 9958 |
isSharedPool |
20214 | 9959 |
"return true if the receiver is a sharedPool. |
10856 | 9960 |
False is returned here - the method is only redefined in SharedPool." |
9961 |
||
9962 |
^ false |
|
9963 |
! |
|
9964 |
||
16770 | 9965 |
isSingleByteString |
20214 | 9966 |
"return true if the receiver is a string or immutableString. |
16772 | 9967 |
false is returned here - the method is only redefined in String. |
9968 |
Must replace foo isMemberOf:String and foo class == String" |
|
16770 | 9969 |
|
9970 |
^ false |
|
9971 |
! |
|
9972 |
||
15514 | 9973 |
isSocketAddress |
9974 |
^ false |
|
9975 |
! |
|
9976 |
||
13565
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9977 |
isSpecialInstrumentationInfoLiteral |
20214 | 9978 |
"return true if the receiver is a special instrumentation info |
13565
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9979 |
object as placed into the literal array of instrumented methods" |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9980 |
|
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9981 |
^ false |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9982 |
|
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9983 |
"Created: / 07-08-2011 / 17:03:41 / cg" |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9984 |
! |
4c0a9ea3a4e1
added: #isSpecialInstrumentationInfoLiteral
Claus Gittinger <cg@exept.de>
parents:
13515
diff
changeset
|
9985 |
|
5755 | 9986 |
isStream |
20214 | 9987 |
"return true if the receiver is some kind of stream; |
5755 | 9988 |
false is returned here - the method is only redefined in Stream." |
9989 |
||
9990 |
^ false |
|
9991 |
! |
|
9992 |
||
9993 |
isString |
|
20214 | 9994 |
"return true if the receiver is some kind of string; |
5755 | 9995 |
false is returned here - the method is only redefined in CharacterArray." |
9996 |
||
9997 |
^ false |
|
9998 |
! |
|
9999 |
||
10000 |
isStringCollection |
|
20214 | 10001 |
"return true if the receiver is some kind of stringCollection; |
5755 | 10002 |
false is returned here - the method is only redefined in StringCollection." |
10003 |
||
10004 |
^ false |
|
10005 |
! |
|
10006 |
||
20535 | 10007 |
isStructure |
10008 |
"redefined in Structure>>#doesNotUnderstand" |
|
10009 |
||
10010 |
^ false |
|
10011 |
! |
|
10012 |
||
5755 | 10013 |
isSymbol |
20214 | 10014 |
"return true if the receiver is some kind of symbol; |
5755 | 10015 |
false is returned here - the method is only redefined in Symbol." |
10016 |
||
10017 |
^ false |
|
10018 |
! |
|
10019 |
||
10020 |
isText |
|
20214 | 10021 |
"return true if the receiver is some kind of text object; |
5755 | 10022 |
false is returned here - the method is only redefined in Text." |
10023 |
||
10024 |
^ false |
|
10025 |
||
10026 |
"Created: 12.5.1996 / 10:56:50 / cg" |
|
10027 |
! |
|
10028 |
||
13656 | 10029 |
isTextView |
20214 | 10030 |
"return true if the receiver is some kind of textView; |
13656 | 10031 |
false is returned here - the method is only redefined in TextViews." |
10032 |
||
10033 |
^ false |
|
10034 |
||
10035 |
"Modified (comment): / 08-09-2011 / 05:12:37 / cg" |
|
10036 |
! |
|
10037 |
||
16349 | 10038 |
isTimeDuration |
20214 | 10039 |
"return true if the receiver is some kind of time duration; |
16349 | 10040 |
false is returned here - the method is only redefined in TimeDuration." |
10041 |
||
10042 |
^ false |
|
10043 |
! |
|
10044 |
||
13229 | 10045 |
isTimestamp |
20214 | 10046 |
"return true if the receiver is some kind of time duration; |
16349 | 10047 |
false is returned here - the method is only redefined in Timestamp." |
10048 |
||
13229 | 10049 |
^ false |
10050 |
! |
|
10051 |
||
13626 | 10052 |
isTrait |
10053 |
"Return true if the receiver is a trait. |
|
10054 |
Note: Do not override in any class except TraitBehavior." |
|
10055 |
||
10056 |
^ false |
|
10057 |
||
10058 |
"Created: / 04-09-2011 / 20:04:43 / cg" |
|
10059 |
! |
|
10060 |
||
21480 | 10061 |
isURL |
10062 |
"Return true if the receiver is a url. |
|
10063 |
Note: Do not override in any class except URL." |
|
10064 |
||
10065 |
^ false |
|
10066 |
||
10067 |
"Created: / 17-02-2017 / 10:25:12 / cg" |
|
10068 |
! |
|
10069 |
||
14296 | 10070 |
isUUID |
16349 | 10071 |
"Return true if the receiver is a uuid. |
10072 |
Note: Do not override in any class except UUID." |
|
10073 |
||
14296 | 10074 |
^ false |
10075 |
! |
|
10076 |
||
5755 | 10077 |
isValueModel |
20214 | 10078 |
"return true if the receiver is some kind of valueModel; |
5755 | 10079 |
false is returned here - the method is only redefined in ValueModel." |
10080 |
||
10081 |
^ false |
|
10082 |
! |
|
10083 |
||
10084 |
isVariable |
|
10085 |
"return true if the receiver has indexed instance variables, |
|
10086 |
false otherwise." |
|
10087 |
||
10088 |
^ self class isVariable |
|
10089 |
! |
|
10090 |
||
10091 |
isVariableBinding |
|
20214 | 10092 |
"return true if this is a binding for a variable. |
5755 | 10093 |
false is returned here - the method is only redefined in Binding." |
10094 |
||
10095 |
^ false |
|
10096 |
||
10097 |
"Created: / 19.6.1997 / 17:38:44 / cg" |
|
10098 |
"Modified: / 8.5.1998 / 21:26:55 / cg" |
|
10099 |
! |
|
10100 |
||
10101 |
isView |
|
20214 | 10102 |
"return true if the receiver is some kind of view; |
5755 | 10103 |
false is returned here - the method is only redefined in View." |
10104 |
||
10105 |
^ false |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
10106 |
! |
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
10107 |
|
15943 | 10108 |
isViewBackground |
10109 |
"return false here; to be redefined in subclass(es)" |
|
10110 |
||
10111 |
^ false |
|
10112 |
! |
|
10113 |
||
20939 | 10114 |
isVoid |
10115 |
"Return true if the receiver is void. |
|
10116 |
This is (and should only be) redefined in VoidObject, |
|
10117 |
for the one and only instance of it, void" |
|
10118 |
||
10119 |
^ false |
|
10120 |
||
10121 |
" |
|
10122 |
nil isVoid |
|
10123 |
void isVoid |
|
10124 |
" |
|
10125 |
! |
|
10126 |
||
18802 | 10127 |
isWeakCollection |
20214 | 10128 |
"return true if the receiver has weak references to its elements." |
18802 | 10129 |
|
10130 |
^ false |
|
10131 |
! |
|
10132 |
||
6932 | 10133 |
notEmptyOrNil |
10134 |
"Squeak compatibility: |
|
10135 |
return true if I am neither nil nor an empty collection. |
|
10136 |
Return true here." |
|
10137 |
||
10138 |
^ true |
|
10139 |
! |
|
10140 |
||
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
10141 |
notNil |
20214 | 10142 |
"Return true if the receiver is not nil. |
9221 | 10143 |
Because notNil is redefined in UndefinedObject, |
10144 |
the receiver is definitely not nil here, so unconditionally return true. |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
10145 |
Notice: |
20535 | 10146 |
This method is open coded (inlined) by the compiler(s) |
10147 |
- redefining it may not work as expected." |
|
6068
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
10148 |
|
1d5ca1175f3f
added #isNilOrEmptyCollection
Claus Gittinger <cg@exept.de>
parents:
6033
diff
changeset
|
10149 |
^ true |
5755 | 10150 |
! ! |
10151 |
||
10152 |
!Object methodsFor:'tracing'! |
|
10153 |
||
10154 |
traceInto:aRequestor level:level from:referrer |
|
10155 |
"double dispatch into tracer, passing my type implicitely in the selector" |
|
10156 |
||
10157 |
^ aRequestor traceObject:self level:level from:referrer |
|
10158 |
||
10159 |
"Created: / 2.9.1999 / 09:05:17 / stefan" |
|
10160 |
! ! |
|
10161 |
||
10162 |
!Object methodsFor:'user interaction & notifications'! |
|
10163 |
||
10164 |
activityNotification:aString |
|
10165 |
"this can be sent from deeply nested methods, which are going to perform |
|
10166 |
some long-time activity. |
|
10167 |
If there is a handler for the ActivityNotificationSignal signal, that one is raised, |
|
10168 |
passing the argument. The handler should show this message whereever it likes, |
|
10169 |
and proceed. If there is no handler, this is simply ignored. |
|
10170 |
||
10171 |
This is very useful to pass busy messages up to some higher level (typically a view) |
|
10172 |
which likes to display that message in its label or a busy-box. |
|
10173 |
It could also be put into some logfile or printed on the standard output/error." |
|
10174 |
||
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
10175 |
ActivityNotification isHandled ifTrue:[ |
20535 | 10176 |
^ ActivityNotification raiseRequestWith:self errorString:aString |
5755 | 10177 |
]. |
10178 |
||
10179 |
" |
|
10180 |
nil activityNotification:'hello there' |
|
10181 |
self activityNotification:'hello there' |
|
10182 |
" |
|
10183 |
||
10184 |
" |
|
8330
15ef95301861
Convert more instance based exceptions to class based exceptions
Stefan Vogel <sv@exept.de>
parents:
8324
diff
changeset
|
10185 |
ActivityNotification handle:[:ex | |
20535 | 10186 |
ex errorString printCR. |
10187 |
ex proceed. |
|
5755 | 10188 |
] do:[ |
20535 | 10189 |
'hello' printCR. |
10190 |
self activityNotification:'doing some long time computation'. |
|
10191 |
'world' printCR. |
|
5755 | 10192 |
] |
10193 |
" |
|
10194 |
||
10195 |
"Modified: 16.12.1995 / 18:23:42 / cg" |
|
10196 |
! |
|
10197 |
||
10198 |
confirm:aString |
|
9694 | 10199 |
"open a modal yes-no dialog. |
10200 |
Return true for yes, false for no. |
|
10527
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
10201 |
If no GUI is present (headless applications), true is returned. |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
10202 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
10203 |
Someone in the sender chain may redefine the confirmation handler |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
10204 |
by handling the UserConfirmation." |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
10205 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
10206 |
^ UserConfirmation raiseRequestErrorString:aString |
10460 | 10207 |
|
5755 | 10208 |
" |
10209 |
nil confirm:'hello' |
|
10210 |
self confirm:'hello' |
|
10211 |
" |
|
10212 |
! |
|
10213 |
||
10214 |
confirm:aString orCancel:cancelBlock |
|
10215 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
10216 |
return true for yes, false for no, or the value from cancelBlock for cancel. |
|
10217 |
If no GUI is present (headless applications), cancelBlock is returned." |
|
10218 |
||
10219 |
|answer| |
|
10220 |
||
10221 |
answer := self confirmWithCancel:aString. |
|
10222 |
answer isNil ifTrue:[ |
|
20535 | 10223 |
^ cancelBlock value |
5755 | 10224 |
]. |
10225 |
^ answer |
|
10460 | 10226 |
|
5755 | 10227 |
" |
10228 |
self confirm:'hello' orCancel:[self halt] |
|
10229 |
" |
|
10230 |
||
10231 |
"Modified: 20.5.1996 / 10:28:40 / cg" |
|
10232 |
! |
|
10233 |
||
10234 |
confirmWithCancel:aString |
|
10235 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
|
10236 |
return true for yes, false for no, nil for cancel. |
|
10527
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
10237 |
If no GUI is present (headless applications), nil is returned. |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
10238 |
|
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
10239 |
Someone in the sender chain may redefine the confirmation handler |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
10240 |
by handling the UserConfirmation." |
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
10241 |
|
11366
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10242 |
^ self confirmWithCancel:aString defaultAnswer:nil |
10460 | 10243 |
|
10244 |
" |
|
10245 |
nil confirmWithCancel:'hello' |
|
5755 | 10246 |
self confirmWithCancel:'hello' |
10247 |
" |
|
10248 |
! |
|
10249 |
||
11366
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10250 |
confirmWithCancel:aString defaultAnswer:defaultAnswerOrNil |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10251 |
"launch a confirmer, which allows user to enter yes, no or cancel. |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10252 |
return true for yes, false for no, nil for cancel. |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10253 |
If no GUI is present (headless applications), nil is returned. |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10254 |
|
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10255 |
Someone in the sender chain may redefine the confirmation handler |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10256 |
by handling the UserConfirmation." |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10257 |
|
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10258 |
^ UserConfirmation new |
20535 | 10259 |
defaultAnswer:defaultAnswerOrNil; |
10260 |
canCancel:true; |
|
10261 |
errorString:aString; |
|
10262 |
raiseRequest |
|
11366
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10263 |
|
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10264 |
" |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10265 |
nil confirmWithCancel:'hello' defaultAnswer:true |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10266 |
self confirmWithCancel:'hello' defaultAnswer:false |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10267 |
" |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10268 |
! |
97a8331d3e4c
+ confirmWithCancel defaultAnswer
Claus Gittinger <cg@exept.de>
parents:
11339
diff
changeset
|
10269 |
|
5755 | 10270 |
errorNotify:aString |
10271 |
"launch a Notifier, showing top stack, telling user something |
|
10272 |
and give user a chance to enter debugger." |
|
10273 |
||
10274 |
^ self |
|
20535 | 10275 |
errorNotify:aString |
10276 |
from:thisContext sender |
|
10277 |
allowDebug:true |
|
10278 |
mayProceed:true |
|
5755 | 10279 |
|
10280 |
" |
|
10281 |
nil errorNotify:'hello there' |
|
10282 |
self errorNotify:'hello there' |
|
10283 |
" |
|
10284 |
||
6199 | 10285 |
"Modified: / 16.11.2001 / 15:36:49 / cg" |
5755 | 10286 |
! |
10287 |
||
10288 |
errorNotify:aString from:aContext |
|
10460 | 10289 |
"launch a Notifier, showing top stack (above aContext), |
5755 | 10290 |
telling user something and give user a chance to enter debugger." |
10291 |
||
15255 | 10292 |
^ self errorNotify:aString from:aContext allowDebug:true mayProceed:true |
5755 | 10293 |
|
10294 |
"Modified: / 17.8.1998 / 10:09:27 / cg" |
|
10295 |
! |
|
10296 |
||
10297 |
errorNotify:aString from:aContext allowDebug:allowDebug |
|
10460 | 10298 |
"launch a Notifier, showing top stack (above aContext), |
15255 | 10299 |
telling user something and give user a chance to enter debugger." |
10300 |
||
10301 |
^ self errorNotify:aString from:aContext allowDebug:allowDebug mayProceed:true |
|
10302 |
! |
|
10303 |
||
10304 |
errorNotify:aString from:aContext allowDebug:allowDebug mayProceed:mayProceed |
|
10305 |
"launch a Notifier, showing top stack (above aContext), |
|
5755 | 10306 |
telling user something and optionally give the user a chance to enter debugger." |
10307 |
||
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
10308 |
|currentScreen con sender action boxLabels boxValues default s| |
5755 | 10309 |
|
10310 |
Smalltalk isInitialized ifFalse:[ |
|
20535 | 10311 |
'errorNotification: ' print. aString printCR. |
10312 |
con := aContext ? thisContext methodHome. |
|
10313 |
con sender printAllLevels:10. |
|
10314 |
^ nil |
|
10460 | 10315 |
]. |
11531 | 10316 |
|
10460 | 10317 |
(Dialog isNil |
6647
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
10318 |
or:[Screen isNil |
79c298b93c07
#errorNotify -- allow copying the backtrace
Stefan Vogel <sv@exept.de>
parents:
6631
diff
changeset
|
10319 |
or:[(currentScreen := Screen current) isNil |
10460 | 10320 |
or:[currentScreen isOpen not]]]) ifTrue:[ |
20535 | 10321 |
" |
10322 |
on systems without GUI, simply show |
|
10323 |
the message on the Transcript and abort. |
|
10324 |
" |
|
10325 |
Transcript showCR:aString. |
|
10326 |
AbortOperationRequest raise. |
|
10327 |
"not reached" |
|
10328 |
^ nil |
|
5755 | 10329 |
]. |
10330 |
||
10331 |
Processor activeProcessIsSystemProcess ifTrue:[ |
|
20535 | 10332 |
action := #debug. |
10333 |
sender := aContext. |
|
10334 |
Debugger isNil ifTrue:[ |
|
10335 |
'****************** Caught Error while in SystemProcess ****************' errorPrintCR. |
|
10336 |
aString errorPrintCR. |
|
10337 |
Exception handle:[:ex | |
|
10338 |
'Caught recursive error while printing backtrace:' errorPrintCR. |
|
10339 |
ex description errorPrintCR. |
|
10340 |
] do:[ |
|
10341 |
thisContext fullPrintAll. |
|
10342 |
]. |
|
10343 |
action := #abort. |
|
10344 |
]. |
|
5755 | 10345 |
] ifFalse:[ |
20535 | 10346 |
Dialog autoload. "in case it is autoloaded" |
10347 |
||
10348 |
Error handle:[:ex | |
|
10349 |
"/ a recursive error - quickly enter debugger |
|
10350 |
"/ this happened, when I corrupted the Dialog class ... |
|
10351 |
('Object [error]: ' , ex description , ' caught in errorNotification') errorPrintCR. |
|
10352 |
action := #debug. |
|
10353 |
ex return. |
|
10354 |
] do:[ |s| |
|
10355 |
sender := aContext. |
|
10356 |
sender isNil ifTrue:[ |
|
10357 |
sender := thisContext methodHome sender. |
|
10358 |
]. |
|
10359 |
con := sender. |
|
10360 |
||
10361 |
"/ skip intermediate (signal & exception) contexts |
|
10362 |
DebugView notNil ifTrue:[ |
|
10363 |
con := DebugView interestingContextFrom:sender |
|
10364 |
]. |
|
10365 |
||
10366 |
"/ show the first few contexts |
|
10367 |
||
10368 |
s := CharacterWriteStream with:aString. |
|
10369 |
s cr; cr. |
|
10370 |
s nextPutLine:'Calling Chain:'. |
|
10371 |
s nextPutLine:'--------------------------------------------------------------'. |
|
10372 |
1 to:25 do:[:n | |
|
10373 |
con notNil ifTrue:[ |
|
10374 |
con printOn:s. |
|
10375 |
s cr. |
|
10376 |
con := con sender |
|
10377 |
] |
|
10378 |
]. |
|
10379 |
||
10380 |
mayProceed ifTrue:[ |
|
10381 |
boxLabels := #('Proceed'). |
|
10382 |
boxValues := #(#proceed). |
|
10383 |
default := #proceed. |
|
10384 |
] ifFalse:[ |
|
10385 |
boxLabels := #(). |
|
10386 |
boxValues := #(). |
|
10387 |
]. |
|
10388 |
||
10389 |
AbortOperationRequest isHandled ifTrue:[ |
|
10390 |
default := #abort. |
|
10391 |
boxLabels := boxLabels , #('Abort'). |
|
10392 |
boxValues := boxValues , #(#abort). |
|
10393 |
AbortAllOperationRequest isHandled ifTrue:[ |
|
10394 |
boxLabels := boxLabels , #('Abort All'). |
|
10395 |
boxValues := boxValues , #(#abortAll). |
|
10396 |
]. |
|
10397 |
true "allowDebug" ifTrue:[ |
|
10398 |
boxLabels := boxLabels , #('Copy Trace and Abort'). |
|
10399 |
boxValues := boxValues , #(#copyAndAbort). |
|
10400 |
]. |
|
10401 |
] ifFalse:[ |
|
10402 |
mayProceed "and:[allowDebug]" ifTrue:[ |
|
10403 |
boxLabels := boxLabels , #('Copy Trace and Proceed'). |
|
10404 |
boxValues := boxValues , #(#copyAndProceed). |
|
10405 |
]. |
|
10406 |
]. |
|
10407 |
||
10408 |
(allowDebug and:[Debugger notNil]) ifTrue:[ |
|
10409 |
boxLabels := boxLabels , #('Debug'). |
|
10410 |
boxValues := boxValues , #(#debug). |
|
10411 |
default := #debug. |
|
10412 |
]. |
|
10413 |
||
10414 |
action := Dialog |
|
10415 |
choose:s contents |
|
10416 |
label:('Exception [' , Processor activeProcess nameOrId , ']') |
|
10417 |
image:WarningBox errorIconBitmap |
|
10418 |
labels:boxLabels |
|
10419 |
values:boxValues |
|
10420 |
default:default |
|
10421 |
onCancel:nil. |
|
10422 |
]. |
|
5755 | 10423 |
]. |
10424 |
||
10425 |
action == #debug ifTrue:[ |
|
20535 | 10426 |
^ Debugger enter:sender withMessage:aString mayProceed:mayProceed |
11236
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
10427 |
]. |
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
10428 |
action == #proceed ifTrue:[ |
20535 | 10429 |
^ nil. |
11335 | 10430 |
]. |
10431 |
(action == #copyAndProceed |
|
10432 |
or:[action == #copyAndAbort]) ifTrue:[ |
|
20535 | 10433 |
s := '' writeStream. |
10434 |
Exception handle:[:ex | |
|
10435 |
'Caught recursive error while printing backtrace' errorPrintCR. |
|
10436 |
] do:[ |
|
10437 |
sender fullPrintAllOn:s. |
|
10438 |
]. |
|
10439 |
currentScreen rootView setClipboardText:s contents. |
|
10440 |
action == #copyAndProceed ifTrue:[ |
|
10441 |
^ nil |
|
10442 |
]. |
|
17306 | 10443 |
]. |
10444 |
(action == #abortAll) ifTrue:[ |
|
20535 | 10445 |
AbortAllOperationRequest raise |
18215 | 10446 |
]. |
11314
0b6e06b60ebe
changed the error-notifier for standAlone apps.
Claus Gittinger <cg@exept.de>
parents:
11244
diff
changeset
|
10447 |
|
11236
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
10448 |
AbortOperationRequest raise. |
c196f9dedf66
exception description in debugger
Claus Gittinger <cg@exept.de>
parents:
11221
diff
changeset
|
10449 |
"not reached" |
5755 | 10450 |
|
10451 |
" |
|
10452 |
nil errorNotify:'hello there' |
|
10453 |
self errorNotify:'hello there' |
|
10454 |
" |
|
10455 |
||
13165
66a6b37405d1
changed: #errorNotify:from:allowDebug:
Claus Gittinger <cg@exept.de>
parents:
13162
diff
changeset
|
10456 |
"Created: / 17-08-1998 / 10:09:26 / cg" |
13566 | 10457 |
"Modified: / 08-08-2011 / 11:26:17 / sr" |
13844
f03a655457f4
changed: #errorNotify:from:allowDebug:
Claus Gittinger <cg@exept.de>
parents:
13812
diff
changeset
|
10458 |
"Modified: / 05-12-2011 / 03:50:59 / cg" |
5755 | 10459 |
! |
10460 |
||
10461 |
information:aString |
|
10460 | 10462 |
"launch an InfoBox, telling user something. |
10463 |
These info-boxes can be suppressed by handling |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10464 |
UserNotification or InformationSignal and proceeding in the handler. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10465 |
Use #notify: for more important messages. |
8371 | 10466 |
If nobody handles the exception, the default action of UserNotification |
10527
b783c0000f54
#confirm: now uses the UserConfirmation otification to request an answer
Stefan Vogel <sv@exept.de>
parents:
10480
diff
changeset
|
10467 |
pops up an info dialog." |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10468 |
|
7035
1d049fb7ae5a
Make UserInformation a class based exception
Stefan Vogel <sv@exept.de>
parents:
7033
diff
changeset
|
10469 |
UserInformation raiseRequestWith:self errorString:aString |
5755 | 10470 |
|
10471 |
" |
|
10472 |
nil information:'hello there' |
|
10473 |
self information:'hello there' |
|
10474 |
" |
|
10475 |
||
10476 |
" |
|
10477 |
InformationSignal handle:[:ex | |
|
20535 | 10478 |
'no box popped' printCR. |
10479 |
ex proceed. |
|
5755 | 10480 |
] do:[ |
20535 | 10481 |
'hello' printCR. |
10482 |
self information:'some info'. |
|
10483 |
'world' printCR. |
|
5755 | 10484 |
] |
10485 |
" |
|
10486 |
||
10487 |
"Modified: 24.11.1995 / 22:29:49 / cg" |
|
10488 |
! |
|
10489 |
||
10490 |
notify:aString |
|
10491 |
"launch a Notifier, telling user something. |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10492 |
Use #information: for ignorable messages. |
21272 | 10493 |
If nobody handles the exception, the default action of UserNotification |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10494 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10495 |
|
5755 | 10496 |
|
10497 |
Smalltalk isInitialized ifFalse:[ |
|
20535 | 10498 |
"/ thisContext fullPrintAll. |
10499 |
'information: ' print. aString printCR. |
|
10500 |
^ self |
|
5755 | 10501 |
]. |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10502 |
UserNotification raiseRequestWith:self errorString:aString. |
5755 | 10503 |
|
10504 |
" |
|
10505 |
nil notify:'hello there' |
|
10506 |
self notify:'hello there' |
|
10507 |
" |
|
10508 |
||
21272 | 10509 |
"Modified: / 20-05-1996 / 10:28:48 / cg" |
10510 |
"Modified (comment): / 23-01-2017 / 16:17:50 / stefan" |
|
5755 | 10511 |
! |
10512 |
||
10513 |
warn:aString |
|
10514 |
"launch a WarningBox, telling user something. |
|
10460 | 10515 |
These warn-boxes can be suppressed by handling the |
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10516 |
UserNotification- or WarningSignal and proceeding in the handler. |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10517 |
If nobody handles the exception, the dafault action of Warning |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10518 |
pops up a warn dialog." |
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10519 |
|
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10520 |
Warning raiseRequestWith:self errorString:aString |
5755 | 10521 |
|
10522 |
" |
|
10523 |
nil warn:'hello there' |
|
10524 |
self warn:'hello there' |
|
10525 |
" |
|
10526 |
||
10527 |
" |
|
7033
c4183ea85a71
Now Warning is a subclass of UserNotification.
Stefan Vogel <sv@exept.de>
parents:
7031
diff
changeset
|
10528 |
Warning handle:[:ex | |
20535 | 10529 |
Transcript showCR:ex description. |
10530 |
ex proceed. |
|
5755 | 10531 |
] do:[ |
20535 | 10532 |
'hello' printCR. |
10533 |
self warn:'some info'. |
|
10534 |
'world' printCR. |
|
5755 | 10535 |
] |
10536 |
" |
|
10537 |
||
10538 |
"Modified: 20.5.1996 / 10:28:53 / cg" |
|
10539 |
! ! |
|
10540 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
10541 |
!Object methodsFor:'visiting'! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
10542 |
|
8426 | 10543 |
acceptVisitor:aVisitor |
10544 |
"double-dispatch onto a Visitor." |
|
10545 |
||
10546 |
^ self acceptVisitor:aVisitor with:nil |
|
10547 |
! |
|
10548 |
||
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
10549 |
acceptVisitor:aVisitor with:aParameter |
16732 | 10550 |
"double-dispatch via visitObject:with: into a Visitor. |
10551 |
Subclasses redefine this to pass their type in the message name (i.e. visitXXX:)" |
|
8397
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
10552 |
|
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
10553 |
^ aVisitor visitObject:self with:aParameter |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
10554 |
! ! |
a1cff241e853
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8383
diff
changeset
|
10555 |
|
21389 | 10556 |
|
10557 |
||
10558 |
||
5755 | 10559 |
!Object class methodsFor:'documentation'! |
1 | 10560 |
|
14056
24d7f7bf46c7
inspector2TabForBasicInspect
Claus Gittinger <cg@exept.de>
parents:
14055
diff
changeset
|
10561 |
version |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18440
diff
changeset
|
10562 |
^ '$Header$' |
14056
24d7f7bf46c7
inspector2TabForBasicInspect
Claus Gittinger <cg@exept.de>
parents:
14055
diff
changeset
|
10563 |
! |
24d7f7bf46c7
inspector2TabForBasicInspect
Claus Gittinger <cg@exept.de>
parents:
14055
diff
changeset
|
10564 |
|
12050 | 10565 |
version_CVS |
18620
b4e9f25d6ce6
preparations for lined index list in WeakArray
Claus Gittinger <cg@exept.de>
parents:
18440
diff
changeset
|
10566 |
^ '$Header$' |
20538 | 10567 |
! ! |
13416 | 10568 |
|
20762 | 10569 |
|
5755 | 10570 |
Object initialize! |