author | Claus Gittinger <cg@exept.de> |
Thu, 16 Dec 2004 12:21:17 +0100 | |
changeset 8666 | 66e7d5922ae9 |
parent 5528 | 2a96dd29ca28 |
child 11168 | 44fef5d29484 |
permissions | -rw-r--r-- |
1 | 1 |
" |
2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
165 | 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 |
" |
|
12 |
||
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
13 |
"{ Package: 'stx:libbasic' }" |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
14 |
|
4623 | 15 |
Context variableSubclass:#BlockContext |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
16 |
instanceVariableNames:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
17 |
classVariableNames:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
18 |
poolDictionaries:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
19 |
category:'Kernel-Methods' |
1 | 20 |
! |
21 |
||
88 | 22 |
!BlockContext class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
165 | 27 |
All Rights Reserved |
1 | 28 |
|
88 | 29 |
This software is furnished under a license and may be used |
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
1 | 37 |
|
88 | 38 |
documentation |
39 |
" |
|
8666 | 40 |
BlockContexts represent the stack context objects of blocks. |
41 |
The layout is the same as for other contexts - this class has been added |
|
88 | 42 |
to avoid a flag in an instance variable. |
43 |
(has become necessary with cheap blocks, which have no home). |
|
44 |
||
8666 | 45 |
WARNING: layout and size known by compiler and runtime system - |
46 |
do not change. |
|
1293 | 47 |
|
48 |
[author:] |
|
8666 | 49 |
Claus Gittinger |
1293 | 50 |
|
51 |
[see also:] |
|
8666 | 52 |
Context Block Method |
53 |
Exception Signal |
|
88 | 54 |
" |
55 |
! ! |
|
1 | 56 |
|
57 |
!BlockContext methodsFor:'accessing'! |
|
58 |
||
623 | 59 |
canReturn |
60 |
"return true, if the receiver allows returning through it. |
|
61 |
For normal method contexts, this normally returns true; |
|
62 |
for blocks, it (currently) always returns false." |
|
63 |
||
64 |
^ false |
|
65 |
! |
|
66 |
||
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
67 |
guessedHome |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
68 |
"a temporary kludge: optimized block contexts do (currently) not provide |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
69 |
any home info. The code below tries to guess the home." |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
70 |
|
8666 | 71 |
|sender tryVars selSender possibleBlocks method| |
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
72 |
|
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
73 |
(home isNil or:[home isContext not]) ifTrue:[ |
8666 | 74 |
(sender := self sender) notNil ifTrue:[ |
75 |
tryVars := false. |
|
76 |
(selSender := sender selector) notNil ifTrue:[ |
|
77 |
(selSender endsWith:'do:') ifTrue:[ |
|
78 |
tryVars := true. |
|
79 |
] ifFalse:[ |
|
80 |
(selSender endsWith:'Do:') ifTrue:[ |
|
81 |
tryVars := true. |
|
82 |
] |
|
83 |
] |
|
84 |
]. |
|
85 |
tryVars ifTrue:[ |
|
86 |
possibleBlocks := sender argsAndVars select:[:v | v isBlock]. |
|
87 |
possibleBlocks := possibleBlocks select:[:b | b home isNil]. |
|
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
88 |
|
8666 | 89 |
possibleBlocks size == 1 ifTrue:[ |
90 |
method := possibleBlocks first method. |
|
91 |
^ method. |
|
92 |
]. |
|
93 |
] |
|
94 |
]. |
|
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
95 |
]. |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
96 |
^ nil |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
97 |
! |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
98 |
|
623 | 99 |
home |
100 |
"return the immediate home of the receiver. |
|
101 |
normally this is the methodcontext, where the block was created, |
|
102 |
for nested block contexts, this is the surrounding blocks context." |
|
103 |
||
104 |
home isContext ifFalse:[^ nil]. "copying blocks have no home" |
|
105 |
^ home |
|
106 |
! |
|
107 |
||
3324
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
108 |
homeReceiver |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
109 |
"return the receiver from the context, where the receiver was defined" |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
110 |
|
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
111 |
home isContext ifFalse:[^ nil]. "copying blocks have no home" |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
112 |
^ home receiver |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
113 |
|
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
114 |
"Created: / 5.3.1998 / 16:20:31 / stefan" |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
115 |
! |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
116 |
|
1 | 117 |
isBlockContext |
118 |
"return true, iff the receiver is a BlockContext, false otherwise" |
|
119 |
||
120 |
^ true |
|
121 |
! |
|
122 |
||
623 | 123 |
method |
124 |
"return the method in which the current contexts block was created." |
|
360 | 125 |
|
623 | 126 |
home notNil ifTrue:[^ home method]. |
127 |
^ nil |
|
360 | 128 |
! |
129 |
||
1 | 130 |
methodHome |
131 |
"return the method-home for block contexts" |
|
132 |
||
133 |
|con h| |
|
134 |
||
135 |
home isNil ifTrue:[^ nil]. "XXX will change soon" |
|
136 |
home isContext ifFalse:[^ nil]. "copying blocks have no method home" |
|
137 |
||
138 |
con := self. |
|
139 |
h := home. |
|
140 |
[h notNil] whileTrue:[ |
|
165 | 141 |
con := h. |
142 |
h := con home |
|
1 | 143 |
]. |
144 |
^ con |
|
145 |
! |
|
146 |
||
147 |
selector |
|
148 |
"return the selector of the context - which is one of the value |
|
281 | 149 |
selectors. This selector is not found in the context, but synthesized." |
1 | 150 |
|
151 |
|nargs| |
|
152 |
||
154 | 153 |
nargs := self numArgs. |
1 | 154 |
(nargs == 0) ifTrue:[^ #value]. |
155 |
(nargs == 1) ifTrue:[^ #value:]. |
|
156 |
(nargs == 2) ifTrue:[^ #value:value:]. |
|
157 |
(nargs == 3) ifTrue:[^ #value:value:value:]. |
|
158 |
(nargs == 4) ifTrue:[^ #value:value:value:value:]. |
|
159 |
(nargs == 5) ifTrue:[^ #value:value:value:value:value:]. |
|
160 |
^ nil |
|
161 |
! ! |
|
162 |
||
92 | 163 |
!BlockContext methodsFor:'printing & storing'! |
1 | 164 |
|
165 |
receiverPrintString |
|
281 | 166 |
"return a printString describing the contexts receiver. |
357 | 167 |
|
168 |
Since this is also used by the debugger(s), be very careful to |
|
281 | 169 |
return something useful, even in case internals of the system |
170 |
got corrupted ... (i.e. avoid messageNotUnderstood here)" |
|
171 |
||
8666 | 172 |
|cls who mHome m className sel |
173 |
method homeSel| |
|
357 | 174 |
|
175 |
(home isNil or:[home isContext not]) ifTrue:[ |
|
8666 | 176 |
" |
177 |
mhmh - an optimized blocks context |
|
178 |
should get the block here, and get the method from |
|
179 |
that one ... |
|
180 |
... but in 2.x, there is no easy way to get to the block |
|
181 |
since that one is not in the context. |
|
182 |
Starting with 3.x, the new block calling scheme will fix this. |
|
183 |
" |
|
241 | 184 |
|
8666 | 185 |
"temporary kludge - peek into the sender context. |
186 |
If its a do-like method and there is a single block variable |
|
187 |
in the args or temporaries, that must be the one. |
|
188 |
This helps in some cases. |
|
189 |
" |
|
190 |
m isNil ifTrue:[ |
|
191 |
^ '[] (optimized) in ???'. |
|
192 |
]. |
|
193 |
^ '[] (optimized) in ' , m mclass name , '-' , m selector. |
|
1 | 194 |
]. |
195 |
||
281 | 196 |
mHome := self methodHome. |
197 |
mHome isNil ifTrue:[ |
|
8666 | 198 |
'BlockContext [warning]: no methodHome' errorPrintCR. |
199 |
^ '[] in ???' |
|
281 | 200 |
]. |
201 |
||
293 | 202 |
" |
203 |
kludge to avoid slow search for containing class |
|
204 |
" |
|
2157
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2128
diff
changeset
|
205 |
((homeSel := mHome selector) == #doIt |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2128
diff
changeset
|
206 |
or:[homeSel == #doIt:]) ifTrue:[ |
8666 | 207 |
sel := #doIt. |
208 |
cls := mHome receiver class. |
|
293 | 209 |
] ifFalse:[ |
8666 | 210 |
m := mHome method. |
211 |
m isNil ifTrue:[ |
|
212 |
'BlockContext [warning]: no method' errorPrintCR. |
|
213 |
^ '[] in ???' |
|
214 |
]. |
|
215 |
who := m who. |
|
216 |
who notNil ifTrue:[ |
|
217 |
cls := who methodClass |
|
218 |
] ifFalse:[ |
|
219 |
cls := receiver class. |
|
220 |
]. |
|
221 |
sel := homeSel printString. |
|
241 | 222 |
]. |
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
223 |
|
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
224 |
cls isNil ifTrue:[ |
8666 | 225 |
'BlockContext [warning]: no home class' errorPrintCR. |
226 |
className := '???' |
|
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
227 |
] ifFalse:[ |
8666 | 228 |
className := cls name. |
229 |
className isNil ifTrue:[ |
|
230 |
'BlockContext [warning]: nameless class' errorPrintCR. |
|
231 |
className := '???' |
|
232 |
] |
|
281 | 233 |
]. |
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
234 |
^ '[] in ' , className , '-' , sel |
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
235 |
|
2157
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2128
diff
changeset
|
236 |
"Modified: 10.1.1997 / 21:26:21 / cg" |
1 | 237 |
! ! |
623 | 238 |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
239 |
!BlockContext class methodsFor:'documentation'! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
240 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
241 |
version |
8666 | 242 |
^ '$Header: /cvs/stx/stx/libbasic/BlockContext.st,v 1.30 2004-12-16 11:21:17 cg Exp $' |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
243 |
! ! |