Helios-Helpers.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  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: "compile",
  24. protocol: 'protocol',
  25. fn: function (){
  26. var self=this;
  27. return smalltalk.withContext(function($ctx1) {
  28. var $1;
  29. _st(self["@sourceCodes"])._do_((function(methodSourceCode){
  30. return smalltalk.withContext(function($ctx2) {
  31. $1=_st(self["@targetClass"])._includesSelector_(_st(methodSourceCode)._selector());
  32. if(! smalltalk.assert($1)){
  33. return _st(self["@targetClass"])._compile_protocol_(_st(methodSourceCode)._sourceCode(),self["@protocol"]);
  34. };
  35. }, function($ctx2) {$ctx2.fillBlock({methodSourceCode:methodSourceCode},$ctx1,1)})}));
  36. return self}, function($ctx1) {$ctx1.fill(self,"compile",{},smalltalk.HLGenerationOutput)})},
  37. args: [],
  38. source: "compile\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 ] ]",
  39. messageSends: ["do:", "ifFalse:", "includesSelector:", "selector", "compile:protocol:", "sourceCode"],
  40. referencedClasses: []
  41. }),
  42. smalltalk.HLGenerationOutput);
  43. smalltalk.addMethod(
  44. smalltalk.method({
  45. selector: "initialize",
  46. protocol: 'initialization',
  47. fn: function (){
  48. var self=this;
  49. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  50. return smalltalk.withContext(function($ctx1) {
  51. smalltalk.HLGenerationOutput.superclass.fn.prototype._initialize.apply(_st(self), []);
  52. self["@sourceCodes"]=_st($OrderedCollection())._new();
  53. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLGenerationOutput)})},
  54. args: [],
  55. source: "initialize\x0a\x09super initialize.\x0a\x09\x0a\x09sourceCodes := OrderedCollection new",
  56. messageSends: ["initialize", "new"],
  57. referencedClasses: ["OrderedCollection"]
  58. }),
  59. smalltalk.HLGenerationOutput);
  60. smalltalk.addMethod(
  61. smalltalk.method({
  62. selector: "protocol",
  63. protocol: 'accessing',
  64. fn: function (){
  65. var self=this;
  66. return smalltalk.withContext(function($ctx1) {
  67. var $1;
  68. $1=self["@protocol"];
  69. return $1;
  70. }, function($ctx1) {$ctx1.fill(self,"protocol",{},smalltalk.HLGenerationOutput)})},
  71. args: [],
  72. source: "protocol\x0a\x09^ protocol",
  73. messageSends: [],
  74. referencedClasses: []
  75. }),
  76. smalltalk.HLGenerationOutput);
  77. smalltalk.addMethod(
  78. smalltalk.method({
  79. selector: "protocol:",
  80. protocol: 'accessing',
  81. fn: function (aString){
  82. var self=this;
  83. return smalltalk.withContext(function($ctx1) {
  84. self["@protocol"]=aString;
  85. return self}, function($ctx1) {$ctx1.fill(self,"protocol:",{aString:aString},smalltalk.HLGenerationOutput)})},
  86. args: ["aString"],
  87. source: "protocol: aString\x0a\x09protocol := aString",
  88. messageSends: [],
  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\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,$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. _st(_st(stream)._cr())._tab();
  342. return _st(_st(stream).__lt_lt("^ ")).__lt_lt(anInstanceVariable);
  343. $ctx2.sendIdx["<<"]=2;
  344. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1,1)})})));
  345. $1=$3;
  346. return $1;
  347. }, function($ctx1) {$ctx1.fill(self,"getterFor:",{anInstanceVariable:anInstanceVariable},smalltalk.HLAccessorsGenerator)})},
  348. args: ["anInstanceVariable"],
  349. 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 tab.\x0a\x09\x09stream << '^ ' << anInstanceVariable ])",
  350. messageSends: ["selector:", "new", "sourceCode:", "streamContents:", "<<", "tab", "cr"],
  351. referencedClasses: ["HLMethodSourceCode", "String"]
  352. }),
  353. smalltalk.HLAccessorsGenerator);
  354. smalltalk.addMethod(
  355. smalltalk.method({
  356. selector: "setterFor:",
  357. protocol: 'private',
  358. fn: function (anInstanceVariable){
  359. var self=this;
  360. function $HLMethodSourceCode(){return smalltalk.HLMethodSourceCode||(typeof HLMethodSourceCode=="undefined"?nil:HLMethodSourceCode)}
  361. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  362. return smalltalk.withContext(function($ctx1) {
  363. var $2,$4,$3,$1;
  364. $2=_st($HLMethodSourceCode())._new();
  365. _st($2)._selector_(_st(anInstanceVariable).__comma(":"));
  366. $3=_st($2)._sourceCode_(_st($String())._streamContents_((function(stream){
  367. return smalltalk.withContext(function($ctx2) {
  368. $4=_st(stream).__lt_lt(anInstanceVariable);
  369. $ctx2.sendIdx["<<"]=2;
  370. _st($4).__lt_lt(": anObject");
  371. $ctx2.sendIdx["<<"]=1;
  372. _st(_st(stream)._cr())._tab();
  373. return _st(_st(stream).__lt_lt(anInstanceVariable)).__lt_lt(" := anObject");
  374. $ctx2.sendIdx["<<"]=3;
  375. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1,1)})})));
  376. $1=$3;
  377. return $1;
  378. }, function($ctx1) {$ctx1.fill(self,"setterFor:",{anInstanceVariable:anInstanceVariable},smalltalk.HLAccessorsGenerator)})},
  379. args: ["anInstanceVariable"],
  380. 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 tab.\x0a\x09\x09stream << anInstanceVariable << ' := anObject' ])",
  381. messageSends: ["selector:", "new", ",", "sourceCode:", "streamContents:", "<<", "tab", "cr"],
  382. referencedClasses: ["HLMethodSourceCode", "String"]
  383. }),
  384. smalltalk.HLAccessorsGenerator);
  385. smalltalk.addClass('HLInitializeGenerator', smalltalk.HLGenerator, [], 'Helios-Helpers');
  386. 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";
  387. smalltalk.addMethod(
  388. smalltalk.method({
  389. selector: "computeIndexForObject",
  390. protocol: 'private',
  391. fn: function (){
  392. var self=this;
  393. var instVars,headerSize,firstInstVarSize;
  394. return smalltalk.withContext(function($ctx1) {
  395. var $1;
  396. headerSize=(32);
  397. instVars=_st(_st(self["@output"])._targetClass())._instanceVariableNames();
  398. firstInstVarSize=_st(_st(instVars)._sorted())._ifEmpty_ifNotEmpty_((function(){
  399. return smalltalk.withContext(function($ctx2) {
  400. return (0);
  401. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),(function(){
  402. return smalltalk.withContext(function($ctx2) {
  403. return _st(_st(_st(instVars)._first())._size()).__plus((4));
  404. $ctx2.sendIdx["+"]=1;
  405. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  406. $1=_st(headerSize).__plus(firstInstVarSize);
  407. return $1;
  408. }, function($ctx1) {$ctx1.fill(self,"computeIndexForObject",{instVars:instVars,headerSize:headerSize,firstInstVarSize:firstInstVarSize},smalltalk.HLInitializeGenerator)})},
  409. args: [],
  410. 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",
  411. messageSends: ["instanceVariableNames", "targetClass", "ifEmpty:ifNotEmpty:", "sorted", "+", "size", "first"],
  412. referencedClasses: []
  413. }),
  414. smalltalk.HLInitializeGenerator);
  415. smalltalk.addMethod(
  416. smalltalk.method({
  417. selector: "generate",
  418. protocol: 'protocol',
  419. fn: function (){
  420. var self=this;
  421. return smalltalk.withContext(function($ctx1) {
  422. var $1,$2;
  423. smalltalk.HLInitializeGenerator.superclass.fn.prototype._generate.apply(_st(self), []);
  424. $1=_st(self["@output"])._targetClass();
  425. _st($1)._initializeSourceCodesWith_(self);
  426. _st($1)._initializeIndexWith_(self);
  427. $2=_st($1)._initializeProtocolWith_(self);
  428. return self}, function($ctx1) {$ctx1.fill(self,"generate",{},smalltalk.HLInitializeGenerator)})},
  429. args: [],
  430. source: "generate\x0a\x09super generate.\x0a\x09\x0a\x09output targetClass \x0a\x09\x09initializeSourceCodesWith: self;\x0a\x09\x09initializeIndexWith: self;\x0a\x09\x09initializeProtocolWith: self",
  431. messageSends: ["generate", "initializeSourceCodesWith:", "targetClass", "initializeIndexWith:", "initializeProtocolWith:"],
  432. referencedClasses: []
  433. }),
  434. smalltalk.HLInitializeGenerator);
  435. smalltalk.addMethod(
  436. smalltalk.method({
  437. selector: "generateInitializeCodeForObject",
  438. protocol: 'private',
  439. fn: function (){
  440. var self=this;
  441. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  442. return smalltalk.withContext(function($ctx1) {
  443. var $3,$2,$4,$5,$6,$7,$8,$1;
  444. $1=_st($String())._streamContents_((function(str){
  445. var instVars,size;
  446. return smalltalk.withContext(function($ctx2) {
  447. instVars=_st(_st(_st(self["@output"])._targetClass())._instanceVariableNames())._sorted();
  448. instVars;
  449. size=_st(instVars)._size();
  450. size;
  451. _st(str).__lt_lt("initialize");
  452. $ctx2.sendIdx["<<"]=1;
  453. $3=_st(str)._cr();
  454. $ctx2.sendIdx["cr"]=1;
  455. $2=_st($3)._tab();
  456. $ctx2.sendIdx["tab"]=1;
  457. _st($2).__lt_lt("super initialize.");
  458. $ctx2.sendIdx["<<"]=2;
  459. $4=_st($2)._cr();
  460. $ctx2.sendIdx["cr"]=2;
  461. $4;
  462. $5=_st(str)._cr();
  463. $ctx2.sendIdx["cr"]=3;
  464. _st($5)._tab();
  465. $ctx2.sendIdx["tab"]=2;
  466. return _st(instVars)._withIndexDo_((function(name,index){
  467. return smalltalk.withContext(function($ctx3) {
  468. $6=_st(index).__tild_eq((1));
  469. $ctx3.sendIdx["~="]=1;
  470. if(smalltalk.assert($6)){
  471. _st(_st(str)._cr())._tab();
  472. };
  473. $7=_st(str).__lt_lt(name);
  474. $ctx3.sendIdx["<<"]=4;
  475. _st($7).__lt_lt(" := nil");
  476. $ctx3.sendIdx["<<"]=3;
  477. $8=_st(index).__tild_eq(size);
  478. if(smalltalk.assert($8)){
  479. return _st(str).__lt_lt(".");
  480. };
  481. }, function($ctx3) {$ctx3.fillBlock({name:name,index:index},$ctx2,2)})}));
  482. }, function($ctx2) {$ctx2.fillBlock({str:str,instVars:instVars,size:size},$ctx1,1)})}));
  483. return $1;
  484. }, function($ctx1) {$ctx1.fill(self,"generateInitializeCodeForObject",{},smalltalk.HLInitializeGenerator)})},
  485. args: [],
  486. 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 << '.' ] ] ].",
  487. messageSends: ["streamContents:", "sorted", "instanceVariableNames", "targetClass", "size", "<<", "tab", "cr", "withIndexDo:", "ifTrue:", "~="],
  488. referencedClasses: ["String"]
  489. }),
  490. smalltalk.HLInitializeGenerator);
  491. smalltalk.addMethod(
  492. smalltalk.method({
  493. selector: "initialize",
  494. protocol: 'initialization',
  495. fn: function (){
  496. var self=this;
  497. function $HLGenerationOutputWithIndex(){return smalltalk.HLGenerationOutputWithIndex||(typeof HLGenerationOutputWithIndex=="undefined"?nil:HLGenerationOutputWithIndex)}
  498. return smalltalk.withContext(function($ctx1) {
  499. smalltalk.HLInitializeGenerator.superclass.fn.prototype._initialize.apply(_st(self), []);
  500. self["@output"]=_st($HLGenerationOutputWithIndex())._new();
  501. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.HLInitializeGenerator)})},
  502. args: [],
  503. source: "initialize\x0a\x09super initialize.\x0a\x09\x0a\x09output := HLGenerationOutputWithIndex new",
  504. messageSends: ["initialize", "new"],
  505. referencedClasses: ["HLGenerationOutputWithIndex"]
  506. }),
  507. smalltalk.HLInitializeGenerator);
  508. smalltalk.addMethod(
  509. smalltalk.method({
  510. selector: "initializeCodeForObject",
  511. protocol: 'private',
  512. fn: function (){
  513. var self=this;
  514. function $HLMethodSourceCode(){return smalltalk.HLMethodSourceCode||(typeof HLMethodSourceCode=="undefined"?nil:HLMethodSourceCode)}
  515. return smalltalk.withContext(function($ctx1) {
  516. var $2,$3,$1;
  517. $2=_st($HLMethodSourceCode())._new();
  518. _st($2)._selector_("initialize");
  519. _st($2)._sourceCode_(self._generateInitializeCodeForObject());
  520. $3=_st($2)._yourself();
  521. $1=$3;
  522. return $1;
  523. }, function($ctx1) {$ctx1.fill(self,"initializeCodeForObject",{},smalltalk.HLInitializeGenerator)})},
  524. args: [],
  525. source: "initializeCodeForObject\x09\x0a\x09^ HLMethodSourceCode new\x0a\x09\x09selector: 'initialize';\x0a\x09\x09sourceCode: self generateInitializeCodeForObject;\x0a\x09\x09yourself",
  526. messageSends: ["selector:", "new", "sourceCode:", "generateInitializeCodeForObject", "yourself"],
  527. referencedClasses: ["HLMethodSourceCode"]
  528. }),
  529. smalltalk.HLInitializeGenerator);
  530. smalltalk.addMethod(
  531. smalltalk.method({
  532. selector: "initializeForObject",
  533. protocol: 'double-dispatch',
  534. fn: function (){
  535. var self=this;
  536. return smalltalk.withContext(function($ctx1) {
  537. _st(self["@output"])._addSourceCode_(self._initializeCodeForObject());
  538. return self}, function($ctx1) {$ctx1.fill(self,"initializeForObject",{},smalltalk.HLInitializeGenerator)})},
  539. args: [],
  540. source: "initializeForObject\x0a\x09output addSourceCode: self initializeCodeForObject",
  541. messageSends: ["addSourceCode:", "initializeCodeForObject"],
  542. referencedClasses: []
  543. }),
  544. smalltalk.HLInitializeGenerator);
  545. smalltalk.addMethod(
  546. smalltalk.method({
  547. selector: "initializeIndexForObject",
  548. protocol: 'double-dispatch',
  549. fn: function (){
  550. var self=this;
  551. return smalltalk.withContext(function($ctx1) {
  552. _st(self["@output"])._index_(self._computeIndexForObject());
  553. return self}, function($ctx1) {$ctx1.fill(self,"initializeIndexForObject",{},smalltalk.HLInitializeGenerator)})},
  554. args: [],
  555. source: "initializeIndexForObject\x0a\x09output index: self computeIndexForObject",
  556. messageSends: ["index:", "computeIndexForObject"],
  557. referencedClasses: []
  558. }),
  559. smalltalk.HLInitializeGenerator);
  560. smalltalk.addMethod(
  561. smalltalk.method({
  562. selector: "initializeProtocolForObject",
  563. protocol: 'double-dispatch',
  564. fn: function (){
  565. var self=this;
  566. return smalltalk.withContext(function($ctx1) {
  567. _st(self["@output"])._protocol_(self._retrieveProtocolForObject());
  568. return self}, function($ctx1) {$ctx1.fill(self,"initializeProtocolForObject",{},smalltalk.HLInitializeGenerator)})},
  569. args: [],
  570. source: "initializeProtocolForObject\x0a\x09output protocol: self retrieveProtocolForObject",
  571. messageSends: ["protocol:", "retrieveProtocolForObject"],
  572. referencedClasses: []
  573. }),
  574. smalltalk.HLInitializeGenerator);
  575. smalltalk.addMethod(
  576. smalltalk.method({
  577. selector: "retrieveProtocolForObject",
  578. protocol: 'private',
  579. fn: function (){
  580. var self=this;
  581. return smalltalk.withContext(function($ctx1) {
  582. return "initialization";
  583. }, function($ctx1) {$ctx1.fill(self,"retrieveProtocolForObject",{},smalltalk.HLInitializeGenerator)})},
  584. args: [],
  585. source: "retrieveProtocolForObject\x0a\x09^ 'initialization'",
  586. messageSends: [],
  587. referencedClasses: []
  588. }),
  589. smalltalk.HLInitializeGenerator);
  590. smalltalk.addClass('HLMethodSourceCode', smalltalk.Object, ['selector', 'sourceCode'], 'Helios-Helpers');
  591. 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";
  592. smalltalk.addMethod(
  593. smalltalk.method({
  594. selector: "selector",
  595. protocol: 'accessing',
  596. fn: function (){
  597. var self=this;
  598. return smalltalk.withContext(function($ctx1) {
  599. var $1;
  600. $1=self["@selector"];
  601. return $1;
  602. }, function($ctx1) {$ctx1.fill(self,"selector",{},smalltalk.HLMethodSourceCode)})},
  603. args: [],
  604. source: "selector\x0a\x09^ selector",
  605. messageSends: [],
  606. referencedClasses: []
  607. }),
  608. smalltalk.HLMethodSourceCode);
  609. smalltalk.addMethod(
  610. smalltalk.method({
  611. selector: "selector:",
  612. protocol: 'accessing',
  613. fn: function (aSelector){
  614. var self=this;
  615. return smalltalk.withContext(function($ctx1) {
  616. self["@selector"]=aSelector;
  617. return self}, function($ctx1) {$ctx1.fill(self,"selector:",{aSelector:aSelector},smalltalk.HLMethodSourceCode)})},
  618. args: ["aSelector"],
  619. source: "selector: aSelector\x0a\x09selector := aSelector",
  620. messageSends: [],
  621. referencedClasses: []
  622. }),
  623. smalltalk.HLMethodSourceCode);
  624. smalltalk.addMethod(
  625. smalltalk.method({
  626. selector: "sourceCode",
  627. protocol: 'accessing',
  628. fn: function (){
  629. var self=this;
  630. return smalltalk.withContext(function($ctx1) {
  631. var $1;
  632. $1=self["@sourceCode"];
  633. return $1;
  634. }, function($ctx1) {$ctx1.fill(self,"sourceCode",{},smalltalk.HLMethodSourceCode)})},
  635. args: [],
  636. source: "sourceCode\x0a\x09^ sourceCode",
  637. messageSends: [],
  638. referencedClasses: []
  639. }),
  640. smalltalk.HLMethodSourceCode);
  641. smalltalk.addMethod(
  642. smalltalk.method({
  643. selector: "sourceCode:",
  644. protocol: 'accessing',
  645. fn: function (aString){
  646. var self=this;
  647. return smalltalk.withContext(function($ctx1) {
  648. self["@sourceCode"]=aString;
  649. return self}, function($ctx1) {$ctx1.fill(self,"sourceCode:",{aString:aString},smalltalk.HLMethodSourceCode)})},
  650. args: ["aString"],
  651. source: "sourceCode: aString\x0a\x09sourceCode := aString",
  652. messageSends: [],
  653. referencedClasses: []
  654. }),
  655. smalltalk.HLMethodSourceCode);
  656. });