author | Claus Gittinger <cg@exept.de> |
Fri, 13 Dec 2019 15:35:34 +0100 | |
changeset 25116 | aa3a98621b0a |
parent 24740 | 7fdaf3987d8f |
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 |
" |
|
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
13 |
|
18433 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
4623 | 16 |
Context variableSubclass:#BlockContext |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
17 |
instanceVariableNames:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
18 |
classVariableNames:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
19 |
poolDictionaries:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
20 |
category:'Kernel-Methods' |
1 | 21 |
! |
22 |
||
88 | 23 |
!BlockContext class methodsFor:'documentation'! |
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
165 | 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 |
" |
|
8666 | 41 |
BlockContexts represent the stack context objects of blocks. |
42 |
The layout is the same as for other contexts - this class has been added |
|
88 | 43 |
to avoid a flag in an instance variable. |
44 |
(has become necessary with cheap blocks, which have no home). |
|
45 |
||
8666 | 46 |
WARNING: layout and size known by compiler and runtime system - |
47 |
do not change. |
|
1293 | 48 |
|
49 |
[author:] |
|
8666 | 50 |
Claus Gittinger |
1293 | 51 |
|
52 |
[see also:] |
|
8666 | 53 |
Context Block Method |
54 |
Exception Signal |
|
88 | 55 |
" |
56 |
! ! |
|
1 | 57 |
|
24740 | 58 |
|
1 | 59 |
!BlockContext methodsFor:'accessing'! |
60 |
||
623 | 61 |
canReturn |
62 |
"return true, if the receiver allows returning through it. |
|
63 |
For normal method contexts, this normally returns true; |
|
64 |
for blocks, it (currently) always returns false." |
|
65 |
||
66 |
^ false |
|
67 |
! |
|
68 |
||
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
69 |
guessedHome |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
70 |
"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
|
71 |
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
|
72 |
|
8666 | 73 |
|sender tryVars selSender possibleBlocks method| |
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
74 |
|
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
75 |
(home isNil or:[home isContext not]) ifTrue:[ |
8666 | 76 |
(sender := self sender) notNil ifTrue:[ |
77 |
tryVars := false. |
|
78 |
(selSender := sender selector) notNil ifTrue:[ |
|
79 |
(selSender endsWith:'do:') ifTrue:[ |
|
80 |
tryVars := true. |
|
81 |
] ifFalse:[ |
|
82 |
(selSender endsWith:'Do:') ifTrue:[ |
|
83 |
tryVars := true. |
|
84 |
] |
|
85 |
] |
|
86 |
]. |
|
87 |
tryVars ifTrue:[ |
|
88 |
possibleBlocks := sender argsAndVars select:[:v | v isBlock]. |
|
89 |
possibleBlocks := possibleBlocks select:[:b | b home isNil]. |
|
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
90 |
|
8666 | 91 |
possibleBlocks size == 1 ifTrue:[ |
92 |
method := possibleBlocks first method. |
|
93 |
^ method. |
|
94 |
]. |
|
95 |
] |
|
96 |
]. |
|
5528
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 |
^ nil |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
99 |
! |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
100 |
|
623 | 101 |
home |
102 |
"return the immediate home of the receiver. |
|
103 |
normally this is the methodcontext, where the block was created, |
|
104 |
for nested block contexts, this is the surrounding blocks context." |
|
105 |
||
106 |
home isContext ifFalse:[^ nil]. "copying blocks have no home" |
|
107 |
^ home |
|
108 |
! |
|
109 |
||
3324
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
110 |
homeReceiver |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
111 |
"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
|
112 |
|
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
113 |
home isContext ifFalse:[^ nil]. "copying blocks have no home" |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
114 |
^ home receiver |
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 |
"Created: / 5.3.1998 / 16:20:31 / stefan" |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
117 |
! |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
118 |
|
623 | 119 |
method |
120 |
"return the method in which the current contexts block was created." |
|
360 | 121 |
|
623 | 122 |
home notNil ifTrue:[^ home method]. |
14213 | 123 |
^ super method |
124 |
||
125 |
"Modified: / 19-07-2012 / 10:58:55 / cg" |
|
360 | 126 |
! |
127 |
||
1 | 128 |
methodHome |
129 |
"return the method-home for block contexts" |
|
130 |
||
131 |
|con h| |
|
132 |
||
15267 | 133 |
home isNil ifTrue:[^ nil]. |
1 | 134 |
home isContext ifFalse:[^ nil]. "copying blocks have no method home" |
135 |
||
136 |
h := home. |
|
22530 | 137 |
[ |
15220 | 138 |
con := h. |
22530 | 139 |
h := con home. |
140 |
h notNil |
|
141 |
] whileTrue. |
|
142 |
||
1 | 143 |
^ con |
22530 | 144 |
|
145 |
"Modified: / 02-02-2018 / 14:01:32 / stefan" |
|
1 | 146 |
! |
147 |
||
148 |
selector |
|
149 |
"return the selector of the context - which is one of the value |
|
281 | 150 |
selectors. This selector is not found in the context, but synthesized." |
1 | 151 |
|
152 |
|nargs| |
|
153 |
||
18433 | 154 |
nargs := self argumentCount. |
1 | 155 |
(nargs == 0) ifTrue:[^ #value]. |
156 |
(nargs == 1) ifTrue:[^ #value:]. |
|
157 |
(nargs == 2) ifTrue:[^ #value:value:]. |
|
158 |
(nargs == 3) ifTrue:[^ #value:value:value:]. |
|
159 |
(nargs == 4) ifTrue:[^ #value:value:value:value:]. |
|
160 |
(nargs == 5) ifTrue:[^ #value:value:value:value:value:]. |
|
11168
44fef5d29484
Support up to 8 args in #selector
Stefan Vogel <sv@exept.de>
parents:
8666
diff
changeset
|
161 |
(nargs == 6) ifTrue:[^ #value:value:value:value:value:value:]. |
44fef5d29484
Support up to 8 args in #selector
Stefan Vogel <sv@exept.de>
parents:
8666
diff
changeset
|
162 |
(nargs == 7) ifTrue:[^ #value:value:value:value:value:value:value:]. |
44fef5d29484
Support up to 8 args in #selector
Stefan Vogel <sv@exept.de>
parents:
8666
diff
changeset
|
163 |
(nargs == 8) ifTrue:[^ #value:value:value:value:value:value:value:value:]. |
15454 | 164 |
(nargs == 9) ifTrue:[^ #value:value:value:value:value:value:value:value:value:]. |
165 |
(nargs == 10) ifTrue:[^ #value:value:value:value:value:value:value:value:value:value:]. |
|
166 |
(nargs == 11) ifTrue:[^ #value:value:value:value:value:value:value:value:value:value:value:]. |
|
167 |
(nargs == 12) ifTrue:[^ #value:value:value:value:value:value:value:value:value:value:value:value:]. |
|
1 | 168 |
^ nil |
169 |
! ! |
|
170 |
||
92 | 171 |
!BlockContext methodsFor:'printing & storing'! |
1 | 172 |
|
24740 | 173 |
printReceiverWithSeparator:sep on:aStream |
15382 | 174 |
"print a string describing the receiver of the context on aStream |
357 | 175 |
|
176 |
Since this is also used by the debugger(s), be very careful to |
|
281 | 177 |
return something useful, even in case internals of the system |
178 |
got corrupted ... (i.e. avoid messageNotUnderstood here)" |
|
179 |
||
15382 | 180 |
|cls who mHome m className homeSel| |
357 | 181 |
|
15382 | 182 |
home isContext ifFalse:[ |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
183 |
" |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
184 |
mhmh - an optimized blocks context |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
185 |
should get the block here, and get the method from |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
186 |
that one ... |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
187 |
... but in 2.x, there is no easy way to get to the block |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
188 |
since that one is not in the context. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
189 |
Starting with 3.x, the new block calling scheme will fix this. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
190 |
" |
241 | 191 |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
192 |
"temporary kludge - peek into the sender context. |
21418 | 193 |
If it's a do-like method and there is a single block variable |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
194 |
in the args or temporaries, that must be the one. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
195 |
This helps in some cases. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
196 |
" |
14213 | 197 |
m := self method. |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
198 |
m isNil ifTrue:[ |
15382 | 199 |
aStream nextPutAll:'[] (optimized) in ???'. |
200 |
] ifFalse:[ |
|
201 |
aStream nextPutAll:'[] in '. |
|
20889 | 202 |
cls := m mclass. |
203 |
cls isNil ifTrue:[ |
|
204 |
cls := m getMclass. |
|
205 |
cls isNil ifTrue:[ |
|
206 |
className := '*Unbound*' |
|
207 |
] ifFalse:[ |
|
208 |
className := '(previously in) ',cls name |
|
209 |
]. |
|
210 |
] ifFalse:[ |
|
211 |
className := cls name. |
|
212 |
]. |
|
213 |
className printOn:aStream. |
|
24740 | 214 |
aStream nextPutAll:sep. |
23132 | 215 |
aStream bold. |
15382 | 216 |
m selector printOn:aStream. |
23132 | 217 |
aStream normal. |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
218 |
]. |
15382 | 219 |
^ self. |
1 | 220 |
]. |
221 |
||
281 | 222 |
mHome := self methodHome. |
223 |
mHome isNil ifTrue:[ |
|
15382 | 224 |
aStream nextPutAll:'[] (no methodHome!!) in ???'. |
225 |
^ self. |
|
281 | 226 |
]. |
227 |
||
293 | 228 |
" |
229 |
kludge to avoid slow search for containing class |
|
230 |
" |
|
15382 | 231 |
homeSel := mHome selector. |
232 |
(homeSel == #doIt or:[homeSel == #doIt:]) ifTrue:[ |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
233 |
cls := mHome receiver class. |
15382 | 234 |
homeSel := #doIt. |
293 | 235 |
] ifFalse:[ |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
236 |
m := mHome method. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
237 |
m isNil ifTrue:[ |
15382 | 238 |
aStream nextPutAll:'[] (no method!!) in ???'. |
239 |
^ self. |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
240 |
]. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
241 |
who := m who. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
242 |
who notNil ifTrue:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
243 |
cls := who methodClass |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
244 |
] ifFalse:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
245 |
cls := receiver class. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
246 |
]. |
241 | 247 |
]. |
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
248 |
|
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
249 |
cls isNil ifTrue:[ |
15382 | 250 |
className := '???(no home class!!)' |
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
251 |
] ifFalse:[ |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
252 |
className := cls name. |
15382 | 253 |
className isEmptyOrNil ifTrue:[ |
254 |
className := '???(nameless class!!)' |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
255 |
] |
281 | 256 |
]. |
24740 | 257 |
aStream nextPutAll:'[] in '; nextPutAll:className; nextPutAll:sep. |
23132 | 258 |
aStream bold. |
15382 | 259 |
homeSel printOn:aStream. |
23132 | 260 |
aStream normal. |
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
261 |
|
14213 | 262 |
"Modified: / 19-07-2012 / 11:02:41 / cg" |
21418 | 263 |
"Modified (format): / 13-02-2017 / 19:56:14 / cg" |
23132 | 264 |
"Modified: / 26-06-2018 / 19:25:02 / Claus Gittinger" |
1 | 265 |
! ! |
623 | 266 |
|
14215 | 267 |
!BlockContext methodsFor:'testing'! |
268 |
||
269 |
isBlockContext |
|
270 |
"return true, iff the receiver is a BlockContext, false otherwise" |
|
271 |
||
272 |
^ true |
|
273 |
! |
|
274 |
||
275 |
isCheapBlockContext |
|
276 |
"return true, iff the receiver is a BlockContext, for a cheap block, false otherwise. |
|
277 |
Cheap blocks do not refer to their home" |
|
278 |
||
279 |
^ home isNil |
|
280 |
||
281 |
"Created: / 19-07-2012 / 11:22:23 / cg" |
|
282 |
! ! |
|
283 |
||
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
284 |
!BlockContext class methodsFor:'documentation'! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
285 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
286 |
version |
20889 | 287 |
^ '$Header$' |
14215 | 288 |
! |
289 |
||
290 |
version_CVS |
|
20889 | 291 |
^ '$Header$' |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
292 |
! ! |
15220 | 293 |