96
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
Message subclass:#MessageSend
|
|
14 |
instanceVariableNames:'receiver'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Kernel-Methods'
|
|
18 |
!
|
|
19 |
|
|
20 |
MessageSend comment:'
|
|
21 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
22 |
All Rights Reserved
|
|
23 |
|
160
|
24 |
$Header: /cvs/stx/stx/libbasic/MessageSend.st,v 1.2 1994-10-10 00:53:52 claus Exp $
|
96
|
25 |
'!
|
|
26 |
|
|
27 |
!MessageSend class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1994 by Claus Gittinger
|
|
32 |
All Rights Reserved
|
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
160
|
45 |
$Header: /cvs/stx/stx/libbasic/MessageSend.st,v 1.2 1994-10-10 00:53:52 claus Exp $
|
96
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
Instances of MessageSend can be used for simulation programs.
|
|
52 |
They keep some receiver, selector and arguments and can be evaluated
|
|
53 |
at any time later.
|
|
54 |
They can also be used as replacement for simple [self foo]-blocks.
|
|
55 |
Of course, they could also be replaced by blocks such as
|
|
56 |
'[receiver perform:selector withArguments:arguments]',
|
|
57 |
but blocks are somewhat more expensive in their creation and use.
|
|
58 |
However, the send-operation itself is faster in a block, since it
|
|
59 |
will use a better caching scheme (inline-cache) for its send, while
|
|
60 |
sending here is done with a #perform:, which is not inline-cached.
|
160
|
61 |
Thus it is not sure, which one is faster in the end ...
|
96
|
62 |
|
|
63 |
Example:
|
|
64 |
|
|
65 |
|m|
|
|
66 |
|
|
67 |
m := MessageSend receiver:1 selector:#+ arguments:#(2).
|
|
68 |
m value.
|
|
69 |
|
|
70 |
Example2 (a simulation)
|
|
71 |
|q|
|
|
72 |
|
|
73 |
q := Queue new.
|
|
74 |
...
|
|
75 |
'put some action into the queue'
|
|
76 |
q nextPut:(MessageSend receiver:something selector:#foo arguments:#().
|
|
77 |
...
|
|
78 |
'evaluate next action from the queue'
|
|
79 |
q next value
|
|
80 |
...
|
|
81 |
"
|
|
82 |
! !
|
|
83 |
|
|
84 |
!MessageSend class methodsFor:'instance creation'!
|
|
85 |
|
|
86 |
receiver:r selector:sel arguments:argArray
|
|
87 |
|newMessage|
|
|
88 |
|
160
|
89 |
newMessage := super setSelector:sel arguments:argArray.
|
96
|
90 |
newMessage receiver:r.
|
|
91 |
^ newMessage
|
|
92 |
! !
|
|
93 |
|
|
94 |
!MessageSend methodsFor:'evaluation'!
|
|
95 |
|
|
96 |
value
|
160
|
97 |
"evaluate the messagesend with the original arguments"
|
96
|
98 |
|
|
99 |
^ receiver perform:selector withArguments:args
|
|
100 |
!
|
|
101 |
|
|
102 |
value:someArgument
|
|
103 |
"evaluate the messagesend, with someArgument instead of the original"
|
|
104 |
|
|
105 |
^ receiver perform:selector with:someArgument
|
|
106 |
!
|
|
107 |
|
|
108 |
value:arg1 value:arg2
|
160
|
109 |
"evaluate the messagesend, with arg1 and arg2 instead of the original
|
|
110 |
arguments"
|
96
|
111 |
|
|
112 |
^ receiver perform:selector with:arg1 with:arg2
|
|
113 |
!
|
|
114 |
|
|
115 |
value:arg1 value:arg2 value:arg3
|
160
|
116 |
"evaluate the messagesend, with arg1, arg2 and arg3 instead of the original
|
|
117 |
arguments"
|
96
|
118 |
|
|
119 |
^ receiver perform:selector with:arg1 with:arg2 with:arg3
|
|
120 |
! !
|
|
121 |
|
|
122 |
!MessageSend methodsFor:'accessing'!
|
|
123 |
|
|
124 |
receiver:r
|
|
125 |
"set the receiver"
|
|
126 |
|
|
127 |
receiver := r
|
|
128 |
!
|
|
129 |
|
|
130 |
receiver
|
|
131 |
"return the receiver"
|
|
132 |
|
|
133 |
^ receiver
|
|
134 |
! !
|
|
135 |
|
|
136 |
!MessageSend methodsFor:'printing & storing'!
|
|
137 |
|
|
138 |
displayString
|
|
139 |
"return a string for display in inspectors etc."
|
|
140 |
|
|
141 |
^ 'MessageSend(' , receiver displayString , '>>' , selector , ')'
|
|
142 |
!
|
|
143 |
|
|
144 |
printOn:aStream
|
|
145 |
"return a string for printing the receiver"
|
|
146 |
|
|
147 |
receiver printOn:aStream.
|
|
148 |
aStream nextPutAll:'>>'.
|
|
149 |
selector printOn:aStream
|
|
150 |
! !
|