author | Stefan Vogel <sv@exept.de> |
Wed, 26 Jan 2005 15:02:39 +0100 | |
changeset 8708 | fd7eba3420e1 |
parent 8682 | 3bbf34191ca2 |
child 8723 | ff9b4eb01fae |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
154 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
5349 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
4299 | 15 |
CompiledCode variableSubclass:#Block |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
16 |
instanceVariableNames:'home nargs sourcePos initialPC' |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
17 |
classVariableNames:'InvalidNewSignal' |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
18 |
poolDictionaries:'' |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
19 |
category:'Kernel-Methods' |
1 | 20 |
! |
21 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
22 |
!Block class methodsFor:'documentation'! |
1 | 23 |
|
92 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
154 | 27 |
All Rights Reserved |
92 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
1 | 38 |
documentation |
39 |
" |
|
67 | 40 |
Blocks are pieces of executable code which can be evaluated by sending |
41 |
them a value-message (''value'', ''value:'', ''value:value:'' etc). |
|
1 | 42 |
|
1265 | 43 |
In smalltalk, Blocks provide the basic (and heavily used) mechanism |
44 |
for looping, enumerating collection elements, visitors, exception |
|
45 |
handling, unwinding, delayed execution and processes. |
|
46 |
||
1254 | 47 |
Blocks are never created explicitely; the only creation |
48 |
is done by the compilers, when some sourceCode is compiled to either |
|
49 |
machine or byteCode. |
|
50 |
||
67 | 51 |
Blocks with arguments need a message of type ''value:arg1 ... value:argn'' |
52 |
for evaluation; the number of arguments passed when evaluating must match |
|
53 |
the number of arguments the block was declared with otherwise an error is |
|
54 |
raised. Blocks without args need a ''value'' message for evaluation. |
|
1 | 55 |
|
154 | 56 |
Blocks keep a reference to the context where the block was declared - |
67 | 57 |
this allows blocks to access the methods arguments and/or variables. |
154 | 58 |
This is still true after the method has returned - since the |
67 | 59 |
block keeps this reference, the methods context will NOT die in this case. |
222 | 60 |
(i.e. Blocks are closures in Smalltalk/X) |
1 | 61 |
|
67 | 62 |
A return (via ^-statement) out of a block will force a return from the |
63 |
blocks method context (if it is still living) - this make the implementation |
|
64 |
of long-jumps and control structures possible. |
|
154 | 65 |
(If the method is not alive (i.e. has already returned), a return out of the |
66 |
block will trigger an error) |
|
1 | 67 |
|
67 | 68 |
Long-jump is done by defining a catchBlock as ''[^ self]'' |
69 |
somewhere up in the calling-tree. Then, to do the long-jump from out of some |
|
70 |
deeply nested method, simply do: ''catchBlock value''. |
|
1 | 71 |
|
1293 | 72 |
[Instance variables:] |
1 | 73 |
|
222 | 74 |
home <Context> the context where this block was created (i.e. defined) |
2238 | 75 |
this may be a blockContext or a methodContext |
222 | 76 |
nargs <SmallInteger> the number of arguments the block expects |
77 |
sourcePos <SmallInteger> the character position of its source, in chars |
|
2238 | 78 |
relative to methods source beginning |
222 | 79 |
initialPC <SmallInteger> the start position within the byteCode |
2238 | 80 |
for compiled blocks, this is nil. |
222 | 81 |
|
82 |
||
1293 | 83 |
[Class variables:] |
222 | 84 |
|
85 |
InvalidNewSignal raised if a Block is tried to be created |
|
2238 | 86 |
with new (which is not allowed). |
87 |
Only the VM is allowed to create Blocks. |
|
1 | 88 |
|
1293 | 89 |
|
67 | 90 |
NOTICE: layout known by runtime system and compiler - do not change |
1293 | 91 |
|
92 |
[author:] |
|
2238 | 93 |
Claus Gittinger |
1293 | 94 |
|
95 |
[see also:] |
|
2238 | 96 |
Process Context |
97 |
Collection |
|
98 |
( contexts. blocks & unwinding : programming/contexts.html) |
|
1 | 99 |
" |
1265 | 100 |
! |
101 |
||
102 |
examples |
|
103 |
" |
|
1293 | 104 |
define a block and evaluate it: |
2238 | 105 |
[exBegin] |
106 |
|b| |
|
1265 | 107 |
|
2238 | 108 |
b := [ Transcript showCR:'hello' ]. |
1293 | 109 |
|
2238 | 110 |
Transcript showCR:'now evaluating the block ...'. |
111 |
b value. |
|
112 |
[exEnd] |
|
1265 | 113 |
|
114 |
||
1293 | 115 |
|
1265 | 116 |
even here, blocks are involved: |
117 |
(although, the compiler optimizes things if possible) |
|
2238 | 118 |
[exBegin] |
119 |
Transcript showCR:'now evaluating one of two blocks ...'. |
|
120 |
1 > 4 ifTrue:[ |
|
121 |
Transcript showCR:'foo' |
|
122 |
] ifFalse:[ |
|
123 |
Transcript showCR:'bar' |
|
124 |
] |
|
125 |
[exEnd] |
|
1265 | 126 |
|
127 |
||
1293 | 128 |
|
1265 | 129 |
here things become obvious: |
2238 | 130 |
[exBegin] |
131 |
|yesBlock noBlock| |
|
1265 | 132 |
|
2238 | 133 |
yesBlock := [ Transcript showCR:'foo' ]. |
134 |
noBlock := [ Transcript showCR:'bar' ]. |
|
1265 | 135 |
|
2238 | 136 |
Transcript showCR:'now evaluating one of two blocks ...'. |
137 |
1 > 4 ifTrue:yesBlock |
|
138 |
ifFalse:noBlock |
|
139 |
[exEnd] |
|
1265 | 140 |
|
141 |
||
1293 | 142 |
|
1265 | 143 |
simple loops: |
144 |
not very objectOriented: |
|
2238 | 145 |
[exBegin] |
146 |
|i| |
|
1265 | 147 |
|
2238 | 148 |
i := 1. |
149 |
[i < 10] whileTrue:[ |
|
150 |
Transcript showCR:i. |
|
151 |
i := i + 1 |
|
152 |
] |
|
153 |
[exEnd] |
|
1265 | 154 |
|
155 |
||
156 |
using integer protocol: |
|
2238 | 157 |
[exBegin] |
158 |
1 to:10 do:[:i | |
|
159 |
Transcript showCR:i. |
|
160 |
] |
|
161 |
[exEnd] |
|
1265 | 162 |
|
163 |
||
164 |
interval protocol: |
|
2238 | 165 |
[exBegin] |
166 |
(1 to:10) do:[:i | |
|
167 |
Transcript showCR:i. |
|
168 |
] |
|
169 |
[exEnd] |
|
1265 | 170 |
|
171 |
||
1293 | 172 |
|
1265 | 173 |
looping over collections: |
174 |
||
1293 | 175 |
bad code: |
176 |
(only works with numeric-indexable collections) |
|
2238 | 177 |
[exBegin] |
178 |
|i coll| |
|
1265 | 179 |
|
2238 | 180 |
coll := #(9 8 7 6 5). |
181 |
i := 1. |
|
182 |
[i <= coll size] whileTrue:[ |
|
183 |
Transcript showCR:(coll at:i). |
|
184 |
i := i + 1. |
|
185 |
] |
|
186 |
[exEnd] |
|
1265 | 187 |
|
188 |
||
189 |
||
1293 | 190 |
just as bad (well, marginally better ;-): |
191 |
(only works with numeric-indexable collections) |
|
2238 | 192 |
[exBegin] |
193 |
|coll| |
|
1265 | 194 |
|
2238 | 195 |
coll := #(9 8 7 6 5). |
196 |
1 to:coll size do:[:i | |
|
197 |
Transcript showCR:(coll at:i). |
|
198 |
] |
|
199 |
[exEnd] |
|
1265 | 200 |
|
201 |
||
202 |
||
1293 | 203 |
the smalltalk way: |
204 |
(works with any collection) |
|
2238 | 205 |
[exBegin] |
206 |
|coll| |
|
1265 | 207 |
|
2238 | 208 |
coll := #(9 8 7 6 5). |
209 |
coll do:[:element | |
|
210 |
Transcript showCR:element. |
|
211 |
] |
|
212 |
[exEnd] |
|
1265 | 213 |
|
214 |
Rule: use enumeration protocol of the collection instead of |
|
2238 | 215 |
manually indexing it. [with few exceptions] |
1265 | 216 |
|
217 |
||
218 |
||
219 |
processes: |
|
220 |
||
221 |
forking a lightweight process (thread): |
|
2238 | 222 |
[exBegin] |
223 |
[ |
|
224 |
Transcript showCR:'waiting ...'. |
|
225 |
Delay waitForSeconds:2. |
|
226 |
Transcript showCR:'here I am'. |
|
227 |
] fork |
|
228 |
[exEnd] |
|
1265 | 229 |
|
230 |
||
231 |
||
232 |
some with low prio: |
|
2238 | 233 |
[exBegin] |
234 |
[ |
|
235 |
Transcript showCR:'computing ...'. |
|
236 |
10000 factorial. |
|
237 |
Transcript showCR:'here I am'. |
|
238 |
] forkAt:(Processor userBackgroundPriority) |
|
239 |
[exEnd] |
|
1265 | 240 |
|
241 |
||
1293 | 242 |
|
243 |
handling exceptions: |
|
2238 | 244 |
[exBegin] |
245 |
Object errorSignal handle:[:ex | |
|
246 |
Transcript showCR:'exception handler forces return'. |
|
247 |
ex return |
|
248 |
] do:[ |
|
249 |
Transcript showCR:'now, doing something bad ...'. |
|
250 |
1 / 0. |
|
251 |
Transcript showCR:'not reached' |
|
252 |
] |
|
253 |
[exEnd] |
|
1265 | 254 |
|
255 |
||
1293 | 256 |
|
257 |
performing cleanup actions: |
|
2238 | 258 |
[exBegin] |
259 |
Object errorSignal handle:[:ex | |
|
260 |
Transcript showCR:'exception handler forces return'. |
|
261 |
ex return |
|
262 |
] do:[ |
|
263 |
[ |
|
264 |
Transcript showCR:'doing something bad ...'. |
|
265 |
1 / 0. |
|
266 |
Transcript showCR:'not reached' |
|
267 |
] valueOnUnwindDo:[ |
|
268 |
Transcript showCR:'cleanup' |
|
269 |
] |
|
270 |
] |
|
271 |
[exEnd] |
|
1265 | 272 |
|
273 |
||
1293 | 274 |
delayed execution (visitor pattern): |
275 |
(looking carefully into the example, |
|
276 |
C/C++ programmers may raise their eyes ;-) |
|
2238 | 277 |
[exBegin] |
278 |
|showBlock countBlock |
|
279 |
howMany |
|
280 |
top panel b1 b2| |
|
1265 | 281 |
|
2238 | 282 |
howMany := 0. |
1265 | 283 |
|
2238 | 284 |
showBlock := [ Transcript showCR:howMany ]. |
285 |
countBlock := [ howMany := howMany + 1 ]. |
|
1265 | 286 |
|
2238 | 287 |
top := StandardSystemView extent:200@200. |
288 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
1265 | 289 |
|
2238 | 290 |
b1 := Button label:'count up' in:panel. |
291 |
b1 action:countBlock. |
|
1265 | 292 |
|
2238 | 293 |
b2 := Button label:'show value' in:panel. |
294 |
b2 action:showBlock. |
|
1265 | 295 |
|
2238 | 296 |
top open. |
1265 | 297 |
|
2238 | 298 |
Transcript showCR:'new process started;'. |
299 |
Transcript showCR:'notice: the blocks can still access the'. |
|
300 |
Transcript showCR:' howMany local variable.'. |
|
301 |
[exEnd] |
|
1265 | 302 |
" |
1 | 303 |
! ! |
304 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
305 |
!Block class methodsFor:'initialization'! |
1 | 306 |
|
307 |
initialize |
|
1254 | 308 |
"create signals raised by various errors" |
1 | 309 |
|
48 | 310 |
InvalidNewSignal isNil ifTrue:[ |
7092
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
6981
diff
changeset
|
311 |
InvalidNewSignal := Error newSignalMayProceed:false. |
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
6981
diff
changeset
|
312 |
InvalidNewSignal nameClass:self message:#invalidNewSignal. |
630807cd320f
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
6981
diff
changeset
|
313 |
InvalidNewSignal notifierString:'blocks are only created by the system'. |
48 | 314 |
] |
1254 | 315 |
|
316 |
"Modified: 22.4.1996 / 16:34:20 / cg" |
|
1 | 317 |
! ! |
318 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
319 |
!Block class methodsFor:'instance creation'! |
1 | 320 |
|
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
321 |
byteCode:bCode numArgs:numArgs numStack:nStack sourcePosition:sourcePos initialPC:initialPC literals:literals |
1 | 322 |
"create a new cheap (homeless) block. |
222 | 323 |
Not for public use - this is a special hook for the compiler." |
1 | 324 |
|
5766
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
325 |
^ self |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
326 |
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
|
327 |
! |
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
328 |
|
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
329 |
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
|
330 |
"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
|
331 |
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
|
332 |
|
1 | 333 |
|newBlock| |
334 |
||
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
335 |
newBlock := (super basicNew:(literals size)) |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
336 |
byteCode:bCode |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
337 |
numArgs:numArgs |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
338 |
numVars:numVars |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
339 |
numStack:nStack |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
340 |
sourcePosition:sourcePos |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
341 |
initialPC:initialPC |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
342 |
literals:literals. |
1 | 343 |
^ newBlock |
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
344 |
|
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
345 |
"Modified: 24.6.1996 / 12:36:48 / stefan" |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
346 |
"Created: 13.4.1997 / 00:04:09 / cg" |
1 | 347 |
! |
348 |
||
22 | 349 |
new |
4299 | 350 |
"catch creation of blocks - only the system creates blocks. |
351 |
If you really need a block (assuming, you are some compiler), |
|
352 |
use basicNew and setup the instance carefully" |
|
1 | 353 |
|
128 | 354 |
^ InvalidNewSignal raise. |
1 | 355 |
! |
356 |
||
22 | 357 |
new:size |
1 | 358 |
"catch creation of blocks - only the system creates blocks" |
359 |
||
128 | 360 |
^ InvalidNewSignal raise. |
1 | 361 |
! ! |
362 |
||
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
363 |
!Block class methodsFor:'queries'! |
1 | 364 |
|
623 | 365 |
isBuiltInClass |
1264 | 366 |
"return true if this class is known by the run-time-system. |
367 |
Here, true is returned for myself, false for subclasses." |
|
11 | 368 |
|
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
369 |
^ self == Block |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
370 |
|
1264 | 371 |
"Modified: 23.4.1996 / 15:55:58 / cg" |
1 | 372 |
! ! |
373 |
||
7261 | 374 |
!Block methodsFor:'Compatibility-ANSI'! |
5349 | 375 |
|
5944 | 376 |
argumentCount |
7352 | 377 |
"VisualAge/ANSI compatibility: alias for #numArgs. |
5944 | 378 |
return the number of arguments I expect for evaluation" |
379 |
||
380 |
^ nargs |
|
381 |
||
382 |
"Created: 15.11.1996 / 11:22:02 / cg" |
|
383 |
! |
|
384 |
||
5349 | 385 |
ensure:aBlock |
386 |
"evaluate the receiver and return its result. |
|
387 |
After evaluation, also evaluate aBlock but ignore its result. |
|
388 |
aBlock is also evaluated in case of abnormal termination. |
|
389 |
(the same as #valueNowOrOnUnwindDo:)" |
|
390 |
||
5666
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
391 |
<exception: #unwind> |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
392 |
|
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
393 |
|v| |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
394 |
|
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
395 |
v := self value. "the real logic is in Context>>unwind" |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
396 |
thisContext unmarkForUnwind. |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
397 |
aBlock value. |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
398 |
^ v |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
399 |
|
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
400 |
"/ the above is the same as in #valueNowOrOnUnwindDo: |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
401 |
"/ (actually, the previous implementation was: |
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
402 |
"/ ^ self valueNowOrOnUnwindDo:aBlock |
5349 | 403 |
|
404 |
" |
|
405 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
406 |
[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
407 |
Transcript showCR:'one'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
408 |
Processor activeProcess terminate. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
409 |
Transcript showCR:'two'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
410 |
] ensure:[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
411 |
Transcript showCR:'three'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
412 |
]. |
5349 | 413 |
] fork. |
414 |
" |
|
415 |
||
416 |
" |
|
417 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
418 |
[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
419 |
Transcript showCR:'one'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
420 |
Transcript showCR:'two'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
421 |
] ensure:[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
422 |
Transcript showCR:'three'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
423 |
]. |
5349 | 424 |
] fork. |
425 |
" |
|
5951 | 426 |
! |
427 |
||
428 |
ifCurtailed:aBlock |
|
429 |
"evaluate the receiver - when some method sent within unwinds (i.e. does |
|
430 |
a long return), evaluate the argument, aBlock. |
|
431 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
432 |
executed regardless of error actions. |
|
433 |
This is the same as #valueOnUnwindDo:" |
|
434 |
||
435 |
<exception: #unwind> |
|
436 |
||
437 |
|v| |
|
438 |
||
439 |
"/ thisContext markForUnwind. -- same as above pragma |
|
440 |
v := self value. "the real logic is in Context>>unwind" |
|
441 |
thisContext unmarkForUnwind. |
|
442 |
^ v |
|
443 |
||
444 |
" |
|
445 |
|s| |
|
446 |
||
447 |
s := 'Makefile' asFilename readStream. |
|
448 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
449 |
^ self |
5951 | 450 |
] ifCurtailed:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
451 |
Transcript showCR:'closing the stream - even though a return occurred'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
452 |
s close |
5951 | 453 |
] |
454 |
" |
|
455 |
" |
|
456 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
457 |
|s| |
5951 | 458 |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
459 |
s := 'Makefile' asFilename readStream. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
460 |
[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
461 |
Processor activeProcess terminate |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
462 |
] ifCurtailed:[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
463 |
Transcript showCR:'closing the stream - even though process was terminated'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
464 |
s close |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
465 |
] |
5951 | 466 |
] fork |
467 |
" |
|
5349 | 468 |
! ! |
469 |
||
8440
66d126056d3d
Dolphin compatibility: #deferredValue
Stefan Vogel <sv@exept.de>
parents:
8394
diff
changeset
|
470 |
!Block methodsFor:'Compatibility-Dolphin'! |
66d126056d3d
Dolphin compatibility: #deferredValue
Stefan Vogel <sv@exept.de>
parents:
8394
diff
changeset
|
471 |
|
66d126056d3d
Dolphin compatibility: #deferredValue
Stefan Vogel <sv@exept.de>
parents:
8394
diff
changeset
|
472 |
deferredValue |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
473 |
"doplphin's alias for futureValue" |
8440
66d126056d3d
Dolphin compatibility: #deferredValue
Stefan Vogel <sv@exept.de>
parents:
8394
diff
changeset
|
474 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
475 |
^ self futureValue |
8440
66d126056d3d
Dolphin compatibility: #deferredValue
Stefan Vogel <sv@exept.de>
parents:
8394
diff
changeset
|
476 |
! ! |
66d126056d3d
Dolphin compatibility: #deferredValue
Stefan Vogel <sv@exept.de>
parents:
8394
diff
changeset
|
477 |
|
7261 | 478 |
!Block methodsFor:'Compatibility-Squeak'! |
5015 | 479 |
|
480 |
ifError:handlerBlock |
|
6159
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
481 |
"same as onError: - for squeak compatibility. |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
482 |
Notice, that the handlerBlock may take 0,1 or 2 args. |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
483 |
(1 arg -> the exception; |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
484 |
2 args -> the errorString and the erronous receiver)" |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
485 |
|
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
486 |
handlerBlock numArgs == 1 ifTrue:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
487 |
^ 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
|
488 |
]. |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
489 |
|
6142 | 490 |
^ self |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
491 |
on:Error |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
492 |
do:[:ex | |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
493 |
|errString errReceiver| |
6142 | 494 |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
495 |
handlerBlock numArgs == 0 ifTrue:[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
496 |
ex return:handlerBlock value |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
497 |
]. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
498 |
errString := ex description. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
499 |
errReceiver := ex suspendedContext receiver. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
500 |
ex return:(handlerBlock value:errString value:errReceiver) |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
501 |
] |
6142 | 502 |
|
503 |
" |
|
504 |
|a| |
|
505 |
||
506 |
a := 0. |
|
507 |
[ 123 / a ] ifError:[:msg :rec | self halt] |
|
508 |
" |
|
6159
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
509 |
|
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
510 |
" |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
511 |
|a| |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
512 |
|
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
513 |
a := 0. |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
514 |
[ 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
|
515 |
" |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
516 |
|
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
517 |
" |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
518 |
|a| |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
519 |
|
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
520 |
a := 0. |
33d75f51cf24
support 0, 1 or 2-arg handler blocks in #ifError:
Claus Gittinger <cg@exept.de>
parents:
6142
diff
changeset
|
521 |
[ 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
|
522 |
" |
5015 | 523 |
! ! |
524 |
||
7261 | 525 |
!Block methodsFor:'Compatibility-V''Age'! |
1979 | 526 |
|
527 |
valueOnReturnDo:aBlock |
|
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
528 |
"VisualAge compatibility: alias for #ifCurtailed: |
1979 | 529 |
evaluate the receiver - when some method sent within unwinds |
530 |
(i.e. does a long return), evaluate the argument, aBlock. |
|
531 |
This is used to make certain that cleanup actions |
|
532 |
(for example closing files etc.) are executed regardless of error actions. |
|
533 |
||
534 |
Q: is this the exact semantics of V'Ages method ? |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
535 |
the documentation is unclean; it could be a valueNowOrOnUnwindDo: ..." |
1979 | 536 |
|
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
537 |
^ self ifCurtailed:aBlock |
1979 | 538 |
|
539 |
"Created: 15.11.1996 / 11:38:37 / cg" |
|
540 |
! ! |
|
541 |
||
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
542 |
!Block methodsFor:'accessing'! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
543 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
544 |
home |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
545 |
"return the receivers home context (the context where it was |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
546 |
created). For cheap blocks, nil is returned" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
547 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
548 |
^ home |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
549 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
550 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
551 |
homeMethod |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
552 |
"return the receivers home method. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
553 |
Thats the method where the block was created." |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
554 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
555 |
home notNil ifTrue:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
556 |
^ home method |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
557 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
558 |
^ nil |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
559 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
560 |
"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
|
561 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
562 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
563 |
method |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
564 |
"return the receivers method |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
565 |
(the method where the block was created). |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
566 |
Obsolete: use #homeMethod for ST80 compatibility." |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
567 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
568 |
<resource: #obsolete> |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
569 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
570 |
^ self homeMethod |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
571 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
572 |
"Modified: 19.6.1997 / 16:15:24 / cg" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
573 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
574 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
575 |
methodHome |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
576 |
"return the receivers method home context (the context where it was |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
577 |
defined). For cheap blocks, nil is returned" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
578 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
579 |
home notNil ifTrue:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
580 |
^ home methodHome |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
581 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
582 |
^ nil |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
583 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
584 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
585 |
numArgs |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
586 |
"return the number of arguments I expect for evaluation. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
587 |
Please use argumentCount, which is ANSI" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
588 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
589 |
"/ <resource: #obsolete> |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
590 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
591 |
^ nargs |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
592 |
! ! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
593 |
|
5931
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
594 |
!Block methodsFor:'binary storage'! |
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
595 |
|
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
596 |
storeBinaryDefinitionOn:stream manager:manager |
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
597 |
byteCode isNil ifTrue:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
598 |
self error:'cannot preserve semantics of block'. |
5931
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
599 |
]. |
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
600 |
^ super storeBinaryDefinitionOn:stream manager:manager |
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
601 |
! ! |
9e40d7255c26
check for nil signal in #handle:do:
Claus Gittinger <cg@exept.de>
parents:
5779
diff
changeset
|
602 |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
603 |
!Block methodsFor:'conversion'! |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
604 |
|
5349 | 605 |
asVarArgBlock |
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
606 |
"convert myself into a varArg block; |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
607 |
this one has 1 formal argument, which gets the list |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
608 |
of actual arguments when evaluated." |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
609 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
610 |
nargs ~~ 1 ifTrue:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
611 |
self error:'vararg blocks must take exactly 1 argument - the arg list'. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
612 |
^ nil |
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
613 |
]. |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
614 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
615 |
self changeClassTo:VarArgBlock. |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
616 |
^ self |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
617 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
618 |
" |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
619 |
|b| |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
620 |
|
5349 | 621 |
b := [:argList | Transcript |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
622 |
show:'invoked with args:'; |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
623 |
showCR:argList |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
624 |
] asVarArgBlock. |
5349 | 625 |
b value. |
626 |
b value:'arg1'. |
|
627 |
b value:'arg1' value:'arg2' value:'arg3' value:'arg4' |
|
628 |
" |
|
629 |
||
630 |
"Created: 23.1.1997 / 13:35:28 / cg" |
|
631 |
"Modified: 23.1.1997 / 13:35:48 / cg" |
|
632 |
! |
|
633 |
||
7151 | 634 |
beCurryingBlock |
635 |
"make myself a currying block; |
|
636 |
thats a block which, if invoked with less-than-expected arguments, |
|
637 |
returns another block which provides the provided argument(s) and expects the remaining args. |
|
638 |
Read any book on functional programming, if you dont understand this." |
|
639 |
||
640 |
self changeClassTo:CurryingBlock. |
|
641 |
^ self |
|
642 |
! |
|
643 |
||
5349 | 644 |
beVarArg |
645 |
"convert myself into a varArg block; |
|
646 |
this one has 1 formal argument, which gets the list |
|
647 |
of actual arguments when evaluated." |
|
648 |
||
649 |
^ self asVarArgBlock. |
|
650 |
||
651 |
" |
|
652 |
|b| |
|
653 |
||
2241 | 654 |
b := [:argList | argList printCR] beVarArg. |
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
655 |
b value. |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
656 |
b value:'arg1' value:'arg2' value:'arg3' value:'arg4' |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
657 |
" |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
658 |
|
2241 | 659 |
"Created: 23.1.1997 / 13:35:28 / cg" |
660 |
"Modified: 23.1.1997 / 13:35:48 / cg" |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
661 |
! ! |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
662 |
|
623 | 663 |
!Block methodsFor:'copying'! |
1 | 664 |
|
3349
84a92126a268
must catch #deppCopyUsing: instead of #deepCopy.
Claus Gittinger <cg@exept.de>
parents:
2841
diff
changeset
|
665 |
deepCopyUsing:aDictionary |
623 | 666 |
"raise an error - deepCopy is not allowed for blocks" |
1 | 667 |
|
8638 | 668 |
home isNil ifTrue:[ |
669 |
^ super deepCopyUsing:aDictionary |
|
670 |
]. |
|
623 | 671 |
^ self deepCopyError |
3349
84a92126a268
must catch #deppCopyUsing: instead of #deepCopy.
Claus Gittinger <cg@exept.de>
parents:
2841
diff
changeset
|
672 |
|
84a92126a268
must catch #deppCopyUsing: instead of #deepCopy.
Claus Gittinger <cg@exept.de>
parents:
2841
diff
changeset
|
673 |
"Created: / 31.3.1998 / 15:46:17 / cg" |
1 | 674 |
! ! |
675 |
||
676 |
!Block methodsFor:'error handling'! |
|
677 |
||
328 | 678 |
invalidCodeObject |
1874 | 679 |
"{ Pragma: +optSpace }" |
680 |
||
67 | 681 |
"this error is triggered by the interpreter when a non-Block object |
682 |
is about to be executed. |
|
683 |
In this case, the VM sends this to the bad method (the receiver). |
|
684 |
Can only happen when the Compiler/runtime system is broken or |
|
685 |
someone played around." |
|
1 | 686 |
|
7602
d048f13cd50a
Exception classes initialize themself.
Stefan Vogel <sv@exept.de>
parents:
7352
diff
changeset
|
687 |
^ InvalidCodeError |
d048f13cd50a
Exception classes initialize themself.
Stefan Vogel <sv@exept.de>
parents:
7352
diff
changeset
|
688 |
raiseRequestWith:self |
d048f13cd50a
Exception classes initialize themself.
Stefan Vogel <sv@exept.de>
parents:
7352
diff
changeset
|
689 |
errorString:'invalid block - not executable' |
1874 | 690 |
|
691 |
"Modified: 4.11.1996 / 22:46:39 / cg" |
|
1 | 692 |
! ! |
693 |
||
694 |
!Block methodsFor:'evaluation'! |
|
695 |
||
696 |
value |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
697 |
"evaluate the receiver with no block args. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
698 |
The receiver must be a block without arguments." |
1 | 699 |
|
700 |
%{ /* NOCONTEXT */ |
|
701 |
||
702 |
REGISTER OBJFUNC thecode; |
|
703 |
OBJ home; |
|
704 |
||
1133 | 705 |
if (__INST(nargs) == __MKSMALLINT(0)) { |
1 | 706 |
#if defined(THIS_CONTEXT) |
7149 | 707 |
if (__ISVALID_ILC_LNO(__pilc)) |
708 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1 | 709 |
#endif |
328 | 710 |
|
7149 | 711 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 712 |
#ifdef NEW_BLOCK_CALL |
7149 | 713 |
if (thecode != (OBJFUNC)nil) { |
714 |
/* compiled machine code */ |
|
715 |
RETURN ( (*thecode)(self) ); |
|
716 |
} |
|
717 |
/* interpreted code */ |
|
328 | 718 |
# ifdef PASS_ARG_POINTER |
7149 | 719 |
RETURN ( __interpret(self, 0, nil, nil, nil, nil) ); |
328 | 720 |
# else |
7149 | 721 |
RETURN ( __interpret(self, 0, nil, nil, nil, nil) ); |
328 | 722 |
# endif |
11 | 723 |
#else |
7149 | 724 |
home = __BlockInstPtr(self)->b_home; |
725 |
if (thecode != (OBJFUNC)nil) { |
|
726 |
/* compiled machine code */ |
|
727 |
RETURN ( (*thecode)(home) ); |
|
728 |
} |
|
729 |
/* interpreted code */ |
|
328 | 730 |
# ifdef PASS_ARG_POINTER |
7149 | 731 |
RETURN ( __interpret(self, 0, nil, home, nil, nil) ); |
328 | 732 |
# else |
7149 | 733 |
RETURN ( __interpret(self, 0, nil, home, nil, nil) ); |
328 | 734 |
# endif |
11 | 735 |
#endif |
1 | 736 |
} |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
737 |
%}. |
103 | 738 |
^ self wrongNumberOfArguments:0 |
1 | 739 |
! |
740 |
||
741 |
value:arg |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
742 |
"evaluate the receiver with one argument. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
743 |
The receiver must be a 1-arg block." |
1 | 744 |
|
745 |
%{ /* NOCONTEXT */ |
|
746 |
||
747 |
REGISTER OBJFUNC thecode; |
|
748 |
OBJ home; |
|
749 |
||
1133 | 750 |
if (__INST(nargs) == __MKSMALLINT(1)) { |
1 | 751 |
#if defined(THIS_CONTEXT) |
7149 | 752 |
if (__ISVALID_ILC_LNO(__pilc)) |
753 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1 | 754 |
#endif |
7149 | 755 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 756 |
#ifdef NEW_BLOCK_CALL |
7149 | 757 |
if (thecode != (OBJFUNC)nil) { |
758 |
RETURN ( (*thecode)(self, arg) ); |
|
759 |
} |
|
760 |
/* interpreted code */ |
|
328 | 761 |
# ifdef PASS_ARG_POINTER |
7149 | 762 |
RETURN ( __interpret(self, 1, nil, nil, nil, nil, &arg) ); |
328 | 763 |
# else |
7149 | 764 |
RETURN ( __interpret(self, 1, nil, nil, nil, nil, arg) ); |
328 | 765 |
# endif |
1 | 766 |
#else |
7149 | 767 |
home = __BlockInstPtr(self)->b_home; |
768 |
if (thecode != (OBJFUNC)nil) { |
|
769 |
RETURN ( (*thecode)(home, arg) ); |
|
770 |
} |
|
771 |
/* interpreted code */ |
|
328 | 772 |
# ifdef PASS_ARG_POINTER |
7149 | 773 |
RETURN ( __interpret(self, 1, nil, home, nil, nil, &arg) ); |
328 | 774 |
# else |
7149 | 775 |
RETURN ( __interpret(self, 1, nil, home, nil, nil, arg) ); |
328 | 776 |
# endif |
1 | 777 |
#endif |
778 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
779 |
%}. |
103 | 780 |
^ self wrongNumberOfArguments:1 |
1 | 781 |
! |
782 |
||
783 |
value:arg1 value:arg2 |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
784 |
"evaluate the receiver with two arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
785 |
The receiver must be a 2-arg block." |
1 | 786 |
|
787 |
%{ /* NOCONTEXT */ |
|
788 |
||
789 |
REGISTER OBJFUNC thecode; |
|
790 |
OBJ home; |
|
791 |
||
1133 | 792 |
if (__INST(nargs) == __MKSMALLINT(2)) { |
1 | 793 |
#if defined(THIS_CONTEXT) |
7149 | 794 |
if (__ISVALID_ILC_LNO(__pilc)) |
795 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1 | 796 |
#endif |
7149 | 797 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 798 |
#ifdef NEW_BLOCK_CALL |
7149 | 799 |
if (thecode != (OBJFUNC)nil) { |
800 |
RETURN ( (*thecode)(self, arg1, arg2) ); |
|
801 |
} |
|
328 | 802 |
# ifdef PASS_ARG_POINTER |
7149 | 803 |
RETURN ( __interpret(self, 2, nil, nil, nil, nil, &arg1) ); |
328 | 804 |
# else |
7149 | 805 |
RETURN ( __interpret(self, 2, nil, nil, nil, nil, arg1, arg2) ); |
328 | 806 |
# endif |
1 | 807 |
#else |
7149 | 808 |
home = __BlockInstPtr(self)->b_home; |
809 |
if (thecode != (OBJFUNC)nil) { |
|
810 |
RETURN ( (*thecode)(home, arg1, arg2) ); |
|
811 |
} |
|
328 | 812 |
# ifdef PASS_ARG_POINTER |
7149 | 813 |
RETURN ( __interpret(self, 2, nil, home, nil, nil, &arg1) ); |
328 | 814 |
# else |
7149 | 815 |
RETURN ( __interpret(self, 2, nil, home, nil, nil, arg1, arg2) ); |
328 | 816 |
# endif |
1 | 817 |
#endif |
818 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
819 |
%}. |
103 | 820 |
^ self wrongNumberOfArguments:2 |
1 | 821 |
! |
822 |
||
823 |
value:arg1 value:arg2 value:arg3 |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
824 |
"evaluate the receiver with three arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
825 |
The receiver must be a 3-arg block." |
1 | 826 |
|
827 |
%{ /* NOCONTEXT */ |
|
828 |
||
829 |
REGISTER OBJFUNC thecode; |
|
830 |
OBJ home; |
|
831 |
||
1133 | 832 |
if (__INST(nargs) == __MKSMALLINT(3)) { |
1 | 833 |
#if defined(THIS_CONTEXT) |
7149 | 834 |
if (__ISVALID_ILC_LNO(__pilc)) |
835 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1 | 836 |
#endif |
7149 | 837 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 838 |
#ifdef NEW_BLOCK_CALL |
7149 | 839 |
if (thecode != (OBJFUNC)nil) { |
840 |
RETURN ( (*thecode)(self, arg1, arg2, arg3) ); |
|
841 |
} |
|
328 | 842 |
# ifdef PASS_ARG_POINTER |
7149 | 843 |
RETURN ( __interpret(self, 3, nil, nil, nil, nil, &arg1) ); |
328 | 844 |
# else |
7149 | 845 |
RETURN ( __interpret(self, 3, nil, nil, nil, nil, arg1, arg2, arg3) ); |
328 | 846 |
# endif |
1 | 847 |
#else |
7149 | 848 |
home = __BlockInstPtr(self)->b_home; |
849 |
if (thecode != (OBJFUNC)nil) { |
|
850 |
RETURN ( (*thecode)(home, arg1, arg2, arg3) ); |
|
851 |
} |
|
328 | 852 |
# ifdef PASS_ARG_POINTER |
7149 | 853 |
RETURN ( __interpret(self, 3, nil, home, nil, nil, &arg1) ); |
328 | 854 |
# else |
7149 | 855 |
RETURN ( __interpret(self, 3, nil, home, nil, nil, arg1, arg2, arg3) ); |
328 | 856 |
# endif |
1 | 857 |
#endif |
858 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
859 |
%}. |
103 | 860 |
^ self wrongNumberOfArguments:3 |
1 | 861 |
! |
862 |
||
863 |
value:arg1 value:arg2 value:arg3 value:arg4 |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
864 |
"evaluate the receiver with four arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
865 |
The receiver must be a 4-arg block." |
1 | 866 |
|
867 |
%{ /* NOCONTEXT */ |
|
868 |
||
869 |
REGISTER OBJFUNC thecode; |
|
870 |
OBJ home; |
|
871 |
||
1133 | 872 |
if (__INST(nargs) == __MKSMALLINT(4)) { |
1 | 873 |
#if defined(THIS_CONTEXT) |
7149 | 874 |
if (__ISVALID_ILC_LNO(__pilc)) |
875 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1 | 876 |
#endif |
7149 | 877 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 878 |
#ifdef NEW_BLOCK_CALL |
7149 | 879 |
if (thecode != (OBJFUNC)nil) { |
880 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4) ); |
|
881 |
} |
|
328 | 882 |
# ifdef PASS_ARG_POINTER |
7149 | 883 |
RETURN ( __interpret(self, 4, nil, nil, nil, nil, &arg1) ); |
328 | 884 |
# else |
7149 | 885 |
RETURN ( __interpret(self, 4, nil, nil, nil, nil, arg1, arg2, arg3, arg4) ); |
328 | 886 |
# endif |
1 | 887 |
#else |
7149 | 888 |
home = __BlockInstPtr(self)->b_home; |
889 |
if (thecode != (OBJFUNC)nil) { |
|
890 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4) ); |
|
891 |
} |
|
328 | 892 |
# ifdef PASS_ARG_POINTER |
7149 | 893 |
RETURN ( __interpret(self, 4, nil, home, nil, nil, &arg1) ); |
328 | 894 |
# else |
7149 | 895 |
RETURN ( __interpret(self, 4, nil, home, nil, nil, arg1, arg2, arg3, arg4) ); |
328 | 896 |
# endif |
1 | 897 |
#endif |
898 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
899 |
%}. |
103 | 900 |
^ self wrongNumberOfArguments:4 |
1 | 901 |
! |
902 |
||
903 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
904 |
"evaluate the receiver with five arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
905 |
The receiver must be a 5-arg block." |
1 | 906 |
|
907 |
%{ /* NOCONTEXT */ |
|
908 |
||
909 |
REGISTER OBJFUNC thecode; |
|
910 |
OBJ home; |
|
911 |
||
1133 | 912 |
if (__INST(nargs) == __MKSMALLINT(5)) { |
1 | 913 |
#if defined(THIS_CONTEXT) |
7149 | 914 |
if (__ISVALID_ILC_LNO(__pilc)) |
915 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1 | 916 |
#endif |
7149 | 917 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 918 |
#ifdef NEW_BLOCK_CALL |
7149 | 919 |
if (thecode != (OBJFUNC)nil) { |
920 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5) ); |
|
921 |
} |
|
328 | 922 |
# ifdef PASS_ARG_POINTER |
7149 | 923 |
RETURN ( __interpret(self, 5, nil, nil, nil, nil, &arg1) ); |
328 | 924 |
# else |
7149 | 925 |
RETURN ( __interpret(self, 5, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5) ); |
328 | 926 |
# endif |
1 | 927 |
#else |
7149 | 928 |
home = __BlockInstPtr(self)->b_home; |
929 |
if (thecode != (OBJFUNC)nil) { |
|
930 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5) ); |
|
931 |
} |
|
328 | 932 |
# ifdef PASS_ARG_POINTER |
7149 | 933 |
RETURN ( __interpret(self, 5, nil, home, nil, nil, &arg1) ); |
328 | 934 |
# else |
7149 | 935 |
RETURN ( __interpret(self, 5, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5) ); |
328 | 936 |
# endif |
1 | 937 |
#endif |
938 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
939 |
%}. |
103 | 940 |
^ self wrongNumberOfArguments:5 |
1 | 941 |
! |
942 |
||
943 |
value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
944 |
"evaluate the receiver with six arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
945 |
The receiver must be a 6-arg block." |
1 | 946 |
|
947 |
%{ /* NOCONTEXT */ |
|
948 |
||
949 |
REGISTER OBJFUNC thecode; |
|
950 |
OBJ home; |
|
951 |
||
1133 | 952 |
if (__INST(nargs) == __MKSMALLINT(6)) { |
1 | 953 |
#if defined(THIS_CONTEXT) |
7149 | 954 |
if (__ISVALID_ILC_LNO(__pilc)) |
955 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
|
1 | 956 |
#endif |
7149 | 957 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 958 |
#ifdef NEW_BLOCK_CALL |
7149 | 959 |
if (thecode != (OBJFUNC)nil) { |
960 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
961 |
} |
|
328 | 962 |
# ifdef PASS_ARG_POINTER |
7149 | 963 |
RETURN ( __interpret(self, 6, nil, nil, nil, nil, &arg1) ); |
328 | 964 |
# else |
7149 | 965 |
RETURN ( __interpret(self, 6, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
328 | 966 |
# endif |
1 | 967 |
#else |
7149 | 968 |
home = __BlockInstPtr(self)->b_home; |
969 |
if (thecode != (OBJFUNC)nil) { |
|
970 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
971 |
} |
|
328 | 972 |
# ifdef PASS_ARG_POINTER |
7149 | 973 |
RETURN ( __interpret(self, 6, nil, home, nil, nil, &arg1) ); |
328 | 974 |
# else |
7149 | 975 |
RETURN ( __interpret(self, 6, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
328 | 976 |
# endif |
1 | 977 |
#endif |
978 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
979 |
%}. |
103 | 980 |
^ self wrongNumberOfArguments:6 |
1 | 981 |
! |
982 |
||
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
983 |
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
|
984 |
"evaluate the receiver with seven arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
985 |
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
|
986 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
987 |
%{ /* NOCONTEXT */ |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
988 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
989 |
REGISTER OBJFUNC thecode; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
990 |
OBJ home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
991 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
992 |
if (__INST(nargs) == __MKSMALLINT(7)) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
993 |
#if defined(THIS_CONTEXT) |
7149 | 994 |
if (__ISVALID_ILC_LNO(__pilc)) |
995 |
__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
|
996 |
#endif |
7149 | 997 |
thecode = __BlockInstPtr(self)->b_code; |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
998 |
#ifdef NEW_BLOCK_CALL |
7149 | 999 |
if (thecode != (OBJFUNC)nil) { |
1000 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
1001 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1002 |
# ifdef PASS_ARG_POINTER |
7149 | 1003 |
RETURN ( __interpret(self, 7, nil, nil, nil, nil, &arg1) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1004 |
# else |
7149 | 1005 |
RETURN ( __interpret(self, 7, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1006 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1007 |
#else |
7149 | 1008 |
home = __BlockInstPtr(self)->b_home; |
1009 |
if (thecode != (OBJFUNC)nil) { |
|
1010 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
|
1011 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1012 |
# ifdef PASS_ARG_POINTER |
7149 | 1013 |
RETURN ( __interpret(self, 7, nil, home, nil, nil, &arg1) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1014 |
# else |
7149 | 1015 |
RETURN ( __interpret(self, 7, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1016 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1017 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1018 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1019 |
%}. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1020 |
^ self wrongNumberOfArguments:7 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1021 |
! |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1022 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1023 |
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
|
1024 |
"evaluate the receiver with eight arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1025 |
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
|
1026 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1027 |
%{ /* NOCONTEXT */ |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1028 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1029 |
REGISTER OBJFUNC thecode; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1030 |
OBJ home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1031 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1032 |
if (__INST(nargs) == __MKSMALLINT(8)) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1033 |
#if defined(THIS_CONTEXT) |
7149 | 1034 |
if (__ISVALID_ILC_LNO(__pilc)) |
1035 |
__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
|
1036 |
#endif |
7149 | 1037 |
thecode = __BlockInstPtr(self)->b_code; |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1038 |
#ifdef NEW_BLOCK_CALL |
7149 | 1039 |
if (thecode != (OBJFUNC)nil) { |
1040 |
RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
|
1041 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1042 |
# ifdef PASS_ARG_POINTER |
7149 | 1043 |
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
|
1044 |
# else |
7149 | 1045 |
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
|
1046 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1047 |
#else |
7149 | 1048 |
home = __BlockInstPtr(self)->b_home; |
1049 |
if (thecode != (OBJFUNC)nil) { |
|
1050 |
RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
|
1051 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1052 |
# ifdef PASS_ARG_POINTER |
7149 | 1053 |
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
|
1054 |
# else |
7149 | 1055 |
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
|
1056 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1057 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1058 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1059 |
%}. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1060 |
^ self wrongNumberOfArguments:8 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1061 |
! |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
1062 |
|
3688 | 1063 |
valueAt:priority |
1064 |
"evaluate the receiver, at the given prioriy; |
|
1065 |
i.e. change the priority for the execution of the receiver." |
|
1066 |
||
1067 |
|oldPrio retVal| |
|
1068 |
||
1069 |
oldPrio := Processor activePriority. |
|
1070 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1071 |
Processor activeProcess priority:priority. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1072 |
retVal := self value. |
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
1073 |
] ensure:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1074 |
Processor activeProcess priority:oldPrio |
3688 | 1075 |
]. |
1076 |
^ retVal |
|
1077 |
||
1078 |
" |
|
1079 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1080 |
1000 timesRepeat:[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1081 |
1000 factorial |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1082 |
] |
3688 | 1083 |
] valueAt:3 |
1084 |
" |
|
1085 |
||
1086 |
"Created: / 29.7.1998 / 19:19:48 / cg" |
|
1087 |
! |
|
1088 |
||
1 | 1089 |
valueWithArguments:argArray |
1090 |
"evaluate the receiver with arguments taken from argArray. |
|
313 | 1091 |
ArgArray must be either an Array or nil. |
1 | 1092 |
The size of the argArray must match the number of arguments the receiver expects." |
1093 |
||
8009 | 1094 |
|a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15| |
1 | 1095 |
|
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1096 |
(argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[ |
7149 | 1097 |
^ self badArgumentArray:argArray |
1 | 1098 |
]. |
1099 |
(argArray size == nargs) ifFalse:[ |
|
7149 | 1100 |
^ self wrongNumberOfArguments:argArray size |
1 | 1101 |
]. |
1102 |
%{ |
|
1103 |
||
1104 |
REGISTER OBJFUNC thecode; |
|
1105 |
OBJ home; |
|
67 | 1106 |
REGISTER OBJ *ap; |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1107 |
OBJ nA; |
1 | 1108 |
|
1109 |
#if defined(THIS_CONTEXT) |
|
328 | 1110 |
if (__ISVALID_ILC_LNO(__pilc)) |
7149 | 1111 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 1112 |
#endif |
1133 | 1113 |
thecode = __BlockInstPtr(self)->b_code; |
1037 | 1114 |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1115 |
nA = __INST(nargs); |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1116 |
|
1037 | 1117 |
#ifndef NEW_BLOCK_CALL |
1133 | 1118 |
home = __BlockInstPtr(self)->b_home; |
1037 | 1119 |
if (thecode != (OBJFUNC)nil) { |
7149 | 1120 |
/* the most common case (0 args) here (without a switch) */ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1121 |
|
7149 | 1122 |
if (nA == __MKSMALLINT(0)) { |
1123 |
RETURN ( (*thecode)(home) ); |
|
1124 |
} |
|
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1125 |
|
7149 | 1126 |
ap = __arrayVal(argArray); /* nonNil after above test (size is known to be ok) */ |
1127 |
switch ((INT)(nA)) { |
|
1128 |
default: |
|
1129 |
goto error; |
|
8009 | 1130 |
case (INT)__MKSMALLINT(15): |
1131 |
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]) ); |
|
1132 |
case (INT)__MKSMALLINT(14): |
|
1133 |
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]) ); |
|
1134 |
case (INT)__MKSMALLINT(13): |
|
1135 |
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]) ); |
|
7149 | 1136 |
case (INT)__MKSMALLINT(12): |
1137 |
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]) ); |
|
1138 |
case (INT)__MKSMALLINT(11): |
|
1139 |
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]) ); |
|
1140 |
case (INT)__MKSMALLINT(10): |
|
1141 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9]) ); |
|
1142 |
case (INT)__MKSMALLINT(9): |
|
1143 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8]) ); |
|
1144 |
case (INT)__MKSMALLINT(8): |
|
1145 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7]) ); |
|
1146 |
case (INT)__MKSMALLINT(7): |
|
1147 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) ); |
|
1148 |
case (INT)__MKSMALLINT(6): |
|
1149 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) ); |
|
1150 |
case (INT)__MKSMALLINT(5): |
|
1151 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4]) ); |
|
1152 |
case (INT)__MKSMALLINT(4): |
|
1153 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3]) ); |
|
1154 |
case (INT)__MKSMALLINT(3): |
|
1155 |
RETURN ( (*thecode)(home, ap[0], ap[1], ap[2]) ); |
|
1156 |
case (INT)__MKSMALLINT(2): |
|
1157 |
RETURN ( (*thecode)(home, ap[0], ap[1]) ); |
|
1158 |
case (INT)__MKSMALLINT(1): |
|
1159 |
RETURN ( (*thecode)(home, ap[0]) ); |
|
1160 |
case (INT)__MKSMALLINT(0): |
|
1161 |
RETURN ( (*thecode)(home) ); |
|
1162 |
break; |
|
1163 |
} |
|
1037 | 1164 |
} |
1165 |
#endif |
|
1166 |
||
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1167 |
if (nA != __MKSMALLINT(0)) { |
7149 | 1168 |
ap = __arrayVal(argArray); /* nonNil after above test (size is known to be ok) */ |
1169 |
switch ((INT)nA) { |
|
1170 |
default: |
|
1171 |
goto error; |
|
8009 | 1172 |
case (INT)__MKSMALLINT(15): |
1173 |
a15 = ap[14]; |
|
1174 |
case (INT)__MKSMALLINT(14): |
|
1175 |
a14 = ap[13]; |
|
1176 |
case (INT)__MKSMALLINT(13): |
|
1177 |
a13 = ap[12]; |
|
7149 | 1178 |
case (INT)__MKSMALLINT(12): |
1179 |
a12 = ap[11]; |
|
1180 |
case (INT)__MKSMALLINT(11): |
|
1181 |
a11 = ap[10]; |
|
1182 |
case (INT)__MKSMALLINT(10): |
|
1183 |
a10 = ap[9]; |
|
1184 |
case (INT)__MKSMALLINT(9): |
|
1185 |
a9 = ap[8]; |
|
1186 |
case (INT)__MKSMALLINT(8): |
|
1187 |
a8 = ap[7]; |
|
1188 |
case (INT)__MKSMALLINT(7): |
|
1189 |
a7 = ap[6]; |
|
1190 |
case (INT)__MKSMALLINT(6): |
|
1191 |
a6 = ap[5]; |
|
1192 |
case (INT)__MKSMALLINT(5): |
|
1193 |
a5 = ap[4]; |
|
1194 |
case (INT)__MKSMALLINT(4): |
|
1195 |
a4 = ap[3]; |
|
1196 |
case (INT)__MKSMALLINT(3): |
|
1197 |
a3 = ap[2]; |
|
1198 |
case (INT)__MKSMALLINT(2): |
|
1199 |
a2 = ap[1]; |
|
1200 |
case (INT)__MKSMALLINT(1): |
|
1201 |
a1 = ap[0]; |
|
1202 |
case (INT)__MKSMALLINT(0): |
|
1203 |
break; |
|
1204 |
} |
|
1 | 1205 |
} |
1133 | 1206 |
|
11 | 1207 |
#ifdef NEW_BLOCK_CALL |
1 | 1208 |
if (thecode != (OBJFUNC)nil) { |
8009 | 1209 |
RETURN ( (*thecode)(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) ); |
11 | 1210 |
} |
328 | 1211 |
# ifdef PASS_ARG_POINTER |
6553
ce4ca4df3415
oops - last modification created a little bug.
Claus Gittinger <cg@exept.de>
parents:
6512
diff
changeset
|
1212 |
RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, &a1) ); |
328 | 1213 |
# else |
8009 | 1214 |
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 | 1215 |
# endif |
1037 | 1216 |
|
1 | 1217 |
#else |
1037 | 1218 |
|
328 | 1219 |
# ifdef PASS_ARG_POINTER |
6553
ce4ca4df3415
oops - last modification created a little bug.
Claus Gittinger <cg@exept.de>
parents:
6512
diff
changeset
|
1220 |
RETURN ( __interpret(self, __intVal(nA), nil, home, nil, nil, &a1) ); |
328 | 1221 |
# else |
8009 | 1222 |
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 | 1223 |
# endif |
1037 | 1224 |
|
1 | 1225 |
#endif |
67 | 1226 |
|
11 | 1227 |
error: ; |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1228 |
%}. |
138 | 1229 |
" |
8009 | 1230 |
the above code only supports up-to 15 arguments |
138 | 1231 |
" |
7602
d048f13cd50a
Exception classes initialize themself.
Stefan Vogel <sv@exept.de>
parents:
7352
diff
changeset
|
1232 |
^ ArgumentError |
7149 | 1233 |
raiseRequestWith:self |
8009 | 1234 |
errorString:'only blocks with up-to 15 arguments supported' |
6317 | 1235 |
! |
1236 |
||
1237 |
valueWithOptionalArgument:arg |
|
1238 |
"evaluate the receiver. |
|
6318 | 1239 |
Optionally pass an argument (if the receiver is a one arg block)." |
6317 | 1240 |
|
6628
4d693c525443
#handlerForSignal:context:originator:
Stefan Vogel <sv@exept.de>
parents:
6611
diff
changeset
|
1241 |
nargs == 1 ifTrue:[ |
4d693c525443
#handlerForSignal:context:originator:
Stefan Vogel <sv@exept.de>
parents:
6611
diff
changeset
|
1242 |
^ self value:arg |
6317 | 1243 |
]. |
1244 |
^ self value |
|
6320 | 1245 |
|
1246 |
" |
|
1247 |
|block| |
|
1248 |
||
1249 |
block := [ Transcript showCR:'hello' ]. |
|
1250 |
block valueWithOptionalArgument:2. |
|
1251 |
||
1252 |
block := [:arg | Transcript showCR:arg ]. |
|
1253 |
block valueWithOptionalArgument:2. |
|
1254 |
" |
|
6785 | 1255 |
! |
1256 |
||
1257 |
valueWithOptionalArgument:arg1 and:arg2 |
|
1258 |
"evaluate the receiver. |
|
1259 |
Optionally pass up to two arguments (if the receiver is a one/two arg block)." |
|
1260 |
||
1261 |
nargs == 2 ifTrue:[ |
|
1262 |
^ self value:arg1 value:arg2 |
|
1263 |
]. |
|
1264 |
nargs == 1 ifTrue:[ |
|
1265 |
^ self value:arg1 |
|
1266 |
]. |
|
1267 |
^ self value |
|
1268 |
||
1269 |
" |
|
1270 |
|block| |
|
1271 |
||
1272 |
block := [ Transcript showCR:'hello' ]. |
|
1273 |
block valueWithOptionalArgument:2. |
|
1274 |
||
1275 |
block := [:arg | Transcript showCR:arg ]. |
|
1276 |
block valueWithOptionalArgument:2. |
|
1277 |
||
1278 |
block := [:arg1 :arg2 | Transcript showCR:arg1. Transcript showCR:arg2 ]. |
|
1279 |
block valueWithOptionalArgument:10 and:20. |
|
1280 |
" |
|
154 | 1281 |
! ! |
1282 |
||
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1283 |
!Block methodsFor:'exception handling'! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1284 |
|
6512 | 1285 |
on:aSignalOrSignalSetOrException do:exceptionBlock |
1286 |
"added for ANSI compatibility; evaluate the receiver, |
|
1287 |
handling aSignalOrSignalSetOrException. |
|
1288 |
The 2nd argument, exceptionBlock is evaluated |
|
1289 |
if the signal is raised during evaluation." |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1290 |
|
4542
5dc47816cf68
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4513
diff
changeset
|
1291 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1292 |
<exception: #handle> |
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1293 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1294 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1295 |
^ 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
|
1296 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1297 |
" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1298 |
[ |
6512 | 1299 |
1 foo |
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1300 |
] 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
|
1301 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1302 |
[ |
6512 | 1303 |
1 foo |
1304 |
] on:(MessageNotUnderstood , AbortOperationRequest) do:[:ex | self halt] |
|
1305 |
||
1306 |
[ |
|
1307 |
1 foo |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1308 |
] on:SignalSet anySignal do:[:ex| 2 bar. self halt] |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1309 |
" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1310 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1311 |
"Modified: / 26.7.1999 / 15:30:48 / stefan" |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1312 |
! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1313 |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1314 |
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
|
1315 |
"added for ANSI compatibility; evaluate the receiver, |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1316 |
handling aSignalOrSignalSetOrException. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1317 |
The 2nd argument, exceptionBlock is evaluated |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1318 |
if the signal is raised during evaluation." |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1319 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1320 |
<context: #return> |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1321 |
<exception: #handle> |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1322 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1323 |
"/ thisContext markForHandle. -- same as above pragma |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1324 |
^ 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
|
1325 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1326 |
" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1327 |
[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1328 |
1 foo |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1329 |
] on:MessageNotUnderstood do:[:ex | self halt:'Got MessageNotUnderstood'] |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1330 |
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
|
1331 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1332 |
[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1333 |
1 // 0 |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1334 |
] on:MessageNotUnderstood do:[:ex | self halt:'Got MessageNotUnderstood'] |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1335 |
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
|
1336 |
" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1337 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1338 |
"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
|
1339 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1340 |
|
4464
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1341 |
valueWithExceptionHandler:handler |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1342 |
"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
|
1343 |
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
|
1344 |
|
4547
082a2f7d9d8e
Add #handlerProtectedBlock:inContext
Stefan Vogel <sv@exept.de>
parents:
4542
diff
changeset
|
1345 |
<context: #return> |
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1346 |
<exception: #handle> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1347 |
|
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1348 |
"/ thisContext markForHandle. -- same as above pragma |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
1349 |
^ 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
|
1350 |
|
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1351 |
"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
|
1352 |
"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
|
1353 |
! ! |
cec93c942c14
Use context flag for exception handling instead of searching for
Stefan Vogel <sv@exept.de>
parents:
4419
diff
changeset
|
1354 |
|
8682
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1355 |
!Block methodsFor:'exception handling private'! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1356 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1357 |
exceptionHandlerFor:anException in:aContext |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1358 |
"answer the exceptionHandler for anException from aContext." |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1359 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1360 |
aContext selector == #on:do:on:do: ifTrue:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1361 |
|exceptionCreator exceptionHandlerInContext| |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1362 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1363 |
exceptionCreator := anException creator. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1364 |
exceptionHandlerInContext := aContext argAt:1. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1365 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1366 |
exceptionHandlerInContext isNil ifTrue:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1367 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1368 |
] ifFalse:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1369 |
'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1370 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1371 |
aContext fullPrint. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1372 |
^ nil. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1373 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1374 |
(exceptionHandlerInContext accepts:exceptionCreator) ifTrue:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1375 |
^ exceptionHandlerInContext. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1376 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1377 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1378 |
exceptionHandlerInContext := aContext argAt:3. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1379 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1380 |
exceptionHandlerInContext isNil ifTrue:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1381 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1382 |
] ifFalse:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1383 |
'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1384 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1385 |
aContext fullPrint. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1386 |
^ nil. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1387 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1388 |
(exceptionHandlerInContext accepts:exceptionCreator) ifTrue:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1389 |
^ exceptionHandlerInContext. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1390 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1391 |
^ nil. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1392 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1393 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1394 |
"aContext selector must be #on:do: or #valueWithExceptionHandler:" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1395 |
^ aContext argAt:1. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1396 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1397 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1398 |
handlerForSignal:exceptionHandler context:theContext originator:originator |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1399 |
"answer the handler block for the exceptionHandler from originator. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1400 |
The handler block is retrieved from aContext. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1401 |
Answer nil if the exceptionHandler is not handled." |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1402 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1403 |
|selector exceptionHandlerInContext| |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1404 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1405 |
selector := theContext selector. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1406 |
selector == #on:do: ifTrue:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1407 |
exceptionHandlerInContext := theContext argAt:1. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1408 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1409 |
exceptionHandlerInContext isNil ifTrue:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1410 |
'Block [warning]: nil ExceptionHandler in on:do:-context' errorPrintCR. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1411 |
] ifFalse:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1412 |
'Block [warning]: non-ExceptionHandler in on:do:-context' errorPrintCR. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1413 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1414 |
theContext fullPrint. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1415 |
^ nil. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1416 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1417 |
(exceptionHandlerInContext == exceptionHandler |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1418 |
or:[exceptionHandlerInContext accepts:exceptionHandler]) ifTrue:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1419 |
^ theContext argAt:2. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1420 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1421 |
] ifFalse:[selector == #on:do:on:do: ifTrue:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1422 |
exceptionHandlerInContext := theContext argAt:1. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1423 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1424 |
exceptionHandlerInContext isNil ifTrue:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1425 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1426 |
] ifFalse:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1427 |
'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1428 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1429 |
theContext fullPrint. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1430 |
^ nil. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1431 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1432 |
(exceptionHandlerInContext == exceptionHandler |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1433 |
or:[exceptionHandlerInContext accepts:exceptionHandler]) ifTrue:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1434 |
^ theContext argAt:2. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1435 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1436 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1437 |
exceptionHandlerInContext := theContext argAt:3. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1438 |
exceptionHandlerInContext isExceptionHandler ifFalse:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1439 |
exceptionHandlerInContext isNil ifTrue:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1440 |
'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1441 |
] ifFalse:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1442 |
'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1443 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1444 |
theContext fullPrint. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1445 |
^ nil. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1446 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1447 |
(exceptionHandlerInContext == exceptionHandler |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1448 |
or:[exceptionHandlerInContext accepts:exceptionHandler]) ifTrue:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1449 |
^ theContext argAt:4. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1450 |
]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1451 |
] ifFalse:[selector == #valueWithExceptionHandler: ifTrue:[ |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1452 |
^ (theContext argAt:1) handlerForSignal:exceptionHandler. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1453 |
]]]. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1454 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1455 |
^ nil |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1456 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1457 |
"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
|
1458 |
"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
|
1459 |
! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1460 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1461 |
handlerProtectedBlock:doBlock inContext:context |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1462 |
"set the block that is protected by an exception handler in context. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1463 |
This is the receiver of the #on:do: or #valueWithExceptionHandler:. |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1464 |
Needed for #restartDo:" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1465 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1466 |
context receiver:doBlock |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1467 |
|
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1468 |
" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1469 |
[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
|
1470 |
" |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1471 |
! ! |
3bbf34191ca2
Support for Block>>#on:do:on:do:
Stefan Vogel <sv@exept.de>
parents:
8638
diff
changeset
|
1472 |
|
623 | 1473 |
!Block methodsFor:'looping'! |
325 | 1474 |
|
623 | 1475 |
doUntil:aBlock |
1476 |
"repeat the receiver block until aBlock evaluates to true. |
|
1477 |
The receiver is evaluated at least once. |
|
1478 |
This is the same as '... doWhile:[... not]' " |
|
325 | 1479 |
|
623 | 1480 |
"this implementation is for purists ... :-)" |
1481 |
||
1482 |
self value. |
|
1483 |
aBlock value ifTrue:[^ nil]. |
|
1484 |
thisContext restart |
|
325 | 1485 |
|
1486 |
" |
|
623 | 1487 |
|n| |
154 | 1488 |
|
623 | 1489 |
n := 1. |
8602 | 1490 |
[n printCR] doUntil:[ (n := n + 1) > 5 ] |
154 | 1491 |
" |
1 | 1492 |
! |
1493 |
||
623 | 1494 |
doWhile:aBlock |
1495 |
"repeat the receiver block until aBlock evaluates to false. |
|
1496 |
The receiver is evaluated at least once." |
|
67 | 1497 |
|
154 | 1498 |
"this implementation is for purists ... :-)" |
1499 |
||
623 | 1500 |
self value. |
1501 |
aBlock value ifFalse:[^ nil]. |
|
1502 |
thisContext restart |
|
1503 |
||
1504 |
" |
|
1505 |
|n| |
|
1506 |
||
1507 |
n := 1. |
|
8602 | 1508 |
[n printCR] doWhile:[ (n := n + 1) <= 5 ] |
623 | 1509 |
" |
1510 |
! |
|
1511 |
||
1512 |
loop |
|
1211 | 1513 |
"repeat the receiver forever |
1514 |
(the receiver block should contain a return somewhere). |
|
1515 |
The implementation below was inspired by a corresponding Self method." |
|
623 | 1516 |
|
1517 |
self value. |
|
67 | 1518 |
thisContext restart |
1519 |
||
1520 |
" |
|
1521 |
|n| |
|
1522 |
||
1523 |
n := 1. |
|
623 | 1524 |
[ |
8602 | 1525 |
n printCR. |
1526 |
n >= 10 ifTrue:[^ nil]. |
|
1527 |
n := n + 1 |
|
623 | 1528 |
] loop |
1529 |
" |
|
1211 | 1530 |
|
1531 |
"Modified: 18.4.1996 / 13:50:40 / cg" |
|
623 | 1532 |
! |
1533 |
||
1534 |
loopWithExit |
|
1535 |
"the receiver must be a block of one argument. It is evaluated in a loop forever, |
|
1536 |
and is passed a block, which, if sent a value:-message, will exit the receiver block, |
|
1537 |
returning the parameter of the value:-message. Used for loops with exit in the middle. |
|
1538 |
Inspired by a corresponding Self method." |
|
1539 |
||
1540 |
|exitBlock| |
|
1541 |
||
1542 |
exitBlock := [:exitValue | ^ exitValue]. |
|
1543 |
[true] whileTrue:[self value:exitBlock] |
|
1544 |
||
1545 |
" |
|
1546 |
|i| |
|
1547 |
i := 1. |
|
1548 |
[:exit | |
|
1422 | 1549 |
Transcript showCR:i. |
623 | 1550 |
i == 5 ifTrue:[exit value:'thats it']. |
1551 |
i := i + 1 |
|
1552 |
] loopWithExit |
|
1553 |
" |
|
1554 |
! |
|
1555 |
||
1556 |
repeat |
|
1211 | 1557 |
"repeat the receiver forever - same as loop, for ST-80 compatibility. |
1558 |
(the receiver block should contain a return somewhere)." |
|
623 | 1559 |
|
1560 |
self value. |
|
1561 |
thisContext restart |
|
1211 | 1562 |
|
1563 |
"Modified: 18.4.1996 / 13:50:55 / cg" |
|
623 | 1564 |
! |
1565 |
||
1566 |
valueWithExit |
|
1567 |
"the receiver must be a block of one argument. It is evaluated, and is passed a block, |
|
1568 |
which, if sent a value:-message, will exit the receiver block, returning the parameter of the |
|
1569 |
value:-message. Used for premature returns to the caller. |
|
1570 |
Taken from a manchester goody (a similar construct also appears in Self)." |
|
1571 |
||
1211 | 1572 |
^ self value:[:exitValue | ^exitValue] |
623 | 1573 |
|
1574 |
" |
|
1575 |
[:exit | |
|
2238 | 1576 |
1 to:10 do:[:i | |
1577 |
Transcript showCR:i. |
|
1578 |
i == 5 ifTrue:[exit value:'thats it'] |
|
1579 |
]. |
|
1580 |
'regular block-value; never returned' |
|
623 | 1581 |
] valueWithExit |
1582 |
" |
|
1211 | 1583 |
|
1584 |
"Modified: 18.4.1996 / 13:51:38 / cg" |
|
623 | 1585 |
! |
1586 |
||
5215 | 1587 |
valueWithRestart |
1588 |
|myContext restartAction| |
|
1589 |
||
1590 |
myContext := thisContext. |
|
1591 |
restartAction := [ myContext restart ]. |
|
1592 |
^ self value:restartAction. |
|
1593 |
||
1594 |
" |
|
1595 |
[:restart | |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1596 |
(self confirm:'try again ?') ifTrue:[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1597 |
restart value. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1598 |
] |
5215 | 1599 |
] valueWithRestart |
1600 |
" |
|
1601 |
||
1602 |
"Modified: / 25.1.2000 / 21:47:50 / cg" |
|
1603 |
! |
|
1604 |
||
623 | 1605 |
whileFalse |
1606 |
"evaluate the receiver while it evaluates to false (ST80 compatibility)" |
|
1607 |
||
1608 |
"this implementation is for purists ... :-)" |
|
1609 |
||
1610 |
self value ifTrue:[^ nil]. |
|
1611 |
thisContext restart |
|
1612 |
||
1613 |
" |
|
1614 |
|n| |
|
1615 |
||
1616 |
n := 1. |
|
8602 | 1617 |
[n printCR. (n := n + 1) > 10] whileFalse |
67 | 1618 |
" |
1619 |
! |
|
1 | 1620 |
|
67 | 1621 |
whileFalse:aBlock |
1622 |
"evaluate the argument, aBlock while the receiver evaluates to false. |
|
1623 |
- usually open coded by compilers, but needed here for #perform |
|
1624 |
and expression evaluation." |
|
1625 |
||
154 | 1626 |
"this implementation is for purists ... :-)" |
1627 |
||
67 | 1628 |
self value ifTrue:[^ nil]. |
1629 |
aBlock value. |
|
1630 |
thisContext restart |
|
1631 |
||
1632 |
" |
|
1633 |
|n| |
|
1634 |
||
1635 |
n := 1. |
|
1636 |
[n > 10] whileFalse:[ |
|
8602 | 1637 |
n printCR. |
1638 |
n := n + 1 |
|
67 | 1639 |
] |
1640 |
" |
|
1 | 1641 |
! |
1642 |
||
1643 |
whileTrue |
|
67 | 1644 |
"evaluate the receiver while it evaluates to true (ST80 compatibility)" |
1 | 1645 |
|
154 | 1646 |
"this implementation is for purists ... :-)" |
1647 |
||
67 | 1648 |
self value ifFalse:[^ nil]. |
1649 |
thisContext restart |
|
1 | 1650 |
|
67 | 1651 |
" |
1652 |
|n| |
|
1 | 1653 |
|
67 | 1654 |
n := 1. |
8602 | 1655 |
[n printCR. (n := n + 1) <= 10] whileTrue |
67 | 1656 |
" |
1 | 1657 |
! |
1658 |
||
623 | 1659 |
whileTrue:aBlock |
1660 |
"evaluate the argument, aBlock while the receiver evaluates to true. |
|
1661 |
- usually open coded by compilers, but needed here for #perform |
|
1662 |
and expression evaluation." |
|
1 | 1663 |
|
154 | 1664 |
"this implementation is for purists ... :-)" |
1665 |
||
623 | 1666 |
self value ifFalse:[^ nil]. |
1667 |
aBlock value. |
|
67 | 1668 |
thisContext restart |
1669 |
||
1670 |
" |
|
1671 |
|n| |
|
1 | 1672 |
|
67 | 1673 |
n := 1. |
623 | 1674 |
[n <= 10] whileTrue:[ |
8602 | 1675 |
n printCR. |
1676 |
n := n + 1 |
|
623 | 1677 |
] |
68 | 1678 |
" |
67 | 1679 |
! ! |
1680 |
||
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1681 |
!Block methodsFor:'parallel evaluation'! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1682 |
|
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1683 |
futureValue |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1684 |
"Fork a synchronised evaluation of myself. |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1685 |
Starts the evaluation in parallel now, but synchronizes |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1686 |
any access to wait until the result is computed." |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1687 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1688 |
^ Future new block:self |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1689 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1690 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1691 |
futureValue:aValue |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1692 |
"Fork a synchronised evaluation of myself. |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1693 |
Starts the evaluation in parallel now, but synchronizes |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1694 |
any access to wait until the result is computed." |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1695 |
|
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1696 |
^ Future new block:self value:aValue |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1697 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1698 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1699 |
futureValue:aValue value:anotherValue |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1700 |
"Fork a synchronised evaluation of myself. |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1701 |
Starts the evaluation in parallel now, but synchronizes |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1702 |
any access to wait until the result is computed." |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1703 |
|
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1704 |
^ Future new |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1705 |
block:self |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1706 |
value:aValue |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1707 |
value:anotherValue |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1708 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1709 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1710 |
futureValue:aValue value:anotherValue value:bValue |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1711 |
"Fork a synchronised evaluation of myself. |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1712 |
Starts the evaluation in parallel now, but synchronizes |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1713 |
any access to wait until the result is computed." |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1714 |
|
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1715 |
^ Future new |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1716 |
block:self |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1717 |
value:aValue |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1718 |
value:anotherValue |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1719 |
value:bValue |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1720 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1721 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1722 |
futureValueWithArguments:anArray |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1723 |
"Fork a synchronised evaluation of myself. |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1724 |
Starts the evaluation in parallel now, but synchronizes |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1725 |
any access to wait until the result is computed." |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1726 |
|
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1727 |
^ Future new block:self valueWithArguments:anArray |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1728 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1729 |
|
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1730 |
lazyValue |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1731 |
"Fork a synchronised evaluation of myself. Only starts |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1732 |
the evaluation when the result is requested." |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1733 |
|
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1734 |
^ Lazy new block:self |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1735 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1736 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1737 |
lazyValue:aValue |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1738 |
"Fork a synchronised evaluation of myself. Only starts |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1739 |
the evaluation when the result is requested." |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1740 |
|
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1741 |
^ Lazy new block:self value:aValue |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1742 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1743 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1744 |
lazyValue:aValue value:anotherValue |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1745 |
"Fork a synchronised evaluation of myself. Only starts |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1746 |
the evaluation when the result is requested." |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1747 |
|
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1748 |
^ Lazy new |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1749 |
block:self |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1750 |
value:aValue |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1751 |
value:anotherValue |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1752 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1753 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1754 |
lazyValue:aValue value:anotherValue value:bValue |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1755 |
"Fork a synchronised evaluation of myself. Only starts |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1756 |
the evaluation when the result is requested." |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1757 |
|
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1758 |
^ Lazy new |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1759 |
block:self |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1760 |
value:aValue |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1761 |
value:anotherValue |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1762 |
value:bValue |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1763 |
! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1764 |
|
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1765 |
lazyValueWithArguments:anArray |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1766 |
"Fork a synchronised evaluation of myself. Only starts |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1767 |
the evaluation when the result is requested." |
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1768 |
|
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
1769 |
^ Lazy new block:self valueWithArguments:anArray |
7660
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1770 |
! ! |
1f3792fd3d37
lazy and future value moved to libbasic.
Claus Gittinger <cg@exept.de>
parents:
7602
diff
changeset
|
1771 |
|
92 | 1772 |
!Block methodsFor:'printing & storing'! |
1 | 1773 |
|
7151 | 1774 |
printBlockBracketsOn:aStream |
1775 |
aStream nextPutAll:'[]'. |
|
1776 |
! |
|
1777 |
||
1 | 1778 |
printOn:aStream |
44 | 1779 |
"append a a printed representation of the block to aStream" |
1780 |
||
6633 | 1781 |
|h sel methodClass| |
54 | 1782 |
|
1783 |
"cheap blocks have no home context, but a method instead" |
|
1784 |
||
1785 |
(home isNil or:[home isContext not]) ifTrue:[ |
|
6633 | 1786 |
aStream nextPutAll:'[] in '. |
1 | 1787 |
|
6633 | 1788 |
" |
1789 |
currently, some cheap blocks don't know where they have been created |
|
1790 |
" |
|
1791 |
aStream nextPutAll:' ??? (optimized)'. |
|
1792 |
^ self |
|
54 | 1793 |
]. |
1794 |
||
1795 |
"a full blown block (with home, but without method)" |
|
7151 | 1796 |
self printBlockBracketsOn:aStream. |
1797 |
aStream nextPutAll:' in '. |
|
154 | 1798 |
h := self methodHome. |
1799 |
sel := h selector. |
|
1800 |
"/ old: |
|
1801 |
"/ home receiver class name printOn:aStream. |
|
1802 |
"/ new: |
|
212 | 1803 |
"/ (h searchClass whichClassImplements:sel) name printOn:aStream. |
213 | 1804 |
methodClass := h methodClass. |
1805 |
methodClass isNil ifTrue:[ |
|
6633 | 1806 |
'UnboundMethod' printOn:aStream. |
213 | 1807 |
] ifFalse:[ |
6633 | 1808 |
methodClass name printOn:aStream. |
213 | 1809 |
]. |
7157
935eaabbe6dc
printString now "... in className >> sel"
Claus Gittinger <cg@exept.de>
parents:
7151
diff
changeset
|
1810 |
aStream nextPutAll:'>>'. |
154 | 1811 |
sel printOn:aStream. |
54 | 1812 |
|
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1813 |
"/ |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1814 |
"/ aStream nextPutAll:'[] in '. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1815 |
"/ homeClass := home containingClass. |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1816 |
"/ 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
|
1817 |
"/ 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
|
1818 |
"/ aStream space. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1819 |
"/ (homeClass selectorForMethod:home) printOn:aStream |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1820 |
"/ ] ifFalse:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1821 |
"/ aStream nextPutAll:' ???' |
2841
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1822 |
"/ ] |
d3cab7c7d334
allow non-array in valueWithArguments
Claus Gittinger <cg@exept.de>
parents:
2828
diff
changeset
|
1823 |
"/ |
1 | 1824 |
! ! |
623 | 1825 |
|
7257 | 1826 |
!Block methodsFor:'private-accessing'! |
623 | 1827 |
|
5766
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
1828 |
byteCode:bCode numArgs:numArgs numVars:numVars numStack:numStack sourcePosition:srcPos initialPC:iPC literals:lits |
1265 | 1829 |
"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
|
1830 |
DANGER ALERT: this interface is strictly private." |
623 | 1831 |
|
1832 |
byteCode := bCode. |
|
1833 |
nargs := numArgs. |
|
1834 |
sourcePos := srcPos. |
|
1835 |
initialPC := iPC. |
|
1777 | 1836 |
flags := 0. |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
1837 |
self stackSize:numStack. |
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1838 |
self literals:lits. |
5766
64d22218e98b
must ensure that nArgs and nVar flag setting is correct
Claus Gittinger <cg@exept.de>
parents:
5744
diff
changeset
|
1839 |
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
|
1840 |
self numberOfVars:numVars. "/ must set the compiledCode flags as well |
1265 | 1841 |
|
1842 |
"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
|
1843 |
"Modified: 24.6.1996 / 12:37:37 / stefan" |
2542
555749f035f4
need stackSize when creating blocks.
Claus Gittinger <cg@exept.de>
parents:
2301
diff
changeset
|
1844 |
"Created: 13.4.1997 / 00:00:57 / cg" |
623 | 1845 |
! |
1846 |
||
5779 | 1847 |
initialPC |
1848 |
"return the initial pc for evaluation." |
|
1849 |
||
1850 |
^ initialPC |
|
1851 |
! |
|
1852 |
||
623 | 1853 |
initialPC:initial |
1265 | 1854 |
"set the initial pc for evaluation. |
1855 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 1856 |
|
1857 |
initialPC := initial |
|
1265 | 1858 |
|
1859 |
"Modified: 23.4.1996 / 16:05:39 / cg" |
|
623 | 1860 |
! |
1861 |
||
1862 |
numArgs:numArgs |
|
1265 | 1863 |
"set the number of arguments the receiver expects for evaluation. |
1864 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 1865 |
|
1866 |
nargs := numArgs |
|
1265 | 1867 |
|
1868 |
"Modified: 23.4.1996 / 16:05:52 / cg" |
|
623 | 1869 |
! |
1870 |
||
5744 | 1871 |
setHome:aContext |
1872 |
home := aContext |
|
1873 |
! |
|
1874 |
||
7323 | 1875 |
source |
1876 |
|m| |
|
1877 |
||
1878 |
sourcePos isString ifTrue:[ "/ misuses the sourcePosition slot |
|
1879 |
^ sourcePos |
|
1880 |
]. |
|
1881 |
m := self method. |
|
1882 |
m notNil ifTrue:[ |
|
1883 |
^ m source |
|
1884 |
]. |
|
1885 |
^ nil |
|
1886 |
! |
|
1887 |
||
6981 | 1888 |
source:aString |
1889 |
"set the source - only to be used, if the block is not contained in a method. |
|
1890 |
This interface is for knowledgable users only." |
|
1891 |
||
1892 |
sourcePos := aString "/ misuse the sourcePosition slot |
|
1893 |
! |
|
1894 |
||
623 | 1895 |
sourcePosition:position |
1265 | 1896 |
"set the position of the source within my method. |
1897 |
This interface is for the compiler only." |
|
623 | 1898 |
|
1899 |
sourcePos := position |
|
1265 | 1900 |
|
1901 |
"Modified: 23.4.1996 / 16:06:19 / cg" |
|
623 | 1902 |
! ! |
1903 |
||
1904 |
!Block methodsFor:'privileged evaluation'! |
|
1905 |
||
1906 |
valueUninterruptably |
|
1907 |
"evaluate the receiver with interrupts blocked. |
|
1908 |
This does not prevent preemption by a higher priority processes |
|
1909 |
if any becomes runnable due to the evaluation of the receiver |
|
1910 |
(i.e. if a semaphore is signalled)." |
|
1911 |
||
2301 | 1912 |
"we must keep track of blocking-state if this is called nested" |
1913 |
(OperatingSystem blockInterrupts) ifTrue:[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1914 |
"/ already blocked. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1915 |
^ self value |
2301 | 1916 |
]. |
864 | 1917 |
|
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
1918 |
^ self ensure:[OperatingSystem unblockInterrupts]. |
623 | 1919 |
! |
1920 |
||
1921 |
valueUnpreemptively |
|
1922 |
"evaluate the receiver without the possiblity of preemption |
|
1923 |
(i.e. at a very high priority)" |
|
1924 |
||
1925 |
|oldPrio activeProcess| |
|
1926 |
||
1927 |
activeProcess := Processor activeProcess. |
|
1928 |
oldPrio := activeProcess changePriority:(Processor highestPriority). |
|
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
1929 |
^ self ensure:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
1930 |
activeProcess priority:oldPrio |
623 | 1931 |
] |
1932 |
! ! |
|
1933 |
||
1934 |
!Block methodsFor:'process creation'! |
|
1935 |
||
1936 |
fork |
|
1937 |
"create a new process executing the receiver at the current priority." |
|
1938 |
||
1939 |
^ self newProcess resume |
|
1940 |
! |
|
1941 |
||
1942 |
forkAt:priority |
|
1943 |
"create a new process executing the receiver at a different priority." |
|
1944 |
||
1945 |
^ (self newProcess priority:priority) resume |
|
1946 |
! |
|
1947 |
||
6609 | 1948 |
forkNamed:aString |
1949 |
"create a new process, give it a name and let it start |
|
1950 |
executing the receiver at the current priority." |
|
1951 |
||
1952 |
|newProcess| |
|
1953 |
||
1954 |
newProcess := self newProcess. |
|
1955 |
newProcess name:aString. |
|
1956 |
newProcess resume. |
|
1957 |
^ newProcess. |
|
1958 |
! |
|
1959 |
||
623 | 1960 |
forkWith:argArray |
1961 |
"create a new process executing the receiver, |
|
1962 |
passing elements in argArray as arguments to the receiver block." |
|
1963 |
||
1964 |
^ [self valueWithArguments:argArray] fork. |
|
1965 |
! |
|
1966 |
||
1967 |
newProcess |
|
1968 |
"create a new (unscheduled) process executing the receiver" |
|
1969 |
||
1970 |
^ Process for:self priority:(Processor activePriority) |
|
1971 |
! |
|
1972 |
||
1973 |
newProcessWithArguments:argArray |
|
1974 |
"create a new (unscheduled) process executing the receiver, |
|
1975 |
passing the elements in argArray as arguments to the receiver block." |
|
1976 |
||
1977 |
^ [self valueWithArguments:argArray] newProcess |
|
1978 |
! |
|
1979 |
||
1980 |
promise |
|
1981 |
"create a promise on the receiver. The promise will evaluate the |
|
1982 |
receiver and promise to return the value with the #value message. |
|
1983 |
The evaluation will be performed as a separate process. |
|
1984 |
Asking the promise for its value will either block the asking process |
|
1985 |
(if the evaluation has not yet been finished) or return the value |
|
1986 |
immediately." |
|
1987 |
||
1988 |
^ Promise value:self |
|
1989 |
||
1990 |
" |
|
1991 |
|p| |
|
1992 |
||
1993 |
p := [1000 factorial] promise. |
|
1994 |
'do something else ...'. |
|
1995 |
p value |
|
1996 |
" |
|
1997 |
! |
|
1998 |
||
1999 |
promiseAt:prio |
|
2000 |
"create a promise on the receiver. The promise will evaluate the |
|
2001 |
receiver and promise to return the value with the #value message. |
|
2002 |
The evaluation will be performed as a separate process running at prio. |
|
2003 |
Asking the promise for its value will either block the asking process |
|
2004 |
(if the evaluation has not yet been finished) or return the value |
|
2005 |
immediately." |
|
2006 |
||
2007 |
^ Promise value:self priority:prio |
|
2008 |
! ! |
|
2009 |
||
2010 |
!Block methodsFor:'testing'! |
|
2011 |
||
2012 |
isBlock |
|
2013 |
"return true, if this is a block - yes I am" |
|
2014 |
||
2015 |
^ true |
|
2237
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
2016 |
! |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
2017 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
2018 |
isVarArgBlock |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
2019 |
"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
|
2020 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
2021 |
^ false |
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
2022 |
|
d54ee88b8106
VarArgBlock as a private subclass
Claus Gittinger <cg@exept.de>
parents:
2201
diff
changeset
|
2023 |
"Created: 23.1.1997 / 04:59:51 / cg" |
623 | 2024 |
! ! |
2025 |
||
2026 |
!Block methodsFor:'unwinding'! |
|
2027 |
||
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
2028 |
unwindHandlerInContext:aContext |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
2029 |
"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
|
2030 |
retrieve the handler block. |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
2031 |
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
|
2032 |
#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
|
2033 |
methods to be added)" |
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
2034 |
|
4896 | 2035 |
aContext selector == #'value:onUnwindDo:' ifTrue:[ |
6608 | 2036 |
^ aContext argAt:2 |
4896 | 2037 |
]. |
2038 |
||
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
2039 |
"/ for now, only #valueNowOrOnUnwindDo: |
4896 | 2040 |
"/ or #valueOnUnwindDo: |
5666
de56e39714da
inlined unwind setup into #ensure:
Claus Gittinger <cg@exept.de>
parents:
5349
diff
changeset
|
2041 |
"/ or #ensure: |
6608 | 2042 |
"/ or #ifCurtailed: |
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
2043 |
|
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
2044 |
^ aContext argAt:1 |
6257
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
2045 |
! ! |
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
2046 |
|
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
2047 |
!Block methodsFor:'unwinding-old'! |
4479
6915eb8eeeff
added query for unwindHandler (like contexts ask for handler)
Claus Gittinger <cg@exept.de>
parents:
4476
diff
changeset
|
2048 |
|
4896 | 2049 |
value:arg onUnwindDo:aBlock |
2050 |
"evaluate the receiver, passing it one argument |
|
2051 |
- when some method sent within unwinds (i.e. does |
|
2052 |
a long return), evaluate the argument, aBlock. |
|
2053 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
2054 |
executed regardless of error actions" |
|
2055 |
||
2056 |
<exception: #unwind> |
|
2057 |
||
2058 |
|v| |
|
2059 |
||
2060 |
"/ thisContext markForUnwind. -- same as above pragma |
|
2061 |
v := self value:arg. "the real logic is in Context>>unwind" |
|
2062 |
thisContext unmarkForUnwind. |
|
2063 |
^ v |
|
2064 |
||
2065 |
" |
|
2066 |
|s| |
|
2067 |
||
2068 |
s := 'Makefile' asFilename readStream. |
|
2069 |
[:arg | |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2070 |
^ self |
4896 | 2071 |
] 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
|
2072 |
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
|
2073 |
s close |
4896 | 2074 |
] |
2075 |
" |
|
2076 |
" |
|
2077 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2078 |
|s| |
4896 | 2079 |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2080 |
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
|
2081 |
[:arg | |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2082 |
Processor activeProcess terminate |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2083 |
] value:12345 onUnwindDo:[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2084 |
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
|
2085 |
s close |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2086 |
] |
4896 | 2087 |
] fork |
2088 |
" |
|
2089 |
||
2090 |
! |
|
2091 |
||
623 | 2092 |
valueNowOrOnUnwindDo:aBlock |
2093 |
"evaluate the receiver - after that, or when some method sent within unwinds (i.e. does |
|
2094 |
a long return), evaluate the argument, aBlock. |
|
2095 |
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
|
2096 |
executed regardless of error actions. |
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
2097 |
Same as the more modern #ensure:" |
623 | 2098 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2099 |
<exception: #unwind> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2100 |
|
623 | 2101 |
|v| |
2102 |
||
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2103 |
"/ thisContext markForUnwind. -- same as above pragma |
623 | 2104 |
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
|
2105 |
thisContext unmarkForUnwind. |
623 | 2106 |
aBlock value. |
2107 |
^ v |
|
2108 |
||
2109 |
" |
|
2110 |
in the following example, f will be closed even if the block |
|
2111 |
returns with 'oops'. There are many more applications of this kind |
|
2112 |
found in the system. |
|
2113 |
" |
|
2114 |
" |
|
2115 |
|f| |
|
2116 |
||
2117 |
f := 'Makefile' asFilename readStream. |
|
2118 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2119 |
l := f nextLine. |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2120 |
l isNil ifTrue:[^ 'oops'] |
623 | 2121 |
] valueNowOrOnUnwindDo:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2122 |
f close |
623 | 2123 |
] |
2124 |
" |
|
1187
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
2125 |
|
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
2126 |
"Modified: 16.4.1996 / 11:05:26 / stefan" |
623 | 2127 |
! |
2128 |
||
2129 |
valueOnUnwindDo:aBlock |
|
2130 |
"evaluate the receiver - when some method sent within unwinds (i.e. does |
|
2131 |
a long return), evaluate the argument, aBlock. |
|
2132 |
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
|
2133 |
executed regardless of error actions |
f77941a61a12
Fix comments. Use #ensure: instead of #valueNowOrOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
6236
diff
changeset
|
2134 |
Same as the more modern #ifCurtailed:" |
623 | 2135 |
|
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2136 |
<exception: #unwind> |
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2137 |
|
2286 | 2138 |
|v| |
2139 |
||
4491
5041cae5651c
use new pragma to flag exception frames.
Claus Gittinger <cg@exept.de>
parents:
4479
diff
changeset
|
2140 |
"/ thisContext markForUnwind. -- same as above pragma |
2286 | 2141 |
v := self value. "the real logic is in Context>>unwind" |
2142 |
thisContext unmarkForUnwind. |
|
2143 |
^ v |
|
2144 |
||
4896 | 2145 |
" |
2146 |
|s| |
|
2147 |
||
2148 |
s := 'Makefile' asFilename readStream. |
|
2149 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2150 |
^ self |
4896 | 2151 |
] valueOnUnwindDo:[ |
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2152 |
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
|
2153 |
s close |
4896 | 2154 |
] |
2155 |
" |
|
2156 |
" |
|
2157 |
[ |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2158 |
|s| |
4896 | 2159 |
|
6498
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2160 |
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
|
2161 |
[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2162 |
Processor activeProcess terminate |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2163 |
] valueOnUnwindDo:[ |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2164 |
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
|
2165 |
s close |
3db82d6e6146
use arrayVal macro; slightly shorter code for value (switch on MKSMALLINT)
Claus Gittinger <cg@exept.de>
parents:
6320
diff
changeset
|
2166 |
] |
4896 | 2167 |
] fork |
2168 |
" |
|
623 | 2169 |
! ! |
2170 |
||
8394
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
2171 |
!Block methodsFor:'visiting'! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
2172 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
2173 |
acceptVisitor:aVisitor with:aParameter |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
2174 |
|
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
2175 |
^ aVisitor visitBlock:self with:aParameter |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
2176 |
! ! |
da194de43766
Generalize visitor pattern and define #visit...:with: -methods instead
Stefan Vogel <sv@exept.de>
parents:
8009
diff
changeset
|
2177 |
|
1773
442d1b73ecb9
no longer allow Blocks with a dynamic-bit to be created
Claus Gittinger <cg@exept.de>
parents:
1672
diff
changeset
|
2178 |
!Block class methodsFor:'documentation'! |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2179 |
|
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2180 |
version |
8708
fd7eba3420e1
Dolphin compat: #deferredValue is the same as #futureValue
Stefan Vogel <sv@exept.de>
parents:
8682
diff
changeset
|
2181 |
^ '$Header: /cvs/stx/stx/libbasic/Block.st,v 1.143 2005-01-26 14:02:39 stefan Exp $' |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
2182 |
! ! |
6785 | 2183 |
|
623 | 2184 |
Block initialize! |