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