Helios-Environments.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. smalltalk.addPackage('Helios-Environments');
  2. smalltalk.addClass('HLEnvironment', smalltalk.Object, [], 'Helios-Environments');
  3. smalltalk.HLEnvironment.comment="Abstract class defining common behavior for local and remote environments"
  4. smalltalk.addMethod(
  5. "_addInstVarNamed_to_",
  6. smalltalk.method({
  7. selector: "addInstVarNamed:to:",
  8. category: 'compiling',
  9. fn: function (aString,aClass){
  10. var self=this;
  11. return smalltalk.withContext(function($ctx1) { var $1,$2;
  12. $1=_st(_st(aClass)._instanceVariableNames())._copy();
  13. _st($1)._add_(aString);
  14. $2=_st($1)._yourself();
  15. _st(_st(self)._classBuilder())._addSubclassOf_named_instanceVariableNames_package_(_st(aClass)._superclass(),_st(aClass)._name(),$2,_st(_st(aClass)._package())._name());
  16. return self}, function($ctx1) {$ctx1.fill(self,"addInstVarNamed:to:",{aString:aString,aClass:aClass}, smalltalk.HLEnvironment)})},
  17. args: ["aString", "aClass"],
  18. source: "addInstVarNamed: aString to: aClass\x0a\x09self classBuilder\x0a\x09\x09addSubclassOf: aClass superclass \x0a\x09\x09named: aClass name \x0a\x09\x09instanceVariableNames: (aClass instanceVariableNames copy add: aString; yourself)\x0a\x09\x09package: aClass package name",
  19. messageSends: ["addSubclassOf:named:instanceVariableNames:package:", "superclass", "name", "add:", "copy", "instanceVariableNames", "yourself", "package", "classBuilder"],
  20. referencedClasses: []
  21. }),
  22. smalltalk.HLEnvironment);
  23. smalltalk.addMethod(
  24. "_classBuilder",
  25. smalltalk.method({
  26. selector: "classBuilder",
  27. category: 'accessing',
  28. fn: function (){
  29. var self=this;
  30. return smalltalk.withContext(function($ctx1) { var $1;
  31. $1=_st(self)._subclassResponsibility();
  32. return $1;
  33. }, function($ctx1) {$ctx1.fill(self,"classBuilder",{}, smalltalk.HLEnvironment)})},
  34. args: [],
  35. source: "classBuilder\x0a\x09^ self subclassResponsibility",
  36. messageSends: ["subclassResponsibility"],
  37. referencedClasses: []
  38. }),
  39. smalltalk.HLEnvironment);
  40. smalltalk.addMethod(
  41. "_compileClassComment_for_",
  42. smalltalk.method({
  43. selector: "compileClassComment:for:",
  44. category: 'compiling',
  45. fn: function (aString,aClass){
  46. var self=this;
  47. return smalltalk.withContext(function($ctx1) { _st(aClass)._comment_(aString);
  48. return self}, function($ctx1) {$ctx1.fill(self,"compileClassComment:for:",{aString:aString,aClass:aClass}, smalltalk.HLEnvironment)})},
  49. args: ["aString", "aClass"],
  50. source: "compileClassComment: aString for: aClass\x0a\x09aClass comment: aString",
  51. messageSends: ["comment:"],
  52. referencedClasses: []
  53. }),
  54. smalltalk.HLEnvironment);
  55. smalltalk.addMethod(
  56. "_compileClassDefinition_",
  57. smalltalk.method({
  58. selector: "compileClassDefinition:",
  59. category: 'compiling',
  60. fn: function (aString){
  61. var self=this;
  62. return smalltalk.withContext(function($ctx1) { _st(self)._eval_on_(aString,_st((smalltalk.DoIt || DoIt))._new());
  63. return self}, function($ctx1) {$ctx1.fill(self,"compileClassDefinition:",{aString:aString}, smalltalk.HLEnvironment)})},
  64. args: ["aString"],
  65. source: "compileClassDefinition: aString\x0a\x09self eval: aString on: DoIt new",
  66. messageSends: ["eval:on:", "new"],
  67. referencedClasses: ["DoIt"]
  68. }),
  69. smalltalk.HLEnvironment);
  70. smalltalk.addMethod(
  71. "_compileMethod_for_protocol_",
  72. smalltalk.method({
  73. selector: "compileMethod:for:protocol:",
  74. category: 'compiling',
  75. fn: function (sourceCode,class_,protocol){
  76. var self=this;
  77. return smalltalk.withContext(function($ctx1) { _st(class_)._compile_category_(sourceCode,protocol);
  78. return self}, function($ctx1) {$ctx1.fill(self,"compileMethod:for:protocol:",{sourceCode:sourceCode,class_:class_,protocol:protocol}, smalltalk.HLEnvironment)})},
  79. args: ["sourceCode", "class", "protocol"],
  80. source: "compileMethod: sourceCode for: class protocol: protocol\x0a\x09class\x0a\x09\x09compile: sourceCode\x0a\x09\x09category: protocol",
  81. messageSends: ["compile:category:"],
  82. referencedClasses: []
  83. }),
  84. smalltalk.HLEnvironment);
  85. smalltalk.addMethod(
  86. "_eval_on_",
  87. smalltalk.method({
  88. selector: "eval:on:",
  89. category: 'actions',
  90. fn: function (someCode,aReceiver){
  91. var self=this;
  92. return smalltalk.withContext(function($ctx1) { var $1;
  93. $1=_st(self)._subclassResponsibility();
  94. return $1;
  95. }, function($ctx1) {$ctx1.fill(self,"eval:on:",{someCode:someCode,aReceiver:aReceiver}, smalltalk.HLEnvironment)})},
  96. args: ["someCode", "aReceiver"],
  97. source: "eval: someCode on: aReceiver\x0a\x0a\x09^ self subclassResponsibility",
  98. messageSends: ["subclassResponsibility"],
  99. referencedClasses: []
  100. }),
  101. smalltalk.HLEnvironment);
  102. smalltalk.addMethod(
  103. "_moveMethod_toClass_",
  104. smalltalk.method({
  105. selector: "moveMethod:toClass:",
  106. category: 'actions',
  107. fn: function (aMethod,aClassName){
  108. var self=this;
  109. return smalltalk.withContext(function($ctx1) { _st(self)._subclassResponsibility();
  110. return self}, function($ctx1) {$ctx1.fill(self,"moveMethod:toClass:",{aMethod:aMethod,aClassName:aClassName},smalltalk.HLEnvironment)})},
  111. args: ["aMethod", "aClassName"],
  112. source: "moveMethod: aMethod toClass: aClassName\x0a\x09self subclassResponsibility",
  113. messageSends: ["subclassResponsibility"],
  114. referencedClasses: []
  115. }),
  116. smalltalk.HLEnvironment);
  117. smalltalk.addMethod(
  118. "_packages",
  119. smalltalk.method({
  120. selector: "packages",
  121. category: 'accessing',
  122. fn: function (){
  123. var self=this;
  124. return smalltalk.withContext(function($ctx1) { var $1;
  125. $1=_st(self)._subclassResponsibility();
  126. return $1;
  127. }, function($ctx1) {$ctx1.fill(self,"packages",{}, smalltalk.HLEnvironment)})},
  128. args: [],
  129. source: "packages\x0a\x09^ self subclassResponsibility",
  130. messageSends: ["subclassResponsibility"],
  131. referencedClasses: []
  132. }),
  133. smalltalk.HLEnvironment);
  134. smalltalk.addClass('HLLocalEnvironment', smalltalk.HLEnvironment, [], 'Helios-Environments');
  135. smalltalk.addMethod(
  136. "_classBuilder",
  137. smalltalk.method({
  138. selector: "classBuilder",
  139. category: 'accessing',
  140. fn: function (){
  141. var self=this;
  142. return smalltalk.withContext(function($ctx1) { var $1;
  143. $1=_st((smalltalk.ClassBuilder || ClassBuilder))._new();
  144. return $1;
  145. }, function($ctx1) {$ctx1.fill(self,"classBuilder",{}, smalltalk.HLLocalEnvironment)})},
  146. args: [],
  147. source: "classBuilder\x0a\x09^ ClassBuilder new",
  148. messageSends: ["new"],
  149. referencedClasses: ["ClassBuilder"]
  150. }),
  151. smalltalk.HLLocalEnvironment);
  152. smalltalk.addMethod(
  153. "_eval_on_",
  154. smalltalk.method({
  155. selector: "eval:on:",
  156. category: 'actions',
  157. fn: function (aString,aReceiver){
  158. var self=this;
  159. var compiler;
  160. return smalltalk.withContext(function($ctx1) { var $1,$2;
  161. var $early={};
  162. try {
  163. compiler=_st((smalltalk.Compiler || Compiler))._new();
  164. _st((function(){
  165. return smalltalk.withContext(function($ctx2) { return _st(compiler)._parseExpression_(aString);
  166. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._on_do_((smalltalk.Error || Error),(function(ex){
  167. return smalltalk.withContext(function($ctx2) { $1=_st(window)._alert_(_st(ex)._messageText());
  168. throw $early=[$1];
  169. }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1)})}));
  170. $2=_st(compiler)._evaluateExpression_on_(aString,aReceiver);
  171. return $2;
  172. }
  173. catch(e) {if(e===$early)return e[0]; throw e}
  174. }, function($ctx1) {$ctx1.fill(self,"eval:on:",{aString:aString,aReceiver:aReceiver,compiler:compiler}, smalltalk.HLLocalEnvironment)})},
  175. args: ["aString", "aReceiver"],
  176. source: "eval: aString on: aReceiver\x0a\x09| compiler |\x0a\x09compiler := Compiler new.\x0a\x09[ compiler parseExpression: aString ] on: Error do: [ :ex |\x0a\x09\x09^ window alert: ex messageText ].\x0a\x09^ compiler evaluateExpression: aString on: aReceiver",
  177. messageSends: ["new", "on:do:", "alert:", "messageText", "parseExpression:", "evaluateExpression:on:"],
  178. referencedClasses: ["Compiler", "Error"]
  179. }),
  180. smalltalk.HLLocalEnvironment);
  181. smalltalk.addMethod(
  182. "_moveMethod_toClass_",
  183. smalltalk.method({
  184. selector: "moveMethod:toClass:",
  185. category: 'actions',
  186. fn: function (aMethod,aClassName){
  187. var self=this;
  188. var destinationClass;
  189. return smalltalk.withContext(function($ctx1) { var $1,$2,$3;
  190. destinationClass=_st(_st((smalltalk.Smalltalk || Smalltalk))._current())._at_(_st(aClassName)._asSymbol());
  191. $1=destinationClass;
  192. if(($receiver = $1) == nil || $receiver == undefined){
  193. _st(self)._error_("Invalid class name");
  194. } else {
  195. $1;
  196. };
  197. $2=_st(destinationClass).__eq_eq(_st(aMethod)._methodClass());
  198. if(smalltalk.assert($2)){
  199. $3=self;
  200. return $3;
  201. };
  202. _st(destinationClass)._adoptMethod_(aMethod);
  203. _st(_st(aMethod)._methodClass())._forsakeMethod_(aMethod);
  204. return self}, function($ctx1) {$ctx1.fill(self,"moveMethod:toClass:",{aMethod:aMethod,aClassName:aClassName,destinationClass:destinationClass},smalltalk.HLLocalEnvironment)})},
  205. args: ["aMethod", "aClassName"],
  206. source: "moveMethod: aMethod toClass: aClassName\x0a\x09| destinationClass |\x0a\x09\x0a\x09destinationClass := Smalltalk current at: aClassName asSymbol.\x0a\x09destinationClass ifNil: [ self error: 'Invalid class name' ].\x0a\x09destinationClass == aMethod methodClass ifTrue: [ ^ self ].\x0a\x09\x0a\x09destinationClass adoptMethod: aMethod.\x0a\x09aMethod methodClass forsakeMethod: aMethod.\x0a\x09",
  207. messageSends: ["at:", "asSymbol", "current", "ifNil:", "error:", "ifTrue:", "==", "methodClass", "adoptMethod:", "forsakeMethod:"],
  208. referencedClasses: ["Smalltalk"]
  209. }),
  210. smalltalk.HLLocalEnvironment);
  211. smalltalk.addMethod(
  212. "_packages",
  213. smalltalk.method({
  214. selector: "packages",
  215. category: 'accessing',
  216. fn: function (){
  217. var self=this;
  218. return smalltalk.withContext(function($ctx1) { var $1;
  219. $1=_st(_st((smalltalk.Smalltalk || Smalltalk))._current())._packages();
  220. return $1;
  221. }, function($ctx1) {$ctx1.fill(self,"packages",{}, smalltalk.HLLocalEnvironment)})},
  222. args: [],
  223. source: "packages\x0a\x09^ Smalltalk current packages",
  224. messageSends: ["packages", "current"],
  225. referencedClasses: ["Smalltalk"]
  226. }),
  227. smalltalk.HLLocalEnvironment);
  228. smalltalk.addClass('HLRemoteEnvironment', smalltalk.HLEnvironment, [], 'Helios-Environments');
  229. smalltalk.addMethod(
  230. "_eval_on_",
  231. smalltalk.method({
  232. selector: "eval:on:",
  233. category: 'actions',
  234. fn: function (someCode,aReceiver){
  235. var self=this;
  236. return smalltalk.withContext(function($ctx1) { _st(self)._notYetImplemented();
  237. return self}, function($ctx1) {$ctx1.fill(self,"eval:on:",{someCode:someCode,aReceiver:aReceiver}, smalltalk.HLRemoteEnvironment)})},
  238. args: ["someCode", "aReceiver"],
  239. source: "eval: someCode on: aReceiver\x0a\x0a\x09\x22Note for future self and friends:\x0a whatever way this compilation happens on the other side, \x0a it should return a proxy to the remote resulting object\x22\x0a \x0a self notYetImplemented",
  240. messageSends: ["notYetImplemented"],
  241. referencedClasses: []
  242. }),
  243. smalltalk.HLRemoteEnvironment);
  244. smalltalk.addMethod(
  245. "_packages",
  246. smalltalk.method({
  247. selector: "packages",
  248. category: 'accessing',
  249. fn: function (){
  250. var self=this;
  251. return smalltalk.withContext(function($ctx1) { return self}, function($ctx1) {$ctx1.fill(self,"packages",{}, smalltalk.HLRemoteEnvironment)})},
  252. args: [],
  253. source: "packages\x0a\x09\x22Answer the remote environment's packages\x22\x0a \x0a\x09\x22to-do\x22\x0a \x0a \x22Note for future self and friends:\x0a the problem with remote stuff is that the answers shouldn't be expected to be\x0a received in a syncrhonous fashion. Everything network is asyc, so you *are going to deal with callbacks* here\x22",
  254. messageSends: [],
  255. referencedClasses: []
  256. }),
  257. smalltalk.HLRemoteEnvironment);
  258. smalltalk.addClass('HLRemoteObject', smalltalk.Object, [], 'Helios-Environments');
  259. smalltalk.HLRemoteObject.comment="This is a local proxy to a remote object.\x0aTipically useful for evaluating and inspecting and interacting with instances of a remote VM.\x0a"
  260. smalltalk.addMethod(
  261. "_doesNotUnderstand_",
  262. smalltalk.method({
  263. selector: "doesNotUnderstand:",
  264. category: 'actions',
  265. fn: function (aMessage){
  266. var self=this;
  267. return smalltalk.withContext(function($ctx1) { return self}, function($ctx1) {$ctx1.fill(self,"doesNotUnderstand:",{aMessage:aMessage}, smalltalk.HLRemoteObject)})},
  268. args: ["aMessage"],
  269. source: "doesNotUnderstand: aMessage\x0a\x0a\x09\x22to-do\x0a\x0a\x09aham, blah blah\x0a\x0a\x09super doesNotUnderstand: aMessage\x22",
  270. messageSends: [],
  271. referencedClasses: []
  272. }),
  273. smalltalk.HLRemoteObject);
  274. smalltalk.addMethod(
  275. "_inspectOn_",
  276. smalltalk.method({
  277. selector: "inspectOn:",
  278. category: 'actions',
  279. fn: function (anInspector){
  280. var self=this;
  281. return smalltalk.withContext(function($ctx1) { return self}, function($ctx1) {$ctx1.fill(self,"inspectOn:",{anInspector:anInspector}, smalltalk.HLRemoteObject)})},
  282. args: ["anInspector"],
  283. source: "inspectOn: anInspector\x0a\x0a\x09\x22to-do\x22\x0a\x0a\x09\x22this is a source of so much fun...\x22\x0a",
  284. messageSends: [],
  285. referencedClasses: []
  286. }),
  287. smalltalk.HLRemoteObject);
  288. smalltalk.addMethod(
  289. "_printString",
  290. smalltalk.method({
  291. selector: "printString",
  292. category: 'actions',
  293. fn: function (){
  294. var self=this;
  295. return smalltalk.withContext(function($ctx1) { return "this is a remote object";
  296. }, function($ctx1) {$ctx1.fill(self,"printString",{}, smalltalk.HLRemoteObject)})},
  297. args: [],
  298. source: "printString\x0a\x09^ 'this is a remote object'",
  299. messageSends: [],
  300. referencedClasses: []
  301. }),
  302. smalltalk.HLRemoteObject);
  303. smalltalk.addMethod(
  304. "_adoptMethod_",
  305. smalltalk.method({
  306. selector: "adoptMethod:",
  307. category: '*Helios-Environments',
  308. fn: function (aMethod){
  309. var self=this;
  310. return smalltalk.withContext(function($ctx1) { _st(self)._compile_category_(_st(aMethod)._source(),_st(aMethod)._protocol());
  311. return self}, function($ctx1) {$ctx1.fill(self,"adoptMethod:",{aMethod:aMethod},smalltalk.Behavior)})},
  312. args: ["aMethod"],
  313. source: "adoptMethod: aMethod\x0a\x09self \x0a\x09\x09compile: aMethod source\x0a\x09\x09category: aMethod protocol.",
  314. messageSends: ["compile:category:", "source", "protocol"],
  315. referencedClasses: []
  316. }),
  317. smalltalk.Behavior);
  318. smalltalk.addMethod(
  319. "_forsakeMethod_",
  320. smalltalk.method({
  321. selector: "forsakeMethod:",
  322. category: '*Helios-Environments',
  323. fn: function (aMethod){
  324. var self=this;
  325. return smalltalk.withContext(function($ctx1) { _st(self)._removeCompiledMethod_(aMethod);
  326. return self}, function($ctx1) {$ctx1.fill(self,"forsakeMethod:",{aMethod:aMethod},smalltalk.Behavior)})},
  327. args: ["aMethod"],
  328. source: "forsakeMethod: aMethod\x0a\x09self removeCompiledMethod: aMethod",
  329. messageSends: ["removeCompiledMethod:"],
  330. referencedClasses: []
  331. }),
  332. smalltalk.Behavior);