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