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