author | Claus Gittinger <cg@exept.de> |
Sat, 11 Nov 1995 15:28:26 +0100 | |
changeset 528 | a083413dfbe8 |
parent 384 | cc3d110ea879 |
child 623 | 6795a71e39d1 |
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 |
||
13 |
Context subclass:#BlockContext |
|
14 |
instanceVariableNames:'' "do not add instvars here" |
|
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'Kernel-Methods' |
|
18 |
! |
|
19 |
||
88 | 20 |
!BlockContext class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
165 | 25 |
All Rights Reserved |
1 | 26 |
|
88 | 27 |
This software is furnished under a license and may be used |
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
1 | 35 |
|
88 | 36 |
version |
528
a083413dfbe8
converted version methods from comment-only to returning-a-string
Claus Gittinger <cg@exept.de>
parents:
384
diff
changeset
|
37 |
^ '$Header: /cvs/stx/stx/libbasic/BlockContext.st,v 1.18 1995-11-11 14:26:48 cg Exp $' |
88 | 38 |
! |
1 | 39 |
|
88 | 40 |
documentation |
41 |
" |
|
42 |
BlockContexts represent the stack context objects of blocks. |
|
43 |
The layout is the same as for other contexts - this class has been added |
|
44 |
to avoid a flag in an instance variable. |
|
45 |
(has become necessary with cheap blocks, which have no home). |
|
46 |
||
47 |
WARNING: layout and size known by compiler and runtime system - |
|
165 | 48 |
do not change. |
88 | 49 |
" |
50 |
! ! |
|
1 | 51 |
|
52 |
!BlockContext methodsFor:'accessing'! |
|
53 |
||
54 |
isBlockContext |
|
55 |
"return true, iff the receiver is a BlockContext, false otherwise" |
|
56 |
||
57 |
^ true |
|
58 |
! |
|
59 |
||
360 | 60 |
canReturn |
61 |
"return true, if the receiver allows returning through it. |
|
62 |
For normal method contexts, this normally returns true; |
|
63 |
for blocks, it (currently) always returns false." |
|
64 |
||
65 |
^ false |
|
66 |
! |
|
67 |
||
1 | 68 |
methodHome |
69 |
"return the method-home for block contexts" |
|
70 |
||
71 |
|con h| |
|
72 |
||
73 |
home isNil ifTrue:[^ nil]. "XXX will change soon" |
|
74 |
home isContext ifFalse:[^ nil]. "copying blocks have no method home" |
|
75 |
||
76 |
con := self. |
|
77 |
h := home. |
|
78 |
[h notNil] whileTrue:[ |
|
165 | 79 |
con := h. |
80 |
h := con home |
|
1 | 81 |
]. |
82 |
^ con |
|
83 |
! |
|
84 |
||
216 | 85 |
method |
86 |
"return the method in which the current contexts block was created." |
|
87 |
||
88 |
home notNil ifTrue:[^ home method]. |
|
89 |
^ nil |
|
90 |
! |
|
91 |
||
1 | 92 |
home |
93 |
"return the immediate home of the receiver. |
|
94 |
normally this is the methodcontext, where the block was created, |
|
95 |
for nested block contexts, this is the surrounding blocks context." |
|
96 |
||
97 |
home isContext ifFalse:[^ nil]. "copying blocks have no home" |
|
98 |
^ home |
|
99 |
! |
|
100 |
||
101 |
selector |
|
102 |
"return the selector of the context - which is one of the value |
|
281 | 103 |
selectors. This selector is not found in the context, but synthesized." |
1 | 104 |
|
105 |
|nargs| |
|
106 |
||
154 | 107 |
nargs := self numArgs. |
1 | 108 |
(nargs == 0) ifTrue:[^ #value]. |
109 |
(nargs == 1) ifTrue:[^ #value:]. |
|
110 |
(nargs == 2) ifTrue:[^ #value:value:]. |
|
111 |
(nargs == 3) ifTrue:[^ #value:value:value:]. |
|
112 |
(nargs == 4) ifTrue:[^ #value:value:value:value:]. |
|
113 |
(nargs == 5) ifTrue:[^ #value:value:value:value:value:]. |
|
114 |
^ nil |
|
115 |
! ! |
|
116 |
||
92 | 117 |
!BlockContext methodsFor:'printing & storing'! |
1 | 118 |
|
119 |
receiverPrintString |
|
281 | 120 |
"return a printString describing the contexts receiver. |
357 | 121 |
|
122 |
Since this is also used by the debugger(s), be very careful to |
|
281 | 123 |
return something useful, even in case internals of the system |
124 |
got corrupted ... (i.e. avoid messageNotUnderstood here)" |
|
125 |
||
357 | 126 |
|cls who mHome m className |
127 |
sender selSender tryVars possibleBlocks method mWho| |
|
128 |
||
129 |
(home isNil or:[home isContext not]) ifTrue:[ |
|
130 |
" |
|
131 |
mhmh - an optimized blocks context |
|
132 |
should get the block here, and get the method from |
|
133 |
that one ... |
|
134 |
... but in 2.10.x, there is no easy way to get to the block |
|
135 |
since that one is not in the context. |
|
136 |
Starting with 2.11, the new block calling scheme will fix this. |
|
137 |
" |
|
241 | 138 |
|
357 | 139 |
"temporary kludge - peek into the sender context. |
140 |
If its a do-like method and there is a single block variable |
|
141 |
in the args or temporaries, that must be the one. |
|
142 |
This helps in some cases. |
|
143 |
" |
|
144 |
(sender := self sender) notNil ifTrue:[ |
|
145 |
tryVars := false. |
|
146 |
(selSender := sender selector) notNil ifTrue:[ |
|
147 |
(selSender endsWith:'do:') ifTrue:[ |
|
148 |
tryVars := true. |
|
149 |
] ifFalse:[ |
|
150 |
(selSender endsWith:'Do:') ifTrue:[ |
|
151 |
tryVars := true. |
|
152 |
] |
|
153 |
] |
|
154 |
]. |
|
155 |
tryVars ifTrue:[ |
|
156 |
possibleBlocks := sender argsAndVars select:[:v | v isBlock]. |
|
157 |
possibleBlocks := possibleBlocks select:[:b | b home isNil]. |
|
158 |
||
159 |
possibleBlocks size == 1 ifTrue:[ |
|
160 |
method := possibleBlocks first method. |
|
161 |
" |
|
162 |
change the line in the upper-listview |
|
163 |
according the information we have now |
|
164 |
" |
|
165 |
mWho := method who. |
|
166 |
^ '[] (optimized) in ' , |
|
167 |
(mWho at:1) name , '-' , (mWho at:2). |
|
168 |
]. |
|
169 |
] |
|
170 |
]. |
|
171 |
||
165 | 172 |
^ '[] optimized' |
1 | 173 |
]. |
174 |
||
281 | 175 |
mHome := self methodHome. |
176 |
mHome isNil ifTrue:[ |
|
177 |
'BCONTEXT: no methodHome' errorPrintNL. |
|
178 |
^ '[] in ???' |
|
179 |
]. |
|
180 |
||
293 | 181 |
" |
182 |
kludge to avoid slow search for containing class |
|
183 |
" |
|
184 |
mHome selector == #doIt ifTrue:[ |
|
185 |
who := Array with:mHome receiver class |
|
186 |
with:#doIt |
|
187 |
] ifFalse:[ |
|
188 |
m := mHome method. |
|
189 |
m isNil ifTrue:[ |
|
190 |
'BCONTEXT: no method' errorPrintNL. |
|
191 |
^ '[] in ???' |
|
192 |
]. |
|
193 |
who := m who. |
|
281 | 194 |
]. |
241 | 195 |
who notNil ifTrue:[ |
196 |
cls := who at:1 |
|
197 |
] ifFalse:[ |
|
198 |
cls := receiver class. |
|
199 |
]. |
|
281 | 200 |
className := cls name. |
201 |
className isNil ifTrue:[ |
|
202 |
'BCONTEXT: nameless class' errorPrintNL. |
|
203 |
className := '???' |
|
204 |
]. |
|
205 |
^ '[] in ' , className , '-' , mHome selector printString |
|
1 | 206 |
! ! |