Helios-Environments.st 4.0 KB

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