1
0

Helios-Environments.st 3.7 KB

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