home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnusmalltalk / blockcontext.st < prev    next >
Text File  |  1992-02-15  |  3KB  |  119 lines

  1. "======================================================================
  2. |
  3. |   BlockContext Method Definitions
  4. |
  5.  ======================================================================"
  6.  
  7.  
  8. "======================================================================
  9. |
  10. | Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
  11. | Written by Steve Byrne.
  12. |
  13. | This file is part of GNU Smalltalk.
  14. |
  15. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  16. | under the terms of the GNU General Public License as published by the Free
  17. | Software Foundation; either version 1, or (at your option) any later version.
  18. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  19. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  20. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  21. | details.
  22. | You should have received a copy of the GNU General Public License along with
  23. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  24. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  25. |
  26.  ======================================================================"
  27.  
  28.  
  29. "
  30. |     Change Log
  31. | ============================================================================
  32. | Author       Date       Change 
  33. | sbb         16 Mar 91      Class creation now separate statement.
  34. |
  35. | sbyrne     25 Apr 89      created.
  36. |
  37. "
  38.  
  39. Object variableSubclass: #BlockContext
  40.        instanceVariableNames: 'caller ip sp numArgs initialIP selector home'
  41.        classVariableNames: ''
  42.        poolDictionaries: ''
  43.        category: nil
  44. !
  45.  
  46. BlockContext comment: 
  47. 'My instances represent Smalltalk blocks, which are portions of executeable
  48. code that have access to the environment that they were declared in, take
  49. parameters, and can be passed around as objects to be executed by methods
  50. outside the current class.  Block contexts are sent a message to compute
  51. their value; this property can be used in the construction of control
  52. flow methods.  I also provide some methods that are used in the creation
  53. of Processes from blocks.' !
  54.  
  55.  
  56. !BlockContext methodsFor: 'basic'!
  57.  
  58. whileTrue: aBlock
  59.     [ self value ] whileTrue: [ aBlock value ].
  60.     ^nil
  61. !
  62.  
  63. whileFalse: aBlock
  64.     [ self value ] whileFalse: [ aBlock value ].
  65.     ^nil
  66. !
  67.  
  68. whileTrue
  69.     ^[ self value ] whileTrue: []
  70. !
  71.  
  72. whileFalse
  73.     ^[ self value ] whileFalse: []
  74. !!
  75.  
  76.  
  77.  
  78. !BlockContext methodsFor: 'multiple process'!
  79.  
  80. fork
  81.     self newProcess resume
  82. !
  83.  
  84. newProcess
  85.     | block |
  86.     block _ [ self value.
  87.               Processor terminateActive ].
  88.     block initBlock.          
  89.     ^Process on: block at: Processor activePriority
  90. !
  91.  
  92. newProcessWith: anArray
  93.     | block |
  94.     block _ [ self valueWithArguments: anArray.
  95.               Processor terminateActive ].
  96.     block initBlock.          
  97.     ^Process on: block at: Processor activePriority
  98. !!
  99.  
  100.  
  101.  
  102. !BlockContext methodsFor: 'scheduling'!
  103.  
  104. forkAt: priority
  105.     (self newProcess priority: priority) resume
  106. !!
  107.  
  108.  
  109.  
  110. !BlockContext methodsFor: 'private'!
  111.  
  112. initBlock 
  113.     ip _ initialIP.
  114.     sp _ 0.
  115.     caller _ nil
  116. !!
  117.