Helios-Environments.st 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. Smalltalk current createPackage: 'Helios-Environments'!
  2. Object subclass: #HLEnvironment
  3. instanceVariableNames: ''
  4. package: 'Helios-Environments'!
  5. !HLEnvironment commentStamp!
  6. Abstract class defining common behavior for local and remote environments!
  7. !HLEnvironment methodsFor: 'accessing'!
  8. availableClassNames
  9. self subclassResponsibility
  10. !
  11. availablePackageNames
  12. self subclassResponsibility
  13. !
  14. availableProtocolsFor: aClass
  15. self subclassResponsibility
  16. !
  17. classBuilder
  18. ^ self subclassResponsibility
  19. !
  20. classNamed: aString
  21. self subclassResponsibility
  22. !
  23. packages
  24. ^ self subclassResponsibility
  25. !
  26. systemAnnouncer
  27. ^ self subclassResponsibility
  28. ! !
  29. !HLEnvironment methodsFor: 'actions'!
  30. commitPackage: aPackage
  31. self subclassResponsibility
  32. !
  33. eval: someCode on: aReceiver
  34. ^ self subclassResponsibility
  35. !
  36. moveClass: aClass toPackage: aPackageName
  37. self subclassResponsibility
  38. !
  39. moveMethod: aMethod toClass: aClassName
  40. self subclassResponsibility
  41. !
  42. moveMethod: aMethod toProtocol: aProtocol
  43. self subclassResponsibility
  44. !
  45. removeClass: aClass
  46. self sublcassResponsibility
  47. !
  48. removeMethod: aMethod
  49. self sublcassResponsibility
  50. ! !
  51. !HLEnvironment methodsFor: 'compiling'!
  52. addInstVarNamed: aString to: aClass
  53. self classBuilder
  54. addSubclassOf: aClass superclass
  55. named: aClass name
  56. instanceVariableNames: (aClass instanceVariableNames copy add: aString; yourself)
  57. package: aClass package name
  58. !
  59. compileClassComment: aString for: aClass
  60. aClass comment: aString
  61. !
  62. compileClassDefinition: aString
  63. self eval: aString on: DoIt new
  64. !
  65. compileMethod: sourceCode for: class protocol: protocol
  66. class
  67. compile: sourceCode
  68. category: protocol
  69. ! !
  70. HLEnvironment subclass: #HLLocalEnvironment
  71. instanceVariableNames: ''
  72. package: 'Helios-Environments'!
  73. !HLLocalEnvironment methodsFor: 'accessing'!
  74. availableClassNames
  75. ^ Smalltalk current classes
  76. collect: [ :each | each name ]
  77. !
  78. availablePackageNames
  79. ^ Smalltalk current packages
  80. collect: [ :each | each name ]
  81. !
  82. availableProtocolsFor: aClass
  83. | protocols |
  84. protocols := aClass protocols.
  85. aClass superclass ifNotNil: [ protocols addAll: (self availableProtocolsFor: aClass superclass) ].
  86. ^ protocols asSet asArray
  87. !
  88. classBuilder
  89. ^ ClassBuilder new
  90. !
  91. classNamed: aString
  92. ^ (Smalltalk current at: aString asSymbol)
  93. ifNil: [ self error: 'Invalid class name' ]
  94. !
  95. packages
  96. ^ Smalltalk current packages
  97. !
  98. systemAnnouncer
  99. ^ SystemAnnouncer current
  100. ! !
  101. !HLLocalEnvironment methodsFor: 'actions'!
  102. commitPackage: aPackage
  103. aPackage commit
  104. !
  105. eval: aString on: aReceiver
  106. | compiler |
  107. compiler := Compiler new.
  108. [ compiler parseExpression: aString ] on: Error do: [ :ex |
  109. ^ window alert: ex messageText ].
  110. ^ compiler evaluateExpression: aString on: aReceiver
  111. !
  112. moveClass: aClass toPackage: aPackageName
  113. | package |
  114. package := Package named: aPackageName.
  115. package ifNil: [ self error: 'Invalid package name' ].
  116. package == aClass package ifTrue: [ ^ self ].
  117. package addClass: aClass
  118. !
  119. moveMethod: aMethod toClass: aClassName
  120. | destinationClass |
  121. destinationClass := Smalltalk current at: aClassName asSymbol.
  122. destinationClass ifNil: [ self error: 'Invalid class name' ].
  123. destinationClass == aMethod methodClass ifTrue: [ ^ self ].
  124. destinationClass adoptMethod: aMethod.
  125. aMethod methodClass forsakeMethod: aMethod.
  126. !
  127. moveMethod: aMethod toProtocol: aProtocol
  128. aMethod category: aProtocol
  129. !
  130. removeClass: aClass
  131. Smalltalk current removeClass: aClass
  132. !
  133. removeMethod: aMethod
  134. aMethod methodClass forsakeMethod: aMethod
  135. ! !
  136. HLEnvironment subclass: #HLRemoteEnvironment
  137. instanceVariableNames: ''
  138. package: 'Helios-Environments'!
  139. !HLRemoteEnvironment methodsFor: 'accessing'!
  140. packages
  141. "Answer the remote environment's packages"
  142. "to-do"
  143. "Note for future self and friends:
  144. the problem with remote stuff is that the answers shouldn't be expected to be
  145. received in a syncrhonous fashion. Everything network is asyc, so you *are going to deal with callbacks* here"
  146. ! !
  147. !HLRemoteEnvironment methodsFor: 'actions'!
  148. eval: someCode on: aReceiver
  149. "Note for future self and friends:
  150. whatever way this compilation happens on the other side,
  151. it should return a proxy to the remote resulting object"
  152. self notYetImplemented
  153. ! !
  154. Object subclass: #HLRemoteObject
  155. instanceVariableNames: ''
  156. package: 'Helios-Environments'!
  157. !HLRemoteObject commentStamp!
  158. This is a local proxy to a remote object.
  159. Tipically useful for evaluating and inspecting and interacting with instances of a remote VM.!
  160. !HLRemoteObject methodsFor: 'actions'!
  161. doesNotUnderstand: aMessage
  162. "to-do
  163. aham, blah blah
  164. super doesNotUnderstand: aMessage"
  165. !
  166. inspectOn: anInspector
  167. "to-do"
  168. "this is a source of so much fun..."
  169. !
  170. printString
  171. ^ 'this is a remote object'
  172. ! !
  173. !Behavior methodsFor: '*Helios-Environments'!
  174. adoptMethod: aMethod
  175. self
  176. compile: aMethod source
  177. category: aMethod protocol.
  178. !
  179. forsakeMethod: aMethod
  180. self removeCompiledMethod: aMethod
  181. ! !