author | Claus Gittinger <cg@exept.de> |
Mon, 14 Oct 1996 12:11:45 +0200 | |
changeset 1727 | 362977e02372 |
parent 1726 | de533c7f3172 |
child 1810 | fc151ad836ef |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
154 | 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 |
Object variableSubclass:#Context |
|
749 | 14 |
instanceVariableNames:'flags sender home receiver selector searchClass lineNr retvalTemp |
15 |
handle*' |
|
1334
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
16 |
classVariableNames:'InvalidReturnSignal SingleStepInterruptRequest' |
749 | 17 |
poolDictionaries:'' |
18 |
category:'Kernel-Methods' |
|
1 | 19 |
! |
20 |
||
1483 | 21 |
!Context class methodsFor:'documentation'! |
54 | 22 |
|
88 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
154 | 26 |
All Rights Reserved |
88 | 27 |
|
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 |
! |
|
36 |
||
54 | 37 |
documentation |
38 |
" |
|
402 | 39 |
Contexts represent the stack frame objects, which keep the processing |
40 |
state of a method or block (i.e. its local variables, temporaries etc.) |
|
41 |
Every message send adds a context to a chain, which can be traced back via |
|
42 |
the sender field. The context of the currently active method is always |
|
43 |
accessable via the pseuodoVariable called 'thisContext'. |
|
141 | 44 |
(The actual implementation uses the machines stack for this, building real |
402 | 45 |
contexts on demand only). |
54 | 46 |
|
69 | 47 |
For both method- and block-contexts, the layout is the same. |
402 | 48 |
For method contexts, the home-field is nil, while for block contexts the home- |
141 | 49 |
field is either the context of its surrounding block (i.e. the context of the |
50 |
block, in which the receiving block was created, if its a nested block) or of |
|
51 |
its home method. |
|
52 |
||
53 |
Contexts of cheap blocks do not have a home context - their home field is |
|
54 |
also nil. |
|
54 | 55 |
|
141 | 56 |
Currently, contexts do not contain a reference to the method or block which |
57 |
created it - this is not needed for program execution, but could get the debugger |
|
58 |
somewhat into trouble: it has to search the class hierarchy for receiver/selector |
|
59 |
combinations to find the method. This usually works, but fails in case of methods |
|
60 |
which are not anchored in any class - especially leading to problems with wrapper- |
|
61 |
and lazy methods. Also, Method>>valueWithReceiver - type of invocations cannot |
|
62 |
be easily debugged. |
|
402 | 63 |
Therefore, the implementation may be changed in the near future, to include a |
141 | 64 |
field for the method/block, and set it in the VM during program execution. |
65 |
(there may be some small performance penalty for this, though). |
|
66 |
||
402 | 67 |
LineNumbers vs. program counter: |
68 |
||
69 |
Due to the compilation to machine code, methods and/or block do not |
|
216 | 70 |
always (actually: do seldom) contain bytecodes. Thus, there is no such concept |
71 |
as a bytecode p-counter. To support debugging, the linenumber within the |
|
72 |
original source is instead remembered when a send or loop entry is performed. |
|
73 |
Since linenumbers are not always sufficient for debugging (multiple sends in one |
|
402 | 74 |
line), this may be changed in future versions to a character offset, giving |
216 | 75 |
the position of the selector in the source. |
1 | 76 |
|
402 | 77 |
Restartable / Returnable contexts: |
78 |
||
79 |
In previous versions (up to ST/X 2.10.5), every method stored enough |
|
80 |
information in the context for that one to be restartable later (for example, |
|
81 |
via the debuggers restart button). With 2.10.6, this is now an stc-compiler |
|
82 |
option, and the system as delivered is compiled to only create restartable |
|
83 |
contexts for those which contain blocks. This resulted in an overall speedup of |
|
84 |
roughly 10-20% percent, depending on the type of CPU. However, it makes most |
|
85 |
methods non-restartable (however, abort, signal handling and unwind blocks work |
|
86 |
as usual). |
|
87 |
In practice, this was reported to be not a severe limitation and all users were happy |
|
88 |
to trade the increased performance for that slight inconvenience. |
|
89 |
(during development, this is seldom a problem, since interpreted methods are always |
|
90 |
returnable and restartable) |
|
91 |
If you do not like this (and you are a happy owner of the full distribution), you |
|
92 |
should recompile all classes with stc's '-optContext' flag. |
|
93 |
||
94 |
Resuming contexts: |
|
95 |
||
96 |
Strictly speaking, ST/X does not support a context to be resumed. However, |
|
97 |
it does support a forced return (i.e. non-local-return) from a context. |
|
98 |
Thus, resume of a context is implemented by forcing a return from the context |
|
99 |
which was created by the method called from the first one. The effect is the same. |
|
100 |
||
101 |
Returning from a dead method: |
|
102 |
||
103 |
Blocksreturn from an outlived context (i.e. its home method has already returned) |
|
104 |
is now rewarded by an invalidReturn exception - it used to be a noop in previous |
|
105 |
releases (The blue book described this to be a noop, but other smalltalk implementations |
|
106 |
changed this to be an invalid operation - good decision) |
|
107 |
||
108 |
||
1282 | 109 |
[instance variables:] |
110 |
flags <SmallInteger> used by the VM; never touch. |
|
111 |
contains info about number of args, |
|
112 |
locals and temporaries. |
|
216 | 113 |
|
1282 | 114 |
sender <Context> the 'calling / sending' context |
216 | 115 |
|
1282 | 116 |
home <Context> the context, where this block was |
117 |
created, or nil if its a method context |
|
118 |
There are also cheap blocks, which do |
|
119 |
not need a reference to the home context, |
|
120 |
for those, its nil too. |
|
216 | 121 |
|
1282 | 122 |
receiver <Object> the receiver of this message |
216 | 123 |
|
1282 | 124 |
selector <Symbol> the selector of this message |
216 | 125 |
|
1282 | 126 |
searchClass <Class> the class, where the message lookup started |
127 |
(for super sends) or nil, for regular sends. |
|
141 | 128 |
|
1282 | 129 |
lineNr <SmallInteger> the position where the context left off |
130 |
(kind of p-counter). Only the low 16bits |
|
131 |
are valid. |
|
141 | 132 |
|
1282 | 133 |
retValTemp nil temporary - always nil, when you see the context |
134 |
(used in the VM as temporary) |
|
216 | 135 |
|
1282 | 136 |
handle *noObject* used by the VM; not accessable, not an object |
141 | 137 |
|
1282 | 138 |
<indexed> arguments of the send followed by |
139 |
locals of the method/block followed by |
|
140 |
temporaries. |
|
1 | 141 |
|
1282 | 142 |
[class variables:] |
143 |
InvalidReturnSignal signal raised when a block tries |
|
144 |
to return ('^') from a method context |
|
145 |
which itself has already returned |
|
146 |
(i.e. there is no place to return to) |
|
216 | 147 |
|
69 | 148 |
WARNING: layout and size known by the compiler and runtime system - do not change. |
1282 | 149 |
|
1293 | 150 |
|
151 |
[author:] |
|
152 |
Claus Gittinger |
|
153 |
||
1282 | 154 |
[see also:] |
155 |
Block Process Method |
|
156 |
( contexts, stacks & unwinding : programming/contexts.html) |
|
54 | 157 |
" |
158 |
! ! |
|
1 | 159 |
|
1483 | 160 |
!Context class methodsFor:'initialization'! |
105 | 161 |
|
162 |
initialize |
|
163 |
InvalidReturnSignal isNil ifTrue:[ |
|
1334
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
164 |
InvalidReturnSignal := ErrorSignal newSignalMayProceed:true. |
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
165 |
InvalidReturnSignal nameClass:self message:#invalidReturnSignal. |
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
166 |
InvalidReturnSignal notifierString:'invalid return; method cannot return twice'. |
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
167 |
|
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
168 |
SingleStepInterruptRequest := QuerySignal new. |
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
169 |
SingleStepInterruptRequest nameClass:self message:#singleStepInterruptRequest. |
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
170 |
SingleStepInterruptRequest notifierString:'single step'. |
105 | 171 |
] |
1334
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
172 |
|
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
173 |
"Modified: 6.5.1996 / 16:46:03 / cg" |
105 | 174 |
! ! |
175 |
||
1483 | 176 |
!Context class methodsFor:'Signal constants'! |
105 | 177 |
|
178 |
invalidReturnSignal |
|
141 | 179 |
"return the signal used when a method is tried to be returned twice |
180 |
or, when some dead context is unwound or restarted." |
|
181 |
||
105 | 182 |
^ InvalidReturnSignal |
1334
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
183 |
! |
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
184 |
|
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
185 |
singleStepInterruptRequest |
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
186 |
"return the dummy query signal to ask for single stepping" |
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
187 |
|
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
188 |
^ SingleStepInterruptRequest |
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
189 |
|
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
190 |
"Created: 6.5.1996 / 16:46:32 / cg" |
105 | 191 |
! ! |
192 |
||
1483 | 193 |
!Context class methodsFor:'queries'! |
3 | 194 |
|
195 |
isBuiltInClass |
|
1264 | 196 |
"return true if this class is known by the run-time-system. |
197 |
Here, true is returned." |
|
3 | 198 |
|
199 |
^ true |
|
1264 | 200 |
|
201 |
"Modified: 23.4.1996 / 15:58:00 / cg" |
|
3 | 202 |
! ! |
203 |
||
623 | 204 |
!Context methodsFor:'accessing'! |
205 |
||
206 |
argAt:n |
|
207 |
"return the n'th argument" |
|
208 |
||
1726 | 209 |
n > self numArgs ifTrue:[ |
210 |
^ self error:'invalid arg access' |
|
211 |
]. |
|
623 | 212 |
^ self at:n |
1726 | 213 |
|
214 |
"Modified: 12.10.1996 / 21:44:28 / cg" |
|
623 | 215 |
! |
216 |
||
217 |
argAt:n put:value |
|
218 |
"set the n'th argument - useful when the receiver should be restarted" |
|
154 | 219 |
|
1726 | 220 |
n > self numArgs ifTrue:[ |
221 |
^ self error:'invalid arg access' |
|
222 |
]. |
|
623 | 223 |
^ self at:n put:value |
1726 | 224 |
|
225 |
"Modified: 12.10.1996 / 21:44:32 / cg" |
|
623 | 226 |
! |
227 |
||
228 |
args |
|
229 |
"return an array filled with the arguments of this context" |
|
230 |
||
231 |
|n| |
|
232 |
||
233 |
n := self numArgs. |
|
234 |
^ (Array new:n) replaceFrom:1 to:n with:self. |
|
235 |
! |
|
154 | 236 |
|
623 | 237 |
argsAndVars |
238 |
"return an array filled with the arguments and variables of this context" |
|
239 |
||
240 |
|n| |
|
241 |
||
242 |
n := self numArgs + self nvars. |
|
243 |
^ (Array new:n) replaceFrom:1 to:n with:self. |
|
244 |
! |
|
154 | 245 |
|
623 | 246 |
home |
247 |
"return the immediate home of the receiver. |
|
248 |
for block contexts, this is the methodcontext, where the block was created, |
|
249 |
for nested block contexts, its the surrounding blocks context. |
|
250 |
for method-contexts this is nil." |
|
25 | 251 |
|
623 | 252 |
^ nil "home" |
253 |
! |
|
1 | 254 |
|
255 |
instVarAt:index |
|
69 | 256 |
"have to catch instVar access to retVal and handle - they are invalid. |
257 |
Notice, that one of the next ST/X versions will get some syntactic |
|
258 |
extension to get this automatically)." |
|
1 | 259 |
|
260 |
(index == 8) ifTrue:[^ nil]. |
|
261 |
(index == 9) ifTrue:[^ nil]. |
|
262 |
^ super instVarAt:index |
|
263 |
! |
|
264 |
||
265 |
instVarAt:index put:value |
|
69 | 266 |
"have to catch instVar access to retVal and handle - they are invalid. |
267 |
Notice, that one of the next ST/X versions will get some syntactic |
|
268 |
extension to get this automatically)." |
|
1 | 269 |
|
270 |
(index == 8) ifTrue:[^ nil]. |
|
271 |
(index == 9) ifTrue:[^ nil]. |
|
272 |
^ super instVarAt:index put:value |
|
273 |
! |
|
274 |
||
623 | 275 |
lineNumber |
276 |
"this returns the lineNumber within the methods source, where the context was |
|
277 |
interrupted or called another method. (currently, sometimes this information |
|
278 |
is not available - in this case 0 is returned)" |
|
1 | 279 |
|
623 | 280 |
lineNr isNil ifTrue:[^ nil]. |
281 |
^ lineNr bitAnd:16rFFFF |
|
1 | 282 |
! |
283 |
||
284 |
method |
|
54 | 285 |
"return the method for which the receiver was created. |
286 |
To save time during normal execution, this information is not held in the |
|
287 |
context, but computed here on request." |
|
1 | 288 |
|
289 |
|c| |
|
290 |
||
325 | 291 |
c := self searchClass. |
292 |
" |
|
293 |
the below cannot happen in normal circumstances |
|
294 |
(added to avoid recursive errors in case of a broken sender chain) |
|
295 |
" |
|
296 |
c isBehavior ifFalse:[ |
|
297 |
'OOPS: non class in searchClass' errorPrintNL. |
|
298 |
' selector: ' errorPrint. selector errorPrint. |
|
299 |
' receiver: ' errorPrint. receiver errorPrintNL. |
|
300 |
^ nil |
|
301 |
]. |
|
302 |
||
328 | 303 |
c := c whichClassIncludesSelector:selector. |
1 | 304 |
c notNil ifTrue:[ |
154 | 305 |
^ c compiledMethodAt:selector |
1 | 306 |
]. |
216 | 307 |
|
308 |
"mhmh - seems to be a context for an unbound method; |
|
309 |
look in the senders context. Consider this a kludge. |
|
310 |
(maybe it was not too good of an idea to not keep the current |
|
325 | 311 |
method in the context .... |
312 |
future versions of ST/X's message lookup may store the method in |
|
313 |
the context.) |
|
216 | 314 |
" |
315 |
(sender notNil and:[sender selector startsWith:'valueWithReceiver:']) ifTrue:[ |
|
316 |
^ sender receiver |
|
317 |
]. |
|
318 |
||
1 | 319 |
^ nil |
320 |
! |
|
321 |
||
212 | 322 |
methodClass |
323 |
"return the class in which the method for which the receiver was created is." |
|
324 |
||
1456 | 325 |
|cls m| |
326 |
||
327 |
cls := self searchClass. |
|
328 |
[cls notNil] whileTrue:[ |
|
329 |
cls := cls whichClassIncludesSelector:selector. |
|
330 |
cls isNil ifTrue:[^ nil]. |
|
331 |
||
332 |
m := cls compiledMethodAt:selector. |
|
333 |
m notNil ifTrue:[ |
|
334 |
m isIgnored ifFalse:[^ cls]. |
|
335 |
]. |
|
336 |
cls := cls superclass |
|
337 |
]. |
|
338 |
^ cls |
|
339 |
||
340 |
"Modified: 10.6.1996 / 14:34:59 / cg" |
|
212 | 341 |
! |
342 |
||
623 | 343 |
methodHome |
344 |
"return the method-home - for method contexts this is the receiver" |
|
345 |
||
346 |
^ self |
|
347 |
! |
|
348 |
||
349 |
ntemp |
|
350 |
"return the number of temporary variables of the Block/Method. |
|
351 |
(for debugging only)" |
|
352 |
||
353 |
^ self size - self numArgs - self nvars |
|
354 |
! |
|
355 |
||
356 |
numArgs |
|
357 |
"return the number of arguments to the Block/Method" |
|
358 |
||
359 |
%{ /* NOCONTEXT */ |
|
360 |
||
1133 | 361 |
RETURN ( __MKSMALLINT( (__intVal(__INST(flags)) >> __NARG_SHIFT) & __NARG_MASK) ); |
623 | 362 |
%} |
363 |
! |
|
364 |
||
365 |
nvars |
|
366 |
"return the number of local variables of the Block/Method" |
|
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
367 |
|
623 | 368 |
%{ /* NOCONTEXT */ |
369 |
||
1133 | 370 |
RETURN ( __MKSMALLINT( (__intVal(__INST(flags)) >> __NVAR_SHIFT) & __NVAR_MASK) ); |
623 | 371 |
%} |
372 |
! |
|
373 |
||
374 |
receiver |
|
375 |
"return the receiver of the context" |
|
376 |
||
377 |
^ receiver |
|
378 |
! |
|
379 |
||
380 |
searchClass |
|
381 |
"this is the class where the method-lookup started; |
|
382 |
for normal sends, it is nil (or sometimes the receivers class). |
|
383 |
For supersends, its the superclass of the one, in which the |
|
384 |
caller was defined." |
|
385 |
||
386 |
searchClass notNil ifTrue:[^ searchClass]. |
|
387 |
^ receiver class |
|
388 |
! |
|
389 |
||
390 |
selector |
|
391 |
"return the selector of the method for which the context was created" |
|
392 |
||
393 |
^ selector |
|
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
394 |
! |
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
395 |
|
1 | 396 |
sender |
397 |
"return the sender of the context" |
|
398 |
||
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
399 |
%{ /* NOCONTEXT */ |
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
400 |
OBJ theContext; |
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
401 |
|
949 | 402 |
/* |
403 |
* this special nil test is for the very first context (startup-context); |
|
404 |
* actually, its cosmetics, to avoid a visible nil>>nil context in the debugger. |
|
405 |
*/ |
|
406 |
||
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
407 |
if (__isNonNilObject(theContext = __INST(sender))) { |
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
408 |
if (__isLazy(theContext)) { |
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
409 |
/* |
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
410 |
* this cannot happen |
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
411 |
*/ |
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
412 |
_PATCHUPCONTEXT(theContext); |
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
413 |
} |
591
11433f47b12b
added a method to print a contexts method
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
414 |
/* |
11433f47b12b
added a method to print a contexts method
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
415 |
* to be prepared for the worst situation |
11433f47b12b
added a method to print a contexts method
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
416 |
* (the sender is not stored, so the trap wont catch it) |
11433f47b12b
added a method to print a contexts method
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
417 |
* make the writeBarrier trigger manually. |
11433f47b12b
added a method to print a contexts method
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
418 |
* We'll see, if this is really required. |
11433f47b12b
added a method to print a contexts method
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
419 |
*/ |
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
420 |
theContext->o_space |= CATCHMARK; |
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
421 |
_markNonLIFO(theContext); |
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
422 |
} |
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
423 |
%}. |
1 | 424 |
^ sender |
425 |
! |
|
426 |
||
623 | 427 |
setLineNumber:aNumber |
428 |
"private entry for uncompiledCodeObject ..." |
|
1 | 429 |
|
623 | 430 |
lineNr := aNumber |
340 | 431 |
! |
432 |
||
202 | 433 |
temporaries |
434 |
"return an array filled with the temporaries of this context" |
|
435 |
||
308 | 436 |
|nonTemps mySize| |
202 | 437 |
|
438 |
nonTemps := self numArgs + self nvars. |
|
439 |
mySize := self ntemp. |
|
308 | 440 |
^ (Array new:mySize) replaceFrom:1 to:mySize with:self startingAt:nonTemps+1 |
202 | 441 |
! |
442 |
||
623 | 443 |
unsafeSender |
444 |
"temporary: for debugging only" |
|
10 | 445 |
|
623 | 446 |
^ sender |
10 | 447 |
! |
448 |
||
449 |
varAt:n |
|
450 |
"return the n'th local variable" |
|
451 |
||
154 | 452 |
^ self at:(n + self numArgs) |
10 | 453 |
! |
454 |
||
455 |
varAt:n put:value |
|
456 |
"set the n'th local variable - useful when the receiver should be restarted |
|
54 | 457 |
or continued" |
10 | 458 |
|
154 | 459 |
self at:(n + self numArgs) put:value |
10 | 460 |
! |
461 |
||
623 | 462 |
vars |
463 |
"return an array filled with the local variables of this context" |
|
375 | 464 |
|
623 | 465 |
|nonVars mySize| |
360 | 466 |
|
623 | 467 |
nonVars := self numArgs. |
468 |
mySize := self nvars. |
|
469 |
^ (Array new:mySize) replaceFrom:1 to:mySize with:self startingAt:nonVars+1 |
|
1 | 470 |
! ! |
471 |
||
623 | 472 |
!Context methodsFor:'copying'! |
415 | 473 |
|
623 | 474 |
deepCopy |
475 |
"raise an error - deepCopy is not allowed for contexts" |
|
37 | 476 |
|
623 | 477 |
^ self deepCopyError |
1 | 478 |
! ! |
479 |
||
77 | 480 |
!Context methodsFor:'error handling'! |
481 |
||
482 |
invalidReturn:returnValue |
|
483 |
"this message is sent by the VM, when a methods context |
|
484 |
which has already returned is about to return again. |
|
485 |
(i.e. about to execute a return from an already returned |
|
105 | 486 |
method in a block). |
141 | 487 |
We raise a signal here, to allow catching of that situation." |
77 | 488 |
|
406 | 489 |
" |
490 |
in previous versions of ST/X and ST-80, this was no error; |
|
491 |
(instead, a normal blockreturn was performed to the value-sender). |
|
492 |
From a note in comp.lang.smalltalk, I conclude that new ST-80 versions |
|
493 |
now raise an error if this happens. |
|
494 |
Comment out the raise below to get that (old) behavior |
|
495 |
BETTER REWRITE YOUR APPLICATION |
|
496 |
" |
|
282 | 497 |
"/ new behavior: |
498 |
||
406 | 499 |
^ InvalidReturnSignal |
500 |
raiseRequestWith:returnValue. |
|
282 | 501 |
|
502 |
"/ old behavior: |
|
406 | 503 |
"/ ^ returnValue |
504 |
! |
|
505 |
||
506 |
invalidReturnOrRestart:returnValue |
|
507 |
"this message is sent by the VM, when a methods context |
|
508 |
which was compiled non-returnable is about to return again. |
|
509 |
We raise a signal here, to allow catching of that situation." |
|
510 |
||
360 | 511 |
^ InvalidReturnSignal |
512 |
raiseRequestWith:returnValue |
|
513 |
errorString:'method was compiled non-resumable' |
|
514 |
! |
|
515 |
||
516 |
invalidReturnOrRestartError:how with:value |
|
517 |
"common error reporter for restart/return errors" |
|
518 |
||
519 |
self canReturn ifTrue:[ |
|
379 | 520 |
" |
521 |
tried to return from/restart a context which is already dead |
|
522 |
(i.e. the method/block has already executed a return) |
|
523 |
" |
|
524 |
^ InvalidReturnSignal |
|
360 | 525 |
raiseRequestWith:value |
526 |
errorString:(how , ': context not on calling chain') |
|
527 |
]. |
|
528 |
" |
|
529 |
tried to return from/restart a context of a method which was compiled |
|
530 |
unrestartable or of a block (which is never restartable) |
|
531 |
" |
|
532 |
^ InvalidReturnSignal |
|
379 | 533 |
raiseRequestWith:value |
360 | 534 |
errorString:(how , ': context cannot be restarted/returned from') |
77 | 535 |
! ! |
536 |
||
623 | 537 |
!Context methodsFor:'minidebugger printing'! |
538 |
||
539 |
fullPrint |
|
540 |
"print the receiver, selector and args of the context |
|
541 |
- used only for MiniDebuggers walkback print" |
|
542 |
||
543 |
self receiverPrintString print. ' ' print. selector print. |
|
544 |
self size ~~ 0 ifTrue: [ |
|
1426 | 545 |
' ' print. self argsDisplayString print |
623 | 546 |
]. |
1426 | 547 |
' [' print. self lineNumber print. ']' printCR |
623 | 548 |
|
549 |
" |
|
550 |
thisContext fullPrint |
|
551 |
" |
|
1426 | 552 |
|
553 |
"Modified: 20.5.1996 / 10:27:14 / cg" |
|
623 | 554 |
! |
555 |
||
556 |
fullPrintAll |
|
557 |
"print a full walkback starting at the receiver |
|
558 |
- used only for MiniDebuggers walkback print" |
|
559 |
||
560 |
|context| |
|
561 |
||
562 |
context := self. |
|
563 |
[context notNil] whileTrue: [ |
|
564 |
context fullPrint. |
|
565 |
context := context sender |
|
566 |
] |
|
567 |
||
568 |
" |
|
569 |
thisContext fullPrintAll |
|
570 |
" |
|
571 |
! ! |
|
572 |
||
1 | 573 |
!Context methodsFor:'non local control flow'! |
574 |
||
575 |
restart |
|
576 |
"restart the receiver - i.e. the method is evaluated again. |
|
402 | 577 |
if the context to restart already died, trigger an error. |
141 | 578 |
This is a low level helper for unwindAndRestart. |
579 |
||
580 |
NOTICE: |
|
154 | 581 |
NO unwind actions are performed - this is usually not |
582 |
what you want (see Context>>unwindAndRestart). |
|
141 | 583 |
|
584 |
LIMITATION: |
|
154 | 585 |
currently a context can only be restarted by |
928 | 586 |
the owning process - not from outside. |
587 |
Also, the compiler has an option (+optcontext) to create |
|
588 |
non-restartable contexts (which are faster). |
|
589 |
If such a context is restarted, a runtime error is raised." |
|
1 | 590 |
|
591 |
sender isNil ifTrue:[^ nil]. |
|
592 |
%{ |
|
141 | 593 |
__RESUMECONTEXT__(SND_COMMA self, RESTART_VALUE, 0); |
360 | 594 |
%}. |
69 | 595 |
" |
360 | 596 |
when we arrive here, something went wrong. |
69 | 597 |
debugging ... |
598 |
" |
|
360 | 599 |
^ self invalidReturnOrRestartError:#restart with:nil |
1 | 600 |
! |
601 |
||
623 | 602 |
resume |
603 |
"resume execution in this context. I.e. as if the method called |
|
604 |
last by the receiver did a ^ nil. |
|
605 |
If the context has already returned, report an error. |
|
606 |
||
607 |
NOTICE: |
|
608 |
NO unwind actions are performed (see Context>>unwind). |
|
609 |
||
610 |
LIMITATION: |
|
611 |
currently a context can only be resumed by |
|
928 | 612 |
the owning process - not from outside. |
613 |
Also, the compiler has an option (+optcontext) to create |
|
614 |
non-resumable contexts (which are faster). |
|
615 |
If such a context is restarted, a runtime error is raised." |
|
623 | 616 |
|
617 |
^ self resume:nil |
|
618 |
! |
|
619 |
||
620 |
resume:value |
|
621 |
"resume the receiver - as if it got 'value' from whatever |
|
622 |
it called. This continues execution in the receivers method |
|
623 |
after the point where it did its last send. |
|
624 |
If the context has already returned - report an error. |
|
625 |
||
626 |
NOTICE: |
|
627 |
NO unwind actions are performed (see Context>>unwind:). |
|
628 |
||
629 |
LIMITATION: |
|
630 |
currently a context can only be resumed by |
|
928 | 631 |
the owning process - not from outside. |
632 |
Also, the compiler has an option (+optcontext) to create |
|
633 |
non-resumable contexts (which are faster). |
|
634 |
If such a context is restarted, a runtime error is raised." |
|
623 | 635 |
|
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
636 |
|theContext| |
623 | 637 |
|
638 |
" |
|
639 |
starting with this context, find the one below (i.e. the one that I |
|
640 |
have called) and return from it. |
|
641 |
" |
|
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
642 |
theContext := thisContext. |
623 | 643 |
%{ |
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
644 |
while ((theContext != nil) && (__ContextInstPtr(theContext)->c_sender != self)) { |
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
645 |
theContext = __ContextInstPtr(theContext)->c_sender; |
623 | 646 |
} |
647 |
%}. |
|
648 |
||
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
649 |
theContext isNil ifTrue:[ |
623 | 650 |
" |
651 |
tried to resume in context which is already dead |
|
652 |
(i.e. the method/block has already executed a return) |
|
653 |
" |
|
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
654 |
^ theContext invalidReturnOrRestartError:#resume with:value |
623 | 655 |
]. |
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
656 |
^ theContext return:value |
623 | 657 |
! |
658 |
||
69 | 659 |
return |
141 | 660 |
"return from this context with nil. I.e. as if it did a ^ nil. |
661 |
NOTICE: |
|
154 | 662 |
NO unwind actions are performed - this is usually not |
663 |
what you want (See Context>>unwind). |
|
664 |
This is a low level method - a helper for unwind. |
|
1 | 665 |
|
141 | 666 |
LIMITATION: |
154 | 667 |
currently a context can only be returned by |
928 | 668 |
the owning process - not from outside. |
669 |
Also, the compiler has an option (+optcontext) to create |
|
670 |
non-returnable contexts (which are faster). |
|
671 |
If such a context is restarted, a runtime error is raised." |
|
141 | 672 |
|
673 |
^ self return:nil |
|
1 | 674 |
! |
675 |
||
69 | 676 |
return:value |
677 |
"return from this context as if it did a '^ value'. |
|
141 | 678 |
NOTICE: |
402 | 679 |
NO unwind actions are performed - this is usually not |
154 | 680 |
what you want (See Context>>unwind:). |
681 |
This is a low level method - a helper for unwind. |
|
141 | 682 |
|
683 |
LIMITATION: |
|
154 | 684 |
currently a context can only be returned by |
928 | 685 |
the owning process - not from outside. |
686 |
Also, the compiler has an option (+optcontext) to create |
|
687 |
non-returnable contexts (which are faster). |
|
688 |
If such a context is restarted, a runtime error is raised." |
|
1 | 689 |
|
690 |
sender isNil ifTrue:[^ nil]. |
|
691 |
%{ |
|
141 | 692 |
__RESUMECONTEXT__(SND_COMMA self, value, 0); |
1 | 693 |
|
360 | 694 |
%}. |
69 | 695 |
" |
360 | 696 |
when we arrive here, something went wrong. |
69 | 697 |
debugging ... |
698 |
" |
|
360 | 699 |
^ self invalidReturnOrRestartError:#return with:value |
1 | 700 |
! |
701 |
||
328 | 702 |
returnDoing:aBlock |
703 |
"return from this context as if it did a '^ aBlock value'. |
|
704 |
The block is evaluated as if called by the receiver context; |
|
705 |
NOT the true executing context. |
|
706 |
NOTICE: |
|
402 | 707 |
NO unwind actions are performed - this is usually not |
708 |
what you want (See Context>>unwindThenDo:). |
|
328 | 709 |
This is a low level method - a helper for unwind. |
710 |
||
711 |
LIMITATION: |
|
712 |
currently a context can only be returned by |
|
928 | 713 |
the owning process - not from outside. |
714 |
Also, the compiler has an option (+optcontext) to create |
|
715 |
non-returnable contexts (which are faster). |
|
716 |
If such a context is restarted, a runtime error is raised." |
|
328 | 717 |
|
718 |
sender isNil ifTrue:[^ nil]. |
|
719 |
%{ |
|
720 |
__RESUMECONTEXT__(SND_COMMA self, aBlock, 2); |
|
360 | 721 |
%}. |
328 | 722 |
" |
360 | 723 |
when we arrive here, something went wrong. |
328 | 724 |
debugging ... |
725 |
" |
|
360 | 726 |
^ self invalidReturnOrRestartError:#return with:aBlock |
328 | 727 |
! |
728 |
||
1 | 729 |
unwind |
69 | 730 |
"return nil from the receiver - i.e. simulate a '^ nil'. |
360 | 731 |
If the context has already retruned, report an error. |
1 | 732 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
69 | 733 |
and Block>>valueOnUnwindDo: on the way. |
1 | 734 |
|
141 | 735 |
LIMITATION: |
154 | 736 |
currently a context can only be unwound by |
928 | 737 |
the owning process - not from outside. |
738 |
Also, the compiler has an option (+optcontext) to create |
|
739 |
non-returnable contexts (which are faster). |
|
740 |
If such a context is restarted, a runtime error is raised." |
|
141 | 741 |
|
742 |
^ self unwind:nil |
|
1 | 743 |
! |
744 |
||
745 |
unwind:value |
|
69 | 746 |
"return value from the receiver - i.e. simulate a '^ value'. |
360 | 747 |
If the context has already returned , report an error. |
1 | 748 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
69 | 749 |
and Block>>valueOnUnwindDo: on the way. |
141 | 750 |
|
751 |
LIMITATION: |
|
154 | 752 |
currently a context can only be unwound by |
928 | 753 |
the owning process - not from outside. |
754 |
Also, the compiler has an option (+optcontext) to create |
|
755 |
non-returnable contexts (which are faster). |
|
756 |
If such a context is restarted, a runtime error is raised." |
|
1 | 757 |
|
559 | 758 |
|con unwindBlock| |
1 | 759 |
|
141 | 760 |
sender isNil ifTrue:[ |
154 | 761 |
" |
762 |
tried to return to a context which is already dead |
|
763 |
(i.e. the method/block has already executed a return) |
|
764 |
" |
|
379 | 765 |
^ self invalidReturnOrRestartError:#unwind with:value |
141 | 766 |
]. |
1 | 767 |
|
141 | 768 |
" |
769 |
start with this context, moving up, looking for unwind actions |
|
770 |
" |
|
1 | 771 |
con := thisContext. |
69 | 772 |
[con notNil and:[con ~~ self]] whileTrue:[ |
552
694ecccaa1a0
only evaluate unwind blocks once
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
773 |
con isUnwindContext ifTrue:[ |
559 | 774 |
"/ |
775 |
"/ mhmh - hardwired knowledge about those methods (taking the 1st arg) |
|
776 |
"/ |
|
552
694ecccaa1a0
only evaluate unwind blocks once
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
777 |
unwindBlock := con argAt:1. |
694ecccaa1a0
only evaluate unwind blocks once
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
778 |
con unmarkForUnwind. |
694ecccaa1a0
only evaluate unwind blocks once
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
779 |
unwindBlock value |
154 | 780 |
]. |
781 |
con := con sender |
|
1 | 782 |
]. |
69 | 783 |
|
141 | 784 |
"oops, I am not on the calling chain |
785 |
(should we check for this situation first and NOT evaluate |
|
786 |
the unwind actions in this case ?) |
|
787 |
" |
|
69 | 788 |
con isNil ifTrue:[ |
154 | 789 |
" |
790 |
tried to return to a context which is already dead |
|
791 |
(i.e. the method/block has already executed a return) |
|
792 |
" |
|
379 | 793 |
^ self invalidReturnOrRestartError:#unwind with:value |
69 | 794 |
]. |
141 | 795 |
" |
796 |
now, that all unwind-actions are done, I can use the |
|
797 |
low-level return ... |
|
798 |
" |
|
799 |
^ self return:value |
|
800 |
! |
|
801 |
||
802 |
unwindAndRestart |
|
803 |
"restart the receiver - i.e. the method is evaluated again. |
|
402 | 804 |
if the context to restart already died report an error. |
141 | 805 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
806 |
and Block>>valueOnUnwindDo: before restarting. |
|
807 |
||
808 |
LIMITATION: |
|
154 | 809 |
currently a context can only be restarted by |
928 | 810 |
the owning process - not from outside. |
811 |
Also, the compiler has an option (+optcontext) to create |
|
812 |
non-restartable contexts (which are faster). |
|
813 |
If such a context is restarted, a runtime error is raised." |
|
141 | 814 |
|
559 | 815 |
|con unwindBlock| |
141 | 816 |
|
817 |
" |
|
818 |
start with this context, moving up, looking for unwind actions |
|
819 |
" |
|
820 |
con := thisContext. |
|
821 |
[con notNil and:[con ~~ self]] whileTrue:[ |
|
552
694ecccaa1a0
only evaluate unwind blocks once
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
822 |
con isUnwindContext ifTrue:[ |
559 | 823 |
"/ |
824 |
"/ mhmh - hardwired knowledge about those methods (taking the 1st arg) |
|
825 |
"/ |
|
552
694ecccaa1a0
only evaluate unwind blocks once
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
826 |
unwindBlock := con argAt:1. |
694ecccaa1a0
only evaluate unwind blocks once
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
827 |
con unmarkForUnwind. |
694ecccaa1a0
only evaluate unwind blocks once
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
828 |
unwindBlock value |
154 | 829 |
]. |
552
694ecccaa1a0
only evaluate unwind blocks once
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
830 |
|
154 | 831 |
con := con sender |
141 | 832 |
]. |
833 |
||
834 |
"oops, I am not on the calling chain |
|
835 |
(should we check for this situation first and NOT evaluate |
|
836 |
the unwind actions in this case ?) |
|
837 |
" |
|
838 |
con isNil ifTrue:[ |
|
154 | 839 |
" |
840 |
tried to return to a context which is already dead |
|
841 |
(i.e. the method/block has already executed a return) |
|
842 |
" |
|
379 | 843 |
^ self invalidReturnOrRestartError:#unwindAndRestart with:nil |
141 | 844 |
]. |
845 |
" |
|
846 |
now, that all unwind-actions are done, I can use the |
|
847 |
low-level restart ... |
|
848 |
" |
|
849 |
^ self restart |
|
328 | 850 |
! |
851 |
||
852 |
unwindThenDo:aBlock |
|
853 |
"return the value of aBlock from the receiver - i.e. simulate a '^ aBlock value'. |
|
360 | 854 |
If the context has already returned , report an error. |
328 | 855 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
856 |
and Block>>valueOnUnwindDo: on the way. |
|
857 |
The block is evaluated AFTER all unwind actions are performed |
|
858 |
(i.e. the blocks sender will be the receiving context, not the |
|
402 | 859 |
currently executing context) |
328 | 860 |
|
861 |
LIMITATION: |
|
862 |
currently a context can only be unwound by |
|
928 | 863 |
the owning process - not from outside. |
864 |
Also, the compiler has an option (+optcontext) to create |
|
865 |
non-returnable contexts (which are faster). |
|
866 |
If such a context is restarted, a runtime error is raised." |
|
328 | 867 |
|
559 | 868 |
|con unwindBlock| |
328 | 869 |
|
870 |
sender isNil ifTrue:[ |
|
871 |
" |
|
872 |
tried to return to a context which is already dead |
|
873 |
(i.e. the method/block has already executed a return) |
|
874 |
" |
|
379 | 875 |
^ self invalidReturnOrRestartError:#unwind with:aBlock |
328 | 876 |
]. |
877 |
||
878 |
" |
|
879 |
start with this context, moving up, looking for unwind actions |
|
880 |
" |
|
881 |
con := thisContext. |
|
882 |
[con notNil and:[con ~~ self]] whileTrue:[ |
|
552
694ecccaa1a0
only evaluate unwind blocks once
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
883 |
con isUnwindContext ifTrue:[ |
559 | 884 |
"/ |
885 |
"/ mhmh - hardwired knowledge about those methods (taking the 1st arg) |
|
886 |
"/ |
|
552
694ecccaa1a0
only evaluate unwind blocks once
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
887 |
unwindBlock := con argAt:1. |
694ecccaa1a0
only evaluate unwind blocks once
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
888 |
con unmarkForUnwind. |
694ecccaa1a0
only evaluate unwind blocks once
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
889 |
unwindBlock value |
328 | 890 |
]. |
891 |
con := con sender |
|
892 |
]. |
|
893 |
||
894 |
"oops, I am not on the calling chain |
|
895 |
(should we check for this situation first and NOT evaluate |
|
896 |
the unwind actions in this case ?) |
|
897 |
" |
|
898 |
con isNil ifTrue:[ |
|
899 |
" |
|
900 |
tried to return to a context which is already dead |
|
901 |
(i.e. the method/block has already executed a return) |
|
902 |
" |
|
379 | 903 |
^ self invalidReturnOrRestartError:#unwind with:aBlock |
328 | 904 |
]. |
905 |
" |
|
906 |
now, that all unwind-actions are done, I can use the |
|
907 |
low-level return ... |
|
908 |
" |
|
909 |
^ self returnDoing:aBlock |
|
1 | 910 |
! ! |
623 | 911 |
|
912 |
!Context methodsFor:'printing & storing'! |
|
913 |
||
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
914 |
argStringFor:someObject |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
915 |
|
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
916 |
|name| |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
917 |
%{ |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
918 |
/* |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
919 |
* special handling for (invalid) free objects. |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
920 |
* these only appear if some primitiveCode does not correctly use SEND macros, |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
921 |
* which may lead to sends to free objects. In normal operation, this 'cannot' happen. |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
922 |
*/ |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
923 |
if (__isNonNilObject(someObject) && (__qClass(someObject)==nil)) { |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
924 |
name = __MKSTRING("FreeObject"); |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
925 |
} |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
926 |
%}. |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
927 |
name notNil ifTrue:[^ name]. |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
928 |
^ someObject displayString |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
929 |
! |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
930 |
|
623 | 931 |
argsDisplayString |
932 |
|fullString n "{ Class: SmallInteger }" | |
|
933 |
||
934 |
fullString := ''. |
|
935 |
n := self numArgs. |
|
936 |
1 to:n do:[:index | |
|
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
937 |
fullString := fullString , ' ' , (self argStringFor:(self at:index)) |
623 | 938 |
]. |
939 |
^ fullString |
|
940 |
! |
|
941 |
||
942 |
displayString |
|
943 |
"return a string describing the context - for display in Inspector" |
|
944 |
||
945 |
^ self class name , '(' , self printString , ')' |
|
946 |
! |
|
947 |
||
948 |
fullPrintString |
|
949 |
"return a string describing the context - this includes the linenumber, |
|
950 |
receiver printString and argument printString" |
|
951 |
||
952 |
|s| |
|
953 |
||
954 |
s := WriteStream on:String new. |
|
955 |
s nextPutAll:self receiverPrintString; space; nextPutAll:selector. |
|
956 |
self size ~~ 0 ifTrue: [ |
|
957 |
s space. |
|
958 |
s nextPutAll:self argsDisplayString |
|
959 |
]. |
|
960 |
s nextPutAll:' ['; nextPutAll:self lineNumber printString; nextPutAll:']' . |
|
961 |
^ s contents |
|
962 |
||
963 |
" |
|
964 |
thisContext fullPrintString |
|
965 |
" |
|
966 |
! |
|
967 |
||
968 |
methodPrintString |
|
969 |
"return a string describing the contexts method as 'implementorClass>>selector'" |
|
970 |
||
971 |
|mthd w| |
|
972 |
||
973 |
mthd := self method. |
|
974 |
mthd notNil ifTrue:[ |
|
975 |
w := mthd who. |
|
976 |
w notNil ifTrue:[ |
|
977 |
^ (w at:1) name , '>>' , (w at:2) |
|
978 |
] |
|
979 |
]. |
|
980 |
^ mthd displayString. |
|
981 |
||
982 |
" |
|
983 |
thisContext methodPrintString |
|
984 |
thisContext sender methodPrintString |
|
985 |
" |
|
986 |
! |
|
987 |
||
988 |
printOn:aStream |
|
989 |
"append a printed description of the receiver onto aStream" |
|
990 |
||
991 |
aStream nextPutAll:(self receiverPrintString). |
|
992 |
aStream space. |
|
993 |
self selector printOn:aStream |
|
994 |
! |
|
995 |
||
996 |
printString |
|
997 |
"return a string describing the context" |
|
998 |
||
999 |
^ self receiverPrintString , ' ' , self selector printString |
|
1000 |
! |
|
1001 |
||
1002 |
receiverPrintString |
|
1003 |
"return a string describing the receiver of the context" |
|
1004 |
||
1005 |
|receiverClass receiverClassName newString implementorClass| |
|
1006 |
||
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1007 |
%{ |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1008 |
/* |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1009 |
* special handling for (invalid) free objects. |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1010 |
* these only appear if some primitiveCode does not correctly use SEND macros, |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1011 |
* which may lead to sends to free objects. In normal operation, this 'cannot' happen. |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1012 |
*/ |
1133 | 1013 |
if (__isNonNilObject(__INST(receiver)) && (__qClass(__INST(receiver))==nil)) { |
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1014 |
receiverClassName = __MKSTRING("FreeObject"); |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1015 |
} |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1016 |
%}. |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1017 |
receiverClassName notNil ifTrue:[^ receiverClassName]. |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1018 |
|
623 | 1019 |
receiverClass := receiver class. |
1020 |
receiverClassName := receiverClass name. |
|
1021 |
(receiverClass == SmallInteger) ifTrue:[ |
|
1022 |
newString := '(' , receiver printString , ') ' , receiverClassName |
|
1023 |
] ifFalse:[ |
|
1024 |
newString := receiverClassName |
|
1025 |
]. |
|
1026 |
||
1027 |
selector notNil ifTrue:[ |
|
1028 |
"/ implementorClass := self searchClass whichClassIncludesSelector:selector. |
|
1029 |
||
1030 |
" |
|
1031 |
kludge to avoid slow search for containing class |
|
1032 |
" |
|
1033 |
selector ~~ #doIt ifTrue:[ |
|
1034 |
implementorClass := self methodClass. |
|
1035 |
]. |
|
1036 |
implementorClass notNil ifTrue: [ |
|
1037 |
(implementorClass ~~ receiverClass) ifTrue: [ |
|
1038 |
newString := newString , '>>>', |
|
1039 |
implementorClass name printString |
|
1040 |
] |
|
1041 |
] ifFalse:[ |
|
1042 |
self searchClass ~~ receiverClass ifTrue:[ |
|
1043 |
newString := newString , '>>>' , self searchClass name |
|
1044 |
]. |
|
1045 |
" |
|
1046 |
kludge for doIt - these unbound methods are not |
|
1047 |
found in the classes methodDictionary |
|
1048 |
" |
|
1049 |
selector ~~ #doIt ifTrue:[ |
|
1050 |
newString := newString , '>>>**NONE**' |
|
1051 |
] |
|
1052 |
] |
|
1053 |
]. |
|
1054 |
||
1055 |
^ newString |
|
1056 |
! ! |
|
1057 |
||
1058 |
!Context methodsFor:'private accessing'! |
|
1059 |
||
753
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1060 |
markForInterrupt |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1061 |
"set the interrupt flag. |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1062 |
The VM needs this to know that some special action is to be performed with |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1063 |
this context upon return - a highly internal mechanism and not for public use." |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1064 |
|
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1065 |
%{ /* NOCONTEXT */ |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1066 |
__markInterrupted(__ContextInstPtr(self)); |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1067 |
%} |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1068 |
! |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1069 |
|
1727 | 1070 |
markForInterruptOnUnwind |
1071 |
"set the interrupt-on-unwind flag in the receiver. |
|
1072 |
The VM will generate a stepInterrupt, when this context returns or |
|
1073 |
is unwound. This is used by the debugger for faster single-stepping; |
|
1074 |
- a highly internal mechanism and not for public use." |
|
1075 |
||
1076 |
%{ /* NOCONTEXT */ |
|
1077 |
__INST(flags) = (OBJ)((INT)__INST(flags) |
|
1078 |
| __MASKSMALLINT(__IRQ_ON_UNWIND)); |
|
1079 |
%} |
|
1080 |
! |
|
1081 |
||
623 | 1082 |
markForUnwind |
749 | 1083 |
"set the mark for unwind flag in the receiver. |
1084 |
The VM needs this to know that some special action is to be performed with |
|
1085 |
this context - a highly internal mechanism and not for public use." |
|
1086 |
||
623 | 1087 |
%{ /* NOCONTEXT */ |
1133 | 1088 |
__INST(flags) = (OBJ)((INT)__INST(flags) | __MASKSMALLINT(__UNWIND_MARK)); |
623 | 1089 |
%} |
749 | 1090 |
|
1091 |
"Modified: 13.12.1995 / 19:05:22 / cg" |
|
623 | 1092 |
! |
1093 |
||
1094 |
unmarkForUnwind |
|
749 | 1095 |
"clear the mark for unwind flag in the receiver. |
1096 |
The VM needs this to know that some special action is to be performed with |
|
1097 |
this context - a highly internal mechanism and not for public use." |
|
1098 |
||
623 | 1099 |
%{ /* NOCONTEXT */ |
1133 | 1100 |
__INST(flags) = (OBJ)((INT)__INST(flags) & ~__MASKSMALLINT(__UNWIND_MARK)); |
623 | 1101 |
%} |
1102 |
! ! |
|
1103 |
||
1051 | 1104 |
!Context methodsFor:'special accessing'! |
1105 |
||
1106 |
canReturn |
|
1107 |
"return true, if the receiver allows returning through it. |
|
1108 |
For normal method contexts, this returns true; |
|
1109 |
for blocks, it (currently) always returns false. |
|
1110 |
||
1111 |
However, the system can be compiled (for production code), to create |
|
1112 |
contexts which cannot be returned or restarted |
|
1113 |
(except, if the method contains a returning block). |
|
1114 |
This saves some administrative work in every method |
|
1115 |
invocation and makes overall execution faster. However, it limits |
|
1116 |
the debugger, in that it cannot return from or restart those contexts. |
|
1117 |
(unwinding and termination is not affected by this optimization) |
|
1118 |
Currently, the system as delivered has this optimization disabled." |
|
1119 |
||
1120 |
%{ /* NOCONTEXT */ |
|
1121 |
||
1133 | 1122 |
RETURN ( (__intVal(__INST(flags)) & __CANNOT_RETURN) ? false : true ); |
1051 | 1123 |
%} |
1124 |
! |
|
1125 |
||
1492 | 1126 |
hasStackToShow |
1127 |
^ false |
|
1128 |
||
1129 |
"Created: 28.6.1996 / 14:48:39 / cg" |
|
1130 |
! |
|
1131 |
||
1051 | 1132 |
isNonLifo |
1133 |
"return true, if this is a nonLifo context" |
|
1134 |
||
1135 |
%{ /* NOCONTEXT */ |
|
1133 | 1136 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__NONLIFO)) ? true : false ); |
1051 | 1137 |
%} |
1138 |
! |
|
1139 |
||
1140 |
isOnMachineStack |
|
1141 |
"return true, if this is a machine stack context as opposed to a |
|
1142 |
real heap context" |
|
1143 |
||
1144 |
%{ /* NOCONTEXT */ |
|
1145 |
RETURN ( (__qSpace(self) >= STACKSPACE) ? true : false ); |
|
1146 |
%} |
|
1147 |
! |
|
1148 |
||
1149 |
isSpecial |
|
1150 |
"return true, if this is either a nonLifo or interrupted context" |
|
1151 |
||
1152 |
%{ /* NOCONTEXT */ |
|
1133 | 1153 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__SPECIAL)) ? true : false ); |
1051 | 1154 |
%} |
1155 |
! |
|
1156 |
||
1157 |
isUnwindContext |
|
1158 |
"return true, if this is an unwindContext" |
|
1159 |
||
1160 |
%{ /* NOCONTEXT */ |
|
1133 | 1161 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__UNWIND_MARK)) ? true : false ); |
1051 | 1162 |
%} |
1163 |
! ! |
|
1164 |
||
623 | 1165 |
!Context methodsFor:'testing'! |
1166 |
||
1167 |
isBlockContext |
|
1168 |
"return true, iff the receiver is a BlockContext, false otherwise" |
|
1169 |
||
1170 |
^ false |
|
1171 |
! |
|
1172 |
||
1173 |
isContext |
|
1174 |
"return true, iff the receiver is a Context, false otherwise" |
|
1175 |
||
1176 |
^ true |
|
1177 |
! |
|
1178 |
||
1179 |
isRecursive |
|
1180 |
"return true, if this context is one of a recursive send of the same |
|
1483 | 1181 |
selector to the same receiver before. |
1182 |
Here, different arguments are ignored - i.e. only the same method |
|
1183 |
counts for recursiveness. |
|
623 | 1184 |
Used to detect recursive errors or recursive printing - for example." |
1185 |
||
1186 |
|c rec "numArgs" "{Class: SmallInteger }"| |
|
1187 |
||
1188 |
rec := 0. |
|
1189 |
c := self sender. |
|
1190 |
[c notNil] whileTrue:[ |
|
1483 | 1191 |
((c selector == selector) |
1192 |
and:[(c receiver == receiver)]) ifTrue:[ |
|
1193 |
" |
|
1194 |
stupid: the current ST/X context does not include |
|
1195 |
the method, but the class, in which the search started ... |
|
1196 |
" |
|
623 | 1197 |
"/ (c searchClass whichClassIncludesSelector:selector) == (self searchClass whichClassIncludesSelector:selector) ifTrue:[ |
1483 | 1198 |
c methodClass == self methodClass ifTrue:[ |
623 | 1199 |
"/ " |
1200 |
"/ finally, look for different arguments |
|
1201 |
"/ " |
|
1202 |
"/ numArgs := self numArgs. |
|
1203 |
"/ 1 to:numArgs do:[:argIndex | |
|
1204 |
"/ (self argAt:argIndex) == (c argAt:argIndex) ifFalse:[^ false] |
|
1205 |
"/ ]. |
|
1483 | 1206 |
^ true |
1207 |
] |
|
1208 |
]. |
|
1209 |
c := c sender. |
|
1210 |
" |
|
1211 |
this special test was added to get out after a while |
|
1212 |
if the sender chain is corrupt - this gives us at least |
|
1213 |
a chance to find those errors. |
|
1214 |
" |
|
1215 |
rec := rec + 1. |
|
1216 |
rec >= 100000 ifTrue:[ |
|
1217 |
'bad context chain' errorPrintNL. |
|
1218 |
^ true |
|
1219 |
] |
|
623 | 1220 |
]. |
1221 |
^ false |
|
1483 | 1222 |
|
1223 |
"Modified: 22.6.1996 / 16:31:12 / cg" |
|
623 | 1224 |
! ! |
1225 |
||
1483 | 1226 |
!Context class methodsFor:'documentation'! |
749 | 1227 |
|
1228 |
version |
|
1727 | 1229 |
^ '$Header: /cvs/stx/stx/libbasic/Context.st,v 1.65 1996-10-14 10:11:45 cg Exp $' |
749 | 1230 |
! ! |
623 | 1231 |
Context initialize! |