author | Claus Gittinger <cg@exept.de> |
Sun, 22 Sep 1996 15:01:43 +0200 | |
changeset 1672 | 1b56d6e95c9e |
parent 1626 | b3b69b572627 |
child 1773 | 442d1b73ecb9 |
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 |
||
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
13 |
'From Smalltalk/X, Version:2.10.9 on 25-jun-1996 at 14:32:20' ! |
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
14 |
|
249 | 15 |
CompiledCode subclass:#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 |
||
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
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) |
1254 | 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 |
|
1254 | 78 |
relative to methods source beginning |
222 | 79 |
initialPC <SmallInteger> the start position within the byteCode |
1254 | 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 |
|
1254 | 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:] |
|
93 |
Claus Gittinger |
|
94 |
||
95 |
[see also:] |
|
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: |
1316 | 105 |
[exBegin] |
1265 | 106 |
|b| |
107 |
||
1422 | 108 |
b := [ Transcript showCR:'hello' ]. |
1293 | 109 |
|
1422 | 110 |
Transcript showCR:'now evaluating the block ...'. |
1265 | 111 |
b value. |
1316 | 112 |
[exEnd] |
1265 | 113 |
|
114 |
||
1293 | 115 |
|
1265 | 116 |
even here, blocks are involved: |
117 |
(although, the compiler optimizes things if possible) |
|
1316 | 118 |
[exBegin] |
1422 | 119 |
Transcript showCR:'now evaluating one of two blocks ...'. |
1265 | 120 |
1 > 4 ifTrue:[ |
1422 | 121 |
Transcript showCR:'foo' |
1265 | 122 |
] ifFalse:[ |
1422 | 123 |
Transcript showCR:'bar' |
1265 | 124 |
] |
1316 | 125 |
[exEnd] |
1265 | 126 |
|
127 |
||
1293 | 128 |
|
1265 | 129 |
here things become obvious: |
1316 | 130 |
[exBegin] |
1265 | 131 |
|yesBlock noBlock| |
132 |
||
1422 | 133 |
yesBlock := [ Transcript showCR:'foo' ]. |
134 |
noBlock := [ Transcript showCR:'bar' ]. |
|
1265 | 135 |
|
1422 | 136 |
Transcript showCR:'now evaluating one of two blocks ...'. |
1265 | 137 |
1 > 4 ifTrue:yesBlock |
138 |
ifFalse:noBlock |
|
1316 | 139 |
[exEnd] |
1265 | 140 |
|
141 |
||
1293 | 142 |
|
1265 | 143 |
simple loops: |
144 |
not very objectOriented: |
|
1316 | 145 |
[exBegin] |
1265 | 146 |
|i| |
147 |
||
148 |
i := 1. |
|
149 |
[i < 10] whileTrue:[ |
|
1422 | 150 |
Transcript showCR:i. |
1265 | 151 |
i := i + 1 |
152 |
] |
|
1316 | 153 |
[exEnd] |
1265 | 154 |
|
155 |
||
156 |
using integer protocol: |
|
1316 | 157 |
[exBegin] |
1265 | 158 |
1 to:10 do:[:i | |
1422 | 159 |
Transcript showCR:i. |
1265 | 160 |
] |
1316 | 161 |
[exEnd] |
1265 | 162 |
|
163 |
||
164 |
interval protocol: |
|
1316 | 165 |
[exBegin] |
1265 | 166 |
(1 to:10) do:[:i | |
1422 | 167 |
Transcript showCR:i. |
1265 | 168 |
] |
1316 | 169 |
[exEnd] |
1265 | 170 |
|
171 |
||
1293 | 172 |
|
1265 | 173 |
looping over collections: |
174 |
||
1293 | 175 |
bad code: |
176 |
(only works with numeric-indexable collections) |
|
1316 | 177 |
[exBegin] |
1265 | 178 |
|i coll| |
179 |
||
180 |
coll := #(9 8 7 6 5). |
|
181 |
i := 1. |
|
182 |
[i <= coll size] whileTrue:[ |
|
1422 | 183 |
Transcript showCR:(coll at:i). |
1265 | 184 |
i := i + 1. |
185 |
] |
|
1316 | 186 |
[exEnd] |
1265 | 187 |
|
188 |
||
189 |
||
1293 | 190 |
just as bad (well, marginally better ;-): |
191 |
(only works with numeric-indexable collections) |
|
1316 | 192 |
[exBegin] |
1293 | 193 |
|coll| |
1265 | 194 |
|
195 |
coll := #(9 8 7 6 5). |
|
196 |
1 to:coll size do:[:i | |
|
1422 | 197 |
Transcript showCR:(coll at:i). |
1265 | 198 |
] |
1316 | 199 |
[exEnd] |
1265 | 200 |
|
201 |
||
202 |
||
1293 | 203 |
the smalltalk way: |
204 |
(works with any collection) |
|
1316 | 205 |
[exBegin] |
1293 | 206 |
|coll| |
1265 | 207 |
|
208 |
coll := #(9 8 7 6 5). |
|
209 |
coll do:[:element | |
|
1422 | 210 |
Transcript showCR:element. |
1265 | 211 |
] |
1316 | 212 |
[exEnd] |
1265 | 213 |
|
214 |
Rule: use enumeration protocol of the collection instead of |
|
215 |
manually indexing it. [with few exceptions] |
|
216 |
||
217 |
||
218 |
||
219 |
processes: |
|
220 |
||
221 |
forking a lightweight process (thread): |
|
1316 | 222 |
[exBegin] |
1265 | 223 |
[ |
1422 | 224 |
Transcript showCR:'waiting ...'. |
1265 | 225 |
Delay waitForSeconds:2. |
1422 | 226 |
Transcript showCR:'here I am'. |
1265 | 227 |
] fork |
1316 | 228 |
[exEnd] |
1265 | 229 |
|
230 |
||
231 |
||
232 |
some with low prio: |
|
1316 | 233 |
[exBegin] |
1265 | 234 |
[ |
1422 | 235 |
Transcript showCR:'computing ...'. |
1265 | 236 |
10000 factorial. |
1422 | 237 |
Transcript showCR:'here I am'. |
1265 | 238 |
] forkAt:(Processor userBackgroundPriority) |
1316 | 239 |
[exEnd] |
1265 | 240 |
|
241 |
||
1293 | 242 |
|
243 |
handling exceptions: |
|
1316 | 244 |
[exBegin] |
1265 | 245 |
Object errorSignal handle:[:ex | |
1422 | 246 |
Transcript showCR:'exception handler forces return'. |
1265 | 247 |
ex return |
248 |
] do:[ |
|
1422 | 249 |
Transcript showCR:'now, doing something bad ...'. |
1265 | 250 |
1 / 0. |
1422 | 251 |
Transcript showCR:'not reached' |
1265 | 252 |
] |
1316 | 253 |
[exEnd] |
1265 | 254 |
|
255 |
||
1293 | 256 |
|
257 |
performing cleanup actions: |
|
1316 | 258 |
[exBegin] |
1265 | 259 |
Object errorSignal handle:[:ex | |
1422 | 260 |
Transcript showCR:'exception handler forces return'. |
1265 | 261 |
ex return |
262 |
] do:[ |
|
263 |
[ |
|
1422 | 264 |
Transcript showCR:'doing something bad ...'. |
1265 | 265 |
1 / 0. |
1422 | 266 |
Transcript showCR:'not reached' |
1265 | 267 |
] valueOnUnwindDo:[ |
1422 | 268 |
Transcript showCR:'cleanup' |
1265 | 269 |
] |
270 |
] |
|
1316 | 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 ;-) |
|
1316 | 277 |
[exBegin] |
1265 | 278 |
|showBlock countBlock |
279 |
howMany |
|
280 |
top panel b1 b2| |
|
281 |
||
282 |
howMany := 0. |
|
283 |
||
1422 | 284 |
showBlock := [ Transcript showCR:howMany ]. |
1265 | 285 |
countBlock := [ howMany := howMany + 1 ]. |
286 |
||
287 |
top := StandardSystemView extent:200@200. |
|
288 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
289 |
||
290 |
b1 := Button label:'count up' in:panel. |
|
291 |
b1 action:countBlock. |
|
292 |
||
293 |
b2 := Button label:'show value' in:panel. |
|
294 |
b2 action:showBlock. |
|
295 |
||
296 |
top open. |
|
297 |
||
1422 | 298 |
Transcript showCR:'new process started;'. |
299 |
Transcript showCR:'notice: the blocks can still access the'. |
|
300 |
Transcript showCR:' howMany local variable.'. |
|
1316 | 301 |
[exEnd] |
1265 | 302 |
" |
1 | 303 |
! ! |
304 |
||
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
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:[ |
1254 | 311 |
InvalidNewSignal := ErrorSignal newSignalMayProceed:false. |
312 |
InvalidNewSignal nameClass:self message:#invalidNewSignal. |
|
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 |
||
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
319 |
!Block class methodsFor:'instance creation'! |
1 | 320 |
|
154 | 321 |
code:codeAddress byteCode:bCode numArgs:numArgs sourcePosition:sourcePos initialPC:initialPC literals:literals dynamic:dynamic |
1 | 322 |
"create a new cheap (homeless) block. |
222 | 323 |
Not for public use - this is a special hook for the compiler." |
1 | 324 |
|
325 |
|newBlock| |
|
326 |
||
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
327 |
newBlock := (super basicNew:(literals size)) |
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
328 |
code:codeAddress |
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
329 |
byteCode:bCode |
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
330 |
numArgs:numArgs |
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
331 |
sourcePosition:sourcePos |
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
332 |
initialPC:initialPC |
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
333 |
literals:literals |
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
334 |
dynamic:dynamic. |
1 | 335 |
^ newBlock |
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
336 |
|
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
337 |
"Modified: 24.6.1996 / 12:36:48 / stefan" |
1 | 338 |
! |
339 |
||
22 | 340 |
new |
1 | 341 |
"catch creation of blocks - only the system creates blocks" |
342 |
||
128 | 343 |
^ InvalidNewSignal raise. |
1 | 344 |
! |
345 |
||
22 | 346 |
new:size |
1 | 347 |
"catch creation of blocks - only the system creates blocks" |
348 |
||
128 | 349 |
^ InvalidNewSignal raise. |
1 | 350 |
! ! |
351 |
||
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
352 |
!Block class methodsFor:'queries'! |
1 | 353 |
|
623 | 354 |
isBuiltInClass |
1264 | 355 |
"return true if this class is known by the run-time-system. |
356 |
Here, true is returned for myself, false for subclasses." |
|
11 | 357 |
|
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
358 |
^ self == Block |
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
359 |
|
1264 | 360 |
"Modified: 23.4.1996 / 15:55:58 / cg" |
1626 | 361 |
! |
362 |
||
363 |
maxNumberOfArguments |
|
364 |
"return the maximum number of arguments a block can have. |
|
365 |
This is a limit in the VM, which may be removed in one of |
|
366 |
the next versions ..." |
|
367 |
||
368 |
%{ /* NOCONTEXT */ |
|
369 |
RETURN (__MKSMALLINT(MAX_METHOD_ARGS)); |
|
370 |
%} |
|
1 | 371 |
! ! |
372 |
||
623 | 373 |
!Block methodsFor:'STV compatibility'! |
1 | 374 |
|
623 | 375 |
on:aSignal do:exceptionBlock |
376 |
"added for ST/V compatibility; evaluate the receiver, |
|
377 |
handling aSignal. The argument, exceptionBlock is evaluated |
|
378 |
if the signal is raised during evaluation. |
|
379 |
Warning: no warranty, if the code below mimics ST/V's behavior |
|
380 |
correctly - give me a note if it does not ." |
|
1 | 381 |
|
623 | 382 |
aSignal handle:[:ex | |
383 |
exceptionBlock value. |
|
384 |
ex return |
|
385 |
] do:self |
|
1 | 386 |
|
623 | 387 |
" |
388 |
[ |
|
389 |
1 foo |
|
390 |
] on:MessageNotUnderstoodSignal do:[] |
|
391 |
" |
|
392 |
! ! |
|
393 |
||
394 |
!Block methodsFor:'accessing'! |
|
154 | 395 |
|
396 |
home |
|
397 |
"return the receivers home context (the context where it was |
|
398 |
created). For cheap blocks, nil is returned" |
|
399 |
||
400 |
^ home |
|
161 | 401 |
! |
402 |
||
403 |
method |
|
404 |
"return the receivers method |
|
405 |
(the method where the block was created)." |
|
406 |
||
407 |
home notNil ifTrue:[ |
|
408 |
^ home method |
|
409 |
]. |
|
410 |
^ nil |
|
623 | 411 |
! |
11 | 412 |
|
623 | 413 |
methodHome |
414 |
"return the receivers method home context (the context where it was |
|
415 |
defined). For cheap blocks, nil is returned" |
|
416 |
||
417 |
home notNil ifTrue:[ |
|
418 |
^ home methodHome |
|
419 |
]. |
|
420 |
^ home |
|
11 | 421 |
! |
422 |
||
623 | 423 |
numArgs |
424 |
"return the number of arguments I expect for evaluation" |
|
1 | 425 |
|
623 | 426 |
^ nargs |
427 |
! ! |
|
1 | 428 |
|
623 | 429 |
!Block methodsFor:'copying'! |
1 | 430 |
|
623 | 431 |
deepCopy |
432 |
"raise an error - deepCopy is not allowed for blocks" |
|
1 | 433 |
|
623 | 434 |
^ self deepCopyError |
1 | 435 |
! ! |
436 |
||
437 |
!Block methodsFor:'error handling'! |
|
438 |
||
328 | 439 |
invalidCodeObject |
67 | 440 |
"this error is triggered by the interpreter when a non-Block object |
441 |
is about to be executed. |
|
442 |
In this case, the VM sends this to the bad method (the receiver). |
|
443 |
Can only happen when the Compiler/runtime system is broken or |
|
444 |
someone played around." |
|
1 | 445 |
|
128 | 446 |
^ InvalidCodeSignal |
154 | 447 |
raiseRequestWith:self |
448 |
errorString:'invalid block - not executable' |
|
623 | 449 |
! |
450 |
||
451 |
wrongNumberOfArguments:numberGiven |
|
452 |
"report that the number of arguments given does not match the number expected" |
|
453 |
||
454 |
^ ArgumentSignal |
|
455 |
raiseRequestWith:self |
|
456 |
errorString:('block got ' , numberGiven printString , |
|
457 |
' args while ' , nargs printString , ' where expected') |
|
1 | 458 |
! ! |
459 |
||
460 |
!Block methodsFor:'evaluation'! |
|
461 |
||
462 |
value |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
463 |
"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
|
464 |
The receiver must be a block without arguments." |
1 | 465 |
|
466 |
%{ /* NOCONTEXT */ |
|
467 |
||
468 |
REGISTER OBJFUNC thecode; |
|
469 |
OBJ home; |
|
470 |
||
1133 | 471 |
if (__INST(nargs) == __MKSMALLINT(0)) { |
1 | 472 |
#if defined(THIS_CONTEXT) |
328 | 473 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 474 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 475 |
#endif |
328 | 476 |
|
1133 | 477 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 478 |
#ifdef NEW_BLOCK_CALL |
154 | 479 |
if (thecode != (OBJFUNC)nil) { |
480 |
/* compiled machine code */ |
|
481 |
RETURN ( (*thecode)(self, COMMA_SND) ); |
|
482 |
} |
|
483 |
/* interpreted code */ |
|
328 | 484 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
485 |
RETURN ( __interpret(self, 0, nil, nil COMMA_SND, nil, nil) ); |
328 | 486 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
487 |
RETURN ( __interpret(self, 0, nil, nil COMMA_SND, nil, nil) ); |
328 | 488 |
# endif |
11 | 489 |
#else |
1133 | 490 |
home = __BlockInstPtr(self)->b_home; |
154 | 491 |
if (thecode != (OBJFUNC)nil) { |
492 |
/* compiled machine code */ |
|
493 |
RETURN ( (*thecode)(home COMMA_SND) ); |
|
494 |
} |
|
495 |
/* interpreted code */ |
|
328 | 496 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
497 |
RETURN ( __interpret(self, 0, nil, home COMMA_SND, nil, nil) ); |
328 | 498 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
499 |
RETURN ( __interpret(self, 0, nil, home COMMA_SND, nil, nil) ); |
328 | 500 |
# endif |
11 | 501 |
#endif |
1 | 502 |
} |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
503 |
%}. |
103 | 504 |
^ self wrongNumberOfArguments:0 |
1 | 505 |
! |
506 |
||
507 |
value:arg |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
508 |
"evaluate the receiver with one argument. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
509 |
The receiver must be a 1-arg block." |
1 | 510 |
|
511 |
%{ /* NOCONTEXT */ |
|
512 |
||
513 |
REGISTER OBJFUNC thecode; |
|
514 |
OBJ home; |
|
515 |
||
1133 | 516 |
if (__INST(nargs) == __MKSMALLINT(1)) { |
1 | 517 |
#if defined(THIS_CONTEXT) |
328 | 518 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 519 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 520 |
#endif |
1133 | 521 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 522 |
#ifdef NEW_BLOCK_CALL |
154 | 523 |
if (thecode != (OBJFUNC)nil) { |
524 |
RETURN ( (*thecode)(self COMMA_SND, arg) ); |
|
525 |
} |
|
526 |
/* interpreted code */ |
|
328 | 527 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
528 |
RETURN ( __interpret(self, 1, nil, nil COMMA_SND, nil, nil, &arg) ); |
328 | 529 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
530 |
RETURN ( __interpret(self, 1, nil, nil COMMA_SND, nil, nil, arg) ); |
328 | 531 |
# endif |
1 | 532 |
#else |
1133 | 533 |
home = __BlockInstPtr(self)->b_home; |
154 | 534 |
if (thecode != (OBJFUNC)nil) { |
535 |
RETURN ( (*thecode)(home COMMA_SND, arg) ); |
|
536 |
} |
|
537 |
/* interpreted code */ |
|
328 | 538 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
539 |
RETURN ( __interpret(self, 1, nil, home COMMA_SND, nil, nil, &arg) ); |
328 | 540 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
541 |
RETURN ( __interpret(self, 1, nil, home COMMA_SND, nil, nil, arg) ); |
328 | 542 |
# endif |
1 | 543 |
#endif |
544 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
545 |
%}. |
103 | 546 |
^ self wrongNumberOfArguments:1 |
1 | 547 |
! |
548 |
||
549 |
value:arg1 value:arg2 |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
550 |
"evaluate the receiver with two arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
551 |
The receiver must be a 2-arg block." |
1 | 552 |
|
553 |
%{ /* NOCONTEXT */ |
|
554 |
||
555 |
REGISTER OBJFUNC thecode; |
|
556 |
OBJ home; |
|
557 |
||
1133 | 558 |
if (__INST(nargs) == __MKSMALLINT(2)) { |
1 | 559 |
#if defined(THIS_CONTEXT) |
328 | 560 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 561 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 562 |
#endif |
1133 | 563 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 564 |
#ifdef NEW_BLOCK_CALL |
154 | 565 |
if (thecode != (OBJFUNC)nil) { |
566 |
RETURN ( (*thecode)(self COMMA_SND, arg1, arg2) ); |
|
567 |
} |
|
328 | 568 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
569 |
RETURN ( __interpret(self, 2, nil, nil COMMA_SND, nil, nil, &arg1) ); |
328 | 570 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
571 |
RETURN ( __interpret(self, 2, nil, nil COMMA_SND, nil, nil, arg1, arg2) ); |
328 | 572 |
# endif |
1 | 573 |
#else |
1133 | 574 |
home = __BlockInstPtr(self)->b_home; |
154 | 575 |
if (thecode != (OBJFUNC)nil) { |
576 |
RETURN ( (*thecode)(home COMMA_SND, arg1, arg2) ); |
|
577 |
} |
|
328 | 578 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
579 |
RETURN ( __interpret(self, 2, nil, home COMMA_SND, nil, nil, &arg1) ); |
328 | 580 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
581 |
RETURN ( __interpret(self, 2, nil, home COMMA_SND, nil, nil, arg1, arg2) ); |
328 | 582 |
# endif |
1 | 583 |
#endif |
584 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
585 |
%}. |
103 | 586 |
^ self wrongNumberOfArguments:2 |
1 | 587 |
! |
588 |
||
589 |
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
|
590 |
"evaluate the receiver with three arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
591 |
The receiver must be a 3-arg block." |
1 | 592 |
|
593 |
%{ /* NOCONTEXT */ |
|
594 |
||
595 |
REGISTER OBJFUNC thecode; |
|
596 |
OBJ home; |
|
597 |
||
1133 | 598 |
if (__INST(nargs) == __MKSMALLINT(3)) { |
1 | 599 |
#if defined(THIS_CONTEXT) |
328 | 600 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 601 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 602 |
#endif |
1133 | 603 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 604 |
#ifdef NEW_BLOCK_CALL |
154 | 605 |
if (thecode != (OBJFUNC)nil) { |
606 |
RETURN ( (*thecode)(self COMMA_SND, arg1, arg2, arg3) ); |
|
607 |
} |
|
328 | 608 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
609 |
RETURN ( __interpret(self, 3, nil, nil COMMA_SND, nil, nil, &arg1) ); |
328 | 610 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
611 |
RETURN ( __interpret(self, 3, nil, nil COMMA_SND, nil, nil, arg1, arg2, arg3) ); |
328 | 612 |
# endif |
1 | 613 |
#else |
1133 | 614 |
home = __BlockInstPtr(self)->b_home; |
154 | 615 |
if (thecode != (OBJFUNC)nil) { |
616 |
RETURN ( (*thecode)(home COMMA_SND, arg1, arg2, arg3) ); |
|
617 |
} |
|
328 | 618 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
619 |
RETURN ( __interpret(self, 3, nil, home COMMA_SND, nil, nil, &arg1) ); |
328 | 620 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
621 |
RETURN ( __interpret(self, 3, nil, home COMMA_SND, nil, nil, arg1, arg2, arg3) ); |
328 | 622 |
# endif |
1 | 623 |
#endif |
624 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
625 |
%}. |
103 | 626 |
^ self wrongNumberOfArguments:3 |
1 | 627 |
! |
628 |
||
629 |
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
|
630 |
"evaluate the receiver with four arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
631 |
The receiver must be a 4-arg block." |
1 | 632 |
|
633 |
%{ /* NOCONTEXT */ |
|
634 |
||
635 |
REGISTER OBJFUNC thecode; |
|
636 |
OBJ home; |
|
637 |
||
1133 | 638 |
if (__INST(nargs) == __MKSMALLINT(4)) { |
1 | 639 |
#if defined(THIS_CONTEXT) |
328 | 640 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 641 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 642 |
#endif |
1133 | 643 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 644 |
#ifdef NEW_BLOCK_CALL |
154 | 645 |
if (thecode != (OBJFUNC)nil) { |
646 |
RETURN ( (*thecode)(self COMMA_SND, arg1, arg2, arg3, arg4) ); |
|
647 |
} |
|
328 | 648 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
649 |
RETURN ( __interpret(self, 4, nil, nil COMMA_SND, nil, nil, &arg1) ); |
328 | 650 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
651 |
RETURN ( __interpret(self, 4, nil, nil COMMA_SND, nil, nil, arg1, arg2, arg3, arg4) ); |
328 | 652 |
# endif |
1 | 653 |
#else |
1133 | 654 |
home = __BlockInstPtr(self)->b_home; |
154 | 655 |
if (thecode != (OBJFUNC)nil) { |
656 |
RETURN ( (*thecode)(home COMMA_SND, arg1, arg2, arg3, arg4) ); |
|
657 |
} |
|
328 | 658 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
659 |
RETURN ( __interpret(self, 4, nil, home COMMA_SND, nil, nil, &arg1) ); |
328 | 660 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
661 |
RETURN ( __interpret(self, 4, nil, home COMMA_SND, nil, nil, arg1, arg2, arg3, arg4) ); |
328 | 662 |
# endif |
1 | 663 |
#endif |
664 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
665 |
%}. |
103 | 666 |
^ self wrongNumberOfArguments:4 |
1 | 667 |
! |
668 |
||
669 |
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
|
670 |
"evaluate the receiver with five arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
671 |
The receiver must be a 5-arg block." |
1 | 672 |
|
673 |
%{ /* NOCONTEXT */ |
|
674 |
||
675 |
REGISTER OBJFUNC thecode; |
|
676 |
OBJ home; |
|
677 |
||
1133 | 678 |
if (__INST(nargs) == __MKSMALLINT(5)) { |
1 | 679 |
#if defined(THIS_CONTEXT) |
328 | 680 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 681 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 682 |
#endif |
1133 | 683 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 684 |
#ifdef NEW_BLOCK_CALL |
154 | 685 |
if (thecode != (OBJFUNC)nil) { |
686 |
RETURN ( (*thecode)(self COMMA_SND, arg1, arg2, arg3, arg4, arg5) ); |
|
687 |
} |
|
328 | 688 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
689 |
RETURN ( __interpret(self, 5, nil, nil COMMA_SND, nil, nil, &arg1) ); |
328 | 690 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
691 |
RETURN ( __interpret(self, 5, nil, nil COMMA_SND, nil, nil, arg1, arg2, arg3, arg4, arg5) ); |
328 | 692 |
# endif |
1 | 693 |
#else |
1133 | 694 |
home = __BlockInstPtr(self)->b_home; |
154 | 695 |
if (thecode != (OBJFUNC)nil) { |
696 |
RETURN ( (*thecode)(home COMMA_SND, arg1, arg2, arg3, arg4, arg5) ); |
|
697 |
} |
|
328 | 698 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
699 |
RETURN ( __interpret(self, 5, nil, home COMMA_SND, nil, nil, &arg1) ); |
328 | 700 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
701 |
RETURN ( __interpret(self, 5, nil, home COMMA_SND, nil, nil, arg1, arg2, arg3, arg4, arg5) ); |
328 | 702 |
# endif |
1 | 703 |
#endif |
704 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
705 |
%}. |
103 | 706 |
^ self wrongNumberOfArguments:5 |
1 | 707 |
! |
708 |
||
709 |
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
|
710 |
"evaluate the receiver with six arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
711 |
The receiver must be a 6-arg block." |
1 | 712 |
|
713 |
%{ /* NOCONTEXT */ |
|
714 |
||
715 |
REGISTER OBJFUNC thecode; |
|
716 |
OBJ home; |
|
717 |
||
1133 | 718 |
if (__INST(nargs) == __MKSMALLINT(6)) { |
1 | 719 |
#if defined(THIS_CONTEXT) |
328 | 720 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 721 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 722 |
#endif |
1133 | 723 |
thecode = __BlockInstPtr(self)->b_code; |
11 | 724 |
#ifdef NEW_BLOCK_CALL |
154 | 725 |
if (thecode != (OBJFUNC)nil) { |
726 |
RETURN ( (*thecode)(self COMMA_SND, arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
727 |
} |
|
328 | 728 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
729 |
RETURN ( __interpret(self, 6, nil, nil COMMA_SND, nil, nil, &arg1) ); |
328 | 730 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
731 |
RETURN ( __interpret(self, 6, nil, nil COMMA_SND, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
328 | 732 |
# endif |
1 | 733 |
#else |
1133 | 734 |
home = __BlockInstPtr(self)->b_home; |
154 | 735 |
if (thecode != (OBJFUNC)nil) { |
736 |
RETURN ( (*thecode)(home COMMA_SND, arg1, arg2, arg3, arg4, arg5, arg6) ); |
|
737 |
} |
|
328 | 738 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
739 |
RETURN ( __interpret(self, 6, nil, home COMMA_SND, nil, nil, &arg1) ); |
328 | 740 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
741 |
RETURN ( __interpret(self, 6, nil, home COMMA_SND, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) ); |
328 | 742 |
# endif |
1 | 743 |
#endif |
744 |
} |
|
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
745 |
%}. |
103 | 746 |
^ self wrongNumberOfArguments:6 |
1 | 747 |
! |
748 |
||
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
749 |
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
|
750 |
"evaluate the receiver with seven arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
751 |
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
|
752 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
753 |
%{ /* NOCONTEXT */ |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
754 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
755 |
REGISTER OBJFUNC thecode; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
756 |
OBJ home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
757 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
758 |
if (__INST(nargs) == __MKSMALLINT(7)) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
759 |
#if defined(THIS_CONTEXT) |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
760 |
if (__ISVALID_ILC_LNO(__pilc)) |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
761 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
762 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
763 |
thecode = __BlockInstPtr(self)->b_code; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
764 |
#ifdef NEW_BLOCK_CALL |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
765 |
if (thecode != (OBJFUNC)nil) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
766 |
RETURN ( (*thecode)(self COMMA_SND, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
767 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
768 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
769 |
RETURN ( __interpret(self, 7, nil, nil COMMA_SND, nil, nil, &arg1) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
770 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
771 |
RETURN ( __interpret(self, 7, nil, nil COMMA_SND, 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
|
772 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
773 |
#else |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
774 |
home = __BlockInstPtr(self)->b_home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
775 |
if (thecode != (OBJFUNC)nil) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
776 |
RETURN ( (*thecode)(home COMMA_SND, arg1, arg2, arg3, arg4, arg5, arg6, arg7) ); |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
777 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
778 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
779 |
RETURN ( __interpret(self, 7, nil, home COMMA_SND, nil, nil, &arg1) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
780 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
781 |
RETURN ( __interpret(self, 7, nil, home COMMA_SND, 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
|
782 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
783 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
784 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
785 |
%}. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
786 |
^ self wrongNumberOfArguments:7 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
787 |
! |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
788 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
789 |
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
|
790 |
"evaluate the receiver with eight arguments. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
791 |
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
|
792 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
793 |
%{ /* NOCONTEXT */ |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
794 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
795 |
REGISTER OBJFUNC thecode; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
796 |
OBJ home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
797 |
|
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
798 |
if (__INST(nargs) == __MKSMALLINT(8)) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
799 |
#if defined(THIS_CONTEXT) |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
800 |
if (__ISVALID_ILC_LNO(__pilc)) |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
801 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
802 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
803 |
thecode = __BlockInstPtr(self)->b_code; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
804 |
#ifdef NEW_BLOCK_CALL |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
805 |
if (thecode != (OBJFUNC)nil) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
806 |
RETURN ( (*thecode)(self COMMA_SND, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
807 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
808 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
809 |
RETURN ( __interpret(self, 8, nil, nil COMMA_SND, nil, nil, &arg1) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
810 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
811 |
RETURN ( __interpret(self, 8, nil, nil COMMA_SND, 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
|
812 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
813 |
#else |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
814 |
home = __BlockInstPtr(self)->b_home; |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
815 |
if (thecode != (OBJFUNC)nil) { |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
816 |
RETURN ( (*thecode)(home COMMA_SND, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) ); |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
817 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
818 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
819 |
RETURN ( __interpret(self, 8, nil, home COMMA_SND, nil, nil, &arg1) ); |
1605
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
820 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
821 |
RETURN ( __interpret(self, 8, nil, home COMMA_SND, 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
|
822 |
# endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
823 |
#endif |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
824 |
} |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
825 |
%}. |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
826 |
^ self wrongNumberOfArguments:8 |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
827 |
! |
61def0ffbdd6
added value:...value: with 7 and 8 args
Claus Gittinger <cg@exept.de>
parents:
1493
diff
changeset
|
828 |
|
1 | 829 |
valueWithArguments:argArray |
830 |
"evaluate the receiver with arguments taken from argArray. |
|
313 | 831 |
ArgArray must be either an Array or nil. |
1 | 832 |
The size of the argArray must match the number of arguments the receiver expects." |
833 |
||
1037 | 834 |
|a1 a2 a3 a4 a5 a6 a7 a8| |
1 | 835 |
|
319 | 836 |
(argArray notNil and:[argArray class ~~ Array]) ifTrue:[ |
154 | 837 |
^ self badArgumentArry |
1 | 838 |
]. |
839 |
(argArray size == nargs) ifFalse:[ |
|
154 | 840 |
^ self wrongNumberOfArguments:(argArray size) |
1 | 841 |
]. |
842 |
%{ |
|
843 |
||
844 |
REGISTER OBJFUNC thecode; |
|
845 |
OBJ home; |
|
67 | 846 |
REGISTER OBJ *ap; |
328 | 847 |
int nargs; |
1 | 848 |
|
849 |
#if defined(THIS_CONTEXT) |
|
328 | 850 |
if (__ISVALID_ILC_LNO(__pilc)) |
1133 | 851 |
__ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc); |
1 | 852 |
#endif |
1133 | 853 |
thecode = __BlockInstPtr(self)->b_code; |
1037 | 854 |
|
855 |
#ifndef NEW_BLOCK_CALL |
|
1133 | 856 |
home = __BlockInstPtr(self)->b_home; |
1037 | 857 |
if (thecode != (OBJFUNC)nil) { |
1133 | 858 |
switch (nargs = __intVal(__INST(nargs))) { |
1037 | 859 |
default: |
860 |
goto error; |
|
861 |
case 8: |
|
1133 | 862 |
ap = __ArrayInstPtr(argArray)->a_element; |
1037 | 863 |
RETURN ( (*thecode)(home COMMA_SND, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7]) ); |
864 |
case 7: |
|
1133 | 865 |
ap = __ArrayInstPtr(argArray)->a_element; |
1037 | 866 |
RETURN ( (*thecode)(home COMMA_SND, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) ); |
867 |
case 6: |
|
1133 | 868 |
ap = __ArrayInstPtr(argArray)->a_element; |
1037 | 869 |
RETURN ( (*thecode)(home COMMA_SND, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) ); |
870 |
case 5: |
|
1133 | 871 |
ap = __ArrayInstPtr(argArray)->a_element; |
1037 | 872 |
RETURN ( (*thecode)(home COMMA_SND, ap[0], ap[1], ap[2], ap[3], ap[4]) ); |
873 |
case 4: |
|
1133 | 874 |
ap = __ArrayInstPtr(argArray)->a_element; |
1037 | 875 |
RETURN ( (*thecode)(home COMMA_SND, ap[0], ap[1], ap[2], ap[3]) ); |
876 |
case 3: |
|
1133 | 877 |
ap = __ArrayInstPtr(argArray)->a_element; |
1037 | 878 |
RETURN ( (*thecode)(home COMMA_SND, ap[0], ap[1], ap[2]) ); |
879 |
case 2: |
|
1133 | 880 |
ap = __ArrayInstPtr(argArray)->a_element; |
1037 | 881 |
RETURN ( (*thecode)(home COMMA_SND, ap[0], ap[1]) ); |
882 |
case 1: |
|
1133 | 883 |
RETURN ( (*thecode)(home COMMA_SND, __ArrayInstPtr(argArray)->a_element[0]) ); |
1037 | 884 |
case 0: |
885 |
RETURN ( (*thecode)(home COMMA_SND) ); |
|
886 |
break; |
|
887 |
} |
|
888 |
} |
|
889 |
#endif |
|
890 |
||
1133 | 891 |
switch (nargs = __intVal(__INST(nargs))) { |
154 | 892 |
default: |
893 |
goto error; |
|
1037 | 894 |
case 8: |
1133 | 895 |
a8 = __ArrayInstPtr(argArray)->a_element[7]; |
154 | 896 |
case 7: |
1133 | 897 |
a7 = __ArrayInstPtr(argArray)->a_element[6]; |
154 | 898 |
case 6: |
1133 | 899 |
a6 = __ArrayInstPtr(argArray)->a_element[5]; |
154 | 900 |
case 5: |
1133 | 901 |
a5 = __ArrayInstPtr(argArray)->a_element[4]; |
154 | 902 |
case 4: |
1133 | 903 |
a4 = __ArrayInstPtr(argArray)->a_element[3]; |
154 | 904 |
case 3: |
1133 | 905 |
a3 = __ArrayInstPtr(argArray)->a_element[2]; |
154 | 906 |
case 2: |
1133 | 907 |
a2 = __ArrayInstPtr(argArray)->a_element[1]; |
154 | 908 |
case 1: |
1133 | 909 |
a1 = __ArrayInstPtr(argArray)->a_element[0]; |
154 | 910 |
case 0: |
911 |
break; |
|
1 | 912 |
} |
1133 | 913 |
|
11 | 914 |
#ifdef NEW_BLOCK_CALL |
1 | 915 |
if (thecode != (OBJFUNC)nil) { |
1037 | 916 |
RETURN ( (*thecode)(self COMMA_SND, a1, a2, a3, a4, a5, a6, a7, a8) ); |
11 | 917 |
} |
328 | 918 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
919 |
RETURN ( __interpret(self, nargs, nil, nil COMMA_SND, nil, nil, &a1) ); |
328 | 920 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
921 |
RETURN ( __interpret(self, nargs, nil, nil COMMA_SND, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8) ); |
328 | 922 |
# endif |
1037 | 923 |
|
1 | 924 |
#else |
1037 | 925 |
|
328 | 926 |
# ifdef PASS_ARG_POINTER |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
927 |
RETURN ( __interpret(self, nargs, nil, home COMMA_SND, nil, nil, &a1) ); |
328 | 928 |
# else |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
929 |
RETURN ( __interpret(self, nargs, nil, home COMMA_SND, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8) ); |
328 | 930 |
# endif |
1037 | 931 |
|
1 | 932 |
#endif |
67 | 933 |
|
11 | 934 |
error: ; |
1 | 935 |
%} |
11 | 936 |
. |
138 | 937 |
" |
938 |
the above code only supports up-to 7 arguments |
|
939 |
" |
|
128 | 940 |
^ ArgumentSignal |
154 | 941 |
raiseRequestWith:self |
942 |
errorString:'only blocks with up-to 7 arguments supported' |
|
943 |
! ! |
|
944 |
||
623 | 945 |
!Block methodsFor:'looping'! |
325 | 946 |
|
623 | 947 |
doUntil:aBlock |
948 |
"repeat the receiver block until aBlock evaluates to true. |
|
949 |
The receiver is evaluated at least once. |
|
950 |
This is the same as '... doWhile:[... not]' " |
|
325 | 951 |
|
623 | 952 |
"this implementation is for purists ... :-)" |
953 |
||
954 |
self value. |
|
955 |
aBlock value ifTrue:[^ nil]. |
|
956 |
thisContext restart |
|
325 | 957 |
|
958 |
" |
|
623 | 959 |
|n| |
154 | 960 |
|
623 | 961 |
n := 1. |
962 |
[n printNewline] doUntil:[ (n := n + 1) > 5 ] |
|
154 | 963 |
" |
1 | 964 |
! |
965 |
||
623 | 966 |
doWhile:aBlock |
967 |
"repeat the receiver block until aBlock evaluates to false. |
|
968 |
The receiver is evaluated at least once." |
|
67 | 969 |
|
154 | 970 |
"this implementation is for purists ... :-)" |
971 |
||
623 | 972 |
self value. |
973 |
aBlock value ifFalse:[^ nil]. |
|
974 |
thisContext restart |
|
975 |
||
976 |
" |
|
977 |
|n| |
|
978 |
||
979 |
n := 1. |
|
980 |
[n printNewline] doWhile:[ (n := n + 1) <= 5 ] |
|
981 |
" |
|
982 |
! |
|
983 |
||
984 |
loop |
|
1211 | 985 |
"repeat the receiver forever |
986 |
(the receiver block should contain a return somewhere). |
|
987 |
The implementation below was inspired by a corresponding Self method." |
|
623 | 988 |
|
989 |
self value. |
|
67 | 990 |
thisContext restart |
991 |
||
992 |
" |
|
993 |
|n| |
|
994 |
||
995 |
n := 1. |
|
623 | 996 |
[ |
1211 | 997 |
n printNewline. |
998 |
n >= 10 ifTrue:[^ nil]. |
|
999 |
n := n + 1 |
|
623 | 1000 |
] loop |
1001 |
" |
|
1211 | 1002 |
|
1003 |
"Modified: 18.4.1996 / 13:50:40 / cg" |
|
623 | 1004 |
! |
1005 |
||
1006 |
loopWithExit |
|
1007 |
"the receiver must be a block of one argument. It is evaluated in a loop forever, |
|
1008 |
and is passed a block, which, if sent a value:-message, will exit the receiver block, |
|
1009 |
returning the parameter of the value:-message. Used for loops with exit in the middle. |
|
1010 |
Inspired by a corresponding Self method." |
|
1011 |
||
1012 |
|exitBlock| |
|
1013 |
||
1014 |
exitBlock := [:exitValue | ^ exitValue]. |
|
1015 |
[true] whileTrue:[self value:exitBlock] |
|
1016 |
||
1017 |
" |
|
1018 |
|i| |
|
1019 |
i := 1. |
|
1020 |
[:exit | |
|
1422 | 1021 |
Transcript showCR:i. |
623 | 1022 |
i == 5 ifTrue:[exit value:'thats it']. |
1023 |
i := i + 1 |
|
1024 |
] loopWithExit |
|
1025 |
" |
|
1026 |
! |
|
1027 |
||
1028 |
repeat |
|
1211 | 1029 |
"repeat the receiver forever - same as loop, for ST-80 compatibility. |
1030 |
(the receiver block should contain a return somewhere)." |
|
623 | 1031 |
|
1032 |
self value. |
|
1033 |
thisContext restart |
|
1211 | 1034 |
|
1035 |
"Modified: 18.4.1996 / 13:50:55 / cg" |
|
623 | 1036 |
! |
1037 |
||
1038 |
valueWithExit |
|
1039 |
"the receiver must be a block of one argument. It is evaluated, and is passed a block, |
|
1040 |
which, if sent a value:-message, will exit the receiver block, returning the parameter of the |
|
1041 |
value:-message. Used for premature returns to the caller. |
|
1042 |
Taken from a manchester goody (a similar construct also appears in Self)." |
|
1043 |
||
1211 | 1044 |
^ self value:[:exitValue | ^exitValue] |
623 | 1045 |
|
1046 |
" |
|
1047 |
[:exit | |
|
1211 | 1048 |
1 to:10 do:[:i | |
1422 | 1049 |
Transcript showCR:i. |
1211 | 1050 |
i == 5 ifTrue:[exit value:'thats it'] |
1051 |
]. |
|
1052 |
'regular block-value; never returned' |
|
623 | 1053 |
] valueWithExit |
1054 |
" |
|
1211 | 1055 |
|
1056 |
"Modified: 18.4.1996 / 13:51:38 / cg" |
|
623 | 1057 |
! |
1058 |
||
1059 |
whileFalse |
|
1060 |
"evaluate the receiver while it evaluates to false (ST80 compatibility)" |
|
1061 |
||
1062 |
"this implementation is for purists ... :-)" |
|
1063 |
||
1064 |
self value ifTrue:[^ nil]. |
|
1065 |
thisContext restart |
|
1066 |
||
1067 |
" |
|
1068 |
|n| |
|
1069 |
||
1070 |
n := 1. |
|
1071 |
[n printNewline. (n := n + 1) > 10] whileFalse |
|
67 | 1072 |
" |
1073 |
! |
|
1 | 1074 |
|
67 | 1075 |
whileFalse:aBlock |
1076 |
"evaluate the argument, aBlock while the receiver evaluates to false. |
|
1077 |
- usually open coded by compilers, but needed here for #perform |
|
1078 |
and expression evaluation." |
|
1079 |
||
154 | 1080 |
"this implementation is for purists ... :-)" |
1081 |
||
67 | 1082 |
self value ifTrue:[^ nil]. |
1083 |
aBlock value. |
|
1084 |
thisContext restart |
|
1085 |
||
1086 |
" |
|
1087 |
|n| |
|
1088 |
||
1089 |
n := 1. |
|
1090 |
[n > 10] whileFalse:[ |
|
154 | 1091 |
n printNewline. |
1092 |
n := n + 1 |
|
67 | 1093 |
] |
1094 |
" |
|
1 | 1095 |
! |
1096 |
||
1097 |
whileTrue |
|
67 | 1098 |
"evaluate the receiver while it evaluates to true (ST80 compatibility)" |
1 | 1099 |
|
154 | 1100 |
"this implementation is for purists ... :-)" |
1101 |
||
67 | 1102 |
self value ifFalse:[^ nil]. |
1103 |
thisContext restart |
|
1 | 1104 |
|
67 | 1105 |
" |
1106 |
|n| |
|
1 | 1107 |
|
67 | 1108 |
n := 1. |
1109 |
[n printNewline. (n := n + 1) <= 10] whileTrue |
|
1110 |
" |
|
1 | 1111 |
! |
1112 |
||
623 | 1113 |
whileTrue:aBlock |
1114 |
"evaluate the argument, aBlock while the receiver evaluates to true. |
|
1115 |
- usually open coded by compilers, but needed here for #perform |
|
1116 |
and expression evaluation." |
|
1 | 1117 |
|
154 | 1118 |
"this implementation is for purists ... :-)" |
1119 |
||
623 | 1120 |
self value ifFalse:[^ nil]. |
1121 |
aBlock value. |
|
67 | 1122 |
thisContext restart |
1123 |
||
1124 |
" |
|
1125 |
|n| |
|
1 | 1126 |
|
67 | 1127 |
n := 1. |
623 | 1128 |
[n <= 10] whileTrue:[ |
154 | 1129 |
n printNewline. |
1130 |
n := n + 1 |
|
623 | 1131 |
] |
68 | 1132 |
" |
67 | 1133 |
! ! |
1134 |
||
92 | 1135 |
!Block methodsFor:'printing & storing'! |
1 | 1136 |
|
1137 |
printOn:aStream |
|
44 | 1138 |
"append a a printed representation of the block to aStream" |
1139 |
||
213 | 1140 |
|homeClass h sel methodClass| |
54 | 1141 |
|
1142 |
"cheap blocks have no home context, but a method instead" |
|
1143 |
||
1144 |
(home isNil or:[home isContext not]) ifTrue:[ |
|
154 | 1145 |
aStream nextPutAll:'[] in '. |
1 | 1146 |
|
154 | 1147 |
" |
1148 |
currently, some cheap blocks don't know where they have been created |
|
1149 |
" |
|
1150 |
aStream nextPutAll:' ??? (optimized)'. |
|
1151 |
^ self |
|
54 | 1152 |
]. |
1153 |
||
1154 |
"a full blown block (with home, but without method)" |
|
1155 |
||
1156 |
aStream nextPutAll:'[] in '. |
|
154 | 1157 |
h := self methodHome. |
1158 |
sel := h selector. |
|
1159 |
"/ old: |
|
1160 |
"/ home receiver class name printOn:aStream. |
|
1161 |
"/ new: |
|
212 | 1162 |
"/ (h searchClass whichClassImplements:sel) name printOn:aStream. |
213 | 1163 |
methodClass := h methodClass. |
1164 |
methodClass isNil ifTrue:[ |
|
1165 |
'UnboundMethod' printOn:aStream. |
|
1166 |
] ifFalse:[ |
|
1167 |
methodClass name printOn:aStream. |
|
1168 |
]. |
|
54 | 1169 |
aStream nextPut:$-. |
154 | 1170 |
sel printOn:aStream. |
54 | 1171 |
|
1172 |
" |
|
1 | 1173 |
aStream nextPutAll:'[] in '. |
1174 |
homeClass := home containingClass. |
|
1175 |
homeClass notNil ifTrue:[ |
|
154 | 1176 |
homeClass name printOn:aStream. |
1177 |
aStream space. |
|
1178 |
(homeClass selectorForMethod:home) printOn:aStream |
|
1 | 1179 |
] ifFalse:[ |
154 | 1180 |
aStream nextPutAll:' ???' |
1 | 1181 |
] |
54 | 1182 |
" |
1 | 1183 |
! ! |
623 | 1184 |
|
1185 |
!Block methodsFor:'private accessing'! |
|
1186 |
||
1187 |
code:codeAddress byteCode:bCode numArgs:numArgs sourcePosition:srcPos initialPC:iPC literals:lits dynamic:dynamic |
|
1265 | 1188 |
"set all relevant internals. |
1189 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 1190 |
|
1191 |
self code:codeAddress. |
|
1192 |
byteCode := bCode. |
|
1193 |
nargs := numArgs. |
|
1194 |
sourcePos := srcPos. |
|
1195 |
initialPC := iPC. |
|
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1196 |
self literals:lits. |
623 | 1197 |
self dynamic:dynamic |
1265 | 1198 |
|
1199 |
"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
|
1200 |
"Modified: 24.6.1996 / 12:37:37 / stefan" |
623 | 1201 |
! |
1202 |
||
1203 |
initialPC:initial |
|
1265 | 1204 |
"set the initial pc for evaluation. |
1205 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 1206 |
|
1207 |
initialPC := initial |
|
1265 | 1208 |
|
1209 |
"Modified: 23.4.1996 / 16:05:39 / cg" |
|
623 | 1210 |
! |
1211 |
||
1212 |
numArgs:numArgs |
|
1265 | 1213 |
"set the number of arguments the receiver expects for evaluation. |
1214 |
DANGER ALERT: this interface is for the compiler only." |
|
623 | 1215 |
|
1216 |
nargs := numArgs |
|
1265 | 1217 |
|
1218 |
"Modified: 23.4.1996 / 16:05:52 / cg" |
|
623 | 1219 |
! |
1220 |
||
1221 |
sourcePosition:position |
|
1265 | 1222 |
"set the position of the source within my method. |
1223 |
This interface is for the compiler only." |
|
623 | 1224 |
|
1225 |
sourcePos := position |
|
1265 | 1226 |
|
1227 |
"Modified: 23.4.1996 / 16:06:19 / cg" |
|
623 | 1228 |
! ! |
1229 |
||
1230 |
!Block methodsFor:'privileged evaluation'! |
|
1231 |
||
1232 |
valueUninterruptably |
|
1233 |
"evaluate the receiver with interrupts blocked. |
|
1234 |
This does not prevent preemption by a higher priority processes |
|
1235 |
if any becomes runnable due to the evaluation of the receiver |
|
1236 |
(i.e. if a semaphore is signalled)." |
|
1237 |
||
864 | 1238 |
|wasBlocked| |
1239 |
||
1240 |
wasBlocked := OperatingSystem blockInterrupts. |
|
1041
12e2524284e2
oops - unterrupts remained blocked sometimes
Claus Gittinger <cg@exept.de>
parents:
1037
diff
changeset
|
1241 |
^ self valueNowOrOnUnwindDo:[wasBlocked ifFalse:[OperatingSystem unblockInterrupts]]. |
623 | 1242 |
! |
1243 |
||
1244 |
valueUnpreemptively |
|
1245 |
"evaluate the receiver without the possiblity of preemption |
|
1246 |
(i.e. at a very high priority)" |
|
1247 |
||
1248 |
|oldPrio activeProcess| |
|
1249 |
||
1250 |
activeProcess := Processor activeProcess. |
|
1251 |
oldPrio := activeProcess changePriority:(Processor highestPriority). |
|
864 | 1252 |
^ self valueNowOrOnUnwindDo:[ |
623 | 1253 |
activeProcess priority:oldPrio |
1254 |
] |
|
1255 |
! ! |
|
1256 |
||
1257 |
!Block methodsFor:'process creation'! |
|
1258 |
||
1259 |
fork |
|
1260 |
"create a new process executing the receiver at the current priority." |
|
1261 |
||
1262 |
^ self newProcess resume |
|
1263 |
! |
|
1264 |
||
1265 |
forkAt:priority |
|
1266 |
"create a new process executing the receiver at a different priority." |
|
1267 |
||
1268 |
^ (self newProcess priority:priority) resume |
|
1269 |
! |
|
1270 |
||
1271 |
forkWith:argArray |
|
1272 |
"create a new process executing the receiver, |
|
1273 |
passing elements in argArray as arguments to the receiver block." |
|
1274 |
||
1275 |
^ [self valueWithArguments:argArray] fork. |
|
1276 |
! |
|
1277 |
||
1278 |
newProcess |
|
1279 |
"create a new (unscheduled) process executing the receiver" |
|
1280 |
||
1281 |
^ Process for:self priority:(Processor activePriority) |
|
1282 |
! |
|
1283 |
||
1284 |
newProcessWithArguments:argArray |
|
1285 |
"create a new (unscheduled) process executing the receiver, |
|
1286 |
passing the elements in argArray as arguments to the receiver block." |
|
1287 |
||
1288 |
^ [self valueWithArguments:argArray] newProcess |
|
1289 |
! |
|
1290 |
||
1291 |
promise |
|
1292 |
"create a promise on the receiver. The promise will evaluate the |
|
1293 |
receiver and promise to return the value with the #value message. |
|
1294 |
The evaluation will be performed as a separate process. |
|
1295 |
Asking the promise for its value will either block the asking process |
|
1296 |
(if the evaluation has not yet been finished) or return the value |
|
1297 |
immediately." |
|
1298 |
||
1299 |
^ Promise value:self |
|
1300 |
||
1301 |
" |
|
1302 |
|p| |
|
1303 |
||
1304 |
p := [1000 factorial] promise. |
|
1305 |
'do something else ...'. |
|
1306 |
p value |
|
1307 |
" |
|
1308 |
! |
|
1309 |
||
1310 |
promiseAt:prio |
|
1311 |
"create a promise on the receiver. The promise will evaluate the |
|
1312 |
receiver and promise to return the value with the #value message. |
|
1313 |
The evaluation will be performed as a separate process running at prio. |
|
1314 |
Asking the promise for its value will either block the asking process |
|
1315 |
(if the evaluation has not yet been finished) or return the value |
|
1316 |
immediately." |
|
1317 |
||
1318 |
^ Promise value:self priority:prio |
|
1319 |
! ! |
|
1320 |
||
1321 |
!Block methodsFor:'testing'! |
|
1322 |
||
1323 |
isBlock |
|
1324 |
"return true, if this is a block - yes I am" |
|
1325 |
||
1326 |
^ true |
|
1327 |
! ! |
|
1328 |
||
1329 |
!Block methodsFor:'unwinding'! |
|
1330 |
||
1331 |
valueNowOrOnUnwindDo:aBlock |
|
1332 |
"evaluate the receiver - after that, or when some method sent within unwinds (i.e. does |
|
1333 |
a long return), evaluate the argument, aBlock. |
|
1334 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
1335 |
executed regardless of error actions" |
|
1336 |
||
1337 |
|v| |
|
1338 |
||
1339 |
thisContext markForUnwind. |
|
1340 |
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
|
1341 |
thisContext unmarkForUnwind. |
623 | 1342 |
aBlock value. |
1343 |
^ v |
|
1344 |
||
1345 |
" |
|
1346 |
in the following example, f will be closed even if the block |
|
1347 |
returns with 'oops'. There are many more applications of this kind |
|
1348 |
found in the system. |
|
1349 |
" |
|
1350 |
" |
|
1351 |
|f| |
|
1352 |
||
1353 |
f := 'Makefile' asFilename readStream. |
|
1354 |
[ |
|
1187
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
1355 |
l := f nextLine. |
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
1356 |
l isNil ifTrue:[^ 'oops'] |
623 | 1357 |
] valueNowOrOnUnwindDo:[ |
1187
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
1358 |
f close |
623 | 1359 |
] |
1360 |
" |
|
1187
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
1361 |
|
619ff79bc665
valueNowOrOnUnwindDo: don't execute unwind block when block is currently executed 'now'.
Stefan Vogel <sv@exept.de>
parents:
1181
diff
changeset
|
1362 |
"Modified: 16.4.1996 / 11:05:26 / stefan" |
623 | 1363 |
! |
1364 |
||
1365 |
valueOnUnwindDo:aBlock |
|
1366 |
"evaluate the receiver - when some method sent within unwinds (i.e. does |
|
1367 |
a long return), evaluate the argument, aBlock. |
|
1368 |
This is used to make certain that cleanup actions (for example closing files etc.) are |
|
1369 |
executed regardless of error actions" |
|
1370 |
||
1371 |
thisContext markForUnwind. |
|
1372 |
^ self value "the real logic is in Context>>unwind" |
|
1373 |
! ! |
|
1374 |
||
1493
33e226c7d187
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
1422
diff
changeset
|
1375 |
!Block class methodsFor:'documentation'! |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1376 |
|
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1377 |
version |
1672
1b56d6e95c9e
changes to call dynamic compiled code right after compilation.
Claus Gittinger <cg@exept.de>
parents:
1626
diff
changeset
|
1378 |
^ '$Header: /cvs/stx/stx/libbasic/Block.st,v 1.61 1996-09-22 13:01:02 cg Exp $' |
1181
6637fee79d7b
only Block & CheapBlock are fixed - subclasses may look different
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1379 |
! ! |
623 | 1380 |
Block initialize! |