author | Claus Gittinger <cg@exept.de> |
Sun, 03 Sep 2000 17:14:56 +0200 | |
changeset 5582 | 737d121ae7de |
parent 5349 | f811d5194e8e |
child 5666 | de56e39714da |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
154 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
5349 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
4299 | 15 |
CompiledCode variableSubclass:#Block |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
16 |
instanceVariableNames:'home nargs sourcePos initialPC' |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
17 |
classVariableNames:'InvalidNewSignal' |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
18 |
poolDictionaries:'' |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
19 |
category:'Kernel-Methods' |
1 | 20 |
! |
21 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
22 |
!Block class methodsFor:'documentation'! |
1 | 23 |
|
92 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
154 | 27 |
All Rights Reserved |
92 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
1 | 38 |
documentation |
39 |
" |
|
67 | 40 |
Blocks are pieces of executable code which can be evaluated by sending |
41 |
them a value-message (''value'', ''value:'', ''value:value:'' etc). |
|
1 | 42 |
|
1265 | 43 |
In smalltalk, Blocks provide the basic (and heavily used) mechanism |
44 |
for looping, enumerating collection elements, visitors, exception |
|
45 |
handling, unwinding, delayed execution and processes. |
|
46 |
||
1254 | 47 |
Blocks are never created explicitely; the only creation |
48 |
is done by the compilers, when some sourceCode is compiled to either |
|
49 |
machine or byteCode. |
|
50 |
||
67 | 51 |
Blocks with arguments need a message of type ''value:arg1 ... value:argn'' |
52 |
for evaluation; the number of arguments passed when evaluating must match |
|
53 |
the number of arguments the block was declared with otherwise an error is |
|
54 |
raised. Blocks without args need a ''value'' message for evaluation. |
|
1 | 55 |
|
154 | 56 |
Blocks keep a reference to the context where the block was declared - |
67 | 57 |
this allows blocks to access the methods arguments and/or variables. |
154 | 58 |
This is still true after the method has returned - since the |
67 | 59 |
block keeps this reference, the methods context will NOT die in this case. |
222 | 60 |
(i.e. Blocks are closures in Smalltalk/X) |
1 | 61 |
|
67 | 62 |
A return (via ^-statement) out of a block will force a return from the |
63 |
blocks method context (if it is still living) - this make the implementation |
|
64 |
of long-jumps and control structures possible. |
|
154 | 65 |
(If the method is not alive (i.e. has already returned), a return out of the |
66 |
block will trigger an error) |
|
1 | 67 |
|
67 | 68 |
Long-jump is done by defining a catchBlock as ''[^ self]'' |
69 |
somewhere up in the calling-tree. Then, to do the long-jump from out of some |
|
70 |
deeply nested method, simply do: ''catchBlock value''. |
|
1 | 71 |
|
1293 | 72 |
[Instance variables:] |
1 | 73 |
|
222 | 74 |
home <Context> the context where this block was created (i.e. defined) |
2238 | 75 |
this may be a blockContext or a methodContext |
222 | 76 |
nargs <SmallInteger> the number of arguments the block expects |
77 |
sourcePos <SmallInteger> the character position of its source, in chars |
|
2238 | 78 |
relative to methods source beginning |
222 | 79 |
initialPC <SmallInteger> the start position within the byteCode |
2238 | 80 |
for compiled blocks, this is nil. |
222 | 81 |
|
82 |
||
1293 | 83 |
[Class variables:] |
222 | 84 |
|
85 |
InvalidNewSignal raised if a Block is tried to be created |
|
2238 | 86 |
with new (which is not allowed). |
87 |
Only the VM is allowed to create Blocks. |
|
1 | 88 |
|
1293 | 89 |
|
67 | 90 |
NOTICE: layout known by runtime system and compiler - do not change |
1293 | 91 |
|
92 |
[author:] |
|
2238 | 93 |
Claus Gittinger |
1293 | 94 |
|
95 |
[see also:] |
|
2238 | 96 |
Process Context |
97 |
Collection |
|
98 |
( contexts. blocks & unwinding : programming/contexts.html) |
|
1 | 99 |
" |
1265 | 100 |
! |
101 |
||
102 |
examples |
|
103 |
" |
|
1293 | 104 |
define a block and evaluate it: |
2238 | 105 |
[exBegin] |
106 |
|b| |
|
1265 | 107 |
|
2238 | 108 |
b := [ Transcript showCR:'hello' ]. |
1293 | 109 |
|
2238 | 110 |
Transcript showCR:'now evaluating the block ...'. |
111 |
b value. |
|
112 |
[exEnd] |
|
1265 | 113 |
|
114 |
||
1293 | 115 |
|
1265 | 116 |
even here, blocks are involved: |
117 |
(although, the compiler optimizes things if possible) |
|
2238 | 118 |
[exBegin] |
119 |
Transcript showCR:'now evaluating one of two blocks ...'. |
|
120 |
1 > 4 ifTrue:[ |
|
121 |
Transcript showCR:'foo' |
|
122 |
] ifFalse:[ |
|
123 |
Transcript showCR:'bar' |
|
124 |
] |
|
125 |
[exEnd] |
|
1265 | 126 |
|
127 |
||
1293 | 128 |
|
1265 | 129 |
here things become obvious: |
2238 | 130 |
[exBegin] |
131 |
|yesBlock noBlock| |
|
1265 | 132 |
|
2238 | 133 |
yesBlock := [ Transcript showCR:'foo' ]. |
134 |
noBlock := [ Transcript showCR:'bar' ]. |
|
1265 | 135 |
|
2238 | 136 |
Transcript showCR:'now evaluating one of two blocks ...'. |
137 |
1 > 4 ifTrue:yesBlock |
|
138 |
ifFalse:noBlock |
|
139 |
[exEnd] |
|
1265 | 140 |
|
141 |
||
1293 | 142 |
|
1265 | 143 |
simple loops: |
144 |
not very objectOriented: |
|
2238 | 145 |
[exBegin] |
146 |
|i| |
|
1265 | 147 |
|
2238 | 148 |
i := 1. |
149 |
[i < 10] whileTrue:[ |
|
150 |
Transcript showCR:i. |
|
151 |
i := i + 1 |
|
152 |
] |
|
153 |
[exEnd] |
|
1265 | 154 |
|
155 |
||
156 |
using integer protocol: |
|
2238 | 157 |
[exBegin] |
158 |
1 to:10 do:[:i | |
|
159 |
Transcript showCR:i. |
|
160 |
] |
|
161 |
[exEnd] |
|
1265 | 162 |
|
163 |
||
164 |
interval protocol: |
|
2238 | 165 |
[exBegin] |
166 |
(1 to:10) do:[:i | |
|
167 |
Transcript showCR:i. |
|
168 |
] |
|
169 |
[exEnd] |
|
1265 | 170 |
|
171 |
||
1293 | 172 |
|
1265 | 173 |
looping over collections: |
174 |
||
1293 | 175 |
bad code: |
176 |
(only works with numeric-indexable collections) |
|
2238 | 177 |
[exBegin] |
178 |
|i coll| |
|
1265 | 179 |
|
2238 | 180 |
coll := #(9 8 7 6 5). |
181 |
i := 1. |
|
182 |
[i <= coll size] whileTrue:[ |
|
183 |
Transcript showCR:(coll at:i). |
|
184 |
i := i + 1. |
|
185 |
] |
|
186 |
[exEnd] |
|
1265 | 187 |
|
188 |
||
189 |
||
1293 | 190 |
just as bad (well, marginally better ;-): |
191 |
(only works with numeric-indexable collections) |
|
2238 | 192 |
[exBegin] |
193 |
|coll| |
|
1265 | 194 |
|
2238 | 195 |
coll := #(9 8 7 6 5). |
196 |
1 to:coll size do:[:i | |
|
197 |
Transcript showCR:(coll at:i). |
|
198 |
] |
|
199 |
[exEnd] |
|
1265 | 200 |
|
201 |
||
202 |
||
1293 | 203 |
the smalltalk way: |
204 |
(works with any collection) |
|
2238 | 205 |
[exBegin] |
206 |
|coll| |
|
1265 | 207 |
|
2238 | 208 |
coll := #(9 8 7 6 5). |
209 |
coll do:[:element | |
|
210 |
Transcript showCR:element. |
|
211 |
] |
|
212 |
[exEnd] |
|
1265 | 213 |
|
214 |
Rule: use enumeration protocol of the collection instead of |
|
2238 | 215 |
manually indexing it. [with few exceptions] |
1265 | 216 |
|
217 |
||
218 |
||
219 |
processes: |
|
220 |
||
221 |
forking a lightweight process (thread): |
|
2238 | 222 |
[exBegin] |
223 |
[ |
|
224 |
Transcript showCR:'waiting ...'. |
|
225 |
Delay waitForSeconds:2. |
|
226 |
Transcript showCR:'here I am'. |
|
227 |
] fork |
|
228 |
[exEnd] |
|
1265 | 229 |
|
230 |
||
231 |
||
232 |
some with low prio: |
|
2238 | 233 |
[exBegin] |
234 |
[ |
|
235 |
Transcript showCR:'computing ...'. |
|
236 |
10000 factorial. |
|
237 |
Transcript showCR:'here I am'. |
|
238 |
] forkAt:(Processor userBackgroundPriority) |
|
239 |
[exEnd] |
|
1265 | 240 |
|
241 |
||
1293 | 242 |
|
243 |
handling exceptions: |
|
2238 | 244 |
[exBegin] |
245 |
Object errorSignal handle:[:ex | |
|
246 |
Transcript showCR:'exception handler forces return'. |
|
247 |
ex return |
|
248 |
] do:[ |
|
249 |
Transcript showCR:'now, doing something bad ...'. |
|
250 |
1 / 0. |
|
251 |
Transcript showCR:'not reached' |
|
252 |
] |
|
253 |
[exEnd] |
|
1265 | 254 |
|
255 |
||
1293 | 256 |
|
257 |
performing cleanup actions: |
|
2238 | 258 |
[exBegin] |
259 |
Object errorSignal handle:[:ex | |
|
260 |
Transcript showCR:'exception handler forces return'. |
|
261 |
ex return |
|
262 |
] do:[ |
|
263 |
[ |
|
264 |
Transcript showCR:'doing something bad ...'. |
|
265 |
1 / 0. |
|
266 |
Transcript showCR:'not reached' |
|
267 |
] valueOnUnwindDo:[ |
|
268 |
Transcript showCR:'cleanup' |
|
269 |
] |
|
270 |
] |
|
271 |
[exEnd] |
|
1265 | 272 |
|
273 |
||
1293 | 274 |
delayed execution (visitor pattern): |
275 |
(looking carefully into the example, |
|
276 |
C/C++ programmers may raise their eyes ;-) |
|
2238 | 277 |
[exBegin] |
278 |
|showBlock countBlock |
|
279 |
howMany |
|
280 |
top panel b1 b2| |
|
1265 | 281 |
|
2238 | 282 |
howMany := 0. |
1265 | 283 |
|
2238 | 284 |
showBlock := [ Transcript showCR:howMany ]. |
285 |
countBlock := [ howMany := howMany + 1 ]. |
|
1265 | 286 |
|
2238 | 287 |
top := StandardSystemView extent:200@200. |
288 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
1265 | 289 |
|
2238 | 290 |
b1 := Button label:'count up' in:panel. |
291 |
b1 action:countBlock. |
|
1265 | 292 |
|
2238 | 293 |
b2 := Button label:'show value' in:panel. |
294 |
b2 action:showBlock. |
|
1265 | 295 |
|
2238 | 296 |
top open. |
1265 | 297 |
|
2238 | 298 |
Transcript showCR:'new process started;'. |
299 |
Transcript showCR:'notice: the blocks can still access the'. |
|
300 |
Transcript showCR:' howMany local variable.'. |
|
301 |
[exEnd] |
|
1265 | 302 |
" |
1 | 303 |
! ! |
304 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
305 |
!Block class methodsFor:'initialization'! |
1 | 306 |
|
307 |
initialize |
|
1254 | 308 |
"create signals raised by various errors" |
1 | 309 |
|
48 | 310 |
InvalidNewSignal isNil ifTrue:[ |
2238 | 311 |
InvalidNewSignal := ErrorSignal newSignalMayProceed:false. |
312 |
InvalidNewSignal nameClass:self message:#invalidNewSignal. |
|
313 |
InvalidNewSignal notifierString:'blocks are only created by the system'. |
|
48 | 314 |
] |
1254 | 315 |
|
316 |
"Modified: 22.4.1996 / 16:34:20 / cg" |
|
1 | 317 |
! ! |
318 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
319 |
!Block class methodsFor:'instance creation'! |
1 | 320 |
|
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
321 |
byteCode:bCode numArgs:numArgs numStack:nStack sourcePosition:sourcePos initialPC:initialPC literals:literals |
1 | 322 |
"create a new cheap (homeless) block. |
222 | 323 |
Not for public use - this is a special hook for the compiler." |
1 | 324 |
|
325 |
|newBlock| |
|
326 |
||
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
327 |
newBlock := (super basicNew:(literals size)) |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
328 |
byteCode:bCode |
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
329 |
numArgs:numArgs |
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
330 |
numStack:nStack |
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
331 |
sourcePosition:sourcePos |
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
332 |
initialPC:initialPC |
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
333 |
literals:literals. |
1 | 334 |
^ newBlock |
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
335 |
|
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
336 |
"Modified: 24.6.1996 / 12:36:48 / stefan" |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
337 |
"Created: 13.4.1997 / 00:04:09 / cg" |
1 | 338 |
! |
339 |
||
22 | 340 |
new |
4299 | 341 |
"catch creation of blocks - only the system creates blocks. |
342 |
If you really need a block (assuming, you are some compiler), |
|
343 |
use basicNew and setup the instance carefully" |
|
1 | 344 |
|
128 | 345 |
^ InvalidNewSignal raise. |
1 | 346 |
! |
347 |
||
22 | 348 |
new:size |
1 | 349 |
"catch creation of blocks - only the system creates blocks" |
350 |
||
128 | 351 |
^ InvalidNewSignal raise. |
1 | 352 |
! ! |
353 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
354 |
!Block class methodsFor:'queries'! |
1 | 355 |
|
623 | 356 |
isBuiltInClass |
1264 | 357 |
"return true if this class is known by the run-time-system. |
358 |
Here, true is returned for myself, false for subclasses." |
|
11 | 359 |
|
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
360 |
^ self == Block |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
361 |
|
1264 | 362 |
"Modified: 23.4.1996 / 15:55:58 / cg" |
1 | 363 |
! ! |
364 |
||
5349 | 365 |
!Block methodsFor:'Compatibility - ANSI'! |
366 |
||
367 |
ensure:aBlock |
|
368 |
"evaluate the receiver and return its result. |
|
369 |
After evaluation, also evaluate aBlock but ignore its result. |
|
370 |
aBlock is also evaluated in case of abnormal termination. |
|
371 |
(the same as #valueNowOrOnUnwindDo:)" |
|
372 |
||
373 |
^ self valueNowOrOnUnwindDo:aBlock |
|
374 |
||
375 |
" |
|
376 |
[ |
|
377 |
[ |
|
378 |
Transcript showCR:'one'. |
|
379 |
Processor activeProcess terminate. |
|
380 |
Transcript showCR:'two'. |
|
381 |
] ensure:[ |
|
382 |
Transcript showCR:'three'. |
|
383 |
]. |
|
384 |
] fork. |
|
385 |
" |
|
386 |
||
387 |
" |
|
388 |
[ |
|
389 |
[ |
|
390 |
Transcript showCR:'one'. |
|
391 |
Transcript showCR:'two'. |
|
392 |
] ensure:[ |
|
393 |
Transcript showCR:'three'. |
|
394 |
]. |
|
395 |
] fork. |
|
396 |
" |
|
397 |
||
398 |
! ! |
|
399 |
||
5015 | 400 |
!Block methodsFor:'Compatibility - Squeak'! |
401 |
||
402 |
ifError:handlerBlock |
|
403 |
^ self on:Error do:handlerBlock |
|
404 |
! ! |
|
405 |
||
1979 | 406 |
!Block methodsFor:'Compatibility - V''Age'! |
407 |
||
408 |
argumentCount |
|
409 |
"VisualAge compatibility: alias for #numArgs. |
|
410 |
return the number of arguments I expect for evaluation" |
|
411 |
||
412 |
^ nargs |
|
413 |
||
414 |
"Created: 15.11.1996 / 11:22:02 / cg" |
|
415 |
! |
|
416 |
||
417 |
valueOnReturnDo:aBlock |
|
418 |
"VisualAge compatibility: alias for #valueOnUnwindDo: |
|
419 |
evaluate the receiver - when some method sent within unwinds |
|
420 |
(i.e. does a long return), evaluate the argument, aBlock. |
|
421 |
This is used to make certain that cleanup actions |
|
422 |
(for example closing files etc.) are executed regardless of error actions. |
|
423 |
||
424 |
Q: is this the exact semantics of V'Ages method ? |
|
2238 | 425 |
the documentation is unclean; it could be a valueNowOrOnUnwindDo: ..." |
1979 | 426 |
|
427 |
^ self valueOnUnwindDo:aBlock |
|
428 |
||
429 |
"Created: 15.11.1996 / 11:38:37 / cg" |
|
430 |
! ! |
|
431 |
||
623 | 432 |
!Block methodsFor:'accessing'! |
154 | 433 |
|
434 |
home |
|
435 |
"return the receivers home context (the context where it was |
|
436 |
created). For cheap blocks, nil is returned" |
|
437 |
||
438 |
^ home |
|
161 | 439 |
! |
440 |
||
2694
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
441 |
homeMethod |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
442 |
"return the receivers home method. |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
443 |
Thats the method where the block was created." |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
444 |
|
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
445 |
home notNil ifTrue:[ |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
446 |
^ home method |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
447 |
]. |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
448 |
^ nil |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
449 |
|
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
450 |
"Created: 19.6.1997 / 16:14:57 / cg" |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
451 |
! |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
452 |
|
161 | 453 |
method |
454 |
"return the receivers method |
|
2694
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
455 |
(the method where the block was created). |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
456 |
Obsolete: use #homeMethod for ST80 compatibility." |
161 | 457 |
|
2694
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
458 |
^ self homeMethod |
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
459 |
|
46ba8cbdc013
added #homeMethod for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents:
2542
diff
changeset
|
460 |
"Modified: 19.6.1997 / 16:15:24 / cg" |
623 | 461 |
! |
11 | 462 |
|
623 | 463 |
methodHome |
464 |
"return the receivers method home context (the context where it was |
|
465 |
defined). For cheap blocks, nil is returned" |
|
466 |
||
467 |
home notNil ifTrue:[ |
|
468 |
^ home methodHome |
|
469 |
]. |
|
470 |
^ home |
|
11 | 471 |
! |
472 |
||
623 | 473 |
numArgs |
474 |
"return the number of arguments I expect for evaluation" |
|
1 | 475 |
|
623 | 476 |
^ nargs |
477 |
! ! |
|
1 | 478 |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
479 |
!Block methodsFor:'conversion'! |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
480 |
|
5349 | 481 |
asVarArgBlock |
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
482 |
"convert myself into a varArg block; |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
483 |
this one has 1 formal argument, which gets the list |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
484 |
of actual arguments when evaluated." |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
485 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
486 |
nargs ~~ 1 ifTrue:[ |
2241 | 487 |
self error:'vararg blocks must take exactly 1 argument - the arg list'. |
488 |
^ nil |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
489 |
]. |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
490 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
491 |
self changeClassTo:VarArgBlock. |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
492 |
^ self |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
493 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
494 |
" |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
495 |
|b| |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
496 |
|
5349 | 497 |
b := [:argList | Transcript |
498 |
show:'invoked with args:'; |
|
499 |
showCR:argList |
|
500 |
] asVarArgBlock. |
|
501 |
b value. |
|
502 |
b value:'arg1'. |
|
503 |
b value:'arg1' value:'arg2' value:'arg3' value:'arg4' |
|
504 |
" |
|
505 |
||
506 |
"Created: 23.1.1997 / 13:35:28 / cg" |
|
507 |
"Modified: 23.1.1997 / 13:35:48 / cg" |
|
508 |
! |
|
509 |
||
510 |
beVarArg |
|
511 |
"convert myself into a varArg block; |
|
512 |
this one has 1 formal argument, which gets the list |
|
513 |
of actual arguments when evaluated." |
|
514 |
||
515 |
^ self asVarArgBlock. |
|
516 |
||
517 |
" |
|
518 |
|b| |
|
519 |
||
2241 | 520 |
b := [:argList | argList printCR] beVarArg. |
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
521 |
b value. |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
522 |
b value:'arg1' value:'arg2' value:'arg3' value:'arg4' |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
523 |
" |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
524 |
|
2241 | 525 |
"Created: 23.1.1997 / 13:35:28 / cg" |
526 |
"Modified: 23.1.1997 / 13:35:48 / cg" |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
527 |
! ! |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
528 |
|
623 | 529 |
!Block methodsFor:'copying'! |
1 | 530 |
|
3349
84a92126a268
must catch #deppCopyUsing: instead of #deepCopy.
Claus Gittinger <cg@exept.de>
parents:
2841
diff
changeset
|
531 |
deepCopyUsing:aDictionary |
623 | 532 |
"raise an error - deepCopy is not allowed for blocks" |
1 | 533 |
|
623 | 534 |
^ self deepCopyError |
3349
84a92126a268
must catch #deppCopyUsing: instead of #deepCopy.
Claus Gittinger <cg@exept.de>
parents:
2841
diff
changeset
|
535 |
|
84a92126a268
must catch #deppCopyUsing: instead of #deepCopy.
Claus Gittinger <cg@exept.de>
parents:
2841
diff
changeset
|
536 |
"Created: / 31.3.1998 / 15:46:17 / cg" |
1 | 537 |
! ! |
538 |
||
539 |
!Block methodsFor:'error handling'! |
|
540 |
||
328 | 541 |
invalidCodeObject |
1874 | 542 |
"{ Pragma: +optSpace }" |
543 |
||
67 | 544 |
"this error is triggered by the interpreter when a non-Block object |
545 |
is about to be executed. |
|
546 |
In this case, the VM sends this to the bad method (the receiver). |
|
547 |
Can only happen when the Compiler/runtime system is broken or |
|
548 |
someone played around." |
|
1 | 549 |
|
128 | 550 |
^ InvalidCodeSignal |
2238 | 551 |
raiseRequestWith:self |
552 |
errorString:'invalid block - not executable' |
|
1874 | 553 |
|
554 |
"Modified: 4.11.1996 / 22:46:39 / cg" |
|
1 | 555 |
! ! |
556 |
||
557 |
!Block methodsFor:'evaluation'! |
|
558 |
||
559 |
value |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
560 |
"evaluate the receiver with no block args. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
561 |
The receiver must be a block without arguments." |
1 | 562 |
|
563 |
%{ /* NOCONTEXT */ |
|
564 |
||
565 |
REGISTER OBJFUNC thecode; |
|
566 |
OBJ home; |
|
567 |
||
1133 | 568 |
if (__INST(nargs) == __MKSMALLINT(0)) { |
1 | 569 |
#if defined(THIS_CONTEXT) |
328 | 570 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 571 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 572 |
#endif |
328 | 573 |
|
1133 | 574 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 575 |
#ifdef NEW_BLOCK_CALL |
154 | 576 |
if (thecode != (OBJFUNC)nil) { |
577 |
/* compiled machine code */ |
|
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
578 |
RETURN ( (*thecode)(self) ); |
154 | 579 |
} |
580 |
/* interpreted code */ |
|
328 | 581 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
582 |
RETURN ( __interpret(self, 0, nil, nil, nil, nil) ); |
328 | 583 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
584 |
RETURN ( __interpret(self, 0, nil, nil, nil, nil) ); |
328 | 585 |
# endif |
11 | 586 |
#else |
1133 | 587 |
home = __BlockInstPtr(self)->b_home; |
154 | 588 |
if (thecode != (OBJFUNC)nil) { |
589 |
/* compiled machine code */ |
|
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
590 |
RETURN ( (*thecode)(home) ); |
154 | 591 |
} |
592 |
/* interpreted code */ |
|
328 | 593 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
594 |
RETURN ( __interpret(self, 0, nil, home, nil, nil) ); |
328 | 595 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
596 |
RETURN ( __interpret(self, 0, nil, home, nil, nil) ); |
328 | 597 |
# endif |
11 | 598 |
#endif |
1 | 599 |
} |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
600 |
%}. |
103 | 601 |
^ self wrongNumberOfArguments:0 |
1 | 602 |
! |
603 |
||
604 |
value:arg |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
605 |
"evaluate the receiver with one argument. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
606 |
The receiver must be a 1-arg block." |
1 | 607 |
|
608 |
%{ /* NOCONTEXT */ |
|
609 |
||
610 |
REGISTER OBJFUNC thecode; |
|
611 |
OBJ home; |
|
612 |
||
1133 | 613 |
if (__INST(nargs) == __MKSMALLINT(1)) { |
1 | 614 |
#if defined(THIS_CONTEXT) |
328 | 615 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 616 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 617 |
#endif |
1133 | 618 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 619 |
#ifdef NEW_BLOCK_CALL |
154 | 620 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
621 |
RETURN ( (*thecode)(self, arg) ); |
154 | 622 |
} |
623 |
/* interpreted code */ |
|
328 | 624 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
625 |
RETURN ( __interpret(self, 1, nil, nil, nil, nil, &arg) ); |
328 | 626 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
627 |
RETURN ( __interpret(self, 1, nil, nil, nil, nil, arg) ); |
328 | 628 |
# endif |
1 | 629 |
#else |
1133 | 630 |
home = __BlockInstPtr(self)->b_home; |
154 | 631 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
632 |
RETURN ( (*thecode)(home, arg) ); |
154 | 633 |
} |
634 |
/* interpreted code */ |
|
328 | 635 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
636 |
RETURN ( __interpret(self, 1, nil, home, nil, nil, &arg) ); |
328 | 637 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
638 |
RETURN ( __interpret(self, 1, nil, home, nil, nil, arg) ); |
328 | 639 |
# endif |
1 | 640 |
#endif |
641 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
642 |
%}. |
103 | 643 |
^ self wrongNumberOfArguments:1 |
1 | 644 |
! |
645 |
||
646 |
value:arg1 value:arg2 |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
647 |
"evaluate the receiver with two arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
648 |
The receiver must be a 2-arg block." |
1 | 649 |
|
650 |
%{ /* NOCONTEXT */ |
|
651 |
||
652 |
REGISTER OBJFUNC thecode; |
|
653 |
OBJ home; |
|
654 |
||
1133 | 655 |
if (__INST(nargs) == __MKSMALLINT(2)) { |
1 | 656 |
#if defined(THIS_CONTEXT) |
328 | 657 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 658 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 659 |
#endif |
1133 | 660 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 661 |
#ifdef NEW_BLOCK_CALL |
154 | 662 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
663 |
RETURN ( (*thecode)(self, arg1, arg2) ); |
154 | 664 |
} |
328 | 665 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
666 |
RETURN ( __interpret(self, 2, nil, nil, nil, nil, &arg1) ); |
328 | 667 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
668 |
RETURN ( __interpret(self, 2, nil, nil, nil, nil, arg1, arg2) ); |
328 | 669 |
# endif |
1 | 670 |
#else |
1133 | 671 |
home = __BlockInstPtr(self)->b_home; |
154 | 672 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
673 |
RETURN ( (*thecode)(home, arg1, arg2) ); |
154 | 674 |
} |
328 | 675 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
676 |
RETURN ( __interpret(self, 2, nil, home, nil, nil, &arg1) ); |
328 | 677 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
678 |
RETURN ( __interpret(self, 2, nil, home, nil, nil, arg1, arg2) ); |
328 | 679 |
# endif |
1 | 680 |
#endif |
681 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
682 |
%}. |
103 | 683 |
^ self wrongNumberOfArguments:2 |
1 | 684 |
! |
685 |
||
686 |
value:arg1 value:arg2 value:arg3 |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
687 |
"evaluate the receiver with three arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
688 |
The receiver must be a 3-arg block." |
1 | 689 |
|
690 |
%{ /* NOCONTEXT */ |
|
691 |
||
692 |
REGISTER OBJFUNC thecode; |
|
693 |
OBJ home; |
|
694 |
||
1133 | 695 |
if (__INST(nargs) == __MKSMALLINT(3)) { |
1 | 696 |
#if defined(THIS_CONTEXT) |
328 | 697 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 698 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 699 |
#endif |
1133 | 700 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 701 |
#ifdef NEW_BLOCK_CALL |
154 | 702 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
703 |
RETURN ( (*thecode)(self, arg1, arg2, arg3) ); |
154 | 704 |
} |
328 | 705 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
706 |
RETURN ( __interpret(self, 3, nil, nil, nil, nil, &arg1) ); |
328 | 707 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
708 |
RETURN ( __interpret(self, 3, nil, nil, nil, nil, arg1, arg2, arg3) ); |
328 | 709 |
# endif |
1 | 710 |
#else |
1133 | 711 |
home = __BlockInstPtr(self)->b_home; |
154 | 712 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
713 |
RETURN ( (*thecode)(home, arg1, arg2, arg3) ); |
154 | 714 |
} |
328 | 715 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
716 |
RETURN ( __interpret(self, 3, nil, home, nil, nil, &arg1) ); |
328 | 717 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
718 |
RETURN ( __interpret(self, 3, nil, home, nil, nil, arg1, arg2, arg3) ); |
328 | 719 |
# endif |
1 | 720 |
#endif |
721 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
722 |
%}. |
103 | 723 |
^ self wrongNumberOfArguments:3 |
1 | 724 |
! |
725 |
||
726 |
value:arg1 value:arg2 value:arg3 value:arg4 |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
727 |
"evaluate the receiver with four arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
728 |
The receiver must be a 4-arg block." |
1 | 729 |
|
730 |
%{ /* NOCONTEXT */ |
|
731 |
||
732 |
REGISTER OBJFUNC thecode; |
|
733 |
OBJ home; |
|
734 |
||
1133 | 735 |
if (__INST(nargs) == __MKSMALLINT(4)) { |
1 | 736 |
#if defined(THIS_CONTEXT) |
328 | 737 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 738 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 739 |
#endif |
1133 | 740 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 741 |
#ifdef NEW_BLOCK_CALL |
154 | 742 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
743 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4) ); |
154 | 744 |
} |
328 | 745 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
746 |
RETURN ( __interpret(self, 4, nil, nil, nil, nil, &arg1) ); |
328 | 747 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
748 |
RETURN ( __interpret(self, 4, nil, nil, nil, nil, arg1, arg2, arg3, arg4) ); |
328 | 749 |
# endif |
1 | 750 |
#else |
1133 | 751 |
home = __BlockInstPtr(self)->b_home; |
154 | 752 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
753 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4) ); |
154 | 754 |
} |
328 | 755 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
756 |
RETURN ( __interpret(self, 4, nil, home, nil, nil, &arg1) ); |
328 | 757 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
758 |
RETURN ( __interpret(self, 4, nil, home, nil, nil, arg1, arg2, arg3, arg4) ); |
328 | 759 |
# endif |
1 | 760 |
#endif |
761 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
762 |
%}. |
103 | 763 |
^ self wrongNumberOfArguments:4 |
1 | 764 |
! |
765 |
||
766 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
767 |
"evaluate the receiver with five arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
768 |
The receiver must be a 5-arg block." |
1 | 769 |
|
770 |
%{ /* NOCONTEXT */ |
|
771 |
||
772 |
REGISTER OBJFUNC thecode; |
|
773 |
OBJ home; |
|
774 |
||
1133 | 775 |
if (__INST(nargs) == __MKSMALLINT(5)) { |
1 | 776 |
#if defined(THIS_CONTEXT) |
328 | 777 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 778 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 779 |
#endif |
1133 | 780 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 781 |
#ifdef NEW_BLOCK_CALL |
154 | 782 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
783 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5) ); |
154 | 784 |
} |
328 | 785 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
786 |
RETURN ( __interpret(self, 5, nil, nil, nil, nil, &arg1) ); |
328 | 787 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
788 |
RETURN ( __interpret(self, 5, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5) ); |
328 | 789 |
# endif |
1 | 790 |
#else |
1133 | 791 |
home = __BlockInstPtr(self)->b_home; |
154 | 792 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
793 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5) ); |
154 | 794 |
} |
328 | 795 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
796 |
RETURN ( __interpret(self, 5, nil, home, nil, nil, &arg1) ); |
328 | 797 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
798 |
RETURN ( __interpret(self, 5, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5) ); |
328 | 799 |
# endif |
1 | 800 |
#endif |
801 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
802 |
%}. |
103 | 803 |
^ self wrongNumberOfArguments:5 |
1 | 804 |
! |
805 |
||
806 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
807 |
"evaluate the receiver with six arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
808 |
The receiver must be a 6-arg block." |
1 | 809 |
|
810 |
%{ /* NOCONTEXT */ |
|
811 |
||
812 |
REGISTER OBJFUNC thecode; |
|
813 |
OBJ home; |
|
814 |
||
1133 | 815 |
if (__INST(nargs) == __MKSMALLINT(6)) { |
1 | 816 |
#if defined(THIS_CONTEXT) |
328 | 817 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 818 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 819 |
#endif |
1133 | 820 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 821 |
#ifdef NEW_BLOCK_CALL |
154 | 822 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
823 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6) ); |
154 | 824 |
} |
328 | 825 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
826 |
RETURN ( __interpret(self, 6, nil, nil, nil, nil, &arg1) ); |
328 | 827 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
828 |
RETURN ( __interpret(self, 6, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
328 | 829 |
# endif |
1 | 830 |
#else |
1133 | 831 |
home = __BlockInstPtr(self)->b_home; |
154 | 832 |
if (thecode != (OBJFUNC)nil) { |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
833 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6) ); |
154 | 834 |
} |
328 | 835 |
# ifdef PASS_ARG_POINTER |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
836 |
RETURN ( __interpret(self, 6, nil, home, nil, nil, &arg1) ); |
328 | 837 |
# else |
2201
db0f6e86c8bb
COMMA_SENDER arg is no longer supported / needed
Claus Gittinger <cg@exept.de>
parents:
1979
diff
changeset
|
838 |
RETURN ( __interpret(self, 6, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
328 | 839 |
# endif |
1 | 840 |
#endif |
841 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
842 |
%}. |
103 | 843 |
^ self wrongNumberOfArguments:6 |
1 | 844 |
! |
845 |
||
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
846 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
847 |
"evaluate the receiver with seven arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
848 |
The receiver must be a 7-arg block." |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
849 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
850 |
%{ /* NOCONTEXT */ |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
851 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
852 |
REGISTER OBJFUNC thecode; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
853 |
OBJ home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
854 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
855 |
if (__INST(nargs) == __MKSMALLINT(7)) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
856 |
#if defined(THIS_CONTEXT) |
2238 | 857 |
if (__ISVALID_ILC_LNO(__pilc)) |
858 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
859 |
#endif |
2238 | 860 |
thecode = __BlockInstPtr(self)->b_code; |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
861 |
#ifdef NEW_BLOCK_CALL |
2238 | 862 |
if (thecode != (OBJFUNC)nil) { |
863 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
864 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
865 |
# ifdef PASS_ARG_POINTER |
2238 | 866 |
RETURN ( __interpret(self, 7, nil, nil, nil, nil, &arg1) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
867 |
# else |
2238 | 868 |
RETURN ( __interpret(self, 7, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
869 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
870 |
#else |
2238 | 871 |
home = __BlockInstPtr(self)->b_home; |
872 |
if (thecode != (OBJFUNC)nil) { |
|
873 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
874 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
875 |
# ifdef PASS_ARG_POINTER |
2238 | 876 |
RETURN ( __interpret(self, 7, nil, home, nil, nil, &arg1) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
877 |
# else |
2238 | 878 |
RETURN ( __interpret(self, 7, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
879 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
880 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
881 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
882 |
%}. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
883 |
^ self wrongNumberOfArguments:7 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
884 |
! |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
885 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
886 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
887 |
"evaluate the receiver with eight arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
888 |
The receiver must be a 8-arg block." |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
889 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
890 |
%{ /* NOCONTEXT */ |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
891 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
892 |
REGISTER OBJFUNC thecode; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
893 |
OBJ home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
894 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
895 |
if (__INST(nargs) == __MKSMALLINT(8)) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
896 |
#if defined(THIS_CONTEXT) |
2238 | 897 |
if (__ISVALID_ILC_LNO(__pilc)) |
898 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
899 |
#endif |
2238 | 900 |
thecode = __BlockInstPtr(self)->b_code; |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
901 |
#ifdef NEW_BLOCK_CALL |
2238 | 902 |
if (thecode != (OBJFUNC)nil) { |
903 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
|
904 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
905 |
# ifdef PASS_ARG_POINTER |
2238 | 906 |
RETURN ( __interpret(self, 8, nil, nil, nil, nil, &arg1) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
907 |
# else |
2238 | 908 |
RETURN ( __interpret(self, 8, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
909 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
910 |
#else |
2238 | 911 |
home = __BlockInstPtr(self)->b_home; |
912 |
if (thecode != (OBJFUNC)nil) { |
|
913 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
|
914 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
915 |
# ifdef PASS_ARG_POINTER |
2238 | 916 |
RETURN ( __interpret(self, 8, nil, home, nil, nil, &arg1) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
917 |
# else |
2238 | 918 |
RETURN ( __interpret(self, 8, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
919 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
920 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
921 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
922 |
%}. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
923 |
^ self wrongNumberOfArguments:8 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
924 |
! |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
925 |
|
3688 | 926 |
valueAt:priority |
927 |
"evaluate the receiver, at the given prioriy; |
|
928 |
i.e. change the priority for the execution of the receiver." |
|
929 |
||
930 |
|oldPrio retVal| |
|
931 |
||
932 |
oldPrio := Processor activePriority. |
|
933 |
[ |
|
934 |
Processor activeProcess priority:priority. |
|
935 |
retVal := self value. |
|
936 |
] valueNowOrOnUnwindDo:[ |
|
937 |
Processor activeProcess priority:oldPrio |
|
938 |
]. |
|
939 |
^ retVal |
|
940 |
||
941 |
" |
|
942 |
[ |
|
943 |
1000 timesRepeat:[ |
|
944 |
1000 factorial |
|
945 |
] |
|
946 |
] valueAt:3 |
|
947 |
" |
|
948 |
||
949 |
"Created: / 29.7.1998 / 19:19:48 / cg" |
|
950 |
! |
|
951 |
||
1 | 952 |
valueWithArguments:argArray |
953 |
"evaluate the receiver with arguments taken from argArray. |
|
313 | 954 |
ArgArray must be either an Array or nil. |
1 | 955 |
The size of the argArray must match the number of arguments the receiver expects." |
956 |
||
3497 | 957 |
|a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12| |
1 | 958 |
|
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
959 |
(argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[ |
3497 | 960 |
^ self badArgumentArry |
1 | 961 |
]. |
962 |
(argArray size == nargs) ifFalse:[ |
|
3497 | 963 |
^ self wrongNumberOfArguments:(argArray size) |
1 | 964 |
]. |
965 |
%{ |
|
966 |
||
967 |
REGISTER OBJFUNC thecode; |
|
968 |
OBJ home; |
|
67 | 969 |
REGISTER OBJ *ap; |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
970 |
int __nargs; |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
971 |
OBJ nA; |
1 | 972 |
|
973 |
#if defined(THIS_CONTEXT) |
|
328 | 974 |
if (__ISVALID_ILC_LNO(__pilc)) |
3497 | 975 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 976 |
#endif |
1133 | 977 |
thecode = __BlockInstPtr(self)->b_code; |
1037 | 978 |
|
979 |
#ifndef NEW_BLOCK_CALL |
|
1133 | 980 |
home = __BlockInstPtr(self)->b_home; |
1037 | 981 |
if (thecode != (OBJFUNC)nil) { |
3497 | 982 |
if ((nA = __INST(nargs)) == __MKSMALLINT(0)) { |
983 |
RETURN ( (*thecode)(home) ); |
|
984 |
} |
|
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
985 |
|
3497 | 986 |
switch (__intVal(__INST(nargs))) { |
987 |
default: |
|
988 |
goto error; |
|
989 |
case 12: |
|
990 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
991 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9], ap[10], ap[11]) ); |
|
992 |
case 11: |
|
993 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
994 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9], ap[10]) ); |
|
995 |
case 10: |
|
996 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
997 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9]) ); |
|
998 |
case 9: |
|
999 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1000 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8]) ); |
|
1001 |
case 8: |
|
1002 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1003 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7]) ); |
|
1004 |
case 7: |
|
1005 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1006 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) ); |
|
1007 |
case 6: |
|
1008 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1009 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) ); |
|
1010 |
case 5: |
|
1011 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1012 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4]) ); |
|
1013 |
case 4: |
|
1014 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1015 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3]) ); |
|
1016 |
case 3: |
|
1017 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1018 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2]) ); |
|
1019 |
case 2: |
|
1020 |
ap = __ArrayInstPtr(argArray)->a_element; |
|
1021 |
RETURN ( (*thecode)(home, ap[0], ap[1]) ); |
|
1022 |
case 1: |
|
1023 |
RETURN ( (*thecode)(home, __ArrayInstPtr(argArray)->a_element[0]) ); |
|
1024 |
case 0: |
|
1025 |
RETURN ( (*thecode)(home) ); |
|
1026 |
break; |
|
1027 |
} |
|
1037 | 1028 |
} |
1029 |
#endif |
|
1030 |
||
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1031 |
__nargs = __intVal(__INST(nargs)); |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1032 |
if (__nargs) { |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1033 |
switch (__nargs) { |
3497 | 1034 |
default: |
1035 |
goto error; |
|
1036 |
case 12: |
|
1037 |
a12 = __ArrayInstPtr(argArray)->a_element[11]; |
|
1038 |
case 11: |
|
1039 |
a11 = __ArrayInstPtr(argArray)->a_element[10]; |
|
1040 |
case 10: |
|
1041 |
a10 = __ArrayInstPtr(argArray)->a_element[9]; |
|
1042 |
case 9: |
|
1043 |
a9 = __ArrayInstPtr(argArray)->a_element[8]; |
|
1044 |
case 8: |
|
1045 |
a8 = __ArrayInstPtr(argArray)->a_element[7]; |
|
1046 |
case 7: |
|
1047 |
a7 = __ArrayInstPtr(argArray)->a_element[6]; |
|
1048 |
case 6: |
|
1049 |
a6 = __ArrayInstPtr(argArray)->a_element[5]; |
|
1050 |
case 5: |
|
1051 |
a5 = __ArrayInstPtr(argArray)->a_element[4]; |
|
1052 |
case 4: |
|
1053 |
a4 = __ArrayInstPtr(argArray)->a_element[3]; |
|
1054 |
case 3: |
|
1055 |
a3 = __ArrayInstPtr(argArray)->a_element[2]; |
|
1056 |
case 2: |
|
1057 |
a2 = __ArrayInstPtr(argArray)->a_element[1]; |
|
1058 |
case 1: |
|
1059 |
a1 = __ArrayInstPtr(argArray)->a_element[0]; |
|
1060 |
case 0: |
|
1061 |
break; |
|
1062 |
} |
|
1 | 1063 |
} |
1133 | 1064 |
|
11 | 1065 |
#ifdef NEW_BLOCK_CALL |
1 | 1066 |
if (thecode != (OBJFUNC)nil) { |
3497 | 1067 |
RETURN ( (*thecode)(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) ); |
11 | 1068 |
} |
328 | 1069 |
# ifdef PASS_ARG_POINTER |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1070 |
RETURN ( __interpret(self, __nargs, nil, nil, nil, nil, &a1) ); |
328 | 1071 |
# else |
3497 | 1072 |
RETURN ( __interpret(self, __nargs, nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) ); |
328 | 1073 |
# endif |
1037 | 1074 |
|
1 | 1075 |
#else |
1037 | 1076 |
|
328 | 1077 |
# ifdef PASS_ARG_POINTER |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1078 |
RETURN ( __interpret(self, __nargs, nil, home, nil, nil, &a1) ); |
328 | 1079 |
# else |
3497 | 1080 |
RETURN ( __interpret(self, __nargs, nil, home, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) ); |
328 | 1081 |
# endif |
1037 | 1082 |
|
1 | 1083 |
#endif |
67 | 1084 |
|
11 | 1085 |
error: ; |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1086 |
%}. |
138 | 1087 |
" |
3497 | 1088 |
the above code only supports up-to 12 arguments |
138 | 1089 |
" |
128 | 1090 |
^ ArgumentSignal |
3497 | 1091 |
raiseRequestWith:self |
1092 |
errorString:'only blocks with up-to 12 arguments supported' |
|
154 | 1093 |
! ! |
1094 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1095 |
!Block methodsFor:'exception handling'! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1096 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1097 |
handlerForSignal:signal context:theContext originator:originator |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1098 |
"answer the handler block for the signal from originator. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1099 |
The handler block is retrieved from aContext. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1100 |
Answer nil if the signal is not handled." |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1101 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1102 |
|sig handler| |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1103 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1104 |
theContext selector == #on:do: ifTrue:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1105 |
sig := theContext argAt:1. |
4513 | 1106 |
(sig == signal or:[sig accepts:signal]) ifTrue:[ |
4471
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1107 |
handler := theContext argAt:2. |
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1108 |
"/ this is for backward compatibility when no ex-arg |
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1109 |
"/ is expected in the block. Is it worth the effort ? |
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1110 |
handler numArgs == 0 ifTrue:[ |
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1111 |
^ [:ex | handler value] |
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1112 |
]. |
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1113 |
^ handler |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1114 |
]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1115 |
] ifFalse:[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1116 |
"must be #valueWithExceptionHandler:" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1117 |
handler := theContext argAt:1. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1118 |
^ handler handlerForSignal:signal. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1119 |
]. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1120 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1121 |
^ nil |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1122 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1123 |
"Created: / 25.7.1999 / 19:52:58 / stefan" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1124 |
"Modified: / 26.7.1999 / 14:30:42 / stefan" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1125 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1126 |
|
4542
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1127 |
handlerProtectedBlock:doBlock inContext:context |
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1128 |
"set the handlerProtectedBlock in context. |
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1129 |
Needed for #restartDo:" |
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1130 |
|
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4542
diff
changeset
|
1131 |
"theContext selector must be #on:do: or #valueWithExceptionHandler:" |
4542
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1132 |
context receiver:doBlock |
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1133 |
|
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1134 |
" |
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1135 |
[1/0] on:Error do:[:ex| ex restartDo:[55]] |
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1136 |
" |
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1137 |
|
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1138 |
|
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1139 |
|
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1140 |
! |
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1141 |
|
4476 | 1142 |
handlingExceptionInContext:theContext |
4471
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1143 |
"answer the handling signal from aContext." |
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1144 |
|
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4542
diff
changeset
|
1145 |
"theContext selector must be #on:do: or #valueWithExceptionHandler:" |
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4542
diff
changeset
|
1146 |
^ theContext argAt:1. |
4471
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1147 |
|
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1148 |
! |
f5ca98d3a5d9
added #handlingSignalInContext:
Claus Gittinger <cg@exept.de>
parents:
4464
diff
changeset
|
1149 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1150 |
on:aSignal do:exceptionBlock |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1151 |
"added for ST/V compatibility; evaluate the receiver, |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1152 |
handling aSignal. The argument, exceptionBlock is evaluated |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1153 |
if the signal is raised during evaluation. |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1154 |
Warning: no warranty, if the code below mimics ST/V's behavior |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1155 |
correctly - give me a note if it does not ." |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1156 |
|
4542
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1157 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1158 |
<exception: #handle> |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1159 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1160 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1161 |
^ self value. "the real logic is in Exception>>doRaise" |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1162 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1163 |
" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1164 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1165 |
1 foo |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1166 |
] on:MessageNotUnderstoodSignal do:[:ex | self halt] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1167 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1168 |
[ |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1169 |
1 foo |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1170 |
] on:SignalSet anySignal do:[:ex| 2 bar. self halt] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1171 |
" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1172 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1173 |
"Modified: / 26.7.1999 / 15:30:48 / stefan" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1174 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1175 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1176 |
valueWithExceptionHandler:handler |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1177 |
"evaluate myself. If any of the signals in handler is raised, |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1178 |
evaluate the corresponding handler block." |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1179 |
|
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4542
diff
changeset
|
1180 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1181 |
<exception: #handle> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1182 |
|
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1183 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1184 |
^ self value. "the real logic is in Exception>>doRaise" |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1185 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1186 |
"Created: / 26.7.1999 / 11:23:45 / stefan" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1187 |
"Modified: / 26.7.1999 / 11:24:06 / stefan" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1188 |
! ! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1189 |
|
623 | 1190 |
!Block methodsFor:'looping'! |
325 | 1191 |
|
623 | 1192 |
doUntil:aBlock |
1193 |
"repeat the receiver block until aBlock evaluates to true. |
|
1194 |
The receiver is evaluated at least once. |
|
1195 |
This is the same as '... doWhile:[... not]' " |
|
325 | 1196 |
|
623 | 1197 |
"this implementation is for purists ... :-)" |
1198 |
||
1199 |
self value. |
|
1200 |
aBlock value ifTrue:[^ nil]. |
|
1201 |
thisContext restart |
|
325 | 1202 |
|
1203 |
" |
|
623 | 1204 |
|n| |
154 | 1205 |
|
623 | 1206 |
n := 1. |
1207 |
[n printNewline] doUntil:[ (n := n + 1) > 5 ] |
|
154 | 1208 |
" |
1 | 1209 |
! |
1210 |
||
623 | 1211 |
doWhile:aBlock |
1212 |
"repeat the receiver block until aBlock evaluates to false. |
|
1213 |
The receiver is evaluated at least once." |
|
67 | 1214 |
|
154 | 1215 |
"this implementation is for purists ... :-)" |
1216 |
||
623 | 1217 |
self value. |
1218 |
aBlock value ifFalse:[^ nil]. |
|
1219 |
thisContext restart |
|
1220 |
||
1221 |
" |
|
1222 |
|n| |
|
1223 |
||
1224 |
n := 1. |
|
1225 |
[n printNewline] doWhile:[ (n := n + 1) <= 5 ] |
|
1226 |
" |
|
1227 |
! |
|
1228 |
||
1229 |
loop |
|
1211 | 1230 |
"repeat the receiver forever |
1231 |
(the receiver block should contain a return somewhere). |
|
1232 |
The implementation below was inspired by a corresponding Self method." |
|
623 | 1233 |
|
1234 |
self value. |
|
67 | 1235 |
thisContext restart |
1236 |
||
1237 |
" |
|
1238 |
|n| |
|
1239 |
||
1240 |
n := 1. |
|
623 | 1241 |
[ |
2238 | 1242 |
n printNewline. |
1243 |
n >= 10 ifTrue:[^ nil]. |
|
1244 |
n := n + 1 |
|
623 | 1245 |
] loop |
1246 |
" |
|
1211 | 1247 |
|
1248 |
"Modified: 18.4.1996 / 13:50:40 / cg" |
|
623 | 1249 |
! |
1250 |
||
1251 |
loopWithExit |
|
1252 |
"the receiver must be a block of one argument. It is evaluated in a loop forever, |
|
1253 |
and is passed a block, which, if sent a value:-message, will exit the receiver block, |
|
1254 |
returning the parameter of the value:-message. Used for loops with exit in the middle. |
|
1255 |
Inspired by a corresponding Self method." |
|
1256 |
||
1257 |
|exitBlock| |
|
1258 |
||
1259 |
exitBlock := [:exitValue | ^ exitValue]. |
|
1260 |
[true] whileTrue:[self value:exitBlock] |
|
1261 |
||
1262 |
" |
|
1263 |
|i| |
|
1264 |
i := 1. |
|
1265 |
[:exit | |
|
1422 | 1266 |
Transcript showCR:i. |
623 | 1267 |
i == 5 ifTrue:[exit value:'thats it']. |
1268 |
i := i + 1 |
|
1269 |
] loopWithExit |
|
1270 |
" |
|
1271 |
! |
|
1272 |
||
1273 |
repeat |
|
1211 | 1274 |
"repeat the receiver forever - same as loop, for ST-80 compatibility. |
1275 |
(the receiver block should contain a return somewhere)." |
|
623 | 1276 |
|
1277 |
self value. |
|
1278 |
thisContext restart |
|
1211 | 1279 |
|
1280 |
"Modified: 18.4.1996 / 13:50:55 / cg" |
|
623 | 1281 |
! |
1282 |
||
1283 |
valueWithExit |
|
1284 |
"the receiver must be a block of one argument. It is evaluated, and is passed a block, |
|
1285 |
which, if sent a value:-message, will exit the receiver block, returning the parameter of the |
|
1286 |
value:-message. Used for premature returns to the caller. |
|
1287 |
Taken from a manchester goody (a similar construct also appears in Self)." |
|
1288 |
||
1211 | 1289 |
^ self value:[:exitValue | ^exitValue] |
623 | 1290 |
|
1291 |
" |
|
1292 |
[:exit | |
|
2238 | 1293 |
1 to:10 do:[:i | |
1294 |
Transcript showCR:i. |
|
1295 |
i == 5 ifTrue:[exit value:'thats it'] |
|
1296 |
]. |
|
1297 |
'regular block-value; never returned' |
|
623 | 1298 |
] valueWithExit |
1299 |
" |
|
1211 | 1300 |
|
1301 |
"Modified: 18.4.1996 / 13:51:38 / cg" |
|
623 | 1302 |
! |
1303 |
||
5215 | 1304 |
valueWithRestart |
1305 |
|myContext restartAction| |
|
1306 |
||
1307 |
myContext := thisContext. |
|
1308 |
restartAction := [ myContext restart ]. |
|
1309 |
^ self value:restartAction. |
|
1310 |
||
1311 |
" |
|
1312 |
[:restart | |
|
1313 |
(self confirm:'try again ?') ifTrue:[ |
|
1314 |
restart value. |
|
1315 |
] |
|
1316 |
] valueWithRestart |
|
1317 |
" |
|
1318 |
||
1319 |
"Modified: / 25.1.2000 / 21:47:50 / cg" |
|
1320 |
! |
|
1321 |
||
623 | 1322 |
whileFalse |
1323 |
"evaluate the receiver while it evaluates to false (ST80 compatibility)" |
|
1324 |
||
1325 |
"this implementation is for purists ... :-)" |
|
1326 |
||
1327 |
self value ifTrue:[^ nil]. |
|
1328 |
thisContext restart |
|
1329 |
||
1330 |
" |
|
1331 |
|n| |
|
1332 |
||
1333 |
n := 1. |
|
1334 |
[n printNewline. (n := n + 1) > 10] whileFalse |
|
67 | 1335 |
" |
1336 |
! |
|
1 | 1337 |
|
67 | 1338 |
whileFalse:aBlock |
1339 |
"evaluate the argument, aBlock while the receiver evaluates to false. |
|
1340 |
- usually open coded by compilers, but needed here for #perform |
|
1341 |
and expression evaluation." |
|
1342 |
||
154 | 1343 |
"this implementation is for purists ... :-)" |
1344 |
||
67 | 1345 |
self value ifTrue:[^ nil]. |
1346 |
aBlock value. |
|
1347 |
thisContext restart |
|
1348 |
||
1349 |
" |
|
1350 |
|n| |
|
1351 |
||
1352 |
n := 1. |
|
1353 |
[n > 10] whileFalse:[ |
|
154 | 1354 |
n printNewline. |
1355 |
n := n + 1 |
|
67 | 1356 |
] |
1357 |
" |
|
1 | 1358 |
! |
1359 |
||
1360 |
whileTrue |
|
67 | 1361 |
"evaluate the receiver while it evaluates to true (ST80 compatibility)" |
1 | 1362 |
|
154 | 1363 |
"this implementation is for purists ... :-)" |
1364 |
||
67 | 1365 |
self value ifFalse:[^ nil]. |
1366 |
thisContext restart |
|
1 | 1367 |
|
67 | 1368 |
" |
1369 |
|n| |
|
1 | 1370 |
|
67 | 1371 |
n := 1. |
1372 |
[n printNewline. (n := n + 1) <= 10] whileTrue |
|
1373 |
" |
|
1 | 1374 |
! |
1375 |
||
623 | 1376 |
whileTrue:aBlock |
1377 |
"evaluate the argument, aBlock while the receiver evaluates to true. |
|
1378 |
- usually open coded by compilers, but needed here for #perform |
|
1379 |
and expression evaluation." |
|
1 | 1380 |
|
154 | 1381 |
"this implementation is for purists ... :-)" |
1382 |
||
623 | 1383 |
self value ifFalse:[^ nil]. |
1384 |
aBlock value. |
|
67 | 1385 |
thisContext restart |
1386 |
||
1387 |
" |
|
1388 |
|n| |
|
1 | 1389 |
|
67 | 1390 |
n := 1. |
623 | 1391 |
[n <= 10] whileTrue:[ |
154 | 1392 |
n printNewline. |
1393 |
n := n + 1 |
|
623 | 1394 |
] |
68 | 1395 |
" |
67 | 1396 |
! ! |
1397 |
||
92 | 1398 |
!Block methodsFor:'printing & storing'! |
1 | 1399 |
|
1400 |
printOn:aStream |
|
44 | 1401 |
"append a a printed representation of the block to aStream" |
1402 |
||
213 | 1403 |
|homeClass h sel methodClass| |
54 | 1404 |
|
1405 |
"cheap blocks have no home context, but a method instead" |
|
1406 |
||
1407 |
(home isNil or:[home isContext not]) ifTrue:[ |
|
154 | 1408 |
aStream nextPutAll:'[] in '. |
1 | 1409 |
|
154 | 1410 |
" |
1411 |
currently, some cheap blocks don't know where they have been created |
|
1412 |
" |
|
1413 |
aStream nextPutAll:' ??? (optimized)'. |
|
1414 |
^ self |
|
54 | 1415 |
]. |
1416 |
||
1417 |
"a full blown block (with home, but without method)" |
|
1418 |
||
1419 |
aStream nextPutAll:'[] in '. |
|
154 | 1420 |
h := self methodHome. |
1421 |
sel := h selector. |
|
1422 |
"/ old: |
|
1423 |
"/ home receiver class name printOn:aStream. |
|
1424 |
"/ new: |
|
212 | 1425 |
"/ (h searchClass whichClassImplements:sel) name printOn:aStream. |
213 | 1426 |
methodClass := h methodClass. |
1427 |
methodClass isNil ifTrue:[ |
|
1428 |
'UnboundMethod' printOn:aStream. |
|
1429 |
] ifFalse:[ |
|
1430 |
methodClass name printOn:aStream. |
|
1431 |
]. |
|
54 | 1432 |
aStream nextPut:$-. |
154 | 1433 |
sel printOn:aStream. |
54 | 1434 |
|
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1435 |
"/ |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1436 |
"/ aStream nextPutAll:'[] in '. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1437 |
"/ homeClass := home containingClass. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1438 |
"/ homeClass notNil ifTrue:[ |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1439 |
"/ homeClass name printOn:aStream. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1440 |
"/ aStream space. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1441 |
"/ (homeClass selectorForMethod:home) printOn:aStream |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1442 |
"/ ] ifFalse:[ |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1443 |
"/ aStream nextPutAll:' ???' |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1444 |
"/ ] |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1445 |
"/ |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1446 |
|
1 | 1447 |
! ! |
623 | 1448 |
|
1449 |
!Block methodsFor:'private accessing'! |
|
1450 |
||
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
1451 |
byteCode:bCode numArgs:numArgs numStack:numStack sourcePosition:srcPos initialPC:iPC literals:lits |
1265 | 1452 |
"set all relevant internals. |
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1453 |
DANGER ALERT: this interface is strictly private." |
623 | 1454 |
|
1455 |
byteCode := bCode. |
|
1456 |
nargs := numArgs. |
|
1457 |
sourcePos := srcPos. |
|
1458 |
initialPC := iPC. |
|
1777 | 1459 |
flags := 0. |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
1460 |
self stackSize:numStack. |
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1461 |
self literals:lits. |
1265 | 1462 |
|
1463 |
"Modified: 23.4.1996 / 16:05:30 / cg" |
|
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1464 |
"Modified: 24.6.1996 / 12:37:37 / stefan" |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
1465 |
"Created: 13.4.1997 / 00:00:57 / cg" |
623 | 1466 |
! |
1467 |
||
1468 |
initialPC:initial |
|
1265 | 1469 |
"set the initial pc for evaluation. |
1470 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 1471 |
|
1472 |
initialPC := initial |
|
1265 | 1473 |
|
1474 |
"Modified: 23.4.1996 / 16:05:39 / cg" |
|
623 | 1475 |
! |
1476 |
||
1477 |
numArgs:numArgs |
|
1265 | 1478 |
"set the number of arguments the receiver expects for evaluation. |
1479 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 1480 |
|
1481 |
nargs := numArgs |
|
1265 | 1482 |
|
1483 |
"Modified: 23.4.1996 / 16:05:52 / cg" |
|
623 | 1484 |
! |
1485 |
||
1486 |
sourcePosition:position |
|
1265 | 1487 |
"set the position of the source within my method. |
1488 |
This interface is for the compiler only." |
|
623 | 1489 |
|
1490 |
sourcePos := position |
|
1265 | 1491 |
|
1492 |
"Modified: 23.4.1996 / 16:06:19 / cg" |
|
623 | 1493 |
! ! |
1494 |
||
1495 |
!Block methodsFor:'privileged evaluation'! |
|
1496 |
||
1497 |
valueUninterruptably |
|
1498 |
"evaluate the receiver with interrupts blocked. |
|
1499 |
This does not prevent preemption by a higher priority processes |
|
1500 |
if any becomes runnable due to the evaluation of the receiver |
|
1501 |
(i.e. if a semaphore is signalled)." |
|
1502 |
||
2301 | 1503 |
"we must keep track of blocking-state if this is called nested" |
1504 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
1505 |
"/ already blocked. |
|
1506 |
^ self value |
|
1507 |
]. |
|
864 | 1508 |
|
2301 | 1509 |
^ self valueNowOrOnUnwindDo:[OperatingSystem unblockInterrupts]. |
623 | 1510 |
! |
1511 |
||
1512 |
valueUnpreemptively |
|
1513 |
"evaluate the receiver without the possiblity of preemption |
|
1514 |
(i.e. at a very high priority)" |
|
1515 |
||
1516 |
|oldPrio activeProcess| |
|
1517 |
||
1518 |
activeProcess := Processor activeProcess. |
|
1519 |
oldPrio := activeProcess changePriority:(Processor highestPriority). |
|
864 | 1520 |
^ self valueNowOrOnUnwindDo:[ |
623 | 1521 |
activeProcess priority:oldPrio |
1522 |
] |
|
1523 |
! ! |
|
1524 |
||
1525 |
!Block methodsFor:'process creation'! |
|
1526 |
||
1527 |
fork |
|
1528 |
"create a new process executing the receiver at the current priority." |
|
1529 |
||
1530 |
^ self newProcess resume |
|
1531 |
! |
|
1532 |
||
1533 |
forkAt:priority |
|
1534 |
"create a new process executing the receiver at a different priority." |
|
1535 |
||
1536 |
^ (self newProcess priority:priority) resume |
|
1537 |
! |
|
1538 |
||
1539 |
forkWith:argArray |
|
1540 |
"create a new process executing the receiver, |
|
1541 |
passing elements in argArray as arguments to the receiver block." |
|
1542 |
||
1543 |
^ [self valueWithArguments:argArray] fork. |
|
1544 |
! |
|
1545 |
||
1546 |
newProcess |
|
1547 |
"create a new (unscheduled) process executing the receiver" |
|
1548 |
||
1549 |
^ Process for:self priority:(Processor activePriority) |
|
1550 |
! |
|
1551 |
||
1552 |
newProcessWithArguments:argArray |
|
1553 |
"create a new (unscheduled) process executing the receiver, |
|
1554 |
passing the elements in argArray as arguments to the receiver block." |
|
1555 |
||
1556 |
^ [self valueWithArguments:argArray] newProcess |
|
1557 |
! |
|
1558 |
||
1559 |
promise |
|
1560 |
"create a promise on the receiver. The promise will evaluate the |
|
1561 |
receiver and promise to return the value with the #value message. |
|
1562 |
The evaluation will be performed as a separate process. |
|
1563 |
Asking the promise for its value will either block the asking process |
|
1564 |
(if the evaluation has not yet been finished) or return the value |
|
1565 |
immediately." |
|
1566 |
||
1567 |
^ Promise value:self |
|
1568 |
||
1569 |
" |
|
1570 |
|p| |
|
1571 |
||
1572 |
p := [1000 factorial] promise. |
|
1573 |
'do something else ...'. |
|
1574 |
p value |
|
1575 |
" |
|
1576 |
! |
|
1577 |
||
1578 |
promiseAt:prio |
|
1579 |
"create a promise on the receiver. The promise will evaluate the |
|
1580 |
receiver and promise to return the value with the #value message. |
|
1581 |
The evaluation will be performed as a separate process running at prio. |
|
1582 |
Asking the promise for its value will either block the asking process |
|
1583 |
(if the evaluation has not yet been finished) or return the value |
|
1584 |
immediately." |
|
1585 |
||
1586 |
^ Promise value:self priority:prio |
|
1587 |
! ! |
|
1588 |
||
1589 |
!Block methodsFor:'testing'! |
|
1590 |
||
1591 |
isBlock |
|
1592 |
"return true, if this is a block - yes I am" |
|
1593 |
||
1594 |
^ true |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1595 |
! |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1596 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1597 |
isVarArgBlock |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1598 |
"return true, if this block accepts a variable number of arguments" |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1599 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1600 |
^ false |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1601 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
1602 |
"Created: 23.1.1997 / 04:59:51 / cg" |
623 | 1603 |
! ! |
1604 |
||
1605 |
!Block methodsFor:'unwinding'! |
|
1606 |
||
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1607 |
unwindHandlerInContext:aContext |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1608 |
"given a context which has been marked for unwind, |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1609 |
retrieve the handler block. |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1610 |
This avoids hardwiring access to the first argument in |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1611 |
#unwind methods (and theoretically allows for other unwinding |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1612 |
methods to be added)" |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1613 |
|
4896 | 1614 |
aContext selector == #'value:onUnwindDo:' ifTrue:[ |
1615 |
^ aContext argAt:2 |
|
1616 |
]. |
|
1617 |
||
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1618 |
"/ for now, only #valueNowOrOnUnwindDo: |
4896 | 1619 |
"/ or #valueOnUnwindDo: |
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1620 |
|
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1621 |
^ aContext argAt:1 |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1622 |
! |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
1623 |
|
4896 | 1624 |
value:arg onUnwindDo:aBlock |
1625 |
"evaluate the receiver, passing it one argument |
|
1626 |
- when some method sent within unwinds (i.e. does |
|
1627 |
a long return), evaluate the argument, aBlock. |
|
1628 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
1629 |
executed regardless of error actions" |
|
1630 |
||
1631 |
<exception: #unwind> |
|
1632 |
||
1633 |
|v| |
|
1634 |
||
1635 |
"/ thisContext markForUnwind. -- same as above pragma |
|
1636 |
v := self value:arg. "the real logic is in Context>>unwind" |
|
1637 |
thisContext unmarkForUnwind. |
|
1638 |
^ v |
|
1639 |
||
1640 |
" |
|
1641 |
|s| |
|
1642 |
||
1643 |
s := 'Makefile' asFilename readStream. |
|
1644 |
[:arg | |
|
1645 |
^ self |
|
1646 |
] value:12345 onUnwindDo:[ |
|
1647 |
Transcript showCR:'closing the stream - even though a return occurred'. |
|
1648 |
s close |
|
1649 |
] |
|
1650 |
" |
|
1651 |
" |
|
1652 |
[ |
|
1653 |
|s| |
|
1654 |
||
1655 |
s := 'Makefile' asFilename readStream. |
|
1656 |
[:arg | |
|
1657 |
Processor activeProcess terminate |
|
1658 |
] value:12345 onUnwindDo:[ |
|
1659 |
Transcript showCR:'closing the stream - even though process was terminated'. |
|
1660 |
s close |
|
1661 |
] |
|
1662 |
] fork |
|
1663 |
" |
|
1664 |
||
1665 |
! |
|
1666 |
||
623 | 1667 |
valueNowOrOnUnwindDo:aBlock |
1668 |
"evaluate the receiver - after that, or when some method sent within unwinds (i.e. does |
|
1669 |
a long return), evaluate the argument, aBlock. |
|
1670 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
1671 |
executed regardless of error actions" |
|
1672 |
||
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1673 |
<exception: #unwind> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1674 |
|
623 | 1675 |
|v| |
1676 |
||
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1677 |
"/ thisContext markForUnwind. -- same as above pragma |
623 | 1678 |
v := self value. "the real logic is in Context>>unwind" |
1187
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
1679 |
thisContext unmarkForUnwind. |
623 | 1680 |
aBlock value. |
1681 |
^ v |
|
1682 |
||
1683 |
" |
|
1684 |
in the following example, f will be closed even if the block |
|
1685 |
returns with 'oops'. There are many more applications of this kind |
|
1686 |
found in the system. |
|
1687 |
" |
|
1688 |
" |
|
1689 |
|f| |
|
1690 |
||
1691 |
f := 'Makefile' asFilename readStream. |
|
1692 |
[ |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1693 |
l := f nextLine. |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1694 |
l isNil ifTrue:[^ 'oops'] |
623 | 1695 |
] valueNowOrOnUnwindDo:[ |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1696 |
f close |
623 | 1697 |
] |
1698 |
" |
|
1187
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
1699 |
|
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
1700 |
"Modified: 16.4.1996 / 11:05:26 / stefan" |
623 | 1701 |
! |
1702 |
||
1703 |
valueOnUnwindDo:aBlock |
|
1704 |
"evaluate the receiver - when some method sent within unwinds (i.e. does |
|
1705 |
a long return), evaluate the argument, aBlock. |
|
1706 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
1707 |
executed regardless of error actions" |
|
1708 |
||
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1709 |
<exception: #unwind> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1710 |
|
2286 | 1711 |
|v| |
1712 |
||
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1713 |
"/ thisContext markForUnwind. -- same as above pragma |
2286 | 1714 |
v := self value. "the real logic is in Context>>unwind" |
1715 |
thisContext unmarkForUnwind. |
|
1716 |
^ v |
|
1717 |
||
4896 | 1718 |
" |
1719 |
|s| |
|
1720 |
||
1721 |
s := 'Makefile' asFilename readStream. |
|
1722 |
[ |
|
1723 |
^ self |
|
1724 |
] valueOnUnwindDo:[ |
|
1725 |
Transcript showCR:'closing the stream - even though a return occurred'. |
|
1726 |
s close |
|
1727 |
] |
|
1728 |
" |
|
1729 |
" |
|
1730 |
[ |
|
1731 |
|s| |
|
1732 |
||
1733 |
s := 'Makefile' asFilename readStream. |
|
1734 |
[ |
|
1735 |
Processor activeProcess terminate |
|
1736 |
] valueOnUnwindDo:[ |
|
1737 |
Transcript showCR:'closing the stream - even though process was terminated'. |
|
1738 |
s close |
|
1739 |
] |
|
1740 |
] fork |
|
1741 |
" |
|
1742 |
||
623 | 1743 |
! ! |
1744 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
1745 |
!Block class methodsFor:'documentation'! |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1746 |
|
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1747 |
version |
5349 | 1748 |
^ '$Header: /cvs/stx/stx/libbasic/Block.st,v 1.96 2000-04-01 13:04:33 cg Exp $' |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1749 |
! ! |
623 | 1750 |
Block initialize! |