Block.st
changeset 18252 1c69f8f3574c
parent 17697 c88f1b712134
child 18261 22bdfc405bca
child 18316 0f25aa39967c
equal deleted inserted replaced
18251:9b7f8e531a16 18252:1c69f8f3574c
    63     (i.e. Blocks are closures in Smalltalk/X)
    63     (i.e. Blocks are closures in Smalltalk/X)
    64 
    64 
    65     A return (via ^-statement) out of a block will force a return from the
    65     A return (via ^-statement) out of a block will force a return from the
    66     blocks method context (if it is still living) - this make the implementation
    66     blocks method context (if it is still living) - this make the implementation
    67     of long-jumps and control structures possible.
    67     of long-jumps and control structures possible.
    68     (If the method is not alive (i.e. has already returned), a return out of the 
    68     (If the method is not alive (i.e. has already returned), a return out of the
    69      block will trigger an error)
    69      block will trigger an error)
    70 
    70 
    71     Long-jump is done by defining a catchBlock as ''[^ self]''
    71     Long-jump is done by defining a catchBlock as ''[^ self]''
    72     somewhere up in the calling-tree. Then, to do the long-jump from out of some 
    72     somewhere up in the calling-tree. Then, to do the long-jump from out of some
    73     deeply nested method, simply do: ''catchBlock value''.
    73     deeply nested method, simply do: ''catchBlock value''.
    74 
    74 
    75     [Instance variables:]
    75     [Instance variables:]
    76 
    76 
    77       home        <Context>         the context where this block was created (i.e. defined)
    77       home        <Context>         the context where this block was created (i.e. defined)
   103 !
   103 !
   104 
   104 
   105 examples
   105 examples
   106 "
   106 "
   107     define a block and evaluate it:
   107     define a block and evaluate it:
   108                                                                         [exBegin]
   108 									[exBegin]
   109         |b|
   109 	|b|
   110 
   110 
   111         b := [ Transcript showCR:'hello' ].
   111 	b := [ Transcript showCR:'hello' ].
   112 
   112 
   113         Transcript showCR:'now evaluating the block ...'.
   113 	Transcript showCR:'now evaluating the block ...'.
   114         b value.
   114 	b value.
   115                                                                         [exEnd]
   115 									[exEnd]
   116 
   116 
   117 
   117 
   118 
   118 
   119     even here, blocks are involved: 
   119     even here, blocks are involved:
   120     (although, the compiler optimizes things if possible)
   120     (although, the compiler optimizes things if possible)
   121                                                                         [exBegin]
   121 									[exBegin]
   122         Transcript showCR:'now evaluating one of two blocks ...'.
   122 	Transcript showCR:'now evaluating one of two blocks ...'.
   123         1 > 4 ifTrue:[
   123 	1 > 4 ifTrue:[
   124             Transcript showCR:'foo'
   124 	    Transcript showCR:'foo'
   125         ] ifFalse:[
   125 	] ifFalse:[
   126             Transcript showCR:'bar'
   126 	    Transcript showCR:'bar'
   127         ]
   127 	]
   128                                                                         [exEnd]
   128 									[exEnd]
   129 
   129 
   130 
   130 
   131 
   131 
   132     here things become obvious:
   132     here things become obvious:
   133                                                                         [exBegin]
   133 									[exBegin]
   134         |yesBlock noBlock|
   134 	|yesBlock noBlock|
   135 
   135 
   136         yesBlock := [ Transcript showCR:'foo' ].
   136 	yesBlock := [ Transcript showCR:'foo' ].
   137         noBlock := [ Transcript showCR:'bar' ].
   137 	noBlock := [ Transcript showCR:'bar' ].
   138 
   138 
   139         Transcript showCR:'now evaluating one of two blocks ...'.
   139 	Transcript showCR:'now evaluating one of two blocks ...'.
   140         1 > 4 ifTrue:yesBlock
   140 	1 > 4 ifTrue:yesBlock
   141               ifFalse:noBlock
   141 	      ifFalse:noBlock
   142                                                                         [exEnd]
   142 									[exEnd]
   143 
   143 
   144 
   144 
   145 
   145 
   146     simple loops:
   146     simple loops:
   147       not very objectOriented:
   147       not very objectOriented:
   148                                                                         [exBegin]
   148 									[exBegin]
   149         |i|
   149 	|i|
   150 
   150 
   151         i := 1.
   151 	i := 1.
   152         [i < 10] whileTrue:[
   152 	[i < 10] whileTrue:[
   153             Transcript showCR:i.
   153 	    Transcript showCR:i.
   154             i := i + 1
   154 	    i := i + 1
   155         ]
   155 	]
   156                                                                         [exEnd]
   156 									[exEnd]
   157 
   157 
   158 
   158 
   159       using integer protocol:
   159       using integer protocol:
   160                                                                         [exBegin]
   160 									[exBegin]
   161         1 to:10 do:[:i |
   161 	1 to:10 do:[:i |
   162             Transcript showCR:i.
   162 	    Transcript showCR:i.
   163         ]
   163 	]
   164                                                                         [exEnd]
   164 									[exEnd]
   165 
   165 
   166 
   166 
   167       interval protocol:
   167       interval protocol:
   168                                                                         [exBegin]
   168 									[exBegin]
   169         (1 to:10) do:[:i |
   169 	(1 to:10) do:[:i |
   170             Transcript showCR:i.
   170 	    Transcript showCR:i.
   171         ]
   171 	]
   172                                                                         [exEnd]
   172 									[exEnd]
   173 
   173 
   174 
   174 
   175 
   175 
   176     looping over collections:
   176     looping over collections:
   177 
   177 
   178       bad code:
   178       bad code:
   179       (only works with numeric-indexable collections)
   179       (only works with numeric-indexable collections)
   180                                                                         [exBegin]
   180 									[exBegin]
   181         |i coll|
   181 	|i coll|
   182 
   182 
   183         coll := #(9 8 7 6 5).
   183 	coll := #(9 8 7 6 5).
   184         i := 1.
   184 	i := 1.
   185         [i <= coll size] whileTrue:[
   185 	[i <= coll size] whileTrue:[
   186             Transcript showCR:(coll at:i).
   186 	    Transcript showCR:(coll at:i).
   187             i := i + 1.
   187 	    i := i + 1.
   188         ]
   188 	]
   189                                                                         [exEnd]
   189 									[exEnd]
   190 
   190 
   191 
   191 
   192 
   192 
   193       just as bad (well, marginally better ;-):
   193       just as bad (well, marginally better ;-):
   194       (only works with numeric-indexable collections)
   194       (only works with numeric-indexable collections)
   195                                                                         [exBegin]
   195 									[exBegin]
   196         |coll|   
   196 	|coll|
   197 
   197 
   198         coll := #(9 8 7 6 5).
   198 	coll := #(9 8 7 6 5).
   199         1 to:coll size do:[:i |
   199 	1 to:coll size do:[:i |
   200             Transcript showCR:(coll at:i).
   200 	    Transcript showCR:(coll at:i).
   201         ]
   201 	]
   202                                                                         [exEnd]
   202 									[exEnd]
   203 
   203 
   204 
   204 
   205 
   205 
   206       the smalltalk way:
   206       the smalltalk way:
   207       (works with any collection)
   207       (works with any collection)
   208                                                                         [exBegin]
   208 									[exBegin]
   209         |coll|   
   209 	|coll|
   210 
   210 
   211         coll := #(9 8 7 6 5).
   211 	coll := #(9 8 7 6 5).
   212         coll do:[:element |
   212 	coll do:[:element |
   213             Transcript showCR:element.
   213 	    Transcript showCR:element.
   214         ]
   214 	]
   215                                                                         [exEnd]
   215 									[exEnd]
   216         
   216 
   217     Rule: use enumeration protocol of the collection instead of
   217     Rule: use enumeration protocol of the collection instead of
   218           manually indexing it. [with few exceptions]
   218 	  manually indexing it. [with few exceptions]
   219 
   219 
   220 
   220 
   221 
   221 
   222     processes:
   222     processes:
   223 
   223 
   224       forking a lightweight process (thread):
   224       forking a lightweight process (thread):
   225                                                                         [exBegin]
   225 									[exBegin]
   226         [
   226 	[
   227             Transcript showCR:'waiting ...'.
   227 	    Transcript showCR:'waiting ...'.
   228             Delay waitForSeconds:2.
   228 	    Delay waitForSeconds:2.
   229             Transcript showCR:'here I am'.
   229 	    Transcript showCR:'here I am'.
   230         ] fork
   230 	] fork
   231                                                                         [exEnd]
   231 									[exEnd]
   232 
   232 
   233 
   233 
   234         
   234 
   235       some with low prio:
   235       some with low prio:
   236                                                                         [exBegin]
   236 									[exBegin]
   237         [
   237 	[
   238             Transcript showCR:'computing ...'.
   238 	    Transcript showCR:'computing ...'.
   239             10000 factorial.
   239 	    10000 factorial.
   240             Transcript showCR:'here I am'.
   240 	    Transcript showCR:'here I am'.
   241         ] forkAt:(Processor userBackgroundPriority)
   241 	] forkAt:(Processor userBackgroundPriority)
   242                                                                         [exEnd]
   242 									[exEnd]
   243 
   243 
   244 
   244 
   245 
   245 
   246     handling exceptions:
   246     handling exceptions:
   247                                                                         [exBegin]
   247 									[exBegin]
   248         Error handle:[:ex |
   248 	Error handle:[:ex |
   249             Transcript showCR:'exception handler forces return'.
   249 	    Transcript showCR:'exception handler forces return'.
   250             ex return
   250 	    ex return
   251         ] do:[
   251 	] do:[
   252             Transcript showCR:'now, doing something bad ...'.
   252 	    Transcript showCR:'now, doing something bad ...'.
   253             1 / 0.
   253 	    1 / 0.
   254             Transcript showCR:'not reached'
   254 	    Transcript showCR:'not reached'
   255         ]
   255 	]
   256                                                                         [exEnd]
   256 									[exEnd]
   257 
   257 
   258 
   258 
   259 
   259 
   260     performing cleanup actions:
   260     performing cleanup actions:
   261                                                                         [exBegin]
   261 									[exBegin]
   262         Error handle:[:ex |
   262 	Error handle:[:ex |
   263             Transcript showCR:'exception handler forces return'.
   263 	    Transcript showCR:'exception handler forces return'.
   264             ex return
   264 	    ex return
   265         ] do:[
   265 	] do:[
   266             [
   266 	    [
   267                 Transcript showCR:'doing something bad ...'.
   267 		Transcript showCR:'doing something bad ...'.
   268                 1 / 0.
   268 		1 / 0.
   269                 Transcript showCR:'not reached'
   269 		Transcript showCR:'not reached'
   270             ] ifCurtailed:[
   270 	    ] ifCurtailed:[
   271                 Transcript showCR:'cleanup'
   271 		Transcript showCR:'cleanup'
   272             ]
   272 	    ]
   273         ]
   273 	]
   274                                                                         [exEnd]
   274 									[exEnd]
   275 
   275 
   276 
   276 
   277     delayed execution (visitor pattern):
   277     delayed execution (visitor pattern):
   278     (looking carefully into the example, 
   278     (looking carefully into the example,
   279      C/C++ programmers may raise their eyes ;-)
   279      C/C++ programmers may raise their eyes ;-)
   280                                                                         [exBegin]
   280 									[exBegin]
   281         |showBlock countBlock 
   281 	|showBlock countBlock
   282          howMany 
   282 	 howMany
   283          top panel b1 b2|
   283 	 top panel b1 b2|
   284 
   284 
   285         howMany := 0.
   285 	howMany := 0.
   286 
   286 
   287         showBlock := [ Transcript showCR:howMany ].
   287 	showBlock := [ Transcript showCR:howMany ].
   288         countBlock := [ howMany := howMany + 1 ].
   288 	countBlock := [ howMany := howMany + 1 ].
   289 
   289 
   290         top := StandardSystemView extent:200@200.
   290 	top := StandardSystemView extent:200@200.
   291         panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
   291 	panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
   292 
   292 
   293         b1 := Button label:'count up' in:panel.
   293 	b1 := Button label:'count up' in:panel.
   294         b1 action:countBlock.
   294 	b1 action:countBlock.
   295 
   295 
   296         b2 := Button label:'show value' in:panel.
   296 	b2 := Button label:'show value' in:panel.
   297         b2 action:showBlock.
   297 	b2 action:showBlock.
   298 
   298 
   299         top open.
   299 	top open.
   300 
   300 
   301         Transcript showCR:'new process started;'.
   301 	Transcript showCR:'new process started;'.
   302         Transcript showCR:'notice: the blocks can still access the'.
   302 	Transcript showCR:'notice: the blocks can still access the'.
   303         Transcript showCR:'        howMany local variable.'.
   303 	Transcript showCR:'        howMany local variable.'.
   304                                                                         [exEnd]
   304 									[exEnd]
   305 "
   305 "
   306 ! !
   306 ! !
   307 
   307 
   308 !Block class methodsFor:'initialization'!
   308 !Block class methodsFor:'initialization'!
   309 
   309 
   310 initialize
   310 initialize
   311     "create signals raised by various errors"
   311     "create signals raised by various errors"
   312 
   312 
   313     InvalidNewSignal isNil ifTrue:[
   313     InvalidNewSignal isNil ifTrue:[
   314         InvalidNewSignal := Error newSignalMayProceed:false.
   314 	InvalidNewSignal := Error newSignalMayProceed:false.
   315         InvalidNewSignal nameClass:self message:#invalidNewSignal.
   315 	InvalidNewSignal nameClass:self message:#invalidNewSignal.
   316         InvalidNewSignal notifierString:'blocks are only created by the system'.
   316 	InvalidNewSignal notifierString:'blocks are only created by the system'.
   317     ]
   317     ]
   318 
   318 
   319     "Modified: 22.4.1996 / 16:34:20 / cg"
   319     "Modified: 22.4.1996 / 16:34:20 / cg"
   320 ! !
   320 ! !
   321 
   321 
   333     "create a new cheap (homeless) block.
   333     "create a new cheap (homeless) block.
   334      Not for public use - this is a special hook for the compiler."
   334      Not for public use - this is a special hook for the compiler."
   335 
   335 
   336     |newBlock|
   336     |newBlock|
   337 
   337 
   338     newBlock := (super basicNew:(literals size)) 
   338     newBlock := (super basicNew:(literals size))
   339 			   byteCode:bCode
   339 			   byteCode:bCode
   340 			   numArgs:numArgs
   340 			   numArgs:numArgs
   341 			   numVars:numVars
   341 			   numVars:numVars
   342 			   numStack:nStack
   342 			   numStack:nStack
   343 		     sourcePosition:sourcePos
   343 		     sourcePosition:sourcePos
   406     "/ (actually, the previous implementation was:
   406     "/ (actually, the previous implementation was:
   407     "/ ^ self valueNowOrOnUnwindDo:aBlock
   407     "/ ^ self valueNowOrOnUnwindDo:aBlock
   408 
   408 
   409     "
   409     "
   410      [
   410      [
   411         [
   411 	[
   412             Transcript showCR:'one'.
   412 	    Transcript showCR:'one'.
   413             Processor activeProcess terminate.
   413 	    Processor activeProcess terminate.
   414             Transcript showCR:'two'.
   414 	    Transcript showCR:'two'.
   415         ] ensure:[
   415 	] ensure:[
   416             Transcript showCR:'three'.
   416 	    Transcript showCR:'three'.
   417         ].
   417 	].
   418      ] fork.
   418      ] fork.
   419     "
   419     "
   420 
   420 
   421     "
   421     "
   422      [
   422      [
   423         [
   423 	[
   424             Transcript showCR:'one'.
   424 	    Transcript showCR:'one'.
   425             Transcript showCR:'two'.
   425 	    Transcript showCR:'two'.
   426         ] ensure:[
   426 	] ensure:[
   427             Transcript showCR:'three'.
   427 	    Transcript showCR:'three'.
   428         ].
   428 	].
   429      ] fork.
   429      ] fork.
   430     "
   430     "
   431 !
   431 !
   432 
   432 
   433 ifCurtailed:aBlock
   433 ifCurtailed:aBlock
   450     "
   450     "
   451      |s|
   451      |s|
   452 
   452 
   453      s := 'Makefile' asFilename readStream.
   453      s := 'Makefile' asFilename readStream.
   454      [
   454      [
   455         ^ self
   455 	^ self
   456      ] ifCurtailed:[
   456      ] ifCurtailed:[
   457         Transcript showCR:'closing the stream - even though a return occurred'.
   457 	Transcript showCR:'closing the stream - even though a return occurred'.
   458         s close
   458 	s close
   459      ]
   459      ]
   460     "
   460     "
   461     "
   461     "
   462      [
   462      [
   463          |s|
   463 	 |s|
   464 
   464 
   465          s := 'Makefile' asFilename readStream.
   465 	 s := 'Makefile' asFilename readStream.
   466          [
   466 	 [
   467             Processor activeProcess terminate
   467 	    Processor activeProcess terminate
   468          ] ifCurtailed:[
   468 	 ] ifCurtailed:[
   469             Transcript showCR:'closing the stream - even though process was terminated'.
   469 	    Transcript showCR:'closing the stream - even though process was terminated'.
   470             s close
   470 	    s close
   471          ]
   471 	 ]
   472      ] fork
   472      ] fork
   473     "
   473     "
   474 ! !
   474 ! !
   475 
   475 
   476 !Block methodsFor:'Compatibility-Dolphin'!
   476 !Block methodsFor:'Compatibility-Dolphin'!
   486 
   486 
   487 deferredValueAt:priority
   487 deferredValueAt:priority
   488     "Dolphin compatibility method - do not use in new code.
   488     "Dolphin compatibility method - do not use in new code.
   489      Dolphin's alias for futureValue"
   489      Dolphin's alias for futureValue"
   490 
   490 
   491     ^ Future new 
   491     ^ Future new
   492         priority:priority block:self
   492 	priority:priority block:self
   493 
   493 
   494     "Created: / 04-10-2011 / 14:55:56 / cg"
   494     "Created: / 04-10-2011 / 14:55:56 / cg"
   495 ! !
   495 ! !
   496 
   496 
   497 !Block methodsFor:'Compatibility-Squeak'!
   497 !Block methodsFor:'Compatibility-Squeak'!
   498 
   498 
   499 cull: optionalFirstArg 
   499 cull: optionalFirstArg
   500     "activate the receiver with one or zero arguments.
   500     "activate the receiver with one or zero arguments.
   501      Squeak compatibility, but also present in VW Smalltalk"
   501      Squeak compatibility, but also present in VW Smalltalk"
   502 
   502 
   503     nargs >= 1 ifTrue:[^ self value:optionalFirstArg].
   503     nargs >= 1 ifTrue:[^ self value:optionalFirstArg].
   504     ^ self value
   504     ^ self value
   516 cull: optionalFirstArg cull: optionalSecondArg cull: optionalThirdArg
   516 cull: optionalFirstArg cull: optionalSecondArg cull: optionalThirdArg
   517     "activate the receiver with three or less arguments.
   517     "activate the receiver with three or less arguments.
   518      Squeak compatibility, but also present in VW Smalltalk"
   518      Squeak compatibility, but also present in VW Smalltalk"
   519 
   519 
   520     nargs >= 2 ifTrue:[
   520     nargs >= 2 ifTrue:[
   521         nargs >= 3 ifTrue:[
   521 	nargs >= 3 ifTrue:[
   522             ^ self value:optionalFirstArg value:optionalSecondArg value:optionalThirdArg
   522 	    ^ self value:optionalFirstArg value:optionalSecondArg value:optionalThirdArg
   523         ].
   523 	].
   524         ^ self value:optionalFirstArg value:optionalSecondArg
   524 	^ self value:optionalFirstArg value:optionalSecondArg
   525     ].
   525     ].
   526     nargs = 1 ifTrue:[^ self value:optionalFirstArg].
   526     nargs = 1 ifTrue:[^ self value:optionalFirstArg].
   527     ^ self value
   527     ^ self value
   528 !
   528 !
   529 
   529 
   537 
   537 
   538     |numArgs|
   538     |numArgs|
   539 
   539 
   540     numArgs := handlerBlock isBlock ifTrue:[handlerBlock numArgs] ifFalse:[0].
   540     numArgs := handlerBlock isBlock ifTrue:[handlerBlock numArgs] ifFalse:[0].
   541     numArgs == 1 ifTrue:[
   541     numArgs == 1 ifTrue:[
   542         ^ self on:Error do:handlerBlock
   542 	^ self on:Error do:handlerBlock
   543     ].
   543     ].
   544 
   544 
   545     ^ self 
   545     ^ self
   546         on:Error 
   546 	on:Error
   547         do:[:ex | 
   547 	do:[:ex |
   548             |errString errReceiver|
   548 	    |errString errReceiver|
   549 
   549 
   550             numArgs == 0 ifTrue:[
   550 	    numArgs == 0 ifTrue:[
   551                 ex return:handlerBlock value
   551 		ex return:handlerBlock value
   552             ] ifFalse:[
   552 	    ] ifFalse:[
   553                 errString := ex description.
   553 		errString := ex description.
   554                 errReceiver := ex suspendedContext receiver.
   554 		errReceiver := ex suspendedContext receiver.
   555                 ex return:(handlerBlock value:errString value:errReceiver)
   555 		ex return:(handlerBlock value:errString value:errReceiver)
   556             ].
   556 	    ].
   557         ]
   557 	]
   558 
   558 
   559     "
   559     "
   560      |a|
   560      |a|
   561 
   561 
   562      a := 0.
   562      a := 0.
   592 
   592 
   593 !Block methodsFor:'Compatibility-V''Age'!
   593 !Block methodsFor:'Compatibility-V''Age'!
   594 
   594 
   595 apply:aCollection from:start to:end
   595 apply:aCollection from:start to:end
   596     "VisualAge compatibility:
   596     "VisualAge compatibility:
   597      Evaluate the receiver for each variable slot of aCollection from start to end. 
   597      Evaluate the receiver for each variable slot of aCollection from start to end.
   598      Answer aCollection."
   598      Answer aCollection."
   599 
   599 
   600     aCollection from:start to:end do:self.
   600     aCollection from:start to:end do:self.
   601     ^ aCollection
   601     ^ aCollection
   602 
   602 
   603     "
   603     "
   604      [:i | Transcript showCR:i ]
   604      [:i | Transcript showCR:i ]
   605         apply:#(10 20 30 40 50 60) from:2 to:4
   605 	apply:#(10 20 30 40 50 60) from:2 to:4
   606     "
   606     "
   607 
   607 
   608     "Created: / 16-05-2012 / 11:20:55 / cg"
   608     "Created: / 16-05-2012 / 11:20:55 / cg"
   609 !
   609 !
   610 
   610 
   611 applyWithIndex:aCollection from:start to:end
   611 applyWithIndex:aCollection from:start to:end
   612     "VisualAge compatibility:
   612     "VisualAge compatibility:
   613      Evaluate the receiver for each variable slot and index of aCollection from start to end. 
   613      Evaluate the receiver for each variable slot and index of aCollection from start to end.
   614      Answer aCollection."
   614      Answer aCollection."
   615 
   615 
   616     aCollection from:start to:end doWithIndex:self.
   616     aCollection from:start to:end doWithIndex:self.
   617     ^ aCollection
   617     ^ aCollection
   618 
   618 
   619     "
   619     "
   620      [:el :i | Transcript showCR:(i -> el) ]
   620      [:el :i | Transcript showCR:(i -> el) ]
   621         applyWithIndex:#(10 20 30 40 50 60) from:2 to:4
   621 	applyWithIndex:#(10 20 30 40 50 60) from:2 to:4
   622     "
   622     "
   623 
   623 
   624     "Created: / 16-05-2012 / 11:22:01 / cg"
   624     "Created: / 16-05-2012 / 11:22:01 / cg"
   625 !
   625 !
   626 
   626 
   627 value:arg1 onReturnDo:aBlock
   627 value:arg1 onReturnDo:aBlock
   628     "VisualAge compatibility: alias for #ensure:
   628     "VisualAge compatibility: alias for #ensure:
   629      evaluate the receiver - when the block returns either a local return
   629      evaluate the receiver - when the block returns either a local return
   630      or an unwind (i.e. does a long return), evaluate the argument, aBlock.
   630      or an unwind (i.e. does a long return), evaluate the argument, aBlock.
   631      This is used to make certain that cleanup actions 
   631      This is used to make certain that cleanup actions
   632      (for example closing files etc.) are executed regardless of error actions."
   632      (for example closing files etc.) are executed regardless of error actions."
   633 
   633 
   634     ^ [self value:arg1] ensure:aBlock
   634     ^ [self value:arg1] ensure:aBlock
   635 
   635 
   636     "Created: / 16-05-2012 / 11:29:30 / cg"
   636     "Created: / 16-05-2012 / 11:29:30 / cg"
   638 
   638 
   639 value:arg1 value:arg2 onReturnDo:aBlock
   639 value:arg1 value:arg2 onReturnDo:aBlock
   640     "VisualAge compatibility: alias for #ensure:
   640     "VisualAge compatibility: alias for #ensure:
   641      evaluate the receiver - when the block returns either a local return
   641      evaluate the receiver - when the block returns either a local return
   642      or an unwind (i.e. does a long return), evaluate the argument, aBlock.
   642      or an unwind (i.e. does a long return), evaluate the argument, aBlock.
   643      This is used to make certain that cleanup actions 
   643      This is used to make certain that cleanup actions
   644      (for example closing files etc.) are executed regardless of error actions."
   644      (for example closing files etc.) are executed regardless of error actions."
   645 
   645 
   646     ^ [self value:arg1 value:arg2] ensure:aBlock
   646     ^ [self value:arg1 value:arg2] ensure:aBlock
   647 
   647 
   648     "Created: / 16-05-2012 / 11:29:46 / cg"
   648     "Created: / 16-05-2012 / 11:29:46 / cg"
   650 
   650 
   651 value:arg1 value:arg2 value:arg3 onReturnDo:aBlock
   651 value:arg1 value:arg2 value:arg3 onReturnDo:aBlock
   652     "VisualAge compatibility: alias for #ensure:
   652     "VisualAge compatibility: alias for #ensure:
   653      evaluate the receiver - when the block returns either a local return
   653      evaluate the receiver - when the block returns either a local return
   654      or an unwind (i.e. does a long return), evaluate the argument, aBlock.
   654      or an unwind (i.e. does a long return), evaluate the argument, aBlock.
   655      This is used to make certain that cleanup actions 
   655      This is used to make certain that cleanup actions
   656      (for example closing files etc.) are executed regardless of error actions."
   656      (for example closing files etc.) are executed regardless of error actions."
   657 
   657 
   658     ^ [self value:arg1 value:arg2 value:arg3] ensure:aBlock
   658     ^ [self value:arg1 value:arg2 value:arg3] ensure:aBlock
   659 
   659 
   660     "Created: / 16-05-2012 / 11:29:59 / cg"
   660     "Created: / 16-05-2012 / 11:29:59 / cg"
   662 
   662 
   663 valueOnReturnDo:aBlock
   663 valueOnReturnDo:aBlock
   664     "VisualAge compatibility: alias for #ensure:
   664     "VisualAge compatibility: alias for #ensure:
   665      evaluate the receiver - when the block returns either a local return
   665      evaluate the receiver - when the block returns either a local return
   666      or an unwind (i.e. does a long return), evaluate the argument, aBlock.
   666      or an unwind (i.e. does a long return), evaluate the argument, aBlock.
   667      This is used to make certain that cleanup actions 
   667      This is used to make certain that cleanup actions
   668      (for example closing files etc.) are executed regardless of error actions."
   668      (for example closing files etc.) are executed regardless of error actions."
   669 
   669 
   670     ^ self ensure:aBlock
   670     ^ self ensure:aBlock
   671 
   671 
   672     "Created: / 15-11-1996 / 11:38:37 / cg"
   672     "Created: / 15-11-1996 / 11:38:37 / cg"
   695      Thats the method where the block was created."
   695      Thats the method where the block was created."
   696 
   696 
   697     |m|
   697     |m|
   698 
   698 
   699     home notNil ifTrue:[
   699     home notNil ifTrue:[
   700         m := home method.
   700 	m := home method.
   701         m notNil ifTrue:[^ m].
   701 	m notNil ifTrue:[^ m].
   702     ].
   702     ].
   703     m := self literalAt:1 ifAbsent:nil.
   703     m := self literalAt:1 ifAbsent:nil.
   704     m isMethod ifTrue:[^ m].
   704     m isMethod ifTrue:[^ m].
   705     ^ nil
   705     ^ nil
   706 
   706 
   707     "Created: 19.6.1997 / 16:14:57 / cg"
   707     "Created: 19.6.1997 / 16:14:57 / cg"
   708 !
   708 !
   709 
   709 
   710 method
   710 method
   711     "return the receivers method 
   711     "return the receivers method
   712      (the method where the block was created).
   712      (the method where the block was created).
   713      Obsolete: use #homeMethod for ST80 compatibility."
   713      Obsolete: use #homeMethod for ST80 compatibility."
   714 
   714 
   715     <resource: #obsolete>
   715     <resource: #obsolete>
   716 
   716 
   722 methodHome
   722 methodHome
   723     "return the receiver's method home context (the context where it was
   723     "return the receiver's method home context (the context where it was
   724      defined). For cheap blocks, nil is returned"
   724      defined). For cheap blocks, nil is returned"
   725 
   725 
   726     home notNil ifTrue:[
   726     home notNil ifTrue:[
   727         ^ home methodHome
   727 	^ home methodHome
   728     ].
   728     ].
   729     ^ nil
   729     ^ nil
   730 !
   730 !
   731 
   731 
   732 numArgs
   732 numArgs
   761     ^ self
   761     ^ self
   762 
   762 
   763     "
   763     "
   764      |b|
   764      |b|
   765 
   765 
   766      b := [:argList | Transcript 
   766      b := [:argList | Transcript
   767 			show:'invoked with args:'; 
   767 			show:'invoked with args:';
   768 			showCR:argList
   768 			showCR:argList
   769 	  ] asVarArgBlock.
   769 	  ] asVarArgBlock.
   770      b value.
   770      b value.
   771      b value:'arg1'.
   771      b value:'arg1'.
   772      b value:'arg1' value:'arg2' value:'arg3' value:'arg4'
   772      b value:'arg1' value:'arg2' value:'arg3' value:'arg4'
   787 
   787 
   788     "
   788     "
   789      |b b1 b2 b3|
   789      |b b1 b2 b3|
   790 
   790 
   791      b := [:a :b :c | a + b + c] beCurryingBlock.
   791      b := [:a :b :c | a + b + c] beCurryingBlock.
   792      b numArgs.    
   792      b numArgs.
   793      b value:1 value:2 value:3.
   793      b value:1 value:2 value:3.
   794 
   794 
   795      b1 := b value:10.
   795      b1 := b value:10.
   796      b1 numArgs.         
   796      b1 numArgs.
   797      b1 value:2 value:3.    
   797      b1 value:2 value:3.
   798 
   798 
   799      b2 := b value:10 value:20.
   799      b2 := b value:10 value:20.
   800      b2 numArgs.
   800      b2 numArgs.
   801      b2 value:3.
   801      b2 value:3.
   802 
   802 
   831 
   831 
   832 deepCopyUsing:aDictionary postCopySelector:postCopySelector
   832 deepCopyUsing:aDictionary postCopySelector:postCopySelector
   833     |copyOfHome copyOfMe|
   833     |copyOfHome copyOfMe|
   834 
   834 
   835     home isNil ifTrue:[
   835     home isNil ifTrue:[
   836         ^ super deepCopyUsing:aDictionary postCopySelector:postCopySelector
   836 	^ super deepCopyUsing:aDictionary postCopySelector:postCopySelector
   837     ].
   837     ].
   838     copyOfHome := home deepCopyUsing:aDictionary.
   838     copyOfHome := home deepCopyUsing:aDictionary.
   839     copyOfMe := self shallowCopy.
   839     copyOfMe := self shallowCopy.
   840     copyOfMe setHome:copyOfHome.
   840     copyOfMe setHome:copyOfHome.
   841     copyOfMe perform:postCopySelector withOptionalArgument:self and:aDictionary.
   841     copyOfMe perform:postCopySelector withOptionalArgument:self and:aDictionary.
   858 
   858 
   859     micros := endTime - startTime.
   859     micros := endTime - startTime.
   860 
   860 
   861     Transcript show:anInfoString.
   861     Transcript show:anInfoString.
   862     micros < 1000 ifTrue:[
   862     micros < 1000 ifTrue:[
   863         Transcript show:micros; show:' µs'.
   863 	Transcript show:micros; show:' µs'.
   864     ] ifFalse:[
   864     ] ifFalse:[
   865         micros < 100000 ifTrue:[
   865 	micros < 100000 ifTrue:[
   866             millis := (micros / 1000.0) asFixedPointRoundedToScale:2.
   866 	    millis := (micros / 1000.0) asFixedPointRoundedToScale:2.
   867             Transcript show:millis; show:' ms'.
   867 	    Transcript show:millis; show:' ms'.
   868         ] ifFalse:[
   868 	] ifFalse:[
   869             millis := micros // 1000.
   869 	    millis := micros // 1000.
   870             Transcript show:(TimeDuration milliseconds:millis).
   870 	    Transcript show:(TimeDuration milliseconds:millis).
   871         ].
   871 	].
   872     ].
   872     ].
   873     Transcript cr.
   873     Transcript cr.
   874 
   874 
   875     "
   875     "
   876         [10 factorial] benchmark:'10 factorial:'
   876 	[10 factorial] benchmark:'10 factorial:'
   877         [100 factorial] benchmark:'100 factorial:'
   877 	[100 factorial] benchmark:'100 factorial:'
   878     "
   878     "
   879 ! !
   879 ! !
   880 
   880 
   881 !Block methodsFor:'error handling'!
   881 !Block methodsFor:'error handling'!
   882 
   882 
   888      In this case, the VM sends this to the bad method (the receiver).
   888      In this case, the VM sends this to the bad method (the receiver).
   889      Can only happen when the Compiler/runtime system is broken or
   889      Can only happen when the Compiler/runtime system is broken or
   890      someone played around."
   890      someone played around."
   891 
   891 
   892     ^ InvalidCodeError
   892     ^ InvalidCodeError
   893         raiseRequestWith:self
   893 	raiseRequestWith:self
   894         errorString:'invalid block - not executable'
   894 	errorString:'invalid block - not executable'
   895 
   895 
   896     "Modified: 4.11.1996 / 22:46:39 / cg"
   896     "Modified: 4.11.1996 / 22:46:39 / cg"
   897 ! !
   897 ! !
   898 
   898 
   899 !Block methodsFor:'evaluation'!
   899 !Block methodsFor:'evaluation'!
   900 
   900 
   901 value
   901 value
   902     "evaluate the receiver with no block args. 
   902     "evaluate the receiver with no block args.
   903      The receiver must be a block without arguments."
   903      The receiver must be a block without arguments."
   904 
   904 
   905 %{  /* NOCONTEXT */
   905 %{  /* NOCONTEXT */
   906 
   906 #ifdef __SCHTEAM__
       
   907     return context.TAILCALL0( self.asSTCallable() );
       
   908     /* NOTREACHED */
       
   909 #else
   907     REGISTER OBJFUNC thecode;
   910     REGISTER OBJFUNC thecode;
   908     OBJ home;
   911     OBJ home;
   909 
   912 
   910     if (__INST(nargs) == __mkSmallInteger(0)) {
   913     if (__INST(nargs) == __mkSmallInteger(0)) {
   911 #if defined(THIS_CONTEXT)
   914 # if defined(THIS_CONTEXT)
   912         if (__ISVALID_ILC_LNO(__pilc))
   915 	if (__ISVALID_ILC_LNO(__pilc))
   913             __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
   916 	    __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
   914 #endif
   917 # endif
   915 
   918 
   916         thecode = __BlockInstPtr(self)->b_code;
   919 	thecode = __BlockInstPtr(self)->b_code;
   917 #ifdef NEW_BLOCK_CALL
   920 # ifdef NEW_BLOCK_CALL
   918         if (thecode != (OBJFUNC)nil) {
   921 	if (thecode != (OBJFUNC)nil) {
   919             /* compiled machine code */
   922 	    /* compiled machine code */
   920             RETURN ( (*thecode)(self) );
   923 	    RETURN ( (*thecode)(self) );
   921         }
   924 	}
   922         /* interpreted code */
   925 	/* interpreted code */
   923 # ifdef PASS_ARG_POINTER
   926 #  ifdef PASS_ARG_POINTER
   924         RETURN ( __interpret(self, 0, nil, nil, nil, nil) );
   927 	RETURN ( __interpret(self, 0, nil, nil, nil, nil) );
       
   928 #  else
       
   929 	RETURN ( __interpret(self, 0, nil, nil, nil, nil) );
       
   930 #  endif
   925 # else
   931 # else
   926         RETURN ( __interpret(self, 0, nil, nil, nil, nil) );
   932 	home = __BlockInstPtr(self)->b_home;
       
   933 	if (thecode != (OBJFUNC)nil) {
       
   934 	    /* compiled machine code */
       
   935 	    RETURN ( (*thecode)(home) );
       
   936 	}
       
   937 	/* interpreted code */
       
   938 #  ifdef PASS_ARG_POINTER
       
   939 	RETURN ( __interpret(self, 0, nil, home, nil, nil) );
       
   940 #  else
       
   941 	RETURN ( __interpret(self, 0, nil, home, nil, nil) );
       
   942 #  endif
   927 # endif
   943 # endif
   928 #else
       
   929         home = __BlockInstPtr(self)->b_home;
       
   930         if (thecode != (OBJFUNC)nil) {
       
   931             /* compiled machine code */
       
   932             RETURN ( (*thecode)(home) );
       
   933         }
       
   934         /* interpreted code */
       
   935 # ifdef PASS_ARG_POINTER
       
   936         RETURN ( __interpret(self, 0, nil, home, nil, nil) );
       
   937 # else
       
   938         RETURN ( __interpret(self, 0, nil, home, nil, nil) );
       
   939 # endif
       
   940 #endif
       
   941     }
   944     }
       
   945 #endif /* not SCHTEAM */
   942 %}.
   946 %}.
   943     ^ self wrongNumberOfArguments:0
   947     ^ self wrongNumberOfArguments:0
   944 !
   948 !
   945 
   949 
   946 value:arg
   950 value:arg
   947     "evaluate the receiver with one argument. 
   951     "evaluate the receiver with one argument.
   948      The receiver must be a 1-arg block."
   952      The receiver must be a 1-arg block."
   949 
   953 
   950 %{  /* NOCONTEXT */
   954 %{  /* NOCONTEXT */
       
   955 #ifdef __SCHTEAM__
       
   956     return context.TAILCALL1( self.asSTCallable(), arg );
       
   957     /* NOTREACHED */
       
   958 #else
   951 
   959 
   952     REGISTER OBJFUNC thecode;
   960     REGISTER OBJFUNC thecode;
   953     OBJ home;
   961     OBJ home;
   954 
   962 
   955     if (__INST(nargs) == __mkSmallInteger(1)) {
   963     if (__INST(nargs) == __mkSmallInteger(1)) {
   956 #if defined(THIS_CONTEXT)
   964 # if defined(THIS_CONTEXT)
   957         if (__ISVALID_ILC_LNO(__pilc))
   965 	if (__ISVALID_ILC_LNO(__pilc))
   958             __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
   966 	    __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
   959 #endif
   967 # endif
   960         thecode = __BlockInstPtr(self)->b_code;
   968 	thecode = __BlockInstPtr(self)->b_code;
   961 #ifdef NEW_BLOCK_CALL
   969 # ifdef NEW_BLOCK_CALL
   962         if (thecode != (OBJFUNC)nil) {
   970 	if (thecode != (OBJFUNC)nil) {
   963             RETURN ( (*thecode)(self, arg) );
   971 	    RETURN ( (*thecode)(self, arg) );
   964         }
   972 	}
   965         /* interpreted code */
   973 	/* interpreted code */
   966 # ifdef PASS_ARG_POINTER
   974 #  ifdef PASS_ARG_POINTER
   967         RETURN ( __interpret(self, 1, nil, nil, nil, nil, &arg) );
   975 	RETURN ( __interpret(self, 1, nil, nil, nil, nil, &arg) );
       
   976 #  else
       
   977 	RETURN ( __interpret(self, 1, nil, nil, nil, nil, arg) );
       
   978 #  endif
   968 # else
   979 # else
   969         RETURN ( __interpret(self, 1, nil, nil, nil, nil, arg) );
   980 	home = __BlockInstPtr(self)->b_home;
       
   981 	if (thecode != (OBJFUNC)nil) {
       
   982 	    RETURN ( (*thecode)(home, arg) );
       
   983 	}
       
   984 	/* interpreted code */
       
   985 #  ifdef PASS_ARG_POINTER
       
   986 	RETURN ( __interpret(self, 1, nil, home, nil, nil, &arg) );
       
   987 #  else
       
   988 	RETURN ( __interpret(self, 1, nil, home, nil, nil, arg) );
       
   989 #  endif
   970 # endif
   990 # endif
   971 #else
       
   972         home = __BlockInstPtr(self)->b_home;
       
   973         if (thecode != (OBJFUNC)nil) {
       
   974             RETURN ( (*thecode)(home, arg) );
       
   975         }
       
   976         /* interpreted code */
       
   977 # ifdef PASS_ARG_POINTER
       
   978         RETURN ( __interpret(self, 1, nil, home, nil, nil, &arg) );
       
   979 # else
       
   980         RETURN ( __interpret(self, 1, nil, home, nil, nil, arg) );
       
   981 # endif
       
   982 #endif
       
   983     }
   991     }
       
   992 #endif /* not SCHTEAM */
   984 %}.
   993 %}.
   985     ^ self wrongNumberOfArguments:1
   994     ^ self wrongNumberOfArguments:1
   986 !
   995 !
   987 
   996 
   988 value:arg1 optionalArgument:arg2
   997 value:arg1 optionalArgument:arg2
   989     "evaluate the receiver.
   998     "evaluate the receiver.
   990      Optionally pass up one or to two arguments (if the receiver is a one/two arg block)."
   999      Optionally pass up one or to two arguments (if the receiver is a one/two arg block)."
   991 
  1000 
   992     nargs == 2 ifTrue:[
  1001     nargs == 2 ifTrue:[
   993         ^ self value:arg1 value:arg2
  1002 	^ self value:arg1 value:arg2
   994     ].
  1003     ].
   995     ^ self value:arg1
  1004     ^ self value:arg1
   996 
  1005 
   997     "
  1006     "
   998      |block|
  1007      |block|
   999 
  1008 
  1000      block := [:arg | Transcript showCR:arg ].
  1009      block := [:arg | Transcript showCR:arg ].
  1001      block value:2 optionalArgument:3.     
  1010      block value:2 optionalArgument:3.
  1002 
  1011 
  1003      block := [:arg1 :arg2 | Transcript show:arg1; space; showCR:arg2 ].
  1012      block := [:arg1 :arg2 | Transcript show:arg1; space; showCR:arg2 ].
  1004      block value:2 optionalArgument:3.     
  1013      block value:2 optionalArgument:3.
  1005     "
  1014     "
  1006 !
  1015 !
  1007 
  1016 
  1008 value:arg1 optionalArgument:arg2 and:arg3
  1017 value:arg1 optionalArgument:arg2 and:arg3
  1009     "evaluate the receiver.
  1018     "evaluate the receiver.
  1010      Optionally pass up one, two or three arguments (if the receiver is a 1/2/3-arg block)."
  1019      Optionally pass up one, two or three arguments (if the receiver is a 1/2/3-arg block)."
  1011 
  1020 
  1012     nargs == 3 ifTrue:[
  1021     nargs == 3 ifTrue:[
  1013         ^ self value:arg1 value:arg2 value:arg3
  1022 	^ self value:arg1 value:arg2 value:arg3
  1014     ].
  1023     ].
  1015     nargs == 2 ifTrue:[
  1024     nargs == 2 ifTrue:[
  1016         ^ self value:arg1 value:arg2
  1025 	^ self value:arg1 value:arg2
  1017     ].
  1026     ].
  1018     ^ self value:arg1
  1027     ^ self value:arg1
  1019 
  1028 
  1020     "
  1029     "
  1021      |block|
  1030      |block|
  1022 
  1031 
  1023      block := [:arg | Transcript showCR:arg ].
  1032      block := [:arg | Transcript showCR:arg ].
  1024      block value:2 optionalArgument:3.     
  1033      block value:2 optionalArgument:3.
  1025 
  1034 
  1026      block := [:arg1 :arg2 | Transcript show:arg1; space; showCR:arg2 ].
  1035      block := [:arg1 :arg2 | Transcript show:arg1; space; showCR:arg2 ].
  1027      block value:2 optionalArgument:3.     
  1036      block value:2 optionalArgument:3.
  1028     "
  1037     "
  1029 !
  1038 !
  1030 
  1039 
  1031 value:arg1 value:arg2
  1040 value:arg1 value:arg2
  1032     "evaluate the receiver with two arguments. 
  1041     "evaluate the receiver with two arguments.
  1033      The receiver must be a 2-arg block."
  1042      The receiver must be a 2-arg block."
  1034 
  1043 
  1035 %{  /* NOCONTEXT */
  1044 %{  /* NOCONTEXT */
       
  1045 #ifdef __SCHTEAM__
       
  1046     return context.TAILCALL2( self.asSTCallable(), arg1, arg2 );
       
  1047     /* NOTREACHED */
       
  1048 #else
  1036 
  1049 
  1037     REGISTER OBJFUNC thecode;
  1050     REGISTER OBJFUNC thecode;
  1038     OBJ home;
  1051     OBJ home;
  1039 
  1052 
  1040     if (__INST(nargs) == __mkSmallInteger(2)) {
  1053     if (__INST(nargs) == __mkSmallInteger(2)) {
  1041 #if defined(THIS_CONTEXT)
  1054 # if defined(THIS_CONTEXT)
  1042         if (__ISVALID_ILC_LNO(__pilc))
  1055 	if (__ISVALID_ILC_LNO(__pilc))
  1043             __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1056 	    __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1044 #endif
  1057 # endif
  1045         thecode = __BlockInstPtr(self)->b_code;
  1058 	thecode = __BlockInstPtr(self)->b_code;
  1046 #ifdef NEW_BLOCK_CALL
  1059 # ifdef NEW_BLOCK_CALL
  1047         if (thecode != (OBJFUNC)nil) {
  1060 	if (thecode != (OBJFUNC)nil) {
  1048             RETURN ( (*thecode)(self, arg1, arg2) );
  1061 	    RETURN ( (*thecode)(self, arg1, arg2) );
  1049         }
  1062 	}
  1050 # ifdef PASS_ARG_POINTER
  1063 #  ifdef PASS_ARG_POINTER
  1051         RETURN ( __interpret(self, 2, nil, nil, nil, nil, &arg1) );
  1064 	RETURN ( __interpret(self, 2, nil, nil, nil, nil, &arg1) );
       
  1065 #  else
       
  1066 	RETURN ( __interpret(self, 2, nil, nil, nil, nil, arg1, arg2) );
       
  1067 #  endif
  1052 # else
  1068 # else
  1053         RETURN ( __interpret(self, 2, nil, nil, nil, nil, arg1, arg2) );
  1069 	home = __BlockInstPtr(self)->b_home;
       
  1070 	if (thecode != (OBJFUNC)nil) {
       
  1071 	    RETURN ( (*thecode)(home, arg1, arg2) );
       
  1072 	}
       
  1073 #  ifdef PASS_ARG_POINTER
       
  1074 	RETURN ( __interpret(self, 2, nil, home, nil, nil, &arg1) );
       
  1075 #  else
       
  1076 	RETURN ( __interpret(self, 2, nil, home, nil, nil, arg1, arg2) );
       
  1077 #  endif
  1054 # endif
  1078 # endif
  1055 #else
       
  1056         home = __BlockInstPtr(self)->b_home;
       
  1057         if (thecode != (OBJFUNC)nil) {
       
  1058             RETURN ( (*thecode)(home, arg1, arg2) );
       
  1059         }
       
  1060 # ifdef PASS_ARG_POINTER
       
  1061         RETURN ( __interpret(self, 2, nil, home, nil, nil, &arg1) );
       
  1062 # else
       
  1063         RETURN ( __interpret(self, 2, nil, home, nil, nil, arg1, arg2) );
       
  1064 # endif
       
  1065 #endif
       
  1066     }
  1079     }
       
  1080 #endif /* not SCHTEAM */
  1067 %}.
  1081 %}.
  1068     ^ self wrongNumberOfArguments:2
  1082     ^ self wrongNumberOfArguments:2
  1069 !
  1083 !
  1070 
  1084 
  1071 value:arg1 value:arg2 optionalArgument:arg3
  1085 value:arg1 value:arg2 optionalArgument:arg3
  1072     "evaluate the receiver.
  1086     "evaluate the receiver.
  1073      Optionally pass two or threearguments (if the receiver is a 2/3-arg block)."
  1087      Optionally pass two or threearguments (if the receiver is a 2/3-arg block)."
  1074 
  1088 
  1075     nargs == 3 ifTrue:[
  1089     nargs == 3 ifTrue:[
  1076         ^ self value:arg1 value:arg2 value:arg3
  1090 	^ self value:arg1 value:arg2 value:arg3
  1077     ].
  1091     ].
  1078     ^ self value:arg1 value:arg2
  1092     ^ self value:arg1 value:arg2
  1079 !
  1093 !
  1080 
  1094 
  1081 value:arg1 value:arg2 value:arg3
  1095 value:arg1 value:arg2 value:arg3
  1082     "evaluate the receiver with three arguments. 
  1096     "evaluate the receiver with three arguments.
  1083      The receiver must be a 3-arg block."
  1097      The receiver must be a 3-arg block."
  1084 
  1098 
  1085 %{  /* NOCONTEXT */
  1099 %{  /* NOCONTEXT */
       
  1100 #ifdef __SCHTEAM__
       
  1101     return context.TAILCALL3( self.asSTCallable(), arg1, arg2, arg3 );
       
  1102     /* NOTREACHED */
       
  1103 #else
  1086 
  1104 
  1087     REGISTER OBJFUNC thecode;
  1105     REGISTER OBJFUNC thecode;
  1088     OBJ home;
  1106     OBJ home;
  1089 
  1107 
  1090     if (__INST(nargs) == __mkSmallInteger(3)) {
  1108     if (__INST(nargs) == __mkSmallInteger(3)) {
  1091 #if defined(THIS_CONTEXT)
  1109 # if defined(THIS_CONTEXT)
  1092         if (__ISVALID_ILC_LNO(__pilc))
  1110 	if (__ISVALID_ILC_LNO(__pilc))
  1093             __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1111 	    __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1094 #endif
  1112 # endif
  1095         thecode = __BlockInstPtr(self)->b_code;
  1113 	thecode = __BlockInstPtr(self)->b_code;
  1096 #ifdef NEW_BLOCK_CALL
  1114 # ifdef NEW_BLOCK_CALL
  1097         if (thecode != (OBJFUNC)nil) {
  1115 	if (thecode != (OBJFUNC)nil) {
  1098             RETURN ( (*thecode)(self, arg1, arg2, arg3) );
  1116 	    RETURN ( (*thecode)(self, arg1, arg2, arg3) );
  1099         }
  1117 	}
  1100 # ifdef PASS_ARG_POINTER
  1118 #  ifdef PASS_ARG_POINTER
  1101         RETURN ( __interpret(self, 3, nil, nil, nil, nil, &arg1) );
  1119 	RETURN ( __interpret(self, 3, nil, nil, nil, nil, &arg1) );
       
  1120 #  else
       
  1121 	RETURN ( __interpret(self, 3, nil, nil, nil, nil, arg1, arg2, arg3) );
       
  1122 #  endif
  1102 # else
  1123 # else
  1103         RETURN ( __interpret(self, 3, nil, nil, nil, nil, arg1, arg2, arg3) );
  1124 	home = __BlockInstPtr(self)->b_home;
       
  1125 	if (thecode != (OBJFUNC)nil) {
       
  1126 	    RETURN ( (*thecode)(home, arg1, arg2, arg3) );
       
  1127 	}
       
  1128 #  ifdef PASS_ARG_POINTER
       
  1129 	RETURN ( __interpret(self, 3, nil, home, nil, nil, &arg1) );
       
  1130 #  else
       
  1131 	RETURN ( __interpret(self, 3, nil, home, nil, nil, arg1, arg2, arg3) );
       
  1132 #  endif
  1104 # endif
  1133 # endif
  1105 #else
       
  1106         home = __BlockInstPtr(self)->b_home;
       
  1107         if (thecode != (OBJFUNC)nil) {
       
  1108             RETURN ( (*thecode)(home, arg1, arg2, arg3) );
       
  1109         }
       
  1110 # ifdef PASS_ARG_POINTER
       
  1111         RETURN ( __interpret(self, 3, nil, home, nil, nil, &arg1) );
       
  1112 # else
       
  1113         RETURN ( __interpret(self, 3, nil, home, nil, nil, arg1, arg2, arg3) );
       
  1114 # endif
       
  1115 #endif
       
  1116     }
  1134     }
       
  1135 #endif /* not SCHTEAM */
  1117 %}.
  1136 %}.
  1118     ^ self wrongNumberOfArguments:3
  1137     ^ self wrongNumberOfArguments:3
  1119 !
  1138 !
  1120 
  1139 
  1121 value:arg1 value:arg2 value:arg3 value:arg4
  1140 value:arg1 value:arg2 value:arg3 value:arg4
  1122     "evaluate the receiver with four arguments. 
  1141     "evaluate the receiver with four arguments.
  1123      The receiver must be a 4-arg block."
  1142      The receiver must be a 4-arg block."
  1124 
  1143 
  1125 %{  /* NOCONTEXT */
  1144 %{  /* NOCONTEXT */
       
  1145 #ifdef __SCHTEAM__
       
  1146     return context.TAILCALL4( self.asSTCallable(), arg1, arg2, arg3, arg4 );
       
  1147     /* NOTREACHED */
       
  1148 #else
  1126 
  1149 
  1127     REGISTER OBJFUNC thecode;
  1150     REGISTER OBJFUNC thecode;
  1128     OBJ home;
  1151     OBJ home;
  1129 
  1152 
  1130     if (__INST(nargs) == __mkSmallInteger(4)) {
  1153     if (__INST(nargs) == __mkSmallInteger(4)) {
  1131 #if defined(THIS_CONTEXT)
  1154 # if defined(THIS_CONTEXT)
  1132         if (__ISVALID_ILC_LNO(__pilc))
  1155 	if (__ISVALID_ILC_LNO(__pilc))
  1133             __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1156 	    __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
       
  1157 # endif
       
  1158 	thecode = __BlockInstPtr(self)->b_code;
       
  1159 # ifdef NEW_BLOCK_CALL
       
  1160 	if (thecode != (OBJFUNC)nil) {
       
  1161 	    RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4) );
       
  1162 	}
       
  1163 #  ifdef PASS_ARG_POINTER
       
  1164 	RETURN ( __interpret(self, 4, nil, nil, nil, nil, &arg1) );
       
  1165 #  else
       
  1166 	RETURN ( __interpret(self, 4, nil, nil, nil, nil, arg1, arg2, arg3, arg4) );
       
  1167 #  endif
       
  1168 # else
       
  1169 	home = __BlockInstPtr(self)->b_home;
       
  1170 	if (thecode != (OBJFUNC)nil) {
       
  1171 	    RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4) );
       
  1172 	}
       
  1173 #  ifdef PASS_ARG_POINTER
       
  1174 	RETURN ( __interpret(self, 4, nil, home, nil, nil, &arg1) );
       
  1175 #  else
       
  1176 	RETURN ( __interpret(self, 4, nil, home, nil, nil, arg1, arg2, arg3, arg4) );
       
  1177 #  endif
       
  1178 # endif
       
  1179     }
  1134 #endif
  1180 #endif
  1135         thecode = __BlockInstPtr(self)->b_code;
       
  1136 #ifdef NEW_BLOCK_CALL
       
  1137         if (thecode != (OBJFUNC)nil) {
       
  1138             RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4) );
       
  1139         }
       
  1140 # ifdef PASS_ARG_POINTER
       
  1141         RETURN ( __interpret(self, 4, nil, nil, nil, nil, &arg1) );
       
  1142 # else
       
  1143         RETURN ( __interpret(self, 4, nil, nil, nil, nil, arg1, arg2, arg3, arg4) );
       
  1144 # endif
       
  1145 #else
       
  1146         home = __BlockInstPtr(self)->b_home;
       
  1147         if (thecode != (OBJFUNC)nil) {
       
  1148             RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4) );
       
  1149         }
       
  1150 # ifdef PASS_ARG_POINTER
       
  1151         RETURN ( __interpret(self, 4, nil, home, nil, nil, &arg1) );
       
  1152 # else
       
  1153         RETURN ( __interpret(self, 4, nil, home, nil, nil, arg1, arg2, arg3, arg4) );
       
  1154 # endif
       
  1155 #endif
       
  1156     }
       
  1157 %}.
  1181 %}.
  1158     ^ self wrongNumberOfArguments:4
  1182     ^ self wrongNumberOfArguments:4
  1159 !
  1183 !
  1160 
  1184 
  1161 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5
  1185 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5
  1162     "evaluate the receiver with five arguments. 
  1186     "evaluate the receiver with five arguments.
  1163      The receiver must be a 5-arg block."
  1187      The receiver must be a 5-arg block."
  1164 
  1188 
  1165 %{  /* NOCONTEXT */
  1189 %{  /* NOCONTEXT */
       
  1190 #ifdef __SCHTEAM__
       
  1191     return context.TAILCALL5( self.asSTCallable(), arg1, arg2, arg3, arg4, arg5 );
       
  1192     /* NOTREACHED */
       
  1193 #else
  1166 
  1194 
  1167     REGISTER OBJFUNC thecode;
  1195     REGISTER OBJFUNC thecode;
  1168     OBJ home;
  1196     OBJ home;
  1169 
  1197 
  1170     if (__INST(nargs) == __mkSmallInteger(5)) {
  1198     if (__INST(nargs) == __mkSmallInteger(5)) {
  1171 #if defined(THIS_CONTEXT)
  1199 # if defined(THIS_CONTEXT)
  1172         if (__ISVALID_ILC_LNO(__pilc))
  1200 	if (__ISVALID_ILC_LNO(__pilc))
  1173             __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1201 	    __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1174 #endif
  1202 # endif
  1175         thecode = __BlockInstPtr(self)->b_code;
  1203 	thecode = __BlockInstPtr(self)->b_code;
  1176 #ifdef NEW_BLOCK_CALL
  1204 # ifdef NEW_BLOCK_CALL
  1177         if (thecode != (OBJFUNC)nil) {
  1205 	if (thecode != (OBJFUNC)nil) {
  1178             RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5) );
  1206 	    RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5) );
  1179         }
  1207 	}
  1180 # ifdef PASS_ARG_POINTER
  1208 #  ifdef PASS_ARG_POINTER
  1181         RETURN ( __interpret(self, 5, nil, nil, nil, nil, &arg1) );
  1209 	RETURN ( __interpret(self, 5, nil, nil, nil, nil, &arg1) );
       
  1210 #  else
       
  1211 	RETURN ( __interpret(self, 5, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5) );
       
  1212 #  endif
  1182 # else
  1213 # else
  1183         RETURN ( __interpret(self, 5, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5) );
  1214 	home = __BlockInstPtr(self)->b_home;
       
  1215 	if (thecode != (OBJFUNC)nil) {
       
  1216 	    RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5) );
       
  1217 	}
       
  1218 #  ifdef PASS_ARG_POINTER
       
  1219 	RETURN ( __interpret(self, 5, nil, home, nil, nil, &arg1) );
       
  1220 #  else
       
  1221 	RETURN ( __interpret(self, 5, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5) );
       
  1222 #  endif
  1184 # endif
  1223 # endif
  1185 #else
       
  1186         home = __BlockInstPtr(self)->b_home;
       
  1187         if (thecode != (OBJFUNC)nil) {
       
  1188             RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5) );
       
  1189         }
       
  1190 # ifdef PASS_ARG_POINTER
       
  1191         RETURN ( __interpret(self, 5, nil, home, nil, nil, &arg1) );
       
  1192 # else
       
  1193         RETURN ( __interpret(self, 5, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5) );
       
  1194 # endif
       
  1195 #endif
       
  1196     }
  1224     }
       
  1225 #endif /* not SCHTEAM */
  1197 %}.
  1226 %}.
  1198     ^ self wrongNumberOfArguments:5
  1227     ^ self wrongNumberOfArguments:5
  1199 !
  1228 !
  1200 
  1229 
  1201 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6
  1230 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6
  1202     "evaluate the receiver with six arguments. 
  1231     "evaluate the receiver with six arguments.
  1203      The receiver must be a 6-arg block."
  1232      The receiver must be a 6-arg block."
  1204 
  1233 
  1205 %{  /* NOCONTEXT */
  1234 %{  /* NOCONTEXT */
       
  1235 #ifdef __SCHTEAM__
       
  1236     return context.TAILCALL6( self.asSTCallable(), arg1, arg2, arg3, arg4, arg5, arg6 );
       
  1237     /* NOTREACHED */
       
  1238 #else
  1206 
  1239 
  1207     REGISTER OBJFUNC thecode;
  1240     REGISTER OBJFUNC thecode;
  1208     OBJ home;
  1241     OBJ home;
  1209 
  1242 
  1210     if (__INST(nargs) == __mkSmallInteger(6)) {
  1243     if (__INST(nargs) == __mkSmallInteger(6)) {
  1211 #if defined(THIS_CONTEXT)
  1244 # if defined(THIS_CONTEXT)
  1212         if (__ISVALID_ILC_LNO(__pilc))
  1245 	if (__ISVALID_ILC_LNO(__pilc))
  1213             __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1246 	    __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1214 #endif
  1247 # endif
  1215         thecode = __BlockInstPtr(self)->b_code;
  1248 	thecode = __BlockInstPtr(self)->b_code;
  1216 #ifdef NEW_BLOCK_CALL
  1249 # ifdef NEW_BLOCK_CALL
  1217         if (thecode != (OBJFUNC)nil) {
  1250 	if (thecode != (OBJFUNC)nil) {
  1218             RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6) );
  1251 	    RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6) );
  1219         }
  1252 	}
  1220 # ifdef PASS_ARG_POINTER
  1253 #  ifdef PASS_ARG_POINTER
  1221         RETURN ( __interpret(self, 6, nil, nil, nil, nil, &arg1) );
  1254 	RETURN ( __interpret(self, 6, nil, nil, nil, nil, &arg1) );
       
  1255 #  else
       
  1256 	RETURN ( __interpret(self, 6, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) );
       
  1257 #  endif
  1222 # else
  1258 # else
  1223         RETURN ( __interpret(self, 6, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) );
  1259 	home = __BlockInstPtr(self)->b_home;
       
  1260 	if (thecode != (OBJFUNC)nil) {
       
  1261 	    RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6) );
       
  1262 	}
       
  1263 #  ifdef PASS_ARG_POINTER
       
  1264 	RETURN ( __interpret(self, 6, nil, home, nil, nil, &arg1) );
       
  1265 #  else
       
  1266 	RETURN ( __interpret(self, 6, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) );
       
  1267 #  endif
  1224 # endif
  1268 # endif
  1225 #else
       
  1226         home = __BlockInstPtr(self)->b_home;
       
  1227         if (thecode != (OBJFUNC)nil) {
       
  1228             RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6) );
       
  1229         }
       
  1230 # ifdef PASS_ARG_POINTER
       
  1231         RETURN ( __interpret(self, 6, nil, home, nil, nil, &arg1) );
       
  1232 # else
       
  1233         RETURN ( __interpret(self, 6, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6) );
       
  1234 # endif
       
  1235 #endif
       
  1236     }
  1269     }
       
  1270 #endif /* not SCHTEAM */
  1237 %}.
  1271 %}.
  1238     ^ self wrongNumberOfArguments:6
  1272     ^ self wrongNumberOfArguments:6
  1239 !
  1273 !
  1240 
  1274 
  1241 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7
  1275 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7
  1242     "evaluate the receiver with seven arguments.
  1276     "evaluate the receiver with seven arguments.
  1243      The receiver must be a 7-arg block."
  1277      The receiver must be a 7-arg block."
  1244 
  1278 
  1245 %{  /* NOCONTEXT */
  1279 %{  /* NOCONTEXT */
       
  1280 #ifdef __SCHTEAM__
       
  1281     return context.TAILCALL7( self.asSTCallable(), arg1, arg2, arg3, arg4, arg5, arg6, arg7 );
       
  1282     /* NOTREACHED */
       
  1283 #else
  1246 
  1284 
  1247     REGISTER OBJFUNC thecode;
  1285     REGISTER OBJFUNC thecode;
  1248     OBJ home;
  1286     OBJ home;
  1249 
  1287 
  1250     if (__INST(nargs) == __mkSmallInteger(7)) {
  1288     if (__INST(nargs) == __mkSmallInteger(7)) {
  1251 #if defined(THIS_CONTEXT)
  1289 # if defined(THIS_CONTEXT)
  1252         if (__ISVALID_ILC_LNO(__pilc))
  1290 	if (__ISVALID_ILC_LNO(__pilc))
  1253             __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1291 	    __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
       
  1292 # endif
       
  1293 	thecode = __BlockInstPtr(self)->b_code;
       
  1294 # ifdef NEW_BLOCK_CALL
       
  1295 	if (thecode != (OBJFUNC)nil) {
       
  1296 	    RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7) );
       
  1297 	}
       
  1298 #  ifdef PASS_ARG_POINTER
       
  1299 	RETURN ( __interpret(self, 7, nil, nil, nil, nil, &arg1) );
       
  1300 #  else
       
  1301 	RETURN ( __interpret(self, 7, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7) );
       
  1302 #  endif
       
  1303 # else
       
  1304 	home = __BlockInstPtr(self)->b_home;
       
  1305 	if (thecode != (OBJFUNC)nil) {
       
  1306 	    RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7) );
       
  1307 	}
       
  1308 #  ifdef PASS_ARG_POINTER
       
  1309 	RETURN ( __interpret(self, 7, nil, home, nil, nil, &arg1) );
       
  1310 #  else
       
  1311 	RETURN ( __interpret(self, 7, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7) );
       
  1312 #  endif
       
  1313 # endif
       
  1314     }
  1254 #endif
  1315 #endif
  1255         thecode = __BlockInstPtr(self)->b_code;
       
  1256 #ifdef NEW_BLOCK_CALL
       
  1257         if (thecode != (OBJFUNC)nil) {
       
  1258             RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7) );
       
  1259         }
       
  1260 # ifdef PASS_ARG_POINTER
       
  1261         RETURN ( __interpret(self, 7, nil, nil, nil, nil, &arg1) );
       
  1262 # else
       
  1263         RETURN ( __interpret(self, 7, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7) );
       
  1264 # endif
       
  1265 #else
       
  1266         home = __BlockInstPtr(self)->b_home;
       
  1267         if (thecode != (OBJFUNC)nil) {
       
  1268             RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7) );
       
  1269         }
       
  1270 # ifdef PASS_ARG_POINTER
       
  1271         RETURN ( __interpret(self, 7, nil, home, nil, nil, &arg1) );
       
  1272 # else
       
  1273         RETURN ( __interpret(self, 7, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7) );
       
  1274 # endif
       
  1275 #endif
       
  1276     }
       
  1277 %}.
  1316 %}.
  1278     ^ self wrongNumberOfArguments:7
  1317     ^ self wrongNumberOfArguments:7
  1279 !
  1318 !
  1280 
  1319 
  1281 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8
  1320 value:arg1 value:arg2 value:arg3 value:arg4 value:arg5 value:arg6 value:arg7 value:arg8
  1287     REGISTER OBJFUNC thecode;
  1326     REGISTER OBJFUNC thecode;
  1288     OBJ home;
  1327     OBJ home;
  1289 
  1328 
  1290     if (__INST(nargs) == __mkSmallInteger(8)) {
  1329     if (__INST(nargs) == __mkSmallInteger(8)) {
  1291 #if defined(THIS_CONTEXT)
  1330 #if defined(THIS_CONTEXT)
  1292         if (__ISVALID_ILC_LNO(__pilc))
  1331 	if (__ISVALID_ILC_LNO(__pilc))
  1293             __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1332 	    __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1294 #endif
  1333 #endif
  1295         thecode = __BlockInstPtr(self)->b_code;
  1334 	thecode = __BlockInstPtr(self)->b_code;
  1296 #ifdef NEW_BLOCK_CALL
  1335 #ifdef NEW_BLOCK_CALL
  1297         if (thecode != (OBJFUNC)nil) {
  1336 	if (thecode != (OBJFUNC)nil) {
  1298             RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) );
  1337 	    RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) );
  1299         }
  1338 	}
  1300 # ifdef PASS_ARG_POINTER
  1339 # ifdef PASS_ARG_POINTER
  1301         RETURN ( __interpret(self, 8, nil, nil, nil, nil, &arg1) );
  1340 	RETURN ( __interpret(self, 8, nil, nil, nil, nil, &arg1) );
  1302 # else
  1341 # else
  1303         RETURN ( __interpret(self, 8, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) );
  1342 	RETURN ( __interpret(self, 8, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) );
  1304 # endif
  1343 # endif
  1305 #else
  1344 #else
  1306         home = __BlockInstPtr(self)->b_home;
  1345 	home = __BlockInstPtr(self)->b_home;
  1307         if (thecode != (OBJFUNC)nil) {
  1346 	if (thecode != (OBJFUNC)nil) {
  1308             RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) );
  1347 	    RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) );
  1309         }
  1348 	}
  1310 # ifdef PASS_ARG_POINTER
  1349 # ifdef PASS_ARG_POINTER
  1311         RETURN ( __interpret(self, 8, nil, home, nil, nil, &arg1) );
  1350 	RETURN ( __interpret(self, 8, nil, home, nil, nil, &arg1) );
  1312 # else
  1351 # else
  1313         RETURN ( __interpret(self, 8, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) );
  1352 	RETURN ( __interpret(self, 8, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) );
  1314 # endif
  1353 # endif
  1315 #endif
  1354 #endif
  1316     }
  1355     }
  1317 %}.
  1356 %}.
  1318     ^ self wrongNumberOfArguments:8
  1357     ^ self wrongNumberOfArguments:8
  1327     REGISTER OBJFUNC thecode;
  1366     REGISTER OBJFUNC thecode;
  1328     OBJ home;
  1367     OBJ home;
  1329 
  1368 
  1330     if (__INST(nargs) == __mkSmallInteger(9)) {
  1369     if (__INST(nargs) == __mkSmallInteger(9)) {
  1331 #if defined(THIS_CONTEXT)
  1370 #if defined(THIS_CONTEXT)
  1332         if (__ISVALID_ILC_LNO(__pilc))
  1371 	if (__ISVALID_ILC_LNO(__pilc))
  1333             __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1372 	    __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1334 #endif
  1373 #endif
  1335         thecode = __BlockInstPtr(self)->b_code;
  1374 	thecode = __BlockInstPtr(self)->b_code;
  1336 #ifdef NEW_BLOCK_CALL
  1375 #ifdef NEW_BLOCK_CALL
  1337         if (thecode != (OBJFUNC)nil) {
  1376 	if (thecode != (OBJFUNC)nil) {
  1338             RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) );
  1377 	    RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) );
  1339         }
  1378 	}
  1340 # ifdef PASS_ARG_POINTER
  1379 # ifdef PASS_ARG_POINTER
  1341         RETURN ( __interpret(self, 9, nil, nil, nil, nil, &arg1) );
  1380 	RETURN ( __interpret(self, 9, nil, nil, nil, nil, &arg1) );
  1342 # else
  1381 # else
  1343         RETURN ( __interpret(self, 9, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) );
  1382 	RETURN ( __interpret(self, 9, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) );
  1344 # endif
  1383 # endif
  1345 #else
  1384 #else
  1346         home = __BlockInstPtr(self)->b_home;
  1385 	home = __BlockInstPtr(self)->b_home;
  1347         if (thecode != (OBJFUNC)nil) {
  1386 	if (thecode != (OBJFUNC)nil) {
  1348             RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) );
  1387 	    RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) );
  1349         }
  1388 	}
  1350 # ifdef PASS_ARG_POINTER
  1389 # ifdef PASS_ARG_POINTER
  1351         RETURN ( __interpret(self, 9, nil, home, nil, nil, &arg1) );
  1390 	RETURN ( __interpret(self, 9, nil, home, nil, nil, &arg1) );
  1352 # else
  1391 # else
  1353         RETURN ( __interpret(self, 9, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) );
  1392 	RETURN ( __interpret(self, 9, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) );
  1354 # endif
  1393 # endif
  1355 #endif
  1394 #endif
  1356     }
  1395     }
  1357 %}.
  1396 %}.
  1358     ^ self wrongNumberOfArguments:9
  1397     ^ self wrongNumberOfArguments:9
  1367     REGISTER OBJFUNC thecode;
  1406     REGISTER OBJFUNC thecode;
  1368     OBJ home;
  1407     OBJ home;
  1369 
  1408 
  1370     if (__INST(nargs) == __mkSmallInteger(10)) {
  1409     if (__INST(nargs) == __mkSmallInteger(10)) {
  1371 #if defined(THIS_CONTEXT)
  1410 #if defined(THIS_CONTEXT)
  1372         if (__ISVALID_ILC_LNO(__pilc))
  1411 	if (__ISVALID_ILC_LNO(__pilc))
  1373             __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1412 	    __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1374 #endif
  1413 #endif
  1375         thecode = __BlockInstPtr(self)->b_code;
  1414 	thecode = __BlockInstPtr(self)->b_code;
  1376 #ifdef NEW_BLOCK_CALL
  1415 #ifdef NEW_BLOCK_CALL
  1377         if (thecode != (OBJFUNC)nil) {
  1416 	if (thecode != (OBJFUNC)nil) {
  1378             RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) );
  1417 	    RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) );
  1379         }
  1418 	}
  1380 # ifdef PASS_ARG_POINTER
  1419 # ifdef PASS_ARG_POINTER
  1381         RETURN ( __interpret(self, 10, nil, nil, nil, nil, &arg1) );
  1420 	RETURN ( __interpret(self, 10, nil, nil, nil, nil, &arg1) );
  1382 # else
  1421 # else
  1383         RETURN ( __interpret(self, 10, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) );
  1422 	RETURN ( __interpret(self, 10, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) );
  1384 # endif
  1423 # endif
  1385 #else
  1424 #else
  1386         home = __BlockInstPtr(self)->b_home;
  1425 	home = __BlockInstPtr(self)->b_home;
  1387         if (thecode != (OBJFUNC)nil) {
  1426 	if (thecode != (OBJFUNC)nil) {
  1388             RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) );
  1427 	    RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) );
  1389         }
  1428 	}
  1390 # ifdef PASS_ARG_POINTER
  1429 # ifdef PASS_ARG_POINTER
  1391         RETURN ( __interpret(self, 10, nil, home, nil, nil, &arg1) );
  1430 	RETURN ( __interpret(self, 10, nil, home, nil, nil, &arg1) );
  1392 # else
  1431 # else
  1393         RETURN ( __interpret(self, 10, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) );
  1432 	RETURN ( __interpret(self, 10, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) );
  1394 # endif
  1433 # endif
  1395 #endif
  1434 #endif
  1396     }
  1435     }
  1397 %}.
  1436 %}.
  1398     ^ self wrongNumberOfArguments:10
  1437     ^ self wrongNumberOfArguments:10
  1407     REGISTER OBJFUNC thecode;
  1446     REGISTER OBJFUNC thecode;
  1408     OBJ home;
  1447     OBJ home;
  1409 
  1448 
  1410     if (__INST(nargs) == __mkSmallInteger(11)) {
  1449     if (__INST(nargs) == __mkSmallInteger(11)) {
  1411 #if defined(THIS_CONTEXT)
  1450 #if defined(THIS_CONTEXT)
  1412         if (__ISVALID_ILC_LNO(__pilc))
  1451 	if (__ISVALID_ILC_LNO(__pilc))
  1413             __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1452 	    __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1414 #endif
  1453 #endif
  1415         thecode = __BlockInstPtr(self)->b_code;
  1454 	thecode = __BlockInstPtr(self)->b_code;
  1416 #ifdef NEW_BLOCK_CALL
  1455 #ifdef NEW_BLOCK_CALL
  1417         if (thecode != (OBJFUNC)nil) {
  1456 	if (thecode != (OBJFUNC)nil) {
  1418             RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) );
  1457 	    RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) );
  1419         }
  1458 	}
  1420 # ifdef PASS_ARG_POINTER
  1459 # ifdef PASS_ARG_POINTER
  1421         RETURN ( __interpret(self, 11, nil, nil, nil, nil, &arg1) );
  1460 	RETURN ( __interpret(self, 11, nil, nil, nil, nil, &arg1) );
  1422 # else
  1461 # else
  1423         RETURN ( __interpret(self, 11, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) );
  1462 	RETURN ( __interpret(self, 11, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) );
  1424 # endif
  1463 # endif
  1425 #else
  1464 #else
  1426         home = __BlockInstPtr(self)->b_home;
  1465 	home = __BlockInstPtr(self)->b_home;
  1427         if (thecode != (OBJFUNC)nil) {
  1466 	if (thecode != (OBJFUNC)nil) {
  1428             RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) );
  1467 	    RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) );
  1429         }
  1468 	}
  1430 # ifdef PASS_ARG_POINTER
  1469 # ifdef PASS_ARG_POINTER
  1431         RETURN ( __interpret(self, 11, nil, home, nil, nil, &arg1) );
  1470 	RETURN ( __interpret(self, 11, nil, home, nil, nil, &arg1) );
  1432 # else
  1471 # else
  1433         RETURN ( __interpret(self, 11, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) );
  1472 	RETURN ( __interpret(self, 11, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11) );
  1434 # endif
  1473 # endif
  1435 #endif
  1474 #endif
  1436     }
  1475     }
  1437 %}.
  1476 %}.
  1438     ^ self wrongNumberOfArguments:11
  1477     ^ self wrongNumberOfArguments:11
  1447     REGISTER OBJFUNC thecode;
  1486     REGISTER OBJFUNC thecode;
  1448     OBJ home;
  1487     OBJ home;
  1449 
  1488 
  1450     if (__INST(nargs) == __mkSmallInteger(12)) {
  1489     if (__INST(nargs) == __mkSmallInteger(12)) {
  1451 #if defined(THIS_CONTEXT)
  1490 #if defined(THIS_CONTEXT)
  1452         if (__ISVALID_ILC_LNO(__pilc))
  1491 	if (__ISVALID_ILC_LNO(__pilc))
  1453             __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1492 	    __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1454 #endif
  1493 #endif
  1455         thecode = __BlockInstPtr(self)->b_code;
  1494 	thecode = __BlockInstPtr(self)->b_code;
  1456 #ifdef NEW_BLOCK_CALL
  1495 #ifdef NEW_BLOCK_CALL
  1457         if (thecode != (OBJFUNC)nil) {
  1496 	if (thecode != (OBJFUNC)nil) {
  1458             RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) );
  1497 	    RETURN ( (*thecode)(self, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) );
  1459         }
  1498 	}
  1460 # ifdef PASS_ARG_POINTER
  1499 # ifdef PASS_ARG_POINTER
  1461         RETURN ( __interpret(self, 12, nil, nil, nil, nil, &arg1) );
  1500 	RETURN ( __interpret(self, 12, nil, nil, nil, nil, &arg1) );
  1462 # else
  1501 # else
  1463         RETURN ( __interpret(self, 12, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) );
  1502 	RETURN ( __interpret(self, 12, nil, nil, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) );
  1464 # endif
  1503 # endif
  1465 #else
  1504 #else
  1466         home = __BlockInstPtr(self)->b_home;
  1505 	home = __BlockInstPtr(self)->b_home;
  1467         if (thecode != (OBJFUNC)nil) {
  1506 	if (thecode != (OBJFUNC)nil) {
  1468             RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) );
  1507 	    RETURN ( (*thecode)(home, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) );
  1469         }
  1508 	}
  1470 # ifdef PASS_ARG_POINTER
  1509 # ifdef PASS_ARG_POINTER
  1471         RETURN ( __interpret(self, 12, nil, home, nil, nil, &arg1) );
  1510 	RETURN ( __interpret(self, 12, nil, home, nil, nil, &arg1) );
  1472 # else
  1511 # else
  1473         RETURN ( __interpret(self, 12, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) );
  1512 	RETURN ( __interpret(self, 12, nil, home, nil, nil, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12) );
  1474 # endif
  1513 # endif
  1475 #endif
  1514 #endif
  1476     }
  1515     }
  1477 %}.
  1516 %}.
  1478     ^ self wrongNumberOfArguments:12
  1517     ^ self wrongNumberOfArguments:12
  1486     |oldPrio retVal activeProcess|
  1525     |oldPrio retVal activeProcess|
  1487 
  1526 
  1488     activeProcess := Processor activeProcess.
  1527     activeProcess := Processor activeProcess.
  1489     oldPrio := Processor activePriority.
  1528     oldPrio := Processor activePriority.
  1490     [
  1529     [
  1491         activeProcess priority:priority.
  1530 	activeProcess priority:priority.
  1492         retVal := self value.
  1531 	retVal := self value.
  1493     ] ensure:[
  1532     ] ensure:[
  1494         activeProcess priority:oldPrio
  1533 	activeProcess priority:oldPrio
  1495     ].
  1534     ].
  1496     ^ retVal
  1535     ^ retVal
  1497 
  1536 
  1498     "
  1537     "
  1499      [
  1538      [
  1500          1000 timesRepeat:[
  1539 	 1000 timesRepeat:[
  1501              1000 factorial
  1540 	     1000 factorial
  1502          ]
  1541 	 ]
  1503      ] valueAt:3
  1542      ] valueAt:3
  1504     "
  1543     "
  1505 
  1544 
  1506     "Created: / 29.7.1998 / 19:19:48 / cg"
  1545     "Created: / 29.7.1998 / 19:19:48 / cg"
  1507 !
  1546 !
  1512      The size of the argArray must match the number of arguments the receiver expects."
  1551      The size of the argArray must match the number of arguments the receiver expects."
  1513 
  1552 
  1514     |a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15|
  1553     |a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15|
  1515 
  1554 
  1516     (argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[
  1555     (argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[
  1517         argArray isCollection ifTrue:[
  1556 	argArray isCollection ifTrue:[
  1518             ^ self valueWithArguments:argArray asArray
  1557 	    ^ self valueWithArguments:argArray asArray
  1519         ].
  1558 	].
  1520         ^ self badArgumentArray:argArray
  1559 	^ self badArgumentArray:argArray
  1521     ].
  1560     ].
  1522     (argArray size == nargs) ifFalse:[
  1561     (argArray size == nargs) ifFalse:[
  1523         ^ self wrongNumberOfArguments:argArray size
  1562 	^ self wrongNumberOfArguments:argArray size
  1524     ].
  1563     ].
  1525 %{
  1564 %{
  1526 
  1565 
  1527     REGISTER OBJFUNC thecode;
  1566     REGISTER OBJFUNC thecode;
  1528     OBJ home;
  1567     OBJ home;
  1529     REGISTER OBJ *ap;
  1568     REGISTER OBJ *ap;
  1530     OBJ nA;
  1569     OBJ nA;
  1531 
  1570 
  1532 #if defined(THIS_CONTEXT)
  1571 #if defined(THIS_CONTEXT)
  1533     if (__ISVALID_ILC_LNO(__pilc))
  1572     if (__ISVALID_ILC_LNO(__pilc))
  1534             __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1573 	    __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1535 #endif
  1574 #endif
  1536     thecode = __BlockInstPtr(self)->b_code;
  1575     thecode = __BlockInstPtr(self)->b_code;
  1537 
  1576 
  1538     nA = __INST(nargs);
  1577     nA = __INST(nargs);
  1539 
  1578 
  1540 #ifndef NEW_BLOCK_CALL
  1579 #ifndef NEW_BLOCK_CALL
  1541     home = __BlockInstPtr(self)->b_home;
  1580     home = __BlockInstPtr(self)->b_home;
  1542     if (thecode != (OBJFUNC)nil) {
  1581     if (thecode != (OBJFUNC)nil) {
  1543         /* the most common case (0 args) here (without a switch) */
  1582 	/* the most common case (0 args) here (without a switch) */
  1544 
  1583 
  1545         if (nA == __mkSmallInteger(0)) {
  1584 	if (nA == __mkSmallInteger(0)) {
  1546             RETURN ( (*thecode)(home) );
  1585 	    RETURN ( (*thecode)(home) );
  1547         }
  1586 	}
  1548 
  1587 
  1549         ap = __arrayVal(argArray);   /* nonNil after above test (size is known to be ok) */
  1588 	ap = __arrayVal(argArray);   /* nonNil after above test (size is known to be ok) */
  1550         switch ((INT)(nA)) {
  1589 	switch ((INT)(nA)) {
  1551             default:
  1590 	    default:
  1552                 goto error;
  1591 		goto error;
  1553             case (INT)__mkSmallInteger(15):
  1592 	    case (INT)__mkSmallInteger(15):
  1554                 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]) );
  1593 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9], ap[10], ap[11], ap[12], ap[13], ap[14]) );
  1555             case (INT)__mkSmallInteger(14):
  1594 	    case (INT)__mkSmallInteger(14):
  1556                 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]) );
  1595 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9], ap[10], ap[11], ap[12], ap[13]) );
  1557             case (INT)__mkSmallInteger(13):
  1596 	    case (INT)__mkSmallInteger(13):
  1558                 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]) );
  1597 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9], ap[10], ap[11], ap[12]) );
  1559             case (INT)__mkSmallInteger(12):
  1598 	    case (INT)__mkSmallInteger(12):
  1560                 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]) );
  1599 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9], ap[10], ap[11]) );
  1561             case (INT)__mkSmallInteger(11):
  1600 	    case (INT)__mkSmallInteger(11):
  1562                 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]) );
  1601 		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]) );
  1563             case (INT)__mkSmallInteger(10):
  1602 	    case (INT)__mkSmallInteger(10):
  1564                 RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9]) );
  1603 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9]) );
  1565             case (INT)__mkSmallInteger(9):
  1604 	    case (INT)__mkSmallInteger(9):
  1566                 RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8]) );
  1605 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8]) );
  1567             case (INT)__mkSmallInteger(8):
  1606 	    case (INT)__mkSmallInteger(8):
  1568                 RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7]) );
  1607 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7]) );
  1569             case (INT)__mkSmallInteger(7):
  1608 	    case (INT)__mkSmallInteger(7):
  1570                 RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) );
  1609 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) );
  1571             case (INT)__mkSmallInteger(6):
  1610 	    case (INT)__mkSmallInteger(6):
  1572                 RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) );
  1611 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) );
  1573             case (INT)__mkSmallInteger(5):
  1612 	    case (INT)__mkSmallInteger(5):
  1574                 RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4]) );
  1613 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4]) );
  1575             case (INT)__mkSmallInteger(4):
  1614 	    case (INT)__mkSmallInteger(4):
  1576                 RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3]) );
  1615 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3]) );
  1577             case (INT)__mkSmallInteger(3):
  1616 	    case (INT)__mkSmallInteger(3):
  1578                 RETURN ( (*thecode)(home, ap[0], ap[1], ap[2]) );
  1617 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2]) );
  1579             case (INT)__mkSmallInteger(2):
  1618 	    case (INT)__mkSmallInteger(2):
  1580                 RETURN ( (*thecode)(home, ap[0], ap[1]) );
  1619 		RETURN ( (*thecode)(home, ap[0], ap[1]) );
  1581             case (INT)__mkSmallInteger(1):
  1620 	    case (INT)__mkSmallInteger(1):
  1582                 RETURN ( (*thecode)(home, ap[0]) );
  1621 		RETURN ( (*thecode)(home, ap[0]) );
  1583             case (INT)__mkSmallInteger(0):
  1622 	    case (INT)__mkSmallInteger(0):
  1584                 RETURN ( (*thecode)(home) );
  1623 		RETURN ( (*thecode)(home) );
  1585                 break;
  1624 		break;
  1586         }
  1625 	}
  1587     }
  1626     }
  1588 #endif
  1627 #endif
  1589 
  1628 
  1590     if (nA != __mkSmallInteger(0)) {
  1629     if (nA != __mkSmallInteger(0)) {
  1591         ap = __arrayVal(argArray);   /* nonNil after above test (size is known to be ok) */
  1630 	ap = __arrayVal(argArray);   /* nonNil after above test (size is known to be ok) */
  1592         switch ((INT)nA) {
  1631 	switch ((INT)nA) {
  1593             default:
  1632 	    default:
  1594                 goto error;
  1633 		goto error;
  1595             case (INT)__mkSmallInteger(15):
  1634 	    case (INT)__mkSmallInteger(15):
  1596                 a15 = ap[14];
  1635 		a15 = ap[14];
  1597             case (INT)__mkSmallInteger(14):
  1636 	    case (INT)__mkSmallInteger(14):
  1598                 a14 = ap[13];
  1637 		a14 = ap[13];
  1599             case (INT)__mkSmallInteger(13):
  1638 	    case (INT)__mkSmallInteger(13):
  1600                 a13 = ap[12];
  1639 		a13 = ap[12];
  1601             case (INT)__mkSmallInteger(12):
  1640 	    case (INT)__mkSmallInteger(12):
  1602                 a12 = ap[11];
  1641 		a12 = ap[11];
  1603             case (INT)__mkSmallInteger(11):
  1642 	    case (INT)__mkSmallInteger(11):
  1604                 a11 = ap[10];
  1643 		a11 = ap[10];
  1605             case (INT)__mkSmallInteger(10):
  1644 	    case (INT)__mkSmallInteger(10):
  1606                 a10 = ap[9];
  1645 		a10 = ap[9];
  1607             case (INT)__mkSmallInteger(9):
  1646 	    case (INT)__mkSmallInteger(9):
  1608                 a9 = ap[8];
  1647 		a9 = ap[8];
  1609             case (INT)__mkSmallInteger(8):
  1648 	    case (INT)__mkSmallInteger(8):
  1610                 a8 = ap[7];
  1649 		a8 = ap[7];
  1611             case (INT)__mkSmallInteger(7):
  1650 	    case (INT)__mkSmallInteger(7):
  1612                 a7 = ap[6];
  1651 		a7 = ap[6];
  1613             case (INT)__mkSmallInteger(6):
  1652 	    case (INT)__mkSmallInteger(6):
  1614                 a6 = ap[5];
  1653 		a6 = ap[5];
  1615             case (INT)__mkSmallInteger(5):
  1654 	    case (INT)__mkSmallInteger(5):
  1616                 a5 = ap[4];
  1655 		a5 = ap[4];
  1617             case (INT)__mkSmallInteger(4):
  1656 	    case (INT)__mkSmallInteger(4):
  1618                 a4 = ap[3];
  1657 		a4 = ap[3];
  1619             case (INT)__mkSmallInteger(3):
  1658 	    case (INT)__mkSmallInteger(3):
  1620                 a3 = ap[2];
  1659 		a3 = ap[2];
  1621             case (INT)__mkSmallInteger(2):
  1660 	    case (INT)__mkSmallInteger(2):
  1622                 a2 = ap[1];
  1661 		a2 = ap[1];
  1623             case (INT)__mkSmallInteger(1):
  1662 	    case (INT)__mkSmallInteger(1):
  1624                 a1 = ap[0];
  1663 		a1 = ap[0];
  1625             case (INT)__mkSmallInteger(0):
  1664 	    case (INT)__mkSmallInteger(0):
  1626                 break;
  1665 		break;
  1627         }
  1666 	}
  1628     }
  1667     }
  1629 
  1668 
  1630 #ifdef NEW_BLOCK_CALL
  1669 #ifdef NEW_BLOCK_CALL
  1631     if (thecode != (OBJFUNC)nil) {
  1670     if (thecode != (OBJFUNC)nil) {
  1632         RETURN ( (*thecode)(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) );
  1671 	RETURN ( (*thecode)(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) );
  1633     }
  1672     }
  1634 # ifdef PASS_ARG_POINTER
  1673 # ifdef PASS_ARG_POINTER
  1635     RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, &a1) );
  1674     RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, &a1) );
  1636 # else
  1675 # else
  1637     RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) );
  1676     RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) );
  1651 %}.
  1690 %}.
  1652     "
  1691     "
  1653      the above code only supports up-to 15 arguments
  1692      the above code only supports up-to 15 arguments
  1654     "
  1693     "
  1655     ^ ArgumentError
  1694     ^ ArgumentError
  1656         raiseRequestWith:self
  1695 	raiseRequestWith:self
  1657         errorString:'only blocks with up-to 15 arguments supported'
  1696 	errorString:'only blocks with up-to 15 arguments supported'
  1658 !
  1697 !
  1659 
  1698 
  1660 valueWithOptionalArgument:arg
  1699 valueWithOptionalArgument:arg
  1661     "evaluate the receiver.
  1700     "evaluate the receiver.
  1662      Optionally pass an argument (if the receiver is a one arg block)."
  1701      Optionally pass an argument (if the receiver is a one arg block)."
  1663 
  1702 
  1664     nargs == 1 ifTrue:[
  1703     nargs == 1 ifTrue:[
  1665         ^ self value:arg
  1704 	^ self value:arg
  1666     ].
  1705     ].
  1667     ^ self value
  1706     ^ self value
  1668 
  1707 
  1669     "
  1708     "
  1670      |block|
  1709      |block|
  1671 
  1710 
  1672      block := [ Transcript showCR:'hello' ].
  1711      block := [ Transcript showCR:'hello' ].
  1673      block valueWithOptionalArgument:2.     
  1712      block valueWithOptionalArgument:2.
  1674 
  1713 
  1675      block := [:arg | Transcript showCR:arg ].
  1714      block := [:arg | Transcript showCR:arg ].
  1676      block valueWithOptionalArgument:2.     
  1715      block valueWithOptionalArgument:2.
  1677     "
  1716     "
  1678 !
  1717 !
  1679 
  1718 
  1680 valueWithOptionalArgument:arg1 and:arg2
  1719 valueWithOptionalArgument:arg1 and:arg2
  1681     "evaluate the receiver.
  1720     "evaluate the receiver.
  1682      Optionally pass up to two arguments (if the receiver is a one/two arg block)."
  1721      Optionally pass up to two arguments (if the receiver is a one/two arg block)."
  1683 
  1722 
  1684     nargs == 2 ifTrue:[
  1723     nargs == 2 ifTrue:[
  1685         ^ self value:arg1 value:arg2
  1724 	^ self value:arg1 value:arg2
  1686     ].
  1725     ].
  1687     nargs == 1 ifTrue:[
  1726     nargs == 1 ifTrue:[
  1688         ^ self value:arg1
  1727 	^ self value:arg1
  1689     ].
  1728     ].
  1690     ^ self value
  1729     ^ self value
  1691 
  1730 
  1692     "
  1731     "
  1693      |block|
  1732      |block|
  1694 
  1733 
  1695      block := [ Transcript showCR:'hello' ].
  1734      block := [ Transcript showCR:'hello' ].
  1696      block valueWithOptionalArgument:2.     
  1735      block valueWithOptionalArgument:2.
  1697 
  1736 
  1698      block := [:arg | Transcript showCR:arg ].
  1737      block := [:arg | Transcript showCR:arg ].
  1699      block valueWithOptionalArgument:2.     
  1738      block valueWithOptionalArgument:2.
  1700 
  1739 
  1701      block := [:arg1 :arg2 | Transcript showCR:arg1. Transcript showCR:arg2 ].
  1740      block := [:arg1 :arg2 | Transcript showCR:arg1. Transcript showCR:arg2 ].
  1702      block valueWithOptionalArgument:10 and:20.     
  1741      block valueWithOptionalArgument:10 and:20.
  1703     "
  1742     "
  1704 !
  1743 !
  1705 
  1744 
  1706 valueWithOptionalArgument:arg1 and:arg2 and:arg3
  1745 valueWithOptionalArgument:arg1 and:arg2 and:arg3
  1707     "evaluate the receiver.
  1746     "evaluate the receiver.
  1708      Optionally pass up to three arguments (if the receiver is a one/two/three arg block)."
  1747      Optionally pass up to three arguments (if the receiver is a one/two/three arg block)."
  1709 
  1748 
  1710     nargs == 3 ifTrue:[
  1749     nargs == 3 ifTrue:[
  1711         ^ self value:arg1 value:arg2 value:arg3
  1750 	^ self value:arg1 value:arg2 value:arg3
  1712     ].
  1751     ].
  1713     nargs == 2 ifTrue:[
  1752     nargs == 2 ifTrue:[
  1714         ^ self value:arg1 value:arg2
  1753 	^ self value:arg1 value:arg2
  1715     ].
  1754     ].
  1716     nargs == 1 ifTrue:[
  1755     nargs == 1 ifTrue:[
  1717         ^ self value:arg1
  1756 	^ self value:arg1
  1718     ].
  1757     ].
  1719     ^ self value
  1758     ^ self value
  1720 
  1759 
  1721     "
  1760     "
  1722      |block|
  1761      |block|
  1723 
  1762 
  1724      block := [ Transcript showCR:'hello' ].
  1763      block := [ Transcript showCR:'hello' ].
  1725      block valueWithOptionalArgument:2.     
  1764      block valueWithOptionalArgument:2.
  1726 
  1765 
  1727      block := [:arg | Transcript showCR:arg ].
  1766      block := [:arg | Transcript showCR:arg ].
  1728      block valueWithOptionalArgument:2.     
  1767      block valueWithOptionalArgument:2.
  1729 
  1768 
  1730      block := [:arg1 :arg2 | Transcript showCR:arg1. Transcript showCR:arg2 ].
  1769      block := [:arg1 :arg2 | Transcript showCR:arg1. Transcript showCR:arg2 ].
  1731      block valueWithOptionalArgument:10 and:20.     
  1770      block valueWithOptionalArgument:10 and:20.
  1732     "
  1771     "
  1733 !
  1772 !
  1734 
  1773 
  1735 valueWithOptionalArgument:arg1 and:arg2 and:arg3 and:arg4
  1774 valueWithOptionalArgument:arg1 and:arg2 and:arg3 and:arg4
  1736     "evaluate the receiver.
  1775     "evaluate the receiver.
  1737      Optionally pass up to four arguments (if the receiver is a one/two/three/four arg block)."
  1776      Optionally pass up to four arguments (if the receiver is a one/two/three/four arg block)."
  1738 
  1777 
  1739     nargs == 4 ifTrue:[
  1778     nargs == 4 ifTrue:[
  1740         ^ self value:arg1 value:arg2 value:arg3 value:arg4
  1779 	^ self value:arg1 value:arg2 value:arg3 value:arg4
  1741     ].
  1780     ].
  1742     nargs == 3 ifTrue:[
  1781     nargs == 3 ifTrue:[
  1743         ^ self value:arg1 value:arg2 value:arg3
  1782 	^ self value:arg1 value:arg2 value:arg3
  1744     ].
  1783     ].
  1745     nargs == 2 ifTrue:[
  1784     nargs == 2 ifTrue:[
  1746         ^ self value:arg1 value:arg2
  1785 	^ self value:arg1 value:arg2
  1747     ].
  1786     ].
  1748     nargs == 1 ifTrue:[
  1787     nargs == 1 ifTrue:[
  1749         ^ self value:arg1
  1788 	^ self value:arg1
  1750     ].
  1789     ].
  1751     ^ self value
  1790     ^ self value
  1752 
  1791 
  1753     "
  1792     "
  1754      |block|
  1793      |block|
  1755 
  1794 
  1756      block := [ Transcript showCR:'hello' ].
  1795      block := [ Transcript showCR:'hello' ].
  1757      block valueWithOptionalArgument:2.     
  1796      block valueWithOptionalArgument:2.
  1758 
  1797 
  1759      block := [:arg | Transcript showCR:arg ].
  1798      block := [:arg | Transcript showCR:arg ].
  1760      block valueWithOptionalArgument:2.     
  1799      block valueWithOptionalArgument:2.
  1761 
  1800 
  1762      block := [:arg1 :arg2 | Transcript showCR:arg1. Transcript showCR:arg2 ].
  1801      block := [:arg1 :arg2 | Transcript showCR:arg1. Transcript showCR:arg2 ].
  1763      block valueWithOptionalArgument:10 and:20.     
  1802      block valueWithOptionalArgument:10 and:20.
  1764     "
  1803     "
  1765 !
  1804 !
  1766 
  1805 
  1767 valueWithOptionalArguments:argArray
  1806 valueWithOptionalArguments:argArray
  1768     "evaluate the receiver with arguments as required taken from argArray.
  1807     "evaluate the receiver with arguments as required taken from argArray.
  1771      If the size of the argArray is smaller than the number of arguments, an error is raised."
  1810      If the size of the argArray is smaller than the number of arguments, an error is raised."
  1772 
  1811 
  1773     |numArgsProvided a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15|
  1812     |numArgsProvided a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15|
  1774 
  1813 
  1775     (argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[
  1814     (argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[
  1776         argArray isCollection ifTrue:[
  1815 	argArray isCollection ifTrue:[
  1777             ^ self valueWithArguments:argArray asArray
  1816 	    ^ self valueWithArguments:argArray asArray
  1778         ].
  1817 	].
  1779         ^ self badArgumentArray:argArray
  1818 	^ self badArgumentArray:argArray
  1780     ].
  1819     ].
  1781     (argArray size >= nargs) ifFalse:[
  1820     (argArray size >= nargs) ifFalse:[
  1782         ^ self wrongNumberOfArguments:argArray size
  1821 	^ self wrongNumberOfArguments:argArray size
  1783     ].
  1822     ].
  1784 %{
  1823 %{
  1785     REGISTER OBJFUNC thecode;
  1824     REGISTER OBJFUNC thecode;
  1786     OBJ home;
  1825     OBJ home;
  1787     REGISTER OBJ *ap;
  1826     REGISTER OBJ *ap;
  1788     OBJ nA;
  1827     OBJ nA;
  1789     int __numArgsProvided = __intVal(numArgsProvided);
  1828     int __numArgsProvided = __intVal(numArgsProvided);
  1790 
  1829 
  1791 #if defined(THIS_CONTEXT)
  1830 #if defined(THIS_CONTEXT)
  1792     if (__ISVALID_ILC_LNO(__pilc))
  1831     if (__ISVALID_ILC_LNO(__pilc))
  1793             __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1832 	    __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1794 #endif
  1833 #endif
  1795     thecode = __BlockInstPtr(self)->b_code;
  1834     thecode = __BlockInstPtr(self)->b_code;
  1796 
  1835 
  1797     nA = __INST(nargs);
  1836     nA = __INST(nargs);
  1798 
  1837 
  1799     if (argArray == nil) {
  1838     if (argArray == nil) {
  1800         ap = 0;  
  1839 	ap = 0;
  1801     } else {
  1840     } else {
  1802         ap = __arrayVal(argArray);   /* nonNil after above test (size is known to be ok) */
  1841 	ap = __arrayVal(argArray);   /* nonNil after above test (size is known to be ok) */
  1803     }
  1842     }
  1804 
  1843 
  1805 #ifndef NEW_BLOCK_CALL
  1844 #ifndef NEW_BLOCK_CALL
  1806     home = __BlockInstPtr(self)->b_home;
  1845     home = __BlockInstPtr(self)->b_home;
  1807     if (thecode != (OBJFUNC)nil) {
  1846     if (thecode != (OBJFUNC)nil) {
  1808         /* the most common case (0 args) here (without a switch) */
  1847 	/* the most common case (0 args) here (without a switch) */
  1809 
  1848 
  1810         if (nA == __mkSmallInteger(0)) {
  1849 	if (nA == __mkSmallInteger(0)) {
  1811             RETURN ( (*thecode)(home) );
  1850 	    RETURN ( (*thecode)(home) );
  1812         }
  1851 	}
  1813 
  1852 
  1814         switch ((INT)(nA)) {
  1853 	switch ((INT)(nA)) {
  1815             default:
  1854 	    default:
  1816                 goto error;
  1855 		goto error;
  1817             case (INT)__mkSmallInteger(15):
  1856 	    case (INT)__mkSmallInteger(15):
  1818                 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]) );
  1857 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9], ap[10], ap[11], ap[12], ap[13], ap[14]) );
  1819             case (INT)__mkSmallInteger(14):
  1858 	    case (INT)__mkSmallInteger(14):
  1820                 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]) );
  1859 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9], ap[10], ap[11], ap[12], ap[13]) );
  1821             case (INT)__mkSmallInteger(13):
  1860 	    case (INT)__mkSmallInteger(13):
  1822                 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]) );
  1861 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9], ap[10], ap[11], ap[12]) );
  1823             case (INT)__mkSmallInteger(12):
  1862 	    case (INT)__mkSmallInteger(12):
  1824                 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]) );
  1863 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9], ap[10], ap[11]) );
  1825             case (INT)__mkSmallInteger(11):
  1864 	    case (INT)__mkSmallInteger(11):
  1826                 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]) );
  1865 		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]) );
  1827             case (INT)__mkSmallInteger(10):
  1866 	    case (INT)__mkSmallInteger(10):
  1828                 RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9]) );
  1867 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8], ap[9]) );
  1829             case (INT)__mkSmallInteger(9):
  1868 	    case (INT)__mkSmallInteger(9):
  1830                 RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8]) );
  1869 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7], ap[8]) );
  1831             case (INT)__mkSmallInteger(8):
  1870 	    case (INT)__mkSmallInteger(8):
  1832                 RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7]) );
  1871 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6], ap[7]) );
  1833             case (INT)__mkSmallInteger(7):
  1872 	    case (INT)__mkSmallInteger(7):
  1834                 RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) );
  1873 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5], ap[6]) );
  1835             case (INT)__mkSmallInteger(6):
  1874 	    case (INT)__mkSmallInteger(6):
  1836                 RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) );
  1875 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4], ap[5]) );
  1837             case (INT)__mkSmallInteger(5):
  1876 	    case (INT)__mkSmallInteger(5):
  1838                 RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4]) );
  1877 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3], ap[4]) );
  1839             case (INT)__mkSmallInteger(4):
  1878 	    case (INT)__mkSmallInteger(4):
  1840                 RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3]) );
  1879 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2], ap[3]) );
  1841             case (INT)__mkSmallInteger(3):
  1880 	    case (INT)__mkSmallInteger(3):
  1842                 RETURN ( (*thecode)(home, ap[0], ap[1], ap[2]) );
  1881 		RETURN ( (*thecode)(home, ap[0], ap[1], ap[2]) );
  1843             case (INT)__mkSmallInteger(2):
  1882 	    case (INT)__mkSmallInteger(2):
  1844                 RETURN ( (*thecode)(home, ap[0], ap[1]) );
  1883 		RETURN ( (*thecode)(home, ap[0], ap[1]) );
  1845             case (INT)__mkSmallInteger(1):
  1884 	    case (INT)__mkSmallInteger(1):
  1846                 RETURN ( (*thecode)(home, ap[0]) );
  1885 		RETURN ( (*thecode)(home, ap[0]) );
  1847             case (INT)__mkSmallInteger(0):
  1886 	    case (INT)__mkSmallInteger(0):
  1848                 RETURN ( (*thecode)(home) );
  1887 		RETURN ( (*thecode)(home) );
  1849                 break;
  1888 		break;
  1850         }
  1889 	}
  1851     }
  1890     }
  1852 #endif
  1891 #endif
  1853 
  1892 
  1854     if (nA != __mkSmallInteger(0)) {
  1893     if (nA != __mkSmallInteger(0)) {
  1855         ap = __arrayVal(argArray);   /* nonNil after above test (size is known to be ok) */
  1894 	ap = __arrayVal(argArray);   /* nonNil after above test (size is known to be ok) */
  1856         switch ((INT)nA) {
  1895 	switch ((INT)nA) {
  1857             default:
  1896 	    default:
  1858                 goto error;
  1897 		goto error;
  1859             case (INT)__mkSmallInteger(15):
  1898 	    case (INT)__mkSmallInteger(15):
  1860                 a15 = ap[14];
  1899 		a15 = ap[14];
  1861             case (INT)__mkSmallInteger(14):
  1900 	    case (INT)__mkSmallInteger(14):
  1862                 a14 = ap[13];
  1901 		a14 = ap[13];
  1863             case (INT)__mkSmallInteger(13):
  1902 	    case (INT)__mkSmallInteger(13):
  1864                 a13 = ap[12];
  1903 		a13 = ap[12];
  1865             case (INT)__mkSmallInteger(12):
  1904 	    case (INT)__mkSmallInteger(12):
  1866                 a12 = ap[11];
  1905 		a12 = ap[11];
  1867             case (INT)__mkSmallInteger(11):
  1906 	    case (INT)__mkSmallInteger(11):
  1868                 a11 = ap[10];
  1907 		a11 = ap[10];
  1869             case (INT)__mkSmallInteger(10):
  1908 	    case (INT)__mkSmallInteger(10):
  1870                 a10 = ap[9];
  1909 		a10 = ap[9];
  1871             case (INT)__mkSmallInteger(9):
  1910 	    case (INT)__mkSmallInteger(9):
  1872                 a9 = ap[8];
  1911 		a9 = ap[8];
  1873             case (INT)__mkSmallInteger(8):
  1912 	    case (INT)__mkSmallInteger(8):
  1874                 a8 = ap[7];
  1913 		a8 = ap[7];
  1875             case (INT)__mkSmallInteger(7):
  1914 	    case (INT)__mkSmallInteger(7):
  1876                 a7 = ap[6];
  1915 		a7 = ap[6];
  1877             case (INT)__mkSmallInteger(6):
  1916 	    case (INT)__mkSmallInteger(6):
  1878                 a6 = ap[5];
  1917 		a6 = ap[5];
  1879             case (INT)__mkSmallInteger(5):
  1918 	    case (INT)__mkSmallInteger(5):
  1880                 a5 = ap[4];
  1919 		a5 = ap[4];
  1881             case (INT)__mkSmallInteger(4):
  1920 	    case (INT)__mkSmallInteger(4):
  1882                 a4 = ap[3];
  1921 		a4 = ap[3];
  1883             case (INT)__mkSmallInteger(3):
  1922 	    case (INT)__mkSmallInteger(3):
  1884                 a3 = ap[2];
  1923 		a3 = ap[2];
  1885             case (INT)__mkSmallInteger(2):
  1924 	    case (INT)__mkSmallInteger(2):
  1886                 a2 = ap[1];
  1925 		a2 = ap[1];
  1887             case (INT)__mkSmallInteger(1):
  1926 	    case (INT)__mkSmallInteger(1):
  1888                 a1 = ap[0];
  1927 		a1 = ap[0];
  1889             case (INT)__mkSmallInteger(0):
  1928 	    case (INT)__mkSmallInteger(0):
  1890                 break;
  1929 		break;
  1891         }
  1930 	}
  1892     }
  1931     }
  1893 #ifdef NEW_BLOCK_CALL
  1932 #ifdef NEW_BLOCK_CALL
  1894     if (thecode != (OBJFUNC)nil) {
  1933     if (thecode != (OBJFUNC)nil) {
  1895         RETURN ( (*thecode)(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) );
  1934 	RETURN ( (*thecode)(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) );
  1896     }
  1935     }
  1897 # ifdef PASS_ARG_POINTER
  1936 # ifdef PASS_ARG_POINTER
  1898     RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, &a1) );
  1937     RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, &a1) );
  1899 # else
  1938 # else
  1900     RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) );
  1939     RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) );
  1914 %}.
  1953 %}.
  1915     "
  1954     "
  1916      the above code only supports up-to 15 arguments
  1955      the above code only supports up-to 15 arguments
  1917     "
  1956     "
  1918     ^ ArgumentError
  1957     ^ ArgumentError
  1919         raiseRequestWith:self
  1958 	raiseRequestWith:self
  1920         errorString:'only blocks with up-to 15 arguments supported'
  1959 	errorString:'only blocks with up-to 15 arguments supported'
  1921 !
  1960 !
  1922 
  1961 
  1923 valueWithPossibleArguments:argArray
  1962 valueWithPossibleArguments:argArray
  1924     "evaluate the receiver with arguments as required taken from argArray.
  1963     "evaluate the receiver with arguments as required taken from argArray.
  1925      If argArray provides less than the required number of arguments, 
  1964      If argArray provides less than the required number of arguments,
  1926      nil is assumed for any remaining argument.
  1965      nil is assumed for any remaining argument.
  1927      (i.e. argArray may be smaller than the required number).
  1966      (i.e. argArray may be smaller than the required number).
  1928      Only the required number of arguments is taken from argArray or nil;
  1967      Only the required number of arguments is taken from argArray or nil;
  1929      (i.e. argArray may be larger than the required number)."
  1968      (i.e. argArray may be larger than the required number)."
  1930 
  1969 
  1931     |numArgsProvided a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15|
  1970     |numArgsProvided a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15|
  1932 
  1971 
  1933     (argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[
  1972     (argArray notNil and:[(argArray class ~~ Array) and:[argArray isArray not]]) ifTrue:[
  1934         argArray isCollection ifTrue:[
  1973 	argArray isCollection ifTrue:[
  1935             ^ self valueWithArguments:argArray asArray
  1974 	    ^ self valueWithArguments:argArray asArray
  1936         ].
  1975 	].
  1937         ^ self badArgumentArray:argArray
  1976 	^ self badArgumentArray:argArray
  1938     ].
  1977     ].
  1939     numArgsProvided := argArray size.
  1978     numArgsProvided := argArray size.
  1940 %{
  1979 %{
  1941     REGISTER OBJFUNC thecode;
  1980     REGISTER OBJFUNC thecode;
  1942     OBJ home;
  1981     OBJ home;
  1944     OBJ nA;
  1983     OBJ nA;
  1945     int __numArgsProvided = __intVal(numArgsProvided);
  1984     int __numArgsProvided = __intVal(numArgsProvided);
  1946 
  1985 
  1947 #if defined(THIS_CONTEXT)
  1986 #if defined(THIS_CONTEXT)
  1948     if (__ISVALID_ILC_LNO(__pilc))
  1987     if (__ISVALID_ILC_LNO(__pilc))
  1949             __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1988 	    __ContextInstPtr(__thisContext)->c_lineno = __ILC_LNO_AS_OBJ(__pilc);
  1950 #endif
  1989 #endif
  1951     thecode = __BlockInstPtr(self)->b_code;
  1990     thecode = __BlockInstPtr(self)->b_code;
  1952 
  1991 
  1953     nA = __INST(nargs);
  1992     nA = __INST(nargs);
  1954 
  1993 
  1955     if (argArray == nil) {
  1994     if (argArray == nil) {
  1956         ap = 0;  
  1995 	ap = 0;
  1957     } else {
  1996     } else {
  1958         ap = __arrayVal(argArray);   /* nonNil after above test (size is known to be ok) */
  1997 	ap = __arrayVal(argArray);   /* nonNil after above test (size is known to be ok) */
  1959     }
  1998     }
  1960     switch (__numArgsProvided) {
  1999     switch (__numArgsProvided) {
  1961         default:
  2000 	default:
  1962         case 15: a15 = ap[14];
  2001 	case 15: a15 = ap[14];
  1963         case 14: a14 = ap[13];
  2002 	case 14: a14 = ap[13];
  1964         case 13: a13 = ap[12];
  2003 	case 13: a13 = ap[12];
  1965         case 12: a12 = ap[11];
  2004 	case 12: a12 = ap[11];
  1966         case 11: a11 = ap[10];
  2005 	case 11: a11 = ap[10];
  1967         case 10: a10 = ap[9];
  2006 	case 10: a10 = ap[9];
  1968         case 9: a9 = ap[8];
  2007 	case 9: a9 = ap[8];
  1969         case 8: a8 = ap[7];
  2008 	case 8: a8 = ap[7];
  1970         case 7: a7 = ap[6];
  2009 	case 7: a7 = ap[6];
  1971         case 6: a6 = ap[5];
  2010 	case 6: a6 = ap[5];
  1972         case 5: a5 = ap[4];
  2011 	case 5: a5 = ap[4];
  1973         case 4: a4 = ap[3];
  2012 	case 4: a4 = ap[3];
  1974         case 3: a3 = ap[2];
  2013 	case 3: a3 = ap[2];
  1975         case 2: a2 = ap[1];
  2014 	case 2: a2 = ap[1];
  1976         case 1: a1 = ap[0];
  2015 	case 1: a1 = ap[0];
  1977         case 0: ;
  2016 	case 0: ;
  1978     }
  2017     }
  1979 
  2018 
  1980 #ifndef NEW_BLOCK_CALL
  2019 #ifndef NEW_BLOCK_CALL
  1981     home = __BlockInstPtr(self)->b_home;
  2020     home = __BlockInstPtr(self)->b_home;
  1982     if (thecode != (OBJFUNC)nil) {
  2021     if (thecode != (OBJFUNC)nil) {
  1983         /* the most common case (0 args) here (without a switch) */
  2022 	/* the most common case (0 args) here (without a switch) */
  1984 
  2023 
  1985         if (nA == __mkSmallInteger(0)) {
  2024 	if (nA == __mkSmallInteger(0)) {
  1986             RETURN ( (*thecode)(home) );
  2025 	    RETURN ( (*thecode)(home) );
  1987         }
  2026 	}
  1988 
  2027 
  1989         switch ((INT)(nA)) {
  2028 	switch ((INT)(nA)) {
  1990             default:
  2029 	    default:
  1991                 goto error;
  2030 		goto error;
  1992             case (INT)__mkSmallInteger(15):
  2031 	    case (INT)__mkSmallInteger(15):
  1993                 RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) );
  2032 		RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) );
  1994             case (INT)__mkSmallInteger(14):
  2033 	    case (INT)__mkSmallInteger(14):
  1995                 RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) );
  2034 		RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) );
  1996             case (INT)__mkSmallInteger(13):
  2035 	    case (INT)__mkSmallInteger(13):
  1997                 RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) );
  2036 		RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) );
  1998             case (INT)__mkSmallInteger(12):
  2037 	    case (INT)__mkSmallInteger(12):
  1999                 RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) );
  2038 		RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) );
  2000             case (INT)__mkSmallInteger(11):
  2039 	    case (INT)__mkSmallInteger(11):
  2001                 RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) );
  2040 		RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) );
  2002             case (INT)__mkSmallInteger(10):
  2041 	    case (INT)__mkSmallInteger(10):
  2003                 RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) );
  2042 		RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) );
  2004             case (INT)__mkSmallInteger(9):
  2043 	    case (INT)__mkSmallInteger(9):
  2005                 RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9) );
  2044 		RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8, a9) );
  2006             case (INT)__mkSmallInteger(8):
  2045 	    case (INT)__mkSmallInteger(8):
  2007                 RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8) );
  2046 		RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7, a8) );
  2008             case (INT)__mkSmallInteger(7):
  2047 	    case (INT)__mkSmallInteger(7):
  2009                 RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7) );
  2048 		RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6, a7) );
  2010             case (INT)__mkSmallInteger(6):
  2049 	    case (INT)__mkSmallInteger(6):
  2011                 RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6) );
  2050 		RETURN ( (*thecode)(home, a1, a2, a3, a4, a5, a6) );
  2012             case (INT)__mkSmallInteger(5):
  2051 	    case (INT)__mkSmallInteger(5):
  2013                 RETURN ( (*thecode)(home, a1, a2, a3, a4, a5) );
  2052 		RETURN ( (*thecode)(home, a1, a2, a3, a4, a5) );
  2014             case (INT)__mkSmallInteger(4):
  2053 	    case (INT)__mkSmallInteger(4):
  2015                 RETURN ( (*thecode)(home, a1, a2, a3, a4) );
  2054 		RETURN ( (*thecode)(home, a1, a2, a3, a4) );
  2016             case (INT)__mkSmallInteger(3):
  2055 	    case (INT)__mkSmallInteger(3):
  2017                 RETURN ( (*thecode)(home, a1, a2, a3) );
  2056 		RETURN ( (*thecode)(home, a1, a2, a3) );
  2018             case (INT)__mkSmallInteger(2):
  2057 	    case (INT)__mkSmallInteger(2):
  2019                 RETURN ( (*thecode)(home, a1, a2) );
  2058 		RETURN ( (*thecode)(home, a1, a2) );
  2020             case (INT)__mkSmallInteger(1):
  2059 	    case (INT)__mkSmallInteger(1):
  2021                 RETURN ( (*thecode)(home, a1) );
  2060 		RETURN ( (*thecode)(home, a1) );
  2022             case (INT)__mkSmallInteger(0):
  2061 	    case (INT)__mkSmallInteger(0):
  2023                 RETURN ( (*thecode)(home) );
  2062 		RETURN ( (*thecode)(home) );
  2024                 break;
  2063 		break;
  2025         }
  2064 	}
  2026     }
  2065     }
  2027 #endif
  2066 #endif
  2028 
  2067 
  2029 #ifdef NEW_BLOCK_CALL
  2068 #ifdef NEW_BLOCK_CALL
  2030     if (thecode != (OBJFUNC)nil) {
  2069     if (thecode != (OBJFUNC)nil) {
  2031         RETURN ( (*thecode)(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) );
  2070 	RETURN ( (*thecode)(self, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) );
  2032     }
  2071     }
  2033 # ifdef PASS_ARG_POINTER
  2072 # ifdef PASS_ARG_POINTER
  2034     RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, &a1) );
  2073     RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, &a1) );
  2035 # else
  2074 # else
  2036     RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) );
  2075     RETURN ( __interpret(self, __intVal(nA), nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) );
  2050 %}.
  2089 %}.
  2051     "
  2090     "
  2052      the above code only supports up-to 15 arguments
  2091      the above code only supports up-to 15 arguments
  2053     "
  2092     "
  2054     ^ ArgumentError
  2093     ^ ArgumentError
  2055         raiseRequestWith:self
  2094 	raiseRequestWith:self
  2056         errorString:'only blocks with up-to 15 arguments supported'
  2095 	errorString:'only blocks with up-to 15 arguments supported'
  2057 ! !
  2096 ! !
  2058 
  2097 
  2059 !Block methodsFor:'exception handling'!
  2098 !Block methodsFor:'exception handling'!
  2060 
  2099 
  2061 on:aSignalOrSignalSetOrException do:exceptionBlock
  2100 on:aSignalOrSignalSetOrException do:exceptionBlock
  2062     "added for ANSI compatibility; evaluate the receiver,
  2101     "added for ANSI compatibility; evaluate the receiver,
  2063      handling aSignalOrSignalSetOrException. 
  2102      handling aSignalOrSignalSetOrException.
  2064      The 2nd argument, exceptionBlock is evaluated
  2103      The 2nd argument, exceptionBlock is evaluated
  2065      if the signal is raised during evaluation."
  2104      if the signal is raised during evaluation."
  2066 
  2105 
  2067     <context: #return>
  2106     <context: #return>
  2068     <exception: #handle>
  2107     <exception: #handle>
  2070     "/ thisContext markForHandle. -- same as above pragma
  2109     "/ thisContext markForHandle. -- same as above pragma
  2071     ^ self value. "the real logic is in Exception>>doRaise"
  2110     ^ self value. "the real logic is in Exception>>doRaise"
  2072 
  2111 
  2073     "
  2112     "
  2074      [
  2113      [
  2075         1 foo
  2114 	1 foo
  2076      ] on:MessageNotUnderstood do:[:ex | self halt]
  2115      ] on:MessageNotUnderstood do:[:ex | self halt]
  2077 
  2116 
  2078      [
  2117      [
  2079         1 foo
  2118 	1 foo
  2080      ] on:(MessageNotUnderstood , AbortOperationRequest) do:[:ex | self halt]
  2119      ] on:(MessageNotUnderstood , AbortOperationRequest) do:[:ex | self halt]
  2081 
  2120 
  2082      [
  2121      [
  2083         1 foo
  2122 	1 foo
  2084      ] on:SignalSet anySignal do:[:ex| 2 bar. self halt]
  2123      ] on:SignalSet anySignal do:[:ex| 2 bar. self halt]
  2085     "
  2124     "
  2086 
  2125 
  2087     "Modified: / 26.7.1999 / 15:30:48 / stefan"
  2126     "Modified: / 26.7.1999 / 15:30:48 / stefan"
  2088 !
  2127 !
  2089 
  2128 
  2090 on:aSignalOrSignalSetOrException do:exceptionBlock ensure:ensureBlock
  2129 on:aSignalOrSignalSetOrException do:exceptionBlock ensure:ensureBlock
  2091     "added for ANSI compatibility; evaluate the receiver,
  2130     "added for ANSI compatibility; evaluate the receiver,
  2092      handling aSignalOrSignalSetOrException. 
  2131      handling aSignalOrSignalSetOrException.
  2093      The 2nd argument, exceptionBlock is evaluated
  2132      The 2nd argument, exceptionBlock is evaluated
  2094      if the signal is raised during evaluation.
  2133      if the signal is raised during evaluation.
  2095      The 3rd argument, ensureBlock is evaluated in any case - even if the activity
  2134      The 3rd argument, ensureBlock is evaluated in any case - even if the activity
  2096      was unwound due to an unhandled exception."
  2135      was unwound due to an unhandled exception."
  2097 
  2136 
  2109     "
  2148     "
  2110      |e|
  2149      |e|
  2111 
  2150 
  2112      e := 0.
  2151      e := 0.
  2113      [
  2152      [
  2114         1 foo
  2153 	1 foo
  2115      ] on:MessageNotUnderstood 
  2154      ] on:MessageNotUnderstood
  2116      do:[:ex | self halt]
  2155      do:[:ex | self halt]
  2117      ensure:[ e := 1 ].
  2156      ensure:[ e := 1 ].
  2118      self assert:(e == 1).
  2157      self assert:(e == 1).
  2119     "
  2158     "
  2120 
  2159 
  2121     "
  2160     "
  2122      |e|
  2161      |e|
  2123 
  2162 
  2124      e := 0.
  2163      e := 0.
  2125      [
  2164      [
  2126         1 negated
  2165 	1 negated
  2127      ] on:MessageNotUnderstood 
  2166      ] on:MessageNotUnderstood
  2128      do:[:ex | self halt]
  2167      do:[:ex | self halt]
  2129      ensure:[ e := 1 ].
  2168      ensure:[ e := 1 ].
  2130      self assert:(e == 1).
  2169      self assert:(e == 1).
  2131     "
  2170     "
  2132 !
  2171 !
  2133 
  2172 
  2134 on:anExceptionHandler do:exceptionBlock on:anExceptionHandler2 do:anExceptionBlock2
  2173 on:anExceptionHandler do:exceptionBlock on:anExceptionHandler2 do:anExceptionBlock2
  2135     "added for ANSI compatibility; evaluate the receiver,
  2174     "added for ANSI compatibility; evaluate the receiver,
  2136      handling aSignalOrSignalSetOrException. 
  2175      handling aSignalOrSignalSetOrException.
  2137      The 2nd argument, exceptionBlock is evaluated
  2176      The 2nd argument, exceptionBlock is evaluated
  2138      if the signal is raised during evaluation."
  2177      if the signal is raised during evaluation."
  2139 
  2178 
  2140     <context: #return>
  2179     <context: #return>
  2141     <exception: #handle>
  2180     <exception: #handle>
  2143     "/ thisContext markForHandle. -- same as above pragma
  2182     "/ thisContext markForHandle. -- same as above pragma
  2144     ^ self value. "the real logic is in Exception>>doRaise"
  2183     ^ self value. "the real logic is in Exception>>doRaise"
  2145 
  2184 
  2146     "
  2185     "
  2147      [
  2186      [
  2148         1 foo
  2187 	1 foo
  2149      ] on:MessageNotUnderstood do:[:ex | self halt:'Got MessageNotUnderstood'] 
  2188      ] on:MessageNotUnderstood do:[:ex | self halt:'Got MessageNotUnderstood']
  2150        on:Error do:[:ex| self halt:'Got Error']
  2189        on:Error do:[:ex| self halt:'Got Error']
  2151 
  2190 
  2152      [
  2191      [
  2153         1 // 0
  2192 	1 // 0
  2154      ] on:MessageNotUnderstood do:[:ex | self halt:'Got MessageNotUnderstood'] 
  2193      ] on:MessageNotUnderstood do:[:ex | self halt:'Got MessageNotUnderstood']
  2155        on:Error do:[:ex| self halt:'Got Error']
  2194        on:Error do:[:ex| self halt:'Got Error']
  2156     "
  2195     "
  2157 
  2196 
  2158     "Modified: / 26.7.1999 / 15:30:48 / stefan"
  2197     "Modified: / 26.7.1999 / 15:30:48 / stefan"
  2159 !
  2198 !
  2178 
  2217 
  2179     ^ self valueWithWatchDog:[^ nil] afterMilliseconds:aTimeDuration asMilliseconds
  2218     ^ self valueWithWatchDog:[^ nil] afterMilliseconds:aTimeDuration asMilliseconds
  2180 
  2219 
  2181     "
  2220     "
  2182      [
  2221      [
  2183         1 to:15 do:[:round |
  2222 	1 to:15 do:[:round |
  2184             Transcript showCR:round.
  2223 	    Transcript showCR:round.
  2185             Delay waitForMilliseconds:20.
  2224 	    Delay waitForMilliseconds:20.
  2186         ].
  2225 	].
  2187         true
  2226 	true
  2188      ] valueWithTimeout:(TimeDuration seconds:1)      
  2227      ] valueWithTimeout:(TimeDuration seconds:1)
  2189     "
  2228     "
  2190 
  2229 
  2191     "
  2230     "
  2192      [
  2231      [
  2193         1 to:100 do:[:round |
  2232 	1 to:100 do:[:round |
  2194             Transcript showCR:round.
  2233 	    Transcript showCR:round.
  2195             Delay waitForMilliseconds:20.
  2234 	    Delay waitForMilliseconds:20.
  2196         ].
  2235 	].
  2197         true
  2236 	true
  2198      ] valueWithTimeout:(TimeDuration seconds:1)                  
  2237      ] valueWithTimeout:(TimeDuration seconds:1)
  2199     "
  2238     "
  2200 !
  2239 !
  2201 
  2240 
  2202 valueWithWatchDog:exceptionBlock afterMilliseconds:aTimeLimit
  2241 valueWithWatchDog:exceptionBlock afterMilliseconds:aTimeLimit
  2203     "a watchdog on a block's execution. If the block does not finish its
  2242     "a watchdog on a block's execution. If the block does not finish its
  2208     |showStopper me retVal done inError|
  2247     |showStopper me retVal done inError|
  2209 
  2248 
  2210     done := false.
  2249     done := false.
  2211     me := Processor activeProcess.
  2250     me := Processor activeProcess.
  2212 
  2251 
  2213     showStopper := 
  2252     showStopper :=
  2214         [ 
  2253 	[
  2215             done ifFalse:[ 
  2254 	    done ifFalse:[
  2216                 me interruptWith:[
  2255 		me interruptWith:[
  2217                     (Processor activeProcess state ~~ #debug) ifTrue:[
  2256 		    (Processor activeProcess state ~~ #debug) ifTrue:[
  2218                         done ifFalse:[ TimeoutNotification raiseRequest ]
  2257 			done ifFalse:[ TimeoutNotification raiseRequest ]
  2219                     ]
  2258 		    ]
  2220                 ] 
  2259 		]
  2221             ]
  2260 	    ]
  2222         ].
  2261 	].
  2223 
  2262 
  2224     TimeoutNotification handle:[:ex |
  2263     TimeoutNotification handle:[:ex |
  2225         inError ifTrue:[
  2264 	inError ifTrue:[
  2226             ex proceed
  2265 	    ex proceed
  2227         ].
  2266 	].
  2228         retVal := exceptionBlock value.
  2267 	retVal := exceptionBlock value.
  2229     ] do:[
  2268     ] do:[
  2230         NoHandlerError handle:[:ex |
  2269 	NoHandlerError handle:[:ex |
  2231             inError := true.
  2270 	    inError := true.
  2232             ex reject.
  2271 	    ex reject.
  2233         ] do:[
  2272 	] do:[
  2234             [
  2273 	    [
  2235                 Processor 
  2274 		Processor
  2236                     addTimedBlock:showStopper 
  2275 		    addTimedBlock:showStopper
  2237                     for:me 
  2276 		    for:me
  2238                     afterMilliseconds:aTimeLimit.
  2277 		    afterMilliseconds:aTimeLimit.
  2239 
  2278 
  2240                 retVal := self value.
  2279 		retVal := self value.
  2241                 done := true.
  2280 		done := true.
  2242             ] ensure:[ 
  2281 	    ] ensure:[
  2243                 Processor removeTimedBlock:showStopper 
  2282 		Processor removeTimedBlock:showStopper
  2244             ].
  2283 	    ].
  2245         ]
  2284 	]
  2246     ].
  2285     ].
  2247     ^ retVal
  2286     ^ retVal
  2248 
  2287 
  2249     "
  2288     "
  2250      [
  2289      [
  2251         Delay waitForSeconds:5.
  2290 	Delay waitForSeconds:5.
  2252         true
  2291 	true
  2253      ] valueWithWatchDog:[false] afterMilliseconds:2000      
  2292      ] valueWithWatchDog:[false] afterMilliseconds:2000
  2254     "
  2293     "
  2255 
  2294 
  2256     "Modified: / 21-05-2010 / 12:19:57 / sr"
  2295     "Modified: / 21-05-2010 / 12:19:57 / sr"
  2257     "Modified: / 18-01-2011 / 19:24:13 / cg"
  2296     "Modified: / 18-01-2011 / 19:24:13 / cg"
  2258 ! !
  2297 ! !
  2261 
  2300 
  2262 exceptionHandlerFor:anException in:aContext
  2301 exceptionHandlerFor:anException in:aContext
  2263     "answer the exceptionHandler (the Error or signal) for anException from aContext."
  2302     "answer the exceptionHandler (the Error or signal) for anException from aContext."
  2264 
  2303 
  2265     aContext selector == #on:do:on:do: ifTrue:[
  2304     aContext selector == #on:do:on:do: ifTrue:[
  2266         |exceptionCreator exceptionHandlerInContext|
  2305 	|exceptionCreator exceptionHandlerInContext|
  2267 
  2306 
  2268         exceptionCreator := anException creator.
  2307 	exceptionCreator := anException creator.
  2269         exceptionHandlerInContext := aContext argAt:1.
  2308 	exceptionHandlerInContext := aContext argAt:1.
  2270         exceptionHandlerInContext isExceptionHandler ifFalse:[
  2309 	exceptionHandlerInContext isExceptionHandler ifFalse:[
  2271             exceptionHandlerInContext isNil ifTrue:[
  2310 	    exceptionHandlerInContext isNil ifTrue:[
  2272                 'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR.
  2311 		'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR.
  2273             ] ifFalse:[
  2312 	    ] ifFalse:[
  2274                 (exceptionHandlerInContext isBehavior 
  2313 		(exceptionHandlerInContext isBehavior
  2275                 and:[exceptionHandlerInContext isLoaded not]) ifTrue:[
  2314 		and:[exceptionHandlerInContext isLoaded not]) ifTrue:[
  2276                     "If the exception class is still autoloaded,
  2315 		    "If the exception class is still autoloaded,
  2277                      it does not accept our exception. Raising the exception would load the class"
  2316 		     it does not accept our exception. Raising the exception would load the class"
  2278                     ^ nil
  2317 		    ^ nil
  2279                 ] ifFalse:[
  2318 		] ifFalse:[
  2280                     'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR.
  2319 		    'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR.
  2281                 ]
  2320 		]
  2282             ].
  2321 	    ].
  2283             aContext fullPrintString errorPrintCR.
  2322 	    aContext fullPrintString errorPrintCR.
  2284             self breakPoint:#cg.
  2323 	    self breakPoint:#cg.
  2285             ^ nil.
  2324 	    ^ nil.
  2286         ].
  2325 	].
  2287         (exceptionHandlerInContext accepts:exceptionCreator) ifTrue:[
  2326 	(exceptionHandlerInContext accepts:exceptionCreator) ifTrue:[
  2288             ^ exceptionHandlerInContext.
  2327 	    ^ exceptionHandlerInContext.
  2289         ].
  2328 	].
  2290 
  2329 
  2291         exceptionHandlerInContext := aContext argAt:3.
  2330 	exceptionHandlerInContext := aContext argAt:3.
  2292         exceptionHandlerInContext isExceptionHandler ifFalse:[
  2331 	exceptionHandlerInContext isExceptionHandler ifFalse:[
  2293             exceptionHandlerInContext isNil ifTrue:[
  2332 	    exceptionHandlerInContext isNil ifTrue:[
  2294                 'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR.
  2333 		'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR.
  2295             ] ifFalse:[
  2334 	    ] ifFalse:[
  2296                 (exceptionHandlerInContext isBehavior 
  2335 		(exceptionHandlerInContext isBehavior
  2297                 and:[exceptionHandlerInContext isLoaded not]) ifTrue:[
  2336 		and:[exceptionHandlerInContext isLoaded not]) ifTrue:[
  2298                     "If the exception class is still autoloaded,
  2337 		    "If the exception class is still autoloaded,
  2299                      it does not accept our exception. Raising the exception would load the class"
  2338 		     it does not accept our exception. Raising the exception would load the class"
  2300                     ^ nil
  2339 		    ^ nil
  2301                 ] ifFalse:[
  2340 		] ifFalse:[
  2302                     'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR.
  2341 		    'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR.
  2303                 ]
  2342 		]
  2304             ].
  2343 	    ].
  2305             aContext fullPrintString errorPrintCR.
  2344 	    aContext fullPrintString errorPrintCR.
  2306             self breakPoint:#cg.
  2345 	    self breakPoint:#cg.
  2307             ^ nil.
  2346 	    ^ nil.
  2308         ].
  2347 	].
  2309         (exceptionHandlerInContext accepts:exceptionCreator) ifTrue:[
  2348 	(exceptionHandlerInContext accepts:exceptionCreator) ifTrue:[
  2310             ^ exceptionHandlerInContext.
  2349 	    ^ exceptionHandlerInContext.
  2311         ].
  2350 	].
  2312         ^ nil.
  2351 	^ nil.
  2313     ].
  2352     ].
  2314 
  2353 
  2315     "aContext selector must be #on:do: , #on:do:ensure: or #valueWithExceptionHandler:"
  2354     "aContext selector must be #on:do: , #on:do:ensure: or #valueWithExceptionHandler:"
  2316     ^ aContext argAt:1.
  2355     ^ aContext argAt:1.
  2317 !
  2356 !
  2325 
  2364 
  2326     selector := theContext selector.
  2365     selector := theContext selector.
  2327 
  2366 
  2328     (selector == #on:do:
  2367     (selector == #on:do:
  2329     or:[ selector == #on:do:ensure: ]) ifTrue:[
  2368     or:[ selector == #on:do:ensure: ]) ifTrue:[
  2330         exceptionHandlerInContext := theContext argAt:1.
  2369 	exceptionHandlerInContext := theContext argAt:1.
  2331         exceptionHandlerInContext isExceptionHandler ifFalse:[
  2370 	exceptionHandlerInContext isExceptionHandler ifFalse:[
  2332             exceptionHandlerInContext isNil ifTrue:[
  2371 	    exceptionHandlerInContext isNil ifTrue:[
  2333                 'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR.
  2372 		'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR.
  2334             ] ifFalse:[(exceptionHandlerInContext isBehavior 
  2373 	    ] ifFalse:[(exceptionHandlerInContext isBehavior
  2335                         and:[exceptionHandlerInContext isLoaded not]) ifTrue:[
  2374 			and:[exceptionHandlerInContext isLoaded not]) ifTrue:[
  2336                 "If the exception class is still autoloaded,
  2375 		"If the exception class is still autoloaded,
  2337                  it does not accept our exception. Raising the exception would load the class"
  2376 		 it does not accept our exception. Raising the exception would load the class"
  2338                 ^ nil
  2377 		^ nil
  2339             ] ifFalse:[
  2378 	    ] ifFalse:[
  2340                 'Block [warning]: non-ExceptionHandler in on:do:-context' errorPrintCR.
  2379 		'Block [warning]: non-ExceptionHandler in on:do:-context' errorPrintCR.
  2341             ]].
  2380 	    ]].
  2342             theContext fullPrint.
  2381 	    theContext fullPrint.
  2343             ^ nil.
  2382 	    ^ nil.
  2344         ].
  2383 	].
  2345         (exceptionHandlerInContext == exceptionHandler 
  2384 	(exceptionHandlerInContext == exceptionHandler
  2346          or:[exceptionHandlerInContext accepts:exceptionHandler]) ifTrue:[
  2385 	 or:[exceptionHandlerInContext accepts:exceptionHandler]) ifTrue:[
  2347             ^ (theContext argAt:2) ? [nil].
  2386 	    ^ (theContext argAt:2) ? [nil].
  2348         ].
  2387 	].
  2349         ^ nil
  2388 	^ nil
  2350     ].
  2389     ].
  2351 
  2390 
  2352     selector == #on:do:on:do: ifTrue:[
  2391     selector == #on:do:on:do: ifTrue:[
  2353         exceptionHandlerInContext := theContext argAt:1.
  2392 	exceptionHandlerInContext := theContext argAt:1.
  2354         exceptionHandlerInContext isExceptionHandler ifFalse:[
  2393 	exceptionHandlerInContext isExceptionHandler ifFalse:[
  2355             exceptionHandlerInContext isNil ifTrue:[
  2394 	    exceptionHandlerInContext isNil ifTrue:[
  2356                 'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR.
  2395 		'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR.
  2357             ] ifFalse:[(exceptionHandlerInContext isBehavior 
  2396 	    ] ifFalse:[(exceptionHandlerInContext isBehavior
  2358                         and:[exceptionHandlerInContext isLoaded not]) ifTrue:[
  2397 			and:[exceptionHandlerInContext isLoaded not]) ifTrue:[
  2359                 "If the exception class is still autoloaded,
  2398 		"If the exception class is still autoloaded,
  2360                  it does not accept our exception. Raising the exception would load the class"
  2399 		 it does not accept our exception. Raising the exception would load the class"
  2361                 ^ nil
  2400 		^ nil
  2362             ] ifFalse:[
  2401 	    ] ifFalse:[
  2363                 'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR.
  2402 		'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR.
  2364             ]].
  2403 	    ]].
  2365             theContext fullPrint.
  2404 	    theContext fullPrint.
  2366             ^ nil.
  2405 	    ^ nil.
  2367         ].
  2406 	].
  2368         (exceptionHandlerInContext == exceptionHandler 
  2407 	(exceptionHandlerInContext == exceptionHandler
  2369          or:[exceptionHandlerInContext accepts:exceptionHandler]) ifTrue:[
  2408 	 or:[exceptionHandlerInContext accepts:exceptionHandler]) ifTrue:[
  2370             ^ (theContext argAt:2) ? [nil].
  2409 	    ^ (theContext argAt:2) ? [nil].
  2371         ].
  2410 	].
  2372 
  2411 
  2373         exceptionHandlerInContext := theContext argAt:3.
  2412 	exceptionHandlerInContext := theContext argAt:3.
  2374         exceptionHandlerInContext isExceptionHandler ifFalse:[
  2413 	exceptionHandlerInContext isExceptionHandler ifFalse:[
  2375             exceptionHandlerInContext isNil ifTrue:[
  2414 	    exceptionHandlerInContext isNil ifTrue:[
  2376                 'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR.
  2415 		'Block [warning]: nil ExceptionHandler in on:do:on:do:-context' errorPrintCR.
  2377             ] ifFalse:[(exceptionHandlerInContext isBehavior 
  2416 	    ] ifFalse:[(exceptionHandlerInContext isBehavior
  2378                         and:[exceptionHandlerInContext isLoaded not]) ifTrue:[
  2417 			and:[exceptionHandlerInContext isLoaded not]) ifTrue:[
  2379                 "If the exception class is still autoloaded,
  2418 		"If the exception class is still autoloaded,
  2380                  it does not accept our exception. Raising the exception would load the class"
  2419 		 it does not accept our exception. Raising the exception would load the class"
  2381                 ^ nil
  2420 		^ nil
  2382             ] ifFalse:[
  2421 	    ] ifFalse:[
  2383                 'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR.
  2422 		'Block [warning]: non-ExceptionHandler in on:do:on:do:-context' errorPrintCR.
  2384             ]].
  2423 	    ]].
  2385             theContext fullPrint.
  2424 	    theContext fullPrint.
  2386             ^ nil.
  2425 	    ^ nil.
  2387         ].
  2426 	].
  2388         (exceptionHandlerInContext == exceptionHandler 
  2427 	(exceptionHandlerInContext == exceptionHandler
  2389          or:[exceptionHandlerInContext accepts:exceptionHandler]) ifTrue:[
  2428 	 or:[exceptionHandlerInContext accepts:exceptionHandler]) ifTrue:[
  2390             ^ (theContext argAt:4) ? [nil].
  2429 	    ^ (theContext argAt:4) ? [nil].
  2391         ].
  2430 	].
  2392         ^ nil
  2431 	^ nil
  2393     ].
  2432     ].
  2394 
  2433 
  2395     selector == #valueWithExceptionHandler: ifTrue:[
  2434     selector == #valueWithExceptionHandler: ifTrue:[
  2396         ^ (theContext argAt:1) handlerForSignal:exceptionHandler.
  2435 	^ (theContext argAt:1) handlerForSignal:exceptionHandler.
  2397     ].
  2436     ].
  2398 
  2437 
  2399     "/ mhmh - should not arrive here
  2438     "/ mhmh - should not arrive here
  2400     ^ nil
  2439     ^ nil
  2401 
  2440 
  2454      [n printCR] doWhile:[ (n := n + 1) <= 5 ]
  2493      [n printCR] doWhile:[ (n := n + 1) <= 5 ]
  2455     "
  2494     "
  2456 !
  2495 !
  2457 
  2496 
  2458 loop
  2497 loop
  2459     "repeat the receiver forever 
  2498     "repeat the receiver forever
  2460      (the receiver block should contain a return somewhere).
  2499      (the receiver block should contain a return somewhere).
  2461      The implementation below was inspired by a corresponding Self method."
  2500      The implementation below was inspired by a corresponding Self method."
  2462 
  2501 
  2463     self value.
  2502     self value.
  2464     thisContext restart
  2503     thisContext restart
  2466     "
  2505     "
  2467      |n|
  2506      |n|
  2468 
  2507 
  2469      n := 1.
  2508      n := 1.
  2470      [
  2509      [
  2471         n printCR.
  2510 	n printCR.
  2472         n >= 10 ifTrue:[^ nil].
  2511 	n >= 10 ifTrue:[^ nil].
  2473         n := n + 1
  2512 	n := n + 1
  2474      ] loop
  2513      ] loop
  2475     "
  2514     "
  2476 
  2515 
  2477     "Modified: 18.4.1996 / 13:50:40 / cg"
  2516     "Modified: 18.4.1996 / 13:50:40 / cg"
  2478 !
  2517 !
  2479 
  2518 
  2480 loopWithExit
  2519 loopWithExit
  2481     "the receiver must be a block of one argument.  It is evaluated in a loop forever, 
  2520     "the receiver must be a block of one argument.  It is evaluated in a loop forever,
  2482      and is passed a block, which, if sent a value:-message, will exit the receiver block, 
  2521      and is passed a block, which, if sent a value:-message, will exit the receiver block,
  2483      returning the parameter of the value:-message. Used for loops with exit in the middle.
  2522      returning the parameter of the value:-message. Used for loops with exit in the middle.
  2484      Inspired by a corresponding Self method."
  2523      Inspired by a corresponding Self method."
  2485 
  2524 
  2486     |exitBlock|
  2525     |exitBlock|
  2487 
  2526 
  2490 
  2529 
  2491     "
  2530     "
  2492      |i|
  2531      |i|
  2493      i := 1.
  2532      i := 1.
  2494      [:exit |
  2533      [:exit |
  2495         Transcript showCR:i.
  2534 	Transcript showCR:i.
  2496         i == 5 ifTrue:[exit value:'thats it'].
  2535 	i == 5 ifTrue:[exit value:'thats it'].
  2497         i := i + 1
  2536 	i := i + 1
  2498      ] loopWithExit
  2537      ] loopWithExit
  2499     "
  2538     "
  2500 !
  2539 !
  2501 
  2540 
  2502 repeat
  2541 repeat
  2508 
  2547 
  2509     "Modified: 18.4.1996 / 13:50:55 / cg"
  2548     "Modified: 18.4.1996 / 13:50:55 / cg"
  2510 !
  2549 !
  2511 
  2550 
  2512 repeat:n
  2551 repeat:n
  2513     "repeat the receiver n times - similar to timesRepeat, but optionally passes the 
  2552     "repeat the receiver n times - similar to timesRepeat, but optionally passes the
  2514      loop counter as argument"
  2553      loop counter as argument"
  2515 
  2554 
  2516     self numArgs == 0 ifTrue:[
  2555     self numArgs == 0 ifTrue:[
  2517         n timesRepeat:self
  2556 	n timesRepeat:self
  2518     ] ifFalse:[
  2557     ] ifFalse:[
  2519         1 to:n do:self
  2558 	1 to:n do:self
  2520     ].
  2559     ].
  2521 
  2560 
  2522     "
  2561     "
  2523       [ Transcript showCR:'hello' ] repeat:3
  2562       [ Transcript showCR:'hello' ] repeat:3
  2524       [:i | Transcript showCR:'hello',i printString ] repeat:3
  2563       [:i | Transcript showCR:'hello',i printString ] repeat:3
  2525     "
  2564     "
  2526 !
  2565 !
  2527 
  2566 
  2528 valueWithExit
  2567 valueWithExit
  2529     "the receiver must be a block of one argument.  It is evaluated, and is passed a block,
  2568     "the receiver must be a block of one argument.  It is evaluated, and is passed a block,
  2530      which, if sent a value:-message, will exit the receiver block, returning the parameter of the 
  2569      which, if sent a value:-message, will exit the receiver block, returning the parameter of the
  2531      value:-message. Used for premature returns to the caller.
  2570      value:-message. Used for premature returns to the caller.
  2532      Taken from a manchester goody (a similar construct also appears in Self)."
  2571      Taken from a manchester goody (a similar construct also appears in Self)."
  2533 
  2572 
  2534     ^ self value:[:exitValue | ^exitValue]
  2573     ^ self value:[:exitValue | ^exitValue]
  2535 
  2574 
  2556     restartAction := [ myContext unwindAndRestart ].
  2595     restartAction := [ myContext unwindAndRestart ].
  2557     ^ self value:restartAction.
  2596     ^ self value:restartAction.
  2558 
  2597 
  2559     "
  2598     "
  2560      [:restart |
  2599      [:restart |
  2561         (self confirm:'try again ?') ifTrue:[
  2600 	(self confirm:'try again ?') ifTrue:[
  2562             restart value.
  2601 	    restart value.
  2563         ]
  2602 	]
  2564      ] valueWithRestart
  2603      ] valueWithRestart
  2565     "
  2604     "
  2566 
  2605 
  2567     "Modified: / 25.1.2000 / 21:47:50 / cg"
  2606     "Modified: / 25.1.2000 / 21:47:50 / cg"
  2568 !
  2607 !
  2577     restartAction := [ myContext unwindAndRestart ].
  2616     restartAction := [ myContext unwindAndRestart ].
  2578     ^ self value:restartAction value:[:exitValue | ^exitValue].
  2617     ^ self value:restartAction value:[:exitValue | ^exitValue].
  2579 
  2618 
  2580     "
  2619     "
  2581      [:restart :exit |
  2620      [:restart :exit |
  2582         |i|
  2621 	|i|
  2583 
  2622 
  2584         i := 0.
  2623 	i := 0.
  2585         [
  2624 	[
  2586             i := i + 1.
  2625 	    i := i + 1.
  2587             (self confirm:('i is ',i printString,'; start over ?')) ifTrue:[
  2626 	    (self confirm:('i is ',i printString,'; start over ?')) ifTrue:[
  2588                 restart value.
  2627 		restart value.
  2589             ].
  2628 	    ].
  2590             (self confirm:'enough ?') ifTrue:[
  2629 	    (self confirm:'enough ?') ifTrue:[
  2591                 exit value:nil.
  2630 		exit value:nil.
  2592             ].
  2631 	    ].
  2593         ] loop
  2632 	] loop
  2594      ] valueWithRestartAndExit
  2633      ] valueWithRestartAndExit
  2595     "
  2634     "
  2596 !
  2635 !
  2597 
  2636 
  2598 whileFalse
  2637 whileFalse
  2611     "
  2650     "
  2612 !
  2651 !
  2613 
  2652 
  2614 whileFalse:aBlock
  2653 whileFalse:aBlock
  2615     "evaluate the argument, aBlock while the receiver evaluates to false.
  2654     "evaluate the argument, aBlock while the receiver evaluates to false.
  2616      - usually open coded by compilers, but needed here for #perform 
  2655      - usually open coded by compilers, but needed here for #perform
  2617        and expression evaluation."
  2656        and expression evaluation."
  2618 
  2657 
  2619     "this implementation is for purists ... :-)"
  2658     "this implementation is for purists ... :-)"
  2620 
  2659 
  2621     self value ifTrue:[^ nil].
  2660     self value ifTrue:[^ nil].
  2625     "
  2664     "
  2626      |n|
  2665      |n|
  2627 
  2666 
  2628      n := 1.
  2667      n := 1.
  2629      [n > 10] whileFalse:[
  2668      [n > 10] whileFalse:[
  2630         n printCR.
  2669 	n printCR.
  2631         n := n + 1
  2670 	n := n + 1
  2632      ]
  2671      ]
  2633     "
  2672     "
  2634 !
  2673 !
  2635 
  2674 
  2636 whileTrue
  2675 whileTrue
  2649     "
  2688     "
  2650 !
  2689 !
  2651 
  2690 
  2652 whileTrue:aBlock
  2691 whileTrue:aBlock
  2653     "evaluate the argument, aBlock while the receiver evaluates to true.
  2692     "evaluate the argument, aBlock while the receiver evaluates to true.
  2654      - usually open coded by compilers, but needed here for #perform 
  2693      - usually open coded by compilers, but needed here for #perform
  2655        and expression evaluation."
  2694        and expression evaluation."
  2656 
  2695 
  2657     "this implementation is for purists ... :-)"
  2696     "this implementation is for purists ... :-)"
  2658 
  2697 
  2659     self value ifFalse:[^ nil].
  2698     self value ifFalse:[^ nil].
  2663     "
  2702     "
  2664      |n|
  2703      |n|
  2665 
  2704 
  2666      n := 1.
  2705      n := 1.
  2667      [n <= 10] whileTrue:[
  2706      [n <= 10] whileTrue:[
  2668         n printCR.
  2707 	n printCR.
  2669         n := n + 1
  2708 	n := n + 1
  2670      ]
  2709      ]
  2671     "
  2710     "
  2672 ! !
  2711 ! !
  2673 
  2712 
  2674 !Block methodsFor:'parallel evaluation'!
  2713 !Block methodsFor:'parallel evaluation'!
  2675 
  2714 
  2676 futureValue
  2715 futureValue
  2677     "Fork a synchronised evaluation of myself. 
  2716     "Fork a synchronised evaluation of myself.
  2678      Starts the evaluation in parallel now, but synchronizes
  2717      Starts the evaluation in parallel now, but synchronizes
  2679      any access to wait until the result is computed."
  2718      any access to wait until the result is computed."
  2680 
  2719 
  2681     ^ Future new block:self
  2720     ^ Future new block:self
  2682 !
  2721 !
  2683 
  2722 
  2684 futureValue:aValue 
  2723 futureValue:aValue
  2685     "Fork a synchronised evaluation of myself. 
  2724     "Fork a synchronised evaluation of myself.
  2686      Starts the evaluation in parallel now, but synchronizes
  2725      Starts the evaluation in parallel now, but synchronizes
  2687      any access to wait until the result is computed."
  2726      any access to wait until the result is computed."
  2688     
  2727 
  2689     ^ Future new block:self value:aValue
  2728     ^ Future new block:self value:aValue
  2690 !
  2729 !
  2691 
  2730 
  2692 futureValue:aValue value:anotherValue 
  2731 futureValue:aValue value:anotherValue
  2693     "Fork a synchronised evaluation of myself. 
  2732     "Fork a synchronised evaluation of myself.
  2694      Starts the evaluation in parallel now, but synchronizes
  2733      Starts the evaluation in parallel now, but synchronizes
  2695      any access to wait until the result is computed."
  2734      any access to wait until the result is computed."
  2696     
  2735 
  2697     ^ Future new 
  2736     ^ Future new
  2698         block:self
  2737 	block:self
  2699         value:aValue
  2738 	value:aValue
  2700         value:anotherValue
  2739 	value:anotherValue
  2701 !
  2740 !
  2702 
  2741 
  2703 futureValue:aValue value:anotherValue value:bValue 
  2742 futureValue:aValue value:anotherValue value:bValue
  2704     "Fork a synchronised evaluation of myself. 
  2743     "Fork a synchronised evaluation of myself.
  2705      Starts the evaluation in parallel now, but synchronizes
  2744      Starts the evaluation in parallel now, but synchronizes
  2706      any access to wait until the result is computed."
  2745      any access to wait until the result is computed."
  2707     
  2746 
  2708     ^ Future new 
  2747     ^ Future new
  2709         block:self
  2748 	block:self
  2710         value:aValue
  2749 	value:aValue
  2711         value:anotherValue
  2750 	value:anotherValue
  2712         value:bValue
  2751 	value:bValue
  2713 !
  2752 !
  2714 
  2753 
  2715 futureValueWithArguments:anArray 
  2754 futureValueWithArguments:anArray
  2716     "Fork a synchronised evaluation of myself. 
  2755     "Fork a synchronised evaluation of myself.
  2717      Starts the evaluation in parallel now, but synchronizes
  2756      Starts the evaluation in parallel now, but synchronizes
  2718      any access to wait until the result is computed."
  2757      any access to wait until the result is computed."
  2719     
  2758 
  2720     ^ Future new 
  2759     ^ Future new
  2721         block:self 
  2760 	block:self
  2722         valueWithArguments:anArray
  2761 	valueWithArguments:anArray
  2723 
  2762 
  2724     "Modified (format): / 04-10-2011 / 14:55:40 / cg"
  2763     "Modified (format): / 04-10-2011 / 14:55:40 / cg"
  2725 !
  2764 !
  2726 
  2765 
  2727 lazyValue
  2766 lazyValue
  2728     "Fork a synchronised evaluation of myself. Only starts
  2767     "Fork a synchronised evaluation of myself. Only starts
  2729      the evaluation when the result is requested."
  2768      the evaluation when the result is requested."
  2730     
  2769 
  2731     ^ Lazy new block:self
  2770     ^ Lazy new block:self
  2732 !
  2771 !
  2733 
  2772 
  2734 lazyValue:aValue 
  2773 lazyValue:aValue
  2735     "Fork a synchronised evaluation of myself. Only starts
  2774     "Fork a synchronised evaluation of myself. Only starts
  2736      the evaluation when the result is requested."
  2775      the evaluation when the result is requested."
  2737     
  2776 
  2738     ^ Lazy new block:self value:aValue
  2777     ^ Lazy new block:self value:aValue
  2739 !
  2778 !
  2740 
  2779 
  2741 lazyValue:aValue value:anotherValue 
  2780 lazyValue:aValue value:anotherValue
  2742     "Fork a synchronised evaluation of myself. Only starts
  2781     "Fork a synchronised evaluation of myself. Only starts
  2743      the evaluation when the result is requested."
  2782      the evaluation when the result is requested."
  2744     
  2783 
  2745     ^ Lazy new 
  2784     ^ Lazy new
  2746         block:self
  2785 	block:self
  2747         value:aValue
  2786 	value:aValue
  2748         value:anotherValue
  2787 	value:anotherValue
  2749 !
  2788 !
  2750 
  2789 
  2751 lazyValue:aValue value:anotherValue value:bValue 
  2790 lazyValue:aValue value:anotherValue value:bValue
  2752     "Fork a synchronised evaluation of myself. Only starts
  2791     "Fork a synchronised evaluation of myself. Only starts
  2753      the evaluation when the result is requested."
  2792      the evaluation when the result is requested."
  2754     
  2793 
  2755     ^ Lazy new 
  2794     ^ Lazy new
  2756         block:self
  2795 	block:self
  2757         value:aValue
  2796 	value:aValue
  2758         value:anotherValue
  2797 	value:anotherValue
  2759         value:bValue
  2798 	value:bValue
  2760 !
  2799 !
  2761 
  2800 
  2762 lazyValueWithArguments:anArray 
  2801 lazyValueWithArguments:anArray
  2763     "Fork a synchronised evaluation of myself. Only starts
  2802     "Fork a synchronised evaluation of myself. Only starts
  2764      the evaluation when the result is requested."
  2803      the evaluation when the result is requested."
  2765     
  2804 
  2766     ^ Lazy new block:self valueWithArguments:anArray
  2805     ^ Lazy new block:self valueWithArguments:anArray
  2767 ! !
  2806 ! !
  2768 
  2807 
  2769 !Block methodsFor:'printing & storing'!
  2808 !Block methodsFor:'printing & storing'!
  2770 
  2809 
  2771 printBlockBracketsOn:aStream
  2810 printBlockBracketsOn:aStream
  2772     aStream nextPutAll:'[]'. 
  2811     aStream nextPutAll:'[]'.
  2773 !
  2812 !
  2774 
  2813 
  2775 printOn:aStream
  2814 printOn:aStream
  2776     "append a a printed representation of the block to aStream"
  2815     "append a a printed representation of the block to aStream"
  2777 
  2816 
  2778     |h sel methodClass|
  2817     |h sel methodClass|
  2779 
  2818 
  2780     "cheap blocks have no home context, but a method instead"
  2819     "cheap blocks have no home context, but a method instead"
  2781 
  2820 
  2782     (home isNil or:[home isContext not]) ifTrue:[
  2821     (home isNil or:[home isContext not]) ifTrue:[
  2783         aStream nextPutAll:'[] in '.
  2822 	aStream nextPutAll:'[] in '.
  2784 
  2823 
  2785         "
  2824 	"
  2786          currently, some cheap blocks don't know where they have been created
  2825 	 currently, some cheap blocks don't know where they have been created
  2787         "
  2826 	"
  2788         aStream nextPutAll:' ??? (optimized)'.
  2827 	aStream nextPutAll:' ??? (optimized)'.
  2789         ^ self
  2828 	^ self
  2790     ].
  2829     ].
  2791 
  2830 
  2792     "a full blown block (with home, but without method)"
  2831     "a full blown block (with home, but without method)"
  2793     self printBlockBracketsOn:aStream.
  2832     self printBlockBracketsOn:aStream.
  2794     aStream nextPutAll:' in '. 
  2833     aStream nextPutAll:' in '.
  2795     h := self methodHome.
  2834     h := self methodHome.
  2796     sel := h selector.
  2835     sel := h selector.
  2797 "/ old:
  2836 "/ old:
  2798 "/    home receiver class name printOn:aStream.
  2837 "/    home receiver class name printOn:aStream.
  2799 "/ new:
  2838 "/ new:
  2800 "/    (h searchClass whichClassImplements:sel) name printOn:aStream.
  2839 "/    (h searchClass whichClassImplements:sel) name printOn:aStream.
  2801     methodClass := h methodClass.
  2840     methodClass := h methodClass.
  2802     methodClass isNil ifTrue:[
  2841     methodClass isNil ifTrue:[
  2803         'UnboundMethod' printOn:aStream.
  2842 	'UnboundMethod' printOn:aStream.
  2804     ] ifFalse:[
  2843     ] ifFalse:[
  2805         methodClass name printOn:aStream.
  2844 	methodClass name printOn:aStream.
  2806     ].
  2845     ].
  2807     aStream nextPutAll:'>>'.
  2846     aStream nextPutAll:'>>'.
  2808     sel printOn:aStream.
  2847     sel printOn:aStream.
  2809 
  2848 
  2810 "/
  2849 "/
  2813 "/    homeClass notNil ifTrue:[
  2852 "/    homeClass notNil ifTrue:[
  2814 "/      homeClass name printOn:aStream.
  2853 "/      homeClass name printOn:aStream.
  2815 "/      aStream space.
  2854 "/      aStream space.
  2816 "/      (homeClass selectorForMethod:home) printOn:aStream
  2855 "/      (homeClass selectorForMethod:home) printOn:aStream
  2817 "/    ] ifFalse:[
  2856 "/    ] ifFalse:[
  2818 "/      aStream nextPutAll:' ???' 
  2857 "/      aStream nextPutAll:' ???'
  2819 "/    ]
  2858 "/    ]
  2820 "/
  2859 "/
  2821 !
  2860 !
  2822 
  2861 
  2823 storeOn:aStream
  2862 storeOn:aStream
  2844     "Modified: 23.4.1996 / 16:05:30 / cg"
  2883     "Modified: 23.4.1996 / 16:05:30 / cg"
  2845     "Modified: 24.6.1996 / 12:37:37 / stefan"
  2884     "Modified: 24.6.1996 / 12:37:37 / stefan"
  2846     "Created: 13.4.1997 / 00:00:57 / cg"
  2885     "Created: 13.4.1997 / 00:00:57 / cg"
  2847 !
  2886 !
  2848 
  2887 
  2849 initialPC 
  2888 initialPC
  2850     "return the initial pc for evaluation."
  2889     "return the initial pc for evaluation."
  2851 
  2890 
  2852     ^ initialPC
  2891     ^ initialPC
  2853 !
  2892 !
  2854 
  2893 
  2855 initialPC:initial 
  2894 initialPC:initial
  2856     "set the initial pc for evaluation.
  2895     "set the initial pc for evaluation.
  2857      DANGER ALERT: this interface is for the compiler only."
  2896      DANGER ALERT: this interface is for the compiler only."
  2858 
  2897 
  2859     initialPC := initial
  2898     initialPC := initial
  2860 
  2899 
  2872 
  2911 
  2873 setHome:aContext
  2912 setHome:aContext
  2874     home := aContext
  2913     home := aContext
  2875 !
  2914 !
  2876 
  2915 
  2877 source 
  2916 source
  2878     |m|
  2917     |m|
  2879 
  2918 
  2880     sourcePos isString ifTrue:[    "/ misuses the sourcePosition slot
  2919     sourcePos isString ifTrue:[    "/ misuses the sourcePosition slot
  2881         ^ sourcePos
  2920 	^ sourcePos
  2882     ].
  2921     ].
  2883     m := self method.
  2922     m := self method.
  2884     m notNil ifTrue:[
  2923     m notNil ifTrue:[
  2885         ^ m source
  2924 	^ m source
  2886     ].
  2925     ].
  2887     ^ nil
  2926     ^ nil
  2888 !
  2927 !
  2889 
  2928 
  2890 source:aString 
  2929 source:aString
  2891     "set the source - only to be used, if the block is not contained in a method.
  2930     "set the source - only to be used, if the block is not contained in a method.
  2892      This interface is for knowledgable users only."
  2931      This interface is for knowledgable users only."
  2893 
  2932 
  2894     sourcePos := aString  "/ misuse the sourcePosition slot
  2933     sourcePos := aString  "/ misuse the sourcePosition slot
  2895 !
  2934 !
  2896 
  2935 
  2897 sourcePosition:position 
  2936 sourcePosition:position
  2898     "set the position of the source within my method.
  2937     "set the position of the source within my method.
  2899      This interface is for the compiler only."
  2938      This interface is for the compiler only."
  2900 
  2939 
  2901     sourcePos := position
  2940     sourcePos := position
  2902 
  2941 
  2946 
  2985 
  2947     ^ (self newProcess priority:priority) resume
  2986     ^ (self newProcess priority:priority) resume
  2948 !
  2987 !
  2949 
  2988 
  2950 forkNamed:aString
  2989 forkNamed:aString
  2951     "create a new process, give it a name and let it start 
  2990     "create a new process, give it a name and let it start
  2952      executing the receiver at the current priority."
  2991      executing the receiver at the current priority."
  2953 
  2992 
  2954     |newProcess|
  2993     |newProcess|
  2955 
  2994 
  2956     newProcess := self newProcess. 
  2995     newProcess := self newProcess.
  2957     newProcess name:aString.
  2996     newProcess name:aString.
  2958     newProcess resume.
  2997     newProcess resume.
  2959     ^ newProcess.
  2998     ^ newProcess.
  2960 !
  2999 !
  2961 
  3000 
  3040 
  3079 
  3041     |selector|
  3080     |selector|
  3042 
  3081 
  3043     selector := aContext selector.
  3082     selector := aContext selector.
  3044     selector == #'value:onUnwindDo:' ifTrue:[
  3083     selector == #'value:onUnwindDo:' ifTrue:[
  3045         ^ aContext argAt:2
  3084 	^ aContext argAt:2
  3046     ].
  3085     ].
  3047     selector == #'on:do:ensure:' ifTrue:[
  3086     selector == #'on:do:ensure:' ifTrue:[
  3048         ^ aContext argAt:3
  3087 	^ aContext argAt:3
  3049     ].
  3088     ].
  3050 
  3089 
  3051     "/ for now, only #valueNowOrOnUnwindDo:
  3090     "/ for now, only #valueNowOrOnUnwindDo:
  3052     "/          or   #valueOnUnwindDo:
  3091     "/          or   #valueOnUnwindDo:
  3053     "/          or   #ensure:
  3092     "/          or   #ensure:
  3189 ! !
  3228 ! !
  3190 
  3229 
  3191 !Block class methodsFor:'documentation'!
  3230 !Block class methodsFor:'documentation'!
  3192 
  3231 
  3193 version
  3232 version
  3194     ^ '$Header: /cvs/stx/stx/libbasic/Block.st,v 1.210 2015-03-27 11:23:34 cg Exp $'
  3233     ^ '$Header: /cvs/stx/stx/libbasic/Block.st,v 1.211 2015-04-21 19:40:04 cg Exp $'
  3195 !
  3234 !
  3196 
  3235 
  3197 version_CVS
  3236 version_CVS
  3198     ^ '$Header: /cvs/stx/stx/libbasic/Block.st,v 1.210 2015-03-27 11:23:34 cg Exp $'
  3237     ^ '$Header: /cvs/stx/stx/libbasic/Block.st,v 1.211 2015-04-21 19:40:04 cg Exp $'
  3199 ! !
  3238 ! !
  3200 
  3239 
  3201 
  3240 
  3202 Block initialize!
  3241 Block initialize!