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