author | Merge Script |
Thu, 14 Jul 2016 06:48:34 +0200 | |
branch | jv |
changeset 20150 | 3a825b090d4e |
parent 19812 | 0866264d6eed |
parent 20144 | edb8a61ce8eb |
child 20205 | 03e626304d06 |
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 |
" |
|
5349 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
17301 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
4299 | 16 |
CompiledCode variableSubclass:#Block |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
17 |
instanceVariableNames:'home nargs sourcePos initialPC' |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
18 |
classVariableNames:'InvalidNewSignal' |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
19 |
poolDictionaries:'' |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
20 |
category:'Kernel-Methods' |
1 | 21 |
! |
22 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
23 |
!Block class methodsFor:'documentation'! |
1 | 24 |
|
92 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
154 | 28 |
All Rights Reserved |
92 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
1 | 39 |
documentation |
40 |
" |
|
67 | 41 |
Blocks are pieces of executable code which can be evaluated by sending |
42 |
them a value-message (''value'', ''value:'', ''value:value:'' etc). |
|
1 | 43 |
|
1265 | 44 |
In smalltalk, Blocks provide the basic (and heavily used) mechanism |
45 |
for looping, enumerating collection elements, visitors, exception |
|
46 |
handling, unwinding, delayed execution and processes. |
|
47 |
||
1254 | 48 |
Blocks are never created explicitely; the only creation |
49 |
is done by the compilers, when some sourceCode is compiled to either |
|
50 |
machine or byteCode. |
|
51 |
||
67 | 52 |
Blocks with arguments need a message of type ''value:arg1 ... value:argn'' |
53 |
for evaluation; the number of arguments passed when evaluating must match |
|
54 |
the number of arguments the block was declared with otherwise an error is |
|
55 |
raised. Blocks without args need a ''value'' message for evaluation. |
|
1 | 56 |
|
154 | 57 |
Blocks keep a reference to the context where the block was declared - |
67 | 58 |
this allows blocks to access the methods arguments and/or variables. |
154 | 59 |
This is still true after the method has returned - since the |
67 | 60 |
block keeps this reference, the methods context will NOT die in this case. |
222 | 61 |
(i.e. Blocks are closures in Smalltalk/X) |
1 | 62 |
|
67 | 63 |
A return (via ^-statement) out of a block will force a return from the |
64 |
blocks method context (if it is still living) - this make the implementation |
|
65 |
of long-jumps and control structures possible. |
|
18252 | 66 |
(If the method is not alive (i.e. has already returned), a return out of the |
154 | 67 |
block will trigger an error) |
1 | 68 |
|
67 | 69 |
Long-jump is done by defining a catchBlock as ''[^ self]'' |
18252 | 70 |
somewhere up in the calling-tree. Then, to do the long-jump from out of some |
67 | 71 |
deeply nested method, simply do: ''catchBlock value''. |
1 | 72 |
|
1293 | 73 |
[Instance variables:] |
1 | 74 |
|
222 | 75 |
home <Context> the context where this block was created (i.e. defined) |
2238 | 76 |
this may be a blockContext or a methodContext |
222 | 77 |
nargs <SmallInteger> the number of arguments the block expects |
78 |
sourcePos <SmallInteger> the character position of its source, in chars |
|
2238 | 79 |
relative to methods source beginning |
222 | 80 |
initialPC <SmallInteger> the start position within the byteCode |
2238 | 81 |
for compiled blocks, this is nil. |
222 | 82 |
|
83 |
||
1293 | 84 |
[Class variables:] |
222 | 85 |
|
86 |
InvalidNewSignal raised if a Block is tried to be created |
|
2238 | 87 |
with new (which is not allowed). |
88 |
Only the VM is allowed to create Blocks. |
|
1 | 89 |
|
1293 | 90 |
|
67 | 91 |
NOTICE: layout known by runtime system and compiler - do not change |
1293 | 92 |
|
93 |
[author:] |
|
2238 | 94 |
Claus Gittinger |
1293 | 95 |
|
96 |
[see also:] |
|
2238 | 97 |
Process Context |
98 |
Collection |
|
99 |
( contexts. blocks & unwinding : programming/contexts.html) |
|
1 | 100 |
" |
1265 | 101 |
! |
102 |
||
103 |
examples |
|
104 |
" |
|
1293 | 105 |
define a block and evaluate it: |
18252 | 106 |
[exBegin] |
107 |
|b| |
|
108 |
||
109 |
b := [ Transcript showCR:'hello' ]. |
|
110 |
||
111 |
Transcript showCR:'now evaluating the block ...'. |
|
112 |
b value. |
|
113 |
[exEnd] |
|
114 |
||
115 |
||
116 |
||
117 |
even here, blocks are involved: |
|
1265 | 118 |
(although, the compiler optimizes things if possible) |
18252 | 119 |
[exBegin] |
120 |
Transcript showCR:'now evaluating one of two blocks ...'. |
|
121 |
1 > 4 ifTrue:[ |
|
122 |
Transcript showCR:'foo' |
|
123 |
] ifFalse:[ |
|
124 |
Transcript showCR:'bar' |
|
125 |
] |
|
126 |
[exEnd] |
|
1265 | 127 |
|
128 |
||
1293 | 129 |
|
1265 | 130 |
here things become obvious: |
18252 | 131 |
[exBegin] |
132 |
|yesBlock noBlock| |
|
133 |
||
134 |
yesBlock := [ Transcript showCR:'foo' ]. |
|
135 |
noBlock := [ Transcript showCR:'bar' ]. |
|
136 |
||
137 |
Transcript showCR:'now evaluating one of two blocks ...'. |
|
138 |
1 > 4 ifTrue:yesBlock |
|
139 |
ifFalse:noBlock |
|
140 |
[exEnd] |
|
1265 | 141 |
|
142 |
||
1293 | 143 |
|
1265 | 144 |
simple loops: |
145 |
not very objectOriented: |
|
18252 | 146 |
[exBegin] |
147 |
|i| |
|
148 |
||
149 |
i := 1. |
|
150 |
[i < 10] whileTrue:[ |
|
151 |
Transcript showCR:i. |
|
152 |
i := i + 1 |
|
153 |
] |
|
154 |
[exEnd] |
|
1265 | 155 |
|
156 |
||
157 |
using integer protocol: |
|
18252 | 158 |
[exBegin] |
159 |
1 to:10 do:[:i | |
|
160 |
Transcript showCR:i. |
|
161 |
] |
|
162 |
[exEnd] |
|
1265 | 163 |
|
164 |
||
165 |
interval protocol: |
|
18252 | 166 |
[exBegin] |
167 |
(1 to:10) do:[:i | |
|
168 |
Transcript showCR:i. |
|
169 |
] |
|
170 |
[exEnd] |
|
1265 | 171 |
|
172 |
||
1293 | 173 |
|
1265 | 174 |
looping over collections: |
175 |
||
1293 | 176 |
bad code: |
177 |
(only works with numeric-indexable collections) |
|
18252 | 178 |
[exBegin] |
179 |
|i coll| |
|
180 |
||
181 |
coll := #(9 8 7 6 5). |
|
182 |
i := 1. |
|
183 |
[i <= coll size] whileTrue:[ |
|
184 |
Transcript showCR:(coll at:i). |
|
185 |
i := i + 1. |
|
186 |
] |
|
187 |
[exEnd] |
|
1265 | 188 |
|
189 |
||
190 |
||
1293 | 191 |
just as bad (well, marginally better ;-): |
192 |
(only works with numeric-indexable collections) |
|
18252 | 193 |
[exBegin] |
194 |
|coll| |
|
195 |
||
196 |
coll := #(9 8 7 6 5). |
|
197 |
1 to:coll size do:[:i | |
|
198 |
Transcript showCR:(coll at:i). |
|
199 |
] |
|
200 |
[exEnd] |
|
1265 | 201 |
|
202 |
||
203 |
||
1293 | 204 |
the smalltalk way: |
205 |
(works with any collection) |
|
18252 | 206 |
[exBegin] |
207 |
|coll| |
|
208 |
||
209 |
coll := #(9 8 7 6 5). |
|
210 |
coll do:[:element | |
|
211 |
Transcript showCR:element. |
|
212 |
] |
|
213 |
[exEnd] |
|
214 |
||
1265 | 215 |
Rule: use enumeration protocol of the collection instead of |
18252 | 216 |
manually indexing it. [with few exceptions] |
1265 | 217 |
|
218 |
||
219 |
||
220 |
processes: |
|
221 |
||
222 |
forking a lightweight process (thread): |
|
18252 | 223 |
[exBegin] |
224 |
[ |
|
225 |
Transcript showCR:'waiting ...'. |
|
226 |
Delay waitForSeconds:2. |
|
227 |
Transcript showCR:'here I am'. |
|
228 |
] fork |
|
229 |
[exEnd] |
|
230 |
||
231 |
||
232 |
||
1265 | 233 |
some with low prio: |
18252 | 234 |
[exBegin] |
235 |
[ |
|
236 |
Transcript showCR:'computing ...'. |
|
237 |
10000 factorial. |
|
238 |
Transcript showCR:'here I am'. |
|
239 |
] forkAt:(Processor userBackgroundPriority) |
|
240 |
[exEnd] |
|
1265 | 241 |
|
242 |
||
1293 | 243 |
|
244 |
handling exceptions: |
|
18252 | 245 |
[exBegin] |
246 |
Error handle:[:ex | |
|
247 |
Transcript showCR:'exception handler forces return'. |
|
248 |
ex return |
|
249 |
] do:[ |
|
250 |
Transcript showCR:'now, doing something bad ...'. |
|
251 |
1 / 0. |
|
252 |
Transcript showCR:'not reached' |
|
253 |
] |
|
254 |
[exEnd] |
|
1265 | 255 |
|
256 |
||
1293 | 257 |
|
258 |
performing cleanup actions: |
|
18252 | 259 |
[exBegin] |
260 |
Error handle:[:ex | |
|
261 |
Transcript showCR:'exception handler forces return'. |
|
262 |
ex return |
|
263 |
] do:[ |
|
264 |
[ |
|
265 |
Transcript showCR:'doing something bad ...'. |
|
266 |
1 / 0. |
|
267 |
Transcript showCR:'not reached' |
|
268 |
] ifCurtailed:[ |
|
269 |
Transcript showCR:'cleanup' |
|
270 |
] |
|
271 |
] |
|
272 |
[exEnd] |
|
1265 | 273 |
|
274 |
||
1293 | 275 |
delayed execution (visitor pattern): |
18252 | 276 |
(looking carefully into the example, |
1293 | 277 |
C/C++ programmers may raise their eyes ;-) |
18252 | 278 |
[exBegin] |
279 |
|showBlock countBlock |
|
280 |
howMany |
|
281 |
top panel b1 b2| |
|
282 |
||
283 |
howMany := 0. |
|
284 |
||
285 |
showBlock := [ Transcript showCR:howMany ]. |
|
286 |
countBlock := [ howMany := howMany + 1 ]. |
|
287 |
||
288 |
top := StandardSystemView extent:200@200. |
|
289 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
290 |
||
291 |
b1 := Button label:'count up' in:panel. |
|
292 |
b1 action:countBlock. |
|
293 |
||
294 |
b2 := Button label:'show value' in:panel. |
|
295 |
b2 action:showBlock. |
|
296 |
||
297 |
top open. |
|
298 |
||
299 |
Transcript showCR:'new process started;'. |
|
300 |
Transcript showCR:'notice: the blocks can still access the'. |
|
301 |
Transcript showCR:' howMany local variable.'. |
|
302 |
[exEnd] |
|
1265 | 303 |
" |
1 | 304 |
! ! |
305 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
306 |
!Block class methodsFor:'initialization'! |
1 | 307 |
|
308 |
initialize |
|
1254 | 309 |
"create signals raised by various errors" |
1 | 310 |
|
48 | 311 |
InvalidNewSignal isNil ifTrue:[ |
18252 | 312 |
InvalidNewSignal := Error newSignalMayProceed:false. |
313 |
InvalidNewSignal nameClass:self message:#invalidNewSignal. |
|
314 |
InvalidNewSignal notifierString:'blocks are only created by the system'. |
|
48 | 315 |
] |
1254 | 316 |
|
317 |
"Modified: 22.4.1996 / 16:34:20 / cg" |
|
1 | 318 |
! ! |
319 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
320 |
!Block class methodsFor:'instance creation'! |
1 | 321 |
|
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
322 |
byteCode:bCode numArgs:numArgs numStack:nStack sourcePosition:sourcePos initialPC:initialPC literals:literals |
1 | 323 |
"create a new cheap (homeless) block. |
222 | 324 |
Not for public use - this is a special hook for the compiler." |
1 | 325 |
|
5766
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
326 |
^ self |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
327 |
byteCode:bCode numArgs:numArgs numVars:0 numStack:nStack sourcePosition:sourcePos initialPC:initialPC literals:literals |
5766
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
328 |
! |
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
329 |
|
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
330 |
byteCode:bCode numArgs:numArgs numVars:numVars numStack:nStack sourcePosition:sourcePos initialPC:initialPC literals:literals |
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
331 |
"create a new cheap (homeless) block. |
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
332 |
Not for public use - this is a special hook for the compiler." |
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
333 |
|
1 | 334 |
|newBlock| |
335 |
||
18252 | 336 |
newBlock := (super basicNew:(literals size)) |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
337 |
byteCode:bCode |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
338 |
numArgs:numArgs |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
339 |
numVars:numVars |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
340 |
numStack:nStack |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
341 |
sourcePosition:sourcePos |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
342 |
initialPC:initialPC |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
343 |
literals:literals. |
1 | 344 |
^ newBlock |
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
345 |
|
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
346 |
"Modified: 24.6.1996 / 12:36:48 / stefan" |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
347 |
"Created: 13.4.1997 / 00:04:09 / cg" |
1 | 348 |
! |
349 |
||
22 | 350 |
new |
4299 | 351 |
"catch creation of blocks - only the system creates blocks. |
352 |
If you really need a block (assuming, you are some compiler), |
|
353 |
use basicNew and setup the instance carefully" |
|
1 | 354 |
|
128 | 355 |
^ InvalidNewSignal raise. |
1 | 356 |
! |
357 |
||
22 | 358 |
new:size |
1 | 359 |
"catch creation of blocks - only the system creates blocks" |
360 |
||
128 | 361 |
^ InvalidNewSignal raise. |
1 | 362 |
! ! |
363 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
364 |
!Block class methodsFor:'queries'! |
1 | 365 |
|
623 | 366 |
isBuiltInClass |
1264 | 367 |
"return true if this class is known by the run-time-system. |
368 |
Here, true is returned for myself, false for subclasses." |
|
11 | 369 |
|
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
370 |
^ self == Block |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
371 |
|
1264 | 372 |
"Modified: 23.4.1996 / 15:55:58 / cg" |
1 | 373 |
! ! |
374 |
||
15850 | 375 |
|
7261 | 376 |
!Block methodsFor:'Compatibility-ANSI'! |
5349 | 377 |
|
5944 | 378 |
argumentCount |
7352 | 379 |
"VisualAge/ANSI compatibility: alias for #numArgs. |
5944 | 380 |
return the number of arguments I expect for evaluation" |
381 |
||
382 |
^ nargs |
|
383 |
||
384 |
"Created: 15.11.1996 / 11:22:02 / cg" |
|
385 |
! |
|
386 |
||
5349 | 387 |
ensure:aBlock |
17697 | 388 |
"VisualAge/ANSI compatibility: |
389 |
evaluate the receiver and return its result. |
|
5349 | 390 |
After evaluation, also evaluate aBlock but ignore its result. |
391 |
aBlock is also evaluated in case of abnormal termination. |
|
392 |
(the same as #valueNowOrOnUnwindDo:)" |
|
393 |
||
5666
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
394 |
<exception: #unwind> |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
395 |
|
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
396 |
|v| |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
397 |
|
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
398 |
v := self value. "the real logic is in Context>>unwind" |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
399 |
thisContext unmarkForUnwind. |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
400 |
aBlock value. |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
401 |
^ v |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
402 |
|
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
403 |
"/ the above is the same as in #valueNowOrOnUnwindDo: |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
404 |
"/ (actually, the previous implementation was: |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
405 |
"/ ^ self valueNowOrOnUnwindDo:aBlock |
5349 | 406 |
|
407 |
" |
|
408 |
[ |
|
18252 | 409 |
[ |
410 |
Transcript showCR:'one'. |
|
411 |
Processor activeProcess terminate. |
|
412 |
Transcript showCR:'two'. |
|
413 |
] ensure:[ |
|
414 |
Transcript showCR:'three'. |
|
415 |
]. |
|
5349 | 416 |
] fork. |
417 |
" |
|
418 |
||
419 |
" |
|
420 |
[ |
|
18252 | 421 |
[ |
422 |
Transcript showCR:'one'. |
|
423 |
Transcript showCR:'two'. |
|
424 |
] ensure:[ |
|
425 |
Transcript showCR:'three'. |
|
426 |
]. |
|
5349 | 427 |
] fork. |
428 |
" |
|
5951 | 429 |
! |
430 |
||
431 |
ifCurtailed:aBlock |
|
17697 | 432 |
"VisualAge/ANSI compatibility: |
433 |
evaluate the receiver - when some method sent within unwinds (i.e. does |
|
5951 | 434 |
a long return), evaluate the argument, aBlock. |
435 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
436 |
executed regardless of error actions. |
|
437 |
This is the same as #valueOnUnwindDo:" |
|
438 |
||
439 |
<exception: #unwind> |
|
440 |
||
441 |
|v| |
|
442 |
||
443 |
"/ thisContext markForUnwind. -- same as above pragma |
|
444 |
v := self value. "the real logic is in Context>>unwind" |
|
445 |
thisContext unmarkForUnwind. |
|
446 |
^ v |
|
447 |
||
448 |
" |
|
449 |
|s| |
|
450 |
||
451 |
s := 'Makefile' asFilename readStream. |
|
452 |
[ |
|
18252 | 453 |
^ self |
5951 | 454 |
] ifCurtailed:[ |
18252 | 455 |
Transcript showCR:'closing the stream - even though a return occurred'. |
456 |
s close |
|
5951 | 457 |
] |
458 |
" |
|
459 |
" |
|
460 |
[ |
|
18252 | 461 |
|s| |
462 |
||
463 |
s := 'Makefile' asFilename readStream. |
|
464 |
[ |
|
465 |
Processor activeProcess terminate |
|
466 |
] ifCurtailed:[ |
|
467 |
Transcript showCR:'closing the stream - even though process was terminated'. |
|
468 |
s close |
|
469 |
] |
|
5951 | 470 |
] fork |
471 |
" |
|
5349 | 472 |
! ! |
473 |
||
8440
66d126056d3d
Dolphin compatibility: #deferredValue
Stefan Vogel <sv@exept.de>
parents:
8394
diff
changeset
|
474 |
!Block methodsFor:'Compatibility-Dolphin'! |
66d126056d3d
Dolphin compatibility: #deferredValue
Stefan Vogel <sv@exept.de>
parents:
8394
diff
changeset
|
475 |
|
66d126056d3d
Dolphin compatibility: #deferredValue
Stefan Vogel <sv@exept.de>
parents:
8394
diff
changeset
|
476 |
deferredValue |
17697 | 477 |
"Dolphin compatibility method - do not use in new code. |
12118
41ee8ff1908e
comment/format in: #deferredValue
Claus Gittinger <cg@exept.de>
parents:
11998
diff
changeset
|
478 |
Dolphin's alias for futureValue" |
8440
66d126056d3d
Dolphin compatibility: #deferredValue
Stefan Vogel <sv@exept.de>
parents:
8394
diff
changeset
|
479 |
|
13767 | 480 |
^ Future new block:self |
481 |
||
482 |
"Modified: / 04-10-2011 / 14:56:27 / cg" |
|
483 |
! |
|
484 |
||
485 |
deferredValueAt:priority |
|
17697 | 486 |
"Dolphin compatibility method - do not use in new code. |
13767 | 487 |
Dolphin's alias for futureValue" |
488 |
||
18252 | 489 |
^ Future new |
490 |
priority:priority block:self |
|
13767 | 491 |
|
492 |
"Created: / 04-10-2011 / 14:55:56 / cg" |
|
8440
66d126056d3d
Dolphin compatibility: #deferredValue
Stefan Vogel <sv@exept.de>
parents:
8394
diff
changeset
|
493 |
! ! |
66d126056d3d
Dolphin compatibility: #deferredValue
Stefan Vogel <sv@exept.de>
parents:
8394
diff
changeset
|
494 |
|
7261 | 495 |
!Block methodsFor:'Compatibility-Squeak'! |
5015 | 496 |
|
18252 | 497 |
cull: optionalFirstArg |
17697 | 498 |
"activate the receiver with one or zero arguments. |
499 |
Squeak compatibility, but also present in VW Smalltalk" |
|
500 |
||
501 |
nargs >= 1 ifTrue:[^ self value:optionalFirstArg]. |
|
15089 | 502 |
^ self value |
503 |
! |
|
504 |
||
17697 | 505 |
cull: optionalFirstArg cull: optionalSecondArg |
506 |
"activate the receiver with two or less arguments. |
|
507 |
Squeak compatibility, but also present in VW Smalltalk" |
|
508 |
||
509 |
nargs >= 2 ifTrue:[^ self value:optionalFirstArg value:optionalSecondArg]. |
|
510 |
nargs = 1 ifTrue:[^ self value:optionalFirstArg]. |
|
15089 | 511 |
^ self value |
512 |
! |
|
513 |
||
17697 | 514 |
cull: optionalFirstArg cull: optionalSecondArg cull: optionalThirdArg |
515 |
"activate the receiver with three or less arguments. |
|
516 |
Squeak compatibility, but also present in VW Smalltalk" |
|
15089 | 517 |
|
518 |
nargs >= 2 ifTrue:[ |
|
18252 | 519 |
nargs >= 3 ifTrue:[ |
520 |
^ self value:optionalFirstArg value:optionalSecondArg value:optionalThirdArg |
|
521 |
]. |
|
522 |
^ self value:optionalFirstArg value:optionalSecondArg |
|
15089 | 523 |
]. |
17697 | 524 |
nargs = 1 ifTrue:[^ self value:optionalFirstArg]. |
15088 | 525 |
^ self value |
526 |
! |
|
527 |
||
5015 | 528 |
ifError:handlerBlock |
15119 | 529 |
"squeak compatibility: |
19450 | 530 |
Evaluate the receiver block and return its value, if no error occurs. |
15119 | 531 |
If an error is raised, return the value from handlerBlock. |
532 |
The handlerBlock may take 0,1 or 2 args. |
|
6159
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
533 |
(1 arg -> the exception; |
20144 | 534 |
2 args -> the errorString and the erroneous receiver)" |
6159
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
535 |
|
11934 | 536 |
|numArgs| |
537 |
||
18434 | 538 |
numArgs := handlerBlock isBlock ifTrue:[handlerBlock argumentCount] ifFalse:[0]. |
11934 | 539 |
numArgs == 1 ifTrue:[ |
18434 | 540 |
^ self on:Error do:handlerBlock |
6159
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
541 |
]. |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
542 |
|
18252 | 543 |
^ self |
18434 | 544 |
on:Error |
545 |
do:[:ex | |
|
546 |
|errString errReceiver| |
|
547 |
||
548 |
numArgs == 0 ifTrue:[ |
|
549 |
ex return:handlerBlock value |
|
550 |
] ifFalse:[ |
|
551 |
errString := ex description. |
|
552 |
errReceiver := ex suspendedContext receiver. |
|
553 |
ex return:(handlerBlock value:errString value:errReceiver) |
|
554 |
]. |
|
555 |
] |
|
6142 | 556 |
|
557 |
" |
|
558 |
|a| |
|
559 |
||
560 |
a := 0. |
|
561 |
[ 123 / a ] ifError:[:msg :rec | self halt] |
|
562 |
" |
|
6159
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
563 |
|
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
564 |
" |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
565 |
|a| |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
566 |
|
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
567 |
a := 0. |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
568 |
[ 123 / a ] ifError:[:ex | self halt] |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
569 |
" |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
570 |
|
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
571 |
" |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
572 |
|a| |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
573 |
|
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
574 |
a := 0. |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
575 |
[ 123 / a ] ifError:[self halt] |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
576 |
" |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
577 |
! |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
578 |
|
15090 | 579 |
timeToRun |
17697 | 580 |
"squeak compatibility: same as millisecondsToRun:" |
581 |
||
15090 | 582 |
^ Time millisecondsToRun:self |
583 |
! |
|
584 |
||
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
585 |
valueWithPossibleArgs:argArray |
17697 | 586 |
"squeak compatibility: same as valueWithOptionalArguments:" |
587 |
||
9602 | 588 |
^ self valueWithOptionalArguments:argArray |
5015 | 589 |
! ! |
590 |
||
7261 | 591 |
!Block methodsFor:'Compatibility-V''Age'! |
1979 | 592 |
|
14139 | 593 |
apply:aCollection from:start to:end |
17697 | 594 |
"VisualAge compatibility: |
18252 | 595 |
Evaluate the receiver for each variable slot of aCollection from start to end. |
14139 | 596 |
Answer aCollection." |
597 |
||
598 |
aCollection from:start to:end do:self. |
|
599 |
^ aCollection |
|
600 |
||
601 |
" |
|
602 |
[:i | Transcript showCR:i ] |
|
18252 | 603 |
apply:#(10 20 30 40 50 60) from:2 to:4 |
14139 | 604 |
" |
605 |
||
606 |
"Created: / 16-05-2012 / 11:20:55 / cg" |
|
607 |
! |
|
608 |
||
609 |
applyWithIndex:aCollection from:start to:end |
|
17697 | 610 |
"VisualAge compatibility: |
18252 | 611 |
Evaluate the receiver for each variable slot and index of aCollection from start to end. |
14139 | 612 |
Answer aCollection." |
613 |
||
614 |
aCollection from:start to:end doWithIndex:self. |
|
615 |
^ aCollection |
|
616 |
||
617 |
" |
|
618 |
[:el :i | Transcript showCR:(i -> el) ] |
|
18252 | 619 |
applyWithIndex:#(10 20 30 40 50 60) from:2 to:4 |
14139 | 620 |
" |
621 |
||
622 |
"Created: / 16-05-2012 / 11:22:01 / cg" |
|
623 |
! |
|
624 |
||
625 |
value:arg1 onReturnDo:aBlock |
|
626 |
"VisualAge compatibility: alias for #ensure: |
|
627 |
evaluate the receiver - when the block returns either a local return |
|
628 |
or an unwind (i.e. does a long return), evaluate the argument, aBlock. |
|
18252 | 629 |
This is used to make certain that cleanup actions |
14139 | 630 |
(for example closing files etc.) are executed regardless of error actions." |
631 |
||
632 |
^ [self value:arg1] ensure:aBlock |
|
633 |
||
634 |
"Created: / 16-05-2012 / 11:29:30 / cg" |
|
635 |
! |
|
636 |
||
637 |
value:arg1 value:arg2 onReturnDo:aBlock |
|
638 |
"VisualAge compatibility: alias for #ensure: |
|
639 |
evaluate the receiver - when the block returns either a local return |
|
640 |
or an unwind (i.e. does a long return), evaluate the argument, aBlock. |
|
18252 | 641 |
This is used to make certain that cleanup actions |
14139 | 642 |
(for example closing files etc.) are executed regardless of error actions." |
643 |
||
644 |
^ [self value:arg1 value:arg2] ensure:aBlock |
|
645 |
||
646 |
"Created: / 16-05-2012 / 11:29:46 / cg" |
|
647 |
! |
|
648 |
||
649 |
value:arg1 value:arg2 value:arg3 onReturnDo:aBlock |
|
650 |
"VisualAge compatibility: alias for #ensure: |
|
651 |
evaluate the receiver - when the block returns either a local return |
|
652 |
or an unwind (i.e. does a long return), evaluate the argument, aBlock. |
|
18252 | 653 |
This is used to make certain that cleanup actions |
14139 | 654 |
(for example closing files etc.) are executed regardless of error actions." |
655 |
||
656 |
^ [self value:arg1 value:arg2 value:arg3] ensure:aBlock |
|
657 |
||
658 |
"Created: / 16-05-2012 / 11:29:59 / cg" |
|
659 |
! |
|
660 |
||
661 |
valueOnReturnDo:aBlock |
|
662 |
"VisualAge compatibility: alias for #ensure: |
|
663 |
evaluate the receiver - when the block returns either a local return |
|
664 |
or an unwind (i.e. does a long return), evaluate the argument, aBlock. |
|
18252 | 665 |
This is used to make certain that cleanup actions |
14139 | 666 |
(for example closing files etc.) are executed regardless of error actions." |
667 |
||
668 |
^ self ensure:aBlock |
|
669 |
||
670 |
"Created: / 15-11-1996 / 11:38:37 / cg" |
|
13054 | 671 |
! |
672 |
||
673 |
when:exceptionClassOrSignal do:handler |
|
17697 | 674 |
"VisualAge compatibility:" |
675 |
||
13054 | 676 |
^ self on:exceptionClassOrSignal do:handler |
677 |
||
678 |
"Created: / 28-08-2010 / 14:41:15 / cg" |
|
1979 | 679 |
! ! |
680 |
||
17697 | 681 |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
682 |
!Block methodsFor:'accessing'! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
683 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
684 |
home |
19450 | 685 |
"return the receiver's home context (the context where it was |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
686 |
created). For cheap blocks, nil is returned" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
687 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
688 |
^ home |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
689 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
690 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
691 |
homeMethod |
19450 | 692 |
"return the receiver's home method. |
693 |
That's the method where the block was created." |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
694 |
|
10473 | 695 |
|m| |
696 |
||
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
697 |
home notNil ifTrue:[ |
19450 | 698 |
m := home method. |
699 |
m notNil ifTrue:[^ m]. |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
700 |
]. |
10473 | 701 |
m := self literalAt:1 ifAbsent:nil. |
702 |
m isMethod ifTrue:[^ m]. |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
703 |
^ nil |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
704 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
705 |
"Created: 19.6.1997 / 16:14:57 / cg" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
706 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
707 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
708 |
method |
19450 | 709 |
"return the receiver's method |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
710 |
(the method where the block was created). |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
711 |
Obsolete: use #homeMethod for ST80 compatibility." |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
712 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
713 |
<resource: #obsolete> |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
714 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
715 |
^ self homeMethod |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
716 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
717 |
"Modified: 19.6.1997 / 16:15:24 / cg" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
718 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
719 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
720 |
methodHome |
15532 | 721 |
"return the receiver's method home context (the context where it was |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
722 |
defined). For cheap blocks, nil is returned" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
723 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
724 |
home notNil ifTrue:[ |
18252 | 725 |
^ home methodHome |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
726 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
727 |
^ nil |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
728 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
729 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
730 |
numArgs |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
731 |
"return the number of arguments I expect for evaluation. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
732 |
Please use argumentCount, which is ANSI" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
733 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
734 |
"/ <resource: #obsolete> |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
735 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
736 |
^ nargs |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
737 |
! ! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
738 |
|
13220
21b4d5e57663
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
13054
diff
changeset
|
739 |
|
10890 | 740 |
!Block methodsFor:'compatibility-Cola & Pepsi'! |
741 |
||
742 |
arity |
|
18434 | 743 |
^ self argumentCount |
10890 | 744 |
! ! |
5931
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
745 |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
746 |
!Block methodsFor:'conversion'! |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
747 |
|
5349 | 748 |
asVarArgBlock |
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
749 |
"convert myself into a varArg block; |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
750 |
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
|
751 |
of actual arguments when evaluated." |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
752 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
753 |
nargs ~~ 1 ifTrue:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
754 |
self error:'vararg blocks must take exactly 1 argument - the arg list'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
755 |
^ nil |
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
756 |
]. |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
757 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
758 |
self changeClassTo:VarArgBlock. |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
759 |
^ self |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
760 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
761 |
" |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
762 |
|b| |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
763 |
|
18252 | 764 |
b := [:argList | Transcript |
765 |
show:'invoked with args:'; |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
766 |
showCR:argList |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
767 |
] asVarArgBlock. |
5349 | 768 |
b value. |
769 |
b value:'arg1'. |
|
770 |
b value:'arg1' value:'arg2' value:'arg3' value:'arg4' |
|
771 |
" |
|
772 |
||
773 |
"Created: 23.1.1997 / 13:35:28 / cg" |
|
774 |
"Modified: 23.1.1997 / 13:35:48 / cg" |
|
775 |
! |
|
776 |
||
7151 | 777 |
beCurryingBlock |
778 |
"make myself a currying block; |
|
12920
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
779 |
that's a block which, if invoked with less-than-expected arguments, |
7151 | 780 |
returns another block which provides the provided argument(s) and expects the remaining args. |
12920
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
781 |
Read any book on functional programming, if you don't understand this." |
7151 | 782 |
|
783 |
self changeClassTo:CurryingBlock. |
|
784 |
^ self |
|
12920
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
785 |
|
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
786 |
" |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
787 |
|b b1 b2 b3| |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
788 |
|
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
789 |
b := [:a :b :c | a + b + c] beCurryingBlock. |
18252 | 790 |
b numArgs. |
12920
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
791 |
b value:1 value:2 value:3. |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
792 |
|
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
793 |
b1 := b value:10. |
18252 | 794 |
b1 numArgs. |
795 |
b1 value:2 value:3. |
|
12920
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
796 |
|
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
797 |
b2 := b value:10 value:20. |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
798 |
b2 numArgs. |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
799 |
b2 value:3. |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
800 |
|
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
801 |
b3 := b1 value:20. |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
802 |
b3 numArgs. |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
803 |
b3 value:3. |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
804 |
" |
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
805 |
|
6f9c1bd017dc
comment/format in: #beCurryingBlock
Claus Gittinger <cg@exept.de>
parents:
12887
diff
changeset
|
806 |
"Modified: / 10-05-2010 / 12:56:20 / cg" |
7151 | 807 |
! |
808 |
||
5349 | 809 |
beVarArg |
810 |
"convert myself into a varArg block; |
|
811 |
this one has 1 formal argument, which gets the list |
|
812 |
of actual arguments when evaluated." |
|
813 |
||
814 |
^ self asVarArgBlock. |
|
815 |
||
816 |
" |
|
817 |
|b| |
|
818 |
||
2241 | 819 |
b := [:argList | argList printCR] beVarArg. |
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
820 |
b value. |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
821 |
b value:'arg1' value:'arg2' value:'arg3' value:'arg4' |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
822 |
" |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
823 |
|
2241 | 824 |
"Created: 23.1.1997 / 13:35:28 / cg" |
825 |
"Modified: 23.1.1997 / 13:35:48 / cg" |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
826 |
! ! |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
827 |
|
623 | 828 |
!Block methodsFor:'copying'! |
1 | 829 |
|
10942 | 830 |
deepCopyUsing:aDictionary postCopySelector:postCopySelector |
10135
66ba0830449b
partial support for copying (ok, if my context is not active)
fm
parents:
9646
diff
changeset
|
831 |
|copyOfHome copyOfMe| |
66ba0830449b
partial support for copying (ok, if my context is not active)
fm
parents:
9646
diff
changeset
|
832 |
|
8638 | 833 |
home isNil ifTrue:[ |
18252 | 834 |
^ super deepCopyUsing:aDictionary postCopySelector:postCopySelector |
8638 | 835 |
]. |
10135
66ba0830449b
partial support for copying (ok, if my context is not active)
fm
parents:
9646
diff
changeset
|
836 |
copyOfHome := home deepCopyUsing:aDictionary. |
66ba0830449b
partial support for copying (ok, if my context is not active)
fm
parents:
9646
diff
changeset
|
837 |
copyOfMe := self shallowCopy. |
66ba0830449b
partial support for copying (ok, if my context is not active)
fm
parents:
9646
diff
changeset
|
838 |
copyOfMe setHome:copyOfHome. |
13517
95a2ffba9880
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13220
diff
changeset
|
839 |
copyOfMe perform:postCopySelector withOptionalArgument:self and:aDictionary. |
10135
66ba0830449b
partial support for copying (ok, if my context is not active)
fm
parents:
9646
diff
changeset
|
840 |
^ copyOfMe |
66ba0830449b
partial support for copying (ok, if my context is not active)
fm
parents:
9646
diff
changeset
|
841 |
|
66ba0830449b
partial support for copying (ok, if my context is not active)
fm
parents:
9646
diff
changeset
|
842 |
"Created: / 31-03-1998 / 15:46:17 / cg" |
13517
95a2ffba9880
changed: #deepCopyUsing:postCopySelector:
Claus Gittinger <cg@exept.de>
parents:
13220
diff
changeset
|
843 |
"Modified: / 21-07-2011 / 13:30:12 / cg" |
1 | 844 |
! ! |
845 |
||
16871 | 846 |
!Block methodsFor:'debugging'! |
847 |
||
848 |
benchmark:anInfoString |
|
849 |
"evaluate myseld and show the timing info on Transcript" |
|
850 |
||
19795 | 851 |
|startTime endTime overhead micros millis| |
852 |
||
853 |
startTime := OperatingSystem getMicrosecondTime. |
|
854 |
[123] value. |
|
855 |
endTime := OperatingSystem getMicrosecondTime. |
|
856 |
overhead := endTime - startTime. |
|
857 |
||
16871 | 858 |
startTime := OperatingSystem getMicrosecondTime. |
859 |
self value. |
|
860 |
endTime := OperatingSystem getMicrosecondTime. |
|
861 |
||
19795 | 862 |
micros := (endTime - startTime - overhead) max:0. |
16871 | 863 |
|
864 |
Transcript show:anInfoString. |
|
17338 | 865 |
micros < 1000 ifTrue:[ |
19795 | 866 |
"/ too stupid: many fonts do not have a mu, |
867 |
"/ so I output it as us here. |
|
868 |
Transcript show:micros; show:' us'. |
|
16871 | 869 |
] ifFalse:[ |
19795 | 870 |
micros < 100000 ifTrue:[ |
871 |
millis := (micros / 1000.0) asFixedPointRoundedToScale:2. |
|
872 |
Transcript show:millis; show:' ms'. |
|
873 |
] ifFalse:[ |
|
874 |
millis := micros // 1000. |
|
875 |
Transcript show:(TimeDuration milliseconds:millis). |
|
876 |
]. |
|
16871 | 877 |
]. |
878 |
Transcript cr. |
|
879 |
||
880 |
" |
|
19795 | 881 |
[10 factorial] benchmark:'10 factorial:' |
882 |
[100 factorial] benchmark:'100 factorial:' |
|
16871 | 883 |
" |
884 |
! ! |
|
885 |
||
1 | 886 |
!Block methodsFor:'error handling'! |
887 |
||
328 | 888 |
invalidCodeObject |
1874 | 889 |
"{ Pragma: +optSpace }" |
890 |
||
67 | 891 |
"this error is triggered by the interpreter when a non-Block object |
892 |
is about to be executed. |
|
893 |
In this case, the VM sends this to the bad method (the receiver). |
|
894 |
Can only happen when the Compiler/runtime system is broken or |
|
895 |
someone played around." |
|
1 | 896 |
|
7602
d048f13cd50a
Exception classes initialize themself.
Stefan Vogel <sv@exept.de>
parents:
7352
diff
changeset
|
897 |
^ InvalidCodeError |
18252 | 898 |
raiseRequestWith:self |
899 |
errorString:'invalid block - not executable' |
|
1874 | 900 |
|
901 |
"Modified: 4.11.1996 / 22:46:39 / cg" |
|
1 | 902 |
! ! |
903 |
||
904 |
!Block methodsFor:'evaluation'! |
|
905 |
||
906 |
value |
|
18252 | 907 |
"evaluate the receiver with no block args. |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
908 |
The receiver must be a block without arguments." |
1 | 909 |
|
910 |
%{ /* NOCONTEXT */ |
|
18252 | 911 |
#ifdef __SCHTEAM__ |
912 |
return context.TAILCALL0( self.asSTCallable() ); |
|
913 |
/* NOTREACHED */ |
|
914 |
#else |
|
1 | 915 |
REGISTER OBJFUNC thecode; |
916 |
OBJ home; |
|
917 |
||
8913 | 918 |
if (__INST(nargs) == __mkSmallInteger(0)) { |
18252 | 919 |
# if defined(THIS_CONTEXT) |
920 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
921 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
922 |
# endif |
|
923 |
||
924 |
thecode = __BlockInstPtr(self)->b_code; |
|
925 |
# ifdef NEW_BLOCK_CALL |
|
926 |
if (thecode != (OBJFUNC)nil) { |
|
927 |
/* compiled machine code */ |
|
928 |
RETURN ( (*thecode)(self) ); |
|
929 |
} |
|
930 |
/* interpreted code */ |
|
931 |
# ifdef PASS_ARG_POINTER |
|
932 |
RETURN ( __interpret(self, 0, nil, nil, nil, nil) ); |
|
933 |
# else |
|
934 |
RETURN ( __interpret(self, 0, nil, nil, nil, nil) ); |
|
935 |
# endif |
|
328 | 936 |
# else |
18252 | 937 |
home = __BlockInstPtr(self)->b_home; |
938 |
if (thecode != (OBJFUNC)nil) { |
|
939 |
/* compiled machine code */ |
|
940 |
RETURN ( (*thecode)(home) ); |
|
941 |
} |
|
942 |
/* interpreted code */ |
|
943 |
# ifdef PASS_ARG_POINTER |
|
944 |
RETURN ( __interpret(self, 0, nil, home, nil, nil) ); |
|
945 |
# else |
|
946 |
RETURN ( __interpret(self, 0, nil, home, nil, nil) ); |
|
947 |
# endif |
|
328 | 948 |
# endif |
1 | 949 |
} |
18252 | 950 |
#endif /* not SCHTEAM */ |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
951 |
%}. |
103 | 952 |
^ self wrongNumberOfArguments:0 |
1 | 953 |
! |
954 |
||
955 |
value:arg |
|
18252 | 956 |
"evaluate the receiver with one argument. |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
957 |
The receiver must be a 1-arg block." |
1 | 958 |
|
959 |
%{ /* NOCONTEXT */ |
|
18252 | 960 |
#ifdef __SCHTEAM__ |
961 |
return context.TAILCALL1( self.asSTCallable(), arg ); |
|
962 |
/* NOTREACHED */ |
|
963 |
#else |
|
1 | 964 |
|
965 |
REGISTER OBJFUNC thecode; |
|
966 |
OBJ home; |
|
967 |
||
8913 | 968 |
if (__INST(nargs) == __mkSmallInteger(1)) { |
18252 | 969 |
# if defined(THIS_CONTEXT) |
970 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
971 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
972 |
# endif |
|
973 |
thecode = __BlockInstPtr(self)->b_code; |
|
974 |
# ifdef NEW_BLOCK_CALL |
|
975 |
if (thecode != (OBJFUNC)nil) { |
|
976 |
RETURN ( (*thecode)(self, arg) ); |
|
977 |
} |
|
978 |
/* interpreted code */ |
|
979 |
# ifdef PASS_ARG_POINTER |
|
980 |
RETURN ( __interpret(self, 1, nil, nil, nil, nil, &arg) ); |
|
981 |
# else |
|
982 |
RETURN ( __interpret(self, 1, nil, nil, nil, nil, arg) ); |
|
983 |
# endif |
|
328 | 984 |
# else |
18252 | 985 |
home = __BlockInstPtr(self)->b_home; |
986 |
if (thecode != (OBJFUNC)nil) { |
|
987 |
RETURN ( (*thecode)(home, arg) ); |
|
988 |
} |
|
989 |
/* interpreted code */ |
|
990 |
# ifdef PASS_ARG_POINTER |
|
991 |
RETURN ( __interpret(self, 1, nil, home, nil, nil, &arg) ); |
|
992 |
# else |
|
993 |
RETURN ( __interpret(self, 1, nil, home, nil, nil, arg) ); |
|
994 |
# endif |
|
328 | 995 |
# endif |
1 | 996 |
} |
18252 | 997 |
#endif /* not SCHTEAM */ |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
998 |
%}. |
103 | 999 |
^ self wrongNumberOfArguments:1 |
1 | 1000 |
! |
1001 |
||
11998 | 1002 |
value:arg1 optionalArgument:arg2 |
1003 |
"evaluate the receiver. |
|
1004 |
Optionally pass up one or to two arguments (if the receiver is a one/two arg block)." |
|
1005 |
||
1006 |
nargs == 2 ifTrue:[ |
|
18252 | 1007 |
^ self value:arg1 value:arg2 |
11998 | 1008 |
]. |
1009 |
^ self value:arg1 |
|
1010 |
||
1011 |
" |
|
1012 |
|block| |
|
1013 |
||
1014 |
block := [:arg | Transcript showCR:arg ]. |
|
18252 | 1015 |
block value:2 optionalArgument:3. |
11998 | 1016 |
|
1017 |
block := [:arg1 :arg2 | Transcript show:arg1; space; showCR:arg2 ]. |
|
18252 | 1018 |
block value:2 optionalArgument:3. |
11998 | 1019 |
" |
1020 |
! |
|
1021 |
||
1022 |
value:arg1 optionalArgument:arg2 and:arg3 |
|
1023 |
"evaluate the receiver. |
|
1024 |
Optionally pass up one, two or three arguments (if the receiver is a 1/2/3-arg block)." |
|
1025 |
||
1026 |
nargs == 3 ifTrue:[ |
|
18252 | 1027 |
^ self value:arg1 value:arg2 value:arg3 |
11998 | 1028 |
]. |
1029 |
nargs == 2 ifTrue:[ |
|
18252 | 1030 |
^ self value:arg1 value:arg2 |
11998 | 1031 |
]. |
1032 |
^ self value:arg1 |
|
1033 |
||
1034 |
" |
|
1035 |
|block| |
|
1036 |
||
1037 |
block := [:arg | Transcript showCR:arg ]. |
|
18252 | 1038 |
block value:2 optionalArgument:3. |
11998 | 1039 |
|
1040 |
block := [:arg1 :arg2 | Transcript show:arg1; space; showCR:arg2 ]. |
|
18252 | 1041 |
block value:2 optionalArgument:3. |
11998 | 1042 |
" |
1043 |
! |
|
1044 |
||
1 | 1045 |
value:arg1 value:arg2 |
18252 | 1046 |
"evaluate the receiver with two arguments. |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1047 |
The receiver must be a 2-arg block." |
1 | 1048 |
|
1049 |
%{ /* NOCONTEXT */ |
|
18252 | 1050 |
#ifdef __SCHTEAM__ |
1051 |
return context.TAILCALL2( self.asSTCallable(), arg1, arg2 ); |
|
1052 |
/* NOTREACHED */ |
|
1053 |
#else |
|
1 | 1054 |
|
1055 |
REGISTER OBJFUNC thecode; |
|
1056 |
OBJ home; |
|
1057 |
||
8913 | 1058 |
if (__INST(nargs) == __mkSmallInteger(2)) { |
18252 | 1059 |
# if defined(THIS_CONTEXT) |
1060 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
1061 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1062 |
# endif |
|
1063 |
thecode = __BlockInstPtr(self)->b_code; |
|
1064 |
# ifdef NEW_BLOCK_CALL |
|
1065 |
if (thecode != (OBJFUNC)nil) { |
|
1066 |
RETURN ( (*thecode)(self, arg1, arg2) ); |
|
1067 |
} |
|
1068 |
# ifdef PASS_ARG_POINTER |
|
1069 |
RETURN ( __interpret(self, 2, nil, nil, nil, nil, &arg1) ); |
|
1070 |
# else |
|
1071 |
RETURN ( __interpret(self, 2, nil, nil, nil, nil, arg1, arg2) ); |
|
1072 |
# endif |
|
328 | 1073 |
# else |
18252 | 1074 |
home = __BlockInstPtr(self)->b_home; |
1075 |
if (thecode != (OBJFUNC)nil) { |
|
1076 |
RETURN ( (*thecode)(home, arg1, arg2) ); |
|
1077 |
} |
|
1078 |
# ifdef PASS_ARG_POINTER |
|
1079 |
RETURN ( __interpret(self, 2, nil, home, nil, nil, &arg1) ); |
|
1080 |
# else |
|
1081 |
RETURN ( __interpret(self, 2, nil, home, nil, nil, arg1, arg2) ); |
|
1082 |
# endif |
|
328 | 1083 |
# endif |
1 | 1084 |
} |
18252 | 1085 |
#endif /* not SCHTEAM */ |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1086 |
%}. |
103 | 1087 |
^ self wrongNumberOfArguments:2 |
1 | 1088 |
! |
1089 |
||
11998 | 1090 |
value:arg1 value:arg2 optionalArgument:arg3 |
1091 |
"evaluate the receiver. |
|
1092 |
Optionally pass two or threearguments (if the receiver is a 2/3-arg block)." |
|
1093 |
||
1094 |
nargs == 3 ifTrue:[ |
|
18252 | 1095 |
^ self value:arg1 value:arg2 value:arg3 |
11998 | 1096 |
]. |
1097 |
^ self value:arg1 value:arg2 |
|
1098 |
! |
|
1099 |
||
1 | 1100 |
value:arg1 value:arg2 value:arg3 |
18252 | 1101 |
"evaluate the receiver with three arguments. |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1102 |
The receiver must be a 3-arg block." |
1 | 1103 |
|
1104 |
%{ /* NOCONTEXT */ |
|
18252 | 1105 |
#ifdef __SCHTEAM__ |
1106 |
return context.TAILCALL3( self.asSTCallable(), arg1, arg2, arg3 ); |
|
1107 |
/* NOTREACHED */ |
|
1108 |
#else |
|
1 | 1109 |
|
1110 |
REGISTER OBJFUNC thecode; |
|
1111 |
OBJ home; |
|
1112 |
||
8913 | 1113 |
if (__INST(nargs) == __mkSmallInteger(3)) { |
18252 | 1114 |
# if defined(THIS_CONTEXT) |
1115 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
1116 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1117 |
# endif |
|
1118 |
thecode = __BlockInstPtr(self)->b_code; |
|
1119 |
# ifdef NEW_BLOCK_CALL |
|
1120 |
if (thecode != (OBJFUNC)nil) { |
|
1121 |
RETURN ( (*thecode)(self, arg1, arg2, arg3) ); |
|
1122 |
} |
|
1123 |
# ifdef PASS_ARG_POINTER |
|
1124 |
RETURN ( __interpret(self, 3, nil, nil, nil, nil, &arg1) ); |
|
1125 |
# else |
|
1126 |
RETURN ( __interpret(self, 3, nil, nil, nil, nil, arg1, arg2, arg3) ); |
|
1127 |
# endif |
|
328 | 1128 |
# else |
18252 | 1129 |
home = __BlockInstPtr(self)->b_home; |
1130 |
if (thecode != (OBJFUNC)nil) { |
|
1131 |
RETURN ( (*thecode)(home, arg1, arg2, arg3) ); |
|
1132 |
} |
|
1133 |
# ifdef PASS_ARG_POINTER |
|
1134 |
RETURN ( __interpret(self, 3, nil, home, nil, nil, &arg1) ); |
|
1135 |
# else |
|
1136 |
RETURN ( __interpret(self, 3, nil, home, nil, nil, arg1, arg2, arg3) ); |
|
1137 |
# endif |
|
328 | 1138 |
# endif |
1 | 1139 |
} |
18252 | 1140 |
#endif /* not SCHTEAM */ |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1141 |
%}. |
103 | 1142 |
^ self wrongNumberOfArguments:3 |
1 | 1143 |
! |
1144 |
||
1145 |
value:arg1 value:arg2 value:arg3 value:arg4 |
|
18252 | 1146 |
"evaluate the receiver with four arguments. |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1147 |
The receiver must be a 4-arg block." |
1 | 1148 |
|
1149 |
%{ /* NOCONTEXT */ |
|
18252 | 1150 |
#ifdef __SCHTEAM__ |
1151 |
return context.TAILCALL4( self.asSTCallable(), arg1, arg2, arg3, arg4 ); |
|
1152 |
/* NOTREACHED */ |
|
1153 |
#else |
|
1 | 1154 |
|
1155 |
REGISTER OBJFUNC thecode; |
|
1156 |
OBJ home; |
|
1157 |
||
8913 | 1158 |
if (__INST(nargs) == __mkSmallInteger(4)) { |
18252 | 1159 |
# if defined(THIS_CONTEXT) |
1160 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
1161 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1162 |
# endif |
|
1163 |
thecode = __BlockInstPtr(self)->b_code; |
|
1164 |
# ifdef NEW_BLOCK_CALL |
|
1165 |
if (thecode != (OBJFUNC)nil) { |
|
1166 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4) ); |
|
1167 |
} |
|
1168 |
# ifdef PASS_ARG_POINTER |
|
1169 |
RETURN ( __interpret(self, 4, nil, nil, nil, nil, &arg1) ); |
|
1170 |
# else |
|
1171 |
RETURN ( __interpret(self, 4, nil, nil, nil, nil, arg1, arg2, arg3, arg4) ); |
|
1172 |
# endif |
|
328 | 1173 |
# else |
18252 | 1174 |
home = __BlockInstPtr(self)->b_home; |
1175 |
if (thecode != (OBJFUNC)nil) { |
|
1176 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4) ); |
|
1177 |
} |
|
1178 |
# ifdef PASS_ARG_POINTER |
|
1179 |
RETURN ( __interpret(self, 4, nil, home, nil, nil, &arg1) ); |
|
1180 |
# else |
|
1181 |
RETURN ( __interpret(self, 4, nil, home, nil, nil, arg1, arg2, arg3, arg4) ); |
|
1182 |
# endif |
|
328 | 1183 |
# endif |
18252 | 1184 |
} |
1 | 1185 |
#endif |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1186 |
%}. |
103 | 1187 |
^ self wrongNumberOfArguments:4 |
1 | 1188 |
! |
1189 |
||
1190 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 |
|
18252 | 1191 |
"evaluate the receiver with five arguments. |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1192 |
The receiver must be a 5-arg block." |
1 | 1193 |
|
1194 |
%{ /* NOCONTEXT */ |
|
18252 | 1195 |
#ifdef __SCHTEAM__ |
1196 |
return context.TAILCALL5( self.asSTCallable(), arg1, arg2, arg3, arg4, arg5 ); |
|
1197 |
/* NOTREACHED */ |
|
1198 |
#else |
|
1 | 1199 |
|
1200 |
REGISTER OBJFUNC thecode; |
|
1201 |
OBJ home; |
|
1202 |
||
8913 | 1203 |
if (__INST(nargs) == __mkSmallInteger(5)) { |
18252 | 1204 |
# if defined(THIS_CONTEXT) |
1205 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
1206 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1207 |
# endif |
|
1208 |
thecode = __BlockInstPtr(self)->b_code; |
|
1209 |
# ifdef NEW_BLOCK_CALL |
|
1210 |
if (thecode != (OBJFUNC)nil) { |
|
1211 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5) ); |
|
1212 |
} |
|
1213 |
# ifdef PASS_ARG_POINTER |
|
1214 |
RETURN ( __interpret(self, 5, nil, nil, nil, nil, &arg1) ); |
|
1215 |
# else |
|
1216 |
RETURN ( __interpret(self, 5, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5) ); |
|
1217 |
# endif |
|
328 | 1218 |
# else |
18252 | 1219 |
home = __BlockInstPtr(self)->b_home; |
1220 |
if (thecode != (OBJFUNC)nil) { |
|
1221 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5) ); |
|
1222 |
} |
|
1223 |
# ifdef PASS_ARG_POINTER |
|
1224 |
RETURN ( __interpret(self, 5, nil, home, nil, nil, &arg1) ); |
|
1225 |
# else |
|
1226 |
RETURN ( __interpret(self, 5, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5) ); |
|
1227 |
# endif |
|
328 | 1228 |
# endif |
1 | 1229 |
} |
18252 | 1230 |
#endif /* not SCHTEAM */ |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1231 |
%}. |
103 | 1232 |
^ self wrongNumberOfArguments:5 |
1 | 1233 |
! |
1234 |
||
1235 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 |
|
18252 | 1236 |
"evaluate the receiver with six arguments. |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1237 |
The receiver must be a 6-arg block." |
1 | 1238 |
|
1239 |
%{ /* NOCONTEXT */ |
|
18252 | 1240 |
#ifdef __SCHTEAM__ |
1241 |
return context.TAILCALL6( self.asSTCallable(), arg1, arg2, arg3, arg4, arg5, arg6 ); |
|
1242 |
/* NOTREACHED */ |
|
1243 |
#else |
|
1 | 1244 |
|
1245 |
REGISTER OBJFUNC thecode; |
|
1246 |
OBJ home; |
|
1247 |
||
8913 | 1248 |
if (__INST(nargs) == __mkSmallInteger(6)) { |
18252 | 1249 |
# if defined(THIS_CONTEXT) |
1250 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
1251 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1252 |
# endif |
|
1253 |
thecode = __BlockInstPtr(self)->b_code; |
|
1254 |
# ifdef NEW_BLOCK_CALL |
|
1255 |
if (thecode != (OBJFUNC)nil) { |
|
1256 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
1257 |
} |
|
1258 |
# ifdef PASS_ARG_POINTER |
|
1259 |
RETURN ( __interpret(self, 6, nil, nil, nil, nil, &arg1) ); |
|
1260 |
# else |
|
1261 |
RETURN ( __interpret(self, 6, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
1262 |
# endif |
|
328 | 1263 |
# else |
18252 | 1264 |
home = __BlockInstPtr(self)->b_home; |
1265 |
if (thecode != (OBJFUNC)nil) { |
|
1266 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
1267 |
} |
|
1268 |
# ifdef PASS_ARG_POINTER |
|
1269 |
RETURN ( __interpret(self, 6, nil, home, nil, nil, &arg1) ); |
|
1270 |
# else |
|
1271 |
RETURN ( __interpret(self, 6, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
1272 |
# endif |
|
328 | 1273 |
# endif |
1 | 1274 |
} |
18252 | 1275 |
#endif /* not SCHTEAM */ |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1276 |
%}. |
103 | 1277 |
^ self wrongNumberOfArguments:6 |
1 | 1278 |
! |
1279 |
||
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1280 |
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
|
1281 |
"evaluate the receiver with seven arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1282 |
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
|
1283 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1284 |
%{ /* NOCONTEXT */ |
18252 | 1285 |
#ifdef __SCHTEAM__ |
1286 |
return context.TAILCALL7( self.asSTCallable(), arg1, arg2, arg3, arg4, arg5, arg6, arg7 ); |
|
1287 |
/* NOTREACHED */ |
|
1288 |
#else |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1289 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1290 |
REGISTER OBJFUNC thecode; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1291 |
OBJ home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1292 |
|
8913 | 1293 |
if (__INST(nargs) == __mkSmallInteger(7)) { |
18252 | 1294 |
# if defined(THIS_CONTEXT) |
1295 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
1296 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1297 |
# endif |
|
1298 |
thecode = __BlockInstPtr(self)->b_code; |
|
1299 |
# ifdef NEW_BLOCK_CALL |
|
1300 |
if (thecode != (OBJFUNC)nil) { |
|
1301 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
1302 |
} |
|
1303 |
# ifdef PASS_ARG_POINTER |
|
1304 |
RETURN ( __interpret(self, 7, nil, nil, nil, nil, &arg1) ); |
|
1305 |
# else |
|
1306 |
RETURN ( __interpret(self, 7, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
1307 |
# endif |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1308 |
# else |
18252 | 1309 |
home = __BlockInstPtr(self)->b_home; |
1310 |
if (thecode != (OBJFUNC)nil) { |
|
1311 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
1312 |
} |
|
1313 |
# ifdef PASS_ARG_POINTER |
|
1314 |
RETURN ( __interpret(self, 7, nil, home, nil, nil, &arg1) ); |
|
1315 |
# else |
|
1316 |
RETURN ( __interpret(self, 7, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
1317 |
# endif |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1318 |
# endif |
18252 | 1319 |
} |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1320 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1321 |
%}. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1322 |
^ self wrongNumberOfArguments:7 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1323 |
! |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1324 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1325 |
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
|
1326 |
"evaluate the receiver with eight arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1327 |
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
|
1328 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1329 |
%{ /* NOCONTEXT */ |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1330 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1331 |
REGISTER OBJFUNC thecode; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1332 |
OBJ home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1333 |
|
8913 | 1334 |
if (__INST(nargs) == __mkSmallInteger(8)) { |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1335 |
#if defined(THIS_CONTEXT) |
18252 | 1336 |
if (__ISVALID_ILC_LNO(__pilc)) |
1337 |
__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
|
1338 |
#endif |
18252 | 1339 |
thecode = __BlockInstPtr(self)->b_code; |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1340 |
#ifdef NEW_BLOCK_CALL |
18252 | 1341 |
if (thecode != (OBJFUNC)nil) { |
1342 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
|
1343 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1344 |
# ifdef PASS_ARG_POINTER |
18252 | 1345 |
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
|
1346 |
# else |
18252 | 1347 |
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
|
1348 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1349 |
#else |
18252 | 1350 |
home = __BlockInstPtr(self)->b_home; |
1351 |
if (thecode != (OBJFUNC)nil) { |
|
1352 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
|
1353 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1354 |
# ifdef PASS_ARG_POINTER |
18252 | 1355 |
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
|
1356 |
# else |
18252 | 1357 |
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
|
1358 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1359 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1360 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1361 |
%}. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1362 |
^ self wrongNumberOfArguments:8 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1363 |
! |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1364 |
|
11588 | 1365 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8 value:arg9 |
11603 | 1366 |
"evaluate the receiver with 9 arguments. |
1367 |
The receiver must be a 9-arg block." |
|
11588 | 1368 |
|
1369 |
%{ /* NOCONTEXT */ |
|
1370 |
||
1371 |
REGISTER OBJFUNC thecode; |
|
1372 |
OBJ home; |
|
1373 |
||
1374 |
if (__INST(nargs) == __mkSmallInteger(9)) { |
|
1375 |
#if defined(THIS_CONTEXT) |
|
18252 | 1376 |
if (__ISVALID_ILC_LNO(__pilc)) |
1377 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
11588 | 1378 |
#endif |
18252 | 1379 |
thecode = __BlockInstPtr(self)->b_code; |
11588 | 1380 |
#ifdef NEW_BLOCK_CALL |
18252 | 1381 |
if (thecode != (OBJFUNC)nil) { |
1382 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) ); |
|
1383 |
} |
|
11588 | 1384 |
# ifdef PASS_ARG_POINTER |
18252 | 1385 |
RETURN ( __interpret(self, 9, nil, nil, nil, nil, &arg1) ); |
11588 | 1386 |
# else |
18252 | 1387 |
RETURN ( __interpret(self, 9, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) ); |
11588 | 1388 |
# endif |
1389 |
#else |
|
18252 | 1390 |
home = __BlockInstPtr(self)->b_home; |
1391 |
if (thecode != (OBJFUNC)nil) { |
|
1392 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) ); |
|
1393 |
} |
|
11588 | 1394 |
# ifdef PASS_ARG_POINTER |
18252 | 1395 |
RETURN ( __interpret(self, 9, nil, home, nil, nil, &arg1) ); |
11588 | 1396 |
# else |
18252 | 1397 |
RETURN ( __interpret(self, 9, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) ); |
11588 | 1398 |
# endif |
1399 |
#endif |
|
1400 |
} |
|
1401 |
%}. |
|
1402 |
^ self wrongNumberOfArguments:9 |
|
1403 |
! |
|
1404 |
||
1405 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8 value:arg9 value:arg10 |
|
11603 | 1406 |
"evaluate the receiver with 10 arguments. |
11588 | 1407 |
The receiver must be a 10-arg block." |
1408 |
||
1409 |
%{ /* NOCONTEXT */ |
|
1410 |
||
1411 |
REGISTER OBJFUNC thecode; |
|
1412 |
OBJ home; |
|
1413 |
||
1414 |
if (__INST(nargs) == __mkSmallInteger(10)) { |
|
1415 |
#if defined(THIS_CONTEXT) |
|
18252 | 1416 |
if (__ISVALID_ILC_LNO(__pilc)) |
1417 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
11588 | 1418 |
#endif |
18252 | 1419 |
thecode = __BlockInstPtr(self)->b_code; |
11588 | 1420 |
#ifdef NEW_BLOCK_CALL |
18252 | 1421 |
if (thecode != (OBJFUNC)nil) { |
1422 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) ); |
|
1423 |
} |
|
11588 | 1424 |
# ifdef PASS_ARG_POINTER |
18252 | 1425 |
RETURN ( __interpret(self, 10, nil, nil, nil, nil, &arg1) ); |
11588 | 1426 |
# else |
18252 | 1427 |
RETURN ( __interpret(self, 10, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) ); |
11588 | 1428 |
# endif |
1429 |
#else |
|
18252 | 1430 |
home = __BlockInstPtr(self)->b_home; |
1431 |
if (thecode != (OBJFUNC)nil) { |
|
1432 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) ); |
|
1433 |
} |
|
11588 | 1434 |
# ifdef PASS_ARG_POINTER |
18252 | 1435 |
RETURN ( __interpret(self, 10, nil, home, nil, nil, &arg1) ); |
11588 | 1436 |
# else |
18252 | 1437 |
RETURN ( __interpret(self, 10, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) ); |
11588 | 1438 |
# endif |
1439 |
#endif |
|
1440 |
} |
|
1441 |
%}. |
|
1442 |
^ self wrongNumberOfArguments:10 |
|
1443 |
! |
|
1444 |
||
1445 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8 value:arg9 value:arg10 value:arg11 |
|
11603 | 1446 |
"evaluate the receiver with 11 arguments. |
1447 |
The receiver must be a 11-arg block." |
|
11588 | 1448 |
|
1449 |
%{ /* NOCONTEXT */ |
|
1450 |
||
1451 |
REGISTER OBJFUNC thecode; |
|
1452 |
OBJ home; |
|
1453 |
||
1454 |
if (__INST(nargs) == __mkSmallInteger(11)) { |
|
1455 |
#if defined(THIS_CONTEXT) |
|
18252 | 1456 |
if (__ISVALID_ILC_LNO(__pilc)) |
1457 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
11588 | 1458 |
#endif |
18252 | 1459 |
thecode = __BlockInstPtr(self)->b_code; |
11588 | 1460 |
#ifdef NEW_BLOCK_CALL |
18252 | 1461 |
if (thecode != (OBJFUNC)nil) { |
1462 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) ); |
|
1463 |
} |
|
11588 | 1464 |
# ifdef PASS_ARG_POINTER |
18252 | 1465 |
RETURN ( __interpret(self, 11, nil, nil, nil, nil, &arg1) ); |
11588 | 1466 |
# else |
18252 | 1467 |
RETURN ( __interpret(self, 11, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) ); |
11588 | 1468 |
# endif |
1469 |
#else |
|
18252 | 1470 |
home = __BlockInstPtr(self)->b_home; |
1471 |
if (thecode != (OBJFUNC)nil) { |
|
1472 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) ); |
|
1473 |
} |
|
11588 | 1474 |
# ifdef PASS_ARG_POINTER |
18252 | 1475 |
RETURN ( __interpret(self, 11, nil, home, nil, nil, &arg1) ); |
11588 | 1476 |
# else |
18252 | 1477 |
RETURN ( __interpret(self, 11, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) ); |
11588 | 1478 |
# endif |
1479 |
#endif |
|
1480 |
} |
|
1481 |
%}. |
|
1482 |
^ self wrongNumberOfArguments:11 |
|
1483 |
! |
|
1484 |
||
11603 | 1485 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8 value:arg9 value:arg10 value:arg11 value:arg12 |
1486 |
"evaluate the receiver with 12 arguments. |
|
1487 |
The receiver must be a 12-arg block." |
|
1488 |
||
1489 |
%{ /* NOCONTEXT */ |
|
1490 |
||
1491 |
REGISTER OBJFUNC thecode; |
|
1492 |
OBJ home; |
|
1493 |
||
1494 |
if (__INST(nargs) == __mkSmallInteger(12)) { |
|
1495 |
#if defined(THIS_CONTEXT) |
|
18252 | 1496 |
if (__ISVALID_ILC_LNO(__pilc)) |
1497 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
11603 | 1498 |
#endif |
18252 | 1499 |
thecode = __BlockInstPtr(self)->b_code; |
11603 | 1500 |
#ifdef NEW_BLOCK_CALL |
18252 | 1501 |
if (thecode != (OBJFUNC)nil) { |
1502 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) ); |
|
1503 |
} |
|
11603 | 1504 |
# ifdef PASS_ARG_POINTER |
18252 | 1505 |
RETURN ( __interpret(self, 12, nil, nil, nil, nil, &arg1) ); |
11603 | 1506 |
# else |
18252 | 1507 |
RETURN ( __interpret(self, 12, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) ); |
11603 | 1508 |
# endif |
1509 |
#else |
|
18252 | 1510 |
home = __BlockInstPtr(self)->b_home; |
1511 |
if (thecode != (OBJFUNC)nil) { |
|
1512 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) ); |
|
1513 |
} |
|
11603 | 1514 |
# ifdef PASS_ARG_POINTER |
18252 | 1515 |
RETURN ( __interpret(self, 12, nil, home, nil, nil, &arg1) ); |
11603 | 1516 |
# else |
18252 | 1517 |
RETURN ( __interpret(self, 12, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) ); |
11603 | 1518 |
# endif |
1519 |
#endif |
|
1520 |
} |
|
1521 |
%}. |
|
1522 |
^ self wrongNumberOfArguments:12 |
|
1523 |
! |
|
1524 |
||
3688 | 1525 |
valueAt:priority |
1526 |
"evaluate the receiver, at the given prioriy; |
|
11998 | 1527 |
i.e. change the priority for the execution of the receiver. |
1528 |
Bad name: should be called evaluateWithPriority: or similar" |
|
3688 | 1529 |
|
9042 | 1530 |
|oldPrio retVal activeProcess| |
1531 |
||
1532 |
activeProcess := Processor activeProcess. |
|
3688 | 1533 |
oldPrio := Processor activePriority. |
1534 |
[ |
|
18252 | 1535 |
activeProcess priority:priority. |
1536 |
retVal := self value. |
|
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
1537 |
] ensure:[ |
18252 | 1538 |
activeProcess priority:oldPrio |
3688 | 1539 |
]. |
1540 |
^ retVal |
|
1541 |
||
1542 |
" |
|
1543 |
[ |
|
18252 | 1544 |
1000 timesRepeat:[ |
1545 |
1000 factorial |
|
1546 |
] |
|
3688 | 1547 |
] valueAt:3 |
1548 |
" |
|
1549 |
||
1550 |
"Created: / 29.7.1998 / 19:19:48 / cg" |
|
1551 |
! |
|
1552 |
||
18993 | 1553 |
valueWithArguments:argArrayIn |
1 | 1554 |
"evaluate the receiver with arguments taken from argArray. |
313 | 1555 |
ArgArray must be either an Array or nil. |
1 | 1556 |
The size of the argArray must match the number of arguments the receiver expects." |
1557 |
||
18993 | 1558 |
|argArray a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
1559 |
||
1560 |
argArray := argArrayIn. |
|
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1561 |
(argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[ |
18993 | 1562 |
argArray isCollection ifTrue:[ |
1563 |
argArray := argArray asArray |
|
1564 |
] ifFalse:[ |
|
1565 |
^ self badArgumentArray:argArray |
|
1566 |
]. |
|
1 | 1567 |
]. |
18993 | 1568 |
(argArray size ~~ nargs) ifTrue:[ |
1569 |
^ self wrongNumberOfArguments:argArray size |
|
1 | 1570 |
]. |
18993 | 1571 |
|
1 | 1572 |
%{ |
1573 |
REGISTER OBJFUNC thecode; |
|
1574 |
OBJ home; |
|
67 | 1575 |
REGISTER OBJ *ap; |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1576 |
OBJ nA; |
1 | 1577 |
|
1578 |
#if defined(THIS_CONTEXT) |
|
328 | 1579 |
if (__ISVALID_ILC_LNO(__pilc)) |
18993 | 1580 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 1581 |
#endif |
1133 | 1582 |
thecode = __BlockInstPtr(self)->b_code; |
1037 | 1583 |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1584 |
nA = __INST(nargs); |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1585 |
|
1037 | 1586 |
#ifndef NEW_BLOCK_CALL |
1133 | 1587 |
home = __BlockInstPtr(self)->b_home; |
1037 | 1588 |
if (thecode != (OBJFUNC)nil) { |
18993 | 1589 |
/* the most common case (0 args) here (without a switch) */ |
1590 |
||
1591 |
if (nA == __mkSmallInteger(0)) { |
|
1592 |
RETURN ( (*thecode)(home) ); |
|
1593 |
} |
|
1594 |
||
1595 |
ap = __arrayVal(argArray); /* nonNil after above test (size is known to be ok) */ |
|
1596 |
switch ((INT)(nA)) { |
|
1597 |
default: |
|
1598 |
goto error; |
|
1599 |
case (INT)__mkSmallInteger(15): |
|
1600 |
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], ap[12], ap[13], ap[14]) ); |
|
1601 |
case (INT)__mkSmallInteger(14): |
|
1602 |
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], ap[12], ap[13]) ); |
|
1603 |
case (INT)__mkSmallInteger(13): |
|
1604 |
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], ap[12]) ); |
|
1605 |
case (INT)__mkSmallInteger(12): |
|
1606 |
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]) ); |
|
1607 |
case (INT)__mkSmallInteger(11): |
|
1608 |
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]) ); |
|
1609 |
case (INT)__mkSmallInteger(10): |
|
1610 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9]) ); |
|
1611 |
case (INT)__mkSmallInteger(9): |
|
1612 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8]) ); |
|
1613 |
case (INT)__mkSmallInteger(8): |
|
1614 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7]) ); |
|
1615 |
case (INT)__mkSmallInteger(7): |
|
1616 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) ); |
|
1617 |
case (INT)__mkSmallInteger(6): |
|
1618 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) ); |
|
1619 |
case (INT)__mkSmallInteger(5): |
|
1620 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4]) ); |
|
1621 |
case (INT)__mkSmallInteger(4): |
|
1622 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3]) ); |
|
1623 |
case (INT)__mkSmallInteger(3): |
|
1624 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2]) ); |
|
1625 |
case (INT)__mkSmallInteger(2): |
|
1626 |
RETURN ( (*thecode)(home, ap[0], ap[1]) ); |
|
1627 |
case (INT)__mkSmallInteger(1): |
|
1628 |
RETURN ( (*thecode)(home, ap[0]) ); |
|
1629 |
case (INT)__mkSmallInteger(0): |
|
1630 |
RETURN ( (*thecode)(home) ); |
|
1631 |
break; |
|
1632 |
} |
|
1037 | 1633 |
} |
1634 |
#endif |
|
1635 |
||
8913 | 1636 |
if (nA != __mkSmallInteger(0)) { |
18993 | 1637 |
ap = __arrayVal(argArray); /* nonNil after above test (size is known to be ok) */ |
1638 |
switch ((INT)nA) { |
|
1639 |
default: |
|
1640 |
goto error; |
|
1641 |
case (INT)__mkSmallInteger(15): |
|
1642 |
a15 = ap[14]; |
|
1643 |
case (INT)__mkSmallInteger(14): |
|
1644 |
a14 = ap[13]; |
|
1645 |
case (INT)__mkSmallInteger(13): |
|
1646 |
a13 = ap[12]; |
|
1647 |
case (INT)__mkSmallInteger(12): |
|
1648 |
a12 = ap[11]; |
|
1649 |
case (INT)__mkSmallInteger(11): |
|
1650 |
a11 = ap[10]; |
|
1651 |
case (INT)__mkSmallInteger(10): |
|
1652 |
a10 = ap[9]; |
|
1653 |
case (INT)__mkSmallInteger(9): |
|
1654 |
a9 = ap[8]; |
|
1655 |
case (INT)__mkSmallInteger(8): |
|
1656 |
a8 = ap[7]; |
|
1657 |
case (INT)__mkSmallInteger(7): |
|
1658 |
a7 = ap[6]; |
|
1659 |
case (INT)__mkSmallInteger(6): |
|
1660 |
a6 = ap[5]; |
|
1661 |
case (INT)__mkSmallInteger(5): |
|
1662 |
a5 = ap[4]; |
|
1663 |
case (INT)__mkSmallInteger(4): |
|
1664 |
a4 = ap[3]; |
|
1665 |
case (INT)__mkSmallInteger(3): |
|
1666 |
a3 = ap[2]; |
|
1667 |
case (INT)__mkSmallInteger(2): |
|
1668 |
a2 = ap[1]; |
|
1669 |
case (INT)__mkSmallInteger(1): |
|
1670 |
a1 = ap[0]; |
|
1671 |
case (INT)__mkSmallInteger(0): |
|
1672 |
break; |
|
1673 |
} |
|
1 | 1674 |
} |
1133 | 1675 |
|
11 | 1676 |
#ifdef NEW_BLOCK_CALL |
1 | 1677 |
if (thecode != (OBJFUNC)nil) { |
18993 | 1678 |
RETURN ( (*thecode)(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
11 | 1679 |
} |
328 | 1680 |
# ifdef PASS_ARG_POINTER |
6553
ce4ca4df3415
oops - last modification created a little bug.
Claus Gittinger <cg@exept.de>
parents:
6512
diff
changeset
|
1681 |
RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, &a1) ); |
328 | 1682 |
# else |
8009 | 1683 |
RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
328 | 1684 |
# endif |
1037 | 1685 |
|
1 | 1686 |
#else |
1037 | 1687 |
|
328 | 1688 |
# ifdef PASS_ARG_POINTER |
6553
ce4ca4df3415
oops - last modification created a little bug.
Claus Gittinger <cg@exept.de>
parents:
6512
diff
changeset
|
1689 |
RETURN ( __interpret(self, __intVal(nA), nil, home, nil, nil, &a1) ); |
328 | 1690 |
# else |
8009 | 1691 |
RETURN ( __interpret(self, __intVal(nA), nil, home, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
328 | 1692 |
# endif |
1037 | 1693 |
|
1 | 1694 |
#endif |
67 | 1695 |
|
11 | 1696 |
error: ; |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1697 |
%}. |
138 | 1698 |
" |
8009 | 1699 |
the above code only supports up-to 15 arguments |
138 | 1700 |
" |
7602
d048f13cd50a
Exception classes initialize themself.
Stefan Vogel <sv@exept.de>
parents:
7352
diff
changeset
|
1701 |
^ ArgumentError |
18993 | 1702 |
raiseRequestWith:self |
1703 |
errorString:'only blocks with up-to 15 arguments supported' |
|
1704 |
||
1705 |
" |
|
1706 |
[:a :b :c | Transcript showCR:a; showCR:b; showCR:c] valueWithArguments:#(1 2 3). |
|
1707 |
[:a :b :c | Transcript showCR:a; showCR:b; showCR:c] valueWithArguments:#(1 2 3) asOrderedCollection. |
|
1708 |
" |
|
6317 | 1709 |
! |
1710 |
||
1711 |
valueWithOptionalArgument:arg |
|
1712 |
"evaluate the receiver. |
|
6318 | 1713 |
Optionally pass an argument (if the receiver is a one arg block)." |
6317 | 1714 |
|
6628
4d693c525443
#handlerForSignal:context:originator:
Stefan Vogel <sv@exept.de>
parents:
6611
diff
changeset
|
1715 |
nargs == 1 ifTrue:[ |
18252 | 1716 |
^ self value:arg |
6317 | 1717 |
]. |
1718 |
^ self value |
|
6320 | 1719 |
|
1720 |
" |
|
1721 |
|block| |
|
1722 |
||
1723 |
block := [ Transcript showCR:'hello' ]. |
|
18252 | 1724 |
block valueWithOptionalArgument:2. |
6320 | 1725 |
|
1726 |
block := [:arg | Transcript showCR:arg ]. |
|
18252 | 1727 |
block valueWithOptionalArgument:2. |
6320 | 1728 |
" |
6785 | 1729 |
! |
1730 |
||
1731 |
valueWithOptionalArgument:arg1 and:arg2 |
|
1732 |
"evaluate the receiver. |
|
1733 |
Optionally pass up to two arguments (if the receiver is a one/two arg block)." |
|
1734 |
||
1735 |
nargs == 2 ifTrue:[ |
|
18252 | 1736 |
^ self value:arg1 value:arg2 |
6785 | 1737 |
]. |
1738 |
nargs == 1 ifTrue:[ |
|
18252 | 1739 |
^ self value:arg1 |
6785 | 1740 |
]. |
1741 |
^ self value |
|
1742 |
||
1743 |
" |
|
1744 |
|block| |
|
1745 |
||
1746 |
block := [ Transcript showCR:'hello' ]. |
|
18252 | 1747 |
block valueWithOptionalArgument:2. |
6785 | 1748 |
|
1749 |
block := [:arg | Transcript showCR:arg ]. |
|
18252 | 1750 |
block valueWithOptionalArgument:2. |
6785 | 1751 |
|
1752 |
block := [:arg1 :arg2 | Transcript showCR:arg1. Transcript showCR:arg2 ]. |
|
18252 | 1753 |
block valueWithOptionalArgument:10 and:20. |
6785 | 1754 |
" |
9010 | 1755 |
! |
1756 |
||
1757 |
valueWithOptionalArgument:arg1 and:arg2 and:arg3 |
|
1758 |
"evaluate the receiver. |
|
1759 |
Optionally pass up to three arguments (if the receiver is a one/two/three arg block)." |
|
1760 |
||
1761 |
nargs == 3 ifTrue:[ |
|
18252 | 1762 |
^ self value:arg1 value:arg2 value:arg3 |
9010 | 1763 |
]. |
1764 |
nargs == 2 ifTrue:[ |
|
18252 | 1765 |
^ self value:arg1 value:arg2 |
9010 | 1766 |
]. |
1767 |
nargs == 1 ifTrue:[ |
|
18252 | 1768 |
^ self value:arg1 |
9010 | 1769 |
]. |
1770 |
^ self value |
|
1771 |
||
1772 |
" |
|
1773 |
|block| |
|
1774 |
||
1775 |
block := [ Transcript showCR:'hello' ]. |
|
18252 | 1776 |
block valueWithOptionalArgument:2. |
9010 | 1777 |
|
1778 |
block := [:arg | Transcript showCR:arg ]. |
|
18252 | 1779 |
block valueWithOptionalArgument:2. |
9010 | 1780 |
|
1781 |
block := [:arg1 :arg2 | Transcript showCR:arg1. Transcript showCR:arg2 ]. |
|
18252 | 1782 |
block valueWithOptionalArgument:10 and:20. |
9010 | 1783 |
" |
1784 |
! |
|
1785 |
||
1786 |
valueWithOptionalArgument:arg1 and:arg2 and:arg3 and:arg4 |
|
1787 |
"evaluate the receiver. |
|
1788 |
Optionally pass up to four arguments (if the receiver is a one/two/three/four arg block)." |
|
1789 |
||
1790 |
nargs == 4 ifTrue:[ |
|
18252 | 1791 |
^ self value:arg1 value:arg2 value:arg3 value:arg4 |
9010 | 1792 |
]. |
1793 |
nargs == 3 ifTrue:[ |
|
18252 | 1794 |
^ self value:arg1 value:arg2 value:arg3 |
9010 | 1795 |
]. |
1796 |
nargs == 2 ifTrue:[ |
|
18252 | 1797 |
^ self value:arg1 value:arg2 |
9010 | 1798 |
]. |
1799 |
nargs == 1 ifTrue:[ |
|
18252 | 1800 |
^ self value:arg1 |
9010 | 1801 |
]. |
1802 |
^ self value |
|
1803 |
||
1804 |
" |
|
1805 |
|block| |
|
1806 |
||
1807 |
block := [ Transcript showCR:'hello' ]. |
|
18252 | 1808 |
block valueWithOptionalArgument:2. |
9010 | 1809 |
|
1810 |
block := [:arg | Transcript showCR:arg ]. |
|
18252 | 1811 |
block valueWithOptionalArgument:2. |
9010 | 1812 |
|
1813 |
block := [:arg1 :arg2 | Transcript showCR:arg1. Transcript showCR:arg2 ]. |
|
18252 | 1814 |
block valueWithOptionalArgument:10 and:20. |
9010 | 1815 |
" |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1816 |
! |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1817 |
|
18992 | 1818 |
valueWithOptionalArguments:argArrayIn |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1819 |
"evaluate the receiver with arguments as required taken from argArray. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1820 |
Only the required number of arguments is taken from argArray or nil; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1821 |
(i.e. argArray may be larger than the required number). |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1822 |
If the size of the argArray is smaller than the number of arguments, an error is raised." |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1823 |
|
18992 | 1824 |
|argArray numArgsProvided a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
1825 |
||
1826 |
argArray := argArrayIn. |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1827 |
(argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[ |
18992 | 1828 |
argArray isCollection ifTrue:[ |
1829 |
argArray := argArray asArray |
|
1830 |
] ifFalse:[ |
|
1831 |
^ self badArgumentArray:argArray |
|
1832 |
]. |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1833 |
]. |
18992 | 1834 |
|
1835 |
(argArray size < nargs) ifTrue:[ |
|
1836 |
^ self wrongNumberOfArguments:argArray size |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1837 |
]. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1838 |
%{ |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1839 |
REGISTER OBJFUNC thecode; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1840 |
OBJ home; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1841 |
REGISTER OBJ *ap; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1842 |
OBJ nA; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1843 |
int __numArgsProvided = __intVal(numArgsProvided); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1844 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1845 |
#if defined(THIS_CONTEXT) |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1846 |
if (__ISVALID_ILC_LNO(__pilc)) |
18992 | 1847 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1848 |
#endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1849 |
thecode = __BlockInstPtr(self)->b_code; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1850 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1851 |
nA = __INST(nargs); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1852 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1853 |
if (argArray == nil) { |
18992 | 1854 |
ap = 0; |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1855 |
} else { |
18992 | 1856 |
ap = __arrayVal(argArray); /* nonNil after above test (size is known to be ok) */ |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1857 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1858 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1859 |
#ifndef NEW_BLOCK_CALL |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1860 |
home = __BlockInstPtr(self)->b_home; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1861 |
if (thecode != (OBJFUNC)nil) { |
18992 | 1862 |
/* the most common case (0 args) here (without a switch) */ |
1863 |
||
1864 |
if (nA == __mkSmallInteger(0)) { |
|
1865 |
RETURN ( (*thecode)(home) ); |
|
1866 |
} |
|
1867 |
||
1868 |
switch ((INT)(nA)) { |
|
1869 |
default: |
|
1870 |
goto error; |
|
1871 |
case (INT)__mkSmallInteger(15): |
|
1872 |
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], ap[12], ap[13], ap[14]) ); |
|
1873 |
case (INT)__mkSmallInteger(14): |
|
1874 |
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], ap[12], ap[13]) ); |
|
1875 |
case (INT)__mkSmallInteger(13): |
|
1876 |
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], ap[12]) ); |
|
1877 |
case (INT)__mkSmallInteger(12): |
|
1878 |
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]) ); |
|
1879 |
case (INT)__mkSmallInteger(11): |
|
1880 |
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]) ); |
|
1881 |
case (INT)__mkSmallInteger(10): |
|
1882 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9]) ); |
|
1883 |
case (INT)__mkSmallInteger(9): |
|
1884 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8]) ); |
|
1885 |
case (INT)__mkSmallInteger(8): |
|
1886 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7]) ); |
|
1887 |
case (INT)__mkSmallInteger(7): |
|
1888 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) ); |
|
1889 |
case (INT)__mkSmallInteger(6): |
|
1890 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) ); |
|
1891 |
case (INT)__mkSmallInteger(5): |
|
1892 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4]) ); |
|
1893 |
case (INT)__mkSmallInteger(4): |
|
1894 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3]) ); |
|
1895 |
case (INT)__mkSmallInteger(3): |
|
1896 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2]) ); |
|
1897 |
case (INT)__mkSmallInteger(2): |
|
1898 |
RETURN ( (*thecode)(home, ap[0], ap[1]) ); |
|
1899 |
case (INT)__mkSmallInteger(1): |
|
1900 |
RETURN ( (*thecode)(home, ap[0]) ); |
|
1901 |
case (INT)__mkSmallInteger(0): |
|
1902 |
RETURN ( (*thecode)(home) ); |
|
1903 |
break; |
|
1904 |
} |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1905 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1906 |
#endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1907 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1908 |
if (nA != __mkSmallInteger(0)) { |
18992 | 1909 |
ap = __arrayVal(argArray); /* nonNil after above test (size is known to be ok) */ |
1910 |
switch ((INT)nA) { |
|
1911 |
default: |
|
1912 |
goto error; |
|
1913 |
case (INT)__mkSmallInteger(15): |
|
1914 |
a15 = ap[14]; |
|
1915 |
case (INT)__mkSmallInteger(14): |
|
1916 |
a14 = ap[13]; |
|
1917 |
case (INT)__mkSmallInteger(13): |
|
1918 |
a13 = ap[12]; |
|
1919 |
case (INT)__mkSmallInteger(12): |
|
1920 |
a12 = ap[11]; |
|
1921 |
case (INT)__mkSmallInteger(11): |
|
1922 |
a11 = ap[10]; |
|
1923 |
case (INT)__mkSmallInteger(10): |
|
1924 |
a10 = ap[9]; |
|
1925 |
case (INT)__mkSmallInteger(9): |
|
1926 |
a9 = ap[8]; |
|
1927 |
case (INT)__mkSmallInteger(8): |
|
1928 |
a8 = ap[7]; |
|
1929 |
case (INT)__mkSmallInteger(7): |
|
1930 |
a7 = ap[6]; |
|
1931 |
case (INT)__mkSmallInteger(6): |
|
1932 |
a6 = ap[5]; |
|
1933 |
case (INT)__mkSmallInteger(5): |
|
1934 |
a5 = ap[4]; |
|
1935 |
case (INT)__mkSmallInteger(4): |
|
1936 |
a4 = ap[3]; |
|
1937 |
case (INT)__mkSmallInteger(3): |
|
1938 |
a3 = ap[2]; |
|
1939 |
case (INT)__mkSmallInteger(2): |
|
1940 |
a2 = ap[1]; |
|
1941 |
case (INT)__mkSmallInteger(1): |
|
1942 |
a1 = ap[0]; |
|
1943 |
case (INT)__mkSmallInteger(0): |
|
1944 |
break; |
|
1945 |
} |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1946 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1947 |
#ifdef NEW_BLOCK_CALL |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1948 |
if (thecode != (OBJFUNC)nil) { |
18992 | 1949 |
RETURN ( (*thecode)(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1950 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1951 |
# ifdef PASS_ARG_POINTER |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1952 |
RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, &a1) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1953 |
# else |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1954 |
RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1955 |
# endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1956 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1957 |
#else |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1958 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1959 |
# ifdef PASS_ARG_POINTER |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1960 |
RETURN ( __interpret(self, __intVal(nA), nil, home, nil, nil, &a1) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1961 |
# else |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1962 |
RETURN ( __interpret(self, __intVal(nA), nil, home, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1963 |
# endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1964 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1965 |
#endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1966 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1967 |
error: ; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1968 |
%}. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1969 |
" |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1970 |
the above code only supports up-to 15 arguments |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1971 |
" |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1972 |
^ ArgumentError |
18992 | 1973 |
raiseRequestWith:self |
1974 |
errorString:'only blocks with up-to 15 arguments supported' |
|
1975 |
||
1976 |
||
1977 |
" |
|
1978 |
[:a :b :c | Transcript showCR:a; showCR:b; showCR:c] valueWithOptionalArguments:#(1 2 3 4). |
|
1979 |
[:a :b :c | Transcript showCR:a; showCR:b; showCR:c] valueWithOptionalArguments:#(1 2 3 4) asOrderedCollection. |
|
1980 |
" |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1981 |
! |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1982 |
|
18992 | 1983 |
valueWithPossibleArguments:argArrayIn |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1984 |
"evaluate the receiver with arguments as required taken from argArray. |
18252 | 1985 |
If argArray provides less than the required number of arguments, |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1986 |
nil is assumed for any remaining argument. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1987 |
(i.e. argArray may be smaller than the required number). |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1988 |
Only the required number of arguments is taken from argArray or nil; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1989 |
(i.e. argArray may be larger than the required number)." |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1990 |
|
18992 | 1991 |
|argArray numArgsProvided a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
1992 |
||
1993 |
argArray := argArrayIn. |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1994 |
(argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[ |
18992 | 1995 |
argArray isCollection ifTrue:[ |
1996 |
argArray := argArray asArray |
|
1997 |
] ifFalse:[ |
|
1998 |
^ self badArgumentArray:argArray |
|
1999 |
]. |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2000 |
]. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2001 |
numArgsProvided := argArray size. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2002 |
%{ |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2003 |
REGISTER OBJFUNC thecode; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2004 |
OBJ home; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2005 |
REGISTER OBJ *ap; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2006 |
OBJ nA; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2007 |
int __numArgsProvided = __intVal(numArgsProvided); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2008 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2009 |
#if defined(THIS_CONTEXT) |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2010 |
if (__ISVALID_ILC_LNO(__pilc)) |
18992 | 2011 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2012 |
#endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2013 |
thecode = __BlockInstPtr(self)->b_code; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2014 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2015 |
nA = __INST(nargs); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2016 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2017 |
if (argArray == nil) { |
18992 | 2018 |
ap = 0; |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2019 |
} else { |
18992 | 2020 |
ap = __arrayVal(argArray); /* nonNil after above test (size is known to be ok) */ |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2021 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2022 |
switch (__numArgsProvided) { |
18992 | 2023 |
default: |
2024 |
case 15: a15 = ap[14]; |
|
2025 |
case 14: a14 = ap[13]; |
|
2026 |
case 13: a13 = ap[12]; |
|
2027 |
case 12: a12 = ap[11]; |
|
2028 |
case 11: a11 = ap[10]; |
|
2029 |
case 10: a10 = ap[9]; |
|
2030 |
case 9: a9 = ap[8]; |
|
2031 |
case 8: a8 = ap[7]; |
|
2032 |
case 7: a7 = ap[6]; |
|
2033 |
case 6: a6 = ap[5]; |
|
2034 |
case 5: a5 = ap[4]; |
|
2035 |
case 4: a4 = ap[3]; |
|
2036 |
case 3: a3 = ap[2]; |
|
2037 |
case 2: a2 = ap[1]; |
|
2038 |
case 1: a1 = ap[0]; |
|
2039 |
case 0: ; |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2040 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2041 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2042 |
#ifndef NEW_BLOCK_CALL |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2043 |
home = __BlockInstPtr(self)->b_home; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2044 |
if (thecode != (OBJFUNC)nil) { |
18992 | 2045 |
/* the most common case (0 args) here (without a switch) */ |
2046 |
||
2047 |
if (nA == __mkSmallInteger(0)) { |
|
2048 |
RETURN ( (*thecode)(home) ); |
|
2049 |
} |
|
2050 |
||
2051 |
switch ((INT)(nA)) { |
|
2052 |
default: |
|
2053 |
goto error; |
|
2054 |
case (INT)__mkSmallInteger(15): |
|
2055 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
|
2056 |
case (INT)__mkSmallInteger(14): |
|
2057 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) ); |
|
2058 |
case (INT)__mkSmallInteger(13): |
|
2059 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) ); |
|
2060 |
case (INT)__mkSmallInteger(12): |
|
2061 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) ); |
|
2062 |
case (INT)__mkSmallInteger(11): |
|
2063 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) ); |
|
2064 |
case (INT)__mkSmallInteger(10): |
|
2065 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) ); |
|
2066 |
case (INT)__mkSmallInteger(9): |
|
2067 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9) ); |
|
2068 |
case (INT)__mkSmallInteger(8): |
|
2069 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8) ); |
|
2070 |
case (INT)__mkSmallInteger(7): |
|
2071 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7) ); |
|
2072 |
case (INT)__mkSmallInteger(6): |
|
2073 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6) ); |
|
2074 |
case (INT)__mkSmallInteger(5): |
|
2075 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5) ); |
|
2076 |
case (INT)__mkSmallInteger(4): |
|
2077 |
RETURN ( (*thecode)(home, a1, a2, a3, a4) ); |
|
2078 |
case (INT)__mkSmallInteger(3): |
|
2079 |
RETURN ( (*thecode)(home, a1, a2, a3) ); |
|
2080 |
case (INT)__mkSmallInteger(2): |
|
2081 |
RETURN ( (*thecode)(home, a1, a2) ); |
|
2082 |
case (INT)__mkSmallInteger(1): |
|
2083 |
RETURN ( (*thecode)(home, a1) ); |
|
2084 |
case (INT)__mkSmallInteger(0): |
|
2085 |
RETURN ( (*thecode)(home) ); |
|
2086 |
break; |
|
2087 |
} |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2088 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2089 |
#endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2090 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2091 |
#ifdef NEW_BLOCK_CALL |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2092 |
if (thecode != (OBJFUNC)nil) { |
18992 | 2093 |
RETURN ( (*thecode)(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2094 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2095 |
# ifdef PASS_ARG_POINTER |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2096 |
RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, &a1) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2097 |
# else |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2098 |
RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2099 |
# endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2100 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2101 |
#else |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2102 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2103 |
# ifdef PASS_ARG_POINTER |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2104 |
RETURN ( __interpret(self, __intVal(nA), nil, home, nil, nil, &a1) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2105 |
# else |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2106 |
RETURN ( __interpret(self, __intVal(nA), nil, home, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2107 |
# endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2108 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2109 |
#endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2110 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2111 |
error: ; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2112 |
%}. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2113 |
" |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2114 |
the above code only supports up-to 15 arguments |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2115 |
" |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2116 |
^ ArgumentError |
18992 | 2117 |
raiseRequestWith:self |
2118 |
errorString:'only blocks with up-to 15 arguments supported' |
|
2119 |
||
2120 |
" |
|
2121 |
[:a :b :c :d| Transcript showCR:a; showCR:b; showCR:c; showCR:d] valueWithPossibleArguments:#(1 2 3). |
|
2122 |
[:a :b :c :d| Transcript showCR:a; showCR:b; showCR:c; showCR:d] valueWithPossibleArguments:#(1 2 3) asOrderedCollection. |
|
2123 |
" |
|
154 | 2124 |
! ! |
2125 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2126 |
!Block methodsFor:'exception handling'! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2127 |
|
6512 | 2128 |
on:aSignalOrSignalSetOrException do:exceptionBlock |
2129 |
"added for ANSI compatibility; evaluate the receiver, |
|
18252 | 2130 |
handling aSignalOrSignalSetOrException. |
18316 | 2131 |
If the signal is raised during evaluation, |
2132 |
the 2nd argument, exceptionBlock is evaluated (and its value returned" |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2133 |
|
4542
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
2134 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2135 |
<exception: #handle> |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2136 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2137 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2138 |
^ 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
|
2139 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2140 |
" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2141 |
[ |
18316 | 2142 |
1 foo |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2143 |
] on:MessageNotUnderstood do:[:ex | self halt] |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2144 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2145 |
[ |
18316 | 2146 |
1 foo |
6512 | 2147 |
] on:(MessageNotUnderstood , AbortOperationRequest) do:[:ex | self halt] |
2148 |
||
2149 |
[ |
|
18316 | 2150 |
1 foo |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2151 |
] on:SignalSet anySignal do:[:ex| 2 bar. self halt] |
18316 | 2152 |
|
2153 |
[ |
|
2154 |
1 foo |
|
2155 |
] on:Error do:[:ex| 2 ] |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2156 |
" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2157 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2158 |
"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
|
2159 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2160 |
|
11338 | 2161 |
on:aSignalOrSignalSetOrException do:exceptionBlock ensure:ensureBlock |
2162 |
"added for ANSI compatibility; evaluate the receiver, |
|
18252 | 2163 |
handling aSignalOrSignalSetOrException. |
11338 | 2164 |
The 2nd argument, exceptionBlock is evaluated |
2165 |
if the signal is raised during evaluation. |
|
2166 |
The 3rd argument, ensureBlock is evaluated in any case - even if the activity |
|
2167 |
was unwound due to an unhandled exception." |
|
2168 |
||
2169 |
<context: #return> |
|
2170 |
<exception: #handle> |
|
2171 |
<exception: #unwind> |
|
2172 |
||
2173 |
|v| |
|
2174 |
||
2175 |
v := self value. "the real logic is in Context>>unwind and Exception>>doRaise" |
|
2176 |
thisContext unmarkForUnwind. |
|
2177 |
ensureBlock value. |
|
2178 |
^ v |
|
2179 |
||
2180 |
" |
|
2181 |
|e| |
|
2182 |
||
2183 |
e := 0. |
|
2184 |
[ |
|
18252 | 2185 |
1 foo |
2186 |
] on:MessageNotUnderstood |
|
11338 | 2187 |
do:[:ex | self halt] |
2188 |
ensure:[ e := 1 ]. |
|
2189 |
self assert:(e == 1). |
|
2190 |
" |
|
2191 |
||
2192 |
" |
|
2193 |
|e| |
|
2194 |
||
2195 |
e := 0. |
|
2196 |
[ |
|
18252 | 2197 |
1 negated |
2198 |
] on:MessageNotUnderstood |
|
11338 | 2199 |
do:[:ex | self halt] |
2200 |
ensure:[ e := 1 ]. |
|
2201 |
self assert:(e == 1). |
|
2202 |
" |
|
2203 |
! |
|
2204 |
||
18959 | 2205 |
on:aSignalOrSignalSetOrException do:exceptionBlock ifCurtailed:curtailBlock |
2206 |
"evaluate the receiver, |
|
2207 |
handling aSignalOrSignalSetOrException. |
|
2208 |
The 2nd argument, exceptionBlock is evaluated |
|
2209 |
if the signal is raised during evaluation. |
|
2210 |
The 3rd argument, curtailBlock is evaluated if the activity |
|
2211 |
was unwound due to an unhandled exception in the receiver block |
|
2212 |
(but not in the exceptionBlock)." |
|
2213 |
||
2214 |
<context: #return> |
|
2215 |
<exception: #handle> |
|
2216 |
<exception: #unwind> |
|
2217 |
||
2218 |
|v| |
|
2219 |
||
2220 |
v := self value. "the real logic is in Context>>unwind and Exception>>doRaise" |
|
2221 |
thisContext unmarkForUnwind. |
|
2222 |
^ v |
|
2223 |
||
2224 |
" |
|
2225 |
|e| |
|
2226 |
||
2227 |
e := 0. |
|
2228 |
[ |
|
2229 |
1 foo |
|
2230 |
] on:MessageNotUnderstood |
|
2231 |
do:[:ex | e := 1] |
|
2232 |
ifCurtailed:[ e := 2 ]. |
|
2233 |
self assert:(e == 1). |
|
2234 |
" |
|
2235 |
||
2236 |
" |
|
2237 |
abort the debugger to perform the ifCurtailedBlock... |
|
2238 |
continue the debugger to go to the end |
|
2239 |
||
2240 |
|e| |
|
2241 |
||
2242 |
e := 0. |
|
2243 |
[ |
|
2244 |
#[] at:2 |
|
2245 |
] on:MessageNotUnderstood |
|
2246 |
do:[:ex | e := 1] |
|
2247 |
ifCurtailed:[ e := 2. e inspect ]. |
|
2248 |
self assert:(e == 0). |
|
2249 |
" |
|
2250 |
||
2251 |
" |
|
2252 |
|e| |
|
2253 |
||
2254 |
e := 0. |
|
2255 |
[ |
|
2256 |
1 negated |
|
2257 |
] on:MessageNotUnderstood |
|
2258 |
do:[:ex | self halt] |
|
2259 |
ifCurtailed:[ e := 1 ]. |
|
2260 |
self assert:(e == 0). |
|
2261 |
" |
|
2262 |
! |
|
2263 |
||
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2264 |
on:anExceptionHandler do:exceptionBlock on:anExceptionHandler2 do:anExceptionBlock2 |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2265 |
"added for ANSI compatibility; evaluate the receiver, |
18252 | 2266 |
handling aSignalOrSignalSetOrException. |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2267 |
The 2nd argument, exceptionBlock is evaluated |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2268 |
if the signal is raised during evaluation." |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2269 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2270 |
<context: #return> |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2271 |
<exception: #handle> |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2272 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2273 |
"/ thisContext markForHandle. -- same as above pragma |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2274 |
^ self value. "the real logic is in Exception>>doRaise" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2275 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2276 |
" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2277 |
[ |
18252 | 2278 |
1 foo |
2279 |
] on:MessageNotUnderstood do:[:ex | self halt:'Got MessageNotUnderstood'] |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2280 |
on:Error do:[:ex| self halt:'Got Error'] |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2281 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2282 |
[ |
18252 | 2283 |
1 // 0 |
2284 |
] on:MessageNotUnderstood do:[:ex | self halt:'Got MessageNotUnderstood'] |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2285 |
on:Error do:[:ex| self halt:'Got Error'] |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2286 |
" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2287 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2288 |
"Modified: / 26.7.1999 / 15:30:48 / stefan" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2289 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2290 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2291 |
valueWithExceptionHandler:handler |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2292 |
"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
|
2293 |
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
|
2294 |
|
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4542
diff
changeset
|
2295 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2296 |
<exception: #handle> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2297 |
|
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2298 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2299 |
^ 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
|
2300 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2301 |
"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
|
2302 |
"Modified: / 26.7.1999 / 11:24:06 / stefan" |
9485
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2303 |
! |
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2304 |
|
19237 | 2305 |
valueWithTimeout:aTimeDurationOrIntegerSeconds |
14803 | 2306 |
"execute the receiver, but abort the evaluation after aTimeDuration if still running. |
16076 | 2307 |
Return the receiver's value, or nil if aborted." |
14803 | 2308 |
|
19237 | 2309 |
|milliseconds| |
2310 |
||
2311 |
milliseconds := aTimeDurationOrIntegerSeconds isTimeDuration |
|
2312 |
ifTrue:[ aTimeDurationOrIntegerSeconds asMilliseconds ] |
|
2313 |
ifFalse:[ (aTimeDurationOrIntegerSeconds * 1000) truncated]. |
|
2314 |
^ self valueWithWatchDog:[^ nil] afterMilliseconds:milliseconds |
|
14803 | 2315 |
|
2316 |
" |
|
2317 |
[ |
|
19237 | 2318 |
1 to:15 do:[:round | |
2319 |
Transcript showCR:round. |
|
2320 |
Delay waitForMilliseconds:20. |
|
2321 |
]. |
|
2322 |
true |
|
18252 | 2323 |
] valueWithTimeout:(TimeDuration seconds:1) |
14803 | 2324 |
" |
2325 |
||
2326 |
" |
|
2327 |
[ |
|
19237 | 2328 |
1 to:100 do:[:round | |
2329 |
Transcript showCR:round. |
|
2330 |
Delay waitForMilliseconds:20. |
|
2331 |
]. |
|
2332 |
true |
|
18252 | 2333 |
] valueWithTimeout:(TimeDuration seconds:1) |
14803 | 2334 |
" |
2335 |
! |
|
2336 |
||
9485
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2337 |
valueWithWatchDog:exceptionBlock afterMilliseconds:aTimeLimit |
11803 | 2338 |
"a watchdog on a block's execution. If the block does not finish its |
2339 |
evaluation after aTimeLimit milliseconds, it is interrupted (aborted) and |
|
2340 |
exceptionBlock's value is returned. The receiver's code must be prepared |
|
2341 |
for premature returning (by adding ensure blocks, as required)" |
|
9485
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2342 |
|
13220
21b4d5e57663
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
13054
diff
changeset
|
2343 |
|showStopper me retVal done inError| |
12927
1caadc2e24d8
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
12921
diff
changeset
|
2344 |
|
1caadc2e24d8
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
12921
diff
changeset
|
2345 |
done := false. |
9485
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2346 |
me := Processor activeProcess. |
11704
a47fdf0a638d
oops - valueWithWatchDog did not
Claus Gittinger <cg@exept.de>
parents:
11638
diff
changeset
|
2347 |
|
18252 | 2348 |
showStopper := |
2349 |
[ |
|
2350 |
done ifFalse:[ |
|
2351 |
me interruptWith:[ |
|
2352 |
(Processor activeProcess state ~~ #debug) ifTrue:[ |
|
2353 |
done ifFalse:[ TimeoutNotification raiseRequest ] |
|
2354 |
] |
|
2355 |
] |
|
2356 |
] |
|
2357 |
]. |
|
13030
9b9f51659b4a
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
12931
diff
changeset
|
2358 |
|
9b9f51659b4a
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
12931
diff
changeset
|
2359 |
TimeoutNotification handle:[:ex | |
18252 | 2360 |
inError ifTrue:[ |
2361 |
ex proceed |
|
2362 |
]. |
|
2363 |
retVal := exceptionBlock value. |
|
10700
0436b2f40e4c
changed #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
10678
diff
changeset
|
2364 |
] do:[ |
18252 | 2365 |
NoHandlerError handle:[:ex | |
2366 |
inError := true. |
|
2367 |
ex reject. |
|
2368 |
] do:[ |
|
2369 |
[ |
|
2370 |
Processor |
|
2371 |
addTimedBlock:showStopper |
|
2372 |
for:me |
|
2373 |
afterMilliseconds:aTimeLimit. |
|
2374 |
||
2375 |
retVal := self value. |
|
2376 |
done := true. |
|
2377 |
] ensure:[ |
|
2378 |
Processor removeTimedBlock:showStopper |
|
2379 |
]. |
|
2380 |
] |
|
9485
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2381 |
]. |
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2382 |
^ retVal |
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2383 |
|
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2384 |
" |
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2385 |
[ |
18252 | 2386 |
Delay waitForSeconds:5. |
2387 |
true |
|
2388 |
] valueWithWatchDog:[false] afterMilliseconds:2000 |
|
9485
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2389 |
" |
10678
5cd10f301f94
changed #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
10473
diff
changeset
|
2390 |
|
12928 | 2391 |
"Modified: / 21-05-2010 / 12:19:57 / sr" |
13220
21b4d5e57663
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
13054
diff
changeset
|
2392 |
"Modified: / 18-01-2011 / 19:24:13 / cg" |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2393 |
! ! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2394 |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2395 |
!Block methodsFor:'exception handling private'! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2396 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2397 |
exceptionHandlerFor:anException in:aContext |
11338 | 2398 |
"answer the exceptionHandler (the Error or signal) for anException from aContext." |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2399 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2400 |
aContext selector == #on:do:on:do: ifTrue:[ |
18252 | 2401 |
|exceptionCreator exceptionHandlerInContext| |
2402 |
||
2403 |
exceptionCreator := anException creator. |
|
2404 |
exceptionHandlerInContext := aContext argAt:1. |
|
2405 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
|
2406 |
exceptionHandlerInContext isNil ifTrue:[ |
|
2407 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2408 |
] ifFalse:[ |
|
2409 |
(exceptionHandlerInContext isBehavior |
|
2410 |
and:[exceptionHandlerInContext isLoaded not]) ifTrue:[ |
|
2411 |
"If the exception class is still autoloaded, |
|
2412 |
it does not accept our exception. Raising the exception would load the class" |
|
2413 |
^ nil |
|
2414 |
] ifFalse:[ |
|
2415 |
'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2416 |
] |
|
2417 |
]. |
|
2418 |
aContext fullPrintString errorPrintCR. |
|
2419 |
self breakPoint:#cg. |
|
2420 |
^ nil. |
|
2421 |
]. |
|
2422 |
(exceptionHandlerInContext accepts:exceptionCreator) ifTrue:[ |
|
2423 |
^ exceptionHandlerInContext. |
|
2424 |
]. |
|
2425 |
||
2426 |
exceptionHandlerInContext := aContext argAt:3. |
|
2427 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
|
2428 |
exceptionHandlerInContext isNil ifTrue:[ |
|
2429 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2430 |
] ifFalse:[ |
|
2431 |
(exceptionHandlerInContext isBehavior |
|
2432 |
and:[exceptionHandlerInContext isLoaded not]) ifTrue:[ |
|
2433 |
"If the exception class is still autoloaded, |
|
2434 |
it does not accept our exception. Raising the exception would load the class" |
|
2435 |
^ nil |
|
2436 |
] ifFalse:[ |
|
2437 |
'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2438 |
] |
|
2439 |
]. |
|
2440 |
aContext fullPrintString errorPrintCR. |
|
2441 |
self breakPoint:#cg. |
|
2442 |
^ nil. |
|
2443 |
]. |
|
2444 |
(exceptionHandlerInContext accepts:exceptionCreator) ifTrue:[ |
|
2445 |
^ exceptionHandlerInContext. |
|
2446 |
]. |
|
2447 |
^ nil. |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2448 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2449 |
|
11338 | 2450 |
"aContext selector must be #on:do: , #on:do:ensure: or #valueWithExceptionHandler:" |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2451 |
^ aContext argAt:1. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2452 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2453 |
|
18959 | 2454 |
handlerForSignal:exceptionCreator context:theContext originator:originator |
2455 |
"answer the handler block for the exceptionCreator from originator. |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2456 |
The handler block is retrieved from aContext. |
18959 | 2457 |
Answer nil if the exceptionCreator is not handled." |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2458 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2459 |
|selector exceptionHandlerInContext| |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2460 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2461 |
selector := theContext selector. |
11338 | 2462 |
|
2463 |
(selector == #on:do: |
|
18959 | 2464 |
or:[ selector == #on:do:ensure: |
2465 |
or:[ selector == #on:do:ifCurtailed: ]] |
|
2466 |
) ifTrue:[ |
|
2467 |
exceptionHandlerInContext := theContext argAt:1. |
|
2468 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
|
2469 |
exceptionHandlerInContext isNil ifTrue:[ |
|
2470 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2471 |
] ifFalse:[(exceptionHandlerInContext isBehavior |
|
2472 |
and:[exceptionHandlerInContext isLoaded not]) ifTrue:[ |
|
2473 |
"If the exception class is still autoloaded, |
|
2474 |
it does not accept our exception. Raising the exception would load the class" |
|
2475 |
^ nil |
|
2476 |
] ifFalse:[ |
|
2477 |
'Block [warning]: non-ExceptionHandler in on:do:-context' errorPrintCR. |
|
2478 |
]]. |
|
2479 |
theContext fullPrint. |
|
2480 |
^ nil. |
|
2481 |
]. |
|
2482 |
(exceptionHandlerInContext == exceptionCreator |
|
2483 |
or:[exceptionHandlerInContext accepts:exceptionCreator]) ifTrue:[ |
|
2484 |
selector == #on:do:ifCurtailed: ifTrue:[ |
|
2485 |
theContext unmarkForUnwind. "if there is a handler, no unwind block has to be performed" |
|
2486 |
]. |
|
2487 |
^ (theContext argAt:2) ? [nil]. |
|
2488 |
]. |
|
2489 |
^ nil |
|
11338 | 2490 |
]. |
2491 |
||
2492 |
selector == #on:do:on:do: ifTrue:[ |
|
18959 | 2493 |
exceptionHandlerInContext := theContext argAt:1. |
2494 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
|
2495 |
exceptionHandlerInContext isNil ifTrue:[ |
|
2496 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2497 |
] ifFalse:[(exceptionHandlerInContext isBehavior |
|
2498 |
and:[exceptionHandlerInContext isLoaded not]) ifTrue:[ |
|
2499 |
"If the exception class is still autoloaded, |
|
2500 |
it does not accept our exception. Raising the exception would load the class" |
|
2501 |
^ nil |
|
2502 |
] ifFalse:[ |
|
2503 |
'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2504 |
]]. |
|
2505 |
theContext fullPrint. |
|
2506 |
^ nil. |
|
2507 |
]. |
|
2508 |
(exceptionHandlerInContext == exceptionCreator |
|
2509 |
or:[exceptionHandlerInContext accepts:exceptionCreator]) ifTrue:[ |
|
2510 |
^ (theContext argAt:2) ? [nil]. |
|
2511 |
]. |
|
2512 |
||
2513 |
exceptionHandlerInContext := theContext argAt:3. |
|
2514 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
|
2515 |
exceptionHandlerInContext isNil ifTrue:[ |
|
2516 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2517 |
] ifFalse:[(exceptionHandlerInContext isBehavior |
|
2518 |
and:[exceptionHandlerInContext isLoaded not]) ifTrue:[ |
|
2519 |
"If the exception class is still autoloaded, |
|
2520 |
it does not accept our exception. Raising the exception would load the class" |
|
2521 |
^ nil |
|
2522 |
] ifFalse:[ |
|
2523 |
'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2524 |
]]. |
|
2525 |
theContext fullPrint. |
|
2526 |
^ nil. |
|
2527 |
]. |
|
2528 |
(exceptionHandlerInContext == exceptionCreator |
|
2529 |
or:[exceptionHandlerInContext accepts:exceptionCreator]) ifTrue:[ |
|
2530 |
^ (theContext argAt:4) ? [nil]. |
|
2531 |
]. |
|
2532 |
^ nil |
|
11338 | 2533 |
]. |
2534 |
||
2535 |
selector == #valueWithExceptionHandler: ifTrue:[ |
|
18959 | 2536 |
^ (theContext argAt:1) handlerForSignal:exceptionCreator. |
11338 | 2537 |
]. |
2538 |
||
2539 |
"/ mhmh - should not arrive here |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2540 |
^ nil |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2541 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2542 |
"Created: / 25.7.1999 / 19:52:58 / stefan" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2543 |
"Modified: / 26.7.1999 / 14:30:42 / stefan" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2544 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2545 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2546 |
handlerProtectedBlock:doBlock inContext:context |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2547 |
"set the block that is protected by an exception handler in context. |
11338 | 2548 |
This is the receiver of the #on:do: or #valueWithExceptionHandler:. |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2549 |
Needed for #restartDo:" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2550 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2551 |
context receiver:doBlock |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2552 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2553 |
" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2554 |
[1/0] on:Error do:[:ex| ex restartDo:[55]] |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2555 |
" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2556 |
! ! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2557 |
|
14139 | 2558 |
|
623 | 2559 |
!Block methodsFor:'looping'! |
325 | 2560 |
|
623 | 2561 |
doUntil:aBlock |
2562 |
"repeat the receiver block until aBlock evaluates to true. |
|
2563 |
The receiver is evaluated at least once. |
|
2564 |
This is the same as '... doWhile:[... not]' " |
|
325 | 2565 |
|
623 | 2566 |
"this implementation is for purists ... :-)" |
2567 |
||
2568 |
self value. |
|
2569 |
aBlock value ifTrue:[^ nil]. |
|
2570 |
thisContext restart |
|
325 | 2571 |
|
2572 |
" |
|
623 | 2573 |
|n| |
154 | 2574 |
|
623 | 2575 |
n := 1. |
8602 | 2576 |
[n printCR] doUntil:[ (n := n + 1) > 5 ] |
154 | 2577 |
" |
1 | 2578 |
! |
2579 |
||
623 | 2580 |
doWhile:aBlock |
2581 |
"repeat the receiver block until aBlock evaluates to false. |
|
2582 |
The receiver is evaluated at least once." |
|
67 | 2583 |
|
154 | 2584 |
"this implementation is for purists ... :-)" |
2585 |
||
623 | 2586 |
self value. |
2587 |
aBlock value ifFalse:[^ nil]. |
|
2588 |
thisContext restart |
|
2589 |
||
2590 |
" |
|
2591 |
|n| |
|
2592 |
||
2593 |
n := 1. |
|
8602 | 2594 |
[n printCR] doWhile:[ (n := n + 1) <= 5 ] |
623 | 2595 |
" |
2596 |
! |
|
2597 |
||
2598 |
loop |
|
18252 | 2599 |
"repeat the receiver forever |
1211 | 2600 |
(the receiver block should contain a return somewhere). |
2601 |
The implementation below was inspired by a corresponding Self method." |
|
623 | 2602 |
|
2603 |
self value. |
|
67 | 2604 |
thisContext restart |
2605 |
||
2606 |
" |
|
2607 |
|n| |
|
2608 |
||
2609 |
n := 1. |
|
623 | 2610 |
[ |
18252 | 2611 |
n printCR. |
2612 |
n >= 10 ifTrue:[^ nil]. |
|
2613 |
n := n + 1 |
|
623 | 2614 |
] loop |
2615 |
" |
|
1211 | 2616 |
|
2617 |
"Modified: 18.4.1996 / 13:50:40 / cg" |
|
623 | 2618 |
! |
2619 |
||
2620 |
loopWithExit |
|
18252 | 2621 |
"the receiver must be a block of one argument. It is evaluated in a loop forever, |
2622 |
and is passed a block, which, if sent a value:-message, will exit the receiver block, |
|
623 | 2623 |
returning the parameter of the value:-message. Used for loops with exit in the middle. |
2624 |
Inspired by a corresponding Self method." |
|
2625 |
||
2626 |
|exitBlock| |
|
2627 |
||
2628 |
exitBlock := [:exitValue | ^ exitValue]. |
|
16239 | 2629 |
[self value:exitBlock] loop. |
623 | 2630 |
|
2631 |
" |
|
2632 |
|i| |
|
2633 |
i := 1. |
|
2634 |
[:exit | |
|
18252 | 2635 |
Transcript showCR:i. |
2636 |
i == 5 ifTrue:[exit value:'thats it']. |
|
2637 |
i := i + 1 |
|
623 | 2638 |
] loopWithExit |
2639 |
" |
|
2640 |
! |
|
2641 |
||
2642 |
repeat |
|
1211 | 2643 |
"repeat the receiver forever - same as loop, for ST-80 compatibility. |
2644 |
(the receiver block should contain a return somewhere)." |
|
623 | 2645 |
|
2646 |
self value. |
|
2647 |
thisContext restart |
|
1211 | 2648 |
|
2649 |
"Modified: 18.4.1996 / 13:50:55 / cg" |
|
623 | 2650 |
! |
2651 |
||
16162 | 2652 |
repeat:n |
18252 | 2653 |
"repeat the receiver n times - similar to timesRepeat, but optionally passes the |
16162 | 2654 |
loop counter as argument" |
2655 |
||
18434 | 2656 |
self argumentCount == 0 ifTrue:[ |
2657 |
n timesRepeat:self |
|
16162 | 2658 |
] ifFalse:[ |
18434 | 2659 |
1 to:n do:self |
16162 | 2660 |
]. |
2661 |
||
2662 |
" |
|
2663 |
[ Transcript showCR:'hello' ] repeat:3 |
|
2664 |
[:i | Transcript showCR:'hello',i printString ] repeat:3 |
|
2665 |
" |
|
2666 |
! |
|
2667 |
||
623 | 2668 |
valueWithExit |
2669 |
"the receiver must be a block of one argument. It is evaluated, and is passed a block, |
|
18252 | 2670 |
which, if sent a value:-message, will exit the receiver block, returning the parameter of the |
623 | 2671 |
value:-message. Used for premature returns to the caller. |
2672 |
Taken from a manchester goody (a similar construct also appears in Self)." |
|
2673 |
||
1211 | 2674 |
^ self value:[:exitValue | ^exitValue] |
623 | 2675 |
|
2676 |
" |
|
2677 |
[:exit | |
|
2238 | 2678 |
1 to:10 do:[:i | |
2679 |
Transcript showCR:i. |
|
2680 |
i == 5 ifTrue:[exit value:'thats it'] |
|
2681 |
]. |
|
2682 |
'regular block-value; never returned' |
|
623 | 2683 |
] valueWithExit |
2684 |
" |
|
1211 | 2685 |
|
2686 |
"Modified: 18.4.1996 / 13:51:38 / cg" |
|
623 | 2687 |
! |
2688 |
||
5215 | 2689 |
valueWithRestart |
14683 | 2690 |
"the receiver must be a block of one argument. It is evaluated, and is passed a block, |
15244 | 2691 |
which, if sent a value-message, will restart the receiver block from the beginning" |
2692 |
||
15316 | 2693 |
|myContext restartAction| |
5215 | 2694 |
|
2695 |
myContext := thisContext. |
|
15320 | 2696 |
restartAction := [ myContext unwindAndRestart ]. |
15316 | 2697 |
^ self value:restartAction. |
5215 | 2698 |
|
2699 |
" |
|
2700 |
[:restart | |
|
18252 | 2701 |
(self confirm:'try again ?') ifTrue:[ |
2702 |
restart value. |
|
2703 |
] |
|
5215 | 2704 |
] valueWithRestart |
2705 |
" |
|
2706 |
||
2707 |
"Modified: / 25.1.2000 / 21:47:50 / cg" |
|
2708 |
! |
|
2709 |
||
14683 | 2710 |
valueWithRestartAndExit |
2711 |
"the receiver must be a block of two arguments, a restart and an exit block. |
|
2712 |
See description of valueWithExit and valueWithRestart for their use" |
|
2713 |
||
15316 | 2714 |
|myContext restartAction| |
14683 | 2715 |
|
2716 |
myContext := thisContext. |
|
15320 | 2717 |
restartAction := [ myContext unwindAndRestart ]. |
15316 | 2718 |
^ self value:restartAction value:[:exitValue | ^exitValue]. |
14683 | 2719 |
|
2720 |
" |
|
2721 |
[:restart :exit | |
|
18252 | 2722 |
|i| |
2723 |
||
2724 |
i := 0. |
|
2725 |
[ |
|
2726 |
i := i + 1. |
|
2727 |
(self confirm:('i is ',i printString,'; start over ?')) ifTrue:[ |
|
2728 |
restart value. |
|
2729 |
]. |
|
2730 |
(self confirm:'enough ?') ifTrue:[ |
|
2731 |
exit value:nil. |
|
2732 |
]. |
|
2733 |
] loop |
|
14683 | 2734 |
] valueWithRestartAndExit |
2735 |
" |
|
2736 |
! |
|
2737 |
||
623 | 2738 |
whileFalse |
2739 |
"evaluate the receiver while it evaluates to false (ST80 compatibility)" |
|
2740 |
||
2741 |
"this implementation is for purists ... :-)" |
|
2742 |
||
2743 |
self value ifTrue:[^ nil]. |
|
2744 |
thisContext restart |
|
2745 |
||
2746 |
" |
|
2747 |
|n| |
|
2748 |
||
2749 |
n := 1. |
|
8602 | 2750 |
[n printCR. (n := n + 1) > 10] whileFalse |
67 | 2751 |
" |
2752 |
! |
|
1 | 2753 |
|
67 | 2754 |
whileFalse:aBlock |
2755 |
"evaluate the argument, aBlock while the receiver evaluates to false. |
|
18252 | 2756 |
- usually open coded by compilers, but needed here for #perform |
67 | 2757 |
and expression evaluation." |
2758 |
||
154 | 2759 |
"this implementation is for purists ... :-)" |
2760 |
||
67 | 2761 |
self value ifTrue:[^ nil]. |
2762 |
aBlock value. |
|
2763 |
thisContext restart |
|
2764 |
||
2765 |
" |
|
2766 |
|n| |
|
2767 |
||
2768 |
n := 1. |
|
2769 |
[n > 10] whileFalse:[ |
|
18252 | 2770 |
n printCR. |
2771 |
n := n + 1 |
|
67 | 2772 |
] |
2773 |
" |
|
1 | 2774 |
! |
2775 |
||
2776 |
whileTrue |
|
67 | 2777 |
"evaluate the receiver while it evaluates to true (ST80 compatibility)" |
1 | 2778 |
|
154 | 2779 |
"this implementation is for purists ... :-)" |
2780 |
||
67 | 2781 |
self value ifFalse:[^ nil]. |
2782 |
thisContext restart |
|
1 | 2783 |
|
67 | 2784 |
" |
2785 |
|n| |
|
1 | 2786 |
|
67 | 2787 |
n := 1. |
8602 | 2788 |
[n printCR. (n := n + 1) <= 10] whileTrue |
67 | 2789 |
" |
1 | 2790 |
! |
2791 |
||
623 | 2792 |
whileTrue:aBlock |
2793 |
"evaluate the argument, aBlock while the receiver evaluates to true. |
|
18252 | 2794 |
- usually open coded by compilers, but needed here for #perform |
623 | 2795 |
and expression evaluation." |
1 | 2796 |
|
154 | 2797 |
"this implementation is for purists ... :-)" |
2798 |
||
623 | 2799 |
self value ifFalse:[^ nil]. |
2800 |
aBlock value. |
|
67 | 2801 |
thisContext restart |
2802 |
||
2803 |
" |
|
2804 |
|n| |
|
1 | 2805 |
|
67 | 2806 |
n := 1. |
623 | 2807 |
[n <= 10] whileTrue:[ |
18252 | 2808 |
n printCR. |
2809 |
n := n + 1 |
|
623 | 2810 |
] |
68 | 2811 |
" |
67 | 2812 |
! ! |
2813 |
||
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2814 |
!Block methodsFor:'parallel evaluation'! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2815 |
|
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2816 |
futureValue |
18252 | 2817 |
"Fork a synchronised evaluation of myself. |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2818 |
Starts the evaluation in parallel now, but synchronizes |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2819 |
any access to wait until the result is computed." |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2820 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2821 |
^ Future new block:self |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2822 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2823 |
|
18252 | 2824 |
futureValue:aValue |
2825 |
"Fork a synchronised evaluation of myself. |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2826 |
Starts the evaluation in parallel now, but synchronizes |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2827 |
any access to wait until the result is computed." |
18252 | 2828 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2829 |
^ Future new block:self value:aValue |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2830 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2831 |
|
18252 | 2832 |
futureValue:aValue value:anotherValue |
2833 |
"Fork a synchronised evaluation of myself. |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2834 |
Starts the evaluation in parallel now, but synchronizes |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2835 |
any access to wait until the result is computed." |
18252 | 2836 |
|
2837 |
^ Future new |
|
2838 |
block:self |
|
2839 |
value:aValue |
|
2840 |
value:anotherValue |
|
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2841 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2842 |
|
18252 | 2843 |
futureValue:aValue value:anotherValue value:bValue |
2844 |
"Fork a synchronised evaluation of myself. |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2845 |
Starts the evaluation in parallel now, but synchronizes |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2846 |
any access to wait until the result is computed." |
18252 | 2847 |
|
2848 |
^ Future new |
|
2849 |
block:self |
|
2850 |
value:aValue |
|
2851 |
value:anotherValue |
|
2852 |
value:bValue |
|
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2853 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2854 |
|
18252 | 2855 |
futureValueWithArguments:anArray |
2856 |
"Fork a synchronised evaluation of myself. |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2857 |
Starts the evaluation in parallel now, but synchronizes |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2858 |
any access to wait until the result is computed." |
18252 | 2859 |
|
2860 |
^ Future new |
|
2861 |
block:self |
|
2862 |
valueWithArguments:anArray |
|
13767 | 2863 |
|
2864 |
"Modified (format): / 04-10-2011 / 14:55:40 / cg" |
|
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2865 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2866 |
|
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2867 |
lazyValue |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2868 |
"Fork a synchronised evaluation of myself. Only starts |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2869 |
the evaluation when the result is requested." |
18252 | 2870 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2871 |
^ Lazy new block:self |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2872 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2873 |
|
18252 | 2874 |
lazyValue:aValue |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2875 |
"Fork a synchronised evaluation of myself. Only starts |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2876 |
the evaluation when the result is requested." |
18252 | 2877 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2878 |
^ Lazy new block:self value:aValue |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2879 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2880 |
|
18252 | 2881 |
lazyValue:aValue value:anotherValue |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2882 |
"Fork a synchronised evaluation of myself. Only starts |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2883 |
the evaluation when the result is requested." |
18252 | 2884 |
|
2885 |
^ Lazy new |
|
2886 |
block:self |
|
2887 |
value:aValue |
|
2888 |
value:anotherValue |
|
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2889 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2890 |
|
18252 | 2891 |
lazyValue:aValue value:anotherValue value:bValue |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2892 |
"Fork a synchronised evaluation of myself. Only starts |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2893 |
the evaluation when the result is requested." |
18252 | 2894 |
|
2895 |
^ Lazy new |
|
2896 |
block:self |
|
2897 |
value:aValue |
|
2898 |
value:anotherValue |
|
2899 |
value:bValue |
|
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2900 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2901 |
|
18252 | 2902 |
lazyValueWithArguments:anArray |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2903 |
"Fork a synchronised evaluation of myself. Only starts |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2904 |
the evaluation when the result is requested." |
18252 | 2905 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2906 |
^ Lazy new block:self valueWithArguments:anArray |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2907 |
! ! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2908 |
|
92 | 2909 |
!Block methodsFor:'printing & storing'! |
1 | 2910 |
|
7151 | 2911 |
printBlockBracketsOn:aStream |
18252 | 2912 |
aStream nextPutAll:'[]'. |
7151 | 2913 |
! |
2914 |
||
1 | 2915 |
printOn:aStream |
44 | 2916 |
"append a a printed representation of the block to aStream" |
2917 |
||
6633 | 2918 |
|h sel methodClass| |
54 | 2919 |
|
2920 |
"cheap blocks have no home context, but a method instead" |
|
2921 |
||
2922 |
(home isNil or:[home isContext not]) ifTrue:[ |
|
18252 | 2923 |
aStream nextPutAll:'[] in '. |
2924 |
||
2925 |
" |
|
2926 |
currently, some cheap blocks don't know where they have been created |
|
2927 |
" |
|
2928 |
aStream nextPutAll:' ??? (optimized)'. |
|
2929 |
^ self |
|
54 | 2930 |
]. |
2931 |
||
2932 |
"a full blown block (with home, but without method)" |
|
7151 | 2933 |
self printBlockBracketsOn:aStream. |
18252 | 2934 |
aStream nextPutAll:' in '. |
154 | 2935 |
h := self methodHome. |
2936 |
sel := h selector. |
|
2937 |
"/ old: |
|
2938 |
"/ home receiver class name printOn:aStream. |
|
2939 |
"/ new: |
|
212 | 2940 |
"/ (h searchClass whichClassImplements:sel) name printOn:aStream. |
213 | 2941 |
methodClass := h methodClass. |
2942 |
methodClass isNil ifTrue:[ |
|
18252 | 2943 |
'UnboundMethod' printOn:aStream. |
213 | 2944 |
] ifFalse:[ |
18252 | 2945 |
methodClass name printOn:aStream. |
213 | 2946 |
]. |
7157
935eaabbe6dc
printString now "... in className >> sel"
Claus Gittinger <cg@exept.de>
parents:
7151
diff
changeset
|
2947 |
aStream nextPutAll:'>>'. |
154 | 2948 |
sel printOn:aStream. |
54 | 2949 |
|
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2950 |
"/ |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2951 |
"/ aStream nextPutAll:'[] in '. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2952 |
"/ homeClass := home containingClass. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2953 |
"/ homeClass notNil ifTrue:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2954 |
"/ homeClass name printOn:aStream. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2955 |
"/ aStream space. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2956 |
"/ (homeClass selectorForMethod:home) printOn:aStream |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2957 |
"/ ] ifFalse:[ |
18252 | 2958 |
"/ aStream nextPutAll:' ???' |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2959 |
"/ ] |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2960 |
"/ |
9253 | 2961 |
! |
2962 |
||
2963 |
storeOn:aStream |
|
15850 | 2964 |
MethodNotAppropriateError raiseRequestErrorString:'Blocks cannot be stored (yet)'. |
9287 | 2965 |
self printOn:aStream. |
1 | 2966 |
! ! |
623 | 2967 |
|
7257 | 2968 |
!Block methodsFor:'private-accessing'! |
623 | 2969 |
|
5766
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
2970 |
byteCode:bCode numArgs:numArgs numVars:numVars numStack:numStack sourcePosition:srcPos initialPC:iPC literals:lits |
1265 | 2971 |
"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
|
2972 |
DANGER ALERT: this interface is strictly private." |
623 | 2973 |
|
2974 |
byteCode := bCode. |
|
2975 |
nargs := numArgs. |
|
2976 |
sourcePos := srcPos. |
|
2977 |
initialPC := iPC. |
|
1777 | 2978 |
flags := 0. |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
2979 |
self stackSize:numStack. |
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2980 |
self literals:lits. |
5766
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
2981 |
self numberOfArgs:numArgs. "/ must set the compiledCode flags as well |
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
2982 |
self numberOfVars:numVars. "/ must set the compiledCode flags as well |
1265 | 2983 |
|
2984 |
"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
|
2985 |
"Modified: 24.6.1996 / 12:37:37 / stefan" |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
2986 |
"Created: 13.4.1997 / 00:00:57 / cg" |
623 | 2987 |
! |
2988 |
||
18252 | 2989 |
initialPC |
5779 | 2990 |
"return the initial pc for evaluation." |
2991 |
||
2992 |
^ initialPC |
|
2993 |
! |
|
2994 |
||
18252 | 2995 |
initialPC:initial |
1265 | 2996 |
"set the initial pc for evaluation. |
2997 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 2998 |
|
2999 |
initialPC := initial |
|
1265 | 3000 |
|
3001 |
"Modified: 23.4.1996 / 16:05:39 / cg" |
|
623 | 3002 |
! |
3003 |
||
3004 |
numArgs:numArgs |
|
1265 | 3005 |
"set the number of arguments the receiver expects for evaluation. |
3006 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 3007 |
|
3008 |
nargs := numArgs |
|
1265 | 3009 |
|
3010 |
"Modified: 23.4.1996 / 16:05:52 / cg" |
|
623 | 3011 |
! |
3012 |
||
5744 | 3013 |
setHome:aContext |
3014 |
home := aContext |
|
3015 |
! |
|
3016 |
||
18252 | 3017 |
source |
7323 | 3018 |
|m| |
3019 |
||
3020 |
sourcePos isString ifTrue:[ "/ misuses the sourcePosition slot |
|
18252 | 3021 |
^ sourcePos |
7323 | 3022 |
]. |
3023 |
m := self method. |
|
3024 |
m notNil ifTrue:[ |
|
18252 | 3025 |
^ m source |
7323 | 3026 |
]. |
3027 |
^ nil |
|
3028 |
! |
|
3029 |
||
18252 | 3030 |
source:aString |
6981 | 3031 |
"set the source - only to be used, if the block is not contained in a method. |
3032 |
This interface is for knowledgable users only." |
|
3033 |
||
3034 |
sourcePos := aString "/ misuse the sourcePosition slot |
|
3035 |
! |
|
3036 |
||
18427
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3037 |
sourcePosition |
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3038 |
"Returns the source position withing method's source. |
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3039 |
The position is 1-based offset of opening bracket. |
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3040 |
If the source position is not known (because of lack of |
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3041 |
support in compiler and/or virtual machine or anut other |
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3042 |
reason, nil is returned" |
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3043 |
|
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3044 |
^ sourcePos |
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3045 |
|
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3046 |
"Created: / 01-06-2015 / 13:05:16 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3047 |
|
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3048 |
! |
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3049 |
|
18252 | 3050 |
sourcePosition:position |
1265 | 3051 |
"set the position of the source within my method. |
3052 |
This interface is for the compiler only." |
|
623 | 3053 |
|
3054 |
sourcePos := position |
|
1265 | 3055 |
|
3056 |
"Modified: 23.4.1996 / 16:06:19 / cg" |
|
623 | 3057 |
! ! |
3058 |
||
3059 |
!Block methodsFor:'privileged evaluation'! |
|
3060 |
||
3061 |
valueUninterruptably |
|
3062 |
"evaluate the receiver with interrupts blocked. |
|
3063 |
This does not prevent preemption by a higher priority processes |
|
3064 |
if any becomes runnable due to the evaluation of the receiver |
|
3065 |
(i.e. if a semaphore is signalled)." |
|
3066 |
||
2301 | 3067 |
"we must keep track of blocking-state if this is called nested" |
3068 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3069 |
"/ already blocked. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3070 |
^ self value |
2301 | 3071 |
]. |
864 | 3072 |
|
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3073 |
^ self ensure:[OperatingSystem unblockInterrupts]. |
623 | 3074 |
! |
3075 |
||
3076 |
valueUnpreemptively |
|
3077 |
"evaluate the receiver without the possiblity of preemption |
|
3078 |
(i.e. at a very high priority)" |
|
3079 |
||
3080 |
|oldPrio activeProcess| |
|
3081 |
||
3082 |
activeProcess := Processor activeProcess. |
|
3083 |
oldPrio := activeProcess changePriority:(Processor highestPriority). |
|
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3084 |
^ self ensure:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3085 |
activeProcess priority:oldPrio |
623 | 3086 |
] |
3087 |
! ! |
|
3088 |
||
3089 |
!Block methodsFor:'process creation'! |
|
3090 |
||
3091 |
fork |
|
3092 |
"create a new process executing the receiver at the current priority." |
|
3093 |
||
3094 |
^ self newProcess resume |
|
3095 |
! |
|
3096 |
||
3097 |
forkAt:priority |
|
3098 |
"create a new process executing the receiver at a different priority." |
|
3099 |
||
3100 |
^ (self newProcess priority:priority) resume |
|
3101 |
! |
|
3102 |
||
6609 | 3103 |
forkNamed:aString |
18252 | 3104 |
"create a new process, give it a name and let it start |
6609 | 3105 |
executing the receiver at the current priority." |
3106 |
||
3107 |
|newProcess| |
|
3108 |
||
18252 | 3109 |
newProcess := self newProcess. |
6609 | 3110 |
newProcess name:aString. |
3111 |
newProcess resume. |
|
3112 |
^ newProcess. |
|
3113 |
! |
|
3114 |
||
623 | 3115 |
forkWith:argArray |
3116 |
"create a new process executing the receiver, |
|
3117 |
passing elements in argArray as arguments to the receiver block." |
|
3118 |
||
3119 |
^ [self valueWithArguments:argArray] fork. |
|
3120 |
! |
|
3121 |
||
3122 |
newProcess |
|
3123 |
"create a new (unscheduled) process executing the receiver" |
|
3124 |
||
3125 |
^ Process for:self priority:(Processor activePriority) |
|
3126 |
! |
|
3127 |
||
3128 |
newProcessWithArguments:argArray |
|
3129 |
"create a new (unscheduled) process executing the receiver, |
|
3130 |
passing the elements in argArray as arguments to the receiver block." |
|
3131 |
||
3132 |
^ [self valueWithArguments:argArray] newProcess |
|
3133 |
! |
|
3134 |
||
3135 |
promise |
|
3136 |
"create a promise on the receiver. The promise will evaluate the |
|
3137 |
receiver and promise to return the value with the #value message. |
|
3138 |
The evaluation will be performed as a separate process. |
|
3139 |
Asking the promise for its value will either block the asking process |
|
3140 |
(if the evaluation has not yet been finished) or return the value |
|
3141 |
immediately." |
|
3142 |
||
3143 |
^ Promise value:self |
|
3144 |
||
3145 |
" |
|
3146 |
|p| |
|
3147 |
||
3148 |
p := [1000 factorial] promise. |
|
3149 |
'do something else ...'. |
|
3150 |
p value |
|
3151 |
" |
|
3152 |
! |
|
3153 |
||
3154 |
promiseAt:prio |
|
3155 |
"create a promise on the receiver. The promise will evaluate the |
|
3156 |
receiver and promise to return the value with the #value message. |
|
3157 |
The evaluation will be performed as a separate process running at prio. |
|
3158 |
Asking the promise for its value will either block the asking process |
|
3159 |
(if the evaluation has not yet been finished) or return the value |
|
3160 |
immediately." |
|
3161 |
||
3162 |
^ Promise value:self priority:prio |
|
3163 |
! ! |
|
3164 |
||
3165 |
!Block methodsFor:'testing'! |
|
3166 |
||
3167 |
isBlock |
|
3168 |
"return true, if this is a block - yes I am" |
|
3169 |
||
3170 |
^ true |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3171 |
! |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3172 |
|
16276 | 3173 |
isCheapBlock |
3174 |
^ false |
|
3175 |
! |
|
3176 |
||
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3177 |
isVarArgBlock |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3178 |
"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
|
3179 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3180 |
^ false |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3181 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3182 |
"Created: 23.1.1997 / 04:59:51 / cg" |
623 | 3183 |
! ! |
3184 |
||
3185 |
!Block methodsFor:'unwinding'! |
|
3186 |
||
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3187 |
unwindHandlerInContext:aContext |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3188 |
"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
|
3189 |
retrieve the handler block. |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3190 |
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
|
3191 |
#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
|
3192 |
methods to be added)" |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3193 |
|
11338 | 3194 |
|selector| |
3195 |
||
3196 |
selector := aContext selector. |
|
3197 |
selector == #'value:onUnwindDo:' ifTrue:[ |
|
18959 | 3198 |
^ aContext argAt:2 |
4896 | 3199 |
]. |
18959 | 3200 |
(selector == #'on:do:ensure:' |
3201 |
or:[selector == #'on:do:ifCurtailed:'])ifTrue:[ |
|
3202 |
^ aContext argAt:3 |
|
11338 | 3203 |
]. |
4896 | 3204 |
|
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3205 |
"/ for now, only #valueNowOrOnUnwindDo: |
4896 | 3206 |
"/ or #valueOnUnwindDo: |
5666
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
3207 |
"/ or #ensure: |
6608 | 3208 |
"/ or #ifCurtailed: |
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3209 |
|
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3210 |
^ aContext argAt:1 |
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3211 |
! ! |
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3212 |
|
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3213 |
!Block methodsFor:'unwinding-old'! |
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3214 |
|
4896 | 3215 |
value:arg onUnwindDo:aBlock |
3216 |
"evaluate the receiver, passing it one argument |
|
3217 |
- when some method sent within unwinds (i.e. does |
|
3218 |
a long return), evaluate the argument, aBlock. |
|
3219 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
3220 |
executed regardless of error actions" |
|
3221 |
||
3222 |
<exception: #unwind> |
|
3223 |
||
3224 |
|v| |
|
3225 |
||
3226 |
"/ thisContext markForUnwind. -- same as above pragma |
|
3227 |
v := self value:arg. "the real logic is in Context>>unwind" |
|
3228 |
thisContext unmarkForUnwind. |
|
3229 |
^ v |
|
3230 |
||
3231 |
" |
|
3232 |
|s| |
|
3233 |
||
3234 |
s := 'Makefile' asFilename readStream. |
|
3235 |
[:arg | |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3236 |
^ self |
4896 | 3237 |
] value:12345 onUnwindDo:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3238 |
Transcript showCR:'closing the stream - even though a return occurred'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3239 |
s close |
4896 | 3240 |
] |
3241 |
" |
|
3242 |
" |
|
3243 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3244 |
|s| |
4896 | 3245 |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3246 |
s := 'Makefile' asFilename readStream. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3247 |
[:arg | |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3248 |
Processor activeProcess terminate |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3249 |
] value:12345 onUnwindDo:[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3250 |
Transcript showCR:'closing the stream - even though process was terminated'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3251 |
s close |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3252 |
] |
4896 | 3253 |
] fork |
3254 |
" |
|
3255 |
||
3256 |
! |
|
3257 |
||
623 | 3258 |
valueNowOrOnUnwindDo:aBlock |
3259 |
"evaluate the receiver - after that, or when some method sent within unwinds (i.e. does |
|
3260 |
a long return), evaluate the argument, aBlock. |
|
3261 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3262 |
executed regardless of error actions. |
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3263 |
Same as the more modern #ensure:" |
623 | 3264 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
3265 |
<exception: #unwind> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
3266 |
|
623 | 3267 |
|v| |
3268 |
||
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
3269 |
"/ thisContext markForUnwind. -- same as above pragma |
623 | 3270 |
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
|
3271 |
thisContext unmarkForUnwind. |
623 | 3272 |
aBlock value. |
3273 |
^ v |
|
3274 |
||
3275 |
" |
|
3276 |
in the following example, f will be closed even if the block |
|
3277 |
returns with 'oops'. There are many more applications of this kind |
|
3278 |
found in the system. |
|
3279 |
" |
|
3280 |
" |
|
3281 |
|f| |
|
3282 |
||
3283 |
f := 'Makefile' asFilename readStream. |
|
3284 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3285 |
l := f nextLine. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3286 |
l isNil ifTrue:[^ 'oops'] |
623 | 3287 |
] valueNowOrOnUnwindDo:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3288 |
f close |
623 | 3289 |
] |
3290 |
" |
|
1187
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
3291 |
|
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
3292 |
"Modified: 16.4.1996 / 11:05:26 / stefan" |
623 | 3293 |
! |
3294 |
||
3295 |
valueOnUnwindDo:aBlock |
|
3296 |
"evaluate the receiver - when some method sent within unwinds (i.e. does |
|
3297 |
a long return), evaluate the argument, aBlock. |
|
3298 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3299 |
executed regardless of error actions |
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3300 |
Same as the more modern #ifCurtailed:" |
623 | 3301 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
3302 |
<exception: #unwind> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
3303 |
|
2286 | 3304 |
|v| |
3305 |
||
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
3306 |
"/ thisContext markForUnwind. -- same as above pragma |
2286 | 3307 |
v := self value. "the real logic is in Context>>unwind" |
3308 |
thisContext unmarkForUnwind. |
|
3309 |
^ v |
|
3310 |
||
4896 | 3311 |
" |
3312 |
|s| |
|
3313 |
||
3314 |
s := 'Makefile' asFilename readStream. |
|
3315 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3316 |
^ self |
4896 | 3317 |
] valueOnUnwindDo:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3318 |
Transcript showCR:'closing the stream - even though a return occurred'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3319 |
s close |
4896 | 3320 |
] |
3321 |
" |
|
3322 |
" |
|
3323 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3324 |
|s| |
4896 | 3325 |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3326 |
s := 'Makefile' asFilename readStream. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3327 |
[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3328 |
Processor activeProcess terminate |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3329 |
] valueOnUnwindDo:[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3330 |
Transcript showCR:'closing the stream - even though process was terminated'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3331 |
s close |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3332 |
] |
4896 | 3333 |
] fork |
3334 |
" |
|
623 | 3335 |
! ! |
3336 |
||
8394
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3337 |
!Block methodsFor:'visiting'! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3338 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3339 |
acceptVisitor:aVisitor with:aParameter |
16730 | 3340 |
"dispatch for visitor pattern; send #visitBlock:with: to aVisitor" |
8394
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3341 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3342 |
^ aVisitor visitBlock:self with:aParameter |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3343 |
! ! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3344 |
|
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
3345 |
!Block class methodsFor:'documentation'! |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3346 |
|
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3347 |
version |
18959 | 3348 |
^ '$Header$' |
12118
41ee8ff1908e
comment/format in: #deferredValue
Claus Gittinger <cg@exept.de>
parents:
11998
diff
changeset
|
3349 |
! |
41ee8ff1908e
comment/format in: #deferredValue
Claus Gittinger <cg@exept.de>
parents:
11998
diff
changeset
|
3350 |
|
41ee8ff1908e
comment/format in: #deferredValue
Claus Gittinger <cg@exept.de>
parents:
11998
diff
changeset
|
3351 |
version_CVS |
18959 | 3352 |
^ '$Header$' |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3353 |
! ! |
6785 | 3354 |
|
14683 | 3355 |
|
623 | 3356 |
Block initialize! |