author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 17 Jun 2015 06:22:00 +0100 | |
branch | jv |
changeset 18487 | 8735bd9eee2f |
parent 18120 | e3a375d5f6a8 |
child 19892 | d1aecb538df5 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
362 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
5591 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
17523 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
1 | 16 |
Object subclass:#Message |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
17 |
instanceVariableNames:'selector args' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
18 |
classVariableNames:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
19 |
poolDictionaries:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
20 |
category:'Kernel-Methods' |
1 | 21 |
! |
22 |
||
88 | 23 |
!Message class methodsFor:'documentation'! |
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
362 | 28 |
All Rights Reserved |
1 | 29 |
|
88 | 30 |
This software is furnished under a license and may be used |
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
1 | 38 |
|
88 | 39 |
documentation |
40 |
" |
|
17523 | 41 |
Instances of Message represent a message being sent, consisting of |
42 |
the message selector and the message arguments. |
|
43 |
||
1268 | 44 |
During normal execution, message objects are NEVER used - |
45 |
instead, argument passing is done more performant via the stack |
|
46 |
or in registers (depends on how your C compiler passes arguments). |
|
47 |
||
48 |
However, messageObjects ARE created, when a message send fails |
|
88 | 49 |
(i.e. some message is not understood). |
17523 | 50 |
In this case, the selector and arguments of the failing message |
1268 | 51 |
are squashed into a new instance of Message, and a #doesNotUnderstand: |
52 |
message is sent to the original receiver, passing the message object |
|
53 |
as argument. |
|
88 | 54 |
|
17523 | 55 |
Typically, #doesNotUnderstand: is not redefined in the receiver's class, |
56 |
so the lookup finds Object>>doesNotUnderstand: and this is evaluated. |
|
57 |
There, a debugger is opened on the suspended thread (actually, it is a little |
|
58 |
more complicated: actually a MessageNotUnderstood exception is raised there, |
|
59 |
which - if not handled by an exception handler - opens the debugger). |
|
60 |
||
61 |
However, it is possible and common to redefine the doesNotUnderstand method, |
|
62 |
which allows for re-evaluation of the failed send (after some cleanup), |
|
63 |
to upload some code, to forward the message to another destination, |
|
64 |
or to simply ignore the error. |
|
93 | 65 |
|
66 |
As an example of its use, see the implementation of the Autoload-class, |
|
67 |
or how ScrollableView forwards unknown messages to its slave-view. |
|
68 |
||
17523 | 69 |
Elegance hint: as mentioned above, Object>>doesNotUnderstand: actually |
70 |
raises an exception which can be handled. In many situations, providing |
|
71 |
an exception handler instead of redefining #doesNotUnderstand is the |
|
72 |
better way to do things. |
|
1268 | 73 |
|
74 |
||
93 | 75 |
Notice: |
17523 | 76 |
The layout of Message-objects is known by the runtime system (VM) |
1268 | 77 |
(it has to create those objects in case of a failure) |
17523 | 78 |
so it is not allowed to change the definition of this class. |
1268 | 79 |
|
80 |
[See also:] |
|
81 |
Signal Exception MessageSend |
|
1293 | 82 |
|
83 |
[author:] |
|
84 |
Claus Gittinger |
|
88 | 85 |
" |
86 |
! ! |
|
1 | 87 |
|
88 |
!Message class methodsFor:'instance creation'! |
|
89 |
||
90 |
selector:aSymbol |
|
91 |
"return a new message object for a send without arguments" |
|
92 |
||
159 | 93 |
^ self basicNew setSelector:aSymbol arguments:nil |
1 | 94 |
! |
95 |
||
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
96 |
selector:aSymbol argument:anArg |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
97 |
"return a new message object for a send with one argument" |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
98 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
99 |
^ self basicNew setSelector:aSymbol arguments:(Array with:anArg) |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
100 |
! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
101 |
|
5751 | 102 |
selector:aSymbol argument:arg1 argument:arg2 |
103 |
"return a new message object for a send with two arguments" |
|
104 |
||
105 |
^ self basicNew setSelector:aSymbol arguments:(Array with:arg1 with:arg2) |
|
106 |
! |
|
107 |
||
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
108 |
selector:aSymbol arguments:argArray |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
109 |
"return a new message object for a send with many arguments" |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
110 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
111 |
^ self basicNew setSelector:aSymbol arguments:argArray |
8323 | 112 |
! ! |
113 |
||
114 |
!Message class methodsFor:'obsolete'! |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
115 |
|
1 | 116 |
selector:aSymbol with:anArg |
159 | 117 |
"return a new message object for a send with one argument. |
118 |
OBSOLETE: use #selector:argument: for ST-80 compatibility." |
|
1 | 119 |
|
8323 | 120 |
<resource:#obsolete> |
121 |
||
159 | 122 |
^ self basicNew setSelector:aSymbol arguments:(Array with:anArg) |
1 | 123 |
! |
124 |
||
125 |
selector:aSymbol with:arg1 with:arg2 |
|
159 | 126 |
"return a new message object for a send with two arguments. |
127 |
OBSOLETE: use #selector:arguments: for ST-80 compatibility." |
|
1 | 128 |
|
8323 | 129 |
<resource:#obsolete> |
130 |
||
159 | 131 |
^ self basicNew setSelector:aSymbol arguments:(Array with:arg1 with:arg2) |
1 | 132 |
! |
133 |
||
134 |
selector:aSymbol withAll:argArray |
|
93 | 135 |
"return a new message object for a send with many arguments. |
159 | 136 |
OBSOLETE: use #selector:arguments: for ST-80 compatibilty." |
137 |
||
8323 | 138 |
<resource:#obsolete> |
139 |
||
159 | 140 |
^ self basicNew setSelector:aSymbol arguments:argArray |
93 | 141 |
! ! |
142 |
||
143 |
!Message class methodsFor:'queries'! |
|
144 |
||
145 |
isBuiltInClass |
|
1264 | 146 |
"return true if this class is known by the run-time-system. |
147 |
Here, true is returned for myself, false for subclasses." |
|
93 | 148 |
|
149 |
^ self == Message |
|
1264 | 150 |
|
151 |
"Modified: 23.4.1996 / 15:59:30 / cg" |
|
1 | 152 |
! ! |
153 |
||
8439 | 154 |
!Message methodsFor:'Compatibility-Dolphin'! |
155 |
||
156 |
value:aReceiver |
|
157 |
"evaluate myself for receiver. |
|
158 |
Same as #sendTo: - compatibility with Dolphin" |
|
159 |
||
160 |
^ aReceiver perform:selector withArguments:args |
|
161 |
! ! |
|
162 |
||
163 |
!Message methodsFor:'Compatibility-GNU'! |
|
164 |
||
8489 | 165 |
reinvokeFor:aReceiver |
166 |
"send the selector with argument to a receiver. |
|
167 |
Same as sendTo: - for GNU-ST compatibility." |
|
8439 | 168 |
|
8489 | 169 |
^ self sendTo:aReceiver |
8439 | 170 |
! ! |
171 |
||
8579 | 172 |
!Message methodsFor:'Compatibility-Squeak'! |
173 |
||
174 |
argument |
|
175 |
"return the 1st argument of the message" |
|
176 |
||
177 |
args size == 1 ifFalse:[ |
|
178 |
self error:'Not a 1-arg message' |
|
179 |
]. |
|
180 |
^ args at:1 |
|
181 |
! ! |
|
182 |
||
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
183 |
!Message methodsFor:'accessing'! |
10 | 184 |
|
6253 | 185 |
arg1 |
186 |
"return the first argument of the message" |
|
187 |
||
188 |
^ args at:1 |
|
189 |
! |
|
190 |
||
8687
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8579
diff
changeset
|
191 |
argumentCount |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8579
diff
changeset
|
192 |
"VisualAge/ANSI compatibility: return the number of arguments of the message" |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8579
diff
changeset
|
193 |
|
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8579
diff
changeset
|
194 |
^ args size |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8579
diff
changeset
|
195 |
! |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8579
diff
changeset
|
196 |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
197 |
arguments |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
198 |
"return the arguments of the message" |
85 | 199 |
|
6062
c8b8b9d382f1
always return a colelction from #arguments.
Claus Gittinger <cg@exept.de>
parents:
5751
diff
changeset
|
200 |
^ args ? #() |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
201 |
! |
1 | 202 |
|
10584 | 203 |
arguments:argArray |
204 |
"set arguments of the receiver" |
|
205 |
||
206 |
args := argArray |
|
207 |
||
208 |
"Created: / 31-05-2007 / 17:53:10 / cg" |
|
209 |
! |
|
210 |
||
6253 | 211 |
numArgs |
212 |
"return the number of arguments of the message" |
|
213 |
||
214 |
^ args size |
|
215 |
! |
|
216 |
||
1 | 217 |
selector |
218 |
"return the selector of the message" |
|
219 |
||
220 |
^ selector |
|
10584 | 221 |
! |
222 |
||
223 |
selector:aSymbol |
|
224 |
selector := aSymbol |
|
225 |
||
226 |
"Created: / 31-05-2007 / 17:53:06 / cg" |
|
1 | 227 |
! ! |
228 |
||
93 | 229 |
!Message methodsFor:'printing & storing'! |
1 | 230 |
|
14287
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
231 |
displayOn:aGCOrStream |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
232 |
"Compatibility |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
233 |
append a printed desription on some stream (Dolphin, Squeak) |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
234 |
OR: |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
235 |
display the receiver in a graphicsContext at 0@0 (ST80). |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
236 |
This method allows for any object to be displayed in some view |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
237 |
(although the fallBack is to display its printString ...)" |
56 | 238 |
|
14287
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
239 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
240 |
"/ ST/X (and some old ST80's) mean: draw-yourself on a GC. |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
241 |
aGCOrStream isStream ifFalse:[ |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
242 |
^ super displayOn:aGCOrStream. |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
243 |
]. |
1833 | 244 |
|
14287
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
245 |
aGCOrStream |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
246 |
nextPutAll:self class name; |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
247 |
nextPut:$(. |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
248 |
selector storeOn:aGCOrStream. |
d172b79d6ebb
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
10584
diff
changeset
|
249 |
aGCOrStream nextPut:$) |
56 | 250 |
! |
251 |
||
252 |
printOn:aStream |
|
4392 | 253 |
"append a user printed representation of the receiver to aStream. |
254 |
The format is suitable for a human - not meant to be read back." |
|
1 | 255 |
|
56 | 256 |
selector printOn:aStream |
1 | 257 |
! ! |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
258 |
|
7257 | 259 |
!Message methodsFor:'private-accessing'! |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
260 |
|
6933 | 261 |
setSelector:aSymbol |
262 |
selector := aSymbol. |
|
263 |
! |
|
264 |
||
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
265 |
setSelector:aSymbol arguments:argArray |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
266 |
"set selector and arguments of the receiver" |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
267 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
268 |
selector := aSymbol. |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
269 |
args := argArray |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
270 |
! ! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
271 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
272 |
!Message methodsFor:'sending'! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
273 |
|
8489 | 274 |
sendTo:aReceiver |
17523 | 275 |
"send the selector with argument(s) to aReceiver" |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
276 |
|
8489 | 277 |
^ aReceiver perform:selector withArguments:args |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
278 |
! ! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
279 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
280 |
!Message class methodsFor:'documentation'! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
281 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
282 |
version |
17523 | 283 |
^ '$Header: /cvs/stx/stx/libbasic/Message.st,v 1.35 2015-02-20 21:27:06 cg Exp $' |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
284 |
! ! |
17523 | 285 |