author | Claus Gittinger <cg@exept.de> |
Mon, 15 Jul 2019 15:32:22 +0200 | |
changeset 24425 | 3733fe6e6258 |
parent 24259 | 46a260a9ca92 |
child 24739 | 46cab49167fb |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
15933 | 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 |
|
12853
3d15dcbe0057
added method-in-context slot.
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
9 |
other person. No t itle to or ownership of the software is |
1 | 10 |
hereby transferred. |
11 |
" |
|
5422 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
17304 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
1 | 16 |
Object variableSubclass:#Context |
13020 | 17 |
instanceVariableNames:'flags sender* home receiver selector searchClass method lineNr |
18 |
retvalTemp handle*' |
|
22262 | 19 |
classVariableNames:'SingleStepInterruptRequest MaxRecursion' |
13020 | 20 |
poolDictionaries:'' |
21 |
category:'Kernel-Methods' |
|
1 | 22 |
! |
23 |
||
1810 | 24 |
!Context class methodsFor:'documentation'! |
54 | 25 |
|
88 | 26 |
copyright |
27 |
" |
|
28 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
15933 | 29 |
All Rights Reserved |
88 | 30 |
|
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
12841 | 35 |
other person. No t itle to or ownership of the software is |
88 | 36 |
hereby transferred. |
37 |
" |
|
38 |
! |
|
39 |
||
54 | 40 |
documentation |
41 |
" |
|
402 | 42 |
Contexts represent the stack frame objects, which keep the processing |
43 |
state of a method or block (i.e. its local variables, temporaries etc.) |
|
12841 | 44 |
Every message send adds a context to a chain, which can be traced back via |
402 | 45 |
the sender field. The context of the currently active method is always |
19110 | 46 |
accessible via the pseuodoVariable called 'thisContext'. |
21415 | 47 |
The actual implementation uses the machine's stack for this, building real |
48 |
contexts on demand only, whenever a context is needed. Also, initially these are |
|
15688 | 49 |
allocated on the stack and only moved to the heap, when a context outlives its |
50 |
activation. |
|
54 | 51 |
|
12841 | 52 |
For both method- and block-contexts, the layout is the same. |
402 | 53 |
For method contexts, the home-field is nil, while for block contexts the home- |
141 | 54 |
field is either the context of its surrounding block (i.e. the context of the |
21415 | 55 |
block, in which the receiving block was created, if it's a nested block) or of |
12841 | 56 |
its home method. |
57 |
||
15688 | 58 |
Cheap blocks are blocks which do not refer to any locals or the receiver (currently), |
59 |
but only access globals, class vars or arguments (for example: [:a :b | a < b] is a cheap block). |
|
60 |
Cheap blocks do not need a home and therefore never require that their home context be moved |
|
61 |
to the heap. Contexts of cheap blocks do not have a home context - their home field is also nil. |
|
141 | 62 |
|
402 | 63 |
LineNumbers vs. program counter: |
64 |
||
65 |
Due to the compilation to machine code, methods and/or block do not |
|
216 | 66 |
always (actually: do seldom) contain bytecodes. Thus, there is no such concept |
67 |
as a bytecode p-counter. To support debugging, the linenumber within the |
|
68 |
original source is instead remembered when a send or loop entry is performed. |
|
69 |
Since linenumbers are not always sufficient for debugging (multiple sends in one |
|
402 | 70 |
line), this may be changed in future versions to a character offset, giving |
216 | 71 |
the position of the selector in the source. |
1 | 72 |
|
402 | 73 |
Restartable / Returnable contexts: |
74 |
||
75 |
In previous versions (up to ST/X 2.10.5), every method stored enough |
|
76 |
information in the context for that one to be restartable later (for example, |
|
15688 | 77 |
via the debugger's restart button). As stc is supposed to generate portable C-code, |
78 |
this means that technically, a setjmp needs to be done at the beginning of the method |
|
79 |
in order to have a resumable (and portable) state (however, inline asm code does this setjmp, |
|
80 |
so it is much faster than the libc-setjmo, which stores a lot of additional state, not needed here). |
|
15933 | 81 |
With 2.10.6, this is now an stc-compiler option, and the system as delivered is compiled |
15688 | 82 |
to only create restartable contexts for those which contain blocks or are marked as special |
15933 | 83 |
via a directive. |
84 |
This resulted in an overall speedup of roughly 10-20% percent, depending on the type of CPU. |
|
85 |
However, it makes most methods non-restartable (however, abort, signal handling and unwind blocks |
|
15688 | 86 |
work as usual). |
402 | 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) |
|
15688 | 91 |
If you do not like this, you should recompile all classes with stc's '-optContext' flag. |
402 | 92 |
|
93 |
Resuming contexts: |
|
94 |
||
15688 | 95 |
Strictly speaking, ST/X does not support a context to be resumed (because the setjmp is |
15933 | 96 |
not done on the caller side, but in the callee). |
15688 | 97 |
However, it does support a forced return (i.e. non-local-return) from a context. |
402 | 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 |
||
15688 | 103 |
Block-return from an outlived context (i.e. its home method has already returned) |
402 | 104 |
is now rewarded by an invalidReturn exception - it used to be a noop in previous |
15688 | 105 |
releases. The blue book described this to be a noop, but other Smalltalk implementations |
106 |
changed this to be an invalid operation - a good decision, as it makes debugging much easier. |
|
402 | 107 |
|
108 |
||
1282 | 109 |
[instance variables:] |
19110 | 110 |
flags <SmallInteger> used by the VM; never touch. |
111 |
contains info about number of args, |
|
112 |
locals and temporaries. |
|
113 |
||
114 |
sender <Context> the 'calling / sending' context |
|
115 |
This is not directly accessible, since it may |
|
116 |
be a lazy context (i.e. an empty frame). |
|
117 |
The #sender method cares for this. |
|
118 |
||
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. |
|
124 |
||
125 |
receiver <Object> the receiver of this message |
|
126 |
||
127 |
selector <Symbol> the selector of this message |
|
128 |
||
129 |
searchClass <Class> the class, where the message lookup started |
|
130 |
(for super sends) or nil, for regular sends. |
|
131 |
||
132 |
lineNr <SmallInteger> the position where the context left off |
|
133 |
(kind of p-counter). Only the low 16bits |
|
134 |
are valid. |
|
135 |
||
136 |
retValTemp nil temporary - always nil, when you see the context |
|
137 |
(used in the VM as temporary) |
|
138 |
||
139 |
handle *noObject* used by the VM; not accessible, not an object |
|
140 |
||
141 |
method the corresponding method |
|
142 |
||
143 |
<indexed> arguments of the send followed by |
|
144 |
locals of the method/block followed by |
|
145 |
temporaries. |
|
1 | 146 |
|
6003 | 147 |
[errors:] |
19110 | 148 |
CannotReturnError raised when a block tries |
149 |
to return ('^') from a method context |
|
150 |
which itself has already returned |
|
151 |
(i.e. there is no place to return to) |
|
12841 | 152 |
|
69 | 153 |
WARNING: layout and size known by the compiler and runtime system - do not change. |
1282 | 154 |
|
1293 | 155 |
|
156 |
[author:] |
|
19110 | 157 |
Claus Gittinger |
1293 | 158 |
|
1282 | 159 |
[see also:] |
19110 | 160 |
Block Process Method |
161 |
( contexts, stacks & unwinding : programming/contexts.html) |
|
54 | 162 |
" |
163 |
! ! |
|
1 | 164 |
|
1810 | 165 |
!Context class methodsFor:'initialization'! |
105 | 166 |
|
167 |
initialize |
|
6000 | 168 |
CannotReturnError notifierString:'invalid return; method cannot return twice'. |
169 |
CannotResumeError notifierString:'invalid resume'. |
|
1334
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
170 |
|
6000 | 171 |
SingleStepInterruptRequest isNil ifTrue:[ |
22262 | 172 |
SingleStepInterruptRequest := QuerySignal new. |
173 |
SingleStepInterruptRequest nameClass:self message:#singleStepInterruptRequest. |
|
174 |
SingleStepInterruptRequest notifierString:'single step'. |
|
175 |
]. |
|
176 |
||
177 |
"/ context searchers (eg. isRecursive) will stop searching after |
|
178 |
"/ this many call levels and assume, that something is wrong with the |
|
179 |
"/ calling chain. |
|
180 |
MaxRecursion := 10000. |
|
181 |
||
182 |
"Modified: / 17-09-2017 / 10:00:19 / cg" |
|
105 | 183 |
! ! |
184 |
||
1810 | 185 |
!Context class methodsFor:'Signal constants'! |
105 | 186 |
|
6000 | 187 |
cannotResumeSignal |
188 |
"return the signal used when a method is tried to be resumed, which cannot" |
|
189 |
||
190 |
^ CannotResumeError |
|
191 |
! |
|
192 |
||
193 |
cannotReturnSignal |
|
194 |
"return the signal used when a method is tried to be returned twice |
|
195 |
or, when some dead context is unwound or restarted." |
|
196 |
||
197 |
^ CannotReturnError |
|
198 |
! |
|
199 |
||
105 | 200 |
invalidReturnSignal |
141 | 201 |
"return the signal used when a method is tried to be returned twice |
202 |
or, when some dead context is unwound or restarted." |
|
203 |
||
8357 | 204 |
<resource: #obsolete> |
6000 | 205 |
self obsoleteMethodWarning:'use #cannotReturnSignal'. |
206 |
^ self cannotReturnSignal. |
|
1334
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
207 |
! |
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
208 |
|
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
209 |
singleStepInterruptRequest |
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
210 |
"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
|
211 |
|
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
212 |
^ SingleStepInterruptRequest |
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
213 |
|
8b21c5f67b15
allow different implementations of singleStep (JAVA support)
Claus Gittinger <cg@exept.de>
parents:
1293
diff
changeset
|
214 |
"Created: 6.5.1996 / 16:46:32 / cg" |
105 | 215 |
! ! |
216 |
||
11473 | 217 |
!Context class methodsFor:'error handling'! |
218 |
||
219 |
showWhereWeCameFrom |
|
12841 | 220 |
"show the stack backtrace: at least 4 levels, or until the first |
11473 | 221 |
send to a non-collection object (because we want to know, |
222 |
which non-collection send invoked a bad collection-method)." |
|
223 |
||
224 |
|con count| |
|
225 |
||
226 |
con := thisContext sender sender. |
|
227 |
count := 0. |
|
228 |
[ |
|
15933 | 229 |
(' from ' , con printString) errorPrintCR. |
230 |
con := con sender. |
|
231 |
count := count + 1. |
|
11631 | 232 |
] doWhile:[con notNil and:[count < 5 or:[con receiver isCollection]]]. |
233 |
"/ one more |
|
234 |
con notNil ifTrue:[ |
|
15933 | 235 |
(' from ' , con printString) errorPrintCR. |
11631 | 236 |
]. |
11473 | 237 |
|
238 |
" |
|
239 |
#() asSet add:nil |
|
240 |
" |
|
241 |
! ! |
|
242 |
||
1810 | 243 |
!Context class methodsFor:'queries'! |
3 | 244 |
|
245 |
isBuiltInClass |
|
1264 | 246 |
"return true if this class is known by the run-time-system. |
247 |
Here, true is returned." |
|
3 | 248 |
|
249 |
^ true |
|
1264 | 250 |
|
251 |
"Modified: 23.4.1996 / 15:58:00 / cg" |
|
3 | 252 |
! ! |
253 |
||
4485 | 254 |
!Context class methodsFor:'special searching'! |
255 |
||
256 |
findFirstSpecialHandle:searchForHandle raise:searchForRaise |
|
257 |
|c| |
|
258 |
||
259 |
%{ |
|
18406 | 260 |
#ifdef __SCHTEAM__ |
261 |
c = __c__.currentContinuation.sender(); |
|
262 |
if (c == null) c = STObject.Nil; |
|
263 |
#else |
|
4485 | 264 |
OBJ __c__; |
265 |
||
266 |
__c__ = __ContextInstPtr(__thisContext)->c_sender; |
|
10537
9ebc87dd0738
Better check for nil sender...
Stefan Vogel <sv@exept.de>
parents:
10136
diff
changeset
|
267 |
if (!__isNonNilObject(__c__)) { |
15933 | 268 |
RETURN(nil) |
10537
9ebc87dd0738
Better check for nil sender...
Stefan Vogel <sv@exept.de>
parents:
10136
diff
changeset
|
269 |
} |
4485 | 270 |
if (__isLazy(__c__)) { |
15933 | 271 |
__PATCHUPCONTEXT(__c__); |
4485 | 272 |
} |
273 |
c = __c__; |
|
18190 | 274 |
#endif |
4485 | 275 |
%}. |
276 |
^ c findSpecialHandle:searchForHandle raise:searchForRaise |
|
277 |
! ! |
|
278 |
||
12573 | 279 |
!Context methodsFor:'Compatibility-Squeak'! |
280 |
||
281 |
longStack |
|
15644 | 282 |
^ self fullPrintAllString |
12573 | 283 |
! ! |
284 |
||
7261 | 285 |
!Context methodsFor:'Compatibility-VW'! |
5983 | 286 |
|
287 |
resumeWith:value |
|
288 |
"same as #resume: - visualWorks compatibility" |
|
289 |
||
290 |
self resume:value |
|
291 |
! ! |
|
292 |
||
623 | 293 |
!Context methodsFor:'accessing'! |
294 |
||
16489 | 295 |
arg1Index |
16544 | 296 |
"return the index of the 1st arg (redefined in JavaContext)" |
297 |
||
298 |
^ 1 |
|
16489 | 299 |
! |
300 |
||
623 | 301 |
argAt:n |
302 |
"return the n'th argument" |
|
303 |
||
18437 | 304 |
n > self argumentCount ifTrue:[ |
305 |
^ self subscriptBoundsError:n. |
|
1726 | 306 |
]. |
623 | 307 |
^ self at:n |
1726 | 308 |
|
309 |
"Modified: 12.10.1996 / 21:44:28 / cg" |
|
623 | 310 |
! |
311 |
||
312 |
argAt:n put:value |
|
313 |
"set the n'th argument - useful when the receiver should be restarted" |
|
154 | 314 |
|
18437 | 315 |
n > self argumentCount ifTrue:[ |
316 |
^ self subscriptBoundsError:n. |
|
1726 | 317 |
]. |
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
318 |
self at:n put:value. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
319 |
^ value |
1726 | 320 |
|
321 |
"Modified: 12.10.1996 / 21:44:32 / cg" |
|
623 | 322 |
! |
323 |
||
324 |
args |
|
325 |
"return an array filled with the arguments of this context" |
|
326 |
||
327 |
|n| |
|
328 |
||
18437 | 329 |
n := self argumentCount. |
3130 | 330 |
n == 0 ifTrue:[ |
18437 | 331 |
"/ little optimization here - avaoid creating empty containers |
332 |
^ #() |
|
3130 | 333 |
]. |
623 | 334 |
^ (Array new:n) replaceFrom:1 to:n with:self. |
335 |
! |
|
154 | 336 |
|
623 | 337 |
argsAndVars |
338 |
"return an array filled with the arguments and variables of this context" |
|
339 |
||
340 |
|n| |
|
341 |
||
18437 | 342 |
n := self argumentCount + self numVars. |
3130 | 343 |
n == 0 ifTrue:[ |
18437 | 344 |
"/ little optimization here - avoid creating empty containers |
345 |
^ #() |
|
3130 | 346 |
]. |
623 | 347 |
^ (Array new:n) replaceFrom:1 to:n with:self. |
1810 | 348 |
|
349 |
"Modified: 23.10.1996 / 16:19:41 / cg" |
|
623 | 350 |
! |
154 | 351 |
|
8687
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
352 |
argumentCount |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
353 |
"ANSI alias for numArgs: return the number of arguments to the Block/Method" |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
354 |
|
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
355 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
356 |
#ifdef __SCHTEAM__ |
18289 | 357 |
return context._RETURN( STInteger._new( self.asSTContinuation().numStArgs() ) ); |
18190 | 358 |
#else |
8913 | 359 |
RETURN ( __mkSmallInteger( (__intVal(__INST(flags)) >> __NARG_SHIFT) & __NARG_MASK) ); |
18190 | 360 |
#endif |
8687
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
361 |
%} |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
362 |
! |
d6e6e2c0c27c
Define #argumentCount as ANSI alias for #numArgs
Stefan Vogel <sv@exept.de>
parents:
8578
diff
changeset
|
363 |
|
7324
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
364 |
at:n put:value |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
365 |
super at:n put:value. |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
366 |
|
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
367 |
"/ need some aid for optimized code - |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
368 |
"/ some machines have the arguments/receiver etc. kept in register vars ... |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
369 |
"/ the unfix updates the machine-stack version of the receiver. |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
370 |
%{ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
371 |
#ifndef __SCHTEAM__ |
7324
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
372 |
__UNFIXCONTEXT(self, 0); |
18190 | 373 |
#endif |
7324
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
374 |
%}. |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
375 |
^ value |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
376 |
! |
9e145a7ae670
need unfix, when changed via at:put:
Claus Gittinger <cg@exept.de>
parents:
7261
diff
changeset
|
377 |
|
623 | 378 |
home |
379 |
"return the immediate home of the receiver. |
|
380 |
for block contexts, this is the methodcontext, where the block was created, |
|
15688 | 381 |
for nested block contexts, it's the surrounding block's context. |
623 | 382 |
for method-contexts this is nil." |
25 | 383 |
|
623 | 384 |
^ nil "home" |
385 |
! |
|
1 | 386 |
|
3324
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
387 |
homeReceiver |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
388 |
"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
|
389 |
|
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
390 |
^ receiver |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
391 |
|
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
392 |
"Created: / 5.3.1998 / 16:18:26 / stefan" |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
393 |
! |
0295f7b3b208
Add #homeReceiver (as in ST80).
Stefan Vogel <sv@exept.de>
parents:
3258
diff
changeset
|
394 |
|
1 | 395 |
instVarAt:index |
69 | 396 |
"have to catch instVar access to retVal and handle - they are invalid. |
12841 | 397 |
Notice, that one of the next ST/X versions might get some syntactic |
69 | 398 |
extension to get this automatically)." |
1 | 399 |
|
18190 | 400 |
|what| |
401 |
||
402 |
%{ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
403 |
#ifdef __SCHTEAM__ |
18214
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
404 |
{ |
18406 | 405 |
int idx = index.intValue("[instVarAt:]"); |
18214
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
406 |
|
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
407 |
if (idx == I_sender) { |
18406 | 408 |
STContinuation c = self.sender(); |
409 |
if (c == null) { |
|
410 |
return __c__._RETURN_nil(); |
|
411 |
} |
|
412 |
return __c__._RETURN( c ); |
|
18214
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
413 |
} |
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
414 |
if (idx == I_retvalTemp) { |
18406 | 415 |
return __c__._RETURN( Nil ); |
18214
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
416 |
} |
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
417 |
if (idx == I_handle) { |
18406 | 418 |
return __c__._RETURN( Nil ); |
18214
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
419 |
} |
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
420 |
} |
18190 | 421 |
#else |
422 |
if (index == __MKSMALLINT(__SLOT_CONTEXT_SENDER)) { // sender - must be accessed specially |
|
423 |
what = @symbol(sender); |
|
424 |
} else if (index == __MKSMALLINT(__SLOT_CONTEXT_RETVAL)) { // retvalTemp - invisible |
|
425 |
RETURN (nil); |
|
426 |
} else if (index == __MKSMALLINT(__SLOT_CONTEXT_HANDLE)) { // handle to machine stack - invisible |
|
427 |
RETURN (nil); |
|
428 |
} |
|
429 |
#endif |
|
430 |
%}. |
|
18214
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
431 |
what == #sender ifTrue:[ |
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
432 |
^ self sender |
60e1764add21
oops - some bugs introduced by java support code
Claus Gittinger <cg@exept.de>
parents:
18190
diff
changeset
|
433 |
]. |
1 | 434 |
^ super instVarAt:index |
435 |
! |
|
436 |
||
437 |
instVarAt:index put:value |
|
69 | 438 |
"have to catch instVar access to retVal and handle - they are invalid. |
12841 | 439 |
Notice, that one of the next ST/X versions might get some syntactic |
69 | 440 |
extension to get this automatically)." |
1 | 441 |
|
18190 | 442 |
%{ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
443 |
#ifdef __SCHTEAM__ |
18190 | 444 |
ERROR("unimplemented"); |
445 |
#else |
|
446 |
if (index == __MKSMALLINT(__SLOT_CONTEXT_SENDER)) { // sender - not allowed to change |
|
447 |
RETURN (nil); |
|
448 |
} else if (index == __MKSMALLINT(__SLOT_CONTEXT_RETVAL)) { // retvalTemp - not allowed to change |
|
449 |
RETURN (nil); |
|
450 |
} else if (index == __MKSMALLINT(__SLOT_CONTEXT_HANDLE)) { // handle to machine stack - not allowed to change |
|
451 |
RETURN (nil); |
|
452 |
} |
|
453 |
#endif |
|
454 |
%}. |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
455 |
super instVarAt:index put:value. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
456 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
457 |
"/ need some aid for optimized code - |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
458 |
"/ some machines have the arguments kept in register vars ... |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
459 |
"/ the unfix updates the machine-stack version of the receiver. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
460 |
%{ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
461 |
#ifndef __SCHTEAM__ |
4570 | 462 |
__UNFIXCONTEXT(self, 0); |
18190 | 463 |
#endif |
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
464 |
%}. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
465 |
^ value |
1 | 466 |
! |
467 |
||
623 | 468 |
lineNumber |
22368 | 469 |
"this returns the lineNumber within the method's source, where the context was |
623 | 470 |
interrupted or called another method. (currently, sometimes this information |
471 |
is not available - in this case 0 is returned)" |
|
1 | 472 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
473 |
|l| |
3923 | 474 |
|
4328
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
475 |
receiver isJavaObject ifTrue:[ |
21923 | 476 |
"/ chances are good that I am a javaContext ... |
477 |
self method isJavaMethod ifTrue:[ |
|
478 |
^ self javaLineNumber |
|
479 |
] |
|
4328
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
480 |
]. |
9cc10bae2f98
care for contexts which really ought to be java contexts
Claus Gittinger <cg@exept.de>
parents:
3923
diff
changeset
|
481 |
|
3923 | 482 |
lineNr notNil ifTrue:[ |
21923 | 483 |
l := lineNr bitAnd:16rFFFF. |
3923 | 484 |
]. |
485 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
486 |
"/ self isJavaContext ifTrue:[ |nr m| |
3923 | 487 |
"/ m := self method. |
488 |
"/ l isNil ifTrue:[ |
|
489 |
"/ m notNil ifTrue:[ |
|
490 |
"/ nr := m lineNumber |
|
491 |
"/ ]. |
|
492 |
"/ nr notNil ifTrue:[ |
|
493 |
"/ ^ nr |
|
494 |
"/ ]. |
|
495 |
"/ ^0 |
|
496 |
"/ ]. |
|
497 |
"/ nr := self method lineNumberForPC:l. |
|
498 |
"/ nr isNil ifTrue:[ |
|
499 |
"/ m notNil ifTrue:[ |
|
500 |
"/ nr := m lineNumber |
|
501 |
"/ ]. |
|
502 |
"/ nr notNil ifTrue:[ |
|
503 |
"/ ^ nr |
|
504 |
"/ ]. |
|
505 |
"/ ^ 0 |
|
506 |
"/ ]. |
|
507 |
"/ ^ nr. |
|
508 |
"/ ]. |
|
509 |
||
510 |
^ l |
|
511 |
||
22368 | 512 |
"Modified: / 10-11-1998 / 13:19:48 / cg" |
513 |
"Modified (comment): / 21-11-2017 / 13:00:40 / cg" |
|
1 | 514 |
! |
515 |
||
4450 | 516 |
lineNumberFromMethod |
517 |
^ 1 |
|
518 |
! |
|
519 |
||
24127 | 520 |
logFacility |
521 |
"the 'log facility'; |
|
522 |
this is used by the Logger both as a prefix to the log message, |
|
523 |
and maybe (later) used to filter and/or control per-facility log thresholds. |
|
524 |
The default here is to base the facility on the package: |
|
525 |
if the class is anywhere in the base ST/X system, 'STX' is returned as facility. |
|
526 |
Otherwise, the last component of the package name is returned." |
|
527 |
||
528 |
|cls| |
|
529 |
||
530 |
method isNil ifTrue:[^ '???']. |
|
531 |
(cls := method mclass) isNil ifTrue:[^ 'DOIT']. |
|
532 |
^ cls logFacility |
|
533 |
||
534 |
" |
|
535 |
thisContext logFacility |
|
536 |
thisContext sender logFacility |
|
537 |
" |
|
538 |
||
539 |
"Created: / 18-05-2019 / 10:12:21 / Claus Gittinger" |
|
540 |
! |
|
541 |
||
8488 | 542 |
message |
543 |
^ Message selector:selector arguments:self args |
|
544 |
||
545 |
" |
|
9355 | 546 |
thisContext methodHome message |
547 |
thisContext message |
|
8488 | 548 |
" |
549 |
! |
|
550 |
||
15851 | 551 |
messageSend |
552 |
^ MessageSend receiver:receiver selector:selector arguments:self args |
|
553 |
||
554 |
" |
|
555 |
thisContext methodHome messageSend |
|
556 |
thisContext messageSend |
|
557 |
" |
|
558 |
! |
|
559 |
||
1 | 560 |
method |
54 | 561 |
"return the method for which the receiver was created. |
13020 | 562 |
Change with ST/X vsn 6: |
24127 | 563 |
In older versions, the method was not stored in the context, but a lookup |
564 |
was simulated using selector and class. |
|
565 |
(which occasionally returned the wrong method - especially in the debugger, |
|
566 |
when the debugged method was changed). |
|
567 |
This has been changed - especially to support Jan's meta-object protocol. |
|
568 |
It is now stored in the context" |
|
1 | 569 |
|
3508 | 570 |
|c sender sendersSelector m| |
14225 | 571 |
|
572 |
(method notNil and:[method isMethod]) ifTrue:[ |
|
24127 | 573 |
^ method |
14225 | 574 |
]. |
575 |
||
576 |
"mhmh - maybe I am a context for an unbound method (as generated by doIt); |
|
577 |
look in the sender's context. Consider this a kludge. |
|
24127 | 578 |
Future versions of ST/X's message lookup may store the method in the context. |
14225 | 579 |
" |
580 |
sender := self sender. |
|
581 |
sender notNil ifTrue:[ |
|
24127 | 582 |
sendersSelector := sender selector. |
583 |
sendersSelector notNil ifTrue:[ |
|
584 |
(sendersSelector startsWith:'valueWithReceiver:') ifTrue:[ |
|
585 |
m := sender receiver. |
|
586 |
m isMethod ifTrue:[ |
|
587 |
method := m. |
|
588 |
^ m |
|
589 |
] |
|
590 |
] |
|
591 |
] |
|
12853
3d15dcbe0057
added method-in-context slot.
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
592 |
]. |
12841 | 593 |
|
325 | 594 |
c := self searchClass. |
595 |
" |
|
596 |
the below cannot happen in normal circumstances |
|
597 |
(added to avoid recursive errors in case of a broken sender chain) |
|
598 |
" |
|
599 |
c isBehavior ifFalse:[ |
|
24127 | 600 |
'Context [error]: non class in searchClass' errorPrintCR. |
601 |
' selector: ' errorPrint. selector errorPrint. |
|
602 |
' receiver: ' errorPrint. receiver errorPrintCR. |
|
603 |
^ nil |
|
325 | 604 |
]. |
605 |
||
328 | 606 |
c := c whichClassIncludesSelector:selector. |
1 | 607 |
c notNil ifTrue:[ |
24127 | 608 |
method := c compiledMethodAt:selector. |
609 |
^ method |
|
1 | 610 |
]. |
216 | 611 |
|
1 | 612 |
^ nil |
2135
6bd144c1c358
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
1853
diff
changeset
|
613 |
|
13426 | 614 |
"Modified: / 28-06-2011 / 20:23:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
14225 | 615 |
"Modified: / 20-07-2012 / 14:46:37 / cg" |
24127 | 616 |
"Modified (comment): / 18-05-2019 / 10:04:17 / Claus Gittinger" |
1 | 617 |
! |
618 |
||
212 | 619 |
methodClass |
620 |
"return the class in which the method for which the receiver was created is." |
|
621 |
||
1456 | 622 |
|cls m| |
623 |
||
12853
3d15dcbe0057
added method-in-context slot.
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
624 |
method notNil ifTrue:[ |
15933 | 625 |
method isMethod ifTrue:[ |
626 |
^ method mclass |
|
627 |
] |
|
12853
3d15dcbe0057
added method-in-context slot.
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
628 |
]. |
12841 | 629 |
|
1456 | 630 |
cls := self searchClass. |
3923 | 631 |
(cls isMeta |
632 |
and:[cls soleInstance isJavaClass]) ifTrue:[ |
|
15933 | 633 |
cls := cls soleInstance |
3923 | 634 |
]. |
1456 | 635 |
|
3923 | 636 |
[cls notNil] whileTrue:[ |
15933 | 637 |
cls := cls whichClassIncludesSelector:selector. |
638 |
cls isNil ifTrue:[^ nil]. |
|
639 |
||
640 |
m := cls compiledMethodAt:selector. |
|
641 |
m notNil ifTrue:[ |
|
642 |
m isIgnored ifFalse:[^ cls]. |
|
643 |
]. |
|
644 |
cls := cls superclass |
|
1456 | 645 |
]. |
646 |
^ cls |
|
647 |
||
3923 | 648 |
"Modified: / 5.11.1998 / 19:07:43 / cg" |
212 | 649 |
! |
650 |
||
623 | 651 |
methodHome |
652 |
"return the method-home - for method contexts this is the receiver" |
|
653 |
||
654 |
^ self |
|
655 |
! |
|
656 |
||
15091 | 657 |
methodSelector |
658 |
"return the method's (or home method's) selector" |
|
659 |
||
660 |
^ self methodHome selector |
|
661 |
! |
|
662 |
||
623 | 663 |
ntemp |
664 |
"return the number of temporary variables of the Block/Method. |
|
1810 | 665 |
(for debugging only). |
20792 | 666 |
I don't like the name of this method; its here for compatibility." |
623 | 667 |
|
1810 | 668 |
^ self numTemps |
669 |
||
670 |
"Modified: 23.10.1996 / 16:19:06 / cg" |
|
623 | 671 |
! |
672 |
||
673 |
numArgs |
|
674 |
"return the number of arguments to the Block/Method" |
|
675 |
||
676 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
677 |
#ifdef __SCHTEAM__ |
18289 | 678 |
return context._RETURN(STInteger._new(self.asSTContinuation().numStArgs())); |
18190 | 679 |
#else |
8913 | 680 |
RETURN ( __mkSmallInteger( (__intVal(__INST(flags)) >> __NARG_SHIFT) & __NARG_MASK) ); |
18190 | 681 |
#endif |
623 | 682 |
%} |
683 |
! |
|
684 |
||
1810 | 685 |
numTemps |
686 |
"return the number of temporary variables of the Block/Method. |
|
687 |
(for debugging only)" |
|
688 |
||
18437 | 689 |
^ self size - self argumentCount - self numVars |
1810 | 690 |
|
691 |
"Created: 23.10.1996 / 16:19:10 / cg" |
|
692 |
"Modified: 23.10.1996 / 16:19:48 / cg" |
|
693 |
! |
|
694 |
||
695 |
numVars |
|
623 | 696 |
"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
|
697 |
|
623 | 698 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
699 |
#ifdef __SCHTEAM__ |
18289 | 700 |
return context._RETURN(STInteger._new(self.asSTContinuation().numLocals(context))); |
18190 | 701 |
#else |
8913 | 702 |
RETURN ( __mkSmallInteger( (__intVal(__INST(flags)) >> __NVAR_SHIFT) & __NVAR_MASK) ); |
18190 | 703 |
#endif |
623 | 704 |
%} |
705 |
! |
|
706 |
||
1810 | 707 |
nvars |
708 |
"return the number of local variables of the Block/Method. |
|
20792 | 709 |
I don't like the name of this method; its here for compatibility." |
1810 | 710 |
|
711 |
^ self numVars |
|
712 |
||
713 |
"Modified: 23.10.1996 / 16:18:44 / cg" |
|
714 |
! |
|
715 |
||
13426 | 716 |
programmingLanguage |
717 |
||
15933 | 718 |
^method notNil |
719 |
ifTrue:[method programmingLanguage] |
|
720 |
ifFalse:[SmalltalkLanguage instance] |
|
13426 | 721 |
|
722 |
"Created: / 17-03-2011 / 10:17:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
13543
63c783128bae
changed: #programmingLanguage
Claus Gittinger <cg@exept.de>
parents:
13519
diff
changeset
|
723 |
"Modified (format): / 02-08-2011 / 09:23:39 / cg" |
13426 | 724 |
! |
725 |
||
623 | 726 |
receiver |
727 |
"return the receiver of the context" |
|
18253 | 728 |
%{ /* NOCONTEXT */ |
729 |
#ifdef __SCHTEAM__ |
|
18289 | 730 |
return context._RETURN( self.asSTContinuation().stSelf(context) ); |
18253 | 731 |
#endif |
732 |
%}. |
|
623 | 733 |
^ receiver |
734 |
! |
|
735 |
||
4543 | 736 |
receiver:aCompiledCode |
737 |
"set the receiver of the message" |
|
738 |
||
4560
618151751813
Need _UNFIXCONTEXT() when changing receiver.
Stefan Vogel <sv@exept.de>
parents:
4557
diff
changeset
|
739 |
receiver := aCompiledCode. |
4543 | 740 |
|
4560
618151751813
Need _UNFIXCONTEXT() when changing receiver.
Stefan Vogel <sv@exept.de>
parents:
4557
diff
changeset
|
741 |
"/ need some aid for optimized code - |
618151751813
Need _UNFIXCONTEXT() when changing receiver.
Stefan Vogel <sv@exept.de>
parents:
4557
diff
changeset
|
742 |
"/ some machines have the arguments kept in register vars ... |
618151751813
Need _UNFIXCONTEXT() when changing receiver.
Stefan Vogel <sv@exept.de>
parents:
4557
diff
changeset
|
743 |
"/ the unfix updates the machine-stack version of the receiver. |
618151751813
Need _UNFIXCONTEXT() when changing receiver.
Stefan Vogel <sv@exept.de>
parents:
4557
diff
changeset
|
744 |
%{ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
745 |
#ifdef __SCHTEAM__ |
18190 | 746 |
ERROR("unimplemented"); |
747 |
#else |
|
4570 | 748 |
__UNFIXCONTEXT(self, 0); |
18190 | 749 |
#endif |
4560
618151751813
Need _UNFIXCONTEXT() when changing receiver.
Stefan Vogel <sv@exept.de>
parents:
4557
diff
changeset
|
750 |
%}. |
4543 | 751 |
|
752 |
! |
|
753 |
||
623 | 754 |
searchClass |
755 |
"this is the class where the method-lookup started; |
|
19448 | 756 |
for normal sends, it is nil (or sometimes the receiver's class). |
623 | 757 |
For supersends, its the superclass of the one, in which the |
758 |
caller was defined." |
|
759 |
||
760 |
searchClass notNil ifTrue:[^ searchClass]. |
|
761 |
^ receiver class |
|
762 |
! |
|
763 |
||
764 |
selector |
|
765 |
"return the selector of the method for which the context was created" |
|
766 |
||
767 |
^ selector |
|
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
768 |
! |
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
769 |
|
1 | 770 |
sender |
771 |
"return the sender of the context" |
|
772 |
||
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
773 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
774 |
#ifdef __SCHTEAM__ |
18406 | 775 |
STContinuation sender = self.sender(); |
776 |
if (sender == null) { |
|
777 |
return __c__._RETURN_nil(); |
|
778 |
} |
|
779 |
return __c__._RETURN(sender); |
|
18253 | 780 |
/* NOTREACHED */ |
18190 | 781 |
#else |
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
782 |
OBJ theContext; |
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
783 |
|
3508 | 784 |
theContext = __INST(sender_); |
949 | 785 |
/* |
786 |
* this special nil test is for the very first context (startup-context); |
|
787 |
* actually, its cosmetics, to avoid a visible nil>>nil context in the debugger. |
|
788 |
*/ |
|
2205 | 789 |
if (__isNonNilObject(theContext)) { |
949 | 790 |
|
15933 | 791 |
if (__isLazy(theContext)) { |
792 |
/* |
|
793 |
* this cannot happen |
|
794 |
*/ |
|
795 |
__PATCHUPCONTEXT(theContext); |
|
796 |
} |
|
797 |
if (! __isNonLIFO(theContext)) { |
|
798 |
/* |
|
799 |
* to be prepared for the worst situation |
|
800 |
* (the sender is not stored, so the trap won't catch it) |
|
801 |
* make the writeBarrier trigger manually. |
|
802 |
* We'll see, if this is really required. |
|
803 |
*/ |
|
804 |
theContext->o_space |= CATCHMARK; |
|
805 |
__markNonLIFO(theContext); |
|
806 |
} |
|
536
dcffd1753902
be safe, when accessing a contexts sender.
Claus Gittinger <cg@exept.de>
parents:
528
diff
changeset
|
807 |
} |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
808 |
RETURN (theContext); |
18190 | 809 |
#endif |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
810 |
%} |
1 | 811 |
! |
812 |
||
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
813 |
senderIsNil |
15319 | 814 |
"return true, if I have no sender. |
815 |
This little ugly piece of code is needed (instead of the obvious |
|
816 |
'sender isNil') because sender is a protected field, which cannot be |
|
817 |
directly accessed by smalltalk code. The reason is that the sender field |
|
818 |
is lazily filled in by the VM, in the sender-accessor, and is usually |
|
819 |
invalid until needed." |
|
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
820 |
|
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
821 |
%{ /* NOCONTEXT */ |
18412 | 822 |
#ifdef __SCHTEAM__ |
823 |
if (((STContinuation)self).caller == null) { |
|
824 |
return __c__._RETURN_true(); |
|
825 |
} |
|
826 |
return __c__._RETURN_false(); |
|
827 |
/* NOTREACHED */ |
|
828 |
#else |
|
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
829 |
if ( __INST(sender_) == nil ) { |
15933 | 830 |
RETURN (true); |
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
831 |
} |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
832 |
RETURN (false); |
18412 | 833 |
#endif |
5422 | 834 |
%}. |
18289 | 835 |
^ self sender isNil |
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
836 |
! |
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
837 |
|
623 | 838 |
setLineNumber:aNumber |
839 |
"private entry for uncompiledCodeObject ..." |
|
1 | 840 |
|
623 | 841 |
lineNr := aNumber |
340 | 842 |
! |
843 |
||
5749 | 844 |
setNumArgs:nA numVars:nV |
845 |
"set the number of arguments and variables" |
|
846 |
||
847 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
848 |
#ifdef __SCHTEAM__ |
18190 | 849 |
ERROR("unimplemented"); |
850 |
#else |
|
8910 | 851 |
INT flg; |
5749 | 852 |
|
853 |
flg = __intVal(__INST(flags)); |
|
854 |
flg = flg & ~(__NARG_MASK << __NARG_SHIFT); |
|
855 |
flg = flg & ~(__NVAR_MASK << __NVAR_SHIFT); |
|
856 |
flg = flg | __intVal(nA) << __NARG_SHIFT; |
|
857 |
flg = flg | __intVal(nV) << __NVAR_SHIFT; |
|
8913 | 858 |
__INST(flags) = __mkSmallInteger(flg); |
18190 | 859 |
#endif |
5749 | 860 |
%} |
861 |
! |
|
862 |
||
12841 | 863 |
tempAt:index |
8578 | 864 |
"return the n'th stack-temporary variable" |
865 |
||
866 |
^ self at:index |
|
867 |
! |
|
868 |
||
12841 | 869 |
temporaries |
202 | 870 |
"return an array filled with the temporaries of this context" |
871 |
||
308 | 872 |
|nonTemps mySize| |
202 | 873 |
|
18437 | 874 |
nonTemps := self argumentCount + self numVars. |
1810 | 875 |
mySize := self numTemps. |
3130 | 876 |
mySize == 0 ifTrue:[ |
18437 | 877 |
"/ little optimization here - avaoid creating empty containers |
878 |
^ #() |
|
3130 | 879 |
]. |
308 | 880 |
^ (Array new:mySize) replaceFrom:1 to:mySize with:self startingAt:nonTemps+1 |
1810 | 881 |
|
882 |
"Modified: 23.10.1996 / 16:20:00 / cg" |
|
202 | 883 |
! |
884 |
||
10 | 885 |
varAt:n |
886 |
"return the n'th local variable" |
|
887 |
||
18437 | 888 |
^ self at:(n + self argumentCount) |
10 | 889 |
! |
890 |
||
891 |
varAt:n put:value |
|
892 |
"set the n'th local variable - useful when the receiver should be restarted |
|
54 | 893 |
or continued" |
10 | 894 |
|
18437 | 895 |
self at:(n + self argumentCount) put:value |
10 | 896 |
! |
897 |
||
12841 | 898 |
vars |
623 | 899 |
"return an array filled with the local variables of this context" |
375 | 900 |
|
623 | 901 |
|nonVars mySize| |
360 | 902 |
|
18437 | 903 |
nonVars := self argumentCount. |
1810 | 904 |
mySize := self numVars. |
3130 | 905 |
mySize == 0 ifTrue:[ |
18437 | 906 |
"/ little optimization here - avaoid creating empty containers |
907 |
^ #() |
|
3130 | 908 |
]. |
623 | 909 |
^ (Array new:mySize) replaceFrom:1 to:mySize with:self startingAt:nonVars+1 |
1810 | 910 |
|
911 |
"Modified: 23.10.1996 / 16:20:06 / cg" |
|
1 | 912 |
! ! |
913 |
||
623 | 914 |
!Context methodsFor:'copying'! |
415 | 915 |
|
10943 | 916 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
10136 | 917 |
|copyOfMe| |
3350
40dc4807a6d4
must catch #deppCopyUsing: instead of #deepCopy.
Claus Gittinger <cg@exept.de>
parents:
3324
diff
changeset
|
918 |
|
10136 | 919 |
copyOfMe := self shallowCopy. |
920 |
copyOfMe setSender:nil. |
|
13516
9bbdb9d05a51
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13473
diff
changeset
|
921 |
copyOfMe perform:postCopySelector withOptionalArgument:self and:aDictionary. |
10136 | 922 |
^ copyOfMe |
923 |
||
924 |
"Created: / 31-03-1998 / 15:51:14 / cg" |
|
13516
9bbdb9d05a51
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13473
diff
changeset
|
925 |
"Modified: / 21-07-2011 / 13:30:21 / cg" |
1 | 926 |
! ! |
927 |
||
15010 | 928 |
!Context methodsFor:'enumerating'! |
929 |
||
930 |
withAllSendersDo:aBlock |
|
931 |
"evaluate aBlock for me and all contexts of my sender chain" |
|
932 |
||
21146 | 933 |
self withSendersUpToContextForWhich:[:con | false] do:aBlock |
934 |
! |
|
935 |
||
936 |
withSendersThroughContextForWhich:checkBlock do:aBlock |
|
937 |
"evaluate aBlock for me and all contexts of my sender chain, |
|
938 |
until checkBlock returns true (incl. that last one)" |
|
939 |
||
15010 | 940 |
|con| |
941 |
||
942 |
con := self. |
|
943 |
[ con notNil ] whileTrue:[ |
|
21146 | 944 |
aBlock value:con. |
945 |
(checkBlock value:con) ifTrue:[^ self]. |
|
946 |
con := con sender. |
|
947 |
] |
|
948 |
! |
|
949 |
||
950 |
withSendersUpToContextForWhich:checkBlock do:aBlock |
|
951 |
"evaluate aBlock for me and all contexts of my sender chain, |
|
952 |
until checkBlock returns true, excl. that context." |
|
953 |
||
954 |
|con| |
|
955 |
||
956 |
con := self. |
|
957 |
[ con notNil ] whileTrue:[ |
|
958 |
(checkBlock value:con) ifTrue:[^ self]. |
|
959 |
aBlock value:con. |
|
960 |
con := con sender. |
|
15010 | 961 |
] |
962 |
! ! |
|
963 |
||
77 | 964 |
!Context methodsFor:'error handling'! |
965 |
||
966 |
invalidReturn:returnValue |
|
967 |
"this message is sent by the VM, when a methods context |
|
968 |
which has already returned is about to return again. |
|
969 |
(i.e. about to execute a return from an already returned |
|
105 | 970 |
method in a block). |
141 | 971 |
We raise a signal here, to allow catching of that situation." |
77 | 972 |
|
406 | 973 |
" |
974 |
in previous versions of ST/X and ST-80, this was no error; |
|
975 |
(instead, a normal blockreturn was performed to the value-sender). |
|
976 |
From a note in comp.lang.smalltalk, I conclude that new ST-80 versions |
|
977 |
now raise an error if this happens. |
|
978 |
Comment out the raise below to get that (old) behavior |
|
979 |
BETTER REWRITE YOUR APPLICATION |
|
12841 | 980 |
" |
3258
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
981 |
"/ old behavior: |
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
982 |
"/ ^ returnValue |
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
983 |
|
282 | 984 |
"/ new behavior: |
985 |
||
3258
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
986 |
"/ 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
|
987 |
"/ use another error message. |
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
988 |
|
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
989 |
(home notNil and:[home sender notNil]) ifTrue:[ |
15933 | 990 |
^ CannotReturnError |
991 |
raiseRequestWith:returnValue |
|
992 |
errorString:'cannot return from another process''s context'. |
|
3258
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
993 |
]. |
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
994 |
|
12841 | 995 |
^ CannotReturnError |
15933 | 996 |
raiseRequestWith:returnValue. |
282 | 997 |
|
3258
2d96bba62ff1
use another error message if attempting to
Claus Gittinger <cg@exept.de>
parents:
3182
diff
changeset
|
998 |
"Modified: / 2.2.1998 / 15:19:52 / cg" |
406 | 999 |
! |
1000 |
||
1001 |
invalidReturnOrRestart:returnValue |
|
15268 | 1002 |
"this message is sent by the VM, when a method's or block's context |
1003 |
which was compiled non-returnable is about to return again, |
|
1004 |
or a non-restartable context is tried to be restarted. |
|
1005 |
In ST/X, not all contexts are restartable/returnable. |
|
406 | 1006 |
We raise a signal here, to allow catching of that situation." |
1007 |
||
6002 | 1008 |
^ CannotReturnError |
15933 | 1009 |
raiseRequestWith:returnValue |
1010 |
errorString:'method was compiled non-resumable' |
|
360 | 1011 |
! |
1012 |
||
1013 |
invalidReturnOrRestartError:how with:value |
|
1014 |
"common error reporter for restart/return errors" |
|
12841 | 1015 |
|
360 | 1016 |
self canReturn ifTrue:[ |
15933 | 1017 |
" |
1018 |
tried to return from/restart a context which is already dead |
|
1019 |
(i.e. the method/block has already executed a return) |
|
1020 |
" |
|
1021 |
^ CannotReturnError |
|
1022 |
raiseRequestWith:value |
|
1023 |
errorString:(how , ' context not on calling chain') |
|
360 | 1024 |
]. |
1025 |
" |
|
1026 |
tried to return from/restart a context of a method which was compiled |
|
1027 |
unrestartable or of a block (which is never restartable) |
|
1028 |
" |
|
12841 | 1029 |
^ CannotReturnError |
15933 | 1030 |
raiseRequestWith:value |
1031 |
errorString:(how , ' context cannot be restarted/returned from') |
|
77 | 1032 |
! ! |
1033 |
||
6404 | 1034 |
!Context methodsFor:'fixups'! |
1035 |
||
1036 |
fixAllLineNumbers |
|
1037 |
%{ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
1038 |
#ifdef __SCHTEAM__ |
18190 | 1039 |
ERROR("unimplemented"); |
1040 |
#else |
|
6404 | 1041 |
__PATCHUPCONTEXTS(__thisContext); |
6424 | 1042 |
__CONTEXTLINENOS(self); |
18190 | 1043 |
#endif |
6404 | 1044 |
%} |
1045 |
! ! |
|
1046 |
||
623 | 1047 |
!Context methodsFor:'minidebugger printing'! |
1048 |
||
1049 |
fullPrint |
|
12841 | 1050 |
"print the receiver, selector and args of the context |
20840 | 1051 |
- used only for MiniDebugger's walkback print" |
1052 |
||
1053 |
self receiverPrintString _errorPrint. ' ' _errorPrint. selector _errorPrint. |
|
18437 | 1054 |
self argumentCount ~~ 0 ifTrue: [ |
20840 | 1055 |
' ' _errorPrint. self argsDisplayString _errorPrint |
623 | 1056 |
]. |
20840 | 1057 |
' [' _errorPrint. self lineNumber _errorPrint. ']' _errorPrintCR |
623 | 1058 |
|
1059 |
" |
|
1060 |
thisContext fullPrint |
|
1061 |
" |
|
1426 | 1062 |
|
1063 |
"Modified: 20.5.1996 / 10:27:14 / cg" |
|
623 | 1064 |
! |
1065 |
||
1066 |
fullPrintAll |
|
1067 |
"print a full walkback starting at the receiver |
|
20840 | 1068 |
- used only for MiniDebugger's walkback print" |
623 | 1069 |
|
15010 | 1070 |
self withAllSendersDo:[:con | con fullPrint]. |
623 | 1071 |
|
1072 |
" |
|
1073 |
thisContext fullPrintAll |
|
1074 |
" |
|
2173 | 1075 |
! |
1076 |
||
4674 | 1077 |
fullPrintAllLevels:nOrNil |
1078 |
"print a full walkback starting at the receiver, only print n levels |
|
20840 | 1079 |
- used only for MiniDebugger's walkback print" |
4674 | 1080 |
|
1081 |
|context count| |
|
1082 |
||
1083 |
count := 0. |
|
1084 |
context := self. |
|
1085 |
[context notNil] whileTrue: [ |
|
20840 | 1086 |
context fullPrint. |
1087 |
context := context sender. |
|
1088 |
nOrNil notNil ifTrue:[ |
|
1089 |
(count := count+1) > nOrNil ifTrue:[^self]. |
|
1090 |
] |
|
4674 | 1091 |
] |
1092 |
||
1093 |
" |
|
6648 | 1094 |
thisContext fullPrintAllLevels:5 |
4674 | 1095 |
" |
1096 |
||
1097 |
"Created: / 3.9.1999 / 14:02:38 / ps" |
|
11540 | 1098 |
! |
1099 |
||
11542 | 1100 |
printAll |
1101 |
"print a full walkback starting at the receiver, only print n levels |
|
20840 | 1102 |
- used only for MiniDebugger's walkback print" |
11542 | 1103 |
|
1104 |
self printAllLevels:nil |
|
1105 |
||
1106 |
" |
|
1107 |
thisContext printAll |
|
1108 |
" |
|
1109 |
! |
|
1110 |
||
11540 | 1111 |
printAllLevels:nOrNil |
1112 |
"print a full walkback starting at the receiver, only print n levels |
|
20840 | 1113 |
- used only for MiniDebugger's walkback print" |
11540 | 1114 |
|
1115 |
|context count| |
|
1116 |
||
1117 |
count := 0. |
|
1118 |
context := self. |
|
16247 | 1119 |
'--------------------------' errorPrintCR. |
11540 | 1120 |
[context notNil] whileTrue: [ |
20840 | 1121 |
context errorPrintCR. |
1122 |
context := context sender. |
|
1123 |
nOrNil notNil ifTrue:[ |
|
1124 |
(count := count+1) > nOrNil ifTrue:[ |
|
1125 |
'--------------------------' errorPrintCR. |
|
1126 |
^ self |
|
1127 |
]. |
|
1128 |
] |
|
11545 | 1129 |
]. |
16247 | 1130 |
'--------------------------' errorPrintCR. |
11540 | 1131 |
|
1132 |
" |
|
1133 |
thisContext printAllLevels:5 |
|
1134 |
" |
|
24259 | 1135 |
! |
1136 |
||
1137 |
savePrint |
|
1138 |
"print the receiver-class and selector only |
|
1139 |
- used when there is a danger that printing results in errors" |
|
1140 |
||
1141 |
self receiver class name _errorPrint. ' ' _errorPrint. selector _errorPrint. |
|
1142 |
' [' _errorPrint. self lineNumber _errorPrint. ']' _errorPrintCR |
|
1143 |
||
1144 |
" |
|
1145 |
thisContext fullPrint |
|
1146 |
thisContext savePrint |
|
1147 |
" |
|
1148 |
||
1149 |
"Created: / 05-06-2019 / 20:25:05 / Claus Gittinger" |
|
623 | 1150 |
! ! |
1151 |
||
1 | 1152 |
!Context methodsFor:'non local control flow'! |
1153 |
||
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1154 |
evaluateUnwindActionsUpTo:aContext |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1155 |
"walk up the calling chain, looking for unwind-cleanup actions to |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1156 |
be performed. This depends upon those contexts being specially |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1157 |
marked using #markForUnwind. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1158 |
Returns the argument (i.e. non-nil), if all went well, |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1159 |
nil if aContext is not on the caller chain (definitely an error)" |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1160 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1161 |
|con unwindBlock| |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1162 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1163 |
" |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1164 |
start with this context, moving up, looking for unwind actions |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1165 |
" |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1166 |
con := self findNextUnwindContextOr:aContext. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1167 |
[con notNil and:[con ~~ aContext]] whileTrue:[ |
15933 | 1168 |
unwindBlock := con receiver unwindHandlerInContext:con. |
1169 |
con unmarkForUnwind. |
|
1170 |
unwindBlock value. |
|
1171 |
||
1172 |
con := con findNextUnwindContextOr:aContext. |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1173 |
]. |
11340
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
1174 |
"/ mhmh - the just unwound context could itself be markedForUnwind |
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
1175 |
(con notNil and:[con isMarkedForUnwind]) ifTrue:[ |
15933 | 1176 |
unwindBlock := con receiver unwindHandlerInContext:con. |
1177 |
con unmarkForUnwind. |
|
1178 |
unwindBlock value. |
|
11340
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
1179 |
]. |
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1180 |
^ con |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1181 |
! |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1182 |
|
15688 | 1183 |
resend |
1184 |
"EXPERIMENTAL: resend the context's message (to the same receiver). |
|
1185 |
if the method's implementation has been changed in the meanwhile (for example, in the debugger), |
|
1186 |
the new code is executed. Otherwise the same code is reexecuted from the start." |
|
1187 |
||
23647 | 1188 |
self returnDoing:[ |
1189 |
selector == #doIt ifTrue:[ |
|
1190 |
method valueWithReceiver:receiver arguments:(self args) selector:selector |
|
1191 |
] ifFalse:[ |
|
1192 |
receiver perform:selector withArguments:(self args) |
|
1193 |
]. |
|
1194 |
]. |
|
15688 | 1195 |
|
1196 |
" |
|
1197 |
when we arrive here, something went wrong. |
|
1198 |
debugging ... |
|
1199 |
" |
|
1200 |
^ self invalidReturnOrRestartError:#'resend' with:nil |
|
23647 | 1201 |
|
1202 |
"Modified: / 26-01-2019 / 19:58:25 / Claus Gittinger" |
|
15688 | 1203 |
! |
1204 |
||
1 | 1205 |
restart |
1206 |
"restart the receiver - i.e. the method is evaluated again. |
|
402 | 1207 |
if the context to restart already died, trigger an error. |
141 | 1208 |
This is a low level helper for unwindAndRestart. |
1209 |
||
12841 | 1210 |
NOTICE: |
15933 | 1211 |
NO unwind actions are performed - this is usually not |
1212 |
what you want (see Context>>unwindAndRestart). |
|
12841 | 1213 |
|
1214 |
LIMITATION: |
|
15933 | 1215 |
currently a context can only be restarted by |
1216 |
the owning process - not from outside. |
|
1217 |
Also, the compiler has an option (+optcontext) to create |
|
1218 |
non-restartable contexts (which are faster). |
|
1219 |
If such a context is restarted, a runtime error is raised." |
|
1 | 1220 |
|
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1221 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
1222 |
#ifdef __SCHTEAM__ |
18364 | 1223 |
return __c__.RESTART(self); |
1224 |
/* NOTREACHED */ |
|
18190 | 1225 |
#else |
15650 | 1226 |
if (__INST(sender_) == nil) { |
15933 | 1227 |
RETURN(nil); |
15650 | 1228 |
} else { |
15933 | 1229 |
__RESUMECONTEXT__(self, RESTART_VALUE, 0); |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1230 |
} |
18190 | 1231 |
#endif |
360 | 1232 |
%}. |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1233 |
|
69 | 1234 |
" |
360 | 1235 |
when we arrive here, something went wrong. |
69 | 1236 |
debugging ... |
1237 |
" |
|
360 | 1238 |
^ self invalidReturnOrRestartError:#restart with:nil |
1 | 1239 |
! |
1240 |
||
623 | 1241 |
resume |
1242 |
"resume execution in this context. I.e. as if the method called |
|
1243 |
last by the receiver did a ^ nil. |
|
1244 |
If the context has already returned, report an error. |
|
1245 |
||
1246 |
NOTICE: |
|
15933 | 1247 |
NO unwind actions are performed (see Context>>unwind). |
12841 | 1248 |
|
1249 |
LIMITATION: |
|
15933 | 1250 |
currently a context can only be resumed by |
1251 |
the owning process - not from outside. |
|
1252 |
Also, the compiler has an option (+optcontext) to create |
|
1253 |
non-resumable contexts (which are faster). |
|
1254 |
If such a context is restarted, a runtime error is raised." |
|
623 | 1255 |
|
1256 |
^ self resume:nil |
|
1257 |
! |
|
1258 |
||
1259 |
resume:value |
|
1260 |
"resume the receiver - as if it got 'value' from whatever |
|
19448 | 1261 |
it called. This continues execution in the receiver's method |
623 | 1262 |
after the point where it did its last send. |
12841 | 1263 |
If the context has already returned - report an error. |
623 | 1264 |
|
1265 |
NOTICE: |
|
19448 | 1266 |
NO unwind actions are performed (see Context>>unwind:). |
623 | 1267 |
|
12841 | 1268 |
LIMITATION: |
19448 | 1269 |
currently a context can only be resumed by |
1270 |
the owning process - not from outside. |
|
1271 |
Also, the compiler has an option (+optcontext) to create |
|
1272 |
non-resumable contexts (which are faster). |
|
1273 |
If such a context is restarted, a runtime error is raised." |
|
623 | 1274 |
|
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
1275 |
|theContext| |
623 | 1276 |
|
1277 |
" |
|
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
1278 |
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
|
1279 |
(i.e. the one that I have called) and return from it. |
623 | 1280 |
" |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1281 |
|
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
1282 |
%{ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
1283 |
#ifdef __SCHTEAM__ |
18408 | 1284 |
return __c__._RETURN_TO(value, self.asSTContinuation()); |
1285 |
/* NOTREACHED */ |
|
18190 | 1286 |
#else |
4557 | 1287 |
OBJ sndr; |
1288 |
||
2510
393a51424d60
avoid marking context as nonLifo (in unwind:)
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
1289 |
theContext = __thisContext; |
4557 | 1290 |
while (theContext != nil) { |
19448 | 1291 |
sndr = __ContextInstPtr(theContext)->c_sender; |
1292 |
if (sndr == self) break; |
|
1293 |
theContext = sndr; |
|
623 | 1294 |
} |
3508 | 1295 |
if (theContext != nil) { |
19448 | 1296 |
if (__isLazy(theContext)) { |
1297 |
__PATCHUPCONTEXT(theContext); |
|
1298 |
} |
|
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1299 |
} |
18190 | 1300 |
#endif |
623 | 1301 |
%}. |
1302 |
||
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
1303 |
theContext isNil ifTrue:[ |
19448 | 1304 |
" |
1305 |
tried to resume in context which is already dead |
|
1306 |
(i.e. the method/block has already executed a return) |
|
1307 |
" |
|
1308 |
^ thisContext invalidReturnOrRestartError:#'resume:' with:value |
|
623 | 1309 |
]. |
1668
41db5950f9ea
oops - con local variables are now renamed (last change in stc)
Claus Gittinger <cg@exept.de>
parents:
1492
diff
changeset
|
1310 |
^ theContext return:value |
623 | 1311 |
! |
1312 |
||
4557 | 1313 |
resumeIgnoringErrors:value |
1314 |
"resume the receiver - as if it got 'value' from whatever |
|
19448 | 1315 |
it called. This continues execution in the receiver's method |
4557 | 1316 |
after the point where it did its last send. |
12841 | 1317 |
If the context has already returned - simply return. |
4557 | 1318 |
|
1319 |
NOTICE: |
|
19448 | 1320 |
NO unwind actions are performed (see Context>>unwind:). |
4557 | 1321 |
|
12841 | 1322 |
LIMITATION: |
19448 | 1323 |
currently a context can only be resumed by |
1324 |
the owning process - not from outside. |
|
1325 |
Also, the compiler has an option (+optcontext) to create |
|
1326 |
non-resumable contexts (which are faster). |
|
1327 |
If such a context is restarted, a runtime error is raised." |
|
4557 | 1328 |
|
1329 |
" |
|
1330 |
starting with this context, find the one below |
|
1331 |
(i.e. the one that I have called) and return from it. |
|
1332 |
" |
|
1333 |
||
1334 |
%{ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
1335 |
#ifdef __SCHTEAM__ |
18408 | 1336 |
return __c__._RETURN_TO(value, self.asSTContinuation()); |
1337 |
/* NOTREACHED */ |
|
18190 | 1338 |
#else |
4557 | 1339 |
OBJ theContext, sndr; |
1340 |
||
1341 |
theContext = __thisContext; |
|
1342 |
while (theContext != nil) { |
|
19448 | 1343 |
sndr = __ContextInstPtr(theContext)->c_sender; |
1344 |
if (sndr == self) break; |
|
1345 |
theContext = sndr; |
|
4557 | 1346 |
} |
1347 |
if (theContext != nil) { |
|
19448 | 1348 |
if (__ContextInstPtr(theContext)->c_sender) { |
1349 |
if (!((INT)(__ContextInstPtr(theContext)->c_flags) & __MASKSMALLINT(__CANNOT_RETURN))) { |
|
1350 |
__RESUMECONTEXT__(theContext, value, 0); |
|
1351 |
} |
|
1352 |
} |
|
4557 | 1353 |
} |
18190 | 1354 |
#endif |
4557 | 1355 |
%}. |
1356 |
||
1357 |
"/ no error reporting |
|
1358 |
! |
|
1359 |
||
1360 |
resumeOnErrorProceed:value |
|
1361 |
"resume the receiver - as if it got 'value' from whatever |
|
19448 | 1362 |
it called. This continues execution in the receiver's method |
4557 | 1363 |
after the point where it did its last send. |
12841 | 1364 |
If the context has already returned - simply return. |
4557 | 1365 |
|
1366 |
NOTICE: |
|
19448 | 1367 |
NO unwind actions are performed (see Context>>unwind:). |
4557 | 1368 |
|
12841 | 1369 |
LIMITATION: |
19448 | 1370 |
currently a context can only be resumed by |
1371 |
the owning process - not from outside. |
|
1372 |
Also, the compiler has an option (+optcontext) to create |
|
1373 |
non-resumable contexts (which are faster). |
|
1374 |
If such a context is restarted, a runtime error is raised." |
|
4557 | 1375 |
|
1376 |
" |
|
1377 |
starting with this context, find the one below |
|
1378 |
(i.e. the one that I have called) and return from it. |
|
1379 |
" |
|
1380 |
||
1381 |
%{ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
1382 |
#ifdef __SCHTEAM__ |
18408 | 1383 |
return __c__._RETURN_TO(value, self.asSTContinuation()); |
1384 |
/* NOTREACHED */ |
|
18190 | 1385 |
#else |
4557 | 1386 |
OBJ theContext, sndr; |
1387 |
||
1388 |
theContext = __thisContext; |
|
1389 |
while (theContext != nil) { |
|
19448 | 1390 |
sndr = __ContextInstPtr(theContext)->c_sender; |
1391 |
if (sndr == self) break; |
|
1392 |
theContext = sndr; |
|
4557 | 1393 |
} |
1394 |
if (theContext != nil) { |
|
19448 | 1395 |
if (__ContextInstPtr(theContext)->c_sender) { |
1396 |
__RESUMECONTEXT__(theContext, value, 0); |
|
1397 |
} |
|
4557 | 1398 |
} |
18190 | 1399 |
#endif |
4557 | 1400 |
%}. |
1401 |
||
1402 |
"/ no error reporting |
|
1403 |
! |
|
1404 |
||
69 | 1405 |
return |
141 | 1406 |
"return from this context with nil. I.e. as if it did a ^ nil. |
1407 |
NOTICE: |
|
15933 | 1408 |
NO unwind actions are performed - this is usually not |
1409 |
what you want (See Context>>unwind). |
|
1410 |
This is a low level method - a helper for unwind. |
|
12841 | 1411 |
|
1412 |
LIMITATION: |
|
15933 | 1413 |
currently a context can only be returned by |
1414 |
the owning process - not from outside. |
|
1415 |
Also, the compiler has an option (+optcontext) to create |
|
1416 |
non-returnable contexts (which are faster). |
|
1417 |
If such a context is restarted, a runtime error is raised." |
|
141 | 1418 |
|
1419 |
^ self return:nil |
|
1 | 1420 |
! |
1421 |
||
69 | 1422 |
return:value |
1423 |
"return from this context as if it did a '^ value'. |
|
141 | 1424 |
NOTICE: |
15933 | 1425 |
NO unwind actions are performed - this is usually not |
1426 |
what you want (See Context>>unwind:). |
|
1427 |
This is a low level method - a helper for unwind. |
|
141 | 1428 |
|
12841 | 1429 |
LIMITATION: |
15933 | 1430 |
currently a context can only be returned by |
1431 |
the owning process - not from outside. |
|
1432 |
Also, the compiler has an option (+optcontext) to create |
|
1433 |
non-returnable contexts (which are faster). |
|
1434 |
If such a context is restarted, a runtime error is raised." |
|
1 | 1435 |
|
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1436 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
1437 |
#ifdef __SCHTEAM__ |
18408 | 1438 |
return __c__._RETURN_FROM(value, self.asSTContinuation()); |
1439 |
/* NOTREACHED */ |
|
18190 | 1440 |
#else |
15651 | 1441 |
if (__INST(sender_) == nil) { |
15933 | 1442 |
RETURN(nil); |
15651 | 1443 |
} else { |
15933 | 1444 |
__RESUMECONTEXT__(self, value, 0); |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1445 |
} |
18190 | 1446 |
#endif |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1447 |
%}. |
1 | 1448 |
|
69 | 1449 |
" |
360 | 1450 |
when we arrive here, something went wrong. |
69 | 1451 |
debugging ... |
1452 |
" |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1453 |
^ self invalidReturnOrRestartError:#'return' with:value |
1 | 1454 |
! |
1455 |
||
328 | 1456 |
returnDoing:aBlock |
1457 |
"return from this context as if it did a '^ aBlock value'. |
|
1458 |
The block is evaluated as if called by the receiver context; |
|
1459 |
NOT the true executing context. |
|
1460 |
NOTICE: |
|
15933 | 1461 |
NO unwind actions are performed - this is usually not |
1462 |
what you want (See Context>>unwindThenDo:). |
|
1463 |
This is a low level method - a helper for unwind. |
|
328 | 1464 |
|
1465 |
LIMITATION: |
|
15933 | 1466 |
currently a context can only be returned by |
1467 |
the owning process - not from outside. |
|
1468 |
Also, the compiler has an option (+optcontext) to create |
|
1469 |
non-returnable contexts (which are faster). |
|
1470 |
If such a context is restarted, a runtime error is raised." |
|
328 | 1471 |
|
12841 | 1472 |
%{ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
1473 |
#ifdef __SCHTEAM__ |
18190 | 1474 |
ERROR("unimplemented"); |
1475 |
#else |
|
15651 | 1476 |
if (__INST(sender_) == nil) { |
15933 | 1477 |
RETURN(nil); |
15651 | 1478 |
} else { |
15933 | 1479 |
__RESUMECONTEXT__(self, aBlock, 2); |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1480 |
} |
18190 | 1481 |
#endif |
360 | 1482 |
%}. |
2368
f13bc879cb45
dont allow direct access to sender
Claus Gittinger <cg@exept.de>
parents:
2291
diff
changeset
|
1483 |
|
328 | 1484 |
" |
360 | 1485 |
when we arrive here, something went wrong. |
328 | 1486 |
debugging ... |
1487 |
" |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1488 |
^ self invalidReturnOrRestartError:#'returnDoing' with:aBlock |
328 | 1489 |
! |
1490 |
||
1 | 1491 |
unwind |
69 | 1492 |
"return nil from the receiver - i.e. simulate a '^ nil'. |
11337 | 1493 |
If the context has already returned, report an error. |
1 | 1494 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
69 | 1495 |
and Block>>valueOnUnwindDo: on the way. |
1 | 1496 |
|
12841 | 1497 |
LIMITATION: |
15933 | 1498 |
currently a context can only be unwound by |
1499 |
the owning process - not from outside. |
|
1500 |
i.e. it is not possible for one thread to unwind |
|
1501 |
another threads context - which does not make sense anyway. |
|
1502 |
However, you can force another thread to do this in its own process |
|
1503 |
context, by giving it an interrupt action - this does make sense. |
|
1504 |
||
1505 |
Also, the compiler has an option (+optcontext) to create |
|
1506 |
non-returnable contexts (which are faster). |
|
1507 |
If such a context is restarted, a runtime error is raised." |
|
141 | 1508 |
|
1509 |
^ self unwind:nil |
|
1 | 1510 |
! |
1511 |
||
1512 |
unwind:value |
|
69 | 1513 |
"return value from the receiver - i.e. simulate a '^ value'. |
360 | 1514 |
If the context has already returned , report an error. |
1 | 1515 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
69 | 1516 |
and Block>>valueOnUnwindDo: on the way. |
141 | 1517 |
|
12841 | 1518 |
LIMITATION: |
15933 | 1519 |
currently a context can only be unwound by |
1520 |
the owning process - not from outside. |
|
1521 |
i.e. it is not possible for one thread to unwind |
|
1522 |
another threads context - which does not make sense anyway. |
|
1523 |
However, you can force another thread to do this in its own process |
|
1524 |
context, by giving it an interrupt action - this does make sense. |
|
1525 |
||
1526 |
Also, the compiler has an option (+optcontext) to create |
|
1527 |
non-returnable contexts (which are faster). |
|
1528 |
If such a context is restarted, a runtime error is raised." |
|
1 | 1529 |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1530 |
|con| |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1531 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1532 |
self senderIsNil ifFalse:[ |
15933 | 1533 |
con := thisContext evaluateUnwindActionsUpTo:self. |
141 | 1534 |
]. |
1 | 1535 |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1536 |
"oops, if nil, I am not on the calling chain; |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1537 |
(bad bad, unwind action have already been performed. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1538 |
should we check for this situation first and NOT evaluate |
141 | 1539 |
the unwind actions in this case ?) |
1540 |
" |
|
69 | 1541 |
con isNil ifTrue:[ |
15933 | 1542 |
" |
1543 |
tried to return to a context which is already dead |
|
1544 |
(i.e. the method/block has already executed a return) |
|
1545 |
" |
|
1546 |
^ self invalidReturnOrRestartError:#'unwind:' with:value |
|
69 | 1547 |
]. |
141 | 1548 |
" |
1549 |
now, that all unwind-actions are done, I can use the |
|
1550 |
low-level return ... |
|
1551 |
" |
|
1552 |
^ self return:value |
|
1553 |
! |
|
1554 |
||
1555 |
unwindAndRestart |
|
1556 |
"restart the receiver - i.e. the method is evaluated again. |
|
13804 | 1557 |
if the context to restart already did report an error. |
141 | 1558 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
1559 |
and Block>>valueOnUnwindDo: before restarting. |
|
1560 |
||
12841 | 1561 |
LIMITATION: |
15933 | 1562 |
a context can only be restarted by |
1563 |
the owning process - not from outside. |
|
1564 |
i.e. it is not possible for one thread to unwindAndRestart |
|
1565 |
another threads context - which does not make sense anyway. |
|
1566 |
However, you can force another thread to do this in its own process |
|
1567 |
context, by giving it an interrupt action - this does make sense. |
|
1568 |
||
1569 |
Also, the compiler has an option (+optcontext) to create |
|
1570 |
non-restartable contexts (which are faster). |
|
1571 |
If such a context is restarted, a runtime error is raised." |
|
552
694ecccaa1a0
only evaluate unwind blocks once
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1572 |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1573 |
|con| |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1574 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1575 |
self senderIsNil ifFalse:[ |
15933 | 1576 |
con := thisContext evaluateUnwindActionsUpTo:self. |
141 | 1577 |
]. |
1578 |
||
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1579 |
"oops, if nil, I am not on the calling chain; |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1580 |
(bad bad, unwind action have already been performed. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1581 |
should we check for this situation first and NOT evaluate |
141 | 1582 |
the unwind actions in this case ?) |
1583 |
" |
|
1584 |
con isNil ifTrue:[ |
|
15933 | 1585 |
" |
1586 |
tried to return to a context which is already dead |
|
1587 |
(i.e. the method/block has already executed a return) |
|
1588 |
" |
|
1589 |
^ self invalidReturnOrRestartError:#'unwindAndRestart:' with:nil |
|
141 | 1590 |
]. |
1591 |
" |
|
1592 |
now, that all unwind-actions are done, I can use the |
|
1593 |
low-level restart ... |
|
1594 |
" |
|
1595 |
^ self restart |
|
328 | 1596 |
! |
1597 |
||
4485 | 1598 |
unwindAndResume:value |
1599 |
"resume execution in the the receiver - i.e. simulate a '^ value' |
|
1600 |
from whatever it called last. |
|
1601 |
If the context has already returned , report an error. |
|
1602 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
|
1603 |
and Block>>valueOnUnwindDo: on the way. |
|
1604 |
||
12841 | 1605 |
LIMITATION: |
15933 | 1606 |
currently a context can only be unwound by |
1607 |
the owning process - not from outside. |
|
1608 |
i.e. it is not possible for one thread to unwind |
|
1609 |
another threads context - which does not make sense anyway. |
|
1610 |
However, you can force another thread to do this in its own process |
|
1611 |
context, by giving it an interrupt action - this does make sense. |
|
1612 |
||
1613 |
Also, the compiler has an option (+optcontext) to create |
|
1614 |
non-returnable contexts (which are faster). |
|
1615 |
If such a context is restarted, a runtime error is raised." |
|
4485 | 1616 |
|
1617 |
|con| |
|
1618 |
||
1619 |
self senderIsNil ifFalse:[ |
|
15933 | 1620 |
con := thisContext evaluateUnwindActionsUpTo:self. |
4485 | 1621 |
]. |
1622 |
||
1623 |
"oops, if nil, I am not on the calling chain; |
|
1624 |
(bad bad, unwind action have already been performed. |
|
1625 |
should we check for this situation first and NOT evaluate |
|
1626 |
the unwind actions in this case ?) |
|
1627 |
" |
|
1628 |
con isNil ifTrue:[ |
|
15933 | 1629 |
" |
1630 |
tried to return to a context which is already dead |
|
1631 |
(i.e. the method/block has already executed a return) |
|
1632 |
" |
|
1633 |
^ self invalidReturnOrRestartError:#'unwindAndResume:' with:value |
|
4485 | 1634 |
]. |
1635 |
" |
|
1636 |
now, that all unwind-actions are done, I can use the |
|
1637 |
low-level resume ... |
|
1638 |
" |
|
1639 |
^ self resume:value |
|
1640 |
! |
|
1641 |
||
12841 | 1642 |
unwindThenDo:aBlock |
328 | 1643 |
"return the value of aBlock from the receiver - i.e. simulate a '^ aBlock value'. |
13804 | 1644 |
If the context has already returned, report an error. |
328 | 1645 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
1646 |
and Block>>valueOnUnwindDo: on the way. |
|
1647 |
The block is evaluated AFTER all unwind actions are performed |
|
15688 | 1648 |
(i.e. the block's sender will be the receiving context, not the |
402 | 1649 |
currently executing context) |
328 | 1650 |
|
12841 | 1651 |
LIMITATION: |
15933 | 1652 |
currently a context can only be unwound by |
1653 |
the owning process - not from outside |
|
1654 |
i.e. it is not possible for one thread to unwindThenDo |
|
1655 |
another threads context - which does not make sense anyway. |
|
1656 |
However, you can force another thread to do this in its own process |
|
1657 |
context, by giving it an interrupt action - this does make sense. |
|
1658 |
||
1659 |
Also, the compiler has an option (+optcontext) to create |
|
1660 |
non-returnable contexts (which are faster). |
|
1661 |
If such a context is restarted, a runtime error is raised." |
|
328 | 1662 |
|
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1663 |
|con| |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1664 |
|
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1665 |
self senderIsNil ifFalse:[ |
15933 | 1666 |
con := thisContext evaluateUnwindActionsUpTo:self. |
328 | 1667 |
]. |
1668 |
||
4477
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1669 |
"oops, if nil, I am not on the calling chain; |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1670 |
(bad bad, unwind action have already been performed. |
ef99343d6756
better #unwind - ask receiver for handler block
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1671 |
should we check for this situation first and NOT evaluate |
328 | 1672 |
the unwind actions in this case ?) |
1673 |
" |
|
1674 |
con isNil ifTrue:[ |
|
15933 | 1675 |
" |
1676 |
tried to return to a context which is already dead |
|
1677 |
(i.e. the method/block has already executed a return) |
|
1678 |
" |
|
1679 |
^ self invalidReturnOrRestartError:#'unwindThenDo:' with:aBlock |
|
328 | 1680 |
]. |
1681 |
" |
|
1682 |
now, that all unwind-actions are done, I can use the |
|
1683 |
low-level return ... |
|
1684 |
" |
|
12841 | 1685 |
^ self returnDoing:aBlock |
15688 | 1686 |
! |
1687 |
||
1688 |
unwindThenResend |
|
1689 |
"EXPERIMENTAL: resend the context's message (to the same receiver). |
|
1690 |
if the method's implementation has been changed in the meanwhile (for example, in the debugger), |
|
1691 |
the new code is executed. Otherwise the same code is reexecuted from the start. |
|
1692 |
Evaluate all unwind-blocks as specified in Block>>valueNowOrOnUnwind: |
|
1693 |
and Block>>valueOnUnwindDo: on the way. |
|
1694 |
The resend happens AFTER all unwind actions are performed |
|
1695 |
||
1696 |
LIMITATION: |
|
15933 | 1697 |
currently a context can only be unwound by |
1698 |
the owning process - not from outside |
|
1699 |
i.e. it is not possible for one thread to unwindThenDo |
|
1700 |
another threads context - which does not make sense anyway. |
|
1701 |
However, you can force another thread to do this in its own process |
|
1702 |
context, by giving it an interrupt action - this does make sense. |
|
1703 |
||
1704 |
Also, the compiler has an option (+optcontext) to create |
|
1705 |
non-returnable contexts (which are faster). |
|
1706 |
If such a context is restarted, a runtime error is raised." |
|
15688 | 1707 |
|
1708 |
|con| |
|
1709 |
||
1710 |
self senderIsNil ifFalse:[ |
|
15933 | 1711 |
con := thisContext evaluateUnwindActionsUpTo:self. |
15688 | 1712 |
]. |
1713 |
||
1714 |
"oops, if nil, I am not on the calling chain; |
|
1715 |
(bad bad, unwind action have already been performed. |
|
1716 |
should we check for this situation first and NOT evaluate |
|
1717 |
the unwind actions in this case ?) |
|
1718 |
" |
|
1719 |
con isNil ifTrue:[ |
|
15933 | 1720 |
" |
1721 |
tried to return to a context which is already dead |
|
1722 |
(i.e. the method/block has already executed a return) |
|
1723 |
" |
|
1724 |
^ self invalidReturnOrRestartError:#'unwindThenResend' with:nil |
|
15688 | 1725 |
]. |
1726 |
||
1727 |
"/ now, that all unwind-actions are done, I can use the low-level resend... |
|
1728 |
^ self resend |
|
1 | 1729 |
! ! |
623 | 1730 |
|
1731 |
!Context methodsFor:'printing & storing'! |
|
1732 |
||
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1733 |
argStringFor:someObject |
15644 | 1734 |
|s| |
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1735 |
%{ |
18297
e0881b40ff42
safeReceiverName fix (was confusing and had wrong name)
Claus Gittinger <cg@exept.de>
parents:
18291
diff
changeset
|
1736 |
#ifndef __SCHTEAM__ |
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1737 |
/* |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1738 |
* 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
|
1739 |
* 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
|
1740 |
* which may lead to sends to free objects. In normal operation, this 'cannot' happen. |
14051 | 1741 |
* However, these print methods are also invoked for low-level pointer errors, so better be prepared... |
12841 | 1742 |
*/ |
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1743 |
if (__isNonNilObject(someObject) && (__qClass(someObject)==nil)) { |
23543 | 1744 |
RETURN(@symbol(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
|
1745 |
} |
18297
e0881b40ff42
safeReceiverName fix (was confusing and had wrong name)
Claus Gittinger <cg@exept.de>
parents:
18291
diff
changeset
|
1746 |
#endif /* not SCHTEAM */ |
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1747 |
%}. |
23543 | 1748 |
someObject isProtoObject ifTrue:[ |
1749 |
"take care, do not evaluate lazy or do sends to |
|
1750 |
a bridge when showing backtrace. Especially not after |
|
1751 |
timeout of a bridge call!!" |
|
1752 |
s := someObject class nameWithArticle. |
|
1753 |
] ifFalse:[ |
|
1754 |
s := someObject displayString. |
|
11539 | 1755 |
]. |
23543 | 1756 |
s isNil ifTrue:[ |
1757 |
^ '**************** nil displayString of ',(someObject class name ? '??'). |
|
1758 |
]. |
|
1759 |
^ s string. |
|
1760 |
||
1761 |
"Modified: / 23-11-2018 / 15:07:34 / Stefan Vogel" |
|
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1762 |
! |
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
1763 |
|
623 | 1764 |
argsDisplayString |
23543 | 1765 |
^ String streamContents:[:s | |
1766 |
self displayArgsOn:s withCRs:false indent:0 contractEachTo:100 |
|
1767 |
]. |
|
14051 | 1768 |
|
1769 |
"Modified (format): / 07-03-2012 / 13:11:17 / cg" |
|
23543 | 1770 |
"Modified: / 23-11-2018 / 14:41:51 / Stefan Vogel" |
623 | 1771 |
! |
1772 |
||
23512 | 1773 |
argsDisplayStringShort |
1774 |
^ String streamContents:[:s | |
|
1775 |
self displayArgsOn:s withCRs:false indent:0 contractEachTo:20. |
|
1776 |
] |
|
1777 |
||
1778 |
"Modified (format): / 07-03-2012 / 13:11:17 / cg" |
|
1779 |
! |
|
1780 |
||
21645 | 1781 |
displayArgsOn:aStream withCRs:withCRs indent:i |
23512 | 1782 |
self displayArgsOn:aStream withCRs:withCRs indent:i contractEachTo:100 |
1783 |
! |
|
1784 |
||
1785 |
displayArgsOn:aStream withCRs:withCRs indent:i contractEachTo:limitOrNil |
|
15933 | 1786 |
| n "{ Class: SmallInteger }" |
15388 | 1787 |
s | |
6648 | 1788 |
|
18437 | 1789 |
n := self argumentCount. |
6648 | 1790 |
1 to:n do:[:index | |
18437 | 1791 |
Error handle:[:ex | |
1792 |
s := '*Error in argString*'. |
|
1793 |
] do:[ |
|
1794 |
s := self argStringFor:(self at:index). |
|
23512 | 1795 |
limitOrNil notNil ifTrue:[ |
1796 |
s := s contractTo:limitOrNil. |
|
1797 |
]. |
|
18437 | 1798 |
]. |
1799 |
||
21645 | 1800 |
aStream spaces:i. |
23543 | 1801 |
aStream nextPutAll:s. |
21645 | 1802 |
withCRs ifTrue:[ |
1803 |
aStream cr. |
|
1804 |
] ifFalse:[ |
|
1805 |
index ~~ n ifTrue:[ aStream space ]. |
|
1806 |
]. |
|
6648 | 1807 |
]. |
14051 | 1808 |
|
21645 | 1809 |
"Created: / 15-03-2017 / 14:13:33 / cg" |
23543 | 1810 |
"Modified: / 23-11-2018 / 12:27:43 / Stefan Vogel" |
21645 | 1811 |
! |
1812 |
||
1813 |
displayLocalsOn:aStream withCRs:withCRs indent:i |
|
1814 |
| n "{ Class: SmallInteger }" |
|
1815 |
s | |
|
1816 |
||
1817 |
n := self argumentCount. |
|
1818 |
n+1 to:self size do:[:index | |
|
1819 |
Error handle:[:ex | |
|
1820 |
s := '*Error in localString*'. |
|
1821 |
] do:[ |
|
1822 |
s := self argStringFor:(self at:index). |
|
1823 |
s := s contractTo:100. |
|
1824 |
]. |
|
1825 |
aStream spaces:i. |
|
23543 | 1826 |
aStream nextPutAll:s. |
21645 | 1827 |
withCRs ifTrue:[ |
1828 |
aStream cr |
|
1829 |
] ifFalse:[ |
|
1830 |
index ~~ n ifTrue:[ aStream space ]. |
|
1831 |
]. |
|
1832 |
]. |
|
1833 |
||
1834 |
"Created: / 15-03-2017 / 14:13:23 / cg" |
|
23543 | 1835 |
"Modified: / 23-11-2018 / 12:27:28 / Stefan Vogel" |
6648 | 1836 |
! |
1837 |
||
14293
f1bc5da76f93
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14225
diff
changeset
|
1838 |
displayOn:aGCOrStream |
f1bc5da76f93
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14225
diff
changeset
|
1839 |
"return a string to display the receiver - for display in Inspector" |
f1bc5da76f93
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14225
diff
changeset
|
1840 |
|
f1bc5da76f93
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14225
diff
changeset
|
1841 |
(aGCOrStream isStream) ifFalse:[ |
23543 | 1842 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream; |
1843 |
"/ old ST80 means: draw-yourself on a GC. |
|
21529 | 1844 |
^ super displayOn:aGCOrStream |
14293
f1bc5da76f93
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14225
diff
changeset
|
1845 |
]. |
f1bc5da76f93
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14225
diff
changeset
|
1846 |
|
15933 | 1847 |
aGCOrStream |
21529 | 1848 |
nextPutAll:self class name; |
1849 |
nextPut:$(. |
|
14293
f1bc5da76f93
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14225
diff
changeset
|
1850 |
self printOn:aGCOrStream. |
f1bc5da76f93
Implement #displayOn: instead of #displayString
Stefan Vogel <sv@exept.de>
parents:
14225
diff
changeset
|
1851 |
aGCOrStream nextPut:$). |
21529 | 1852 |
|
1853 |
"Modified (comment): / 22-02-2017 / 16:47:42 / cg" |
|
23543 | 1854 |
"Modified (comment): / 23-11-2018 / 14:46:56 / Stefan Vogel" |
623 | 1855 |
! |
1856 |
||
6648 | 1857 |
fullPrintAllOn:aStream |
12789 | 1858 |
"print a full walkback (incl arguments) starting at the receiver" |
6648 | 1859 |
|
21645 | 1860 |
self fullPrintAllOn:aStream withVariables:false |
6648 | 1861 |
|
1862 |
" |
|
1863 |
thisContext fullPrintAllOn:Transcript |
|
1864 |
" |
|
1865 |
||
21645 | 1866 |
"Created: / 15-01-1997 / 18:09:05 / cg" |
1867 |
"Modified: / 15-03-2017 / 14:16:12 / cg" |
|
6648 | 1868 |
! |
1869 |
||
22201 | 1870 |
fullPrintAllOn:aStream levels:numLevels |
1871 |
"print a full walkback (incl arguments) starting at the receiver" |
|
1872 |
||
22202 | 1873 |
self fullPrintAllOn:aStream levels:numLevels indent:0 |
22201 | 1874 |
|
1875 |
" |
|
1876 |
thisContext fullPrintAllOn:Transcript levels:10 |
|
1877 |
" |
|
1878 |
||
1879 |
"Created: / 18-08-2017 / 15:12:17 / cg" |
|
22202 | 1880 |
"Modified: / 21-08-2017 / 19:14:58 / cg" |
1881 |
! |
|
1882 |
||
1883 |
fullPrintAllOn:aStream levels:numLevels indent:indent |
|
1884 |
"print a full walkback (incl arguments) starting at the receiver" |
|
1885 |
||
1886 |
|count| |
|
1887 |
||
1888 |
count := 0. |
|
1889 |
self |
|
1890 |
withSendersThroughContextForWhich:[:c | false] |
|
1891 |
do:[:con | |
|
1892 |
aStream spaces:indent. |
|
1893 |
con fullPrintOn:aStream. aStream cr. |
|
1894 |
count := count + 1. |
|
1895 |
count >= numLevels ifTrue:[^ self]. |
|
1896 |
]. |
|
1897 |
||
1898 |
" |
|
1899 |
thisContext fullPrintAllOn:Transcript levels:10 |
|
1900 |
" |
|
1901 |
||
1902 |
"Created: / 21-08-2017 / 19:14:46 / cg" |
|
22201 | 1903 |
! |
1904 |
||
18977 | 1905 |
fullPrintAllOn:aStream throughContextForWhich:aBlock |
23543 | 1906 |
"print a full walkback (inclusive arguments) starting at the receiver" |
18977 | 1907 |
|
21146 | 1908 |
self withSendersThroughContextForWhich:aBlock do:[:con | |
23543 | 1909 |
con fullPrintOn:aStream withVariables:false. aStream cr. |
18977 | 1910 |
]. |
1911 |
||
1912 |
" |
|
1913 |
thisContext fullPrintAllOn:Transcript throughContextForWhich:[:con | con selector == #doIt]. |
|
1914 |
" |
|
23543 | 1915 |
|
1916 |
"Modified (comment): / 23-11-2018 / 12:21:11 / Stefan Vogel" |
|
18977 | 1917 |
! |
1918 |
||
1919 |
fullPrintAllOn:aStream upToContextForWhich:aBlock |
|
1920 |
"print a full walkback (incl arguments) starting at the receiver" |
|
1921 |
||
21146 | 1922 |
self withSendersUpToContextForWhich:aBlock do:[:con | |
18977 | 1923 |
con fullPrintOn:aStream. aStream cr. |
1924 |
]. |
|
1925 |
||
1926 |
" |
|
1927 |
thisContext fullPrintAllOn:Transcript upToContextForWhich:[:con | con selector == #doIt]. |
|
1928 |
" |
|
1929 |
! |
|
1930 |
||
21645 | 1931 |
fullPrintAllOn:aStream withVariables:withVariables |
1932 |
"print a full walkback (incl arguments) starting at the receiver" |
|
1933 |
||
1934 |
self withAllSendersDo:[:con | con fullPrintOn:aStream withVariables:withVariables. aStream cr]. |
|
1935 |
||
1936 |
" |
|
1937 |
thisContext fullPrintAllOn:Transcript withVariables:true |
|
1938 |
" |
|
1939 |
||
1940 |
"Created: / 15-03-2017 / 14:14:41 / cg" |
|
1941 |
! |
|
1942 |
||
13612 | 1943 |
fullPrintAllString |
1944 |
"return a string containing the full walkback (incl. arguments)" |
|
1945 |
||
21146 | 1946 |
|s| |
1947 |
||
22506 | 1948 |
s := '' writeStream. |
21146 | 1949 |
self fullPrintAllOn:s. |
1950 |
^ s contents |
|
13612 | 1951 |
|
1952 |
" |
|
1953 |
thisContext fullPrintAllString |
|
1954 |
" |
|
1955 |
||
1956 |
"Created: / 21-08-2011 / 07:37:36 / cg" |
|
1957 |
! |
|
1958 |
||
6648 | 1959 |
fullPrintOn:aStream |
12789 | 1960 |
"append a verbose description (incl. arguments) of the receiver onto aStream" |
6648 | 1961 |
|
21645 | 1962 |
self fullPrintOn:aStream withVariables:false |
1963 |
||
1964 |
" |
|
1965 |
thisContext fullPrintOn:Transcript |
|
1966 |
thisContext sender fullPrintOn:Transcript |
|
1967 |
" |
|
1968 |
||
1969 |
"Created: / 15-01-1997 / 18:09:06 / cg" |
|
1970 |
"Modified (comment): / 15-03-2017 / 14:08:51 / cg" |
|
1971 |
! |
|
1972 |
||
1973 |
fullPrintOn:aStream withVariables:withVariables |
|
1974 |
"append a verbose description (incl. arguments) of the receiver onto aStream" |
|
1975 |
||
15383 | 1976 |
self printReceiverOn:aStream. |
12841 | 1977 |
aStream nextPutAll:' >> '. |
11311 | 1978 |
self selector printOn:aStream. "show as string (as symbol looks too ugly in browser ...)" |
1979 |
"/ self selector storeOn:aStream. "show as symbol" |
|
8578 | 1980 |
|
21645 | 1981 |
withVariables ifFalse:[ |
1982 |
self size ~~ 0 ifTrue: [ |
|
1983 |
aStream space. |
|
23543 | 1984 |
self displayArgsOn:aStream withCRs:false indent:0. |
21645 | 1985 |
]. |
6648 | 1986 |
]. |
12841 | 1987 |
aStream nextPutAll:' {'. |
1988 |
self identityHash printOn:aStream. |
|
15383 | 1989 |
aStream nextPut:$}. |
12841 | 1990 |
|
1991 |
aStream nextPutAll:' ['. |
|
6648 | 1992 |
self lineNumber printOn:aStream. |
15383 | 1993 |
aStream nextPut:$]. |
6648 | 1994 |
|
21645 | 1995 |
withVariables ifTrue:[ |
1996 |
self size ~~ 0 ifTrue: [ |
|
1997 |
self argumentCount ~~ 0 ifTrue:[ |
|
1998 |
aStream cr; nextPutAll:' Args:'; cr. |
|
1999 |
self displayArgsOn:aStream withCRs:true indent:4. |
|
2000 |
]. |
|
2001 |
self size > self argumentCount ifTrue:[ |
|
2002 |
aStream cr; nextPutAll:' Locals:'; cr. |
|
2003 |
self displayLocalsOn:aStream withCRs:true indent:4. |
|
2004 |
]. |
|
2005 |
]. |
|
2006 |
]. |
|
2007 |
||
6648 | 2008 |
" |
21645 | 2009 |
thisContext fullPrintOn:Transcript withVariables:true |
2010 |
" |
|
2011 |
||
2012 |
"Created: / 15-03-2017 / 13:24:16 / cg" |
|
23543 | 2013 |
"Modified: / 23-11-2018 / 14:44:28 / Stefan Vogel" |
6648 | 2014 |
! |
2015 |
||
623 | 2016 |
fullPrintString |
2017 |
"return a string describing the context - this includes the linenumber, |
|
2018 |
receiver printString and argument printString" |
|
2019 |
||
15644 | 2020 |
^ String streamContents:[:s | self fullPrintOn:s] |
623 | 2021 |
|
2022 |
" |
|
2023 |
thisContext fullPrintString |
|
2024 |
" |
|
2025 |
! |
|
2026 |
||
2027 |
methodPrintString |
|
12841 | 2028 |
"return a string describing the contexts method as 'implementorClass>>selector'" |
623 | 2029 |
|
1853
09cd1e8df9a2
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1810
diff
changeset
|
2030 |
|mthd who| |
623 | 2031 |
|
2032 |
mthd := self method. |
|
2033 |
mthd notNil ifTrue:[ |
|
15933 | 2034 |
who := mthd who. |
2035 |
who notNil ifTrue:[ |
|
2036 |
^ who methodClass name , ' >> #' , who methodSelector |
|
2037 |
] |
|
623 | 2038 |
]. |
2039 |
^ mthd displayString. |
|
2040 |
||
2041 |
" |
|
12841 | 2042 |
thisContext methodPrintString |
2043 |
thisContext sender methodPrintString |
|
623 | 2044 |
" |
1853
09cd1e8df9a2
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1810
diff
changeset
|
2045 |
|
09cd1e8df9a2
use new Method>>who interface
Claus Gittinger <cg@exept.de>
parents:
1810
diff
changeset
|
2046 |
"Modified: 1.11.1996 / 16:21:49 / cg" |
623 | 2047 |
! |
2048 |
||
12789 | 2049 |
printAllOn:aStream |
2050 |
"print a brief walkback (excl. arguments) starting at the receiver" |
|
2051 |
||
15010 | 2052 |
self withAllSendersDo:[:con | con printOn:aStream. aStream cr]. |
12789 | 2053 |
|
2054 |
" |
|
2055 |
thisContext printAllOn:Transcript |
|
2056 |
" |
|
2057 |
||
2058 |
"Created: 15.1.1997 / 18:09:05 / cg" |
|
2059 |
! |
|
2060 |
||
21146 | 2061 |
printAllOn:aStream throughContextForWhich:aBlock |
2062 |
"print a short walkback (excl. arguments) starting at the receiver" |
|
2063 |
||
2064 |
self withSendersThroughContextForWhich:aBlock do:[:con | |
|
2065 |
con printOn:aStream. aStream cr. |
|
2066 |
]. |
|
2067 |
||
2068 |
" |
|
2069 |
thisContext printAllOn:Transcript throughContextForWhich:[:con | con selector == #doIt]. |
|
2070 |
" |
|
2071 |
! |
|
2072 |
||
2073 |
printAllOn:aStream upToContextForWhich:aBlock |
|
2074 |
"print a short walkback (excl. arguments) starting at the receiver" |
|
2075 |
||
2076 |
self withSendersUpToContextForWhich:aBlock do:[:con | |
|
2077 |
con printOn:aStream. aStream cr. |
|
2078 |
]. |
|
2079 |
||
2080 |
" |
|
2081 |
thisContext printAllOn:Transcript upToContextForWhich:[:con | con selector == #withCursor:do:]. |
|
2082 |
" |
|
2083 |
! |
|
2084 |
||
13612 | 2085 |
printAllString |
2086 |
"return a string containing the walkback (excl. arguments)" |
|
2087 |
||
2088 |
|s| |
|
2089 |
||
22506 | 2090 |
s := '' writeStream. |
13612 | 2091 |
self printAllOn:s. |
2092 |
^ s contents |
|
2093 |
||
2094 |
" |
|
2095 |
thisContext printAllString |
|
2096 |
" |
|
2097 |
||
2098 |
"Created: / 21-08-2011 / 07:38:05 / cg" |
|
2099 |
! |
|
2100 |
||
16223 | 2101 |
printClassNameOf:aClass on:aStream |
2102 |
"helper for printing" |
|
2103 |
||
16819
c96b396b7307
Oops, fix in Context >> printClassNameOf:on: for Java static methods
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16818
diff
changeset
|
2104 |
| nonMeta | |
c96b396b7307
Oops, fix in Context >> printClassNameOf:on: for Java static methods
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16818
diff
changeset
|
2105 |
|
21923 | 2106 |
nonMeta := aClass theNonMetaclass. |
2107 |
nonMeta isJavaClass ifTrue:[ |
|
2108 |
nonMeta javaName printOn: aStream |
|
16223 | 2109 |
] ifFalse:[ |
21923 | 2110 |
(aClass name ? '????') printOn:aStream. |
16223 | 2111 |
]. |
16818
2f2ff0820cef
Fixes in Context>>#printClassNameOf:on: / #printOn: for Java classes.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16797
diff
changeset
|
2112 |
|
16819
c96b396b7307
Oops, fix in Context >> printClassNameOf:on: for Java static methods
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
16818
diff
changeset
|
2113 |
"Modified: / 08-08-2014 / 09:39:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
16223 | 2114 |
! |
2115 |
||
623 | 2116 |
printOn:aStream |
12789 | 2117 |
"append a brief description (excl. arguments) of the receiver onto aStream" |
623 | 2118 |
|
22601 | 2119 |
self printWithSeparator:' >> ' on:aStream |
623 | 2120 |
! |
2121 |
||
15383 | 2122 |
printReceiverOn:aStream |
2123 |
"print description of the receiver of the context to aStream" |
|
2124 |
||
2125 |
|receiverClass receiverClassName implementorClass| |
|
2126 |
||
18297
e0881b40ff42
safeReceiverName fix (was confusing and had wrong name)
Claus Gittinger <cg@exept.de>
parents:
18291
diff
changeset
|
2127 |
receiverClassName := self safeReceiverClassNameIfInvalid. |
15383 | 2128 |
receiverClassName notNil ifTrue:[ |
23224 | 2129 |
"if we come here, this is a context with an illegal class" |
2130 |
receiverClassName printOn:aStream. |
|
2131 |
^ self. |
|
15383 | 2132 |
]. |
1070
cf35b237612d
in argPrint: handle invalid objects (avoids crash in MiniDebugger when debugging bad primitives)
Claus Gittinger <cg@exept.de>
parents:
1051
diff
changeset
|
2133 |
|
623 | 2134 |
receiverClass := receiver class. |
15383 | 2135 |
|
2136 |
(receiverClass == SmallInteger or:[receiverClass == Float]) ifTrue:[ |
|
23224 | 2137 |
aStream nextPut:$(. receiver printOn:aStream. aStream nextPutAll:') '. |
15383 | 2138 |
]. |
16223 | 2139 |
self printClassNameOf:receiverClass on:aStream. |
15383 | 2140 |
|
2141 |
(selector notNil or:[method notNil]) ifTrue:[ |
|
23224 | 2142 |
"/ implementorClass := self searchClass whichClassIncludesSelector:selector. |
2143 |
||
2144 |
" |
|
2145 |
kludge to avoid slow search for containing class |
|
2146 |
" |
|
2147 |
(method notNil |
|
2148 |
or:[selector ~~ #doIt and:[selector ~~ #doIt:]]) ifTrue:[ |
|
2149 |
implementorClass := self methodClass. |
|
2150 |
implementorClass isNil ifTrue:[ |
|
2151 |
" |
|
2152 |
kludge for the frame called by a wrappedmethod; |
|
2153 |
the wrappedmethod is in the class, so its mclass is correct. |
|
2154 |
however, the originalmethod is invoked via performMethod, and its mclass |
|
2155 |
is nil. Care for this here. Think about keeping the mclass in the original method. |
|
2156 |
" |
|
2157 |
(method notNil and:[method isWrapped not]) ifTrue:[ |
|
2158 |
WrappedMethod notNil ifTrue:[ |
|
2159 |
WrappedMethod allWrappedMethodsDo:[:wrapped | |
|
2160 |
wrapped originalMethodIfWrapped == method ifTrue:[ |
|
2161 |
implementorClass := wrapped mclass. |
|
2162 |
]. |
|
2163 |
]. |
|
2164 |
]. |
|
2165 |
] |
|
2166 |
]. |
|
2167 |
]. |
|
2168 |
||
2169 |
implementorClass notNil ifTrue: [ |
|
2170 |
(implementorClass ~~ receiverClass) ifTrue: [ |
|
2171 |
aStream nextPut:$(. |
|
2172 |
self printClassNameOf:implementorClass on:aStream. |
|
2173 |
aStream nextPut:$). |
|
2174 |
] |
|
2175 |
] ifFalse:[ |
|
2176 |
| srchClass where | |
|
2177 |
||
2178 |
srchClass := self searchClass. |
|
2179 |
srchClass ~~ receiverClass ifTrue:[ |
|
2180 |
aStream nextPut:$(. |
|
2181 |
self printClassNameOf:srchClass on:aStream. |
|
2182 |
aStream nextPut:$). |
|
2183 |
]. |
|
2184 |
" |
|
2185 |
kludge for doIt - these unbound methods are not |
|
2186 |
found in the classes methodDictionary |
|
2187 |
" |
|
2188 |
true "(selector ~~ #doIt and:[selector ~~ #doIt:])" ifTrue:[ |
|
2189 |
" |
|
2190 |
kludge for methods invoked explicitly via valueWithReceiver... |
|
2191 |
" |
|
2192 |
(self sender notNil |
|
2193 |
and:[ self sender isBridgeProxy not |
|
23259 | 2194 |
and:[ self sender receiver isBridgeProxy not |
23224 | 2195 |
and:[ self sender receiver isMethod |
23259 | 2196 |
and:[ self sender selector startsWith:'valueWithReceiver:' ]]]]) ifTrue:[ |
23224 | 2197 |
where := '(**DIRECTED**)'. |
2198 |
] ifFalse:[ |
|
2199 |
where := '(**NONE**)'. |
|
2200 |
]. |
|
2201 |
aStream nextPutAll:where |
|
2202 |
] |
|
2203 |
] |
|
623 | 2204 |
]. |
2205 |
||
15961 | 2206 |
"Created: / 23-10-2013 / 11:13:19 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
2207 |
"Modified: / 05-02-2014 / 17:50:33 / cg" |
|
23259 | 2208 |
"Modified: / 03-08-2018 / 08:44:19 / Claus Gittinger" |
10549 | 2209 |
! |
2210 |
||
22601 | 2211 |
printWithSeparator:sep on:aStream |
2212 |
"append a brief description (excl. arguments) of the receiver onto aStream" |
|
2213 |
||
2214 |
| m | |
|
2215 |
||
2216 |
self printReceiverOn:aStream. |
|
23133 | 2217 |
|
2218 |
(self isBlockContext and:[self selector == #value]) ifFalse:[ |
|
2219 |
||
2220 |
"/ aStream nextPutAll:' '. |
|
2221 |
aStream nextPutAll:sep. |
|
2222 |
||
2223 |
aStream bold. |
|
2224 |
m := self method. |
|
2225 |
m isJavaMethod ifTrue:[ |
|
2226 |
aStream nextPutAll: (m printStringForBrowserWithSelector: self selector). |
|
2227 |
] ifFalse:[ |
|
2228 |
self selector printOn:aStream. "show as string (as symbol looks too ugly in browser ...)" |
|
2229 |
"/ self selector storeOn:aStream. "show as symbol" |
|
2230 |
]. |
|
2231 |
aStream normal. |
|
22601 | 2232 |
]. |
23133 | 2233 |
|
22601 | 2234 |
(method notNil and:[method isWrapped]) ifTrue:[ |
2235 |
aStream nextPutAll:' (wrapped) ' |
|
2236 |
]. |
|
2237 |
aStream nextPutAll:' ['. |
|
2238 |
m isJavaMethod ifTrue:[ |
|
2239 |
aStream nextPutAll: self method mclass sourceFile ? '???' . |
|
2240 |
m isNative ifTrue:[ |
|
2241 |
aStream nextPutAll: ':in native code' |
|
2242 |
] ifFalse:[ |
|
2243 |
aStream nextPut: $:. |
|
2244 |
(m lineNumberForPC0: lineNr) ? '???' printOn: aStream. |
|
2245 |
]. |
|
2246 |
] ifFalse:[ |
|
2247 |
self lineNumber printOn: aStream |
|
2248 |
]. |
|
2249 |
aStream nextPut:$]. |
|
2250 |
||
2251 |
"Modified: / 05-08-2012 / 12:00:00 / cg" |
|
2252 |
"Modified: / 08-08-2014 / 07:37:24 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
23133 | 2253 |
"Modified: / 26-06-2018 / 19:22:56 / Claus Gittinger" |
22601 | 2254 |
! |
2255 |
||
15383 | 2256 |
receiverPrintString |
2257 |
"return a string describing the receiver of the context" |
|
2258 |
||
2259 |
|s| |
|
2260 |
||
22506 | 2261 |
s := '' writeStream. |
15383 | 2262 |
self printReceiverOn:s. |
2263 |
^ s contents |
|
2264 |
||
2265 |
" |
|
22506 | 2266 |
thisContext receiverPrintString |
15383 | 2267 |
" |
2268 |
! |
|
2269 |
||
18297
e0881b40ff42
safeReceiverName fix (was confusing and had wrong name)
Claus Gittinger <cg@exept.de>
parents:
18291
diff
changeset
|
2270 |
safeReceiverClassNameIfInvalid |
e0881b40ff42
safeReceiverName fix (was confusing and had wrong name)
Claus Gittinger <cg@exept.de>
parents:
18291
diff
changeset
|
2271 |
"if the receiver refers to an invalid object, |
e0881b40ff42
safeReceiverName fix (was confusing and had wrong name)
Claus Gittinger <cg@exept.de>
parents:
18291
diff
changeset
|
2272 |
return a replacement string. otherwise nil. |
10549 | 2273 |
This cares for invalid (free) objects which may appear with bad primitive code, |
2274 |
and prevents a crash in such a case." |
|
2275 |
||
2276 |
%{ |
|
18412 | 2277 |
#ifdef __SCHTEAM__ |
2278 |
return __c__._RETURN( ((STContinuation)self).stSelf(__c__) ); |
|
2279 |
#else |
|
10549 | 2280 |
/* |
2281 |
* special handling for (invalid) free objects. |
|
2282 |
* these only appear if some primitiveCode does not correctly use SEND macros, |
|
2283 |
* which may lead to sends to free objects. In normal operation, this 'cannot' happen. |
|
12841 | 2284 |
*/ |
10549 | 2285 |
if (__isNonNilObject(__INST(receiver)) && (__qClass(__INST(receiver))==nil)) { |
18297
e0881b40ff42
safeReceiverName fix (was confusing and had wrong name)
Claus Gittinger <cg@exept.de>
parents:
18291
diff
changeset
|
2286 |
RETURN( __MKSTRING("FreeObject") ); |
10549 | 2287 |
} |
18297
e0881b40ff42
safeReceiverName fix (was confusing and had wrong name)
Claus Gittinger <cg@exept.de>
parents:
18291
diff
changeset
|
2288 |
#endif /* not SCHTEAM */ |
10549 | 2289 |
%}. |
18297
e0881b40ff42
safeReceiverName fix (was confusing and had wrong name)
Claus Gittinger <cg@exept.de>
parents:
18291
diff
changeset
|
2290 |
^ nil |
10549 | 2291 |
|
2292 |
"Created: / 21-05-2007 / 13:19:37 / cg" |
|
623 | 2293 |
! ! |
2294 |
||
7257 | 2295 |
!Context methodsFor:'private-accessing'! |
623 | 2296 |
|
11340
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2297 |
isMarkedForUnwind |
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2298 |
"true if the mark for unwind flag is set in the receiver. |
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2299 |
The VM needs this to know that some special action is to be performed with |
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2300 |
this context - a highly internal mechanism and not for public use." |
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2301 |
|
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2302 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2303 |
#ifdef __SCHTEAM__ |
18412 | 2304 |
return context._RETURN ( ((STContinuation)self).isMarkedForUnwind() ); |
18190 | 2305 |
#else |
18253 | 2306 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__UNWIND_MARK)) ? true : false ); |
18190 | 2307 |
#endif |
11340
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2308 |
%} |
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2309 |
" |
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2310 |
thisContext isMarkedForUnwind |
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2311 |
" |
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2312 |
! |
ceae06796c52
unwinding fixed for on:do:ensure:
Claus Gittinger <cg@exept.de>
parents:
11337
diff
changeset
|
2313 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2314 |
markForHandle |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2315 |
"set the mark for exception handle flag in the receiver. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2316 |
The VM needs this to know that some special action is to be performed with |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2317 |
this context - a highly internal mechanism and not for public use." |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2318 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2319 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2320 |
#ifdef __SCHTEAM__ |
18412 | 2321 |
((STContinuation)self).markForHandle(); |
18190 | 2322 |
#else |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2323 |
__INST(flags) = (OBJ)((INT)__INST(flags) | __MASKSMALLINT(__HANDLE_MARK)); |
18190 | 2324 |
#endif |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2325 |
%} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2326 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2327 |
"Modified: 13.12.1995 / 19:05:22 / cg" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2328 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2329 |
|
753
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
2330 |
markForInterrupt |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
2331 |
"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
|
2332 |
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
|
2333 |
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
|
2334 |
|
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
2335 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2336 |
#ifdef __SCHTEAM__ |
18412 | 2337 |
((STContinuation)self).markForInterrupt(); |
18190 | 2338 |
#else |
753
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
2339 |
__markInterrupted(__ContextInstPtr(self)); |
18190 | 2340 |
#endif |
753
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
2341 |
%} |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
2342 |
! |
81d54fc53a18
added mechanism to force a stepInterrupt whenever a context returns or unwinds
Claus Gittinger <cg@exept.de>
parents:
749
diff
changeset
|
2343 |
|
1727 | 2344 |
markForInterruptOnUnwind |
2345 |
"set the interrupt-on-unwind flag in the receiver. |
|
2346 |
The VM will generate a stepInterrupt, when this context returns or |
|
2347 |
is unwound. This is used by the debugger for faster single-stepping; |
|
2348 |
- a highly internal mechanism and not for public use." |
|
2349 |
||
2350 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2351 |
#ifdef __SCHTEAM__ |
18412 | 2352 |
((STContinuation)self).markForInterruptOnUnwind(); |
18190 | 2353 |
#else |
3508 | 2354 |
__INST(flags) = (OBJ)((INT)__INST(flags) | __MASKSMALLINT(__IRQ_ON_UNWIND)); |
18190 | 2355 |
#endif |
1727 | 2356 |
%} |
2357 |
! |
|
2358 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2359 |
markForRaise |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2360 |
"set the mark for exception raise flag in the receiver. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2361 |
The VM needs this to know that some special action is to be performed with |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2362 |
this context - a highly internal mechanism and not for public use." |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2363 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2364 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2365 |
#ifdef __SCHTEAM__ |
18412 | 2366 |
((STContinuation)self).markForRaise(); |
18190 | 2367 |
#else |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2368 |
__INST(flags) = (OBJ)((INT)__INST(flags) | __MASKSMALLINT(__RAISE_MARK)); |
18190 | 2369 |
#endif |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2370 |
%} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2371 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2372 |
"Modified: 13.12.1995 / 19:05:22 / cg" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2373 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2374 |
|
623 | 2375 |
markForUnwind |
749 | 2376 |
"set the mark for unwind flag in the receiver. |
2377 |
The VM needs this to know that some special action is to be performed with |
|
2378 |
this context - a highly internal mechanism and not for public use." |
|
2379 |
||
623 | 2380 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2381 |
#ifdef __SCHTEAM__ |
18412 | 2382 |
((STContinuation)self).markForUnwind(); |
18190 | 2383 |
#else |
1133 | 2384 |
__INST(flags) = (OBJ)((INT)__INST(flags) | __MASKSMALLINT(__UNWIND_MARK)); |
18190 | 2385 |
#endif |
623 | 2386 |
%} |
749 | 2387 |
|
2388 |
"Modified: 13.12.1995 / 19:05:22 / cg" |
|
623 | 2389 |
! |
2390 |
||
5780 | 2391 |
setHome:aContext |
2392 |
"set the homeContext. |
|
2393 |
DANGER: this is for experimental, internal use only (byteCode interpreters)" |
|
2394 |
||
2395 |
home := aContext. |
|
2396 |
! |
|
2397 |
||
2398 |
setSender:aContext |
|
2399 |
"set the sender of the context. |
|
2400 |
DANGER: this is for experimental, internal use only (byteCode interpreters)" |
|
2401 |
||
2402 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2403 |
#ifdef __SCHTEAM__ |
18412 | 2404 |
((STContinuation)self).caller = aContext.asSTContinuation(); |
18190 | 2405 |
#else |
5780 | 2406 |
__INST(sender_) = aContext; |
18190 | 2407 |
#endif |
5780 | 2408 |
%} |
2409 |
! |
|
2410 |
||
623 | 2411 |
unmarkForUnwind |
749 | 2412 |
"clear the mark for unwind flag in the receiver. |
2413 |
The VM needs this to know that some special action is to be performed with |
|
2414 |
this context - a highly internal mechanism and not for public use." |
|
2415 |
||
623 | 2416 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2417 |
#ifdef __SCHTEAM__ |
18412 | 2418 |
((STContinuation)self).unmarkForUnwind(); |
18190 | 2419 |
#else |
1133 | 2420 |
__INST(flags) = (OBJ)((INT)__INST(flags) & ~__MASKSMALLINT(__UNWIND_MARK)); |
18190 | 2421 |
#endif |
623 | 2422 |
%} |
2423 |
! ! |
|
2424 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2425 |
!Context methodsFor:'searching'! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2426 |
|
8284 | 2427 |
findExceptional |
12841 | 2428 |
"walk along the sender chain (starting with the sender), |
8284 | 2429 |
for a context which is marked as handle or raise context. |
2430 |
This non-standard interface is only to be used by exception" |
|
2431 |
||
2432 |
"/ this could have been (actually: was) implemented as: |
|
2433 |
"/ |
|
2434 |
"/ |con| |
|
2435 |
"/ |
|
2436 |
"/ con := self. |
|
2437 |
"/ [con notNil] whileTrue:[ |
|
2438 |
"/ [con isHandleContext] ifTrue:[^con]. |
|
2439 |
"/ [con isRaiseContext] ifTrue:[^con]. |
|
2440 |
"/ con := con sender. |
|
2441 |
"/ ]. |
|
2442 |
"/ ^ nil |
|
2443 |
"/ |
|
2444 |
"/ and the code below does exactly this (somewhat faster, though). |
|
2445 |
"/ |
|
2446 |
"/ (it avoids referencing all intermediate contexts, which would mark them special, |
|
2447 |
"/ although they aren't really - this is expert knowledge, no need to understand that ...) |
|
2448 |
||
2449 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2450 |
#ifdef __SCHTEAM__ |
18253 | 2451 |
{ |
18412 | 2452 |
STContinuation lastCallee = (STContinuation)self; |
2453 |
STContinuation caller = lastCallee.caller; |
|
18406 | 2454 |
|
2455 |
while (caller != null) { |
|
18253 | 2456 |
if (caller.isExceptionalSmalltalkContext()) { |
18412 | 2457 |
caller = lastCallee.sender(); // exposed |
18253 | 2458 |
return context._RETURN(caller); |
2459 |
} |
|
18412 | 2460 |
lastCallee = caller; |
2461 |
caller = lastCallee.caller; |
|
18253 | 2462 |
} |
2463 |
return context._RETURN( STObject.Nil ); |
|
2464 |
} |
|
2465 |
/* NOTREACHED */ |
|
18190 | 2466 |
#else |
8284 | 2467 |
OBJ theContext; |
2468 |
||
2469 |
theContext = self; |
|
2470 |
while (__isNonNilObject(theContext)) { |
|
15933 | 2471 |
if ((INT)(__ContextInstPtr(theContext)->c_flags) & __MASKSMALLINT(__HANDLE_MARK|__RAISE_MARK)) { |
2472 |
if (__isLazy(theContext)) { |
|
2473 |
__PATCHUPCONTEXT(theContext); |
|
2474 |
} |
|
2475 |
||
2476 |
if (! __isNonLIFO(theContext)) { |
|
2477 |
/* |
|
2478 |
* to be prepared for the worst situation |
|
2479 |
* (the sender is not stored, so the trap won't catch it) |
|
2480 |
* make the writeBarrier trigger manually. |
|
2481 |
* We'll see, if this is really required. |
|
2482 |
*/ |
|
2483 |
theContext->o_space |= CATCHMARK; |
|
18190 | 2484 |
# if 0 |
15933 | 2485 |
__markNonLIFO(theContext); |
18190 | 2486 |
# endif |
15933 | 2487 |
} |
2488 |
RETURN (theContext); |
|
2489 |
} |
|
2490 |
theContext = __ContextInstPtr(theContext)->c_sender; |
|
8284 | 2491 |
} |
18253 | 2492 |
#endif /* not SCHTEAM */ |
8284 | 2493 |
%}. |
2494 |
^ nil |
|
2495 |
! |
|
2496 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2497 |
findNextContextWithSelector:selector1 or:selector2 or:selector3 |
12841 | 2498 |
"walk along the sender chain (starting with the sender), |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2499 |
for a context with either one of the given selectors. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2500 |
This non-standard interface is only to be used by exception" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2501 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2502 |
"/ this could have been (actually: was) implemented as: |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2503 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2504 |
"/ |con| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2505 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2506 |
"/ con := self sender. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2507 |
"/ [con notNil] whileTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2508 |
"/ con selector == aSelector ifTrue:[^ con]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2509 |
"/ con := con sender. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2510 |
"/ ]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2511 |
"/ ^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2512 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2513 |
"/ and the code below does exactly this (somewhat faster, though). |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2514 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2515 |
"/ (it avoids referencing all intermediate contexts, which would mark them special, |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2516 |
"/ although they aren't really - this is expert knowledge, no need to understand that ...) |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2517 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2518 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2519 |
#ifdef __SCHTEAM__ |
18216 | 2520 |
{ |
18412 | 2521 |
STContinuation lastCallee = (STContinuation)self; |
2522 |
STContinuation cont = lastCallee.caller; |
|
2523 |
||
18216 | 2524 |
STObject sel1 = context.stArg(0); |
2525 |
STObject sel2 = context.stArg(1); |
|
2526 |
STObject sel3 = context.stArg(2); |
|
2527 |
||
18406 | 2528 |
while (cont != null) { |
2529 |
if (cont.isSmalltalkContext()) { |
|
2530 |
STObject thisSelector = cont.contextSelector(); |
|
18216 | 2531 |
|
2532 |
if ((thisSelector == sel1) |
|
2533 |
|| (thisSelector == sel2) |
|
2534 |
|| (thisSelector == sel3)) { |
|
2535 |
break; |
|
2536 |
} |
|
2537 |
} |
|
18412 | 2538 |
lastCallee = cont; |
2539 |
cont = lastCallee.caller; |
|
18216 | 2540 |
} |
18406 | 2541 |
if (cont == null) { |
2542 |
return __c__._RETURN_nil(); |
|
2543 |
} |
|
18412 | 2544 |
cont = lastCallee.sender(); // exposed |
18406 | 2545 |
return __c__._RETURN(cont); |
18216 | 2546 |
} |
2547 |
/* NOTREACHED */ |
|
18190 | 2548 |
#else |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2549 |
OBJ theContext; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2550 |
OBJ sel; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2551 |
OBJ __FETCHSELECTOR(); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2552 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2553 |
theContext = __INST(sender_); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2554 |
while (__isNonNilObject(theContext)) { |
15933 | 2555 |
if (__isLazy(theContext)) { |
18190 | 2556 |
# ifdef TRADITIONAL_STACK_FRAME |
15933 | 2557 |
sel = __FETCHSELECTOR(theContext); |
18190 | 2558 |
# else |
15933 | 2559 |
/* mhmh - not really needed */ |
2560 |
__PATCHUPCONTEXT(theContext); |
|
2561 |
sel = __ContextInstPtr(theContext)->c_selector; |
|
18190 | 2562 |
# endif |
15933 | 2563 |
} else { |
2564 |
sel = __ContextInstPtr(theContext)->c_selector; |
|
2565 |
} |
|
2566 |
||
2567 |
if ((sel == selector1) |
|
2568 |
|| ((selector2 != nil) && (sel == selector2)) |
|
2569 |
|| ((selector3 != nil) && (sel == selector3))) { |
|
2570 |
if (__isLazy(theContext)) { |
|
2571 |
__PATCHUPCONTEXT(theContext); |
|
2572 |
} |
|
2573 |
||
2574 |
if (! __isNonLIFO(theContext)) { |
|
2575 |
/* |
|
2576 |
* to be prepared for the worst situation |
|
2577 |
* (the sender is not stored, so the trap won't catch it) |
|
2578 |
* make the writeBarrier trigger manually. |
|
2579 |
* We'll see, if this is really required. |
|
2580 |
*/ |
|
2581 |
theContext->o_space |= CATCHMARK; |
|
2582 |
__markNonLIFO(theContext); |
|
2583 |
} |
|
2584 |
RETURN (theContext); |
|
2585 |
} |
|
2586 |
theContext = __ContextInstPtr(theContext)->c_sender; |
|
5422 | 2587 |
} |
2588 |
RETURN (nil); |
|
18190 | 2589 |
#endif |
5422 | 2590 |
%}. |
2591 |
" |
|
2592 |
|con sel| |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2593 |
|
5422 | 2594 |
con := self sender. |
2595 |
[con notNil] whileTrue:[ |
|
15933 | 2596 |
sel := con selector. |
2597 |
sel == selector1 ifTrue:[^ con]. |
|
2598 |
(selector2 notNil and:[sel == selector2]) ifTrue:[^ con]. |
|
2599 |
(selector3 notNil and:[sel == selector3]) ifTrue:[^ con]. |
|
2600 |
con := con sender. |
|
5422 | 2601 |
]. |
2602 |
^ nil |
|
2603 |
" |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2604 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2605 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2606 |
findNextUnwindContextOr:aContext |
12841 | 2607 |
"walk along the sender chain (starting at the sender), |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2608 |
for a context marked for unwindAction or aContext. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2609 |
This non-standard interface is only to be used by mySelf" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2610 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2611 |
"/ this could have been (actually: was) implemented as: |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2612 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2613 |
"/ |con| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2614 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2615 |
"/ con := self sender. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2616 |
"/ [con notNil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2617 |
"/ and:[con ~~ aContext |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2618 |
"/ and:[con isUnwindContext not]]] whileTrue:[con := con sender]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2619 |
"/ ^ con |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2620 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2621 |
"/ and the code below does exactly this (somewhat faster, though). |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2622 |
"/ (it avoids referencing all intermediate contexts, which would mark them special, |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2623 |
"/ although they aren't really - this is expert knowledge, no need to understand that ...) |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2624 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2625 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2626 |
#ifdef __SCHTEAM__ |
18408 | 2627 |
{ |
2628 |
if (self == aContext) { |
|
2629 |
return __c__._RETURN(self); |
|
2630 |
} |
|
2631 |
||
18412 | 2632 |
STContinuation lastCallee = (STContinuation)self; |
2633 |
STContinuation theContext = lastCallee.caller; |
|
18408 | 2634 |
|
2635 |
while (theContext != null) { |
|
2636 |
if ((theContext == aContext) |
|
2637 |
|| theContext.isMarkedForUnwind()) { |
|
18412 | 2638 |
theContext = lastCallee.sender(); // exposed |
18408 | 2639 |
return __c__._RETURN(theContext); |
2640 |
} |
|
18412 | 2641 |
lastCallee = theContext; |
2642 |
theContext = lastCallee.caller; |
|
18408 | 2643 |
} |
2644 |
} |
|
18190 | 2645 |
#else |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2646 |
OBJ theContext; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2647 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2648 |
if (self == aContext) { |
15933 | 2649 |
RETURN (self); |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2650 |
} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2651 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2652 |
theContext = __INST(sender_); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2653 |
while (__isNonNilObject(theContext)) { |
15933 | 2654 |
if ((theContext == aContext) |
2655 |
|| ((INT)(__ContextInstPtr(theContext)->c_flags) & __MASKSMALLINT(__UNWIND_MARK))) { |
|
2656 |
if (__isLazy(theContext)) { |
|
2657 |
__PATCHUPCONTEXT(theContext); |
|
2658 |
} |
|
2659 |
if (! __isNonLIFO(theContext)) { |
|
2660 |
/* |
|
2661 |
* to be prepared for the worst situation |
|
2662 |
* (the sender is not stored, so the trap won't catch it) |
|
2663 |
* make the writeBarrier trigger manually. |
|
2664 |
* We'll see, if this is really required. |
|
2665 |
*/ |
|
2666 |
theContext->o_space |= CATCHMARK; |
|
18190 | 2667 |
# if 0 |
15933 | 2668 |
__markNonLIFO(theContext); |
18190 | 2669 |
# endif |
15933 | 2670 |
} |
2671 |
RETURN (theContext); |
|
2672 |
} |
|
2673 |
theContext = __ContextInstPtr(theContext)->c_sender; |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2674 |
} |
18190 | 2675 |
#endif |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2676 |
%}. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2677 |
^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2678 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2679 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2680 |
findSpecialHandle:findHandleContext raise:findRaiseContext |
12841 | 2681 |
"walk along the sender chain (starting with the sender), |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2682 |
for a context which is marked as handle or raise context. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2683 |
This non-standard interface is only to be used by exception" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2684 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2685 |
"/ this could have been (actually: was) implemented as: |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2686 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2687 |
"/ |con| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2688 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2689 |
"/ con := self sender. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2690 |
"/ [con notNil] whileTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2691 |
"/ (findHandleContext and:[con isHandleContext]) ifTrue:[^con]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2692 |
"/ (findRaiseContext and:[con isRaiseContext]) ifTrue:[^con]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2693 |
"/ con := con sender. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2694 |
"/ ]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2695 |
"/ ^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2696 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2697 |
"/ and the code below does exactly this (somewhat faster, though). |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2698 |
"/ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2699 |
"/ (it avoids referencing all intermediate contexts, which would mark them special, |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2700 |
"/ although they aren't really - this is expert knowledge, no need to understand that ...) |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2701 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2702 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2703 |
#ifdef __SCHTEAM__ |
18406 | 2704 |
{ |
18412 | 2705 |
STContinuation lastCallee = (STContinuation)self; |
2706 |
STContinuation theContext = lastCallee.caller; |
|
2707 |
||
18406 | 2708 |
while (theContext != null) { |
2709 |
if (theContext.isMarkedSpecial()) { |
|
2710 |
if ((findHandleContext == STObject.True) |
|
2711 |
&& theContext.isMarkedForHandle()) { |
|
18412 | 2712 |
theContext = lastCallee.sender(); // exposed |
18406 | 2713 |
return __c__._RETURN(theContext); |
2714 |
} |
|
2715 |
if ((findRaiseContext == STObject.True) |
|
2716 |
&& theContext.isMarkedForRaise()) { |
|
18412 | 2717 |
theContext = lastCallee.sender(); // exposed |
18406 | 2718 |
return __c__._RETURN(theContext); |
2719 |
} |
|
2720 |
} |
|
18412 | 2721 |
lastCallee = theContext; |
2722 |
theContext = lastCallee.caller; |
|
18406 | 2723 |
} |
2724 |
} |
|
18190 | 2725 |
#else |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2726 |
OBJ theContext; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2727 |
int flagMask = 0; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2728 |
INT mask; |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2729 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2730 |
if (findHandleContext == true) |
15933 | 2731 |
flagMask = __HANDLE_MARK; |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2732 |
if (findRaiseContext == true) |
15933 | 2733 |
flagMask |= __RAISE_MARK; |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2734 |
|
12841 | 2735 |
mask = __MASKSMALLINT(flagMask); |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2736 |
theContext = __INST(sender_); |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2737 |
while (__isNonNilObject(theContext)) { |
15933 | 2738 |
if ((INT)(__ContextInstPtr(theContext)->c_flags) & mask) { |
2739 |
if (__isLazy(theContext)) { |
|
2740 |
__PATCHUPCONTEXT(theContext); |
|
2741 |
} |
|
2742 |
||
2743 |
if (! __isNonLIFO(theContext)) { |
|
2744 |
/* |
|
2745 |
* to be prepared for the worst situation |
|
2746 |
* (the sender is not stored, so the trap won't catch it) |
|
2747 |
* make the writeBarrier trigger manually. |
|
2748 |
* We'll see, if this is really required. |
|
2749 |
*/ |
|
2750 |
theContext->o_space |= CATCHMARK; |
|
18190 | 2751 |
# if 0 |
15933 | 2752 |
__markNonLIFO(theContext); |
18190 | 2753 |
# endif |
15933 | 2754 |
} |
2755 |
RETURN (theContext); |
|
2756 |
} |
|
2757 |
theContext = __ContextInstPtr(theContext)->c_sender; |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2758 |
} |
18190 | 2759 |
#endif |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2760 |
%}. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2761 |
^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2762 |
! ! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2763 |
|
1051 | 2764 |
!Context methodsFor:'special accessing'! |
2765 |
||
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2766 |
argAndVarNames |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2767 |
"helper: given a context, return a collection of arg&var names" |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2768 |
|
15644 | 2769 |
|homeContext homeMethod block numArgs numVars m src |
8217 | 2770 |
sel isDoIt blocksLineNr extractFromBlock sender| |
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2771 |
|
18437 | 2772 |
numArgs := self argumentCount. |
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2773 |
numVars := self numVars. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2774 |
(numArgs == 0 and:[numVars == 0]) ifTrue:[^ #()]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2775 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2776 |
homeContext := self methodHome. |
7652 | 2777 |
homeContext notNil ifTrue:[ |
18437 | 2778 |
sel := homeContext selector. |
2779 |
homeMethod := homeContext method. |
|
7652 | 2780 |
]. |
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2781 |
|
12841 | 2782 |
extractFromBlock := |
18437 | 2783 |
[ |
21923 | 2784 |
|blockNode argNames varNames vars blocksHome| |
18437 | 2785 |
|
2786 |
blockNode := Compiler |
|
2787 |
blockAtLine:blocksLineNr |
|
2788 |
in:m |
|
2789 |
orSource:src |
|
2790 |
numArgs:numArgs |
|
2791 |
numVars:numVars. |
|
2792 |
||
2793 |
blockNode notNil ifTrue:[ |
|
2794 |
"/ a kludge |
|
2795 |
blockNode lineNumber == blocksLineNr ifTrue:[ |
|
2796 |
blocksHome := blockNode home. |
|
2797 |
(blocksHome notNil and:[blocksHome isBlock]) ifTrue:[ |
|
2798 |
(blocksHome numArgs == numArgs |
|
2799 |
and:[ blocksHome numVars == numVars ]) ifTrue:[ |
|
2800 |
blockNode := blocksHome |
|
2801 |
]. |
|
2802 |
]. |
|
2803 |
]. |
|
2804 |
||
2805 |
argNames := #(). |
|
2806 |
varNames := #(). |
|
2807 |
||
2808 |
numArgs > 0 ifTrue:[ |
|
2809 |
vars := blockNode arguments. |
|
2810 |
vars notEmptyOrNil ifTrue:[ |
|
2811 |
argNames := vars collect:[:var | var name] |
|
2812 |
] |
|
2813 |
]. |
|
2814 |
numVars > 0 ifTrue:[ |
|
2815 |
vars := blockNode variablesIncludingInlined: (homeMethod code notNil and:[homeMethod byteCode isNil]). |
|
2816 |
vars notEmptyOrNil ifTrue:[ |
|
2817 |
varNames := vars collect:[:var | var name]. |
|
2818 |
] |
|
2819 |
]. |
|
2820 |
^ argNames , varNames |
|
2821 |
]. |
|
2822 |
]. |
|
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2823 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2824 |
"/ #doIt needs special handling below |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2825 |
isDoIt := (sel == #'doIt') or:[sel == #'doIt:']. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2826 |
self isBlockContext ifFalse:[ |
18437 | 2827 |
isDoIt ifTrue:[ |
2828 |
homeMethod notNil ifTrue:[ |
|
2829 |
"/ special for #doIt |
|
2830 |
m := nil. |
|
2831 |
src := ('[' , homeMethod source , '\]') withCRs. |
|
2832 |
"/ blocksLineNr := self lineNumber. |
|
2833 |
blocksLineNr := (self home ? self) lineNumber. |
|
2834 |
extractFromBlock value. |
|
2835 |
] |
|
2836 |
]. |
|
2837 |
||
2838 |
homeMethod notNil ifTrue:[ |
|
2839 |
^ homeMethod methodArgAndVarNamesInContext: self. |
|
2840 |
]. |
|
2841 |
^ #() |
|
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2842 |
]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2843 |
|
15644 | 2844 |
homeMethod notNil ifTrue:[ |
18437 | 2845 |
isDoIt ifTrue:[ |
2846 |
"/ special for #doIt |
|
2847 |
"/ my source is found in the method. |
|
2848 |
m := nil. |
|
2849 |
src := ('[' , homeMethod source , '\]') withCRs. |
|
2850 |
] ifFalse:[ |
|
2851 |
m := homeMethod. |
|
2852 |
src := nil. |
|
2853 |
]. |
|
2854 |
blocksLineNr := self lineNumber. |
|
2855 |
extractFromBlock value. |
|
2856 |
blocksLineNr := self home lineNumber. |
|
2857 |
extractFromBlock value. |
|
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2858 |
]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2859 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2860 |
blocksLineNr isNil ifTrue:[ |
18437 | 2861 |
self isBlockContext ifTrue:[ |
2862 |
sender := self sender. |
|
2863 |
(sender notNil |
|
2864 |
and:[sender receiver isBlock |
|
2865 |
and:[sender selector startsWith:'value']]) |
|
2866 |
ifTrue:[ |
|
2867 |
block := sender receiver. |
|
2868 |
src := block source. |
|
2869 |
src isNil ifTrue:[ |
|
2870 |
self error:'no source'. |
|
2871 |
]. |
|
2872 |
blocksLineNr := 1. |
|
2873 |
extractFromBlock value. |
|
2874 |
]. |
|
2875 |
sender := nil. |
|
2876 |
]. |
|
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2877 |
]. |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2878 |
|
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2879 |
^ #() |
15644 | 2880 |
|
2881 |
"Modified: / 19-08-2013 / 12:13:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
7568
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2882 |
! |
1dc12a1080b0
** changed access to blockContexts args and vars -- please watch out
penk
parents:
7324
diff
changeset
|
2883 |
|
4557 | 2884 |
canResume |
2885 |
"return true, if the receiver allows to be resumed. |
|
18412 | 2886 |
In ST/X, due to the implementation, this requires that the context which |
2887 |
is right below the receiver is returnable and still active." |
|
4557 | 2888 |
|
2889 |
|theContext| |
|
2890 |
||
2891 |
" |
|
2892 |
starting with this context, find the one below |
|
2893 |
(i.e. the one that I have called) and return from it. |
|
2894 |
" |
|
2895 |
%{ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2896 |
#ifdef __SCHTEAM__ |
18412 | 2897 |
// in the SCHTEAM-engine, all contexts are resumable |
18289 | 2898 |
return context._RETURN_true(); |
18190 | 2899 |
#else |
4557 | 2900 |
OBJ sndr; |
2901 |
||
2902 |
theContext = __thisContext; |
|
2903 |
while (theContext != nil) { |
|
15933 | 2904 |
sndr = __ContextInstPtr(theContext)->c_sender; |
2905 |
if (sndr == self) break; |
|
2906 |
theContext = sndr; |
|
4557 | 2907 |
} |
2908 |
if (theContext != nil) { |
|
15933 | 2909 |
if (__isLazy(theContext)) { |
2910 |
__PATCHUPCONTEXT(theContext); |
|
2911 |
} |
|
4557 | 2912 |
} |
18190 | 2913 |
#endif |
4557 | 2914 |
%}. |
2915 |
theContext isNil ifTrue:[ |
|
15933 | 2916 |
^ false |
4557 | 2917 |
]. |
2918 |
^ theContext canReturn |
|
2919 |
! |
|
2920 |
||
1051 | 2921 |
canReturn |
2922 |
"return true, if the receiver allows returning through it. |
|
4557 | 2923 |
Blocks, (currently) always return false. |
2646 | 2924 |
Methods which contain a (non-inlined) block are always |
2925 |
returnable - for other methods, it depends on how the system |
|
2926 |
was compiled (stc flag +/-optContext). |
|
2927 |
If it was compiled with +optContext, methods are compiled |
|
4557 | 2928 |
non returnable, unless a return-pragma was present in the method. |
2646 | 2929 |
Since this saves some administrative work in every method |
2930 |
invocation and makes overall execution faster, the system classes |
|
18412 | 2931 |
are all compiled with this flag turned on. |
2932 |
This means, that by default, it is not possible to walk up the |
|
2933 |
calling chain and return to an arbitrary context. |
|
2934 |
For contexts which are known to require this (i.e. handlers as found |
|
2935 |
by the exception walkers, these are marked specially (markForReturn), |
|
2936 |
so compilers know that they should create full featured contexts." |
|
1051 | 2937 |
|
2938 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2939 |
#ifdef __SCHTEAM__ |
18412 | 2940 |
// in the SCHTEAM-engine, all contexts can be returned from |
18289 | 2941 |
return context._RETURN_true(); |
18190 | 2942 |
#else |
3508 | 2943 |
RETURN ( ((INT)(__INST(flags)) & __MASKSMALLINT(__CANNOT_RETURN)) ? false : true ); |
18190 | 2944 |
#endif |
5441 | 2945 |
%}. |
2946 |
^ true |
|
1051 | 2947 |
! |
2948 |
||
1492 | 2949 |
hasStackToShow |
2646 | 2950 |
"private interface to the debugger. |
2951 |
Smalltalk contexts return false here - other language frames |
|
2952 |
(i.e. Java frames) may want to show the evaluation stack" |
|
2953 |
||
1492 | 2954 |
^ false |
2955 |
||
2956 |
"Created: 28.6.1996 / 14:48:39 / cg" |
|
2646 | 2957 |
"Modified: 13.5.1997 / 16:31:12 / cg" |
1492 | 2958 |
! |
2959 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2960 |
isHandleContext |
4505 | 2961 |
"return true, if this is a context with exception-handle flag set" |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2962 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2963 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2964 |
#ifdef __SCHTEAM__ |
18412 | 2965 |
return __c__._RETURN ( ((STContinuation)self).isMarkedForHandle() ); |
18190 | 2966 |
#else |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2967 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__HANDLE_MARK)) ? true : false ); |
18190 | 2968 |
#endif |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2969 |
%} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2970 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
2971 |
|
1051 | 2972 |
isNonLifo |
2646 | 2973 |
"return true, if this is a nonLifo context. |
2974 |
A nonLifo context is one that is still on the machine stack, |
|
2975 |
but has a reference taken and needs to be converted to a real |
|
2976 |
object (in objectMemory) when the method/block returns. |
|
18412 | 2977 |
You don't have to understand this - this is a special ST/X |
2646 | 2978 |
debug query, which may be removed without notice." |
1051 | 2979 |
|
2980 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2981 |
#ifdef __SCHTEAM__ |
18412 | 2982 |
return __c__._RETURN ( ((STContinuation)self).isNonLifo() ); |
18190 | 2983 |
#else |
1133 | 2984 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__NONLIFO)) ? true : false ); |
18190 | 2985 |
#endif |
1051 | 2986 |
%} |
2987 |
! |
|
2988 |
||
2989 |
isOnMachineStack |
|
12841 | 2990 |
"return true, if this is a machine stack context as opposed to a |
18412 | 2991 |
real heap context (i.e. if it has not been captured and returned from). |
2992 |
You don't have to understand this - this is a special ST/X |
|
2646 | 2993 |
debug query, which may be removed without notice." |
1051 | 2994 |
|
2995 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
2996 |
#ifdef __SCHTEAM__ |
18412 | 2997 |
return __c__._RETURN ( ! ((STContinuation)self).isCopiedToHeap() ); |
18190 | 2998 |
#else |
18412 | 2999 |
RETURN ( (__qSpace(self) >= STACKSPACE) ? true : false ); |
18190 | 3000 |
#endif |
1051 | 3001 |
%} |
3002 |
! |
|
3003 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
3004 |
isRaiseContext |
4505 | 3005 |
"return true, if this is a context with exception-raise flag set" |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
3006 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
3007 |
%{ /* NOCONTEXT */ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
3008 |
#ifdef __SCHTEAM__ |
18412 | 3009 |
return __c__._RETURN ( ((STContinuation)self).isMarkedForRaise() ); |
18190 | 3010 |
#else |
18412 | 3011 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__RAISE_MARK)) ? true : false ); |
18190 | 3012 |
#endif |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
3013 |
%} |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
3014 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4450
diff
changeset
|
3015 |
|
1051 | 3016 |
isSpecial |
3017 |
"return true, if this is either a nonLifo or interrupted context" |
|
3018 |
||
3019 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
3020 |
#ifdef __SCHTEAM__ |
18412 | 3021 |
return __c__._RETURN ( ((STContinuation)self).isMarkedSpecial() ); |
18190 | 3022 |
#else |
18412 | 3023 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__SPECIAL)) ? true : false ); |
18190 | 3024 |
#endif |
1051 | 3025 |
%} |
3026 |
! |
|
3027 |
||
3028 |
isUnwindContext |
|
3029 |
"return true, if this is an unwindContext" |
|
3030 |
||
3031 |
%{ /* NOCONTEXT */ |
|
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18216
diff
changeset
|
3032 |
#ifdef __SCHTEAM__ |
18412 | 3033 |
return __c__._RETURN ( ((STContinuation)self).isMarkedForUnwind() ); |
18190 | 3034 |
#else |
18412 | 3035 |
RETURN ( ((INT)__INST(flags) & __MASKSMALLINT(__UNWIND_MARK)) ? true : false ); |
18190 | 3036 |
#endif |
1051 | 3037 |
%} |
8578 | 3038 |
! |
3039 |
||
3040 |
tempNames |
|
3041 |
"helper: given a context, return a collection of arg, var and temporary names" |
|
3042 |
||
3043 |
|names nTemps| |
|
3044 |
||
3045 |
names := self argAndVarNames. |
|
3046 |
(nTemps := self numTemps) > 0 ifTrue:[ |
|
15933 | 3047 |
^ names , ((1 to:nTemps) collect:[:idx | '_tmp' , idx printString]). |
8578 | 3048 |
]. |
3049 |
^ names. |
|
1051 | 3050 |
! ! |
3051 |
||
623 | 3052 |
!Context methodsFor:'testing'! |
3053 |
||
3054 |
isBlockContext |
|
3055 |
"return true, iff the receiver is a BlockContext, false otherwise" |
|
3056 |
||
3057 |
^ false |
|
3058 |
! |
|
3059 |
||
14214 | 3060 |
isCheapBlockContext |
3061 |
"return true, iff the receiver is a BlockContext, for a cheap block, false otherwise. |
|
3062 |
Cheap blocks do not refer to their home" |
|
3063 |
||
3064 |
^ false |
|
3065 |
||
3066 |
"Created: / 19-07-2012 / 11:22:38 / cg" |
|
3067 |
! |
|
3068 |
||
623 | 3069 |
isContext |
3070 |
"return true, iff the receiver is a Context, false otherwise" |
|
3071 |
||
3072 |
^ true |
|
3073 |
! |
|
3074 |
||
16078 | 3075 |
isReallyRecursive |
3076 |
"return true, if this context is one of a recursive send of the same |
|
3077 |
selector AND same argument(s) to the same receiver before. |
|
3078 |
Here, different arguments are NOT ignored" |
|
3079 |
||
3080 |
|c count "{Class: SmallInteger }" sameArgs| |
|
3081 |
||
3082 |
count := 0. |
|
3083 |
||
22262 | 3084 |
c := self. |
3085 |
[ |
|
3086 |
c := c findNextContextWithSelector:selector or:nil or:nil. |
|
3087 |
c notNil |
|
3088 |
] whileTrue:[ |
|
18437 | 3089 |
(c receiver == receiver) ifTrue:[ |
3090 |
c method == self method ifTrue:[ |
|
3091 |
sameArgs := true. |
|
3092 |
1 to:self argumentCount do:[:i | |
|
22262 | 3093 |
(c argAt:1) ~~ (self argAt:i) ifTrue:[ |
18437 | 3094 |
sameArgs := false |
3095 |
] |
|
3096 |
]. |
|
3097 |
sameArgs ifTrue:[^ true]. |
|
3098 |
] |
|
3099 |
]. |
|
3100 |
||
3101 |
" |
|
3102 |
this special test was added to get out after a while |
|
3103 |
if the sender chain is corrupt - this gives us at least |
|
3104 |
a chance to find those errors. |
|
3105 |
" |
|
3106 |
count := count + 1. |
|
22262 | 3107 |
count >= MaxRecursion ifTrue:[ |
3108 |
'Context [warning]: long context chain' errorPrintCR. |
|
18437 | 3109 |
^ true |
3110 |
] |
|
16078 | 3111 |
]. |
3112 |
^ false |
|
22262 | 3113 |
|
3114 |
"Modified: / 17-09-2017 / 10:00:34 / cg" |
|
16078 | 3115 |
! |
3116 |
||
623 | 3117 |
isRecursive |
3118 |
"return true, if this context is one of a recursive send of the same |
|
1483 | 3119 |
selector to the same receiver before. |
3120 |
Here, different arguments are ignored - i.e. only the same method |
|
3121 |
counts for recursiveness. |
|
623 | 3122 |
Used to detect recursive errors or recursive printing - for example." |
3123 |
||
16078 | 3124 |
|c count "{Class: SmallInteger }"| |
2291
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
3125 |
|
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
3126 |
count := 0. |
af7652b82404
avoid touching contexts (making them nonLifo) when searching for unwind-contexts,
Claus Gittinger <cg@exept.de>
parents:
2285
diff
changeset
|
3127 |
|
22262 | 3128 |
c := self. |
3129 |
[ |
|
3130 |
c := c findNextContextWithSelector:selector or:nil or:nil. |
|
3131 |
c notNil |
|
3132 |
] whileTrue:[ |
|
3133 |
(c receiver == receiver) ifTrue:[ |
|
3134 |
c method == self method ifTrue:[^ true]. |
|
3135 |
]. |
|
3136 |
||
3137 |
" |
|
3138 |
this special test was added to get out after a while |
|
3139 |
if the sender chain is corrupt - this gives us at least |
|
3140 |
a chance to find those errors. |
|
3141 |
" |
|
3142 |
count := count + 1. |
|
3143 |
count >= MaxRecursion ifTrue:[ |
|
3144 |
'Context [warning]: long context chain' errorPrintCR. |
|
3145 |
^ true |
|
3146 |
] |
|
623 | 3147 |
]. |
3148 |
^ false |
|
1483 | 3149 |
|
22262 | 3150 |
"Modified (format): / 17-09-2017 / 10:02:04 / cg" |
623 | 3151 |
! ! |
3152 |
||
1810 | 3153 |
!Context class methodsFor:'documentation'! |
749 | 3154 |
|
14418
6558e5c3b32e
changed: #receiverPrintString
Claus Gittinger <cg@exept.de>
parents:
14413
diff
changeset
|
3155 |
version |
18977 | 3156 |
^ '$Header$' |
14418
6558e5c3b32e
changed: #receiverPrintString
Claus Gittinger <cg@exept.de>
parents:
14413
diff
changeset
|
3157 |
! |
6558e5c3b32e
changed: #receiverPrintString
Claus Gittinger <cg@exept.de>
parents:
14413
diff
changeset
|
3158 |
|
13426 | 3159 |
version_CVS |
18977 | 3160 |
^ '$Header$' |
15644 | 3161 |
! |
3162 |
||
3163 |
version_HG |
|
3164 |
||
3165 |
^ '$Changeset: <not expanded> $' |
|
12573 | 3166 |
! |
3167 |
||
13426 | 3168 |
version_SVN |
15232 | 3169 |
^ '$ Id: Context.st 10643 2011-06-08 21:53:07Z vranyj1 $' |
749 | 3170 |
! ! |
7257 | 3171 |
|
14700 | 3172 |
|
623 | 3173 |
Context initialize! |