author | Claus Gittinger <cg@exept.de> |
Mon, 03 Nov 1997 16:35:38 +0100 | |
changeset 3095 | cdb753308f6e |
parent 2893 | 8ba406da6b22 |
child 3130 | 6cef19640207 |
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 |
|
2646 | 14 |
instanceVariableNames:'flags sender* home receiver selector searchClass lineNr |
15 |
retvalTemp 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 |
||
1810 | 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 |
|
1810 | 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 |
||
1810 | 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 |
||
1810 | 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 |
||
1810 | 242 |
n := self numArgs + self numVars. |
623 | 243 |
^ (Array new:n) replaceFrom:1 to:n with:self. |
1810 | 244 |
|
245 |
"Modified: 23.10.1996 / 16:19:41 / cg" |
|
623 | 246 |
! |
154 | 247 |
|
623 | 248 |
home |
249 |
"return the immediate home of the receiver. |
|
250 |
for block contexts, this is the methodcontext, where the block was created, |
|
251 |
for nested block contexts, its the surrounding blocks context. |
|
252 |
for method-contexts this is nil." |
|
25 | 253 |
|
623 | 254 |
^ nil "home" |
255 |
! |
|
1 | 256 |
|
257 |
instVarAt:index |
|
69 | 258 |
"have to catch instVar access to retVal and handle - they are invalid. |
259 |
Notice, that one of the next ST/X versions will get some syntactic |
|
260 |
extension to get this automatically)." |
|
1 | 261 |
|
262 |
(index == 8) ifTrue:[^ nil]. |
|
263 |
(index == 9) ifTrue:[^ nil]. |
|
264 |
^ super instVarAt:index |
|
265 |
! |
|
266 |
||
267 |
instVarAt:index put:value |
|
69 | 268 |
"have to catch instVar access to retVal and handle - they are invalid. |
269 |
Notice, that one of the next ST/X versions will get some syntactic |
|
270 |
extension to get this automatically)." |
|
1 | 271 |
|
272 |
(index == 8) ifTrue:[^ nil]. |
|
273 |
(index == 9) ifTrue:[^ nil]. |
|
274 |
^ super instVarAt:index put:value |
|
275 |
! |
|
276 |
||
623 | 277 |
lineNumber |
278 |
"this returns the lineNumber within the methods source, where the context was |
|
279 |
interrupted or called another method. (currently, sometimes this information |
|
280 |
is not available - in this case 0 is returned)" |
|
1 | 281 |
|
623 | 282 |
lineNr isNil ifTrue:[^ nil]. |
283 |
^ lineNr bitAnd:16rFFFF |
|
1 | 284 |
! |
285 |
||
286 |
method |
|
54 | 287 |
"return the method for which the receiver was created. |
288 |
To save time during normal execution, this information is not held in the |
|
289 |
context, but computed here on request." |
|
1 | 290 |
|
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
291 |
|c sender| |
1 | 292 |
|
325 | 293 |
c := self searchClass. |
294 |
" |
|
295 |
the below cannot happen in normal circumstances |
|
296 |
(added to avoid recursive errors in case of a broken sender chain) |
|
297 |
" |
|
298 |
c isBehavior ifFalse:[ |
|
2135
6bd144c1c358
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1853
diff
changeset
|
299 |
'Context [error]: non class in searchClass' errorPrintCR. |
6bd144c1c358
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1853
diff
changeset
|
300 |
' selector: ' errorPrint. selector errorPrint. |
6bd144c1c358
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1853
diff
changeset
|
301 |
' receiver: ' errorPrint. receiver errorPrintCR. |
6bd144c1c358
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1853
diff
changeset
|
302 |
^ nil |
325 | 303 |
]. |
304 |
||
328 | 305 |
c := c whichClassIncludesSelector:selector. |
1 | 306 |
c notNil ifTrue:[ |
2135
6bd144c1c358
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1853
diff
changeset
|
307 |
^ c compiledMethodAt:selector |
1 | 308 |
]. |
216 | 309 |
|
310 |
"mhmh - seems to be a context for an unbound method; |
|
311 |
look in the senders context. Consider this a kludge. |
|
312 |
(maybe it was not too good of an idea to not keep the current |
|
325 | 313 |
method in the context .... |
314 |
future versions of ST/X's message lookup may store the method in |
|
315 |
the context.) |
|
216 | 316 |
" |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
317 |
sender := self sender. |
216 | 318 |
(sender notNil and:[sender selector startsWith:'valueWithReceiver:']) ifTrue:[ |
2135
6bd144c1c358
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1853
diff
changeset
|
319 |
^ sender receiver |
216 | 320 |
]. |
321 |
||
1 | 322 |
^ nil |
2135
6bd144c1c358
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1853
diff
changeset
|
323 |
|
6bd144c1c358
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1853
diff
changeset
|
324 |
"Modified: 10.1.1997 / 17:34:48 / cg" |
1 | 325 |
! |
326 |
||
212 | 327 |
methodClass |
328 |
"return the class in which the method for which the receiver was created is." |
|
329 |
||
1456 | 330 |
|cls m| |
331 |
||
332 |
cls := self searchClass. |
|
333 |
[cls notNil] whileTrue:[ |
|
334 |
cls := cls whichClassIncludesSelector:selector. |
|
335 |
cls isNil ifTrue:[^ nil]. |
|
336 |
||
337 |
m := cls compiledMethodAt:selector. |
|
338 |
m notNil ifTrue:[ |
|
339 |
m isIgnored ifFalse:[^ cls]. |
|
340 |
]. |
|
341 |
cls := cls superclass |
|
342 |
]. |
|
343 |
^ cls |
|
344 |
||
345 |
"Modified: 10.6.1996 / 14:34:59 / cg" |
|
212 | 346 |
! |
347 |
||
623 | 348 |
methodHome |
349 |
"return the method-home - for method contexts this is the receiver" |
|
350 |
||
351 |
^ self |
|
352 |
! |
|
353 |
||
354 |
ntemp |
|
355 |
"return the number of temporary variables of the Block/Method. |
|
1810 | 356 |
(for debugging only). |
357 |
I dont like the name of this method; its here for compatibility." |
|
623 | 358 |
|
1810 | 359 |
^ self numTemps |
360 |
||
361 |
"Modified: 23.10.1996 / 16:19:06 / cg" |
|
623 | 362 |
! |
363 |
||
364 |
numArgs |
|
365 |
"return the number of arguments to the Block/Method" |
|
366 |
||
367 |
%{ /* NOCONTEXT */ |
|
368 |
||
1133 | 369 |
RETURN ( __MKSMALLINT( (__intVal(__INST(flags)) >> __NARG_SHIFT) & __NARG_MASK) ); |
623 | 370 |
%} |
371 |
! |
|
372 |
||
1810 | 373 |
numTemps |
374 |
"return the number of temporary variables of the Block/Method. |
|
375 |
(for debugging only)" |
|
376 |
||
377 |
^ self size - self numArgs - self numVars |
|
378 |
||
379 |
"Created: 23.10.1996 / 16:19:10 / cg" |
|
380 |
"Modified: 23.10.1996 / 16:19:48 / cg" |
|
381 |
! |
|
382 |
||
383 |
numVars |
|
623 | 384 |
"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
|
385 |
|
623 | 386 |
%{ /* NOCONTEXT */ |
387 |
||
1133 | 388 |
RETURN ( __MKSMALLINT( (__intVal(__INST(flags)) >> __NVAR_SHIFT) & __NVAR_MASK) ); |
623 | 389 |
%} |
390 |
! |
|
391 |
||
1810 | 392 |
nvars |
393 |
"return the number of local variables of the Block/Method. |
|
394 |
I dont like the name of this method; its here for compatibility." |
|
395 |
||
396 |
^ self numVars |
|
397 |
||
398 |
"Modified: 23.10.1996 / 16:18:44 / cg" |
|
399 |
! |
|
400 |
||
623 | 401 |
receiver |
402 |
"return the receiver of the context" |
|
403 |
||
404 |
^ receiver |
|
405 |
! |
|
406 |
||
407 |
searchClass |
|
408 |
"this is the class where the method-lookup started; |
|
409 |
for normal sends, it is nil (or sometimes the receivers class). |
|
410 |
For supersends, its the superclass of the one, in which the |
|
411 |
caller was defined." |
|
412 |
||
413 |
searchClass notNil ifTrue:[^ searchClass]. |
|
414 |
^ receiver class |
|
415 |
! |
|
416 |
||
417 |
selector |
|
418 |
"return the selector of the method for which the context was created" |
|
419 |
||
420 |
^ selector |
|
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
421 |
! |
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
422 |
|
1 | 423 |
sender |
424 |
"return the sender of the context" |
|
425 |
||
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
426 |
%{ /* NOCONTEXT */ |
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
427 |
OBJ theContext; |
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
428 |
|
949 | 429 |
/* |
430 |
* this special nil test is for the very first context (startup-context); |
|
431 |
* actually, its cosmetics, to avoid a visible nil>>nil context in the debugger. |
|
432 |
*/ |
|
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
433 |
theContext = __INST(sender_); |
2205 | 434 |
if (__isNonNilObject(theContext)) { |
949 | 435 |
|
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
436 |
if (__isLazy(theContext)) { |
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
437 |
/* |
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
438 |
* this cannot happen |
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
439 |
*/ |
2212 | 440 |
__PATCHUPCONTEXT(theContext); |
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
441 |
} |
591
11433f47b12b
added a method to print a contexts method
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
442 |
/* |
11433f47b12b
added a method to print a contexts method
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
443 |
* 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
|
444 |
* (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
|
445 |
* make the writeBarrier trigger manually. |
11433f47b12b
added a method to print a contexts method
Claus Gittinger <cg@exept.de>
parents:
564
diff
changeset
|
446 |
* 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
|
447 |
*/ |
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
448 |
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
|
449 |
_markNonLIFO(theContext); |
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
450 |
} |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
451 |
RETURN (theContext); |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
452 |
%} |
1 | 453 |
! |
454 |
||
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
455 |
senderIsNil |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
456 |
"return true, if I have no sender" |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
457 |
|
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
458 |
%{ /* NOCONTEXT */ |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
459 |
if ( __INST(sender_) == nil ) { |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
460 |
RETURN (true); |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
461 |
} |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
462 |
RETURN (false); |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
463 |
%} |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
464 |
! |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
465 |
|
623 | 466 |
setLineNumber:aNumber |
467 |
"private entry for uncompiledCodeObject ..." |
|
1 | 468 |
|
623 | 469 |
lineNr := aNumber |
340 | 470 |
! |
471 |
||
202 | 472 |
temporaries |
473 |
"return an array filled with the temporaries of this context" |
|
474 |
||
308 | 475 |
|nonTemps mySize| |
202 | 476 |
|
1810 | 477 |
nonTemps := self numArgs + self numVars. |
478 |
mySize := self numTemps. |
|
308 | 479 |
^ (Array new:mySize) replaceFrom:1 to:mySize with:self startingAt:nonTemps+1 |
1810 | 480 |
|
481 |
"Modified: 23.10.1996 / 16:20:00 / cg" |
|
202 | 482 |
! |
483 |
||
10 | 484 |
varAt:n |
485 |
"return the n'th local variable" |
|
486 |
||
154 | 487 |
^ self at:(n + self numArgs) |
10 | 488 |
! |
489 |
||
490 |
varAt:n put:value |
|
491 |
"set the n'th local variable - useful when the receiver should be restarted |
|
54 | 492 |
or continued" |
10 | 493 |
|
154 | 494 |
self at:(n + self numArgs) put:value |
10 | 495 |
! |
496 |
||
623 | 497 |
vars |
498 |
"return an array filled with the local variables of this context" |
|
375 | 499 |
|
623 | 500 |
|nonVars mySize| |
360 | 501 |
|
623 | 502 |
nonVars := self numArgs. |
1810 | 503 |
mySize := self numVars. |
623 | 504 |
^ (Array new:mySize) replaceFrom:1 to:mySize with:self startingAt:nonVars+1 |
1810 | 505 |
|
506 |
"Modified: 23.10.1996 / 16:20:06 / cg" |
|
1 | 507 |
! ! |
508 |
||
623 | 509 |
!Context methodsFor:'copying'! |
415 | 510 |
|
623 | 511 |
deepCopy |
512 |
"raise an error - deepCopy is not allowed for contexts" |
|
37 | 513 |
|
623 | 514 |
^ self deepCopyError |
1 | 515 |
! ! |
516 |
||
77 | 517 |
!Context methodsFor:'error handling'! |
518 |
||
519 |
invalidReturn:returnValue |
|
520 |
"this message is sent by the VM, when a methods context |
|
521 |
which has already returned is about to return again. |
|
522 |
(i.e. about to execute a return from an already returned |
|
105 | 523 |
method in a block). |
141 | 524 |
We raise a signal here, to allow catching of that situation." |
77 | 525 |
|
406 | 526 |
" |
527 |
in previous versions of ST/X and ST-80, this was no error; |
|
528 |
(instead, a normal blockreturn was performed to the value-sender). |
|
529 |
From a note in comp.lang.smalltalk, I conclude that new ST-80 versions |
|
530 |
now raise an error if this happens. |
|
531 |
Comment out the raise below to get that (old) behavior |
|
532 |
BETTER REWRITE YOUR APPLICATION |
|
533 |
" |
|
282 | 534 |
"/ new behavior: |
535 |
||
406 | 536 |
^ InvalidReturnSignal |
537 |
raiseRequestWith:returnValue. |
|
282 | 538 |
|
539 |
"/ old behavior: |
|
406 | 540 |
"/ ^ returnValue |
541 |
! |
|
542 |
||
543 |
invalidReturnOrRestart:returnValue |
|
544 |
"this message is sent by the VM, when a methods context |
|
545 |
which was compiled non-returnable is about to return again. |
|
546 |
We raise a signal here, to allow catching of that situation." |
|
547 |
||
360 | 548 |
^ InvalidReturnSignal |
549 |
raiseRequestWith:returnValue |
|
550 |
errorString:'method was compiled non-resumable' |
|
551 |
! |
|
552 |
||
553 |
invalidReturnOrRestartError:how with:value |
|
554 |
"common error reporter for restart/return errors" |
|
555 |
||
556 |
self canReturn ifTrue:[ |
|
379 | 557 |
" |
558 |
tried to return from/restart a context which is already dead |
|
559 |
(i.e. the method/block has already executed a return) |
|
560 |
" |
|
561 |
^ InvalidReturnSignal |
|
360 | 562 |
raiseRequestWith:value |
563 |
errorString:(how , ': context not on calling chain') |
|
564 |
]. |
|
565 |
" |
|
566 |
tried to return from/restart a context of a method which was compiled |
|
567 |
unrestartable or of a block (which is never restartable) |
|
568 |
" |
|
569 |
^ InvalidReturnSignal |
|
379 | 570 |
raiseRequestWith:value |
360 | 571 |
errorString:(how , ': context cannot be restarted/returned from') |
77 | 572 |
! ! |
573 |
||
2205 | 574 |
!Context methodsFor:'exception support'! |
575 |
||
2893 | 576 |
findNextContextWithSelector:selector1 or:selector2 or:selector3 |
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
577 |
"walk along the sender chain (starting with the sender), |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
578 |
for a context with either one of the given selectors. |
2205 | 579 |
This non-standard interface is only to be used by exception" |
580 |
||
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
581 |
"/ this could have been (actually: was) implemented as: |
2205 | 582 |
"/ |
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
583 |
"/ |con| |
2205 | 584 |
"/ |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
585 |
"/ con := self sender. |
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
586 |
"/ [con notNil] whileTrue:[ |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
587 |
"/ con selector == aSelector ifTrue:[^ con]. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
588 |
"/ con := con sender. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
589 |
"/ ]. |
2205 | 590 |
"/ ^ nil |
591 |
"/ |
|
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
592 |
"/ and the code below does exactly this (somewhat faster, though). |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
593 |
"/ |
2285 | 594 |
"/ (it avoids referencing all intermediate contexts, which would mark them special, |
595 |
"/ although they aren't really - this is expert knowledge, no need to understand that ...) |
|
2205 | 596 |
|
597 |
%{ /* NOCONTEXT */ |
|
598 |
||
599 |
OBJ theContext; |
|
600 |
OBJ sel; |
|
2255
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
601 |
OBJ __FETCHSELECTOR(); |
2205 | 602 |
|
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
603 |
theContext = __INST(sender_); |
2205 | 604 |
while (__isNonNilObject(theContext)) { |
605 |
if (__isLazy(theContext)) { |
|
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
606 |
#ifdef TRADITIONAL_STACK_FRAME |
2255
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
607 |
sel = __FETCHSELECTOR(theContext); |
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
608 |
#else |
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
609 |
/* mhmh - not really needed */ |
2212 | 610 |
__PATCHUPCONTEXT(theContext); |
2255
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
611 |
sel = __ContextInstPtr(theContext)->c_selector; |
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
612 |
#endif |
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
613 |
} else { |
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
614 |
sel = __ContextInstPtr(theContext)->c_selector; |
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
615 |
} |
2205 | 616 |
|
617 |
if ((sel == selector1) |
|
2893 | 618 |
|| ((selector2 != nil) && (sel == selector2)) |
619 |
|| ((selector3 != nil) && (sel == selector3))) { |
|
2255
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
620 |
if (__isLazy(theContext)) { |
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
621 |
__PATCHUPCONTEXT(theContext); |
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
622 |
} |
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
623 |
|
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
624 |
if (! __isNonLIFO(theContext)) { |
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
625 |
/* |
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
626 |
* to be prepared for the worst situation |
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
627 |
* (the sender is not stored, so the trap wont catch it) |
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
628 |
* make the writeBarrier trigger manually. |
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
629 |
* We'll see, if this is really required. |
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
630 |
*/ |
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
631 |
theContext->o_space |= CATCHMARK; |
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
632 |
_markNonLIFO(theContext); |
0e4c8d88a65d
can search for a context, without PATCHING them all
Claus Gittinger <cg@exept.de>
parents:
2212
diff
changeset
|
633 |
} |
2205 | 634 |
RETURN (theContext); |
635 |
} |
|
636 |
theContext = __ContextInstPtr(theContext)->c_sender; |
|
637 |
} |
|
638 |
%}. |
|
639 |
^ nil |
|
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
640 |
! |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
641 |
|
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
642 |
findNextUnwindContextOr:aContext |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
643 |
"walk along the sender chain (starting at the sender), |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
644 |
for a context marked for unwindAction or aContext. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
645 |
This non-standard interface is only to be used by mySelf" |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
646 |
|
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
647 |
"/ this could have been (actually: was) implemented as: |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
648 |
"/ |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
649 |
"/ |con| |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
650 |
"/ |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
651 |
"/ con := self sender. |
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
652 |
"/ [con notNil |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
653 |
"/ and:[con ~~ aContext |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
654 |
"/ and:[con isUnwindContext not]]] whileTrue:[con := con sender]. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
655 |
"/ ^ con |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
656 |
"/ |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
657 |
"/ and the code below does exactly this (somewhat faster, though). |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
658 |
"/ (it avoids referencing all intermediate contexts, which would mark them special, |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
659 |
"/ although they aren't really - this is expert knowledge, no need to understand that ...) |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
660 |
|
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
661 |
%{ /* NOCONTEXT */ |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
662 |
|
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
663 |
OBJ theContext; |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
664 |
|
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
665 |
if (self == aContext) { |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
666 |
RETURN (self); |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
667 |
} |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
668 |
|
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
669 |
theContext = __INST(sender_); |
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
670 |
while (__isNonNilObject(theContext)) { |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
671 |
if ((theContext == aContext) |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
672 |
|| ((INT)(__ContextInstPtr(theContext)->c_flags) & __MASKSMALLINT(__UNWIND_MARK))) { |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
673 |
if (__isLazy(theContext)) { |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
674 |
__PATCHUPCONTEXT(theContext); |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
675 |
} |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
676 |
if (! __isNonLIFO(theContext)) { |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
677 |
/* |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
678 |
* to be prepared for the worst situation |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
679 |
* (the sender is not stored, so the trap wont catch it) |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
680 |
* make the writeBarrier trigger manually. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
681 |
* We'll see, if this is really required. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
682 |
*/ |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
683 |
theContext->o_space |= CATCHMARK; |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
684 |
_markNonLIFO(theContext); |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
685 |
} |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
686 |
RETURN (theContext); |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
687 |
} |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
688 |
theContext = __ContextInstPtr(theContext)->c_sender; |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
689 |
} |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
690 |
%}. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
691 |
^ nil |
2205 | 692 |
! ! |
693 |
||
623 | 694 |
!Context methodsFor:'minidebugger printing'! |
695 |
||
696 |
fullPrint |
|
697 |
"print the receiver, selector and args of the context |
|
698 |
- used only for MiniDebuggers walkback print" |
|
699 |
||
700 |
self receiverPrintString print. ' ' print. selector print. |
|
701 |
self size ~~ 0 ifTrue: [ |
|
1426 | 702 |
' ' print. self argsDisplayString print |
623 | 703 |
]. |
1426 | 704 |
' [' print. self lineNumber print. ']' printCR |
623 | 705 |
|
706 |
" |
|
707 |
thisContext fullPrint |
|
708 |
" |
|
1426 | 709 |
|
710 |
"Modified: 20.5.1996 / 10:27:14 / cg" |
|
623 | 711 |
! |
712 |
||
713 |
fullPrintAll |
|
714 |
"print a full walkback starting at the receiver |
|
715 |
- used only for MiniDebuggers walkback print" |
|
716 |
||
717 |
|context| |
|
718 |
||
719 |
context := self. |
|
720 |
[context notNil] whileTrue: [ |
|
721 |
context fullPrint. |
|
722 |
context := context sender |
|
723 |
] |
|
724 |
||
725 |
" |
|
726 |
thisContext fullPrintAll |
|
727 |
" |
|
2173 | 728 |
! |
729 |
||
730 |
fullPrintAllOn:aStream |
|
731 |
"print a full walkback starting at the receiver |
|
732 |
- used only for MiniDebuggers walkback print" |
|
733 |
||
734 |
|context| |
|
735 |
||
736 |
context := self. |
|
737 |
[context notNil] whileTrue: [ |
|
738 |
context fullPrintOn:aStream. |
|
739 |
context := context sender |
|
740 |
] |
|
741 |
||
742 |
" |
|
743 |
thisContext fullPrintAllOn:Transcript |
|
744 |
" |
|
745 |
||
746 |
"Created: 15.1.1997 / 18:09:05 / cg" |
|
747 |
! |
|
748 |
||
749 |
fullPrintOn:aStream |
|
750 |
"print the receiver, selector and args of the context |
|
751 |
- used only for MiniDebuggers walkback print" |
|
752 |
||
753 |
self receiverPrintString printOn:aStream. ' ' printOn:aStream. selector printOn:aStream. |
|
754 |
self size ~~ 0 ifTrue: [ |
|
755 |
' ' printOn:aStream. self argsDisplayString printOn:aStream |
|
756 |
]. |
|
757 |
' [' printOn:aStream. self lineNumber printOn:aStream. ']' printOn:aStream. |
|
758 |
aStream cr |
|
759 |
||
760 |
" |
|
761 |
thisContext fullPrintOn:Transcript |
|
762 |
" |
|
763 |
||
764 |
"Modified: 20.5.1996 / 10:27:14 / cg" |
|
765 |
"Created: 15.1.1997 / 18:09:06 / cg" |
|
623 | 766 |
! ! |
767 |
||
1 | 768 |
!Context methodsFor:'non local control flow'! |
769 |
||
770 |
restart |
|
771 |
"restart the receiver - i.e. the method is evaluated again. |
|
402 | 772 |
if the context to restart already died, trigger an error. |
141 | 773 |
This is a low level helper for unwindAndRestart. |
774 |
||
775 |
NOTICE: |
|
154 | 776 |
NO unwind actions are performed - this is usually not |
777 |
what you want (see Context>>unwindAndRestart). |
|
141 | 778 |
|
779 |
LIMITATION: |
|
154 | 780 |
currently a context can only be restarted by |
928 | 781 |
the owning process - not from outside. |
782 |
Also, the compiler has an option (+optcontext) to create |
|
783 |
non-restartable contexts (which are faster). |
|
784 |
If such a context is restarted, a runtime error is raised." |
|
1 | 785 |
|
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
786 |
%{ /* NOCONTEXT */ |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
787 |
if (__INST(sender_) != nil) { |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
788 |
__RESUMECONTEXT__(self, RESTART_VALUE, 0); |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
789 |
} |
360 | 790 |
%}. |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
791 |
self sender isNil ifTrue:[^ nil]. |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
792 |
|
69 | 793 |
" |
360 | 794 |
when we arrive here, something went wrong. |
69 | 795 |
debugging ... |
796 |
" |
|
360 | 797 |
^ self invalidReturnOrRestartError:#restart with:nil |
1 | 798 |
! |
799 |
||
623 | 800 |
resume |
801 |
"resume execution in this context. I.e. as if the method called |
|
802 |
last by the receiver did a ^ nil. |
|
803 |
If the context has already returned, report an error. |
|
804 |
||
805 |
NOTICE: |
|
806 |
NO unwind actions are performed (see Context>>unwind). |
|
807 |
||
808 |
LIMITATION: |
|
809 |
currently a context can only be resumed by |
|
928 | 810 |
the owning process - not from outside. |
811 |
Also, the compiler has an option (+optcontext) to create |
|
812 |
non-resumable contexts (which are faster). |
|
813 |
If such a context is restarted, a runtime error is raised." |
|
623 | 814 |
|
815 |
^ self resume:nil |
|
816 |
! |
|
817 |
||
818 |
resume:value |
|
819 |
"resume the receiver - as if it got 'value' from whatever |
|
820 |
it called. This continues execution in the receivers method |
|
821 |
after the point where it did its last send. |
|
822 |
If the context has already returned - report an error. |
|
823 |
||
824 |
NOTICE: |
|
825 |
NO unwind actions are performed (see Context>>unwind:). |
|
826 |
||
827 |
LIMITATION: |
|
828 |
currently a context can only be resumed by |
|
928 | 829 |
the owning process - not from outside. |
830 |
Also, the compiler has an option (+optcontext) to create |
|
831 |
non-resumable contexts (which are faster). |
|
832 |
If such a context is restarted, a runtime error is raised." |
|
623 | 833 |
|
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
834 |
|theContext| |
623 | 835 |
|
836 |
" |
|
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
837 |
starting with this context, find the one below |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
838 |
(i.e. the one that I have called) and return from it. |
623 | 839 |
" |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
840 |
|
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
841 |
%{ |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
842 |
theContext = __thisContext; |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
843 |
while ((theContext != nil) |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
844 |
&& (__ContextInstPtr(theContext)->c_sender != self)) { |
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
845 |
theContext = __ContextInstPtr(theContext)->c_sender; |
623 | 846 |
} |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
847 |
if (theContext) { |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
848 |
if (__isLazy(theContext)) { |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
849 |
__PATCHUPCONTEXT(theContext); |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
850 |
} |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
851 |
} |
623 | 852 |
%}. |
853 |
||
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
854 |
theContext isNil ifTrue:[ |
623 | 855 |
" |
856 |
tried to resume in context which is already dead |
|
857 |
(i.e. the method/block has already executed a return) |
|
858 |
" |
|
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
859 |
^ theContext invalidReturnOrRestartError:#resume with:value |
623 | 860 |
]. |
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
861 |
^ theContext return:value |
623 | 862 |
! |
863 |
||
69 | 864 |
return |
141 | 865 |
"return from this context with nil. I.e. as if it did a ^ nil. |
866 |
NOTICE: |
|
154 | 867 |
NO unwind actions are performed - this is usually not |
868 |
what you want (See Context>>unwind). |
|
869 |
This is a low level method - a helper for unwind. |
|
1 | 870 |
|
141 | 871 |
LIMITATION: |
154 | 872 |
currently a context can only be returned by |
928 | 873 |
the owning process - not from outside. |
874 |
Also, the compiler has an option (+optcontext) to create |
|
875 |
non-returnable contexts (which are faster). |
|
876 |
If such a context is restarted, a runtime error is raised." |
|
141 | 877 |
|
878 |
^ self return:nil |
|
1 | 879 |
! |
880 |
||
69 | 881 |
return:value |
882 |
"return from this context as if it did a '^ value'. |
|
141 | 883 |
NOTICE: |
402 | 884 |
NO unwind actions are performed - this is usually not |
154 | 885 |
what you want (See Context>>unwind:). |
886 |
This is a low level method - a helper for unwind. |
|
141 | 887 |
|
888 |
LIMITATION: |
|
154 | 889 |
currently a context can only be returned by |
928 | 890 |
the owning process - not from outside. |
891 |
Also, the compiler has an option (+optcontext) to create |
|
892 |
non-returnable contexts (which are faster). |
|
893 |
If such a context is restarted, a runtime error is raised." |
|
1 | 894 |
|
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
895 |
%{ /* NOCONTEXT */ |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
896 |
if (__INST(sender_) != nil) { |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
897 |
__RESUMECONTEXT__(self, value, 0); |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
898 |
} |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
899 |
%}. |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
900 |
self sender isNil ifTrue:[^ nil]. |
1 | 901 |
|
69 | 902 |
" |
360 | 903 |
when we arrive here, something went wrong. |
69 | 904 |
debugging ... |
905 |
" |
|
360 | 906 |
^ self invalidReturnOrRestartError:#return with:value |
1 | 907 |
! |
908 |
||
328 | 909 |
returnDoing:aBlock |
910 |
"return from this context as if it did a '^ aBlock value'. |
|
911 |
The block is evaluated as if called by the receiver context; |
|
912 |
NOT the true executing context. |
|
913 |
NOTICE: |
|
402 | 914 |
NO unwind actions are performed - this is usually not |
915 |
what you want (See Context>>unwindThenDo:). |
|
328 | 916 |
This is a low level method - a helper for unwind. |
917 |
||
918 |
LIMITATION: |
|
919 |
currently a context can only be returned by |
|
928 | 920 |
the owning process - not from outside. |
921 |
Also, the compiler has an option (+optcontext) to create |
|
922 |
non-returnable contexts (which are faster). |
|
923 |
If such a context is restarted, a runtime error is raised." |
|
328 | 924 |
|
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
925 |
%{ /* NOCONTEXT */ |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
926 |
if (__INST(sender_) != nil) { |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
927 |
__RESUMECONTEXT__(self, aBlock, 2); |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
928 |
} |
360 | 929 |
%}. |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
930 |
self sender isNil ifTrue:[^ nil]. |
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
931 |
|
328 | 932 |
" |
360 | 933 |
when we arrive here, something went wrong. |
328 | 934 |
debugging ... |
935 |
" |
|
360 | 936 |
^ self invalidReturnOrRestartError:#return with:aBlock |
328 | 937 |
! |
938 |
||
1 | 939 |
unwind |
69 | 940 |
"return nil from the receiver - i.e. simulate a '^ nil'. |
360 | 941 |
If the context has already retruned, report an error. |
1 | 942 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
69 | 943 |
and Block>>valueOnUnwindDo: on the way. |
1 | 944 |
|
141 | 945 |
LIMITATION: |
154 | 946 |
currently a context can only be unwound by |
928 | 947 |
the owning process - not from outside. |
948 |
Also, the compiler has an option (+optcontext) to create |
|
949 |
non-returnable contexts (which are faster). |
|
950 |
If such a context is restarted, a runtime error is raised." |
|
141 | 951 |
|
952 |
^ self unwind:nil |
|
1 | 953 |
! |
954 |
||
955 |
unwind:value |
|
69 | 956 |
"return value from the receiver - i.e. simulate a '^ value'. |
360 | 957 |
If the context has already returned , report an error. |
1 | 958 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
69 | 959 |
and Block>>valueOnUnwindDo: on the way. |
141 | 960 |
|
961 |
LIMITATION: |
|
154 | 962 |
currently a context can only be unwound by |
928 | 963 |
the owning process - not from outside. |
964 |
Also, the compiler has an option (+optcontext) to create |
|
965 |
non-returnable contexts (which are faster). |
|
966 |
If such a context is restarted, a runtime error is raised." |
|
1 | 967 |
|
559 | 968 |
|con unwindBlock| |
1 | 969 |
|
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
970 |
self senderIsNil ifTrue:[ |
154 | 971 |
" |
972 |
tried to return to a context which is already dead |
|
973 |
(i.e. the method/block has already executed a return) |
|
974 |
" |
|
379 | 975 |
^ self invalidReturnOrRestartError:#unwind with:value |
141 | 976 |
]. |
1 | 977 |
|
141 | 978 |
" |
979 |
start with this context, moving up, looking for unwind actions |
|
980 |
" |
|
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
981 |
con := thisContext findNextUnwindContextOr:self. |
69 | 982 |
[con notNil and:[con ~~ self]] whileTrue:[ |
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
983 |
"/ |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
984 |
"/ mhmh - hardwired knowledge about those methods (taking the 1st arg) |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
985 |
"/ |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
986 |
unwindBlock := con argAt:1. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
987 |
con unmarkForUnwind. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
988 |
unwindBlock value. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
989 |
|
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
990 |
con := con findNextUnwindContextOr:self. |
1 | 991 |
]. |
69 | 992 |
|
141 | 993 |
"oops, I am not on the calling chain |
994 |
(should we check for this situation first and NOT evaluate |
|
995 |
the unwind actions in this case ?) |
|
996 |
" |
|
69 | 997 |
con isNil ifTrue:[ |
154 | 998 |
" |
999 |
tried to return to a context which is already dead |
|
1000 |
(i.e. the method/block has already executed a return) |
|
1001 |
" |
|
379 | 1002 |
^ self invalidReturnOrRestartError:#unwind with:value |
69 | 1003 |
]. |
141 | 1004 |
" |
1005 |
now, that all unwind-actions are done, I can use the |
|
1006 |
low-level return ... |
|
1007 |
" |
|
1008 |
^ self return:value |
|
1009 |
! |
|
1010 |
||
1011 |
unwindAndRestart |
|
1012 |
"restart the receiver - i.e. the method is evaluated again. |
|
402 | 1013 |
if the context to restart already died report an error. |
141 | 1014 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
1015 |
and Block>>valueOnUnwindDo: before restarting. |
|
1016 |
||
1017 |
LIMITATION: |
|
154 | 1018 |
currently a context can only be restarted by |
928 | 1019 |
the owning process - not from outside. |
1020 |
Also, the compiler has an option (+optcontext) to create |
|
1021 |
non-restartable contexts (which are faster). |
|
1022 |
If such a context is restarted, a runtime error is raised." |
|
141 | 1023 |
|
559 | 1024 |
|con unwindBlock| |
141 | 1025 |
|
1026 |
" |
|
1027 |
start with this context, moving up, looking for unwind actions |
|
1028 |
" |
|
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1029 |
con := thisContext findNextUnwindContextOr:self. |
141 | 1030 |
[con notNil and:[con ~~ self]] whileTrue:[ |
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1031 |
"/ |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1032 |
"/ mhmh - hardwired knowledge about those methods (taking the 1st arg) |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1033 |
"/ |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1034 |
unwindBlock := con argAt:1. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1035 |
con unmarkForUnwind. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1036 |
unwindBlock value. |
552
694ecccaa1a0
only evaluate unwind blocks once
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1037 |
|
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1038 |
con := con findNextUnwindContextOr:self. |
141 | 1039 |
]. |
1040 |
||
1041 |
"oops, I am not on the calling chain |
|
1042 |
(should we check for this situation first and NOT evaluate |
|
1043 |
the unwind actions in this case ?) |
|
1044 |
" |
|
1045 |
con isNil ifTrue:[ |
|
154 | 1046 |
" |
1047 |
tried to return to a context which is already dead |
|
1048 |
(i.e. the method/block has already executed a return) |
|
1049 |
" |
|
379 | 1050 |
^ self invalidReturnOrRestartError:#unwindAndRestart with:nil |
141 | 1051 |
]. |
1052 |
" |
|
1053 |
now, that all unwind-actions are done, I can use the |
|
1054 |
low-level restart ... |
|
1055 |
" |
|
1056 |
^ self restart |
|
328 | 1057 |
! |
1058 |
||
1059 |
unwindThenDo:aBlock |
|
1060 |
"return the value of aBlock from the receiver - i.e. simulate a '^ aBlock value'. |
|
360 | 1061 |
If the context has already returned , report an error. |
328 | 1062 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
1063 |
and Block>>valueOnUnwindDo: on the way. |
|
1064 |
The block is evaluated AFTER all unwind actions are performed |
|
1065 |
(i.e. the blocks sender will be the receiving context, not the |
|
402 | 1066 |
currently executing context) |
328 | 1067 |
|
1068 |
LIMITATION: |
|
1069 |
currently a context can only be unwound by |
|
928 | 1070 |
the owning process - not from outside. |
1071 |
Also, the compiler has an option (+optcontext) to create |
|
1072 |
non-returnable contexts (which are faster). |
|
1073 |
If such a context is restarted, a runtime error is raised." |
|
328 | 1074 |
|
559 | 1075 |
|con unwindBlock| |
328 | 1076 |
|
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
1077 |
self senderIsNil ifTrue:[ |
328 | 1078 |
" |
1079 |
tried to return to a context which is already dead |
|
1080 |
(i.e. the method/block has already executed a return) |
|
1081 |
" |
|
379 | 1082 |
^ self invalidReturnOrRestartError:#unwind with:aBlock |
328 | 1083 |
]. |
1084 |
||
1085 |
" |
|
1086 |
start with this context, moving up, looking for unwind actions |
|
1087 |
" |
|
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1088 |
con := thisContext findNextUnwindContextOr:self. |
328 | 1089 |
[con notNil and:[con ~~ self]] whileTrue:[ |
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1090 |
"/ |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1091 |
"/ mhmh - hardwired knowledge about those methods (taking the 1st arg) |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1092 |
"/ |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1093 |
unwindBlock := con argAt:1. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1094 |
con unmarkForUnwind. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1095 |
unwindBlock value. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1096 |
|
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1097 |
con := con findNextUnwindContextOr:self. |
328 | 1098 |
]. |
1099 |
||
1100 |
"oops, I am not on the calling chain |
|
1101 |
(should we check for this situation first and NOT evaluate |
|
1102 |
the unwind actions in this case ?) |
|
1103 |
" |
|
1104 |
con isNil ifTrue:[ |
|
1105 |
" |
|
1106 |
tried to return to a context which is already dead |
|
1107 |
(i.e. the method/block has already executed a return) |
|
1108 |
" |
|
379 | 1109 |
^ self invalidReturnOrRestartError:#unwind with:aBlock |
328 | 1110 |
]. |
1111 |
" |
|
1112 |
now, that all unwind-actions are done, I can use the |
|
1113 |
low-level return ... |
|
1114 |
" |
|
1115 |
^ self returnDoing:aBlock |
|
1 | 1116 |
! ! |
623 | 1117 |
|
1118 |
!Context methodsFor:'printing & storing'! |
|
1119 |
||
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1120 |
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
|
1121 |
|
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1122 |
|name| |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1123 |
%{ |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1124 |
/* |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1125 |
* 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
|
1126 |
* 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
|
1127 |
* 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
|
1128 |
*/ |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1129 |
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
|
1130 |
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
|
1131 |
} |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1132 |
%}. |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1133 |
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
|
1134 |
^ 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
|
1135 |
! |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1136 |
|
623 | 1137 |
argsDisplayString |
1138 |
|fullString n "{ Class: SmallInteger }" | |
|
1139 |
||
1140 |
fullString := ''. |
|
1141 |
n := self numArgs. |
|
1142 |
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
|
1143 |
fullString := fullString , ' ' , (self argStringFor:(self at:index)) |
623 | 1144 |
]. |
1145 |
^ fullString |
|
1146 |
! |
|
1147 |
||
1148 |
displayString |
|
1149 |
"return a string describing the context - for display in Inspector" |
|
1150 |
||
1151 |
^ self class name , '(' , self printString , ')' |
|
1152 |
! |
|
1153 |
||
1154 |
fullPrintString |
|
1155 |
"return a string describing the context - this includes the linenumber, |
|
1156 |
receiver printString and argument printString" |
|
1157 |
||
1158 |
|s| |
|
1159 |
||
1160 |
s := WriteStream on:String new. |
|
1161 |
s nextPutAll:self receiverPrintString; space; nextPutAll:selector. |
|
1162 |
self size ~~ 0 ifTrue: [ |
|
1163 |
s space. |
|
1164 |
s nextPutAll:self argsDisplayString |
|
1165 |
]. |
|
1166 |
s nextPutAll:' ['; nextPutAll:self lineNumber printString; nextPutAll:']' . |
|
1167 |
^ s contents |
|
1168 |
||
1169 |
" |
|
1170 |
thisContext fullPrintString |
|
1171 |
" |
|
1172 |
! |
|
1173 |
||
1174 |
methodPrintString |
|
1175 |
"return a string describing the contexts method as 'implementorClass>>selector'" |
|
1176 |
||
1853
09cd1e8df9a2
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1810
diff
changeset
|
1177 |
|mthd who| |
623 | 1178 |
|
1179 |
mthd := self method. |
|
1180 |
mthd notNil ifTrue:[ |
|
1853
09cd1e8df9a2
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1810
diff
changeset
|
1181 |
who := mthd who. |
09cd1e8df9a2
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1810
diff
changeset
|
1182 |
who notNil ifTrue:[ |
09cd1e8df9a2
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1810
diff
changeset
|
1183 |
^ who methodClass name , '>>' , who methodSelector |
09cd1e8df9a2
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1810
diff
changeset
|
1184 |
] |
623 | 1185 |
]. |
1186 |
^ mthd displayString. |
|
1187 |
||
1188 |
" |
|
1189 |
thisContext methodPrintString |
|
1190 |
thisContext sender methodPrintString |
|
1191 |
" |
|
1853
09cd1e8df9a2
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1810
diff
changeset
|
1192 |
|
09cd1e8df9a2
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1810
diff
changeset
|
1193 |
"Modified: 1.11.1996 / 16:21:49 / cg" |
623 | 1194 |
! |
1195 |
||
1196 |
printOn:aStream |
|
1197 |
"append a printed description of the receiver onto aStream" |
|
1198 |
||
1199 |
aStream nextPutAll:(self receiverPrintString). |
|
1200 |
aStream space. |
|
1201 |
self selector printOn:aStream |
|
1202 |
! |
|
1203 |
||
1204 |
printString |
|
1205 |
"return a string describing the context" |
|
1206 |
||
1207 |
^ self receiverPrintString , ' ' , self selector printString |
|
1208 |
! |
|
1209 |
||
1210 |
receiverPrintString |
|
1211 |
"return a string describing the receiver of the context" |
|
1212 |
||
1213 |
|receiverClass receiverClassName newString implementorClass| |
|
1214 |
||
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1215 |
%{ |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1216 |
/* |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1217 |
* 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
|
1218 |
* 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
|
1219 |
* 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
|
1220 |
*/ |
1133 | 1221 |
if (__isNonNilObject(__INST(receiver)) && (__qClass(__INST(receiver))==nil)) { |
2157
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1222 |
receiverClassName = __MKSTRING("FreeObject"); |
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1223 |
} |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1224 |
%}. |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1225 |
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
|
1226 |
|
623 | 1227 |
receiverClass := receiver class. |
1228 |
receiverClassName := receiverClass name. |
|
1229 |
(receiverClass == SmallInteger) ifTrue:[ |
|
2157
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1230 |
newString := '(' , receiver printString , ') ' , receiverClassName |
623 | 1231 |
] ifFalse:[ |
2157
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1232 |
newString := receiverClassName |
623 | 1233 |
]. |
1234 |
||
1235 |
selector notNil ifTrue:[ |
|
1236 |
"/ implementorClass := self searchClass whichClassIncludesSelector:selector. |
|
1237 |
||
2157
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1238 |
" |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1239 |
kludge to avoid slow search for containing class |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1240 |
" |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1241 |
(selector ~~ #doIt and:[selector ~~ #doIt:]) ifTrue:[ |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1242 |
implementorClass := self methodClass. |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1243 |
]. |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1244 |
implementorClass notNil ifTrue: [ |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1245 |
(implementorClass ~~ receiverClass) ifTrue: [ |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1246 |
newString := newString , '>>>', |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1247 |
implementorClass name printString |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1248 |
] |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1249 |
] ifFalse:[ |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1250 |
self searchClass ~~ receiverClass ifTrue:[ |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1251 |
newString := newString , '>>>' , self searchClass name |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1252 |
]. |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1253 |
" |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1254 |
kludge for doIt - these unbound methods are not |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1255 |
found in the classes methodDictionary |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1256 |
" |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1257 |
(selector ~~ #doIt and:[selector ~~ #doIt:]) ifTrue:[ |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1258 |
newString := newString , '>>>**NONE**' |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1259 |
] |
436ad20004f4
prepare for #doIt: (with context)
Claus Gittinger <cg@exept.de>
parents:
2135
diff
changeset
|
1260 |
] |
623 | 1261 |
]. |
1262 |
||
1263 |
^ newString |
|
1264 |
! ! |
|
1265 |
||
1266 |
!Context methodsFor:'private accessing'! |
|
1267 |
||
753
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1268 |
markForInterrupt |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1269 |
"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
|
1270 |
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
|
1271 |
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
|
1272 |
|
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1273 |
%{ /* NOCONTEXT */ |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1274 |
__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
|
1275 |
%} |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1276 |
! |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
1277 |
|
1727 | 1278 |
markForInterruptOnUnwind |
1279 |
"set the interrupt-on-unwind flag in the receiver. |
|
1280 |
The VM will generate a stepInterrupt, when this context returns or |
|
1281 |
is unwound. This is used by the debugger for faster single-stepping; |
|
1282 |
- a highly internal mechanism and not for public use." |
|
1283 |
||
1284 |
%{ /* NOCONTEXT */ |
|
1285 |
__INST(flags) = (OBJ)((INT)__INST(flags) |
|
1286 |
| __MASKSMALLINT(__IRQ_ON_UNWIND)); |
|
1287 |
%} |
|
1288 |
! |
|
1289 |
||
623 | 1290 |
markForUnwind |
749 | 1291 |
"set the mark for unwind flag in the receiver. |
1292 |
The VM needs this to know that some special action is to be performed with |
|
1293 |
this context - a highly internal mechanism and not for public use." |
|
1294 |
||
623 | 1295 |
%{ /* NOCONTEXT */ |
1133 | 1296 |
__INST(flags) = (OBJ)((INT)__INST(flags) | __MASKSMALLINT(__UNWIND_MARK)); |
623 | 1297 |
%} |
749 | 1298 |
|
1299 |
"Modified: 13.12.1995 / 19:05:22 / cg" |
|
623 | 1300 |
! |
1301 |
||
1302 |
unmarkForUnwind |
|
749 | 1303 |
"clear the mark for unwind flag in the receiver. |
1304 |
The VM needs this to know that some special action is to be performed with |
|
1305 |
this context - a highly internal mechanism and not for public use." |
|
1306 |
||
623 | 1307 |
%{ /* NOCONTEXT */ |
1133 | 1308 |
__INST(flags) = (OBJ)((INT)__INST(flags) & ~__MASKSMALLINT(__UNWIND_MARK)); |
623 | 1309 |
%} |
1310 |
! ! |
|
1311 |
||
1051 | 1312 |
!Context methodsFor:'special accessing'! |
1313 |
||
1314 |
canReturn |
|
1315 |
"return true, if the receiver allows returning through it. |
|
2646 | 1316 |
Blocks, it (currently) always returns false. |
1317 |
Methods which contain a (non-inlined) block are always |
|
1318 |
returnable - for other methods, it depends on how the system |
|
1319 |
was compiled (stc flag +/-optContext). |
|
1320 |
If it was compiled with +optContext, methods are compiled |
|
1321 |
non returnable. |
|
1322 |
Since this saves some administrative work in every method |
|
1323 |
invocation and makes overall execution faster, the system classes |
|
1324 |
are all compiled with this flag turned on." |
|
1051 | 1325 |
|
1326 |
%{ /* NOCONTEXT */ |
|
1327 |
||
1133 | 1328 |
RETURN ( (__intVal(__INST(flags)) & __CANNOT_RETURN) ? false : true ); |
1051 | 1329 |
%} |
1330 |
! |
|
1331 |
||
1492 | 1332 |
hasStackToShow |
2646 | 1333 |
"private interface to the debugger. |
1334 |
Smalltalk contexts return false here - other language frames |
|
1335 |
(i.e. Java frames) may want to show the evaluation stack" |
|
1336 |
||
1492 | 1337 |
^ false |
1338 |
||
1339 |
"Created: 28.6.1996 / 14:48:39 / cg" |
|
2646 | 1340 |
"Modified: 13.5.1997 / 16:31:12 / cg" |
1492 | 1341 |
! |
1342 |
||
1051 | 1343 |
isNonLifo |
2646 | 1344 |
"return true, if this is a nonLifo context. |
1345 |
A nonLifo context is one that is still on the machine stack, |
|
1346 |
but has a reference taken and needs to be converted to a real |
|
1347 |
object (in objectMemory) when the method/block returns. |
|
1348 |
You dont have to understand this - this is a special ST/X |
|
1349 |
debug query, which may be removed without notice." |
|
1051 | 1350 |
|
1351 |
%{ /* NOCONTEXT */ |
|
1133 | 1352 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__NONLIFO)) ? true : false ); |
1051 | 1353 |
%} |
1354 |
! |
|
1355 |
||
1356 |
isOnMachineStack |
|
1357 |
"return true, if this is a machine stack context as opposed to a |
|
2646 | 1358 |
real heap context. |
1359 |
You dont have to understand this - this is a special ST/X |
|
1360 |
debug query, which may be removed without notice." |
|
1051 | 1361 |
|
1362 |
%{ /* NOCONTEXT */ |
|
1363 |
RETURN ( (__qSpace(self) >= STACKSPACE) ? true : false ); |
|
1364 |
%} |
|
1365 |
! |
|
1366 |
||
1367 |
isSpecial |
|
1368 |
"return true, if this is either a nonLifo or interrupted context" |
|
1369 |
||
1370 |
%{ /* NOCONTEXT */ |
|
1133 | 1371 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__SPECIAL)) ? true : false ); |
1051 | 1372 |
%} |
1373 |
! |
|
1374 |
||
1375 |
isUnwindContext |
|
1376 |
"return true, if this is an unwindContext" |
|
1377 |
||
1378 |
%{ /* NOCONTEXT */ |
|
1133 | 1379 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__UNWIND_MARK)) ? true : false ); |
1051 | 1380 |
%} |
1381 |
! ! |
|
1382 |
||
623 | 1383 |
!Context methodsFor:'testing'! |
1384 |
||
1385 |
isBlockContext |
|
1386 |
"return true, iff the receiver is a BlockContext, false otherwise" |
|
1387 |
||
1388 |
^ false |
|
1389 |
! |
|
1390 |
||
1391 |
isContext |
|
1392 |
"return true, iff the receiver is a Context, false otherwise" |
|
1393 |
||
1394 |
^ true |
|
1395 |
! |
|
1396 |
||
1397 |
isRecursive |
|
1398 |
"return true, if this context is one of a recursive send of the same |
|
1483 | 1399 |
selector to the same receiver before. |
1400 |
Here, different arguments are ignored - i.e. only the same method |
|
1401 |
counts for recursiveness. |
|
623 | 1402 |
Used to detect recursive errors or recursive printing - for example." |
1403 |
||
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1404 |
|c count "{Class: SmallInteger }" myMethodsClass| |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1405 |
|
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1406 |
count := 0. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1407 |
|
2893 | 1408 |
c := self findNextContextWithSelector:selector or:nil or:nil. |
623 | 1409 |
[c notNil] whileTrue:[ |
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1410 |
(c receiver == receiver) ifTrue:[ |
1483 | 1411 |
" |
1412 |
stupid: the current ST/X context does not include |
|
1413 |
the method, but the class, in which the search started ... |
|
1414 |
" |
|
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1415 |
myMethodsClass isNil ifTrue:[ |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1416 |
myMethodsClass := self methodClass. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1417 |
]. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1418 |
c methodClass == myMethodsClass ifTrue:[ |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1419 |
^ true |
1483 | 1420 |
] |
1421 |
]. |
|
2893 | 1422 |
c := c findNextContextWithSelector:selector or:nil or:nil. |
2135
6bd144c1c358
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1853
diff
changeset
|
1423 |
|
1483 | 1424 |
" |
1425 |
this special test was added to get out after a while |
|
1426 |
if the sender chain is corrupt - this gives us at least |
|
1427 |
a chance to find those errors. |
|
1428 |
" |
|
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1429 |
count := count + 1. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
1430 |
count >= 100000 ifTrue:[ |
2135
6bd144c1c358
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1853
diff
changeset
|
1431 |
'Context [warning]: bad context chain' errorPrintCR. |
1483 | 1432 |
^ true |
1433 |
] |
|
623 | 1434 |
]. |
1435 |
^ false |
|
1483 | 1436 |
|
2135
6bd144c1c358
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1853
diff
changeset
|
1437 |
"Modified: 10.1.1997 / 17:34:26 / cg" |
623 | 1438 |
! ! |
1439 |
||
1810 | 1440 |
!Context class methodsFor:'documentation'! |
749 | 1441 |
|
1442 |
version |
|
2893 | 1443 |
^ '$Header: /cvs/stx/stx/libbasic/Context.st,v 1.80 1997-09-02 17:40:57 cg Exp $' |
749 | 1444 |
! ! |
623 | 1445 |
Context initialize! |