author | Merge Script |
Fri, 27 Nov 2015 06:55:43 +0100 | |
branch | jv |
changeset 18960 | 6e6225b7a7d9 |
parent 18442 | bd42fa983e3f |
parent 18959 | 59de21f18945 |
child 18995 | 05e03473f406 |
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: |
530 |
Evaluate the recevier block and return its value, if no error occurs. |
|
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; |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
534 |
2 args -> the errorString and the erronous receiver)" |
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 |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
685 |
"return the receivers home context (the context where it was |
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 |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
692 |
"return the receivers home method. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
693 |
Thats the method where the block was created." |
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:[ |
18252 | 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 |
18252 | 709 |
"return the receivers 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 |
||
851 |
|startTime endTime micros millis| |
|
852 |
||
853 |
startTime := OperatingSystem getMicrosecondTime. |
|
854 |
self value. |
|
855 |
endTime := OperatingSystem getMicrosecondTime. |
|
856 |
||
857 |
micros := endTime - startTime. |
|
858 |
||
859 |
Transcript show:anInfoString. |
|
17338 | 860 |
micros < 1000 ifTrue:[ |
18959 | 861 |
Transcript show:micros; show:' µs'. |
16871 | 862 |
] ifFalse:[ |
18252 | 863 |
micros < 100000 ifTrue:[ |
864 |
millis := (micros / 1000.0) asFixedPointRoundedToScale:2. |
|
865 |
Transcript show:millis; show:' ms'. |
|
866 |
] ifFalse:[ |
|
867 |
millis := micros // 1000. |
|
868 |
Transcript show:(TimeDuration milliseconds:millis). |
|
869 |
]. |
|
16871 | 870 |
]. |
871 |
Transcript cr. |
|
872 |
||
873 |
" |
|
18252 | 874 |
[10 factorial] benchmark:'10 factorial:' |
875 |
[100 factorial] benchmark:'100 factorial:' |
|
16871 | 876 |
" |
877 |
! ! |
|
878 |
||
1 | 879 |
!Block methodsFor:'error handling'! |
880 |
||
328 | 881 |
invalidCodeObject |
1874 | 882 |
"{ Pragma: +optSpace }" |
883 |
||
67 | 884 |
"this error is triggered by the interpreter when a non-Block object |
885 |
is about to be executed. |
|
886 |
In this case, the VM sends this to the bad method (the receiver). |
|
887 |
Can only happen when the Compiler/runtime system is broken or |
|
888 |
someone played around." |
|
1 | 889 |
|
7602
d048f13cd50a
Exception classes initialize themself.
Stefan Vogel <sv@exept.de>
parents:
7352
diff
changeset
|
890 |
^ InvalidCodeError |
18252 | 891 |
raiseRequestWith:self |
892 |
errorString:'invalid block - not executable' |
|
1874 | 893 |
|
894 |
"Modified: 4.11.1996 / 22:46:39 / cg" |
|
1 | 895 |
! ! |
896 |
||
897 |
!Block methodsFor:'evaluation'! |
|
898 |
||
899 |
value |
|
18252 | 900 |
"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
|
901 |
The receiver must be a block without arguments." |
1 | 902 |
|
903 |
%{ /* NOCONTEXT */ |
|
18252 | 904 |
#ifdef __SCHTEAM__ |
905 |
return context.TAILCALL0( self.asSTCallable() ); |
|
906 |
/* NOTREACHED */ |
|
907 |
#else |
|
1 | 908 |
REGISTER OBJFUNC thecode; |
909 |
OBJ home; |
|
910 |
||
8913 | 911 |
if (__INST(nargs) == __mkSmallInteger(0)) { |
18252 | 912 |
# if defined(THIS_CONTEXT) |
913 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
914 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
915 |
# endif |
|
916 |
||
917 |
thecode = __BlockInstPtr(self)->b_code; |
|
918 |
# ifdef NEW_BLOCK_CALL |
|
919 |
if (thecode != (OBJFUNC)nil) { |
|
920 |
/* compiled machine code */ |
|
921 |
RETURN ( (*thecode)(self) ); |
|
922 |
} |
|
923 |
/* interpreted code */ |
|
924 |
# ifdef PASS_ARG_POINTER |
|
925 |
RETURN ( __interpret(self, 0, nil, nil, nil, nil) ); |
|
926 |
# else |
|
927 |
RETURN ( __interpret(self, 0, nil, nil, nil, nil) ); |
|
928 |
# endif |
|
328 | 929 |
# else |
18252 | 930 |
home = __BlockInstPtr(self)->b_home; |
931 |
if (thecode != (OBJFUNC)nil) { |
|
932 |
/* compiled machine code */ |
|
933 |
RETURN ( (*thecode)(home) ); |
|
934 |
} |
|
935 |
/* interpreted code */ |
|
936 |
# ifdef PASS_ARG_POINTER |
|
937 |
RETURN ( __interpret(self, 0, nil, home, nil, nil) ); |
|
938 |
# else |
|
939 |
RETURN ( __interpret(self, 0, nil, home, nil, nil) ); |
|
940 |
# endif |
|
328 | 941 |
# endif |
1 | 942 |
} |
18252 | 943 |
#endif /* not SCHTEAM */ |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
944 |
%}. |
103 | 945 |
^ self wrongNumberOfArguments:0 |
1 | 946 |
! |
947 |
||
948 |
value:arg |
|
18252 | 949 |
"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
|
950 |
The receiver must be a 1-arg block." |
1 | 951 |
|
952 |
%{ /* NOCONTEXT */ |
|
18252 | 953 |
#ifdef __SCHTEAM__ |
954 |
return context.TAILCALL1( self.asSTCallable(), arg ); |
|
955 |
/* NOTREACHED */ |
|
956 |
#else |
|
1 | 957 |
|
958 |
REGISTER OBJFUNC thecode; |
|
959 |
OBJ home; |
|
960 |
||
8913 | 961 |
if (__INST(nargs) == __mkSmallInteger(1)) { |
18252 | 962 |
# if defined(THIS_CONTEXT) |
963 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
964 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
965 |
# endif |
|
966 |
thecode = __BlockInstPtr(self)->b_code; |
|
967 |
# ifdef NEW_BLOCK_CALL |
|
968 |
if (thecode != (OBJFUNC)nil) { |
|
969 |
RETURN ( (*thecode)(self, arg) ); |
|
970 |
} |
|
971 |
/* interpreted code */ |
|
972 |
# ifdef PASS_ARG_POINTER |
|
973 |
RETURN ( __interpret(self, 1, nil, nil, nil, nil, &arg) ); |
|
974 |
# else |
|
975 |
RETURN ( __interpret(self, 1, nil, nil, nil, nil, arg) ); |
|
976 |
# endif |
|
328 | 977 |
# else |
18252 | 978 |
home = __BlockInstPtr(self)->b_home; |
979 |
if (thecode != (OBJFUNC)nil) { |
|
980 |
RETURN ( (*thecode)(home, arg) ); |
|
981 |
} |
|
982 |
/* interpreted code */ |
|
983 |
# ifdef PASS_ARG_POINTER |
|
984 |
RETURN ( __interpret(self, 1, nil, home, nil, nil, &arg) ); |
|
985 |
# else |
|
986 |
RETURN ( __interpret(self, 1, nil, home, nil, nil, arg) ); |
|
987 |
# endif |
|
328 | 988 |
# endif |
1 | 989 |
} |
18252 | 990 |
#endif /* not SCHTEAM */ |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
991 |
%}. |
103 | 992 |
^ self wrongNumberOfArguments:1 |
1 | 993 |
! |
994 |
||
11998 | 995 |
value:arg1 optionalArgument:arg2 |
996 |
"evaluate the receiver. |
|
997 |
Optionally pass up one or to two arguments (if the receiver is a one/two arg block)." |
|
998 |
||
999 |
nargs == 2 ifTrue:[ |
|
18252 | 1000 |
^ self value:arg1 value:arg2 |
11998 | 1001 |
]. |
1002 |
^ self value:arg1 |
|
1003 |
||
1004 |
" |
|
1005 |
|block| |
|
1006 |
||
1007 |
block := [:arg | Transcript showCR:arg ]. |
|
18252 | 1008 |
block value:2 optionalArgument:3. |
11998 | 1009 |
|
1010 |
block := [:arg1 :arg2 | Transcript show:arg1; space; showCR:arg2 ]. |
|
18252 | 1011 |
block value:2 optionalArgument:3. |
11998 | 1012 |
" |
1013 |
! |
|
1014 |
||
1015 |
value:arg1 optionalArgument:arg2 and:arg3 |
|
1016 |
"evaluate the receiver. |
|
1017 |
Optionally pass up one, two or three arguments (if the receiver is a 1/2/3-arg block)." |
|
1018 |
||
1019 |
nargs == 3 ifTrue:[ |
|
18252 | 1020 |
^ self value:arg1 value:arg2 value:arg3 |
11998 | 1021 |
]. |
1022 |
nargs == 2 ifTrue:[ |
|
18252 | 1023 |
^ self value:arg1 value:arg2 |
11998 | 1024 |
]. |
1025 |
^ self value:arg1 |
|
1026 |
||
1027 |
" |
|
1028 |
|block| |
|
1029 |
||
1030 |
block := [:arg | Transcript showCR:arg ]. |
|
18252 | 1031 |
block value:2 optionalArgument:3. |
11998 | 1032 |
|
1033 |
block := [:arg1 :arg2 | Transcript show:arg1; space; showCR:arg2 ]. |
|
18252 | 1034 |
block value:2 optionalArgument:3. |
11998 | 1035 |
" |
1036 |
! |
|
1037 |
||
1 | 1038 |
value:arg1 value:arg2 |
18252 | 1039 |
"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
|
1040 |
The receiver must be a 2-arg block." |
1 | 1041 |
|
1042 |
%{ /* NOCONTEXT */ |
|
18252 | 1043 |
#ifdef __SCHTEAM__ |
1044 |
return context.TAILCALL2( self.asSTCallable(), arg1, arg2 ); |
|
1045 |
/* NOTREACHED */ |
|
1046 |
#else |
|
1 | 1047 |
|
1048 |
REGISTER OBJFUNC thecode; |
|
1049 |
OBJ home; |
|
1050 |
||
8913 | 1051 |
if (__INST(nargs) == __mkSmallInteger(2)) { |
18252 | 1052 |
# if defined(THIS_CONTEXT) |
1053 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
1054 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1055 |
# endif |
|
1056 |
thecode = __BlockInstPtr(self)->b_code; |
|
1057 |
# ifdef NEW_BLOCK_CALL |
|
1058 |
if (thecode != (OBJFUNC)nil) { |
|
1059 |
RETURN ( (*thecode)(self, arg1, arg2) ); |
|
1060 |
} |
|
1061 |
# ifdef PASS_ARG_POINTER |
|
1062 |
RETURN ( __interpret(self, 2, nil, nil, nil, nil, &arg1) ); |
|
1063 |
# else |
|
1064 |
RETURN ( __interpret(self, 2, nil, nil, nil, nil, arg1, arg2) ); |
|
1065 |
# endif |
|
328 | 1066 |
# else |
18252 | 1067 |
home = __BlockInstPtr(self)->b_home; |
1068 |
if (thecode != (OBJFUNC)nil) { |
|
1069 |
RETURN ( (*thecode)(home, arg1, arg2) ); |
|
1070 |
} |
|
1071 |
# ifdef PASS_ARG_POINTER |
|
1072 |
RETURN ( __interpret(self, 2, nil, home, nil, nil, &arg1) ); |
|
1073 |
# else |
|
1074 |
RETURN ( __interpret(self, 2, nil, home, nil, nil, arg1, arg2) ); |
|
1075 |
# endif |
|
328 | 1076 |
# endif |
1 | 1077 |
} |
18252 | 1078 |
#endif /* not SCHTEAM */ |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1079 |
%}. |
103 | 1080 |
^ self wrongNumberOfArguments:2 |
1 | 1081 |
! |
1082 |
||
11998 | 1083 |
value:arg1 value:arg2 optionalArgument:arg3 |
1084 |
"evaluate the receiver. |
|
1085 |
Optionally pass two or threearguments (if the receiver is a 2/3-arg block)." |
|
1086 |
||
1087 |
nargs == 3 ifTrue:[ |
|
18252 | 1088 |
^ self value:arg1 value:arg2 value:arg3 |
11998 | 1089 |
]. |
1090 |
^ self value:arg1 value:arg2 |
|
1091 |
! |
|
1092 |
||
1 | 1093 |
value:arg1 value:arg2 value:arg3 |
18252 | 1094 |
"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
|
1095 |
The receiver must be a 3-arg block." |
1 | 1096 |
|
1097 |
%{ /* NOCONTEXT */ |
|
18252 | 1098 |
#ifdef __SCHTEAM__ |
1099 |
return context.TAILCALL3( self.asSTCallable(), arg1, arg2, arg3 ); |
|
1100 |
/* NOTREACHED */ |
|
1101 |
#else |
|
1 | 1102 |
|
1103 |
REGISTER OBJFUNC thecode; |
|
1104 |
OBJ home; |
|
1105 |
||
8913 | 1106 |
if (__INST(nargs) == __mkSmallInteger(3)) { |
18252 | 1107 |
# if defined(THIS_CONTEXT) |
1108 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
1109 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1110 |
# endif |
|
1111 |
thecode = __BlockInstPtr(self)->b_code; |
|
1112 |
# ifdef NEW_BLOCK_CALL |
|
1113 |
if (thecode != (OBJFUNC)nil) { |
|
1114 |
RETURN ( (*thecode)(self, arg1, arg2, arg3) ); |
|
1115 |
} |
|
1116 |
# ifdef PASS_ARG_POINTER |
|
1117 |
RETURN ( __interpret(self, 3, nil, nil, nil, nil, &arg1) ); |
|
1118 |
# else |
|
1119 |
RETURN ( __interpret(self, 3, nil, nil, nil, nil, arg1, arg2, arg3) ); |
|
1120 |
# endif |
|
328 | 1121 |
# else |
18252 | 1122 |
home = __BlockInstPtr(self)->b_home; |
1123 |
if (thecode != (OBJFUNC)nil) { |
|
1124 |
RETURN ( (*thecode)(home, arg1, arg2, arg3) ); |
|
1125 |
} |
|
1126 |
# ifdef PASS_ARG_POINTER |
|
1127 |
RETURN ( __interpret(self, 3, nil, home, nil, nil, &arg1) ); |
|
1128 |
# else |
|
1129 |
RETURN ( __interpret(self, 3, nil, home, nil, nil, arg1, arg2, arg3) ); |
|
1130 |
# endif |
|
328 | 1131 |
# endif |
1 | 1132 |
} |
18252 | 1133 |
#endif /* not SCHTEAM */ |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1134 |
%}. |
103 | 1135 |
^ self wrongNumberOfArguments:3 |
1 | 1136 |
! |
1137 |
||
1138 |
value:arg1 value:arg2 value:arg3 value:arg4 |
|
18252 | 1139 |
"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
|
1140 |
The receiver must be a 4-arg block." |
1 | 1141 |
|
1142 |
%{ /* NOCONTEXT */ |
|
18252 | 1143 |
#ifdef __SCHTEAM__ |
1144 |
return context.TAILCALL4( self.asSTCallable(), arg1, arg2, arg3, arg4 ); |
|
1145 |
/* NOTREACHED */ |
|
1146 |
#else |
|
1 | 1147 |
|
1148 |
REGISTER OBJFUNC thecode; |
|
1149 |
OBJ home; |
|
1150 |
||
8913 | 1151 |
if (__INST(nargs) == __mkSmallInteger(4)) { |
18252 | 1152 |
# if defined(THIS_CONTEXT) |
1153 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
1154 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1155 |
# endif |
|
1156 |
thecode = __BlockInstPtr(self)->b_code; |
|
1157 |
# ifdef NEW_BLOCK_CALL |
|
1158 |
if (thecode != (OBJFUNC)nil) { |
|
1159 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4) ); |
|
1160 |
} |
|
1161 |
# ifdef PASS_ARG_POINTER |
|
1162 |
RETURN ( __interpret(self, 4, nil, nil, nil, nil, &arg1) ); |
|
1163 |
# else |
|
1164 |
RETURN ( __interpret(self, 4, nil, nil, nil, nil, arg1, arg2, arg3, arg4) ); |
|
1165 |
# endif |
|
328 | 1166 |
# else |
18252 | 1167 |
home = __BlockInstPtr(self)->b_home; |
1168 |
if (thecode != (OBJFUNC)nil) { |
|
1169 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4) ); |
|
1170 |
} |
|
1171 |
# ifdef PASS_ARG_POINTER |
|
1172 |
RETURN ( __interpret(self, 4, nil, home, nil, nil, &arg1) ); |
|
1173 |
# else |
|
1174 |
RETURN ( __interpret(self, 4, nil, home, nil, nil, arg1, arg2, arg3, arg4) ); |
|
1175 |
# endif |
|
328 | 1176 |
# endif |
18252 | 1177 |
} |
1 | 1178 |
#endif |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1179 |
%}. |
103 | 1180 |
^ self wrongNumberOfArguments:4 |
1 | 1181 |
! |
1182 |
||
1183 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 |
|
18252 | 1184 |
"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
|
1185 |
The receiver must be a 5-arg block." |
1 | 1186 |
|
1187 |
%{ /* NOCONTEXT */ |
|
18252 | 1188 |
#ifdef __SCHTEAM__ |
1189 |
return context.TAILCALL5( self.asSTCallable(), arg1, arg2, arg3, arg4, arg5 ); |
|
1190 |
/* NOTREACHED */ |
|
1191 |
#else |
|
1 | 1192 |
|
1193 |
REGISTER OBJFUNC thecode; |
|
1194 |
OBJ home; |
|
1195 |
||
8913 | 1196 |
if (__INST(nargs) == __mkSmallInteger(5)) { |
18252 | 1197 |
# if defined(THIS_CONTEXT) |
1198 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
1199 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1200 |
# endif |
|
1201 |
thecode = __BlockInstPtr(self)->b_code; |
|
1202 |
# ifdef NEW_BLOCK_CALL |
|
1203 |
if (thecode != (OBJFUNC)nil) { |
|
1204 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5) ); |
|
1205 |
} |
|
1206 |
# ifdef PASS_ARG_POINTER |
|
1207 |
RETURN ( __interpret(self, 5, nil, nil, nil, nil, &arg1) ); |
|
1208 |
# else |
|
1209 |
RETURN ( __interpret(self, 5, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5) ); |
|
1210 |
# endif |
|
328 | 1211 |
# else |
18252 | 1212 |
home = __BlockInstPtr(self)->b_home; |
1213 |
if (thecode != (OBJFUNC)nil) { |
|
1214 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5) ); |
|
1215 |
} |
|
1216 |
# ifdef PASS_ARG_POINTER |
|
1217 |
RETURN ( __interpret(self, 5, nil, home, nil, nil, &arg1) ); |
|
1218 |
# else |
|
1219 |
RETURN ( __interpret(self, 5, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5) ); |
|
1220 |
# endif |
|
328 | 1221 |
# endif |
1 | 1222 |
} |
18252 | 1223 |
#endif /* not SCHTEAM */ |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1224 |
%}. |
103 | 1225 |
^ self wrongNumberOfArguments:5 |
1 | 1226 |
! |
1227 |
||
1228 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 |
|
18252 | 1229 |
"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
|
1230 |
The receiver must be a 6-arg block." |
1 | 1231 |
|
1232 |
%{ /* NOCONTEXT */ |
|
18252 | 1233 |
#ifdef __SCHTEAM__ |
1234 |
return context.TAILCALL6( self.asSTCallable(), arg1, arg2, arg3, arg4, arg5, arg6 ); |
|
1235 |
/* NOTREACHED */ |
|
1236 |
#else |
|
1 | 1237 |
|
1238 |
REGISTER OBJFUNC thecode; |
|
1239 |
OBJ home; |
|
1240 |
||
8913 | 1241 |
if (__INST(nargs) == __mkSmallInteger(6)) { |
18252 | 1242 |
# if defined(THIS_CONTEXT) |
1243 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
1244 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1245 |
# endif |
|
1246 |
thecode = __BlockInstPtr(self)->b_code; |
|
1247 |
# ifdef NEW_BLOCK_CALL |
|
1248 |
if (thecode != (OBJFUNC)nil) { |
|
1249 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
1250 |
} |
|
1251 |
# ifdef PASS_ARG_POINTER |
|
1252 |
RETURN ( __interpret(self, 6, nil, nil, nil, nil, &arg1) ); |
|
1253 |
# else |
|
1254 |
RETURN ( __interpret(self, 6, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
1255 |
# endif |
|
328 | 1256 |
# else |
18252 | 1257 |
home = __BlockInstPtr(self)->b_home; |
1258 |
if (thecode != (OBJFUNC)nil) { |
|
1259 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
1260 |
} |
|
1261 |
# ifdef PASS_ARG_POINTER |
|
1262 |
RETURN ( __interpret(self, 6, nil, home, nil, nil, &arg1) ); |
|
1263 |
# else |
|
1264 |
RETURN ( __interpret(self, 6, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
1265 |
# endif |
|
328 | 1266 |
# endif |
1 | 1267 |
} |
18252 | 1268 |
#endif /* not SCHTEAM */ |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1269 |
%}. |
103 | 1270 |
^ self wrongNumberOfArguments:6 |
1 | 1271 |
! |
1272 |
||
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1273 |
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
|
1274 |
"evaluate the receiver with seven arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1275 |
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
|
1276 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1277 |
%{ /* NOCONTEXT */ |
18252 | 1278 |
#ifdef __SCHTEAM__ |
1279 |
return context.TAILCALL7( self.asSTCallable(), arg1, arg2, arg3, arg4, arg5, arg6, arg7 ); |
|
1280 |
/* NOTREACHED */ |
|
1281 |
#else |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1282 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1283 |
REGISTER OBJFUNC thecode; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1284 |
OBJ home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1285 |
|
8913 | 1286 |
if (__INST(nargs) == __mkSmallInteger(7)) { |
18252 | 1287 |
# if defined(THIS_CONTEXT) |
1288 |
if (__ISVALID_ILC_LNO(__pilc)) |
|
1289 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1290 |
# endif |
|
1291 |
thecode = __BlockInstPtr(self)->b_code; |
|
1292 |
# ifdef NEW_BLOCK_CALL |
|
1293 |
if (thecode != (OBJFUNC)nil) { |
|
1294 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
1295 |
} |
|
1296 |
# ifdef PASS_ARG_POINTER |
|
1297 |
RETURN ( __interpret(self, 7, nil, nil, nil, nil, &arg1) ); |
|
1298 |
# else |
|
1299 |
RETURN ( __interpret(self, 7, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
1300 |
# endif |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1301 |
# else |
18252 | 1302 |
home = __BlockInstPtr(self)->b_home; |
1303 |
if (thecode != (OBJFUNC)nil) { |
|
1304 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
1305 |
} |
|
1306 |
# ifdef PASS_ARG_POINTER |
|
1307 |
RETURN ( __interpret(self, 7, nil, home, nil, nil, &arg1) ); |
|
1308 |
# else |
|
1309 |
RETURN ( __interpret(self, 7, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
1310 |
# endif |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1311 |
# endif |
18252 | 1312 |
} |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1313 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1314 |
%}. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1315 |
^ self wrongNumberOfArguments:7 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1316 |
! |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1317 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1318 |
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
|
1319 |
"evaluate the receiver with eight arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1320 |
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
|
1321 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1322 |
%{ /* NOCONTEXT */ |
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 |
REGISTER OBJFUNC thecode; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1325 |
OBJ home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1326 |
|
8913 | 1327 |
if (__INST(nargs) == __mkSmallInteger(8)) { |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1328 |
#if defined(THIS_CONTEXT) |
18252 | 1329 |
if (__ISVALID_ILC_LNO(__pilc)) |
1330 |
__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
|
1331 |
#endif |
18252 | 1332 |
thecode = __BlockInstPtr(self)->b_code; |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1333 |
#ifdef NEW_BLOCK_CALL |
18252 | 1334 |
if (thecode != (OBJFUNC)nil) { |
1335 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
|
1336 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1337 |
# ifdef PASS_ARG_POINTER |
18252 | 1338 |
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
|
1339 |
# else |
18252 | 1340 |
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
|
1341 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1342 |
#else |
18252 | 1343 |
home = __BlockInstPtr(self)->b_home; |
1344 |
if (thecode != (OBJFUNC)nil) { |
|
1345 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
|
1346 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1347 |
# ifdef PASS_ARG_POINTER |
18252 | 1348 |
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
|
1349 |
# else |
18252 | 1350 |
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
|
1351 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1352 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1353 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1354 |
%}. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1355 |
^ self wrongNumberOfArguments:8 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1356 |
! |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1357 |
|
11588 | 1358 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8 value:arg9 |
11603 | 1359 |
"evaluate the receiver with 9 arguments. |
1360 |
The receiver must be a 9-arg block." |
|
11588 | 1361 |
|
1362 |
%{ /* NOCONTEXT */ |
|
1363 |
||
1364 |
REGISTER OBJFUNC thecode; |
|
1365 |
OBJ home; |
|
1366 |
||
1367 |
if (__INST(nargs) == __mkSmallInteger(9)) { |
|
1368 |
#if defined(THIS_CONTEXT) |
|
18252 | 1369 |
if (__ISVALID_ILC_LNO(__pilc)) |
1370 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
11588 | 1371 |
#endif |
18252 | 1372 |
thecode = __BlockInstPtr(self)->b_code; |
11588 | 1373 |
#ifdef NEW_BLOCK_CALL |
18252 | 1374 |
if (thecode != (OBJFUNC)nil) { |
1375 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) ); |
|
1376 |
} |
|
11588 | 1377 |
# ifdef PASS_ARG_POINTER |
18252 | 1378 |
RETURN ( __interpret(self, 9, nil, nil, nil, nil, &arg1) ); |
11588 | 1379 |
# else |
18252 | 1380 |
RETURN ( __interpret(self, 9, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) ); |
11588 | 1381 |
# endif |
1382 |
#else |
|
18252 | 1383 |
home = __BlockInstPtr(self)->b_home; |
1384 |
if (thecode != (OBJFUNC)nil) { |
|
1385 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) ); |
|
1386 |
} |
|
11588 | 1387 |
# ifdef PASS_ARG_POINTER |
18252 | 1388 |
RETURN ( __interpret(self, 9, nil, home, nil, nil, &arg1) ); |
11588 | 1389 |
# else |
18252 | 1390 |
RETURN ( __interpret(self, 9, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) ); |
11588 | 1391 |
# endif |
1392 |
#endif |
|
1393 |
} |
|
1394 |
%}. |
|
1395 |
^ self wrongNumberOfArguments:9 |
|
1396 |
! |
|
1397 |
||
1398 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8 value:arg9 value:arg10 |
|
11603 | 1399 |
"evaluate the receiver with 10 arguments. |
11588 | 1400 |
The receiver must be a 10-arg block." |
1401 |
||
1402 |
%{ /* NOCONTEXT */ |
|
1403 |
||
1404 |
REGISTER OBJFUNC thecode; |
|
1405 |
OBJ home; |
|
1406 |
||
1407 |
if (__INST(nargs) == __mkSmallInteger(10)) { |
|
1408 |
#if defined(THIS_CONTEXT) |
|
18252 | 1409 |
if (__ISVALID_ILC_LNO(__pilc)) |
1410 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
11588 | 1411 |
#endif |
18252 | 1412 |
thecode = __BlockInstPtr(self)->b_code; |
11588 | 1413 |
#ifdef NEW_BLOCK_CALL |
18252 | 1414 |
if (thecode != (OBJFUNC)nil) { |
1415 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) ); |
|
1416 |
} |
|
11588 | 1417 |
# ifdef PASS_ARG_POINTER |
18252 | 1418 |
RETURN ( __interpret(self, 10, nil, nil, nil, nil, &arg1) ); |
11588 | 1419 |
# else |
18252 | 1420 |
RETURN ( __interpret(self, 10, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) ); |
11588 | 1421 |
# endif |
1422 |
#else |
|
18252 | 1423 |
home = __BlockInstPtr(self)->b_home; |
1424 |
if (thecode != (OBJFUNC)nil) { |
|
1425 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) ); |
|
1426 |
} |
|
11588 | 1427 |
# ifdef PASS_ARG_POINTER |
18252 | 1428 |
RETURN ( __interpret(self, 10, nil, home, nil, nil, &arg1) ); |
11588 | 1429 |
# else |
18252 | 1430 |
RETURN ( __interpret(self, 10, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) ); |
11588 | 1431 |
# endif |
1432 |
#endif |
|
1433 |
} |
|
1434 |
%}. |
|
1435 |
^ self wrongNumberOfArguments:10 |
|
1436 |
! |
|
1437 |
||
1438 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8 value:arg9 value:arg10 value:arg11 |
|
11603 | 1439 |
"evaluate the receiver with 11 arguments. |
1440 |
The receiver must be a 11-arg block." |
|
11588 | 1441 |
|
1442 |
%{ /* NOCONTEXT */ |
|
1443 |
||
1444 |
REGISTER OBJFUNC thecode; |
|
1445 |
OBJ home; |
|
1446 |
||
1447 |
if (__INST(nargs) == __mkSmallInteger(11)) { |
|
1448 |
#if defined(THIS_CONTEXT) |
|
18252 | 1449 |
if (__ISVALID_ILC_LNO(__pilc)) |
1450 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
11588 | 1451 |
#endif |
18252 | 1452 |
thecode = __BlockInstPtr(self)->b_code; |
11588 | 1453 |
#ifdef NEW_BLOCK_CALL |
18252 | 1454 |
if (thecode != (OBJFUNC)nil) { |
1455 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) ); |
|
1456 |
} |
|
11588 | 1457 |
# ifdef PASS_ARG_POINTER |
18252 | 1458 |
RETURN ( __interpret(self, 11, nil, nil, nil, nil, &arg1) ); |
11588 | 1459 |
# else |
18252 | 1460 |
RETURN ( __interpret(self, 11, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) ); |
11588 | 1461 |
# endif |
1462 |
#else |
|
18252 | 1463 |
home = __BlockInstPtr(self)->b_home; |
1464 |
if (thecode != (OBJFUNC)nil) { |
|
1465 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) ); |
|
1466 |
} |
|
11588 | 1467 |
# ifdef PASS_ARG_POINTER |
18252 | 1468 |
RETURN ( __interpret(self, 11, nil, home, nil, nil, &arg1) ); |
11588 | 1469 |
# else |
18252 | 1470 |
RETURN ( __interpret(self, 11, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) ); |
11588 | 1471 |
# endif |
1472 |
#endif |
|
1473 |
} |
|
1474 |
%}. |
|
1475 |
^ self wrongNumberOfArguments:11 |
|
1476 |
! |
|
1477 |
||
11603 | 1478 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8 value:arg9 value:arg10 value:arg11 value:arg12 |
1479 |
"evaluate the receiver with 12 arguments. |
|
1480 |
The receiver must be a 12-arg block." |
|
1481 |
||
1482 |
%{ /* NOCONTEXT */ |
|
1483 |
||
1484 |
REGISTER OBJFUNC thecode; |
|
1485 |
OBJ home; |
|
1486 |
||
1487 |
if (__INST(nargs) == __mkSmallInteger(12)) { |
|
1488 |
#if defined(THIS_CONTEXT) |
|
18252 | 1489 |
if (__ISVALID_ILC_LNO(__pilc)) |
1490 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
11603 | 1491 |
#endif |
18252 | 1492 |
thecode = __BlockInstPtr(self)->b_code; |
11603 | 1493 |
#ifdef NEW_BLOCK_CALL |
18252 | 1494 |
if (thecode != (OBJFUNC)nil) { |
1495 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) ); |
|
1496 |
} |
|
11603 | 1497 |
# ifdef PASS_ARG_POINTER |
18252 | 1498 |
RETURN ( __interpret(self, 12, nil, nil, nil, nil, &arg1) ); |
11603 | 1499 |
# else |
18252 | 1500 |
RETURN ( __interpret(self, 12, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) ); |
11603 | 1501 |
# endif |
1502 |
#else |
|
18252 | 1503 |
home = __BlockInstPtr(self)->b_home; |
1504 |
if (thecode != (OBJFUNC)nil) { |
|
1505 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) ); |
|
1506 |
} |
|
11603 | 1507 |
# ifdef PASS_ARG_POINTER |
18252 | 1508 |
RETURN ( __interpret(self, 12, nil, home, nil, nil, &arg1) ); |
11603 | 1509 |
# else |
18252 | 1510 |
RETURN ( __interpret(self, 12, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) ); |
11603 | 1511 |
# endif |
1512 |
#endif |
|
1513 |
} |
|
1514 |
%}. |
|
1515 |
^ self wrongNumberOfArguments:12 |
|
1516 |
! |
|
1517 |
||
3688 | 1518 |
valueAt:priority |
1519 |
"evaluate the receiver, at the given prioriy; |
|
11998 | 1520 |
i.e. change the priority for the execution of the receiver. |
1521 |
Bad name: should be called evaluateWithPriority: or similar" |
|
3688 | 1522 |
|
9042 | 1523 |
|oldPrio retVal activeProcess| |
1524 |
||
1525 |
activeProcess := Processor activeProcess. |
|
3688 | 1526 |
oldPrio := Processor activePriority. |
1527 |
[ |
|
18252 | 1528 |
activeProcess priority:priority. |
1529 |
retVal := self value. |
|
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
1530 |
] ensure:[ |
18252 | 1531 |
activeProcess priority:oldPrio |
3688 | 1532 |
]. |
1533 |
^ retVal |
|
1534 |
||
1535 |
" |
|
1536 |
[ |
|
18252 | 1537 |
1000 timesRepeat:[ |
1538 |
1000 factorial |
|
1539 |
] |
|
3688 | 1540 |
] valueAt:3 |
1541 |
" |
|
1542 |
||
1543 |
"Created: / 29.7.1998 / 19:19:48 / cg" |
|
1544 |
! |
|
1545 |
||
1 | 1546 |
valueWithArguments:argArray |
1547 |
"evaluate the receiver with arguments taken from argArray. |
|
313 | 1548 |
ArgArray must be either an Array or nil. |
1 | 1549 |
The size of the argArray must match the number of arguments the receiver expects." |
1550 |
||
8009 | 1551 |
|a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
1 | 1552 |
|
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1553 |
(argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[ |
18252 | 1554 |
argArray isCollection ifTrue:[ |
1555 |
^ self valueWithArguments:argArray asArray |
|
1556 |
]. |
|
1557 |
^ self badArgumentArray:argArray |
|
1 | 1558 |
]. |
1559 |
(argArray size == nargs) ifFalse:[ |
|
18252 | 1560 |
^ self wrongNumberOfArguments:argArray size |
1 | 1561 |
]. |
1562 |
%{ |
|
1563 |
||
1564 |
REGISTER OBJFUNC thecode; |
|
1565 |
OBJ home; |
|
67 | 1566 |
REGISTER OBJ *ap; |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1567 |
OBJ nA; |
1 | 1568 |
|
1569 |
#if defined(THIS_CONTEXT) |
|
328 | 1570 |
if (__ISVALID_ILC_LNO(__pilc)) |
18252 | 1571 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 1572 |
#endif |
1133 | 1573 |
thecode = __BlockInstPtr(self)->b_code; |
1037 | 1574 |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1575 |
nA = __INST(nargs); |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1576 |
|
1037 | 1577 |
#ifndef NEW_BLOCK_CALL |
1133 | 1578 |
home = __BlockInstPtr(self)->b_home; |
1037 | 1579 |
if (thecode != (OBJFUNC)nil) { |
18252 | 1580 |
/* the most common case (0 args) here (without a switch) */ |
1581 |
||
1582 |
if (nA == __mkSmallInteger(0)) { |
|
1583 |
RETURN ( (*thecode)(home) ); |
|
1584 |
} |
|
1585 |
||
1586 |
ap = __arrayVal(argArray); /* nonNil after above test (size is known to be ok) */ |
|
1587 |
switch ((INT)(nA)) { |
|
1588 |
default: |
|
1589 |
goto error; |
|
1590 |
case (INT)__mkSmallInteger(15): |
|
1591 |
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]) ); |
|
1592 |
case (INT)__mkSmallInteger(14): |
|
1593 |
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]) ); |
|
1594 |
case (INT)__mkSmallInteger(13): |
|
1595 |
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]) ); |
|
1596 |
case (INT)__mkSmallInteger(12): |
|
1597 |
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]) ); |
|
1598 |
case (INT)__mkSmallInteger(11): |
|
1599 |
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]) ); |
|
1600 |
case (INT)__mkSmallInteger(10): |
|
1601 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9]) ); |
|
1602 |
case (INT)__mkSmallInteger(9): |
|
1603 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8]) ); |
|
1604 |
case (INT)__mkSmallInteger(8): |
|
1605 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7]) ); |
|
1606 |
case (INT)__mkSmallInteger(7): |
|
1607 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) ); |
|
1608 |
case (INT)__mkSmallInteger(6): |
|
1609 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) ); |
|
1610 |
case (INT)__mkSmallInteger(5): |
|
1611 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4]) ); |
|
1612 |
case (INT)__mkSmallInteger(4): |
|
1613 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3]) ); |
|
1614 |
case (INT)__mkSmallInteger(3): |
|
1615 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2]) ); |
|
1616 |
case (INT)__mkSmallInteger(2): |
|
1617 |
RETURN ( (*thecode)(home, ap[0], ap[1]) ); |
|
1618 |
case (INT)__mkSmallInteger(1): |
|
1619 |
RETURN ( (*thecode)(home, ap[0]) ); |
|
1620 |
case (INT)__mkSmallInteger(0): |
|
1621 |
RETURN ( (*thecode)(home) ); |
|
1622 |
break; |
|
1623 |
} |
|
1037 | 1624 |
} |
1625 |
#endif |
|
1626 |
||
8913 | 1627 |
if (nA != __mkSmallInteger(0)) { |
18252 | 1628 |
ap = __arrayVal(argArray); /* nonNil after above test (size is known to be ok) */ |
1629 |
switch ((INT)nA) { |
|
1630 |
default: |
|
1631 |
goto error; |
|
1632 |
case (INT)__mkSmallInteger(15): |
|
1633 |
a15 = ap[14]; |
|
1634 |
case (INT)__mkSmallInteger(14): |
|
1635 |
a14 = ap[13]; |
|
1636 |
case (INT)__mkSmallInteger(13): |
|
1637 |
a13 = ap[12]; |
|
1638 |
case (INT)__mkSmallInteger(12): |
|
1639 |
a12 = ap[11]; |
|
1640 |
case (INT)__mkSmallInteger(11): |
|
1641 |
a11 = ap[10]; |
|
1642 |
case (INT)__mkSmallInteger(10): |
|
1643 |
a10 = ap[9]; |
|
1644 |
case (INT)__mkSmallInteger(9): |
|
1645 |
a9 = ap[8]; |
|
1646 |
case (INT)__mkSmallInteger(8): |
|
1647 |
a8 = ap[7]; |
|
1648 |
case (INT)__mkSmallInteger(7): |
|
1649 |
a7 = ap[6]; |
|
1650 |
case (INT)__mkSmallInteger(6): |
|
1651 |
a6 = ap[5]; |
|
1652 |
case (INT)__mkSmallInteger(5): |
|
1653 |
a5 = ap[4]; |
|
1654 |
case (INT)__mkSmallInteger(4): |
|
1655 |
a4 = ap[3]; |
|
1656 |
case (INT)__mkSmallInteger(3): |
|
1657 |
a3 = ap[2]; |
|
1658 |
case (INT)__mkSmallInteger(2): |
|
1659 |
a2 = ap[1]; |
|
1660 |
case (INT)__mkSmallInteger(1): |
|
1661 |
a1 = ap[0]; |
|
1662 |
case (INT)__mkSmallInteger(0): |
|
1663 |
break; |
|
1664 |
} |
|
1 | 1665 |
} |
1133 | 1666 |
|
11 | 1667 |
#ifdef NEW_BLOCK_CALL |
1 | 1668 |
if (thecode != (OBJFUNC)nil) { |
18252 | 1669 |
RETURN ( (*thecode)(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
11 | 1670 |
} |
328 | 1671 |
# ifdef PASS_ARG_POINTER |
6553
ce4ca4df3415
oops - last modification created a little bug.
Claus Gittinger <cg@exept.de>
parents:
6512
diff
changeset
|
1672 |
RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, &a1) ); |
328 | 1673 |
# else |
8009 | 1674 |
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 | 1675 |
# endif |
1037 | 1676 |
|
1 | 1677 |
#else |
1037 | 1678 |
|
328 | 1679 |
# ifdef PASS_ARG_POINTER |
6553
ce4ca4df3415
oops - last modification created a little bug.
Claus Gittinger <cg@exept.de>
parents:
6512
diff
changeset
|
1680 |
RETURN ( __interpret(self, __intVal(nA), nil, home, nil, nil, &a1) ); |
328 | 1681 |
# else |
8009 | 1682 |
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 | 1683 |
# endif |
1037 | 1684 |
|
1 | 1685 |
#endif |
67 | 1686 |
|
11 | 1687 |
error: ; |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1688 |
%}. |
138 | 1689 |
" |
8009 | 1690 |
the above code only supports up-to 15 arguments |
138 | 1691 |
" |
7602
d048f13cd50a
Exception classes initialize themself.
Stefan Vogel <sv@exept.de>
parents:
7352
diff
changeset
|
1692 |
^ ArgumentError |
18252 | 1693 |
raiseRequestWith:self |
1694 |
errorString:'only blocks with up-to 15 arguments supported' |
|
6317 | 1695 |
! |
1696 |
||
1697 |
valueWithOptionalArgument:arg |
|
1698 |
"evaluate the receiver. |
|
6318 | 1699 |
Optionally pass an argument (if the receiver is a one arg block)." |
6317 | 1700 |
|
6628
4d693c525443
#handlerForSignal:context:originator:
Stefan Vogel <sv@exept.de>
parents:
6611
diff
changeset
|
1701 |
nargs == 1 ifTrue:[ |
18252 | 1702 |
^ self value:arg |
6317 | 1703 |
]. |
1704 |
^ self value |
|
6320 | 1705 |
|
1706 |
" |
|
1707 |
|block| |
|
1708 |
||
1709 |
block := [ Transcript showCR:'hello' ]. |
|
18252 | 1710 |
block valueWithOptionalArgument:2. |
6320 | 1711 |
|
1712 |
block := [:arg | Transcript showCR:arg ]. |
|
18252 | 1713 |
block valueWithOptionalArgument:2. |
6320 | 1714 |
" |
6785 | 1715 |
! |
1716 |
||
1717 |
valueWithOptionalArgument:arg1 and:arg2 |
|
1718 |
"evaluate the receiver. |
|
1719 |
Optionally pass up to two arguments (if the receiver is a one/two arg block)." |
|
1720 |
||
1721 |
nargs == 2 ifTrue:[ |
|
18252 | 1722 |
^ self value:arg1 value:arg2 |
6785 | 1723 |
]. |
1724 |
nargs == 1 ifTrue:[ |
|
18252 | 1725 |
^ self value:arg1 |
6785 | 1726 |
]. |
1727 |
^ self value |
|
1728 |
||
1729 |
" |
|
1730 |
|block| |
|
1731 |
||
1732 |
block := [ Transcript showCR:'hello' ]. |
|
18252 | 1733 |
block valueWithOptionalArgument:2. |
6785 | 1734 |
|
1735 |
block := [:arg | Transcript showCR:arg ]. |
|
18252 | 1736 |
block valueWithOptionalArgument:2. |
6785 | 1737 |
|
1738 |
block := [:arg1 :arg2 | Transcript showCR:arg1. Transcript showCR:arg2 ]. |
|
18252 | 1739 |
block valueWithOptionalArgument:10 and:20. |
6785 | 1740 |
" |
9010 | 1741 |
! |
1742 |
||
1743 |
valueWithOptionalArgument:arg1 and:arg2 and:arg3 |
|
1744 |
"evaluate the receiver. |
|
1745 |
Optionally pass up to three arguments (if the receiver is a one/two/three arg block)." |
|
1746 |
||
1747 |
nargs == 3 ifTrue:[ |
|
18252 | 1748 |
^ self value:arg1 value:arg2 value:arg3 |
9010 | 1749 |
]. |
1750 |
nargs == 2 ifTrue:[ |
|
18252 | 1751 |
^ self value:arg1 value:arg2 |
9010 | 1752 |
]. |
1753 |
nargs == 1 ifTrue:[ |
|
18252 | 1754 |
^ self value:arg1 |
9010 | 1755 |
]. |
1756 |
^ self value |
|
1757 |
||
1758 |
" |
|
1759 |
|block| |
|
1760 |
||
1761 |
block := [ Transcript showCR:'hello' ]. |
|
18252 | 1762 |
block valueWithOptionalArgument:2. |
9010 | 1763 |
|
1764 |
block := [:arg | Transcript showCR:arg ]. |
|
18252 | 1765 |
block valueWithOptionalArgument:2. |
9010 | 1766 |
|
1767 |
block := [:arg1 :arg2 | Transcript showCR:arg1. Transcript showCR:arg2 ]. |
|
18252 | 1768 |
block valueWithOptionalArgument:10 and:20. |
9010 | 1769 |
" |
1770 |
! |
|
1771 |
||
1772 |
valueWithOptionalArgument:arg1 and:arg2 and:arg3 and:arg4 |
|
1773 |
"evaluate the receiver. |
|
1774 |
Optionally pass up to four arguments (if the receiver is a one/two/three/four arg block)." |
|
1775 |
||
1776 |
nargs == 4 ifTrue:[ |
|
18252 | 1777 |
^ self value:arg1 value:arg2 value:arg3 value:arg4 |
9010 | 1778 |
]. |
1779 |
nargs == 3 ifTrue:[ |
|
18252 | 1780 |
^ self value:arg1 value:arg2 value:arg3 |
9010 | 1781 |
]. |
1782 |
nargs == 2 ifTrue:[ |
|
18252 | 1783 |
^ self value:arg1 value:arg2 |
9010 | 1784 |
]. |
1785 |
nargs == 1 ifTrue:[ |
|
18252 | 1786 |
^ self value:arg1 |
9010 | 1787 |
]. |
1788 |
^ self value |
|
1789 |
||
1790 |
" |
|
1791 |
|block| |
|
1792 |
||
1793 |
block := [ Transcript showCR:'hello' ]. |
|
18252 | 1794 |
block valueWithOptionalArgument:2. |
9010 | 1795 |
|
1796 |
block := [:arg | Transcript showCR:arg ]. |
|
18252 | 1797 |
block valueWithOptionalArgument:2. |
9010 | 1798 |
|
1799 |
block := [:arg1 :arg2 | Transcript showCR:arg1. Transcript showCR:arg2 ]. |
|
18252 | 1800 |
block valueWithOptionalArgument:10 and:20. |
9010 | 1801 |
" |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1802 |
! |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1803 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1804 |
valueWithOptionalArguments:argArray |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1805 |
"evaluate the receiver with arguments as required taken from argArray. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1806 |
Only the required number of arguments is taken from argArray or nil; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1807 |
(i.e. argArray may be larger than the required number). |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1808 |
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
|
1809 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1810 |
|numArgsProvided 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
|
1811 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1812 |
(argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[ |
18252 | 1813 |
argArray isCollection ifTrue:[ |
1814 |
^ self valueWithArguments:argArray asArray |
|
1815 |
]. |
|
1816 |
^ self badArgumentArray:argArray |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1817 |
]. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1818 |
(argArray size >= nargs) ifFalse:[ |
18252 | 1819 |
^ self wrongNumberOfArguments:argArray size |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1820 |
]. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1821 |
%{ |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1822 |
REGISTER OBJFUNC thecode; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1823 |
OBJ home; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1824 |
REGISTER OBJ *ap; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1825 |
OBJ nA; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1826 |
int __numArgsProvided = __intVal(numArgsProvided); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1827 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1828 |
#if defined(THIS_CONTEXT) |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1829 |
if (__ISVALID_ILC_LNO(__pilc)) |
18252 | 1830 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1831 |
#endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1832 |
thecode = __BlockInstPtr(self)->b_code; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1833 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1834 |
nA = __INST(nargs); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1835 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1836 |
if (argArray == nil) { |
18252 | 1837 |
ap = 0; |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1838 |
} else { |
18252 | 1839 |
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
|
1840 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1841 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1842 |
#ifndef NEW_BLOCK_CALL |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1843 |
home = __BlockInstPtr(self)->b_home; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1844 |
if (thecode != (OBJFUNC)nil) { |
18252 | 1845 |
/* the most common case (0 args) here (without a switch) */ |
1846 |
||
1847 |
if (nA == __mkSmallInteger(0)) { |
|
1848 |
RETURN ( (*thecode)(home) ); |
|
1849 |
} |
|
1850 |
||
1851 |
switch ((INT)(nA)) { |
|
1852 |
default: |
|
1853 |
goto error; |
|
1854 |
case (INT)__mkSmallInteger(15): |
|
1855 |
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]) ); |
|
1856 |
case (INT)__mkSmallInteger(14): |
|
1857 |
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]) ); |
|
1858 |
case (INT)__mkSmallInteger(13): |
|
1859 |
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]) ); |
|
1860 |
case (INT)__mkSmallInteger(12): |
|
1861 |
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]) ); |
|
1862 |
case (INT)__mkSmallInteger(11): |
|
1863 |
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]) ); |
|
1864 |
case (INT)__mkSmallInteger(10): |
|
1865 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9]) ); |
|
1866 |
case (INT)__mkSmallInteger(9): |
|
1867 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8]) ); |
|
1868 |
case (INT)__mkSmallInteger(8): |
|
1869 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7]) ); |
|
1870 |
case (INT)__mkSmallInteger(7): |
|
1871 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) ); |
|
1872 |
case (INT)__mkSmallInteger(6): |
|
1873 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) ); |
|
1874 |
case (INT)__mkSmallInteger(5): |
|
1875 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4]) ); |
|
1876 |
case (INT)__mkSmallInteger(4): |
|
1877 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3]) ); |
|
1878 |
case (INT)__mkSmallInteger(3): |
|
1879 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2]) ); |
|
1880 |
case (INT)__mkSmallInteger(2): |
|
1881 |
RETURN ( (*thecode)(home, ap[0], ap[1]) ); |
|
1882 |
case (INT)__mkSmallInteger(1): |
|
1883 |
RETURN ( (*thecode)(home, ap[0]) ); |
|
1884 |
case (INT)__mkSmallInteger(0): |
|
1885 |
RETURN ( (*thecode)(home) ); |
|
1886 |
break; |
|
1887 |
} |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1888 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1889 |
#endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1890 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1891 |
if (nA != __mkSmallInteger(0)) { |
18252 | 1892 |
ap = __arrayVal(argArray); /* nonNil after above test (size is known to be ok) */ |
1893 |
switch ((INT)nA) { |
|
1894 |
default: |
|
1895 |
goto error; |
|
1896 |
case (INT)__mkSmallInteger(15): |
|
1897 |
a15 = ap[14]; |
|
1898 |
case (INT)__mkSmallInteger(14): |
|
1899 |
a14 = ap[13]; |
|
1900 |
case (INT)__mkSmallInteger(13): |
|
1901 |
a13 = ap[12]; |
|
1902 |
case (INT)__mkSmallInteger(12): |
|
1903 |
a12 = ap[11]; |
|
1904 |
case (INT)__mkSmallInteger(11): |
|
1905 |
a11 = ap[10]; |
|
1906 |
case (INT)__mkSmallInteger(10): |
|
1907 |
a10 = ap[9]; |
|
1908 |
case (INT)__mkSmallInteger(9): |
|
1909 |
a9 = ap[8]; |
|
1910 |
case (INT)__mkSmallInteger(8): |
|
1911 |
a8 = ap[7]; |
|
1912 |
case (INT)__mkSmallInteger(7): |
|
1913 |
a7 = ap[6]; |
|
1914 |
case (INT)__mkSmallInteger(6): |
|
1915 |
a6 = ap[5]; |
|
1916 |
case (INT)__mkSmallInteger(5): |
|
1917 |
a5 = ap[4]; |
|
1918 |
case (INT)__mkSmallInteger(4): |
|
1919 |
a4 = ap[3]; |
|
1920 |
case (INT)__mkSmallInteger(3): |
|
1921 |
a3 = ap[2]; |
|
1922 |
case (INT)__mkSmallInteger(2): |
|
1923 |
a2 = ap[1]; |
|
1924 |
case (INT)__mkSmallInteger(1): |
|
1925 |
a1 = ap[0]; |
|
1926 |
case (INT)__mkSmallInteger(0): |
|
1927 |
break; |
|
1928 |
} |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1929 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1930 |
#ifdef NEW_BLOCK_CALL |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1931 |
if (thecode != (OBJFUNC)nil) { |
18252 | 1932 |
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
|
1933 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1934 |
# ifdef PASS_ARG_POINTER |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1935 |
RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, &a1) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1936 |
# else |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1937 |
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
|
1938 |
# endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1939 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1940 |
#else |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1941 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1942 |
# ifdef PASS_ARG_POINTER |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1943 |
RETURN ( __interpret(self, __intVal(nA), nil, home, nil, nil, &a1) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1944 |
# else |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1945 |
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
|
1946 |
# endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1947 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1948 |
#endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1949 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1950 |
error: ; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1951 |
%}. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1952 |
" |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1953 |
the above code only supports up-to 15 arguments |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1954 |
" |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1955 |
^ ArgumentError |
18252 | 1956 |
raiseRequestWith:self |
1957 |
errorString:'only blocks with up-to 15 arguments supported' |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1958 |
! |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1959 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1960 |
valueWithPossibleArguments:argArray |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1961 |
"evaluate the receiver with arguments as required taken from argArray. |
18252 | 1962 |
If argArray provides less than the required number of arguments, |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1963 |
nil is assumed for any remaining argument. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1964 |
(i.e. argArray may be smaller than the required number). |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1965 |
Only the required number of arguments is taken from argArray or nil; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1966 |
(i.e. argArray may be larger than the required number)." |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1967 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1968 |
|numArgsProvided 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
|
1969 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1970 |
(argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[ |
18252 | 1971 |
argArray isCollection ifTrue:[ |
1972 |
^ self valueWithArguments:argArray asArray |
|
1973 |
]. |
|
1974 |
^ self badArgumentArray:argArray |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1975 |
]. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1976 |
numArgsProvided := argArray size. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1977 |
%{ |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1978 |
REGISTER OBJFUNC thecode; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1979 |
OBJ home; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1980 |
REGISTER OBJ *ap; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1981 |
OBJ nA; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1982 |
int __numArgsProvided = __intVal(numArgsProvided); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1983 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1984 |
#if defined(THIS_CONTEXT) |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1985 |
if (__ISVALID_ILC_LNO(__pilc)) |
18252 | 1986 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1987 |
#endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1988 |
thecode = __BlockInstPtr(self)->b_code; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1989 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1990 |
nA = __INST(nargs); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1991 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1992 |
if (argArray == nil) { |
18252 | 1993 |
ap = 0; |
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1994 |
} else { |
18252 | 1995 |
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
|
1996 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
1997 |
switch (__numArgsProvided) { |
18252 | 1998 |
default: |
1999 |
case 15: a15 = ap[14]; |
|
2000 |
case 14: a14 = ap[13]; |
|
2001 |
case 13: a13 = ap[12]; |
|
2002 |
case 12: a12 = ap[11]; |
|
2003 |
case 11: a11 = ap[10]; |
|
2004 |
case 10: a10 = ap[9]; |
|
2005 |
case 9: a9 = ap[8]; |
|
2006 |
case 8: a8 = ap[7]; |
|
2007 |
case 7: a7 = ap[6]; |
|
2008 |
case 6: a6 = ap[5]; |
|
2009 |
case 5: a5 = ap[4]; |
|
2010 |
case 4: a4 = ap[3]; |
|
2011 |
case 3: a3 = ap[2]; |
|
2012 |
case 2: a2 = ap[1]; |
|
2013 |
case 1: a1 = ap[0]; |
|
2014 |
case 0: ; |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2015 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2016 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2017 |
#ifndef NEW_BLOCK_CALL |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2018 |
home = __BlockInstPtr(self)->b_home; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2019 |
if (thecode != (OBJFUNC)nil) { |
18252 | 2020 |
/* the most common case (0 args) here (without a switch) */ |
2021 |
||
2022 |
if (nA == __mkSmallInteger(0)) { |
|
2023 |
RETURN ( (*thecode)(home) ); |
|
2024 |
} |
|
2025 |
||
2026 |
switch ((INT)(nA)) { |
|
2027 |
default: |
|
2028 |
goto error; |
|
2029 |
case (INT)__mkSmallInteger(15): |
|
2030 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
|
2031 |
case (INT)__mkSmallInteger(14): |
|
2032 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) ); |
|
2033 |
case (INT)__mkSmallInteger(13): |
|
2034 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) ); |
|
2035 |
case (INT)__mkSmallInteger(12): |
|
2036 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) ); |
|
2037 |
case (INT)__mkSmallInteger(11): |
|
2038 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) ); |
|
2039 |
case (INT)__mkSmallInteger(10): |
|
2040 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) ); |
|
2041 |
case (INT)__mkSmallInteger(9): |
|
2042 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9) ); |
|
2043 |
case (INT)__mkSmallInteger(8): |
|
2044 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8) ); |
|
2045 |
case (INT)__mkSmallInteger(7): |
|
2046 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7) ); |
|
2047 |
case (INT)__mkSmallInteger(6): |
|
2048 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6) ); |
|
2049 |
case (INT)__mkSmallInteger(5): |
|
2050 |
RETURN ( (*thecode)(home, a1, a2, a3, a4, a5) ); |
|
2051 |
case (INT)__mkSmallInteger(4): |
|
2052 |
RETURN ( (*thecode)(home, a1, a2, a3, a4) ); |
|
2053 |
case (INT)__mkSmallInteger(3): |
|
2054 |
RETURN ( (*thecode)(home, a1, a2, a3) ); |
|
2055 |
case (INT)__mkSmallInteger(2): |
|
2056 |
RETURN ( (*thecode)(home, a1, a2) ); |
|
2057 |
case (INT)__mkSmallInteger(1): |
|
2058 |
RETURN ( (*thecode)(home, a1) ); |
|
2059 |
case (INT)__mkSmallInteger(0): |
|
2060 |
RETURN ( (*thecode)(home) ); |
|
2061 |
break; |
|
2062 |
} |
|
9145
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2063 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2064 |
#endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2065 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2066 |
#ifdef NEW_BLOCK_CALL |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2067 |
if (thecode != (OBJFUNC)nil) { |
18252 | 2068 |
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
|
2069 |
} |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2070 |
# ifdef PASS_ARG_POINTER |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2071 |
RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, &a1) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2072 |
# else |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2073 |
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
|
2074 |
# endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2075 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2076 |
#else |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2077 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2078 |
# ifdef PASS_ARG_POINTER |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2079 |
RETURN ( __interpret(self, __intVal(nA), nil, home, nil, nil, &a1) ); |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2080 |
# else |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2081 |
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
|
2082 |
# endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2083 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2084 |
#endif |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2085 |
|
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2086 |
error: ; |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2087 |
%}. |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2088 |
" |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2089 |
the above code only supports up-to 15 arguments |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2090 |
" |
c0ccf0f361ba
+valueWithPossibleArguments:
Claus Gittinger <cg@exept.de>
parents:
9042
diff
changeset
|
2091 |
^ ArgumentError |
18252 | 2092 |
raiseRequestWith:self |
2093 |
errorString:'only blocks with up-to 15 arguments supported' |
|
154 | 2094 |
! ! |
2095 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2096 |
!Block methodsFor:'exception handling'! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2097 |
|
6512 | 2098 |
on:aSignalOrSignalSetOrException do:exceptionBlock |
2099 |
"added for ANSI compatibility; evaluate the receiver, |
|
18252 | 2100 |
handling aSignalOrSignalSetOrException. |
18316 | 2101 |
If the signal is raised during evaluation, |
2102 |
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
|
2103 |
|
4542
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
2104 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2105 |
<exception: #handle> |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2106 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2107 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2108 |
^ 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
|
2109 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2110 |
" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2111 |
[ |
18316 | 2112 |
1 foo |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2113 |
] 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
|
2114 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2115 |
[ |
18316 | 2116 |
1 foo |
6512 | 2117 |
] on:(MessageNotUnderstood , AbortOperationRequest) do:[:ex | self halt] |
2118 |
||
2119 |
[ |
|
18316 | 2120 |
1 foo |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2121 |
] on:SignalSet anySignal do:[:ex| 2 bar. self halt] |
18316 | 2122 |
|
2123 |
[ |
|
2124 |
1 foo |
|
2125 |
] 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
|
2126 |
" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2127 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2128 |
"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
|
2129 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2130 |
|
11338 | 2131 |
on:aSignalOrSignalSetOrException do:exceptionBlock ensure:ensureBlock |
2132 |
"added for ANSI compatibility; evaluate the receiver, |
|
18252 | 2133 |
handling aSignalOrSignalSetOrException. |
11338 | 2134 |
The 2nd argument, exceptionBlock is evaluated |
2135 |
if the signal is raised during evaluation. |
|
2136 |
The 3rd argument, ensureBlock is evaluated in any case - even if the activity |
|
2137 |
was unwound due to an unhandled exception." |
|
2138 |
||
2139 |
<context: #return> |
|
2140 |
<exception: #handle> |
|
2141 |
<exception: #unwind> |
|
2142 |
||
2143 |
|v| |
|
2144 |
||
2145 |
v := self value. "the real logic is in Context>>unwind and Exception>>doRaise" |
|
2146 |
thisContext unmarkForUnwind. |
|
2147 |
ensureBlock value. |
|
2148 |
^ v |
|
2149 |
||
2150 |
" |
|
2151 |
|e| |
|
2152 |
||
2153 |
e := 0. |
|
2154 |
[ |
|
18252 | 2155 |
1 foo |
2156 |
] on:MessageNotUnderstood |
|
11338 | 2157 |
do:[:ex | self halt] |
2158 |
ensure:[ e := 1 ]. |
|
2159 |
self assert:(e == 1). |
|
2160 |
" |
|
2161 |
||
2162 |
" |
|
2163 |
|e| |
|
2164 |
||
2165 |
e := 0. |
|
2166 |
[ |
|
18252 | 2167 |
1 negated |
2168 |
] on:MessageNotUnderstood |
|
11338 | 2169 |
do:[:ex | self halt] |
2170 |
ensure:[ e := 1 ]. |
|
2171 |
self assert:(e == 1). |
|
2172 |
" |
|
2173 |
! |
|
2174 |
||
18959 | 2175 |
on:aSignalOrSignalSetOrException do:exceptionBlock ifCurtailed:curtailBlock |
2176 |
"evaluate the receiver, |
|
2177 |
handling aSignalOrSignalSetOrException. |
|
2178 |
The 2nd argument, exceptionBlock is evaluated |
|
2179 |
if the signal is raised during evaluation. |
|
2180 |
The 3rd argument, curtailBlock is evaluated if the activity |
|
2181 |
was unwound due to an unhandled exception in the receiver block |
|
2182 |
(but not in the exceptionBlock)." |
|
2183 |
||
2184 |
<context: #return> |
|
2185 |
<exception: #handle> |
|
2186 |
<exception: #unwind> |
|
2187 |
||
2188 |
|v| |
|
2189 |
||
2190 |
v := self value. "the real logic is in Context>>unwind and Exception>>doRaise" |
|
2191 |
thisContext unmarkForUnwind. |
|
2192 |
^ v |
|
2193 |
||
2194 |
" |
|
2195 |
|e| |
|
2196 |
||
2197 |
e := 0. |
|
2198 |
[ |
|
2199 |
1 foo |
|
2200 |
] on:MessageNotUnderstood |
|
2201 |
do:[:ex | e := 1] |
|
2202 |
ifCurtailed:[ e := 2 ]. |
|
2203 |
self assert:(e == 1). |
|
2204 |
" |
|
2205 |
||
2206 |
" |
|
2207 |
abort the debugger to perform the ifCurtailedBlock... |
|
2208 |
continue the debugger to go to the end |
|
2209 |
||
2210 |
|e| |
|
2211 |
||
2212 |
e := 0. |
|
2213 |
[ |
|
2214 |
#[] at:2 |
|
2215 |
] on:MessageNotUnderstood |
|
2216 |
do:[:ex | e := 1] |
|
2217 |
ifCurtailed:[ e := 2. e inspect ]. |
|
2218 |
self assert:(e == 0). |
|
2219 |
" |
|
2220 |
||
2221 |
" |
|
2222 |
|e| |
|
2223 |
||
2224 |
e := 0. |
|
2225 |
[ |
|
2226 |
1 negated |
|
2227 |
] on:MessageNotUnderstood |
|
2228 |
do:[:ex | self halt] |
|
2229 |
ifCurtailed:[ e := 1 ]. |
|
2230 |
self assert:(e == 0). |
|
2231 |
" |
|
2232 |
! |
|
2233 |
||
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2234 |
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
|
2235 |
"added for ANSI compatibility; evaluate the receiver, |
18252 | 2236 |
handling aSignalOrSignalSetOrException. |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2237 |
The 2nd argument, exceptionBlock is evaluated |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2238 |
if the signal is raised during evaluation." |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2239 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2240 |
<context: #return> |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2241 |
<exception: #handle> |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2242 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2243 |
"/ thisContext markForHandle. -- same as above pragma |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2244 |
^ 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
|
2245 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2246 |
" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2247 |
[ |
18252 | 2248 |
1 foo |
2249 |
] 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
|
2250 |
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
|
2251 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2252 |
[ |
18252 | 2253 |
1 // 0 |
2254 |
] 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
|
2255 |
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
|
2256 |
" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2257 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2258 |
"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
|
2259 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2260 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2261 |
valueWithExceptionHandler:handler |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2262 |
"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
|
2263 |
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
|
2264 |
|
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4542
diff
changeset
|
2265 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2266 |
<exception: #handle> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2267 |
|
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2268 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2269 |
^ 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
|
2270 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2271 |
"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
|
2272 |
"Modified: / 26.7.1999 / 11:24:06 / stefan" |
9485
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2273 |
! |
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2274 |
|
14803 | 2275 |
valueWithTimeout:aTimeDuration |
2276 |
"execute the receiver, but abort the evaluation after aTimeDuration if still running. |
|
16076 | 2277 |
Return the receiver's value, or nil if aborted." |
14803 | 2278 |
|
2279 |
^ self valueWithWatchDog:[^ nil] afterMilliseconds:aTimeDuration asMilliseconds |
|
2280 |
||
2281 |
" |
|
2282 |
[ |
|
18252 | 2283 |
1 to:15 do:[:round | |
2284 |
Transcript showCR:round. |
|
2285 |
Delay waitForMilliseconds:20. |
|
2286 |
]. |
|
2287 |
true |
|
2288 |
] valueWithTimeout:(TimeDuration seconds:1) |
|
14803 | 2289 |
" |
2290 |
||
2291 |
" |
|
2292 |
[ |
|
18252 | 2293 |
1 to:100 do:[:round | |
2294 |
Transcript showCR:round. |
|
2295 |
Delay waitForMilliseconds:20. |
|
2296 |
]. |
|
2297 |
true |
|
2298 |
] valueWithTimeout:(TimeDuration seconds:1) |
|
14803 | 2299 |
" |
2300 |
! |
|
2301 |
||
9485
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2302 |
valueWithWatchDog:exceptionBlock afterMilliseconds:aTimeLimit |
11803 | 2303 |
"a watchdog on a block's execution. If the block does not finish its |
2304 |
evaluation after aTimeLimit milliseconds, it is interrupted (aborted) and |
|
2305 |
exceptionBlock's value is returned. The receiver's code must be prepared |
|
2306 |
for premature returning (by adding ensure blocks, as required)" |
|
9485
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2307 |
|
13220
21b4d5e57663
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
13054
diff
changeset
|
2308 |
|showStopper me retVal done inError| |
12927
1caadc2e24d8
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
12921
diff
changeset
|
2309 |
|
1caadc2e24d8
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
12921
diff
changeset
|
2310 |
done := false. |
9485
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2311 |
me := Processor activeProcess. |
11704
a47fdf0a638d
oops - valueWithWatchDog did not
Claus Gittinger <cg@exept.de>
parents:
11638
diff
changeset
|
2312 |
|
18252 | 2313 |
showStopper := |
2314 |
[ |
|
2315 |
done ifFalse:[ |
|
2316 |
me interruptWith:[ |
|
2317 |
(Processor activeProcess state ~~ #debug) ifTrue:[ |
|
2318 |
done ifFalse:[ TimeoutNotification raiseRequest ] |
|
2319 |
] |
|
2320 |
] |
|
2321 |
] |
|
2322 |
]. |
|
13030
9b9f51659b4a
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
12931
diff
changeset
|
2323 |
|
9b9f51659b4a
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
12931
diff
changeset
|
2324 |
TimeoutNotification handle:[:ex | |
18252 | 2325 |
inError ifTrue:[ |
2326 |
ex proceed |
|
2327 |
]. |
|
2328 |
retVal := exceptionBlock value. |
|
10700
0436b2f40e4c
changed #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
10678
diff
changeset
|
2329 |
] do:[ |
18252 | 2330 |
NoHandlerError handle:[:ex | |
2331 |
inError := true. |
|
2332 |
ex reject. |
|
2333 |
] do:[ |
|
2334 |
[ |
|
2335 |
Processor |
|
2336 |
addTimedBlock:showStopper |
|
2337 |
for:me |
|
2338 |
afterMilliseconds:aTimeLimit. |
|
2339 |
||
2340 |
retVal := self value. |
|
2341 |
done := true. |
|
2342 |
] ensure:[ |
|
2343 |
Processor removeTimedBlock:showStopper |
|
2344 |
]. |
|
2345 |
] |
|
9485
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2346 |
]. |
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2347 |
^ retVal |
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2348 |
|
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2349 |
" |
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2350 |
[ |
18252 | 2351 |
Delay waitForSeconds:5. |
2352 |
true |
|
2353 |
] valueWithWatchDog:[false] afterMilliseconds:2000 |
|
9485
dab6bd4e2a81
added evaluation with watchdog
Claus Gittinger <cg@exept.de>
parents:
9287
diff
changeset
|
2354 |
" |
10678
5cd10f301f94
changed #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
10473
diff
changeset
|
2355 |
|
12928 | 2356 |
"Modified: / 21-05-2010 / 12:19:57 / sr" |
13220
21b4d5e57663
changed: #valueWithWatchDog:afterMilliseconds:
Claus Gittinger <cg@exept.de>
parents:
13054
diff
changeset
|
2357 |
"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
|
2358 |
! ! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
2359 |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2360 |
!Block methodsFor:'exception handling private'! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2361 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2362 |
exceptionHandlerFor:anException in:aContext |
11338 | 2363 |
"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
|
2364 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2365 |
aContext selector == #on:do:on:do: ifTrue:[ |
18252 | 2366 |
|exceptionCreator exceptionHandlerInContext| |
2367 |
||
2368 |
exceptionCreator := anException creator. |
|
2369 |
exceptionHandlerInContext := aContext argAt:1. |
|
2370 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
|
2371 |
exceptionHandlerInContext isNil ifTrue:[ |
|
2372 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2373 |
] ifFalse:[ |
|
2374 |
(exceptionHandlerInContext isBehavior |
|
2375 |
and:[exceptionHandlerInContext isLoaded not]) ifTrue:[ |
|
2376 |
"If the exception class is still autoloaded, |
|
2377 |
it does not accept our exception. Raising the exception would load the class" |
|
2378 |
^ nil |
|
2379 |
] ifFalse:[ |
|
2380 |
'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2381 |
] |
|
2382 |
]. |
|
2383 |
aContext fullPrintString errorPrintCR. |
|
2384 |
self breakPoint:#cg. |
|
2385 |
^ nil. |
|
2386 |
]. |
|
2387 |
(exceptionHandlerInContext accepts:exceptionCreator) ifTrue:[ |
|
2388 |
^ exceptionHandlerInContext. |
|
2389 |
]. |
|
2390 |
||
2391 |
exceptionHandlerInContext := aContext argAt:3. |
|
2392 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
|
2393 |
exceptionHandlerInContext isNil ifTrue:[ |
|
2394 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2395 |
] ifFalse:[ |
|
2396 |
(exceptionHandlerInContext isBehavior |
|
2397 |
and:[exceptionHandlerInContext isLoaded not]) ifTrue:[ |
|
2398 |
"If the exception class is still autoloaded, |
|
2399 |
it does not accept our exception. Raising the exception would load the class" |
|
2400 |
^ nil |
|
2401 |
] ifFalse:[ |
|
2402 |
'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2403 |
] |
|
2404 |
]. |
|
2405 |
aContext fullPrintString errorPrintCR. |
|
2406 |
self breakPoint:#cg. |
|
2407 |
^ nil. |
|
2408 |
]. |
|
2409 |
(exceptionHandlerInContext accepts:exceptionCreator) ifTrue:[ |
|
2410 |
^ exceptionHandlerInContext. |
|
2411 |
]. |
|
2412 |
^ nil. |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2413 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2414 |
|
11338 | 2415 |
"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
|
2416 |
^ aContext argAt:1. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2417 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2418 |
|
18959 | 2419 |
handlerForSignal:exceptionCreator context:theContext originator:originator |
2420 |
"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
|
2421 |
The handler block is retrieved from aContext. |
18959 | 2422 |
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
|
2423 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2424 |
|selector exceptionHandlerInContext| |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2425 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2426 |
selector := theContext selector. |
11338 | 2427 |
|
2428 |
(selector == #on:do: |
|
18959 | 2429 |
or:[ selector == #on:do:ensure: |
2430 |
or:[ selector == #on:do:ifCurtailed: ]] |
|
2431 |
) ifTrue:[ |
|
2432 |
exceptionHandlerInContext := theContext argAt:1. |
|
2433 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
|
2434 |
exceptionHandlerInContext isNil ifTrue:[ |
|
2435 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2436 |
] ifFalse:[(exceptionHandlerInContext isBehavior |
|
2437 |
and:[exceptionHandlerInContext isLoaded not]) ifTrue:[ |
|
2438 |
"If the exception class is still autoloaded, |
|
2439 |
it does not accept our exception. Raising the exception would load the class" |
|
2440 |
^ nil |
|
2441 |
] ifFalse:[ |
|
2442 |
'Block [warning]: non-ExceptionHandler in on:do:-context' errorPrintCR. |
|
2443 |
]]. |
|
2444 |
theContext fullPrint. |
|
2445 |
^ nil. |
|
2446 |
]. |
|
2447 |
(exceptionHandlerInContext == exceptionCreator |
|
2448 |
or:[exceptionHandlerInContext accepts:exceptionCreator]) ifTrue:[ |
|
2449 |
selector == #on:do:ifCurtailed: ifTrue:[ |
|
2450 |
theContext unmarkForUnwind. "if there is a handler, no unwind block has to be performed" |
|
2451 |
]. |
|
2452 |
^ (theContext argAt:2) ? [nil]. |
|
2453 |
]. |
|
2454 |
^ nil |
|
11338 | 2455 |
]. |
2456 |
||
2457 |
selector == #on:do:on:do: ifTrue:[ |
|
18959 | 2458 |
exceptionHandlerInContext := theContext argAt:1. |
2459 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
|
2460 |
exceptionHandlerInContext isNil ifTrue:[ |
|
2461 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2462 |
] ifFalse:[(exceptionHandlerInContext isBehavior |
|
2463 |
and:[exceptionHandlerInContext isLoaded not]) ifTrue:[ |
|
2464 |
"If the exception class is still autoloaded, |
|
2465 |
it does not accept our exception. Raising the exception would load the class" |
|
2466 |
^ nil |
|
2467 |
] ifFalse:[ |
|
2468 |
'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2469 |
]]. |
|
2470 |
theContext fullPrint. |
|
2471 |
^ nil. |
|
2472 |
]. |
|
2473 |
(exceptionHandlerInContext == exceptionCreator |
|
2474 |
or:[exceptionHandlerInContext accepts:exceptionCreator]) ifTrue:[ |
|
2475 |
^ (theContext argAt:2) ? [nil]. |
|
2476 |
]. |
|
2477 |
||
2478 |
exceptionHandlerInContext := theContext argAt:3. |
|
2479 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
|
2480 |
exceptionHandlerInContext isNil ifTrue:[ |
|
2481 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2482 |
] ifFalse:[(exceptionHandlerInContext isBehavior |
|
2483 |
and:[exceptionHandlerInContext isLoaded not]) ifTrue:[ |
|
2484 |
"If the exception class is still autoloaded, |
|
2485 |
it does not accept our exception. Raising the exception would load the class" |
|
2486 |
^ nil |
|
2487 |
] ifFalse:[ |
|
2488 |
'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
|
2489 |
]]. |
|
2490 |
theContext fullPrint. |
|
2491 |
^ nil. |
|
2492 |
]. |
|
2493 |
(exceptionHandlerInContext == exceptionCreator |
|
2494 |
or:[exceptionHandlerInContext accepts:exceptionCreator]) ifTrue:[ |
|
2495 |
^ (theContext argAt:4) ? [nil]. |
|
2496 |
]. |
|
2497 |
^ nil |
|
11338 | 2498 |
]. |
2499 |
||
2500 |
selector == #valueWithExceptionHandler: ifTrue:[ |
|
18959 | 2501 |
^ (theContext argAt:1) handlerForSignal:exceptionCreator. |
11338 | 2502 |
]. |
2503 |
||
2504 |
"/ mhmh - should not arrive here |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2505 |
^ nil |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2506 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2507 |
"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
|
2508 |
"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
|
2509 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2510 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2511 |
handlerProtectedBlock:doBlock inContext:context |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2512 |
"set the block that is protected by an exception handler in context. |
11338 | 2513 |
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
|
2514 |
Needed for #restartDo:" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2515 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2516 |
context receiver:doBlock |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2517 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2518 |
" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2519 |
[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
|
2520 |
" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2521 |
! ! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
2522 |
|
14139 | 2523 |
|
623 | 2524 |
!Block methodsFor:'looping'! |
325 | 2525 |
|
623 | 2526 |
doUntil:aBlock |
2527 |
"repeat the receiver block until aBlock evaluates to true. |
|
2528 |
The receiver is evaluated at least once. |
|
2529 |
This is the same as '... doWhile:[... not]' " |
|
325 | 2530 |
|
623 | 2531 |
"this implementation is for purists ... :-)" |
2532 |
||
2533 |
self value. |
|
2534 |
aBlock value ifTrue:[^ nil]. |
|
2535 |
thisContext restart |
|
325 | 2536 |
|
2537 |
" |
|
623 | 2538 |
|n| |
154 | 2539 |
|
623 | 2540 |
n := 1. |
8602 | 2541 |
[n printCR] doUntil:[ (n := n + 1) > 5 ] |
154 | 2542 |
" |
1 | 2543 |
! |
2544 |
||
623 | 2545 |
doWhile:aBlock |
2546 |
"repeat the receiver block until aBlock evaluates to false. |
|
2547 |
The receiver is evaluated at least once." |
|
67 | 2548 |
|
154 | 2549 |
"this implementation is for purists ... :-)" |
2550 |
||
623 | 2551 |
self value. |
2552 |
aBlock value ifFalse:[^ nil]. |
|
2553 |
thisContext restart |
|
2554 |
||
2555 |
" |
|
2556 |
|n| |
|
2557 |
||
2558 |
n := 1. |
|
8602 | 2559 |
[n printCR] doWhile:[ (n := n + 1) <= 5 ] |
623 | 2560 |
" |
2561 |
! |
|
2562 |
||
2563 |
loop |
|
18252 | 2564 |
"repeat the receiver forever |
1211 | 2565 |
(the receiver block should contain a return somewhere). |
2566 |
The implementation below was inspired by a corresponding Self method." |
|
623 | 2567 |
|
2568 |
self value. |
|
67 | 2569 |
thisContext restart |
2570 |
||
2571 |
" |
|
2572 |
|n| |
|
2573 |
||
2574 |
n := 1. |
|
623 | 2575 |
[ |
18252 | 2576 |
n printCR. |
2577 |
n >= 10 ifTrue:[^ nil]. |
|
2578 |
n := n + 1 |
|
623 | 2579 |
] loop |
2580 |
" |
|
1211 | 2581 |
|
2582 |
"Modified: 18.4.1996 / 13:50:40 / cg" |
|
623 | 2583 |
! |
2584 |
||
2585 |
loopWithExit |
|
18252 | 2586 |
"the receiver must be a block of one argument. It is evaluated in a loop forever, |
2587 |
and is passed a block, which, if sent a value:-message, will exit the receiver block, |
|
623 | 2588 |
returning the parameter of the value:-message. Used for loops with exit in the middle. |
2589 |
Inspired by a corresponding Self method." |
|
2590 |
||
2591 |
|exitBlock| |
|
2592 |
||
2593 |
exitBlock := [:exitValue | ^ exitValue]. |
|
16239 | 2594 |
[self value:exitBlock] loop. |
623 | 2595 |
|
2596 |
" |
|
2597 |
|i| |
|
2598 |
i := 1. |
|
2599 |
[:exit | |
|
18252 | 2600 |
Transcript showCR:i. |
2601 |
i == 5 ifTrue:[exit value:'thats it']. |
|
2602 |
i := i + 1 |
|
623 | 2603 |
] loopWithExit |
2604 |
" |
|
2605 |
! |
|
2606 |
||
2607 |
repeat |
|
1211 | 2608 |
"repeat the receiver forever - same as loop, for ST-80 compatibility. |
2609 |
(the receiver block should contain a return somewhere)." |
|
623 | 2610 |
|
2611 |
self value. |
|
2612 |
thisContext restart |
|
1211 | 2613 |
|
2614 |
"Modified: 18.4.1996 / 13:50:55 / cg" |
|
623 | 2615 |
! |
2616 |
||
16162 | 2617 |
repeat:n |
18252 | 2618 |
"repeat the receiver n times - similar to timesRepeat, but optionally passes the |
16162 | 2619 |
loop counter as argument" |
2620 |
||
18434 | 2621 |
self argumentCount == 0 ifTrue:[ |
2622 |
n timesRepeat:self |
|
16162 | 2623 |
] ifFalse:[ |
18434 | 2624 |
1 to:n do:self |
16162 | 2625 |
]. |
2626 |
||
2627 |
" |
|
2628 |
[ Transcript showCR:'hello' ] repeat:3 |
|
2629 |
[:i | Transcript showCR:'hello',i printString ] repeat:3 |
|
2630 |
" |
|
2631 |
! |
|
2632 |
||
623 | 2633 |
valueWithExit |
2634 |
"the receiver must be a block of one argument. It is evaluated, and is passed a block, |
|
18252 | 2635 |
which, if sent a value:-message, will exit the receiver block, returning the parameter of the |
623 | 2636 |
value:-message. Used for premature returns to the caller. |
2637 |
Taken from a manchester goody (a similar construct also appears in Self)." |
|
2638 |
||
1211 | 2639 |
^ self value:[:exitValue | ^exitValue] |
623 | 2640 |
|
2641 |
" |
|
2642 |
[:exit | |
|
2238 | 2643 |
1 to:10 do:[:i | |
2644 |
Transcript showCR:i. |
|
2645 |
i == 5 ifTrue:[exit value:'thats it'] |
|
2646 |
]. |
|
2647 |
'regular block-value; never returned' |
|
623 | 2648 |
] valueWithExit |
2649 |
" |
|
1211 | 2650 |
|
2651 |
"Modified: 18.4.1996 / 13:51:38 / cg" |
|
623 | 2652 |
! |
2653 |
||
5215 | 2654 |
valueWithRestart |
14683 | 2655 |
"the receiver must be a block of one argument. It is evaluated, and is passed a block, |
15244 | 2656 |
which, if sent a value-message, will restart the receiver block from the beginning" |
2657 |
||
15316 | 2658 |
|myContext restartAction| |
5215 | 2659 |
|
2660 |
myContext := thisContext. |
|
15320 | 2661 |
restartAction := [ myContext unwindAndRestart ]. |
15316 | 2662 |
^ self value:restartAction. |
5215 | 2663 |
|
2664 |
" |
|
2665 |
[:restart | |
|
18252 | 2666 |
(self confirm:'try again ?') ifTrue:[ |
2667 |
restart value. |
|
2668 |
] |
|
5215 | 2669 |
] valueWithRestart |
2670 |
" |
|
2671 |
||
2672 |
"Modified: / 25.1.2000 / 21:47:50 / cg" |
|
2673 |
! |
|
2674 |
||
14683 | 2675 |
valueWithRestartAndExit |
2676 |
"the receiver must be a block of two arguments, a restart and an exit block. |
|
2677 |
See description of valueWithExit and valueWithRestart for their use" |
|
2678 |
||
15316 | 2679 |
|myContext restartAction| |
14683 | 2680 |
|
2681 |
myContext := thisContext. |
|
15320 | 2682 |
restartAction := [ myContext unwindAndRestart ]. |
15316 | 2683 |
^ self value:restartAction value:[:exitValue | ^exitValue]. |
14683 | 2684 |
|
2685 |
" |
|
2686 |
[:restart :exit | |
|
18252 | 2687 |
|i| |
2688 |
||
2689 |
i := 0. |
|
2690 |
[ |
|
2691 |
i := i + 1. |
|
2692 |
(self confirm:('i is ',i printString,'; start over ?')) ifTrue:[ |
|
2693 |
restart value. |
|
2694 |
]. |
|
2695 |
(self confirm:'enough ?') ifTrue:[ |
|
2696 |
exit value:nil. |
|
2697 |
]. |
|
2698 |
] loop |
|
14683 | 2699 |
] valueWithRestartAndExit |
2700 |
" |
|
2701 |
! |
|
2702 |
||
623 | 2703 |
whileFalse |
2704 |
"evaluate the receiver while it evaluates to false (ST80 compatibility)" |
|
2705 |
||
2706 |
"this implementation is for purists ... :-)" |
|
2707 |
||
2708 |
self value ifTrue:[^ nil]. |
|
2709 |
thisContext restart |
|
2710 |
||
2711 |
" |
|
2712 |
|n| |
|
2713 |
||
2714 |
n := 1. |
|
8602 | 2715 |
[n printCR. (n := n + 1) > 10] whileFalse |
67 | 2716 |
" |
2717 |
! |
|
1 | 2718 |
|
67 | 2719 |
whileFalse:aBlock |
2720 |
"evaluate the argument, aBlock while the receiver evaluates to false. |
|
18252 | 2721 |
- usually open coded by compilers, but needed here for #perform |
67 | 2722 |
and expression evaluation." |
2723 |
||
154 | 2724 |
"this implementation is for purists ... :-)" |
2725 |
||
67 | 2726 |
self value ifTrue:[^ nil]. |
2727 |
aBlock value. |
|
2728 |
thisContext restart |
|
2729 |
||
2730 |
" |
|
2731 |
|n| |
|
2732 |
||
2733 |
n := 1. |
|
2734 |
[n > 10] whileFalse:[ |
|
18252 | 2735 |
n printCR. |
2736 |
n := n + 1 |
|
67 | 2737 |
] |
2738 |
" |
|
1 | 2739 |
! |
2740 |
||
2741 |
whileTrue |
|
67 | 2742 |
"evaluate the receiver while it evaluates to true (ST80 compatibility)" |
1 | 2743 |
|
154 | 2744 |
"this implementation is for purists ... :-)" |
2745 |
||
67 | 2746 |
self value ifFalse:[^ nil]. |
2747 |
thisContext restart |
|
1 | 2748 |
|
67 | 2749 |
" |
2750 |
|n| |
|
1 | 2751 |
|
67 | 2752 |
n := 1. |
8602 | 2753 |
[n printCR. (n := n + 1) <= 10] whileTrue |
67 | 2754 |
" |
1 | 2755 |
! |
2756 |
||
623 | 2757 |
whileTrue:aBlock |
2758 |
"evaluate the argument, aBlock while the receiver evaluates to true. |
|
18252 | 2759 |
- usually open coded by compilers, but needed here for #perform |
623 | 2760 |
and expression evaluation." |
1 | 2761 |
|
154 | 2762 |
"this implementation is for purists ... :-)" |
2763 |
||
623 | 2764 |
self value ifFalse:[^ nil]. |
2765 |
aBlock value. |
|
67 | 2766 |
thisContext restart |
2767 |
||
2768 |
" |
|
2769 |
|n| |
|
1 | 2770 |
|
67 | 2771 |
n := 1. |
623 | 2772 |
[n <= 10] whileTrue:[ |
18252 | 2773 |
n printCR. |
2774 |
n := n + 1 |
|
623 | 2775 |
] |
68 | 2776 |
" |
67 | 2777 |
! ! |
2778 |
||
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2779 |
!Block methodsFor:'parallel evaluation'! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2780 |
|
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2781 |
futureValue |
18252 | 2782 |
"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
|
2783 |
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
|
2784 |
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
|
2785 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2786 |
^ Future new block:self |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2787 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2788 |
|
18252 | 2789 |
futureValue:aValue |
2790 |
"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
|
2791 |
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
|
2792 |
any access to wait until the result is computed." |
18252 | 2793 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2794 |
^ Future new block:self value:aValue |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2795 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2796 |
|
18252 | 2797 |
futureValue:aValue value:anotherValue |
2798 |
"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
|
2799 |
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
|
2800 |
any access to wait until the result is computed." |
18252 | 2801 |
|
2802 |
^ Future new |
|
2803 |
block:self |
|
2804 |
value:aValue |
|
2805 |
value:anotherValue |
|
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2806 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2807 |
|
18252 | 2808 |
futureValue:aValue value:anotherValue value:bValue |
2809 |
"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
|
2810 |
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
|
2811 |
any access to wait until the result is computed." |
18252 | 2812 |
|
2813 |
^ Future new |
|
2814 |
block:self |
|
2815 |
value:aValue |
|
2816 |
value:anotherValue |
|
2817 |
value:bValue |
|
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2818 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2819 |
|
18252 | 2820 |
futureValueWithArguments:anArray |
2821 |
"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
|
2822 |
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
|
2823 |
any access to wait until the result is computed." |
18252 | 2824 |
|
2825 |
^ Future new |
|
2826 |
block:self |
|
2827 |
valueWithArguments:anArray |
|
13767 | 2828 |
|
2829 |
"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
|
2830 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2831 |
|
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2832 |
lazyValue |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2833 |
"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
|
2834 |
the evaluation when the result is requested." |
18252 | 2835 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2836 |
^ Lazy new block:self |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2837 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2838 |
|
18252 | 2839 |
lazyValue:aValue |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2840 |
"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
|
2841 |
the evaluation when the result is requested." |
18252 | 2842 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2843 |
^ Lazy new block:self value:aValue |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2844 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2845 |
|
18252 | 2846 |
lazyValue:aValue value:anotherValue |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2847 |
"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
|
2848 |
the evaluation when the result is requested." |
18252 | 2849 |
|
2850 |
^ Lazy new |
|
2851 |
block:self |
|
2852 |
value:aValue |
|
2853 |
value:anotherValue |
|
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2854 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
2855 |
|
18252 | 2856 |
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
|
2857 |
"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
|
2858 |
the evaluation when the result is requested." |
18252 | 2859 |
|
2860 |
^ Lazy new |
|
2861 |
block:self |
|
2862 |
value:aValue |
|
2863 |
value:anotherValue |
|
2864 |
value:bValue |
|
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 |
|
18252 | 2867 |
lazyValueWithArguments:anArray |
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 valueWithArguments:anArray |
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 |
|
92 | 2874 |
!Block methodsFor:'printing & storing'! |
1 | 2875 |
|
7151 | 2876 |
printBlockBracketsOn:aStream |
18252 | 2877 |
aStream nextPutAll:'[]'. |
7151 | 2878 |
! |
2879 |
||
1 | 2880 |
printOn:aStream |
44 | 2881 |
"append a a printed representation of the block to aStream" |
2882 |
||
6633 | 2883 |
|h sel methodClass| |
54 | 2884 |
|
2885 |
"cheap blocks have no home context, but a method instead" |
|
2886 |
||
2887 |
(home isNil or:[home isContext not]) ifTrue:[ |
|
18252 | 2888 |
aStream nextPutAll:'[] in '. |
2889 |
||
2890 |
" |
|
2891 |
currently, some cheap blocks don't know where they have been created |
|
2892 |
" |
|
2893 |
aStream nextPutAll:' ??? (optimized)'. |
|
2894 |
^ self |
|
54 | 2895 |
]. |
2896 |
||
2897 |
"a full blown block (with home, but without method)" |
|
7151 | 2898 |
self printBlockBracketsOn:aStream. |
18252 | 2899 |
aStream nextPutAll:' in '. |
154 | 2900 |
h := self methodHome. |
2901 |
sel := h selector. |
|
2902 |
"/ old: |
|
2903 |
"/ home receiver class name printOn:aStream. |
|
2904 |
"/ new: |
|
212 | 2905 |
"/ (h searchClass whichClassImplements:sel) name printOn:aStream. |
213 | 2906 |
methodClass := h methodClass. |
2907 |
methodClass isNil ifTrue:[ |
|
18252 | 2908 |
'UnboundMethod' printOn:aStream. |
213 | 2909 |
] ifFalse:[ |
18252 | 2910 |
methodClass name printOn:aStream. |
213 | 2911 |
]. |
7157
935eaabbe6dc
printString now "... in className >> sel"
Claus Gittinger <cg@exept.de>
parents:
7151
diff
changeset
|
2912 |
aStream nextPutAll:'>>'. |
154 | 2913 |
sel printOn:aStream. |
54 | 2914 |
|
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2915 |
"/ |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2916 |
"/ aStream nextPutAll:'[] in '. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2917 |
"/ homeClass := home containingClass. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2918 |
"/ 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
|
2919 |
"/ 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
|
2920 |
"/ aStream space. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2921 |
"/ (homeClass selectorForMethod:home) printOn:aStream |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2922 |
"/ ] ifFalse:[ |
18252 | 2923 |
"/ aStream nextPutAll:' ???' |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2924 |
"/ ] |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
2925 |
"/ |
9253 | 2926 |
! |
2927 |
||
2928 |
storeOn:aStream |
|
15850 | 2929 |
MethodNotAppropriateError raiseRequestErrorString:'Blocks cannot be stored (yet)'. |
9287 | 2930 |
self printOn:aStream. |
1 | 2931 |
! ! |
623 | 2932 |
|
7257 | 2933 |
!Block methodsFor:'private-accessing'! |
623 | 2934 |
|
5766
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
2935 |
byteCode:bCode numArgs:numArgs numVars:numVars numStack:numStack sourcePosition:srcPos initialPC:iPC literals:lits |
1265 | 2936 |
"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
|
2937 |
DANGER ALERT: this interface is strictly private." |
623 | 2938 |
|
2939 |
byteCode := bCode. |
|
2940 |
nargs := numArgs. |
|
2941 |
sourcePos := srcPos. |
|
2942 |
initialPC := iPC. |
|
1777 | 2943 |
flags := 0. |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
2944 |
self stackSize:numStack. |
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
2945 |
self literals:lits. |
5766
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
2946 |
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
|
2947 |
self numberOfVars:numVars. "/ must set the compiledCode flags as well |
1265 | 2948 |
|
2949 |
"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
|
2950 |
"Modified: 24.6.1996 / 12:37:37 / stefan" |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
2951 |
"Created: 13.4.1997 / 00:00:57 / cg" |
623 | 2952 |
! |
2953 |
||
18252 | 2954 |
initialPC |
5779 | 2955 |
"return the initial pc for evaluation." |
2956 |
||
2957 |
^ initialPC |
|
2958 |
! |
|
2959 |
||
18252 | 2960 |
initialPC:initial |
1265 | 2961 |
"set the initial pc for evaluation. |
2962 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 2963 |
|
2964 |
initialPC := initial |
|
1265 | 2965 |
|
2966 |
"Modified: 23.4.1996 / 16:05:39 / cg" |
|
623 | 2967 |
! |
2968 |
||
2969 |
numArgs:numArgs |
|
1265 | 2970 |
"set the number of arguments the receiver expects for evaluation. |
2971 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 2972 |
|
2973 |
nargs := numArgs |
|
1265 | 2974 |
|
2975 |
"Modified: 23.4.1996 / 16:05:52 / cg" |
|
623 | 2976 |
! |
2977 |
||
5744 | 2978 |
setHome:aContext |
2979 |
home := aContext |
|
2980 |
! |
|
2981 |
||
18252 | 2982 |
source |
7323 | 2983 |
|m| |
2984 |
||
2985 |
sourcePos isString ifTrue:[ "/ misuses the sourcePosition slot |
|
18252 | 2986 |
^ sourcePos |
7323 | 2987 |
]. |
2988 |
m := self method. |
|
2989 |
m notNil ifTrue:[ |
|
18252 | 2990 |
^ m source |
7323 | 2991 |
]. |
2992 |
^ nil |
|
2993 |
! |
|
2994 |
||
18252 | 2995 |
source:aString |
6981 | 2996 |
"set the source - only to be used, if the block is not contained in a method. |
2997 |
This interface is for knowledgable users only." |
|
2998 |
||
2999 |
sourcePos := aString "/ misuse the sourcePosition slot |
|
3000 |
! |
|
3001 |
||
18427
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3002 |
sourcePosition |
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3003 |
"Returns the source position withing method's source. |
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3004 |
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
|
3005 |
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
|
3006 |
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
|
3007 |
reason, nil is returned" |
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3008 |
|
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3009 |
^ sourcePos |
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3010 |
|
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3011 |
"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
|
3012 |
|
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3013 |
! |
5866c511fe0b
Added Block>>sourcePosition accessor.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
18317
diff
changeset
|
3014 |
|
18252 | 3015 |
sourcePosition:position |
1265 | 3016 |
"set the position of the source within my method. |
3017 |
This interface is for the compiler only." |
|
623 | 3018 |
|
3019 |
sourcePos := position |
|
1265 | 3020 |
|
3021 |
"Modified: 23.4.1996 / 16:06:19 / cg" |
|
623 | 3022 |
! ! |
3023 |
||
3024 |
!Block methodsFor:'privileged evaluation'! |
|
3025 |
||
3026 |
valueUninterruptably |
|
3027 |
"evaluate the receiver with interrupts blocked. |
|
3028 |
This does not prevent preemption by a higher priority processes |
|
3029 |
if any becomes runnable due to the evaluation of the receiver |
|
3030 |
(i.e. if a semaphore is signalled)." |
|
3031 |
||
2301 | 3032 |
"we must keep track of blocking-state if this is called nested" |
3033 |
(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
|
3034 |
"/ already blocked. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3035 |
^ self value |
2301 | 3036 |
]. |
864 | 3037 |
|
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3038 |
^ self ensure:[OperatingSystem unblockInterrupts]. |
623 | 3039 |
! |
3040 |
||
3041 |
valueUnpreemptively |
|
3042 |
"evaluate the receiver without the possiblity of preemption |
|
3043 |
(i.e. at a very high priority)" |
|
3044 |
||
3045 |
|oldPrio activeProcess| |
|
3046 |
||
3047 |
activeProcess := Processor activeProcess. |
|
3048 |
oldPrio := activeProcess changePriority:(Processor highestPriority). |
|
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3049 |
^ self ensure:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3050 |
activeProcess priority:oldPrio |
623 | 3051 |
] |
3052 |
! ! |
|
3053 |
||
3054 |
!Block methodsFor:'process creation'! |
|
3055 |
||
3056 |
fork |
|
3057 |
"create a new process executing the receiver at the current priority." |
|
3058 |
||
3059 |
^ self newProcess resume |
|
3060 |
! |
|
3061 |
||
3062 |
forkAt:priority |
|
3063 |
"create a new process executing the receiver at a different priority." |
|
3064 |
||
3065 |
^ (self newProcess priority:priority) resume |
|
3066 |
! |
|
3067 |
||
6609 | 3068 |
forkNamed:aString |
18252 | 3069 |
"create a new process, give it a name and let it start |
6609 | 3070 |
executing the receiver at the current priority." |
3071 |
||
3072 |
|newProcess| |
|
3073 |
||
18252 | 3074 |
newProcess := self newProcess. |
6609 | 3075 |
newProcess name:aString. |
3076 |
newProcess resume. |
|
3077 |
^ newProcess. |
|
3078 |
! |
|
3079 |
||
623 | 3080 |
forkWith:argArray |
3081 |
"create a new process executing the receiver, |
|
3082 |
passing elements in argArray as arguments to the receiver block." |
|
3083 |
||
3084 |
^ [self valueWithArguments:argArray] fork. |
|
3085 |
! |
|
3086 |
||
3087 |
newProcess |
|
3088 |
"create a new (unscheduled) process executing the receiver" |
|
3089 |
||
3090 |
^ Process for:self priority:(Processor activePriority) |
|
3091 |
! |
|
3092 |
||
3093 |
newProcessWithArguments:argArray |
|
3094 |
"create a new (unscheduled) process executing the receiver, |
|
3095 |
passing the elements in argArray as arguments to the receiver block." |
|
3096 |
||
3097 |
^ [self valueWithArguments:argArray] newProcess |
|
3098 |
! |
|
3099 |
||
3100 |
promise |
|
3101 |
"create a promise on the receiver. The promise will evaluate the |
|
3102 |
receiver and promise to return the value with the #value message. |
|
3103 |
The evaluation will be performed as a separate process. |
|
3104 |
Asking the promise for its value will either block the asking process |
|
3105 |
(if the evaluation has not yet been finished) or return the value |
|
3106 |
immediately." |
|
3107 |
||
3108 |
^ Promise value:self |
|
3109 |
||
3110 |
" |
|
3111 |
|p| |
|
3112 |
||
3113 |
p := [1000 factorial] promise. |
|
3114 |
'do something else ...'. |
|
3115 |
p value |
|
3116 |
" |
|
3117 |
! |
|
3118 |
||
3119 |
promiseAt:prio |
|
3120 |
"create a promise on the receiver. The promise will evaluate the |
|
3121 |
receiver and promise to return the value with the #value message. |
|
3122 |
The evaluation will be performed as a separate process running at prio. |
|
3123 |
Asking the promise for its value will either block the asking process |
|
3124 |
(if the evaluation has not yet been finished) or return the value |
|
3125 |
immediately." |
|
3126 |
||
3127 |
^ Promise value:self priority:prio |
|
3128 |
! ! |
|
3129 |
||
3130 |
!Block methodsFor:'testing'! |
|
3131 |
||
3132 |
isBlock |
|
3133 |
"return true, if this is a block - yes I am" |
|
3134 |
||
3135 |
^ true |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3136 |
! |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3137 |
|
16276 | 3138 |
isCheapBlock |
3139 |
^ false |
|
3140 |
! |
|
3141 |
||
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3142 |
isVarArgBlock |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3143 |
"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
|
3144 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3145 |
^ false |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3146 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
3147 |
"Created: 23.1.1997 / 04:59:51 / cg" |
623 | 3148 |
! ! |
3149 |
||
3150 |
!Block methodsFor:'unwinding'! |
|
3151 |
||
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3152 |
unwindHandlerInContext:aContext |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3153 |
"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
|
3154 |
retrieve the handler block. |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3155 |
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
|
3156 |
#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
|
3157 |
methods to be added)" |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3158 |
|
11338 | 3159 |
|selector| |
3160 |
||
3161 |
selector := aContext selector. |
|
3162 |
selector == #'value:onUnwindDo:' ifTrue:[ |
|
18959 | 3163 |
^ aContext argAt:2 |
4896 | 3164 |
]. |
18959 | 3165 |
(selector == #'on:do:ensure:' |
3166 |
or:[selector == #'on:do:ifCurtailed:'])ifTrue:[ |
|
3167 |
^ aContext argAt:3 |
|
11338 | 3168 |
]. |
4896 | 3169 |
|
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3170 |
"/ for now, only #valueNowOrOnUnwindDo: |
4896 | 3171 |
"/ or #valueOnUnwindDo: |
5666
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
3172 |
"/ or #ensure: |
6608 | 3173 |
"/ or #ifCurtailed: |
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3174 |
|
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3175 |
^ aContext argAt:1 |
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3176 |
! ! |
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3177 |
|
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3178 |
!Block methodsFor:'unwinding-old'! |
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
3179 |
|
4896 | 3180 |
value:arg onUnwindDo:aBlock |
3181 |
"evaluate the receiver, passing it one argument |
|
3182 |
- when some method sent within unwinds (i.e. does |
|
3183 |
a long return), evaluate the argument, aBlock. |
|
3184 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
3185 |
executed regardless of error actions" |
|
3186 |
||
3187 |
<exception: #unwind> |
|
3188 |
||
3189 |
|v| |
|
3190 |
||
3191 |
"/ thisContext markForUnwind. -- same as above pragma |
|
3192 |
v := self value:arg. "the real logic is in Context>>unwind" |
|
3193 |
thisContext unmarkForUnwind. |
|
3194 |
^ v |
|
3195 |
||
3196 |
" |
|
3197 |
|s| |
|
3198 |
||
3199 |
s := 'Makefile' asFilename readStream. |
|
3200 |
[:arg | |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3201 |
^ self |
4896 | 3202 |
] 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
|
3203 |
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
|
3204 |
s close |
4896 | 3205 |
] |
3206 |
" |
|
3207 |
" |
|
3208 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3209 |
|s| |
4896 | 3210 |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3211 |
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
|
3212 |
[:arg | |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3213 |
Processor activeProcess terminate |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3214 |
] value:12345 onUnwindDo:[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3215 |
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
|
3216 |
s close |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3217 |
] |
4896 | 3218 |
] fork |
3219 |
" |
|
3220 |
||
3221 |
! |
|
3222 |
||
623 | 3223 |
valueNowOrOnUnwindDo:aBlock |
3224 |
"evaluate the receiver - after that, or when some method sent within unwinds (i.e. does |
|
3225 |
a long return), evaluate the argument, aBlock. |
|
3226 |
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
|
3227 |
executed regardless of error actions. |
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3228 |
Same as the more modern #ensure:" |
623 | 3229 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
3230 |
<exception: #unwind> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
3231 |
|
623 | 3232 |
|v| |
3233 |
||
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
3234 |
"/ thisContext markForUnwind. -- same as above pragma |
623 | 3235 |
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
|
3236 |
thisContext unmarkForUnwind. |
623 | 3237 |
aBlock value. |
3238 |
^ v |
|
3239 |
||
3240 |
" |
|
3241 |
in the following example, f will be closed even if the block |
|
3242 |
returns with 'oops'. There are many more applications of this kind |
|
3243 |
found in the system. |
|
3244 |
" |
|
3245 |
" |
|
3246 |
|f| |
|
3247 |
||
3248 |
f := 'Makefile' asFilename readStream. |
|
3249 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3250 |
l := f nextLine. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3251 |
l isNil ifTrue:[^ 'oops'] |
623 | 3252 |
] valueNowOrOnUnwindDo:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3253 |
f close |
623 | 3254 |
] |
3255 |
" |
|
1187
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
3256 |
|
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
3257 |
"Modified: 16.4.1996 / 11:05:26 / stefan" |
623 | 3258 |
! |
3259 |
||
3260 |
valueOnUnwindDo:aBlock |
|
3261 |
"evaluate the receiver - when some method sent within unwinds (i.e. does |
|
3262 |
a long return), evaluate the argument, aBlock. |
|
3263 |
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
|
3264 |
executed regardless of error actions |
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
3265 |
Same as the more modern #ifCurtailed:" |
623 | 3266 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
3267 |
<exception: #unwind> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
3268 |
|
2286 | 3269 |
|v| |
3270 |
||
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
3271 |
"/ thisContext markForUnwind. -- same as above pragma |
2286 | 3272 |
v := self value. "the real logic is in Context>>unwind" |
3273 |
thisContext unmarkForUnwind. |
|
3274 |
^ v |
|
3275 |
||
4896 | 3276 |
" |
3277 |
|s| |
|
3278 |
||
3279 |
s := 'Makefile' asFilename readStream. |
|
3280 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3281 |
^ self |
4896 | 3282 |
] valueOnUnwindDo:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3283 |
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
|
3284 |
s close |
4896 | 3285 |
] |
3286 |
" |
|
3287 |
" |
|
3288 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3289 |
|s| |
4896 | 3290 |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3291 |
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
|
3292 |
[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3293 |
Processor activeProcess terminate |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3294 |
] valueOnUnwindDo:[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3295 |
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
|
3296 |
s close |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
3297 |
] |
4896 | 3298 |
] fork |
3299 |
" |
|
623 | 3300 |
! ! |
3301 |
||
8394
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3302 |
!Block methodsFor:'visiting'! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3303 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3304 |
acceptVisitor:aVisitor with:aParameter |
16730 | 3305 |
"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
|
3306 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3307 |
^ aVisitor visitBlock:self with:aParameter |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3308 |
! ! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
3309 |
|
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
3310 |
!Block class methodsFor:'documentation'! |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3311 |
|
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3312 |
version |
18959 | 3313 |
^ '$Header$' |
12118
41ee8ff1908e
comment/format in: #deferredValue
Claus Gittinger <cg@exept.de>
parents:
11998
diff
changeset
|
3314 |
! |
41ee8ff1908e
comment/format in: #deferredValue
Claus Gittinger <cg@exept.de>
parents:
11998
diff
changeset
|
3315 |
|
41ee8ff1908e
comment/format in: #deferredValue
Claus Gittinger <cg@exept.de>
parents:
11998
diff
changeset
|
3316 |
version_CVS |
18959 | 3317 |
^ '$Header$' |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
3318 |
! ! |
6785 | 3319 |
|
14683 | 3320 |
|
623 | 3321 |
Block initialize! |