Helios-Helpers.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. define("amber_core/Helios-Helpers", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_core/Kernel-Objects"], function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Helios-Helpers');
  3. smalltalk.packages["Helios-Helpers"].transport = {"type":"amd","amdNamespace":"amber_core"};
  4. smalltalk.addClass('HLGenerationOutput', smalltalk.Object, ['sourceCodes', 'protocol', 'targetClass'], 'Helios-Helpers');
  5. smalltalk.HLGenerationOutput.comment="I am a simple data object used to store the result of a generation process";
  6. smalltalk.addMethod(
  7. smalltalk.method({
  8. selector: "addSourceCode:",
  9. protocol: 'protocol',
  10. fn: function (aString){
  11. var self=this;
  12. return smalltalk.withContext(function($ctx1) {
  13. _st(self["@sourceCodes"])._add_(aString);
  14. return self}, function($ctx1) {$ctx1.fill(self,"addSourceCode:",{aString:aString},smalltalk.HLGenerationOutput)})},
  15. args: ["aString"],
  16. source: "addSourceCode: aString\x0a\x09sourceCodes add: aString",
  17. messageSends: ["add:"],
  18. referencedClasses: []
  19. }),
  20. smalltalk.HLGenerationOutput);
  21. smalltalk.addMethod(
  22. smalltalk.method({
  23. selector: "initialize",
  24. protocol: 'initialization',
  25. fn: function (){
  26. var self=this;
  27. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  28. return smalltalk.withContext(function($ctx1) {
  29. smalltalk.HLGenerationOutput.superclass.fn.prototype._initialize.apply(_st(self), []);
  30. self["@sourceCodes"]=_st($OrderedCollection())._new();
  31. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLGenerationOutput)})},
  32. args: [],
  33. source: "initialize\x0a\x09super initialize.\x0a\x09\x0a\x09sourceCodes := OrderedCollection new",
  34. messageSends: ["initialize", "new"],
  35. referencedClasses: ["OrderedCollection"]
  36. }),
  37. smalltalk.HLGenerationOutput);
  38. smalltalk.addMethod(
  39. smalltalk.method({
  40. selector: "protocol",
  41. protocol: 'accessing',
  42. fn: function (){
  43. var self=this;
  44. return smalltalk.withContext(function($ctx1) {
  45. var $1;
  46. $1=self["@protocol"];
  47. return $1;
  48. }, function($ctx1) {$ctx1.fill(self,"protocol",{},smalltalk.HLGenerationOutput)})},
  49. args: [],
  50. source: "protocol\x0a\x09^ protocol",
  51. messageSends: [],
  52. referencedClasses: []
  53. }),
  54. smalltalk.HLGenerationOutput);
  55. smalltalk.addMethod(
  56. smalltalk.method({
  57. selector: "protocol:",
  58. protocol: 'accessing',
  59. fn: function (aString){
  60. var self=this;
  61. return smalltalk.withContext(function($ctx1) {
  62. self["@protocol"]=aString;
  63. return self}, function($ctx1) {$ctx1.fill(self,"protocol:",{aString:aString},smalltalk.HLGenerationOutput)})},
  64. args: ["aString"],
  65. source: "protocol: aString\x0a\x09protocol := aString",
  66. messageSends: [],
  67. referencedClasses: []
  68. }),
  69. smalltalk.HLGenerationOutput);
  70. smalltalk.addMethod(
  71. smalltalk.method({
  72. selector: "serialize",
  73. protocol: 'protocol',
  74. fn: function (){
  75. var self=this;
  76. return smalltalk.withContext(function($ctx1) {
  77. var $1;
  78. _st(self["@sourceCodes"])._do_((function(methodSourceCode){
  79. return smalltalk.withContext(function($ctx2) {
  80. $1=_st(self["@targetClass"])._includesSelector_(_st(methodSourceCode)._selector());
  81. if(! smalltalk.assert($1)){
  82. return _st(self["@targetClass"])._compile_protocol_(_st(methodSourceCode)._sourceCode(),self["@protocol"]);
  83. };
  84. }, function($ctx2) {$ctx2.fillBlock({methodSourceCode:methodSourceCode},$ctx1,1)})}));
  85. return self}, function($ctx1) {$ctx1.fill(self,"serialize",{},smalltalk.HLGenerationOutput)})},
  86. args: [],
  87. source: "serialize\x0a\x09sourceCodes do: [ :methodSourceCode |\x0a\x09\x09(targetClass includesSelector: methodSourceCode selector)\x0a\x09\x09\x09ifFalse: [ \x0a\x09\x09\x09\x09targetClass \x0a\x09\x09\x09\x09\x09compile: methodSourceCode sourceCode\x0a\x09\x09\x09\x09\x09protocol: protocol ] ]",
  88. messageSends: ["do:", "ifFalse:", "includesSelector:", "selector", "compile:protocol:", "sourceCode"],
  89. referencedClasses: []
  90. }),
  91. smalltalk.HLGenerationOutput);
  92. smalltalk.addMethod(
  93. smalltalk.method({
  94. selector: "sourceCodes",
  95. protocol: 'accessing',
  96. fn: function (){
  97. var self=this;
  98. return smalltalk.withContext(function($ctx1) {
  99. var $1;
  100. $1=self["@sourceCodes"];
  101. return $1;
  102. }, function($ctx1) {$ctx1.fill(self,"sourceCodes",{},smalltalk.HLGenerationOutput)})},
  103. args: [],
  104. source: "sourceCodes\x0a\x09^ sourceCodes",
  105. messageSends: [],
  106. referencedClasses: []
  107. }),
  108. smalltalk.HLGenerationOutput);
  109. smalltalk.addMethod(
  110. smalltalk.method({
  111. selector: "sourceCodes:",
  112. protocol: 'accessing',
  113. fn: function (aCollection){
  114. var self=this;
  115. return smalltalk.withContext(function($ctx1) {
  116. self["@sourceCodes"]=aCollection;
  117. return self}, function($ctx1) {$ctx1.fill(self,"sourceCodes:",{aCollection:aCollection},smalltalk.HLGenerationOutput)})},
  118. args: ["aCollection"],
  119. source: "sourceCodes: aCollection\x0a\x09sourceCodes := aCollection",
  120. messageSends: [],
  121. referencedClasses: []
  122. }),
  123. smalltalk.HLGenerationOutput);
  124. smalltalk.addMethod(
  125. smalltalk.method({
  126. selector: "targetClass",
  127. protocol: 'accessing',
  128. fn: function (){
  129. var self=this;
  130. return smalltalk.withContext(function($ctx1) {
  131. var $1;
  132. $1=self["@targetClass"];
  133. return $1;
  134. }, function($ctx1) {$ctx1.fill(self,"targetClass",{},smalltalk.HLGenerationOutput)})},
  135. args: [],
  136. source: "targetClass\x0a\x09^ targetClass",
  137. messageSends: [],
  138. referencedClasses: []
  139. }),
  140. smalltalk.HLGenerationOutput);
  141. smalltalk.addMethod(
  142. smalltalk.method({
  143. selector: "targetClass:",
  144. protocol: 'accessing',
  145. fn: function (aClass){
  146. var self=this;
  147. return smalltalk.withContext(function($ctx1) {
  148. self["@targetClass"]=aClass;
  149. return self}, function($ctx1) {$ctx1.fill(self,"targetClass:",{aClass:aClass},smalltalk.HLGenerationOutput)})},
  150. args: ["aClass"],
  151. source: "targetClass: aClass\x0a\x09targetClass := aClass",
  152. messageSends: [],
  153. referencedClasses: []
  154. }),
  155. smalltalk.HLGenerationOutput);
  156. smalltalk.addClass('HLGenerationOutputWithIndex', smalltalk.HLGenerationOutput, ['index'], 'Helios-Helpers');
  157. smalltalk.HLGenerationOutputWithIndex.comment="I am a simple data object used to store the result of a generation process.\x0a\x0aIn addition of my super class, I have an index where to put the cursor at the end of the process for the first method created (aka. the first in `sourceCodes`)";
  158. smalltalk.addMethod(
  159. smalltalk.method({
  160. selector: "index",
  161. protocol: 'accessing',
  162. fn: function (){
  163. var self=this;
  164. return smalltalk.withContext(function($ctx1) {
  165. var $1;
  166. $1=self["@index"];
  167. return $1;
  168. }, function($ctx1) {$ctx1.fill(self,"index",{},smalltalk.HLGenerationOutputWithIndex)})},
  169. args: [],
  170. source: "index\x0a\x09^ index",
  171. messageSends: [],
  172. referencedClasses: []
  173. }),
  174. smalltalk.HLGenerationOutputWithIndex);
  175. smalltalk.addMethod(
  176. smalltalk.method({
  177. selector: "index:",
  178. protocol: 'accessing',
  179. fn: function (anIndex){
  180. var self=this;
  181. return smalltalk.withContext(function($ctx1) {
  182. self["@index"]=anIndex;
  183. return self}, function($ctx1) {$ctx1.fill(self,"index:",{anIndex:anIndex},smalltalk.HLGenerationOutputWithIndex)})},
  184. args: ["anIndex"],
  185. source: "index: anIndex\x0a\x09index := anIndex",
  186. messageSends: [],
  187. referencedClasses: []
  188. }),
  189. smalltalk.HLGenerationOutputWithIndex);
  190. smalltalk.addClass('HLGenerator', smalltalk.Object, ['output'], 'Helios-Helpers');
  191. smalltalk.HLGenerator.comment="I am the abstract super class of the generators.\x0a\x0aMy main method is `generate` which produce an `output` object";
  192. smalltalk.addMethod(
  193. smalltalk.method({
  194. selector: "class:",
  195. protocol: 'accessing',
  196. fn: function (aClass){
  197. var self=this;
  198. return smalltalk.withContext(function($ctx1) {
  199. _st(self["@output"])._targetClass_(aClass);
  200. return self}, function($ctx1) {$ctx1.fill(self,"class:",{aClass:aClass},smalltalk.HLGenerator)})},
  201. args: ["aClass"],
  202. source: "class: aClass\x0a\x09output targetClass: aClass",
  203. messageSends: ["targetClass:"],
  204. referencedClasses: []
  205. }),
  206. smalltalk.HLGenerator);
  207. smalltalk.addMethod(
  208. smalltalk.method({
  209. selector: "generate",
  210. protocol: 'protocol',
  211. fn: function (){
  212. var self=this;
  213. return smalltalk.withContext(function($ctx1) {
  214. var $1;
  215. $1=_st(self["@output"])._targetClass();
  216. if(($receiver = $1) == nil || $receiver == null){
  217. self._error_("class should not be nil");
  218. } else {
  219. $1;
  220. };
  221. return self}, function($ctx1) {$ctx1.fill(self,"generate",{},smalltalk.HLGenerator)})},
  222. args: [],
  223. source: "generate\x0a\x0a\x09output targetClass ifNil: [ self error: 'class should not be nil'].",
  224. messageSends: ["ifNil:", "targetClass", "error:"],
  225. referencedClasses: []
  226. }),
  227. smalltalk.HLGenerator);
  228. smalltalk.addMethod(
  229. smalltalk.method({
  230. selector: "initialize",
  231. protocol: 'initialization',
  232. fn: function (){
  233. var self=this;
  234. function $HLGenerationOutput(){return smalltalk.HLGenerationOutput||(typeof HLGenerationOutput=="undefined"?nil:HLGenerationOutput)}
  235. return smalltalk.withContext(function($ctx1) {
  236. smalltalk.HLGenerator.superclass.fn.prototype._initialize.apply(_st(self), []);
  237. self["@output"]=_st($HLGenerationOutput())._new();
  238. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLGenerator)})},
  239. args: [],
  240. source: "initialize\x0a\x09super initialize.\x0a\x09\x0a\x09output := HLGenerationOutput new",
  241. messageSends: ["initialize", "new"],
  242. referencedClasses: ["HLGenerationOutput"]
  243. }),
  244. smalltalk.HLGenerator);
  245. smalltalk.addMethod(
  246. smalltalk.method({
  247. selector: "output",
  248. protocol: 'accessing',
  249. fn: function (){
  250. var self=this;
  251. return smalltalk.withContext(function($ctx1) {
  252. var $1;
  253. $1=self["@output"];
  254. return $1;
  255. }, function($ctx1) {$ctx1.fill(self,"output",{},smalltalk.HLGenerator)})},
  256. args: [],
  257. source: "output\x0a\x09^ output",
  258. messageSends: [],
  259. referencedClasses: []
  260. }),
  261. smalltalk.HLGenerator);
  262. smalltalk.addClass('HLAccessorsGenerator', smalltalk.HLGenerator, [], 'Helios-Helpers');
  263. smalltalk.HLAccessorsGenerator.comment="I am a generator used to compile the getters/setters of a class";
  264. smalltalk.addMethod(
  265. smalltalk.method({
  266. selector: "accessorProtocolForObject",
  267. protocol: 'double-dispatch',
  268. fn: function (){
  269. var self=this;
  270. return smalltalk.withContext(function($ctx1) {
  271. _st(self["@output"])._protocol_("accessing");
  272. return self}, function($ctx1) {$ctx1.fill(self,"accessorProtocolForObject",{},smalltalk.HLAccessorsGenerator)})},
  273. args: [],
  274. source: "accessorProtocolForObject\x0a\x09output protocol: 'accessing'",
  275. messageSends: ["protocol:"],
  276. referencedClasses: []
  277. }),
  278. smalltalk.HLAccessorsGenerator);
  279. smalltalk.addMethod(
  280. smalltalk.method({
  281. selector: "accessorsSourceCodesForObject",
  282. protocol: 'double-dispatch',
  283. fn: function (){
  284. var self=this;
  285. var sources;
  286. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  287. return smalltalk.withContext(function($ctx1) {
  288. var $1,$2;
  289. sources=_st($OrderedCollection())._new();
  290. _st(_st(_st(_st(self["@output"])._targetClass())._instanceVariableNames())._sorted())._do_((function(each){
  291. return smalltalk.withContext(function($ctx2) {
  292. $1=sources;
  293. _st($1)._add_(self._getterFor_(each));
  294. $ctx2.sendIdx["add:"]=1;
  295. $2=_st($1)._add_(self._setterFor_(each));
  296. return $2;
  297. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  298. _st(self["@output"])._sourceCodes_(sources);
  299. return self}, function($ctx1) {$ctx1.fill(self,"accessorsSourceCodesForObject",{sources:sources},smalltalk.HLAccessorsGenerator)})},
  300. args: [],
  301. source: "accessorsSourceCodesForObject\x0a\x09| sources |\x0a\x09\x0a\x09sources := OrderedCollection new.\x0a\x09output targetClass instanceVariableNames sorted do: [ :each | \x0a\x09\x09sources \x0a\x09\x09\x09add: (self getterFor: each);\x0a\x09\x09\x09add: (self setterFor: each) ].\x0a\x09output sourceCodes: sources",
  302. messageSends: ["new", "do:", "sorted", "instanceVariableNames", "targetClass", "add:", "getterFor:", "setterFor:", "sourceCodes:"],
  303. referencedClasses: ["OrderedCollection"]
  304. }),
  305. smalltalk.HLAccessorsGenerator);
  306. smalltalk.addMethod(
  307. smalltalk.method({
  308. selector: "generate",
  309. protocol: 'protocol',
  310. fn: function (){
  311. var self=this;
  312. return smalltalk.withContext(function($ctx1) {
  313. var $1,$2;
  314. smalltalk.HLAccessorsGenerator.superclass.fn.prototype._generate.apply(_st(self), []);
  315. $1=_st(self["@output"])._targetClass();
  316. _st($1)._accessorsSourceCodesWith_(self);
  317. $2=_st($1)._accessorProtocolWith_(self);
  318. return self}, function($ctx1) {$ctx1.fill(self,"generate",{},smalltalk.HLAccessorsGenerator)})},
  319. args: [],
  320. source: "generate\x0a\x09super generate.\x0a\x09\x0a\x09output targetClass \x0a\x09\x09accessorsSourceCodesWith: self;\x0a\x09\x09accessorProtocolWith: self",
  321. messageSends: ["generate", "accessorsSourceCodesWith:", "targetClass", "accessorProtocolWith:"],
  322. referencedClasses: []
  323. }),
  324. smalltalk.HLAccessorsGenerator);
  325. smalltalk.addMethod(
  326. smalltalk.method({
  327. selector: "getterFor:",
  328. protocol: 'private',
  329. fn: function (anInstanceVariable){
  330. var self=this;
  331. function $HLMethodSourceCode(){return smalltalk.HLMethodSourceCode||(typeof HLMethodSourceCode=="undefined"?nil:HLMethodSourceCode)}
  332. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  333. return smalltalk.withContext(function($ctx1) {
  334. var $2,$4,$3,$1;
  335. $2=_st($HLMethodSourceCode())._new();
  336. _st($2)._selector_(anInstanceVariable);
  337. $3=_st($2)._sourceCode_(_st($String())._streamContents_((function(stream){
  338. return smalltalk.withContext(function($ctx2) {
  339. _st(stream).__lt_lt(anInstanceVariable);
  340. $ctx2.sendIdx["<<"]=1;
  341. $4=_st(_st(stream)._cr())._cr();
  342. $ctx2.sendIdx["cr"]=1;
  343. _st($4)._tab();
  344. return _st(_st(stream).__lt_lt("^ ")).__lt_lt(anInstanceVariable);
  345. $ctx2.sendIdx["<<"]=2;
  346. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1,1)})})));
  347. $1=$3;
  348. return $1;
  349. }, function($ctx1) {$ctx1.fill(self,"getterFor:",{anInstanceVariable:anInstanceVariable},smalltalk.HLAccessorsGenerator)})},
  350. args: ["anInstanceVariable"],
  351. source: "getterFor: anInstanceVariable\x0a\x09^ HLMethodSourceCode new\x0a\x09\x09selector:anInstanceVariable;\x0a\x09\x09sourceCode: (String streamContents: [ :stream |\x0a\x09\x09stream << anInstanceVariable.\x0a\x09\x09stream cr cr tab.\x0a\x09\x09stream << '^ ' << anInstanceVariable ])",
  352. messageSends: ["selector:", "new", "sourceCode:", "streamContents:", "<<", "tab", "cr"],
  353. referencedClasses: ["HLMethodSourceCode", "String"]
  354. }),
  355. smalltalk.HLAccessorsGenerator);
  356. smalltalk.addMethod(
  357. smalltalk.method({
  358. selector: "setterFor:",
  359. protocol: 'private',
  360. fn: function (anInstanceVariable){
  361. var self=this;
  362. function $HLMethodSourceCode(){return smalltalk.HLMethodSourceCode||(typeof HLMethodSourceCode=="undefined"?nil:HLMethodSourceCode)}
  363. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  364. return smalltalk.withContext(function($ctx1) {
  365. var $2,$4,$5,$3,$1;
  366. $2=_st($HLMethodSourceCode())._new();
  367. _st($2)._selector_(_st(anInstanceVariable).__comma(":"));
  368. $3=_st($2)._sourceCode_(_st($String())._streamContents_((function(stream){
  369. return smalltalk.withContext(function($ctx2) {
  370. $4=_st(stream).__lt_lt(anInstanceVariable);
  371. $ctx2.sendIdx["<<"]=2;
  372. _st($4).__lt_lt(": anObject");
  373. $ctx2.sendIdx["<<"]=1;
  374. $5=_st(_st(stream)._cr())._cr();
  375. $ctx2.sendIdx["cr"]=1;
  376. _st($5)._tab();
  377. return _st(_st(stream).__lt_lt(anInstanceVariable)).__lt_lt(" := anObject");
  378. $ctx2.sendIdx["<<"]=3;
  379. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1,1)})})));
  380. $1=$3;
  381. return $1;
  382. }, function($ctx1) {$ctx1.fill(self,"setterFor:",{anInstanceVariable:anInstanceVariable},smalltalk.HLAccessorsGenerator)})},
  383. args: ["anInstanceVariable"],
  384. source: "setterFor: anInstanceVariable\x0a\x09^ HLMethodSourceCode new\x0a\x09\x09selector: anInstanceVariable, ':';\x0a\x09\x09sourceCode: (String streamContents: [ :stream |\x0a\x09\x09stream << anInstanceVariable << ': anObject'.\x0a\x09\x09stream cr cr tab.\x0a\x09\x09stream << anInstanceVariable << ' := anObject' ])",
  385. messageSends: ["selector:", "new", ",", "sourceCode:", "streamContents:", "<<", "tab", "cr"],
  386. referencedClasses: ["HLMethodSourceCode", "String"]
  387. }),
  388. smalltalk.HLAccessorsGenerator);
  389. smalltalk.addClass('HLInitializeGenerator', smalltalk.HLGenerator, [], 'Helios-Helpers');
  390. smalltalk.HLInitializeGenerator.comment="I am used to double-dispatch the `initialize` method(s) generation.\x0a\x0aUsage:\x0a\x0a ^ HLInitializeGenerator new\x0a class: aClass;\x0a generate;\x0a output\x0a\x0aI am a disposable object";
  391. smalltalk.addMethod(
  392. smalltalk.method({
  393. selector: "computeIndexForObject",
  394. protocol: 'private',
  395. fn: function (){
  396. var self=this;
  397. var instVars,headerSize,firstInstVarSize;
  398. return smalltalk.withContext(function($ctx1) {
  399. var $1;
  400. headerSize=(32);
  401. instVars=_st(_st(self["@output"])._targetClass())._instanceVariableNames();
  402. firstInstVarSize=_st(_st(instVars)._sorted())._ifEmpty_ifNotEmpty_((function(){
  403. return smalltalk.withContext(function($ctx2) {
  404. return (0);
  405. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),(function(){
  406. return smalltalk.withContext(function($ctx2) {
  407. return _st(_st(_st(instVars)._first())._size()).__plus((4));
  408. $ctx2.sendIdx["+"]=1;
  409. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  410. $1=_st(headerSize).__plus(firstInstVarSize);
  411. return $1;
  412. }, function($ctx1) {$ctx1.fill(self,"computeIndexForObject",{instVars:instVars,headerSize:headerSize,firstInstVarSize:firstInstVarSize},smalltalk.HLInitializeGenerator)})},
  413. args: [],
  414. source: "computeIndexForObject\x0a\x09| instVars headerSize firstInstVarSize |\x0a\x09\x0a\x09\x2232 is the size of the `initiliaze super initialize` part\x22\x0a\x09headerSize := 32.\x0a\x09instVars := output targetClass instanceVariableNames.\x0a\x09firstInstVarSize := instVars sorted\x0a\x09\x09ifEmpty: [ 0 ]\x0a\x09\x09ifNotEmpty:[ instVars first size + 4 ].\x0a\x09^ headerSize + firstInstVarSize",
  415. messageSends: ["instanceVariableNames", "targetClass", "ifEmpty:ifNotEmpty:", "sorted", "+", "size", "first"],
  416. referencedClasses: []
  417. }),
  418. smalltalk.HLInitializeGenerator);
  419. smalltalk.addMethod(
  420. smalltalk.method({
  421. selector: "generate",
  422. protocol: 'protocol',
  423. fn: function (){
  424. var self=this;
  425. return smalltalk.withContext(function($ctx1) {
  426. var $1,$2;
  427. smalltalk.HLInitializeGenerator.superclass.fn.prototype._generate.apply(_st(self), []);
  428. $1=_st(self["@output"])._targetClass();
  429. _st($1)._initializeSourceCodesWith_(self);
  430. _st($1)._initializeIndexWith_(self);
  431. $2=_st($1)._initializeProtocolWith_(self);
  432. return self}, function($ctx1) {$ctx1.fill(self,"generate",{},smalltalk.HLInitializeGenerator)})},
  433. args: [],
  434. source: "generate\x0a\x09super generate.\x0a\x09\x0a\x09output targetClass \x0a\x09\x09initializeSourceCodesWith: self;\x0a\x09\x09initializeIndexWith: self;\x0a\x09\x09initializeProtocolWith: self",
  435. messageSends: ["generate", "initializeSourceCodesWith:", "targetClass", "initializeIndexWith:", "initializeProtocolWith:"],
  436. referencedClasses: []
  437. }),
  438. smalltalk.HLInitializeGenerator);
  439. smalltalk.addMethod(
  440. smalltalk.method({
  441. selector: "generateInitializeCodeForObject",
  442. protocol: 'private',
  443. fn: function (){
  444. var self=this;
  445. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  446. return smalltalk.withContext(function($ctx1) {
  447. var $3,$2,$4,$5,$6,$7,$8,$1;
  448. $1=_st($String())._streamContents_((function(str){
  449. var instVars,size;
  450. return smalltalk.withContext(function($ctx2) {
  451. instVars=_st(_st(_st(self["@output"])._targetClass())._instanceVariableNames())._sorted();
  452. instVars;
  453. size=_st(instVars)._size();
  454. size;
  455. _st(str).__lt_lt("initialize");
  456. $ctx2.sendIdx["<<"]=1;
  457. $3=_st(str)._cr();
  458. $ctx2.sendIdx["cr"]=1;
  459. $2=_st($3)._tab();
  460. $ctx2.sendIdx["tab"]=1;
  461. _st($2).__lt_lt("super initialize.");
  462. $ctx2.sendIdx["<<"]=2;
  463. $4=_st($2)._cr();
  464. $ctx2.sendIdx["cr"]=2;
  465. $4;
  466. $5=_st(str)._cr();
  467. $ctx2.sendIdx["cr"]=3;
  468. _st($5)._tab();
  469. $ctx2.sendIdx["tab"]=2;
  470. return _st(instVars)._withIndexDo_((function(name,index){
  471. return smalltalk.withContext(function($ctx3) {
  472. $6=_st(index).__tild_eq((1));
  473. $ctx3.sendIdx["~="]=1;
  474. if(smalltalk.assert($6)){
  475. _st(_st(str)._cr())._tab();
  476. };
  477. $7=_st(str).__lt_lt(name);
  478. $ctx3.sendIdx["<<"]=4;
  479. _st($7).__lt_lt(" := nil");
  480. $ctx3.sendIdx["<<"]=3;
  481. $8=_st(index).__tild_eq(size);
  482. if(smalltalk.assert($8)){
  483. return _st(str).__lt_lt(".");
  484. };
  485. }, function($ctx3) {$ctx3.fillBlock({name:name,index:index},$ctx2,2)})}));
  486. }, function($ctx2) {$ctx2.fillBlock({str:str,instVars:instVars,size:size},$ctx1,1)})}));
  487. return $1;
  488. }, function($ctx1) {$ctx1.fill(self,"generateInitializeCodeForObject",{},smalltalk.HLInitializeGenerator)})},
  489. args: [],
  490. source: "generateInitializeCodeForObject\x09\x0a\x09^ String streamContents: [ :str || instVars size |\x0a\x09\x09instVars := output targetClass instanceVariableNames sorted.\x0a\x09\x09size := instVars size.\x0a\x09\x09str << 'initialize'.\x0a\x09\x09str cr tab << 'super initialize.';cr.\x0a\x09\x09str cr tab.\x0a\x09\x09instVars withIndexDo: [ :name :index |\x0a\x09\x09\x09index ~= 1 ifTrue: [ str cr tab ].\x0a\x09\x09\x09str << name << ' := nil'.\x0a\x09\x09\x09index ~= size ifTrue: [ str << '.' ] ] ].",
  491. messageSends: ["streamContents:", "sorted", "instanceVariableNames", "targetClass", "size", "<<", "tab", "cr", "withIndexDo:", "ifTrue:", "~="],
  492. referencedClasses: ["String"]
  493. }),
  494. smalltalk.HLInitializeGenerator);
  495. smalltalk.addMethod(
  496. smalltalk.method({
  497. selector: "initialize",
  498. protocol: 'initialization',
  499. fn: function (){
  500. var self=this;
  501. function $HLGenerationOutputWithIndex(){return smalltalk.HLGenerationOutputWithIndex||(typeof HLGenerationOutputWithIndex=="undefined"?nil:HLGenerationOutputWithIndex)}
  502. return smalltalk.withContext(function($ctx1) {
  503. smalltalk.HLInitializeGenerator.superclass.fn.prototype._initialize.apply(_st(self), []);
  504. self["@output"]=_st($HLGenerationOutputWithIndex())._new();
  505. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLInitializeGenerator)})},
  506. args: [],
  507. source: "initialize\x0a\x09super initialize.\x0a\x09\x0a\x09output := HLGenerationOutputWithIndex new",
  508. messageSends: ["initialize", "new"],
  509. referencedClasses: ["HLGenerationOutputWithIndex"]
  510. }),
  511. smalltalk.HLInitializeGenerator);
  512. smalltalk.addMethod(
  513. smalltalk.method({
  514. selector: "initializeCodeForObject",
  515. protocol: 'private',
  516. fn: function (){
  517. var self=this;
  518. function $HLMethodSourceCode(){return smalltalk.HLMethodSourceCode||(typeof HLMethodSourceCode=="undefined"?nil:HLMethodSourceCode)}
  519. return smalltalk.withContext(function($ctx1) {
  520. var $2,$3,$1;
  521. $2=_st($HLMethodSourceCode())._new();
  522. _st($2)._selector_("initialize");
  523. _st($2)._sourceCode_(self._generateInitializeCodeForObject());
  524. $3=_st($2)._yourself();
  525. $1=$3;
  526. return $1;
  527. }, function($ctx1) {$ctx1.fill(self,"initializeCodeForObject",{},smalltalk.HLInitializeGenerator)})},
  528. args: [],
  529. source: "initializeCodeForObject\x09\x0a\x09^ HLMethodSourceCode new\x0a\x09\x09selector: 'initialize';\x0a\x09\x09sourceCode: self generateInitializeCodeForObject;\x0a\x09\x09yourself",
  530. messageSends: ["selector:", "new", "sourceCode:", "generateInitializeCodeForObject", "yourself"],
  531. referencedClasses: ["HLMethodSourceCode"]
  532. }),
  533. smalltalk.HLInitializeGenerator);
  534. smalltalk.addMethod(
  535. smalltalk.method({
  536. selector: "initializeForObject",
  537. protocol: 'double-dispatch',
  538. fn: function (){
  539. var self=this;
  540. return smalltalk.withContext(function($ctx1) {
  541. _st(self["@output"])._addSourceCode_(self._initializeCodeForObject());
  542. return self}, function($ctx1) {$ctx1.fill(self,"initializeForObject",{},smalltalk.HLInitializeGenerator)})},
  543. args: [],
  544. source: "initializeForObject\x0a\x09output addSourceCode: self initializeCodeForObject",
  545. messageSends: ["addSourceCode:", "initializeCodeForObject"],
  546. referencedClasses: []
  547. }),
  548. smalltalk.HLInitializeGenerator);
  549. smalltalk.addMethod(
  550. smalltalk.method({
  551. selector: "initializeIndexForObject",
  552. protocol: 'double-dispatch',
  553. fn: function (){
  554. var self=this;
  555. return smalltalk.withContext(function($ctx1) {
  556. _st(self["@output"])._index_(self._computeIndexForObject());
  557. return self}, function($ctx1) {$ctx1.fill(self,"initializeIndexForObject",{},smalltalk.HLInitializeGenerator)})},
  558. args: [],
  559. source: "initializeIndexForObject\x0a\x09output index: self computeIndexForObject",
  560. messageSends: ["index:", "computeIndexForObject"],
  561. referencedClasses: []
  562. }),
  563. smalltalk.HLInitializeGenerator);
  564. smalltalk.addMethod(
  565. smalltalk.method({
  566. selector: "initializeProtocolForObject",
  567. protocol: 'double-dispatch',
  568. fn: function (){
  569. var self=this;
  570. return smalltalk.withContext(function($ctx1) {
  571. _st(self["@output"])._protocol_(self._retrieveProtocolForObject());
  572. return self}, function($ctx1) {$ctx1.fill(self,"initializeProtocolForObject",{},smalltalk.HLInitializeGenerator)})},
  573. args: [],
  574. source: "initializeProtocolForObject\x0a\x09output protocol: self retrieveProtocolForObject",
  575. messageSends: ["protocol:", "retrieveProtocolForObject"],
  576. referencedClasses: []
  577. }),
  578. smalltalk.HLInitializeGenerator);
  579. smalltalk.addMethod(
  580. smalltalk.method({
  581. selector: "retrieveProtocolForObject",
  582. protocol: 'private',
  583. fn: function (){
  584. var self=this;
  585. return smalltalk.withContext(function($ctx1) {
  586. return "initialization";
  587. }, function($ctx1) {$ctx1.fill(self,"retrieveProtocolForObject",{},smalltalk.HLInitializeGenerator)})},
  588. args: [],
  589. source: "retrieveProtocolForObject\x0a\x09^ 'initialization'",
  590. messageSends: [],
  591. referencedClasses: []
  592. }),
  593. smalltalk.HLInitializeGenerator);
  594. smalltalk.addClass('HLMethodSourceCode', smalltalk.Object, ['selector', 'sourceCode'], 'Helios-Helpers');
  595. smalltalk.HLMethodSourceCode.comment="I am a simple data object keeping track of the information about a method that will be compiled at the end of the generation process";
  596. smalltalk.addMethod(
  597. smalltalk.method({
  598. selector: "selector",
  599. protocol: 'accessing',
  600. fn: function (){
  601. var self=this;
  602. return smalltalk.withContext(function($ctx1) {
  603. var $1;
  604. $1=self["@selector"];
  605. return $1;
  606. }, function($ctx1) {$ctx1.fill(self,"selector",{},smalltalk.HLMethodSourceCode)})},
  607. args: [],
  608. source: "selector\x0a\x09^ selector",
  609. messageSends: [],
  610. referencedClasses: []
  611. }),
  612. smalltalk.HLMethodSourceCode);
  613. smalltalk.addMethod(
  614. smalltalk.method({
  615. selector: "selector:",
  616. protocol: 'accessing',
  617. fn: function (aSelector){
  618. var self=this;
  619. return smalltalk.withContext(function($ctx1) {
  620. self["@selector"]=aSelector;
  621. return self}, function($ctx1) {$ctx1.fill(self,"selector:",{aSelector:aSelector},smalltalk.HLMethodSourceCode)})},
  622. args: ["aSelector"],
  623. source: "selector: aSelector\x0a\x09selector := aSelector",
  624. messageSends: [],
  625. referencedClasses: []
  626. }),
  627. smalltalk.HLMethodSourceCode);
  628. smalltalk.addMethod(
  629. smalltalk.method({
  630. selector: "sourceCode",
  631. protocol: 'accessing',
  632. fn: function (){
  633. var self=this;
  634. return smalltalk.withContext(function($ctx1) {
  635. var $1;
  636. $1=self["@sourceCode"];
  637. return $1;
  638. }, function($ctx1) {$ctx1.fill(self,"sourceCode",{},smalltalk.HLMethodSourceCode)})},
  639. args: [],
  640. source: "sourceCode\x0a\x09^ sourceCode",
  641. messageSends: [],
  642. referencedClasses: []
  643. }),
  644. smalltalk.HLMethodSourceCode);
  645. smalltalk.addMethod(
  646. smalltalk.method({
  647. selector: "sourceCode:",
  648. protocol: 'accessing',
  649. fn: function (aString){
  650. var self=this;
  651. return smalltalk.withContext(function($ctx1) {
  652. self["@sourceCode"]=aString;
  653. return self}, function($ctx1) {$ctx1.fill(self,"sourceCode:",{aString:aString},smalltalk.HLMethodSourceCode)})},
  654. args: ["aString"],
  655. source: "sourceCode: aString\x0a\x09sourceCode := aString",
  656. messageSends: [],
  657. referencedClasses: []
  658. }),
  659. smalltalk.HLMethodSourceCode);
  660. });