author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 18 Jul 2011 16:22:09 +0100 | |
branch | jv |
changeset 17846 | 24edc476ac18 |
parent 17845 | 7e0cfaac936d |
child 17865 | 598963c6ff8e |
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 |
|
56 |
!BlockContext methodsFor:'accessing'! |
|
57 |
||
623 | 58 |
canReturn |
59 |
"return true, if the receiver allows returning through it. |
|
60 |
For normal method contexts, this normally returns true; |
|
61 |
for blocks, it (currently) always returns false." |
|
62 |
||
63 |
^ false |
|
64 |
! |
|
65 |
||
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
66 |
guessedHome |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
67 |
"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
|
68 |
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
|
69 |
|
8666 | 70 |
|sender tryVars selSender possibleBlocks method| |
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
71 |
|
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
72 |
(home isNil or:[home isContext not]) ifTrue:[ |
8666 | 73 |
(sender := self sender) notNil ifTrue:[ |
74 |
tryVars := false. |
|
75 |
(selSender := sender selector) notNil ifTrue:[ |
|
76 |
(selSender endsWith:'do:') ifTrue:[ |
|
77 |
tryVars := true. |
|
78 |
] ifFalse:[ |
|
79 |
(selSender endsWith:'Do:') ifTrue:[ |
|
80 |
tryVars := true. |
|
81 |
] |
|
82 |
] |
|
83 |
]. |
|
84 |
tryVars ifTrue:[ |
|
85 |
possibleBlocks := sender argsAndVars select:[:v | v isBlock]. |
|
86 |
possibleBlocks := possibleBlocks select:[:b | b home isNil]. |
|
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
87 |
|
8666 | 88 |
possibleBlocks size == 1 ifTrue:[ |
89 |
method := possibleBlocks first method. |
|
90 |
^ method. |
|
91 |
]. |
|
92 |
] |
|
93 |
]. |
|
5528
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
94 |
]. |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
95 |
^ nil |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
96 |
! |
2a96dd29ca28
guess home of optimized block contexts
Claus Gittinger <cg@exept.de>
parents:
4623
diff
changeset
|
97 |
|
623 | 98 |
home |
99 |
"return the immediate home of the receiver. |
|
100 |
normally this is the methodcontext, where the block was created, |
|
101 |
for nested block contexts, this is the surrounding blocks context." |
|
102 |
||
103 |
home isContext ifFalse:[^ nil]. "copying blocks have no home" |
|
104 |
^ home |
|
105 |
! |
|
106 |
||
3324
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
107 |
homeReceiver |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
108 |
"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
|
109 |
|
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
110 |
home isContext ifFalse:[^ nil]. "copying blocks have no home" |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
111 |
^ home receiver |
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 |
"Created: / 5.3.1998 / 16:20:31 / stefan" |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
114 |
! |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
2157
diff
changeset
|
115 |
|
1 | 116 |
isBlockContext |
117 |
"return true, iff the receiver is a BlockContext, false otherwise" |
|
118 |
||
119 |
^ true |
|
120 |
! |
|
121 |
||
623 | 122 |
method |
123 |
"return the method in which the current contexts block was created." |
|
360 | 124 |
|
623 | 125 |
home notNil ifTrue:[^ home method]. |
126 |
^ nil |
|
360 | 127 |
! |
128 |
||
1 | 129 |
methodHome |
130 |
"return the method-home for block contexts" |
|
131 |
||
132 |
|con h| |
|
133 |
||
134 |
home isNil ifTrue:[^ nil]. "XXX will change soon" |
|
135 |
home isContext ifFalse:[^ nil]. "copying blocks have no method home" |
|
136 |
||
137 |
con := self. |
|
138 |
h := home. |
|
139 |
[h notNil] whileTrue:[ |
|
165 | 140 |
con := h. |
141 |
h := con home |
|
1 | 142 |
]. |
143 |
^ con |
|
144 |
! |
|
145 |
||
146 |
selector |
|
147 |
"return the selector of the context - which is one of the value |
|
281 | 148 |
selectors. This selector is not found in the context, but synthesized." |
1 | 149 |
|
150 |
|nargs| |
|
151 |
||
154 | 152 |
nargs := self numArgs. |
1 | 153 |
(nargs == 0) ifTrue:[^ #value]. |
154 |
(nargs == 1) ifTrue:[^ #value:]. |
|
155 |
(nargs == 2) ifTrue:[^ #value:value:]. |
|
156 |
(nargs == 3) ifTrue:[^ #value:value:value:]. |
|
157 |
(nargs == 4) ifTrue:[^ #value:value:value:value:]. |
|
158 |
(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
|
159 |
(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
|
160 |
(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
|
161 |
(nargs == 8) ifTrue:[^ #value:value:value:value:value:value:value:value:]. |
1 | 162 |
^ nil |
163 |
! ! |
|
164 |
||
92 | 165 |
!BlockContext methodsFor:'printing & storing'! |
1 | 166 |
|
167 |
receiverPrintString |
|
281 | 168 |
"return a printString describing the contexts receiver. |
357 | 169 |
|
170 |
Since this is also used by the debugger(s), be very careful to |
|
281 | 171 |
return something useful, even in case internals of the system |
172 |
got corrupted ... (i.e. avoid messageNotUnderstood here)" |
|
173 |
||
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
174 |
|cls who mHome m className sel homeSel| |
357 | 175 |
|
176 |
(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
|
177 |
" |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
178 |
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
|
179 |
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
|
180 |
that one ... |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
181 |
... 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
|
182 |
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
|
183 |
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
|
184 |
" |
241 | 185 |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
186 |
"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
|
187 |
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
|
188 |
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
|
189 |
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
|
190 |
" |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
191 |
m isNil ifTrue:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
192 |
^ '[] (optimized) in ???'. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
193 |
]. |
11313 | 194 |
^ '[] (optimized) in ' , m mclass name , ' >> ' , m selector. |
1 | 195 |
]. |
196 |
||
281 | 197 |
mHome := self methodHome. |
198 |
mHome isNil ifTrue:[ |
|
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
199 |
'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
|
200 |
^ '[] in ???' |
281 | 201 |
]. |
202 |
||
293 | 203 |
" |
204 |
kludge to avoid slow search for containing class |
|
205 |
" |
|
2157
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2128
diff
changeset
|
206 |
((homeSel := mHome selector) == #doIt |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2128
diff
changeset
|
207 |
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
|
208 |
sel := #doIt. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
209 |
cls := mHome receiver class. |
293 | 210 |
] ifFalse:[ |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
211 |
m := mHome method. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
212 |
m isNil ifTrue:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
213 |
'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
|
214 |
^ '[] in ???' |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
215 |
]. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
216 |
who := m who. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
217 |
who notNil ifTrue:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
218 |
cls := who methodClass |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
219 |
] ifFalse:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
220 |
cls := receiver class. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
221 |
]. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
222 |
sel := homeSel printString. |
241 | 223 |
]. |
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
224 |
|
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
225 |
cls isNil ifTrue:[ |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
226 |
'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
|
227 |
className := '???' |
1852
89b2328f4203
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
228 |
] ifFalse:[ |
11307
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
229 |
className := cls name. |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
230 |
className isNil ifTrue:[ |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
231 |
'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
|
232 |
className := '???' |
98d31040610f
Print methods: Show message sends as Class >> #selector (with the #),
Stefan Vogel <sv@exept.de>
parents:
11168
diff
changeset
|
233 |
] |
281 | 234 |
]. |
11313 | 235 |
^ '[] in ' , className , ' >> ' , sel |
1444
cb2493aa4d0c
fixed homeless-optimized-block printString
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
236 |
|
2157
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2128
diff
changeset
|
237 |
"Modified: 10.1.1997 / 21:26:21 / cg" |
1 | 238 |
! ! |
623 | 239 |
|
1183
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
240 |
!BlockContext class methodsFor:'documentation'! |
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
241 |
|
e3d58d115e53
subclasses of fixed classes are still possible
Claus Gittinger <cg@exept.de>
parents:
623
diff
changeset
|
242 |
version |
17846 | 243 |
^ '$Id: BlockContext.st 10660 2011-07-18 15:22:09Z vranyj1 $' |
244 |
! ! |