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