Block.st
changeset 5349 f811d5194e8e
parent 5215 888c106f3240
child 5666 de56e39714da
equal deleted inserted replaced
5348:8220f8db1cc1 5349:f811d5194e8e
     7  inclusion of the above copyright notice.   This software may not
     7  inclusion of the above copyright notice.   This software may not
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
       
    12 
       
    13 "{ Package: 'stx:libbasic' }"
    12 
    14 
    13 CompiledCode variableSubclass:#Block
    15 CompiledCode variableSubclass:#Block
    14 	instanceVariableNames:'home nargs sourcePos initialPC'
    16 	instanceVariableNames:'home nargs sourcePos initialPC'
    15 	classVariableNames:'InvalidNewSignal'
    17 	classVariableNames:'InvalidNewSignal'
    16 	poolDictionaries:''
    18 	poolDictionaries:''
   358     ^ self == Block
   360     ^ self == Block
   359 
   361 
   360     "Modified: 23.4.1996 / 15:55:58 / cg"
   362     "Modified: 23.4.1996 / 15:55:58 / cg"
   361 ! !
   363 ! !
   362 
   364 
       
   365 !Block methodsFor:'Compatibility - ANSI'!
       
   366 
       
   367 ensure:aBlock
       
   368     "evaluate the receiver and return its result.
       
   369      After evaluation, also evaluate aBlock but ignore its result.
       
   370      aBlock is also evaluated in case of abnormal termination.
       
   371      (the same as #valueNowOrOnUnwindDo:)"
       
   372 
       
   373     ^ self valueNowOrOnUnwindDo:aBlock
       
   374 
       
   375     "
       
   376      [
       
   377         [
       
   378             Transcript showCR:'one'.
       
   379             Processor activeProcess terminate.
       
   380             Transcript showCR:'two'.
       
   381         ] ensure:[
       
   382             Transcript showCR:'three'.
       
   383         ].
       
   384      ] fork.
       
   385     "
       
   386 
       
   387     "
       
   388      [
       
   389         [
       
   390             Transcript showCR:'one'.
       
   391             Transcript showCR:'two'.
       
   392         ] ensure:[
       
   393             Transcript showCR:'three'.
       
   394         ].
       
   395      ] fork.
       
   396     "
       
   397 
       
   398 ! !
       
   399 
   363 !Block methodsFor:'Compatibility - Squeak'!
   400 !Block methodsFor:'Compatibility - Squeak'!
   364 
   401 
   365 ifError:handlerBlock
   402 ifError:handlerBlock
   366     ^ self on:Error do:handlerBlock
   403     ^ self on:Error do:handlerBlock
   367 ! !
   404 ! !
   439     ^ nargs
   476     ^ nargs
   440 ! !
   477 ! !
   441 
   478 
   442 !Block methodsFor:'conversion'!
   479 !Block methodsFor:'conversion'!
   443 
   480 
       
   481 asVarArgBlock
       
   482     "convert myself into a varArg block;
       
   483      this one has 1 formal argument, which gets the list
       
   484      of actual arguments when evaluated."
       
   485 
       
   486     nargs ~~ 1 ifTrue:[
       
   487         self error:'vararg blocks must take exactly 1 argument - the arg list'.
       
   488         ^ nil
       
   489     ].
       
   490 
       
   491     self changeClassTo:VarArgBlock.
       
   492     ^ self
       
   493 
       
   494     "
       
   495      |b|
       
   496 
       
   497      b := [:argList | Transcript 
       
   498                         show:'invoked with args:'; 
       
   499                         showCR:argList
       
   500           ] asVarArgBlock.
       
   501      b value.
       
   502      b value:'arg1'.
       
   503      b value:'arg1' value:'arg2' value:'arg3' value:'arg4'
       
   504     "
       
   505 
       
   506     "Created: 23.1.1997 / 13:35:28 / cg"
       
   507     "Modified: 23.1.1997 / 13:35:48 / cg"
       
   508 !
       
   509 
   444 beVarArg
   510 beVarArg
   445     "convert myself into a varArg block;
   511     "convert myself into a varArg block;
   446      this one has 1 formal argument, which gets the list
   512      this one has 1 formal argument, which gets the list
   447      of actual arguments when evaluated."
   513      of actual arguments when evaluated."
   448 
   514 
   449     nargs ~~ 1 ifTrue:[
   515     ^ self asVarArgBlock.
   450         self error:'vararg blocks must take exactly 1 argument - the arg list'.
       
   451         ^ nil
       
   452     ].
       
   453 
       
   454     self changeClassTo:VarArgBlock.
       
   455     ^ self
       
   456 
   516 
   457     "
   517     "
   458      |b|
   518      |b|
   459 
   519 
   460      b := [:argList | argList printCR] beVarArg.
   520      b := [:argList | argList printCR] beVarArg.
  1542     "Created: 23.1.1997 / 04:59:51 / cg"
  1602     "Created: 23.1.1997 / 04:59:51 / cg"
  1543 ! !
  1603 ! !
  1544 
  1604 
  1545 !Block methodsFor:'unwinding'!
  1605 !Block methodsFor:'unwinding'!
  1546 
  1606 
  1547 ensure:aBlock
       
  1548     "evaluate the receiver and return its result.
       
  1549      After evaluation, also evaluate aBlock but ignore its result.
       
  1550      aBlock is also evaluated in case of abnormal termination.
       
  1551      (the same as #valueNowOrOnUnwindDo:)"
       
  1552 
       
  1553     ^ self valueNowOrOnUnwindDo:aBlock
       
  1554 
       
  1555     "
       
  1556      [
       
  1557         [
       
  1558             Transcript showCR:'one'.
       
  1559             Processor activeProcess terminate.
       
  1560             Transcript showCR:'two'.
       
  1561         ] ensure:[
       
  1562             Transcript showCR:'three'.
       
  1563         ].
       
  1564      ] fork.
       
  1565     "
       
  1566 
       
  1567     "
       
  1568      [
       
  1569         [
       
  1570             Transcript showCR:'one'.
       
  1571             Transcript showCR:'two'.
       
  1572         ] ensure:[
       
  1573             Transcript showCR:'three'.
       
  1574         ].
       
  1575      ] fork.
       
  1576     "
       
  1577 
       
  1578 !
       
  1579 
       
  1580 unwindHandlerInContext:aContext
  1607 unwindHandlerInContext:aContext
  1581     "given a context which has been marked for unwind,
  1608     "given a context which has been marked for unwind,
  1582      retrieve the handler block.
  1609      retrieve the handler block.
  1583      This avoids hardwiring access to the first argument in
  1610      This avoids hardwiring access to the first argument in
  1584      #unwind methods (and theoretically allows for other unwinding
  1611      #unwind methods (and theoretically allows for other unwinding
  1716 ! !
  1743 ! !
  1717 
  1744 
  1718 !Block class methodsFor:'documentation'!
  1745 !Block class methodsFor:'documentation'!
  1719 
  1746 
  1720 version
  1747 version
  1721     ^ '$Header: /cvs/stx/stx/libbasic/Block.st,v 1.95 2000-01-27 12:02:31 cg Exp $'
  1748     ^ '$Header: /cvs/stx/stx/libbasic/Block.st,v 1.96 2000-04-01 13:04:33 cg Exp $'
  1722 ! !
  1749 ! !
  1723 Block initialize!
  1750 Block initialize!