author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Wed, 25 Jul 2012 09:45:15 +0100 | |
branch | jv |
changeset 17955 | f5ee690b1a27 |
parent 17911 | a99f15c5efa5 |
child 18011 | deb0c3355881 |
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 |
|
4623 | 14 |
Context variableSubclass:#BlockContext |
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
15 |
instanceVariableNames:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
16 |
classVariableNames:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
17 |
poolDictionaries:'' |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
18 |
category:'Kernel-Methods' |
1 | 19 |
! |
20 |
||
88 | 21 |
!BlockContext class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
165 | 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 |
" |
|
8666 | 39 |
BlockContexts represent the stack context objects of blocks. |
40 |
The layout is the same as for other contexts - this class has been added |
|
88 | 41 |
to avoid a flag in an instance variable. |
42 |
(has become necessary with cheap blocks, which have no home). |
|
43 |
||
8666 | 44 |
WARNING: layout and size known by compiler and runtime system - |
45 |
do not change. |
|
1293 | 46 |
|
47 |
[author:] |
|
8666 | 48 |
Claus Gittinger |
1293 | 49 |
|
50 |
[see also:] |
|
8666 | 51 |
Context Block Method |
52 |
Exception Signal |
|
88 | 53 |
" |
54 |
! ! |
|
1 | 55 |
|
17865 | 56 |
|
1 | 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 |
|
623 | 117 |
method |
118 |
"return the method in which the current contexts block was created." |
|
360 | 119 |
|
623 | 120 |
home notNil ifTrue:[^ home method]. |
17955 | 121 |
^ super method |
122 |
||
123 |
"Modified: / 19-07-2012 / 10:58:55 / cg" |
|
360 | 124 |
! |
125 |
||
1 | 126 |
methodHome |
127 |
"return the method-home for block contexts" |
|
128 |
||
129 |
|con h| |
|
130 |
||
131 |
home isNil ifTrue:[^ nil]. "XXX will change soon" |
|
132 |
home isContext ifFalse:[^ nil]. "copying blocks have no method home" |
|
133 |
||
134 |
con := self. |
|
135 |
h := home. |
|
136 |
[h notNil] whileTrue:[ |
|
165 | 137 |
con := h. |
138 |
h := con home |
|
1 | 139 |
]. |
140 |
^ con |
|
141 |
! |
|
142 |
||
143 |
selector |
|
144 |
"return the selector of the context - which is one of the value |
|
281 | 145 |
selectors. This selector is not found in the context, but synthesized." |
1 | 146 |
|
147 |
|nargs| |
|
148 |
||
154 | 149 |
nargs := self numArgs. |
1 | 150 |
(nargs == 0) ifTrue:[^ #value]. |
151 |
(nargs == 1) ifTrue:[^ #value:]. |
|
152 |
(nargs == 2) ifTrue:[^ #value:value:]. |
|
153 |
(nargs == 3) ifTrue:[^ #value:value:value:]. |
|
154 |
(nargs == 4) ifTrue:[^ #value:value:value:value:]. |
|
155 |
(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
|
156 |
(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
|
157 |
(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
|
158 |
(nargs == 8) ifTrue:[^ #value:value:value:value:value:value:value:value:]. |
1 | 159 |
^ nil |
160 |
! ! |
|
161 |
||
92 | 162 |
!BlockContext methodsFor:'printing & storing'! |
1 | 163 |
|
164 |
receiverPrintString |
|
281 | 165 |
"return a printString describing the contexts receiver. |
357 | 166 |
|
167 |
Since this is also used by the debugger(s), be very careful to |
|
281 | 168 |
return something useful, even in case internals of the system |
169 |
got corrupted ... (i.e. avoid messageNotUnderstood here)" |
|
170 |
||
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
171 |
|cls who mHome m className sel homeSel| |
357 | 172 |
|
173 |
(home isNil or:[home isContext not]) ifTrue:[ |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
174 |
" |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
175 |
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
|
176 |
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
|
177 |
that one ... |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
178 |
... 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
|
179 |
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
|
180 |
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
|
181 |
" |
241 | 182 |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
183 |
"temporary kludge - peek into the sender context. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
184 |
If its a do-like method and there is a single block variable |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
185 |
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
|
186 |
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
|
187 |
" |
17955 | 188 |
m := self method. |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
189 |
m isNil ifTrue:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
190 |
^ '[] (optimized) in ???'. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
191 |
]. |
17955 | 192 |
^ '[] in ' , m mclass name , ' >> ' , m selector. |
1 | 193 |
]. |
194 |
||
281 | 195 |
mHome := self methodHome. |
196 |
mHome isNil ifTrue:[ |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
197 |
'BlockContext [warning]: no methodHome' errorPrintCR. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
198 |
^ '[] in ???' |
281 | 199 |
]. |
200 |
||
293 | 201 |
" |
202 |
kludge to avoid slow search for containing class |
|
203 |
" |
|
2157
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2128
diff
changeset
|
204 |
((homeSel := mHome selector) == #doIt |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2128
diff
changeset
|
205 |
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
|
206 |
sel := #doIt. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
207 |
cls := mHome receiver class. |
293 | 208 |
] ifFalse:[ |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
209 |
m := mHome method. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
210 |
m isNil ifTrue:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
211 |
'BlockContext [warning]: no method' errorPrintCR. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
212 |
^ '[] in ???' |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
213 |
]. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
214 |
who := m who. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
215 |
who notNil ifTrue:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
216 |
cls := who methodClass |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
217 |
] ifFalse:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
218 |
cls := receiver class. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
219 |
]. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
220 |
sel := homeSel printString. |
241 | 221 |
]. |
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
222 |
|
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
223 |
cls isNil ifTrue:[ |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
224 |
'BlockContext [warning]: no home class' errorPrintCR. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
225 |
className := '???' |
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
226 |
] ifFalse:[ |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
227 |
className := cls name. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
228 |
className isNil ifTrue:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
229 |
'BlockContext [warning]: nameless class' errorPrintCR. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
230 |
className := '???' |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
231 |
] |
281 | 232 |
]. |
11313 | 233 |
^ '[] in ' , className , ' >> ' , sel |
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
234 |
|
17955 | 235 |
"Modified: / 19-07-2012 / 11:02:41 / cg" |
236 |
! ! |
|
237 |
||
238 |
!BlockContext methodsFor:'testing'! |
|
239 |
||
240 |
isBlockContext |
|
241 |
"return true, iff the receiver is a BlockContext, false otherwise" |
|
242 |
||
243 |
^ true |
|
244 |
! |
|
245 |
||
246 |
isCheapBlockContext |
|
247 |
"return true, iff the receiver is a BlockContext, for a cheap block, false otherwise. |
|
248 |
Cheap blocks do not refer to their home" |
|
249 |
||
250 |
^ home isNil |
|
251 |
||
252 |
"Created: / 19-07-2012 / 11:22:23 / cg" |
|
1 | 253 |
! ! |
623 | 254 |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
255 |
!BlockContext class methodsFor:'documentation'! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
256 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
257 |
version |
17955 | 258 |
^ '$Header: /cvs/stx/stx/libbasic/BlockContext.st,v 1.35 2012/07/19 09:24:00 cg Exp $' |
259 |
! |
|
260 |
||
261 |
version_CVS |
|
262 |
^ '§Header: /cvs/stx/stx/libbasic/BlockContext.st,v 1.35 2012/07/19 09:24:00 cg Exp §' |
|
17865 | 263 |
! |
264 |
||
265 |
version_SVN |
|
17955 | 266 |
^ '$Id: BlockContext.st 10829 2012-07-25 08:45:15Z vranyj1 $' |
17846 | 267 |
! ! |
17892 | 268 |
|
17910 | 269 |
|
17911 | 270 |