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