1
0

Helios-Environments.st 4.3 KB

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