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