Compiler-Inlining.js 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742
  1. define("amber_core/Compiler-Inlining", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_core/Compiler-IR", "amber_core/Kernel-Objects", "amber_core/Compiler-Core"], function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Compiler-Inlining');
  3. smalltalk.packages["Compiler-Inlining"].transport = {"type":"amd","amdNamespace":"amber_core"};
  4. smalltalk.addClass('IRInlinedAssignment', smalltalk.IRAssignment, [], 'Compiler-Inlining');
  5. smalltalk.IRInlinedAssignment.comment="I represent an inlined assignment instruction.";
  6. smalltalk.addMethod(
  7. smalltalk.method({
  8. selector: "accept:",
  9. category: 'visiting',
  10. fn: function (aVisitor){
  11. var self=this;
  12. return smalltalk.withContext(function($ctx1) {
  13. var $1;
  14. $1=_st(aVisitor)._visitIRInlinedAssignment_(self);
  15. return $1;
  16. }, function($ctx1) {$ctx1.fill(self,"accept:",{aVisitor:aVisitor},smalltalk.IRInlinedAssignment)})},
  17. args: ["aVisitor"],
  18. source: "accept: aVisitor\x0a\x09^ aVisitor visitIRInlinedAssignment: self",
  19. messageSends: ["visitIRInlinedAssignment:"],
  20. referencedClasses: []
  21. }),
  22. smalltalk.IRInlinedAssignment);
  23. smalltalk.addMethod(
  24. smalltalk.method({
  25. selector: "isInlined",
  26. category: 'testing',
  27. fn: function (){
  28. var self=this;
  29. return smalltalk.withContext(function($ctx1) {
  30. return true;
  31. }, function($ctx1) {$ctx1.fill(self,"isInlined",{},smalltalk.IRInlinedAssignment)})},
  32. args: [],
  33. source: "isInlined\x0a\x09^ true",
  34. messageSends: [],
  35. referencedClasses: []
  36. }),
  37. smalltalk.IRInlinedAssignment);
  38. smalltalk.addClass('IRInlinedClosure', smalltalk.IRClosure, [], 'Compiler-Inlining');
  39. smalltalk.IRInlinedClosure.comment="I represent an inlined closure instruction.";
  40. smalltalk.addMethod(
  41. smalltalk.method({
  42. selector: "accept:",
  43. category: 'visiting',
  44. fn: function (aVisitor){
  45. var self=this;
  46. return smalltalk.withContext(function($ctx1) {
  47. _st(aVisitor)._visitIRInlinedClosure_(self);
  48. return self}, function($ctx1) {$ctx1.fill(self,"accept:",{aVisitor:aVisitor},smalltalk.IRInlinedClosure)})},
  49. args: ["aVisitor"],
  50. source: "accept: aVisitor\x0a\x09aVisitor visitIRInlinedClosure: self",
  51. messageSends: ["visitIRInlinedClosure:"],
  52. referencedClasses: []
  53. }),
  54. smalltalk.IRInlinedClosure);
  55. smalltalk.addMethod(
  56. smalltalk.method({
  57. selector: "isInlined",
  58. category: 'testing',
  59. fn: function (){
  60. var self=this;
  61. return smalltalk.withContext(function($ctx1) {
  62. return true;
  63. }, function($ctx1) {$ctx1.fill(self,"isInlined",{},smalltalk.IRInlinedClosure)})},
  64. args: [],
  65. source: "isInlined\x0a\x09^ true",
  66. messageSends: [],
  67. referencedClasses: []
  68. }),
  69. smalltalk.IRInlinedClosure);
  70. smalltalk.addClass('IRInlinedReturn', smalltalk.IRReturn, [], 'Compiler-Inlining');
  71. smalltalk.IRInlinedReturn.comment="I represent an inlined local return instruction.";
  72. smalltalk.addMethod(
  73. smalltalk.method({
  74. selector: "accept:",
  75. category: 'visiting',
  76. fn: function (aVisitor){
  77. var self=this;
  78. return smalltalk.withContext(function($ctx1) {
  79. var $1;
  80. $1=_st(aVisitor)._visitIRInlinedReturn_(self);
  81. return $1;
  82. }, function($ctx1) {$ctx1.fill(self,"accept:",{aVisitor:aVisitor},smalltalk.IRInlinedReturn)})},
  83. args: ["aVisitor"],
  84. source: "accept: aVisitor\x0a\x09^ aVisitor visitIRInlinedReturn: self",
  85. messageSends: ["visitIRInlinedReturn:"],
  86. referencedClasses: []
  87. }),
  88. smalltalk.IRInlinedReturn);
  89. smalltalk.addMethod(
  90. smalltalk.method({
  91. selector: "isInlined",
  92. category: 'testing',
  93. fn: function (){
  94. var self=this;
  95. return smalltalk.withContext(function($ctx1) {
  96. return true;
  97. }, function($ctx1) {$ctx1.fill(self,"isInlined",{},smalltalk.IRInlinedReturn)})},
  98. args: [],
  99. source: "isInlined\x0a\x09^ true",
  100. messageSends: [],
  101. referencedClasses: []
  102. }),
  103. smalltalk.IRInlinedReturn);
  104. smalltalk.addClass('IRInlinedSend', smalltalk.IRSend, [], 'Compiler-Inlining');
  105. smalltalk.IRInlinedSend.comment="I am the abstract super class of inlined message send instructions.";
  106. smalltalk.addMethod(
  107. smalltalk.method({
  108. selector: "accept:",
  109. category: 'visiting',
  110. fn: function (aVisitor){
  111. var self=this;
  112. return smalltalk.withContext(function($ctx1) {
  113. _st(aVisitor)._visitInlinedSend_(self);
  114. return self}, function($ctx1) {$ctx1.fill(self,"accept:",{aVisitor:aVisitor},smalltalk.IRInlinedSend)})},
  115. args: ["aVisitor"],
  116. source: "accept: aVisitor\x0a\x09aVisitor visitInlinedSend: self",
  117. messageSends: ["visitInlinedSend:"],
  118. referencedClasses: []
  119. }),
  120. smalltalk.IRInlinedSend);
  121. smalltalk.addMethod(
  122. smalltalk.method({
  123. selector: "isInlined",
  124. category: 'testing',
  125. fn: function (){
  126. var self=this;
  127. return smalltalk.withContext(function($ctx1) {
  128. return true;
  129. }, function($ctx1) {$ctx1.fill(self,"isInlined",{},smalltalk.IRInlinedSend)})},
  130. args: [],
  131. source: "isInlined\x0a\x09^ true",
  132. messageSends: [],
  133. referencedClasses: []
  134. }),
  135. smalltalk.IRInlinedSend);
  136. smalltalk.addClass('IRInlinedIfFalse', smalltalk.IRInlinedSend, [], 'Compiler-Inlining');
  137. smalltalk.IRInlinedIfFalse.comment="I represent an inlined `#ifFalse:` message send instruction.";
  138. smalltalk.addMethod(
  139. smalltalk.method({
  140. selector: "accept:",
  141. category: 'visiting',
  142. fn: function (aVisitor){
  143. var self=this;
  144. return smalltalk.withContext(function($ctx1) {
  145. _st(aVisitor)._visitIRInlinedIfFalse_(self);
  146. return self}, function($ctx1) {$ctx1.fill(self,"accept:",{aVisitor:aVisitor},smalltalk.IRInlinedIfFalse)})},
  147. args: ["aVisitor"],
  148. source: "accept: aVisitor\x0a\x09aVisitor visitIRInlinedIfFalse: self",
  149. messageSends: ["visitIRInlinedIfFalse:"],
  150. referencedClasses: []
  151. }),
  152. smalltalk.IRInlinedIfFalse);
  153. smalltalk.addClass('IRInlinedIfNilIfNotNil', smalltalk.IRInlinedSend, [], 'Compiler-Inlining');
  154. smalltalk.IRInlinedIfNilIfNotNil.comment="I represent an inlined `#ifNil:ifNotNil:` message send instruction.";
  155. smalltalk.addMethod(
  156. smalltalk.method({
  157. selector: "accept:",
  158. category: 'visiting',
  159. fn: function (aVisitor){
  160. var self=this;
  161. return smalltalk.withContext(function($ctx1) {
  162. _st(aVisitor)._visitIRInlinedIfNilIfNotNil_(self);
  163. return self}, function($ctx1) {$ctx1.fill(self,"accept:",{aVisitor:aVisitor},smalltalk.IRInlinedIfNilIfNotNil)})},
  164. args: ["aVisitor"],
  165. source: "accept: aVisitor\x0a\x09aVisitor visitIRInlinedIfNilIfNotNil: self",
  166. messageSends: ["visitIRInlinedIfNilIfNotNil:"],
  167. referencedClasses: []
  168. }),
  169. smalltalk.IRInlinedIfNilIfNotNil);
  170. smalltalk.addClass('IRInlinedIfTrue', smalltalk.IRInlinedSend, [], 'Compiler-Inlining');
  171. smalltalk.IRInlinedIfTrue.comment="I represent an inlined `#ifTrue:` message send instruction.";
  172. smalltalk.addMethod(
  173. smalltalk.method({
  174. selector: "accept:",
  175. category: 'visiting',
  176. fn: function (aVisitor){
  177. var self=this;
  178. return smalltalk.withContext(function($ctx1) {
  179. _st(aVisitor)._visitIRInlinedIfTrue_(self);
  180. return self}, function($ctx1) {$ctx1.fill(self,"accept:",{aVisitor:aVisitor},smalltalk.IRInlinedIfTrue)})},
  181. args: ["aVisitor"],
  182. source: "accept: aVisitor\x0a\x09aVisitor visitIRInlinedIfTrue: self",
  183. messageSends: ["visitIRInlinedIfTrue:"],
  184. referencedClasses: []
  185. }),
  186. smalltalk.IRInlinedIfTrue);
  187. smalltalk.addClass('IRInlinedIfTrueIfFalse', smalltalk.IRInlinedSend, [], 'Compiler-Inlining');
  188. smalltalk.IRInlinedIfTrueIfFalse.comment="I represent an inlined `#ifTrue:ifFalse:` message send instruction.";
  189. smalltalk.addMethod(
  190. smalltalk.method({
  191. selector: "accept:",
  192. category: 'visiting',
  193. fn: function (aVisitor){
  194. var self=this;
  195. return smalltalk.withContext(function($ctx1) {
  196. _st(aVisitor)._visitIRInlinedIfTrueIfFalse_(self);
  197. return self}, function($ctx1) {$ctx1.fill(self,"accept:",{aVisitor:aVisitor},smalltalk.IRInlinedIfTrueIfFalse)})},
  198. args: ["aVisitor"],
  199. source: "accept: aVisitor\x0a\x09aVisitor visitIRInlinedIfTrueIfFalse: self",
  200. messageSends: ["visitIRInlinedIfTrueIfFalse:"],
  201. referencedClasses: []
  202. }),
  203. smalltalk.IRInlinedIfTrueIfFalse);
  204. smalltalk.addClass('IRInlinedSequence', smalltalk.IRBlockSequence, [], 'Compiler-Inlining');
  205. smalltalk.IRInlinedSequence.comment="I represent a (block) sequence inside an inlined closure instruction (instance of `IRInlinedClosure`).";
  206. smalltalk.addMethod(
  207. smalltalk.method({
  208. selector: "accept:",
  209. category: 'visiting',
  210. fn: function (aVisitor){
  211. var self=this;
  212. return smalltalk.withContext(function($ctx1) {
  213. _st(aVisitor)._visitIRInlinedSequence_(self);
  214. return self}, function($ctx1) {$ctx1.fill(self,"accept:",{aVisitor:aVisitor},smalltalk.IRInlinedSequence)})},
  215. args: ["aVisitor"],
  216. source: "accept: aVisitor\x0a\x09aVisitor visitIRInlinedSequence: self",
  217. messageSends: ["visitIRInlinedSequence:"],
  218. referencedClasses: []
  219. }),
  220. smalltalk.IRInlinedSequence);
  221. smalltalk.addMethod(
  222. smalltalk.method({
  223. selector: "isInlined",
  224. category: 'testing',
  225. fn: function (){
  226. var self=this;
  227. return smalltalk.withContext(function($ctx1) {
  228. return true;
  229. }, function($ctx1) {$ctx1.fill(self,"isInlined",{},smalltalk.IRInlinedSequence)})},
  230. args: [],
  231. source: "isInlined\x0a\x09^ true",
  232. messageSends: [],
  233. referencedClasses: []
  234. }),
  235. smalltalk.IRInlinedSequence);
  236. smalltalk.addClass('IRInliner', smalltalk.IRVisitor, [], 'Compiler-Inlining');
  237. smalltalk.IRInliner.comment="I visit an IR tree, inlining message sends and block closures.\x0a\x0aMessage selectors that can be inlined are answered by `IRSendInliner >> #inlinedSelectors`";
  238. smalltalk.addMethod(
  239. smalltalk.method({
  240. selector: "assignmentInliner",
  241. category: 'factory',
  242. fn: function (){
  243. var self=this;
  244. function $IRAssignmentInliner(){return smalltalk.IRAssignmentInliner||(typeof IRAssignmentInliner=="undefined"?nil:IRAssignmentInliner)}
  245. return smalltalk.withContext(function($ctx1) {
  246. var $2,$3,$1;
  247. $2=_st($IRAssignmentInliner())._new();
  248. _st($2)._translator_(self);
  249. $3=_st($2)._yourself();
  250. $1=$3;
  251. return $1;
  252. }, function($ctx1) {$ctx1.fill(self,"assignmentInliner",{},smalltalk.IRInliner)})},
  253. args: [],
  254. source: "assignmentInliner\x0a\x09^ IRAssignmentInliner new\x0a\x09\x09translator: self;\x0a\x09\x09yourself",
  255. messageSends: ["translator:", "new", "yourself"],
  256. referencedClasses: ["IRAssignmentInliner"]
  257. }),
  258. smalltalk.IRInliner);
  259. smalltalk.addMethod(
  260. smalltalk.method({
  261. selector: "returnInliner",
  262. category: 'factory',
  263. fn: function (){
  264. var self=this;
  265. function $IRReturnInliner(){return smalltalk.IRReturnInliner||(typeof IRReturnInliner=="undefined"?nil:IRReturnInliner)}
  266. return smalltalk.withContext(function($ctx1) {
  267. var $2,$3,$1;
  268. $2=_st($IRReturnInliner())._new();
  269. _st($2)._translator_(self);
  270. $3=_st($2)._yourself();
  271. $1=$3;
  272. return $1;
  273. }, function($ctx1) {$ctx1.fill(self,"returnInliner",{},smalltalk.IRInliner)})},
  274. args: [],
  275. source: "returnInliner\x0a\x09^ IRReturnInliner new\x0a\x09\x09translator: self;\x0a\x09\x09yourself",
  276. messageSends: ["translator:", "new", "yourself"],
  277. referencedClasses: ["IRReturnInliner"]
  278. }),
  279. smalltalk.IRInliner);
  280. smalltalk.addMethod(
  281. smalltalk.method({
  282. selector: "sendInliner",
  283. category: 'factory',
  284. fn: function (){
  285. var self=this;
  286. function $IRSendInliner(){return smalltalk.IRSendInliner||(typeof IRSendInliner=="undefined"?nil:IRSendInliner)}
  287. return smalltalk.withContext(function($ctx1) {
  288. var $2,$3,$1;
  289. $2=_st($IRSendInliner())._new();
  290. _st($2)._translator_(self);
  291. $3=_st($2)._yourself();
  292. $1=$3;
  293. return $1;
  294. }, function($ctx1) {$ctx1.fill(self,"sendInliner",{},smalltalk.IRInliner)})},
  295. args: [],
  296. source: "sendInliner\x0a\x09^ IRSendInliner new\x0a\x09\x09translator: self;\x0a\x09\x09yourself",
  297. messageSends: ["translator:", "new", "yourself"],
  298. referencedClasses: ["IRSendInliner"]
  299. }),
  300. smalltalk.IRInliner);
  301. smalltalk.addMethod(
  302. smalltalk.method({
  303. selector: "shouldInlineAssignment:",
  304. category: 'testing',
  305. fn: function (anIRAssignment){
  306. var self=this;
  307. return smalltalk.withContext(function($ctx1) {
  308. var $4,$3,$2,$6,$5,$1;
  309. $1=_st(_st(_st(anIRAssignment)._isInlined())._not())._and_((function(){
  310. return smalltalk.withContext(function($ctx2) {
  311. $4=_st(anIRAssignment)._instructions();
  312. $ctx2.sendIdx["instructions"]=1;
  313. $3=_st($4)._last();
  314. $ctx2.sendIdx["last"]=1;
  315. $2=_st($3)._isSend();
  316. return _st($2)._and_((function(){
  317. return smalltalk.withContext(function($ctx3) {
  318. $6=_st(anIRAssignment)._instructions();
  319. $5=_st($6)._last();
  320. return self._shouldInlineSend_($5);
  321. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
  322. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  323. $ctx1.sendIdx["and:"]=1;
  324. return $1;
  325. }, function($ctx1) {$ctx1.fill(self,"shouldInlineAssignment:",{anIRAssignment:anIRAssignment},smalltalk.IRInliner)})},
  326. args: ["anIRAssignment"],
  327. source: "shouldInlineAssignment: anIRAssignment\x0a\x09^ anIRAssignment isInlined not and: [\x0a\x09\x09anIRAssignment instructions last isSend and: [\x0a\x09\x09\x09self shouldInlineSend: (anIRAssignment instructions last) ]]",
  328. messageSends: ["and:", "not", "isInlined", "isSend", "last", "instructions", "shouldInlineSend:"],
  329. referencedClasses: []
  330. }),
  331. smalltalk.IRInliner);
  332. smalltalk.addMethod(
  333. smalltalk.method({
  334. selector: "shouldInlineReturn:",
  335. category: 'testing',
  336. fn: function (anIRReturn){
  337. var self=this;
  338. return smalltalk.withContext(function($ctx1) {
  339. var $4,$3,$2,$6,$5,$1;
  340. $1=_st(_st(_st(anIRReturn)._isInlined())._not())._and_((function(){
  341. return smalltalk.withContext(function($ctx2) {
  342. $4=_st(anIRReturn)._instructions();
  343. $ctx2.sendIdx["instructions"]=1;
  344. $3=_st($4)._first();
  345. $ctx2.sendIdx["first"]=1;
  346. $2=_st($3)._isSend();
  347. return _st($2)._and_((function(){
  348. return smalltalk.withContext(function($ctx3) {
  349. $6=_st(anIRReturn)._instructions();
  350. $5=_st($6)._first();
  351. return self._shouldInlineSend_($5);
  352. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
  353. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  354. $ctx1.sendIdx["and:"]=1;
  355. return $1;
  356. }, function($ctx1) {$ctx1.fill(self,"shouldInlineReturn:",{anIRReturn:anIRReturn},smalltalk.IRInliner)})},
  357. args: ["anIRReturn"],
  358. source: "shouldInlineReturn: anIRReturn\x0a\x09^ anIRReturn isInlined not and: [\x0a\x09\x09anIRReturn instructions first isSend and: [\x0a\x09\x09\x09self shouldInlineSend: (anIRReturn instructions first) ]]",
  359. messageSends: ["and:", "not", "isInlined", "isSend", "first", "instructions", "shouldInlineSend:"],
  360. referencedClasses: []
  361. }),
  362. smalltalk.IRInliner);
  363. smalltalk.addMethod(
  364. smalltalk.method({
  365. selector: "shouldInlineSend:",
  366. category: 'testing',
  367. fn: function (anIRSend){
  368. var self=this;
  369. function $IRSendInliner(){return smalltalk.IRSendInliner||(typeof IRSendInliner=="undefined"?nil:IRSendInliner)}
  370. return smalltalk.withContext(function($ctx1) {
  371. var $1;
  372. $1=_st(_st(_st(anIRSend)._isInlined())._not())._and_((function(){
  373. return smalltalk.withContext(function($ctx2) {
  374. return _st($IRSendInliner())._shouldInline_(anIRSend);
  375. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  376. return $1;
  377. }, function($ctx1) {$ctx1.fill(self,"shouldInlineSend:",{anIRSend:anIRSend},smalltalk.IRInliner)})},
  378. args: ["anIRSend"],
  379. source: "shouldInlineSend: anIRSend\x0a\x09^ anIRSend isInlined not and: [\x0a\x09\x09IRSendInliner shouldInline: anIRSend ]",
  380. messageSends: ["and:", "not", "isInlined", "shouldInline:"],
  381. referencedClasses: ["IRSendInliner"]
  382. }),
  383. smalltalk.IRInliner);
  384. smalltalk.addMethod(
  385. smalltalk.method({
  386. selector: "transformNonLocalReturn:",
  387. category: 'visiting',
  388. fn: function (anIRNonLocalReturn){
  389. var self=this;
  390. var localReturn;
  391. function $IRReturn(){return smalltalk.IRReturn||(typeof IRReturn=="undefined"?nil:IRReturn)}
  392. return smalltalk.withContext(function($ctx1) {
  393. var $2,$1,$4,$3,$5,$6,$7,$8,$9,$10,$11;
  394. $2=_st(anIRNonLocalReturn)._scope();
  395. $ctx1.sendIdx["scope"]=1;
  396. $1=_st($2)._canInlineNonLocalReturns();
  397. if(smalltalk.assert($1)){
  398. $4=_st(anIRNonLocalReturn)._scope();
  399. $ctx1.sendIdx["scope"]=2;
  400. $3=_st($4)._methodScope();
  401. $5=_st(anIRNonLocalReturn)._scope();
  402. $ctx1.sendIdx["scope"]=3;
  403. _st($3)._removeNonLocalReturn_($5);
  404. $6=_st($IRReturn())._new();
  405. $7=$6;
  406. $8=_st(anIRNonLocalReturn)._scope();
  407. _st($7)._scope_($8);
  408. $9=_st($6)._yourself();
  409. localReturn=$9;
  410. localReturn;
  411. _st(_st(anIRNonLocalReturn)._instructions())._do_((function(each){
  412. return smalltalk.withContext(function($ctx2) {
  413. return _st(localReturn)._add_(each);
  414. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)})}));
  415. _st(anIRNonLocalReturn)._replaceWith_(localReturn);
  416. $10=localReturn;
  417. return $10;
  418. };
  419. $11=smalltalk.IRInliner.superclass.fn.prototype._visitIRNonLocalReturn_.apply(_st(self), [anIRNonLocalReturn]);
  420. return $11;
  421. }, function($ctx1) {$ctx1.fill(self,"transformNonLocalReturn:",{anIRNonLocalReturn:anIRNonLocalReturn,localReturn:localReturn},smalltalk.IRInliner)})},
  422. args: ["anIRNonLocalReturn"],
  423. source: "transformNonLocalReturn: anIRNonLocalReturn\x0a\x09\x22Replace a non local return into a local return\x22\x0a\x0a\x09| localReturn |\x0a\x09anIRNonLocalReturn scope canInlineNonLocalReturns ifTrue: [\x0a\x09\x09anIRNonLocalReturn scope methodScope removeNonLocalReturn: anIRNonLocalReturn scope.\x0a\x09\x09localReturn := IRReturn new\x0a\x09\x09\x09scope: anIRNonLocalReturn scope;\x0a\x09\x09\x09yourself.\x0a\x09\x09anIRNonLocalReturn instructions do: [ :each |\x0a\x09\x09\x09localReturn add: each ].\x0a\x09\x09anIRNonLocalReturn replaceWith: localReturn.\x0a\x09\x09^ localReturn ].\x0a\x09^ super visitIRNonLocalReturn: anIRNonLocalReturn",
  424. messageSends: ["ifTrue:", "canInlineNonLocalReturns", "scope", "removeNonLocalReturn:", "methodScope", "scope:", "new", "yourself", "do:", "instructions", "add:", "replaceWith:", "visitIRNonLocalReturn:"],
  425. referencedClasses: ["IRReturn"]
  426. }),
  427. smalltalk.IRInliner);
  428. smalltalk.addMethod(
  429. smalltalk.method({
  430. selector: "visitIRAssignment:",
  431. category: 'visiting',
  432. fn: function (anIRAssignment){
  433. var self=this;
  434. return smalltalk.withContext(function($ctx1) {
  435. var $1;
  436. if(smalltalk.assert(self._shouldInlineAssignment_(anIRAssignment))){
  437. $1=_st(self._assignmentInliner())._inlineAssignment_(anIRAssignment);
  438. } else {
  439. $1=smalltalk.IRInliner.superclass.fn.prototype._visitIRAssignment_.apply(_st(self), [anIRAssignment]);
  440. };
  441. return $1;
  442. }, function($ctx1) {$ctx1.fill(self,"visitIRAssignment:",{anIRAssignment:anIRAssignment},smalltalk.IRInliner)})},
  443. args: ["anIRAssignment"],
  444. source: "visitIRAssignment: anIRAssignment\x0a\x09^ (self shouldInlineAssignment: anIRAssignment)\x0a\x09\x09ifTrue: [ self assignmentInliner inlineAssignment: anIRAssignment ]\x0a\x09\x09ifFalse: [ super visitIRAssignment: anIRAssignment ]",
  445. messageSends: ["ifTrue:ifFalse:", "shouldInlineAssignment:", "inlineAssignment:", "assignmentInliner", "visitIRAssignment:"],
  446. referencedClasses: []
  447. }),
  448. smalltalk.IRInliner);
  449. smalltalk.addMethod(
  450. smalltalk.method({
  451. selector: "visitIRNonLocalReturn:",
  452. category: 'visiting',
  453. fn: function (anIRNonLocalReturn){
  454. var self=this;
  455. return smalltalk.withContext(function($ctx1) {
  456. var $1;
  457. $1=self._transformNonLocalReturn_(anIRNonLocalReturn);
  458. return $1;
  459. }, function($ctx1) {$ctx1.fill(self,"visitIRNonLocalReturn:",{anIRNonLocalReturn:anIRNonLocalReturn},smalltalk.IRInliner)})},
  460. args: ["anIRNonLocalReturn"],
  461. source: "visitIRNonLocalReturn: anIRNonLocalReturn\x0a\x09^ self transformNonLocalReturn: anIRNonLocalReturn",
  462. messageSends: ["transformNonLocalReturn:"],
  463. referencedClasses: []
  464. }),
  465. smalltalk.IRInliner);
  466. smalltalk.addMethod(
  467. smalltalk.method({
  468. selector: "visitIRReturn:",
  469. category: 'visiting',
  470. fn: function (anIRReturn){
  471. var self=this;
  472. return smalltalk.withContext(function($ctx1) {
  473. var $1;
  474. if(smalltalk.assert(self._shouldInlineReturn_(anIRReturn))){
  475. $1=_st(self._returnInliner())._inlineReturn_(anIRReturn);
  476. } else {
  477. $1=smalltalk.IRInliner.superclass.fn.prototype._visitIRReturn_.apply(_st(self), [anIRReturn]);
  478. };
  479. return $1;
  480. }, function($ctx1) {$ctx1.fill(self,"visitIRReturn:",{anIRReturn:anIRReturn},smalltalk.IRInliner)})},
  481. args: ["anIRReturn"],
  482. source: "visitIRReturn: anIRReturn\x0a\x09^ (self shouldInlineReturn: anIRReturn)\x0a\x09\x09ifTrue: [ self returnInliner inlineReturn: anIRReturn ]\x0a\x09\x09ifFalse: [ super visitIRReturn: anIRReturn ]",
  483. messageSends: ["ifTrue:ifFalse:", "shouldInlineReturn:", "inlineReturn:", "returnInliner", "visitIRReturn:"],
  484. referencedClasses: []
  485. }),
  486. smalltalk.IRInliner);
  487. smalltalk.addMethod(
  488. smalltalk.method({
  489. selector: "visitIRSend:",
  490. category: 'visiting',
  491. fn: function (anIRSend){
  492. var self=this;
  493. return smalltalk.withContext(function($ctx1) {
  494. var $1;
  495. if(smalltalk.assert(self._shouldInlineSend_(anIRSend))){
  496. $1=_st(self._sendInliner())._inlineSend_(anIRSend);
  497. } else {
  498. $1=smalltalk.IRInliner.superclass.fn.prototype._visitIRSend_.apply(_st(self), [anIRSend]);
  499. };
  500. return $1;
  501. }, function($ctx1) {$ctx1.fill(self,"visitIRSend:",{anIRSend:anIRSend},smalltalk.IRInliner)})},
  502. args: ["anIRSend"],
  503. source: "visitIRSend: anIRSend\x0a\x09^ (self shouldInlineSend: anIRSend)\x0a\x09\x09ifTrue: [ self sendInliner inlineSend: anIRSend ]\x0a\x09\x09ifFalse: [ super visitIRSend: anIRSend ]",
  504. messageSends: ["ifTrue:ifFalse:", "shouldInlineSend:", "inlineSend:", "sendInliner", "visitIRSend:"],
  505. referencedClasses: []
  506. }),
  507. smalltalk.IRInliner);
  508. smalltalk.addClass('IRInliningJSTranslator', smalltalk.IRJSTranslator, [], 'Compiler-Inlining');
  509. smalltalk.IRInliningJSTranslator.comment="I am a specialized JavaScript translator able to write inlined IR instructions to JavaScript stream (`JSStream` instance).";
  510. smalltalk.addMethod(
  511. smalltalk.method({
  512. selector: "visitIRInlinedAssignment:",
  513. category: 'visiting',
  514. fn: function (anIRInlinedAssignment){
  515. var self=this;
  516. return smalltalk.withContext(function($ctx1) {
  517. self._visit_(_st(_st(anIRInlinedAssignment)._instructions())._last());
  518. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedAssignment:",{anIRInlinedAssignment:anIRInlinedAssignment},smalltalk.IRInliningJSTranslator)})},
  519. args: ["anIRInlinedAssignment"],
  520. source: "visitIRInlinedAssignment: anIRInlinedAssignment\x0a\x09self visit: anIRInlinedAssignment instructions last",
  521. messageSends: ["visit:", "last", "instructions"],
  522. referencedClasses: []
  523. }),
  524. smalltalk.IRInliningJSTranslator);
  525. smalltalk.addMethod(
  526. smalltalk.method({
  527. selector: "visitIRInlinedClosure:",
  528. category: 'visiting',
  529. fn: function (anIRInlinedClosure){
  530. var self=this;
  531. return smalltalk.withContext(function($ctx1) {
  532. _st(self._stream())._nextPutVars_(_st(_st(anIRInlinedClosure)._tempDeclarations())._collect_((function(each){
  533. return smalltalk.withContext(function($ctx2) {
  534. return _st(_st(each)._name())._asVariableName();
  535. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})})));
  536. _st(_st(anIRInlinedClosure)._instructions())._do_((function(each){
  537. return smalltalk.withContext(function($ctx2) {
  538. return self._visit_(each);
  539. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)})}));
  540. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedClosure:",{anIRInlinedClosure:anIRInlinedClosure},smalltalk.IRInliningJSTranslator)})},
  541. args: ["anIRInlinedClosure"],
  542. source: "visitIRInlinedClosure: anIRInlinedClosure\x0a\x09self stream nextPutVars: (anIRInlinedClosure tempDeclarations collect: [ :each |\x0a\x09\x09each name asVariableName ]).\x0a\x09anIRInlinedClosure instructions do: [ :each |\x0a\x09\x09self visit: each ]",
  543. messageSends: ["nextPutVars:", "stream", "collect:", "tempDeclarations", "asVariableName", "name", "do:", "instructions", "visit:"],
  544. referencedClasses: []
  545. }),
  546. smalltalk.IRInliningJSTranslator);
  547. smalltalk.addMethod(
  548. smalltalk.method({
  549. selector: "visitIRInlinedIfFalse:",
  550. category: 'visiting',
  551. fn: function (anIRInlinedIfFalse){
  552. var self=this;
  553. return smalltalk.withContext(function($ctx1) {
  554. var $1,$2,$4,$3,$5,$7,$6;
  555. $1=self._stream();
  556. $ctx1.sendIdx["stream"]=1;
  557. _st($1)._nextPutIf_with_((function(){
  558. return smalltalk.withContext(function($ctx2) {
  559. $2=self._stream();
  560. $ctx2.sendIdx["stream"]=2;
  561. _st($2)._nextPutAll_("! smalltalk.assert(");
  562. $ctx2.sendIdx["nextPutAll:"]=1;
  563. $4=_st(anIRInlinedIfFalse)._instructions();
  564. $ctx2.sendIdx["instructions"]=1;
  565. $3=_st($4)._first();
  566. self._visit_($3);
  567. $ctx2.sendIdx["visit:"]=1;
  568. $5=self._stream();
  569. return _st($5)._nextPutAll_(")");
  570. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),(function(){
  571. return smalltalk.withContext(function($ctx2) {
  572. $7=_st(anIRInlinedIfFalse)._instructions();
  573. $6=_st($7)._last();
  574. return self._visit_($6);
  575. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  576. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedIfFalse:",{anIRInlinedIfFalse:anIRInlinedIfFalse},smalltalk.IRInliningJSTranslator)})},
  577. args: ["anIRInlinedIfFalse"],
  578. source: "visitIRInlinedIfFalse: anIRInlinedIfFalse\x0a\x09self stream nextPutIf: [\x0a\x09\x09self stream nextPutAll: '! smalltalk.assert('.\x0a\x09\x09self visit: anIRInlinedIfFalse instructions first.\x0a\x09\x09self stream nextPutAll: ')' ]\x0a\x09\x09with: [ self visit: anIRInlinedIfFalse instructions last ]",
  579. messageSends: ["nextPutIf:with:", "stream", "nextPutAll:", "visit:", "first", "instructions", "last"],
  580. referencedClasses: []
  581. }),
  582. smalltalk.IRInliningJSTranslator);
  583. smalltalk.addMethod(
  584. smalltalk.method({
  585. selector: "visitIRInlinedIfNil:",
  586. category: 'visiting',
  587. fn: function (anIRInlinedIfNil){
  588. var self=this;
  589. return smalltalk.withContext(function($ctx1) {
  590. var $1,$2,$4,$3,$5,$7,$6;
  591. $1=self._stream();
  592. $ctx1.sendIdx["stream"]=1;
  593. _st($1)._nextPutIf_with_((function(){
  594. return smalltalk.withContext(function($ctx2) {
  595. $2=self._stream();
  596. $ctx2.sendIdx["stream"]=2;
  597. _st($2)._nextPutAll_("($receiver = ");
  598. $ctx2.sendIdx["nextPutAll:"]=1;
  599. $4=_st(anIRInlinedIfNil)._instructions();
  600. $ctx2.sendIdx["instructions"]=1;
  601. $3=_st($4)._first();
  602. self._visit_($3);
  603. $ctx2.sendIdx["visit:"]=1;
  604. $5=self._stream();
  605. return _st($5)._nextPutAll_(") == nil || $receiver == null");
  606. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),(function(){
  607. return smalltalk.withContext(function($ctx2) {
  608. $7=_st(anIRInlinedIfNil)._instructions();
  609. $6=_st($7)._last();
  610. return self._visit_($6);
  611. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  612. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedIfNil:",{anIRInlinedIfNil:anIRInlinedIfNil},smalltalk.IRInliningJSTranslator)})},
  613. args: ["anIRInlinedIfNil"],
  614. source: "visitIRInlinedIfNil: anIRInlinedIfNil\x0a\x09self stream nextPutIf: [\x0a\x09\x09self stream nextPutAll: '($receiver = '.\x0a\x09\x09self visit: anIRInlinedIfNil instructions first.\x0a\x09\x09self stream nextPutAll: ') == nil || $receiver == null' ]\x0a\x09\x09with: [ self visit: anIRInlinedIfNil instructions last ]",
  615. messageSends: ["nextPutIf:with:", "stream", "nextPutAll:", "visit:", "first", "instructions", "last"],
  616. referencedClasses: []
  617. }),
  618. smalltalk.IRInliningJSTranslator);
  619. smalltalk.addMethod(
  620. smalltalk.method({
  621. selector: "visitIRInlinedIfNilIfNotNil:",
  622. category: 'visiting',
  623. fn: function (anIRInlinedIfNilIfNotNil){
  624. var self=this;
  625. return smalltalk.withContext(function($ctx1) {
  626. var $1,$2,$4,$3,$5,$7,$6,$9,$8;
  627. $1=self._stream();
  628. $ctx1.sendIdx["stream"]=1;
  629. _st($1)._nextPutIfElse_with_with_((function(){
  630. return smalltalk.withContext(function($ctx2) {
  631. $2=self._stream();
  632. $ctx2.sendIdx["stream"]=2;
  633. _st($2)._nextPutAll_("($receiver = ");
  634. $ctx2.sendIdx["nextPutAll:"]=1;
  635. $4=_st(anIRInlinedIfNilIfNotNil)._instructions();
  636. $ctx2.sendIdx["instructions"]=1;
  637. $3=_st($4)._first();
  638. self._visit_($3);
  639. $ctx2.sendIdx["visit:"]=1;
  640. $5=self._stream();
  641. return _st($5)._nextPutAll_(") == nil || $receiver == null");
  642. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),(function(){
  643. return smalltalk.withContext(function($ctx2) {
  644. $7=_st(anIRInlinedIfNilIfNotNil)._instructions();
  645. $ctx2.sendIdx["instructions"]=2;
  646. $6=_st($7)._second();
  647. return self._visit_($6);
  648. $ctx2.sendIdx["visit:"]=2;
  649. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}),(function(){
  650. return smalltalk.withContext(function($ctx2) {
  651. $9=_st(anIRInlinedIfNilIfNotNil)._instructions();
  652. $8=_st($9)._third();
  653. return self._visit_($8);
  654. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)})}));
  655. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedIfNilIfNotNil:",{anIRInlinedIfNilIfNotNil:anIRInlinedIfNilIfNotNil},smalltalk.IRInliningJSTranslator)})},
  656. args: ["anIRInlinedIfNilIfNotNil"],
  657. source: "visitIRInlinedIfNilIfNotNil: anIRInlinedIfNilIfNotNil\x0a\x09self stream\x0a\x09\x09nextPutIfElse: [\x0a\x09\x09\x09self stream nextPutAll: '($receiver = '.\x0a\x09\x09\x09self visit: anIRInlinedIfNilIfNotNil instructions first.\x0a\x09\x09\x09self stream nextPutAll: ') == nil || $receiver == null' ]\x0a\x09\x09with: [ self visit: anIRInlinedIfNilIfNotNil instructions second ]\x0a\x09\x09with: [ self visit: anIRInlinedIfNilIfNotNil instructions third ]",
  658. messageSends: ["nextPutIfElse:with:with:", "stream", "nextPutAll:", "visit:", "first", "instructions", "second", "third"],
  659. referencedClasses: []
  660. }),
  661. smalltalk.IRInliningJSTranslator);
  662. smalltalk.addMethod(
  663. smalltalk.method({
  664. selector: "visitIRInlinedIfTrue:",
  665. category: 'visiting',
  666. fn: function (anIRInlinedIfTrue){
  667. var self=this;
  668. return smalltalk.withContext(function($ctx1) {
  669. var $1,$2,$4,$3,$5,$7,$6;
  670. $1=self._stream();
  671. $ctx1.sendIdx["stream"]=1;
  672. _st($1)._nextPutIf_with_((function(){
  673. return smalltalk.withContext(function($ctx2) {
  674. $2=self._stream();
  675. $ctx2.sendIdx["stream"]=2;
  676. _st($2)._nextPutAll_("smalltalk.assert(");
  677. $ctx2.sendIdx["nextPutAll:"]=1;
  678. $4=_st(anIRInlinedIfTrue)._instructions();
  679. $ctx2.sendIdx["instructions"]=1;
  680. $3=_st($4)._first();
  681. self._visit_($3);
  682. $ctx2.sendIdx["visit:"]=1;
  683. $5=self._stream();
  684. return _st($5)._nextPutAll_(")");
  685. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),(function(){
  686. return smalltalk.withContext(function($ctx2) {
  687. $7=_st(anIRInlinedIfTrue)._instructions();
  688. $6=_st($7)._last();
  689. return self._visit_($6);
  690. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  691. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedIfTrue:",{anIRInlinedIfTrue:anIRInlinedIfTrue},smalltalk.IRInliningJSTranslator)})},
  692. args: ["anIRInlinedIfTrue"],
  693. source: "visitIRInlinedIfTrue: anIRInlinedIfTrue\x0a\x09self stream nextPutIf: [\x0a\x09\x09self stream nextPutAll: 'smalltalk.assert('.\x0a\x09\x09self visit: anIRInlinedIfTrue instructions first.\x0a\x09\x09self stream nextPutAll: ')' ]\x0a\x09\x09with: [ self visit: anIRInlinedIfTrue instructions last ]",
  694. messageSends: ["nextPutIf:with:", "stream", "nextPutAll:", "visit:", "first", "instructions", "last"],
  695. referencedClasses: []
  696. }),
  697. smalltalk.IRInliningJSTranslator);
  698. smalltalk.addMethod(
  699. smalltalk.method({
  700. selector: "visitIRInlinedIfTrueIfFalse:",
  701. category: 'visiting',
  702. fn: function (anIRInlinedIfTrueIfFalse){
  703. var self=this;
  704. return smalltalk.withContext(function($ctx1) {
  705. var $1,$2,$4,$3,$5,$7,$6,$9,$8;
  706. $1=self._stream();
  707. $ctx1.sendIdx["stream"]=1;
  708. _st($1)._nextPutIfElse_with_with_((function(){
  709. return smalltalk.withContext(function($ctx2) {
  710. $2=self._stream();
  711. $ctx2.sendIdx["stream"]=2;
  712. _st($2)._nextPutAll_("smalltalk.assert(");
  713. $ctx2.sendIdx["nextPutAll:"]=1;
  714. $4=_st(anIRInlinedIfTrueIfFalse)._instructions();
  715. $ctx2.sendIdx["instructions"]=1;
  716. $3=_st($4)._first();
  717. self._visit_($3);
  718. $ctx2.sendIdx["visit:"]=1;
  719. $5=self._stream();
  720. return _st($5)._nextPutAll_(")");
  721. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),(function(){
  722. return smalltalk.withContext(function($ctx2) {
  723. $7=_st(anIRInlinedIfTrueIfFalse)._instructions();
  724. $ctx2.sendIdx["instructions"]=2;
  725. $6=_st($7)._second();
  726. return self._visit_($6);
  727. $ctx2.sendIdx["visit:"]=2;
  728. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}),(function(){
  729. return smalltalk.withContext(function($ctx2) {
  730. $9=_st(anIRInlinedIfTrueIfFalse)._instructions();
  731. $8=_st($9)._third();
  732. return self._visit_($8);
  733. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)})}));
  734. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedIfTrueIfFalse:",{anIRInlinedIfTrueIfFalse:anIRInlinedIfTrueIfFalse},smalltalk.IRInliningJSTranslator)})},
  735. args: ["anIRInlinedIfTrueIfFalse"],
  736. source: "visitIRInlinedIfTrueIfFalse: anIRInlinedIfTrueIfFalse\x0a\x09self stream\x0a\x09\x09nextPutIfElse: [\x0a\x09\x09\x09self stream nextPutAll: 'smalltalk.assert('.\x0a\x09\x09\x09self visit: anIRInlinedIfTrueIfFalse instructions first.\x0a\x09\x09\x09self stream nextPutAll: ')' ]\x0a\x09\x09with: [ self visit: anIRInlinedIfTrueIfFalse instructions second ]\x0a\x09\x09with: [ self visit: anIRInlinedIfTrueIfFalse instructions third ]",
  737. messageSends: ["nextPutIfElse:with:with:", "stream", "nextPutAll:", "visit:", "first", "instructions", "second", "third"],
  738. referencedClasses: []
  739. }),
  740. smalltalk.IRInliningJSTranslator);
  741. smalltalk.addMethod(
  742. smalltalk.method({
  743. selector: "visitIRInlinedNonLocalReturn:",
  744. category: 'visiting',
  745. fn: function (anIRInlinedReturn){
  746. var self=this;
  747. return smalltalk.withContext(function($ctx1) {
  748. var $1,$2;
  749. $1=self._stream();
  750. $ctx1.sendIdx["stream"]=1;
  751. _st($1)._nextPutStatementWith_((function(){
  752. return smalltalk.withContext(function($ctx2) {
  753. return self._visit_(_st(_st(anIRInlinedReturn)._instructions())._last());
  754. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  755. $2=self._stream();
  756. _st($2)._nextPutNonLocalReturnWith_((function(){
  757. return smalltalk.withContext(function($ctx2) {
  758. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  759. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedNonLocalReturn:",{anIRInlinedReturn:anIRInlinedReturn},smalltalk.IRInliningJSTranslator)})},
  760. args: ["anIRInlinedReturn"],
  761. source: "visitIRInlinedNonLocalReturn: anIRInlinedReturn\x0a\x09self stream nextPutStatementWith: [\x0a\x09\x09self visit: anIRInlinedReturn instructions last ].\x0a\x09self stream nextPutNonLocalReturnWith: [ ]",
  762. messageSends: ["nextPutStatementWith:", "stream", "visit:", "last", "instructions", "nextPutNonLocalReturnWith:"],
  763. referencedClasses: []
  764. }),
  765. smalltalk.IRInliningJSTranslator);
  766. smalltalk.addMethod(
  767. smalltalk.method({
  768. selector: "visitIRInlinedReturn:",
  769. category: 'visiting',
  770. fn: function (anIRInlinedReturn){
  771. var self=this;
  772. return smalltalk.withContext(function($ctx1) {
  773. self._visit_(_st(_st(anIRInlinedReturn)._instructions())._last());
  774. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedReturn:",{anIRInlinedReturn:anIRInlinedReturn},smalltalk.IRInliningJSTranslator)})},
  775. args: ["anIRInlinedReturn"],
  776. source: "visitIRInlinedReturn: anIRInlinedReturn\x0a\x09self visit: anIRInlinedReturn instructions last",
  777. messageSends: ["visit:", "last", "instructions"],
  778. referencedClasses: []
  779. }),
  780. smalltalk.IRInliningJSTranslator);
  781. smalltalk.addMethod(
  782. smalltalk.method({
  783. selector: "visitIRInlinedSequence:",
  784. category: 'visiting',
  785. fn: function (anIRInlinedSequence){
  786. var self=this;
  787. return smalltalk.withContext(function($ctx1) {
  788. _st(_st(anIRInlinedSequence)._instructions())._do_((function(each){
  789. return smalltalk.withContext(function($ctx2) {
  790. return _st(self._stream())._nextPutStatementWith_((function(){
  791. return smalltalk.withContext(function($ctx3) {
  792. return self._visit_(each);
  793. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
  794. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  795. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedSequence:",{anIRInlinedSequence:anIRInlinedSequence},smalltalk.IRInliningJSTranslator)})},
  796. args: ["anIRInlinedSequence"],
  797. source: "visitIRInlinedSequence: anIRInlinedSequence\x0a\x09anIRInlinedSequence instructions do: [ :each |\x0a\x09\x09self stream nextPutStatementWith: [ self visit: each ]]",
  798. messageSends: ["do:", "instructions", "nextPutStatementWith:", "stream", "visit:"],
  799. referencedClasses: []
  800. }),
  801. smalltalk.IRInliningJSTranslator);
  802. smalltalk.addClass('IRSendInliner', smalltalk.Object, ['send', 'translator'], 'Compiler-Inlining');
  803. smalltalk.IRSendInliner.comment="I inline some message sends and block closure arguments. I heavily rely on #perform: to dispatch inlining methods.";
  804. smalltalk.addMethod(
  805. smalltalk.method({
  806. selector: "ifFalse:",
  807. category: 'inlining',
  808. fn: function (anIRInstruction){
  809. var self=this;
  810. function $IRInlinedIfFalse(){return smalltalk.IRInlinedIfFalse||(typeof IRInlinedIfFalse=="undefined"?nil:IRInlinedIfFalse)}
  811. return smalltalk.withContext(function($ctx1) {
  812. var $1;
  813. $1=self._inlinedSend_with_(_st($IRInlinedIfFalse())._new(),anIRInstruction);
  814. return $1;
  815. }, function($ctx1) {$ctx1.fill(self,"ifFalse:",{anIRInstruction:anIRInstruction},smalltalk.IRSendInliner)})},
  816. args: ["anIRInstruction"],
  817. source: "ifFalse: anIRInstruction\x0a\x09^ self inlinedSend: IRInlinedIfFalse new with: anIRInstruction",
  818. messageSends: ["inlinedSend:with:", "new"],
  819. referencedClasses: ["IRInlinedIfFalse"]
  820. }),
  821. smalltalk.IRSendInliner);
  822. smalltalk.addMethod(
  823. smalltalk.method({
  824. selector: "ifFalse:ifTrue:",
  825. category: 'inlining',
  826. fn: function (anIRInstruction,anotherIRInstruction){
  827. var self=this;
  828. return smalltalk.withContext(function($ctx1) {
  829. var $1;
  830. $1=self._perform_withArguments_("ifTrue:ifFalse:",[anotherIRInstruction,anIRInstruction]);
  831. return $1;
  832. }, function($ctx1) {$ctx1.fill(self,"ifFalse:ifTrue:",{anIRInstruction:anIRInstruction,anotherIRInstruction:anotherIRInstruction},smalltalk.IRSendInliner)})},
  833. args: ["anIRInstruction", "anotherIRInstruction"],
  834. source: "ifFalse: anIRInstruction ifTrue: anotherIRInstruction\x0a\x09^ self perform: #ifTrue:ifFalse: withArguments: { anotherIRInstruction. anIRInstruction }",
  835. messageSends: ["perform:withArguments:"],
  836. referencedClasses: []
  837. }),
  838. smalltalk.IRSendInliner);
  839. smalltalk.addMethod(
  840. smalltalk.method({
  841. selector: "ifNil:",
  842. category: 'inlining',
  843. fn: function (anIRInstruction){
  844. var self=this;
  845. function $IRInlinedIfNilIfNotNil(){return smalltalk.IRInlinedIfNilIfNotNil||(typeof IRInlinedIfNilIfNotNil=="undefined"?nil:IRInlinedIfNilIfNotNil)}
  846. function $IRClosure(){return smalltalk.IRClosure||(typeof IRClosure=="undefined"?nil:IRClosure)}
  847. function $IRBlockSequence(){return smalltalk.IRBlockSequence||(typeof IRBlockSequence=="undefined"?nil:IRBlockSequence)}
  848. return smalltalk.withContext(function($ctx1) {
  849. var $2,$4,$5,$7,$8,$6,$9,$3,$1;
  850. $2=_st($IRInlinedIfNilIfNotNil())._new();
  851. $ctx1.sendIdx["new"]=1;
  852. $4=_st($IRClosure())._new();
  853. $ctx1.sendIdx["new"]=2;
  854. _st($4)._scope_(_st(_st(anIRInstruction)._scope())._copy());
  855. $5=$4;
  856. $7=_st($IRBlockSequence())._new();
  857. _st($7)._add_(_st(_st(self._send())._instructions())._first());
  858. $8=_st($7)._yourself();
  859. $ctx1.sendIdx["yourself"]=1;
  860. $6=$8;
  861. _st($5)._add_($6);
  862. $ctx1.sendIdx["add:"]=1;
  863. $9=_st($4)._yourself();
  864. $3=$9;
  865. $1=self._inlinedSend_with_with_($2,anIRInstruction,$3);
  866. return $1;
  867. }, function($ctx1) {$ctx1.fill(self,"ifNil:",{anIRInstruction:anIRInstruction},smalltalk.IRSendInliner)})},
  868. args: ["anIRInstruction"],
  869. source: "ifNil: anIRInstruction\x0a\x09^ self\x0a\x09\x09inlinedSend: IRInlinedIfNilIfNotNil new\x0a\x09\x09with: anIRInstruction\x0a\x09\x09with: (IRClosure new\x0a\x09\x09\x09scope: anIRInstruction scope copy;\x0a\x09\x09\x09add: (IRBlockSequence new\x0a\x09\x09\x09\x09add: self send instructions first;\x0a\x09\x09\x09\x09yourself);\x0a\x09\x09\x09yourself)",
  870. messageSends: ["inlinedSend:with:with:", "new", "scope:", "copy", "scope", "add:", "first", "instructions", "send", "yourself"],
  871. referencedClasses: ["IRInlinedIfNilIfNotNil", "IRClosure", "IRBlockSequence"]
  872. }),
  873. smalltalk.IRSendInliner);
  874. smalltalk.addMethod(
  875. smalltalk.method({
  876. selector: "ifNil:ifNotNil:",
  877. category: 'inlining',
  878. fn: function (anIRInstruction,anotherIRInstruction){
  879. var self=this;
  880. function $IRInlinedIfNilIfNotNil(){return smalltalk.IRInlinedIfNilIfNotNil||(typeof IRInlinedIfNilIfNotNil=="undefined"?nil:IRInlinedIfNilIfNotNil)}
  881. return smalltalk.withContext(function($ctx1) {
  882. var $1;
  883. $1=self._inlinedSend_with_with_(_st($IRInlinedIfNilIfNotNil())._new(),anIRInstruction,anotherIRInstruction);
  884. return $1;
  885. }, function($ctx1) {$ctx1.fill(self,"ifNil:ifNotNil:",{anIRInstruction:anIRInstruction,anotherIRInstruction:anotherIRInstruction},smalltalk.IRSendInliner)})},
  886. args: ["anIRInstruction", "anotherIRInstruction"],
  887. source: "ifNil: anIRInstruction ifNotNil: anotherIRInstruction\x0a\x09^ self inlinedSend: IRInlinedIfNilIfNotNil new with: anIRInstruction with: anotherIRInstruction",
  888. messageSends: ["inlinedSend:with:with:", "new"],
  889. referencedClasses: ["IRInlinedIfNilIfNotNil"]
  890. }),
  891. smalltalk.IRSendInliner);
  892. smalltalk.addMethod(
  893. smalltalk.method({
  894. selector: "ifNotNil:",
  895. category: 'inlining',
  896. fn: function (anIRInstruction){
  897. var self=this;
  898. function $IRInlinedIfNilIfNotNil(){return smalltalk.IRInlinedIfNilIfNotNil||(typeof IRInlinedIfNilIfNotNil=="undefined"?nil:IRInlinedIfNilIfNotNil)}
  899. function $IRClosure(){return smalltalk.IRClosure||(typeof IRClosure=="undefined"?nil:IRClosure)}
  900. function $IRBlockSequence(){return smalltalk.IRBlockSequence||(typeof IRBlockSequence=="undefined"?nil:IRBlockSequence)}
  901. return smalltalk.withContext(function($ctx1) {
  902. var $2,$4,$5,$7,$8,$6,$9,$3,$1;
  903. $2=_st($IRInlinedIfNilIfNotNil())._new();
  904. $ctx1.sendIdx["new"]=1;
  905. $4=_st($IRClosure())._new();
  906. $ctx1.sendIdx["new"]=2;
  907. _st($4)._scope_(_st(_st(anIRInstruction)._scope())._copy());
  908. $5=$4;
  909. $7=_st($IRBlockSequence())._new();
  910. _st($7)._add_(_st(_st(self._send())._instructions())._first());
  911. $8=_st($7)._yourself();
  912. $ctx1.sendIdx["yourself"]=1;
  913. $6=$8;
  914. _st($5)._add_($6);
  915. $ctx1.sendIdx["add:"]=1;
  916. $9=_st($4)._yourself();
  917. $3=$9;
  918. $1=self._inlinedSend_with_with_($2,$3,anIRInstruction);
  919. return $1;
  920. }, function($ctx1) {$ctx1.fill(self,"ifNotNil:",{anIRInstruction:anIRInstruction},smalltalk.IRSendInliner)})},
  921. args: ["anIRInstruction"],
  922. source: "ifNotNil: anIRInstruction\x0a\x09^ self\x0a\x09\x09inlinedSend: IRInlinedIfNilIfNotNil new\x0a\x09\x09with: (IRClosure new\x0a\x09\x09\x09scope: anIRInstruction scope copy;\x0a\x09\x09\x09add: (IRBlockSequence new\x0a\x09\x09\x09\x09add: self send instructions first;\x0a\x09\x09\x09\x09yourself);\x0a\x09\x09\x09yourself)\x0a\x09\x09with: anIRInstruction",
  923. messageSends: ["inlinedSend:with:with:", "new", "scope:", "copy", "scope", "add:", "first", "instructions", "send", "yourself"],
  924. referencedClasses: ["IRInlinedIfNilIfNotNil", "IRClosure", "IRBlockSequence"]
  925. }),
  926. smalltalk.IRSendInliner);
  927. smalltalk.addMethod(
  928. smalltalk.method({
  929. selector: "ifNotNil:ifNil:",
  930. category: 'inlining',
  931. fn: function (anIRInstruction,anotherIRInstruction){
  932. var self=this;
  933. function $IRInlinedIfNilIfNotNil(){return smalltalk.IRInlinedIfNilIfNotNil||(typeof IRInlinedIfNilIfNotNil=="undefined"?nil:IRInlinedIfNilIfNotNil)}
  934. return smalltalk.withContext(function($ctx1) {
  935. var $1;
  936. $1=self._inlinedSend_with_with_(_st($IRInlinedIfNilIfNotNil())._new(),anotherIRInstruction,anIRInstruction);
  937. return $1;
  938. }, function($ctx1) {$ctx1.fill(self,"ifNotNil:ifNil:",{anIRInstruction:anIRInstruction,anotherIRInstruction:anotherIRInstruction},smalltalk.IRSendInliner)})},
  939. args: ["anIRInstruction", "anotherIRInstruction"],
  940. source: "ifNotNil: anIRInstruction ifNil: anotherIRInstruction\x0a\x09^ self inlinedSend: IRInlinedIfNilIfNotNil new with: anotherIRInstruction with: anIRInstruction",
  941. messageSends: ["inlinedSend:with:with:", "new"],
  942. referencedClasses: ["IRInlinedIfNilIfNotNil"]
  943. }),
  944. smalltalk.IRSendInliner);
  945. smalltalk.addMethod(
  946. smalltalk.method({
  947. selector: "ifTrue:",
  948. category: 'inlining',
  949. fn: function (anIRInstruction){
  950. var self=this;
  951. function $IRInlinedIfTrue(){return smalltalk.IRInlinedIfTrue||(typeof IRInlinedIfTrue=="undefined"?nil:IRInlinedIfTrue)}
  952. return smalltalk.withContext(function($ctx1) {
  953. var $1;
  954. $1=self._inlinedSend_with_(_st($IRInlinedIfTrue())._new(),anIRInstruction);
  955. return $1;
  956. }, function($ctx1) {$ctx1.fill(self,"ifTrue:",{anIRInstruction:anIRInstruction},smalltalk.IRSendInliner)})},
  957. args: ["anIRInstruction"],
  958. source: "ifTrue: anIRInstruction\x0a\x09^ self inlinedSend: IRInlinedIfTrue new with: anIRInstruction",
  959. messageSends: ["inlinedSend:with:", "new"],
  960. referencedClasses: ["IRInlinedIfTrue"]
  961. }),
  962. smalltalk.IRSendInliner);
  963. smalltalk.addMethod(
  964. smalltalk.method({
  965. selector: "ifTrue:ifFalse:",
  966. category: 'inlining',
  967. fn: function (anIRInstruction,anotherIRInstruction){
  968. var self=this;
  969. function $IRInlinedIfTrueIfFalse(){return smalltalk.IRInlinedIfTrueIfFalse||(typeof IRInlinedIfTrueIfFalse=="undefined"?nil:IRInlinedIfTrueIfFalse)}
  970. return smalltalk.withContext(function($ctx1) {
  971. var $1;
  972. $1=self._inlinedSend_with_with_(_st($IRInlinedIfTrueIfFalse())._new(),anIRInstruction,anotherIRInstruction);
  973. return $1;
  974. }, function($ctx1) {$ctx1.fill(self,"ifTrue:ifFalse:",{anIRInstruction:anIRInstruction,anotherIRInstruction:anotherIRInstruction},smalltalk.IRSendInliner)})},
  975. args: ["anIRInstruction", "anotherIRInstruction"],
  976. source: "ifTrue: anIRInstruction ifFalse: anotherIRInstruction\x0a\x09^ self inlinedSend: IRInlinedIfTrueIfFalse new with: anIRInstruction with: anotherIRInstruction",
  977. messageSends: ["inlinedSend:with:with:", "new"],
  978. referencedClasses: ["IRInlinedIfTrueIfFalse"]
  979. }),
  980. smalltalk.IRSendInliner);
  981. smalltalk.addMethod(
  982. smalltalk.method({
  983. selector: "inlineClosure:",
  984. category: 'inlining',
  985. fn: function (anIRClosure){
  986. var self=this;
  987. var inlinedClosure,sequence,statements;
  988. function $IRTempDeclaration(){return smalltalk.IRTempDeclaration||(typeof IRTempDeclaration=="undefined"?nil:IRTempDeclaration)}
  989. function $IRAssignment(){return smalltalk.IRAssignment||(typeof IRAssignment=="undefined"?nil:IRAssignment)}
  990. function $IRVariable(){return smalltalk.IRVariable||(typeof IRVariable=="undefined"?nil:IRVariable)}
  991. function $AliasVar(){return smalltalk.AliasVar||(typeof AliasVar=="undefined"?nil:AliasVar)}
  992. return smalltalk.withContext(function($ctx1) {
  993. var $1,$2,$3,$5,$6,$4,$7,$9,$10,$12,$14,$15,$16,$17,$13,$11,$18,$20,$22,$23,$24,$25,$21,$19,$26,$8,$28,$27,$31,$30,$32,$29,$33,$36,$35,$34,$37,$38,$39;
  994. inlinedClosure=self._inlinedClosure();
  995. $1=inlinedClosure;
  996. $2=_st(anIRClosure)._scope();
  997. $ctx1.sendIdx["scope"]=1;
  998. _st($1)._scope_($2);
  999. $ctx1.sendIdx["scope:"]=1;
  1000. _st(_st(anIRClosure)._tempDeclarations())._do_((function(each){
  1001. return smalltalk.withContext(function($ctx2) {
  1002. return _st(inlinedClosure)._add_(each);
  1003. $ctx2.sendIdx["add:"]=1;
  1004. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1005. $ctx1.sendIdx["do:"]=1;
  1006. sequence=self._inlinedSequence();
  1007. _st(_st(anIRClosure)._arguments())._do_((function(each){
  1008. return smalltalk.withContext(function($ctx2) {
  1009. $3=inlinedClosure;
  1010. $5=_st($IRTempDeclaration())._new();
  1011. $ctx2.sendIdx["new"]=1;
  1012. _st($5)._name_(each);
  1013. $ctx2.sendIdx["name:"]=1;
  1014. $6=_st($5)._yourself();
  1015. $ctx2.sendIdx["yourself"]=1;
  1016. $4=$6;
  1017. _st($3)._add_($4);
  1018. $ctx2.sendIdx["add:"]=2;
  1019. $7=sequence;
  1020. $9=_st($IRAssignment())._new();
  1021. $ctx2.sendIdx["new"]=2;
  1022. $10=$9;
  1023. $12=_st($IRVariable())._new();
  1024. $ctx2.sendIdx["new"]=3;
  1025. $14=_st($AliasVar())._new();
  1026. $ctx2.sendIdx["new"]=4;
  1027. $15=$14;
  1028. $16=_st(inlinedClosure)._scope();
  1029. $ctx2.sendIdx["scope"]=2;
  1030. _st($15)._scope_($16);
  1031. $ctx2.sendIdx["scope:"]=2;
  1032. _st($14)._name_(each);
  1033. $ctx2.sendIdx["name:"]=2;
  1034. $17=_st($14)._yourself();
  1035. $ctx2.sendIdx["yourself"]=2;
  1036. $13=$17;
  1037. $11=_st($12)._variable_($13);
  1038. $ctx2.sendIdx["variable:"]=1;
  1039. _st($10)._add_($11);
  1040. $ctx2.sendIdx["add:"]=4;
  1041. $18=$9;
  1042. $20=_st($IRVariable())._new();
  1043. $ctx2.sendIdx["new"]=5;
  1044. $22=_st($AliasVar())._new();
  1045. $23=$22;
  1046. $24=_st(inlinedClosure)._scope();
  1047. _st($23)._scope_($24);
  1048. _st($22)._name_("$receiver");
  1049. $25=_st($22)._yourself();
  1050. $ctx2.sendIdx["yourself"]=3;
  1051. $21=$25;
  1052. $19=_st($20)._variable_($21);
  1053. _st($18)._add_($19);
  1054. $ctx2.sendIdx["add:"]=5;
  1055. $26=_st($9)._yourself();
  1056. $8=$26;
  1057. return _st($7)._add_($8);
  1058. $ctx2.sendIdx["add:"]=3;
  1059. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)})}));
  1060. $ctx1.sendIdx["do:"]=2;
  1061. _st(inlinedClosure)._add_(sequence);
  1062. $ctx1.sendIdx["add:"]=6;
  1063. $28=_st(anIRClosure)._instructions();
  1064. $ctx1.sendIdx["instructions"]=2;
  1065. $27=_st($28)._last();
  1066. $ctx1.sendIdx["last"]=1;
  1067. statements=_st($27)._instructions();
  1068. $ctx1.sendIdx["instructions"]=1;
  1069. _st(statements)._ifNotEmpty_((function(){
  1070. return smalltalk.withContext(function($ctx2) {
  1071. _st(_st(statements)._allButLast())._do_((function(each){
  1072. return smalltalk.withContext(function($ctx3) {
  1073. return _st(sequence)._add_(each);
  1074. $ctx3.sendIdx["add:"]=7;
  1075. }, function($ctx3) {$ctx3.fillBlock({each:each},$ctx2,4)})}));
  1076. $31=_st(statements)._last();
  1077. $ctx2.sendIdx["last"]=2;
  1078. $30=_st($31)._isReturn();
  1079. $29=_st($30)._and_((function(){
  1080. return smalltalk.withContext(function($ctx3) {
  1081. $32=_st(statements)._last();
  1082. $ctx3.sendIdx["last"]=3;
  1083. return _st($32)._isBlockReturn();
  1084. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,5)})}));
  1085. if(smalltalk.assert($29)){
  1086. $33=sequence;
  1087. $36=_st(statements)._last();
  1088. $ctx2.sendIdx["last"]=4;
  1089. $35=_st($36)._instructions();
  1090. $34=_st($35)._first();
  1091. return _st($33)._add_($34);
  1092. $ctx2.sendIdx["add:"]=8;
  1093. } else {
  1094. $37=sequence;
  1095. $38=_st(statements)._last();
  1096. return _st($37)._add_($38);
  1097. };
  1098. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)})}));
  1099. $39=inlinedClosure;
  1100. return $39;
  1101. }, function($ctx1) {$ctx1.fill(self,"inlineClosure:",{anIRClosure:anIRClosure,inlinedClosure:inlinedClosure,sequence:sequence,statements:statements},smalltalk.IRSendInliner)})},
  1102. args: ["anIRClosure"],
  1103. source: "inlineClosure: anIRClosure\x0a\x09| inlinedClosure sequence statements |\x0a\x0a\x09inlinedClosure := self inlinedClosure.\x0a\x09inlinedClosure scope: anIRClosure scope.\x0a\x0a\x09\x22Add the possible temp declarations\x22\x0a\x09anIRClosure tempDeclarations do: [ :each |\x0a\x09\x09\x09inlinedClosure add: each ].\x0a\x0a\x09\x22Add a block sequence\x22\x0a\x09sequence := self inlinedSequence.\x0a\x0a\x09\x22Map the closure arguments to the receiver of the message send\x22\x0a\x09anIRClosure arguments do: [ :each |\x0a\x09\x09inlinedClosure add: (IRTempDeclaration new name: each; yourself).\x0a\x09\x09sequence add: (IRAssignment new\x0a\x09\x09\x09add: (IRVariable new variable: (AliasVar new scope: inlinedClosure scope; name: each; yourself));\x0a\x09\x09\x09add: (IRVariable new variable: (AliasVar new scope: inlinedClosure scope; name: '$receiver'; yourself));\x0a\x09\x09\x09yourself) ].\x0a\x09\x09\x09\x0a\x09\x22To ensure the correct order of the closure instructions: first the temps then the sequence\x22\x0a\x09inlinedClosure add: sequence.\x0a\x0a\x09\x22Get all the statements\x22\x0a\x09statements := anIRClosure instructions last instructions.\x0a\x09\x0a\x09statements ifNotEmpty: [\x0a\x09\x09statements allButLast do: [ :each | sequence add: each ].\x0a\x0a\x09\x09\x22Inlined closures don't have implicit local returns\x22\x0a\x09\x09(statements last isReturn and: [ statements last isBlockReturn ])\x0a\x09\x09\x09ifTrue: [ sequence add: statements last instructions first ]\x0a\x09\x09\x09ifFalse: [ sequence add: statements last ] ].\x0a\x0a\x09^ inlinedClosure",
  1104. messageSends: ["inlinedClosure", "scope:", "scope", "do:", "tempDeclarations", "add:", "inlinedSequence", "arguments", "name:", "new", "yourself", "variable:", "instructions", "last", "ifNotEmpty:", "allButLast", "ifTrue:ifFalse:", "and:", "isReturn", "isBlockReturn", "first"],
  1105. referencedClasses: ["IRTempDeclaration", "IRAssignment", "IRVariable", "AliasVar"]
  1106. }),
  1107. smalltalk.IRSendInliner);
  1108. smalltalk.addMethod(
  1109. smalltalk.method({
  1110. selector: "inlineSend:",
  1111. category: 'inlining',
  1112. fn: function (anIRSend){
  1113. var self=this;
  1114. return smalltalk.withContext(function($ctx1) {
  1115. var $3,$2,$6,$5,$4,$1;
  1116. self._send_(anIRSend);
  1117. $3=self._send();
  1118. $ctx1.sendIdx["send"]=1;
  1119. $2=_st($3)._selector();
  1120. $6=self._send();
  1121. $5=_st($6)._instructions();
  1122. $4=_st($5)._allButFirst();
  1123. $1=self._perform_withArguments_($2,$4);
  1124. return $1;
  1125. }, function($ctx1) {$ctx1.fill(self,"inlineSend:",{anIRSend:anIRSend},smalltalk.IRSendInliner)})},
  1126. args: ["anIRSend"],
  1127. source: "inlineSend: anIRSend\x0a\x09self send: anIRSend.\x0a\x09^ self\x0a\x09\x09perform: self send selector\x0a\x09\x09withArguments: self send instructions allButFirst",
  1128. messageSends: ["send:", "perform:withArguments:", "selector", "send", "allButFirst", "instructions"],
  1129. referencedClasses: []
  1130. }),
  1131. smalltalk.IRSendInliner);
  1132. smalltalk.addMethod(
  1133. smalltalk.method({
  1134. selector: "inlinedClosure",
  1135. category: 'factory',
  1136. fn: function (){
  1137. var self=this;
  1138. function $IRInlinedClosure(){return smalltalk.IRInlinedClosure||(typeof IRInlinedClosure=="undefined"?nil:IRInlinedClosure)}
  1139. return smalltalk.withContext(function($ctx1) {
  1140. var $1;
  1141. $1=_st($IRInlinedClosure())._new();
  1142. return $1;
  1143. }, function($ctx1) {$ctx1.fill(self,"inlinedClosure",{},smalltalk.IRSendInliner)})},
  1144. args: [],
  1145. source: "inlinedClosure\x0a\x09^ IRInlinedClosure new",
  1146. messageSends: ["new"],
  1147. referencedClasses: ["IRInlinedClosure"]
  1148. }),
  1149. smalltalk.IRSendInliner);
  1150. smalltalk.addMethod(
  1151. smalltalk.method({
  1152. selector: "inlinedSend:with:",
  1153. category: 'inlining',
  1154. fn: function (inlinedSend,anIRInstruction){
  1155. var self=this;
  1156. var inlinedClosure;
  1157. return smalltalk.withContext(function($ctx1) {
  1158. var $3,$2,$1,$4,$5;
  1159. if(! smalltalk.assert(_st(anIRInstruction)._isClosure())){
  1160. self._inliningError_("Message argument should be a block");
  1161. $ctx1.sendIdx["inliningError:"]=1;
  1162. };
  1163. if(! smalltalk.assert(_st(_st(_st(anIRInstruction)._arguments())._size()).__eq((0)))){
  1164. self._inliningError_("Inlined block should have zero argument");
  1165. };
  1166. inlinedClosure=_st(self._translator())._visit_(self._inlineClosure_(anIRInstruction));
  1167. $3=self._send();
  1168. $ctx1.sendIdx["send"]=1;
  1169. $2=_st($3)._instructions();
  1170. $1=_st($2)._first();
  1171. _st(inlinedSend)._add_($1);
  1172. $ctx1.sendIdx["add:"]=1;
  1173. $4=_st(inlinedSend)._add_(inlinedClosure);
  1174. $5=self._send();
  1175. _st($5)._replaceWith_(inlinedSend);
  1176. return inlinedSend;
  1177. }, function($ctx1) {$ctx1.fill(self,"inlinedSend:with:",{inlinedSend:inlinedSend,anIRInstruction:anIRInstruction,inlinedClosure:inlinedClosure},smalltalk.IRSendInliner)})},
  1178. args: ["inlinedSend", "anIRInstruction"],
  1179. source: "inlinedSend: inlinedSend with: anIRInstruction\x0a\x09| inlinedClosure |\x0a\x0a\x09anIRInstruction isClosure ifFalse: [ self inliningError: 'Message argument should be a block' ].\x0a\x09anIRInstruction arguments size = 0 ifFalse: [ self inliningError: 'Inlined block should have zero argument' ].\x0a\x0a\x09inlinedClosure := self translator visit: (self inlineClosure: anIRInstruction).\x0a\x0a\x09inlinedSend\x0a\x09\x09add: self send instructions first;\x0a\x09\x09add: inlinedClosure.\x0a\x0a\x09self send replaceWith: inlinedSend.\x0a\x0a\x09^ inlinedSend",
  1180. messageSends: ["ifFalse:", "isClosure", "inliningError:", "=", "size", "arguments", "visit:", "translator", "inlineClosure:", "add:", "first", "instructions", "send", "replaceWith:"],
  1181. referencedClasses: []
  1182. }),
  1183. smalltalk.IRSendInliner);
  1184. smalltalk.addMethod(
  1185. smalltalk.method({
  1186. selector: "inlinedSend:with:with:",
  1187. category: 'inlining',
  1188. fn: function (inlinedSend,anIRInstruction,anotherIRInstruction){
  1189. var self=this;
  1190. var inlinedClosure1,inlinedClosure2;
  1191. return smalltalk.withContext(function($ctx1) {
  1192. var $1,$2,$3,$4,$5,$6,$9,$8,$7,$10,$11;
  1193. $1=_st(anIRInstruction)._isClosure();
  1194. $ctx1.sendIdx["isClosure"]=1;
  1195. if(! smalltalk.assert($1)){
  1196. self._inliningError_("Message argument should be a block");
  1197. $ctx1.sendIdx["inliningError:"]=1;
  1198. };
  1199. $2=_st(anotherIRInstruction)._isClosure();
  1200. if(! smalltalk.assert($2)){
  1201. self._inliningError_("Message argument should be a block");
  1202. };
  1203. $3=self._translator();
  1204. $ctx1.sendIdx["translator"]=1;
  1205. $4=self._inlineClosure_(anIRInstruction);
  1206. $ctx1.sendIdx["inlineClosure:"]=1;
  1207. inlinedClosure1=_st($3)._visit_($4);
  1208. $ctx1.sendIdx["visit:"]=1;
  1209. $5=self._translator();
  1210. $6=self._inlineClosure_(anotherIRInstruction);
  1211. inlinedClosure2=_st($5)._visit_($6);
  1212. $9=self._send();
  1213. $ctx1.sendIdx["send"]=1;
  1214. $8=_st($9)._instructions();
  1215. $7=_st($8)._first();
  1216. _st(inlinedSend)._add_($7);
  1217. $ctx1.sendIdx["add:"]=1;
  1218. _st(inlinedSend)._add_(inlinedClosure1);
  1219. $ctx1.sendIdx["add:"]=2;
  1220. $10=_st(inlinedSend)._add_(inlinedClosure2);
  1221. $11=self._send();
  1222. _st($11)._replaceWith_(inlinedSend);
  1223. return inlinedSend;
  1224. }, function($ctx1) {$ctx1.fill(self,"inlinedSend:with:with:",{inlinedSend:inlinedSend,anIRInstruction:anIRInstruction,anotherIRInstruction:anotherIRInstruction,inlinedClosure1:inlinedClosure1,inlinedClosure2:inlinedClosure2},smalltalk.IRSendInliner)})},
  1225. args: ["inlinedSend", "anIRInstruction", "anotherIRInstruction"],
  1226. source: "inlinedSend: inlinedSend with: anIRInstruction with: anotherIRInstruction\x0a\x09| inlinedClosure1 inlinedClosure2 |\x0a\x0a\x09anIRInstruction isClosure ifFalse: [ self inliningError: 'Message argument should be a block' ].\x0a\x09anotherIRInstruction isClosure ifFalse: [ self inliningError: 'Message argument should be a block' ].\x0a\x0a\x09inlinedClosure1 := self translator visit: (self inlineClosure: anIRInstruction).\x0a\x09inlinedClosure2 := self translator visit: (self inlineClosure: anotherIRInstruction).\x0a\x0a\x09inlinedSend\x0a\x09\x09add: self send instructions first;\x0a\x09\x09add: inlinedClosure1;\x0a\x09\x09add: inlinedClosure2.\x0a\x0a\x09self send replaceWith: inlinedSend.\x0a\x09^ inlinedSend",
  1227. messageSends: ["ifFalse:", "isClosure", "inliningError:", "visit:", "translator", "inlineClosure:", "add:", "first", "instructions", "send", "replaceWith:"],
  1228. referencedClasses: []
  1229. }),
  1230. smalltalk.IRSendInliner);
  1231. smalltalk.addMethod(
  1232. smalltalk.method({
  1233. selector: "inlinedSequence",
  1234. category: 'factory',
  1235. fn: function (){
  1236. var self=this;
  1237. function $IRInlinedSequence(){return smalltalk.IRInlinedSequence||(typeof IRInlinedSequence=="undefined"?nil:IRInlinedSequence)}
  1238. return smalltalk.withContext(function($ctx1) {
  1239. var $1;
  1240. $1=_st($IRInlinedSequence())._new();
  1241. return $1;
  1242. }, function($ctx1) {$ctx1.fill(self,"inlinedSequence",{},smalltalk.IRSendInliner)})},
  1243. args: [],
  1244. source: "inlinedSequence\x0a\x09^ IRInlinedSequence new",
  1245. messageSends: ["new"],
  1246. referencedClasses: ["IRInlinedSequence"]
  1247. }),
  1248. smalltalk.IRSendInliner);
  1249. smalltalk.addMethod(
  1250. smalltalk.method({
  1251. selector: "inliningError:",
  1252. category: 'error handling',
  1253. fn: function (aString){
  1254. var self=this;
  1255. function $InliningError(){return smalltalk.InliningError||(typeof InliningError=="undefined"?nil:InliningError)}
  1256. return smalltalk.withContext(function($ctx1) {
  1257. _st($InliningError())._signal_(aString);
  1258. return self}, function($ctx1) {$ctx1.fill(self,"inliningError:",{aString:aString},smalltalk.IRSendInliner)})},
  1259. args: ["aString"],
  1260. source: "inliningError: aString\x0a\x09InliningError signal: aString",
  1261. messageSends: ["signal:"],
  1262. referencedClasses: ["InliningError"]
  1263. }),
  1264. smalltalk.IRSendInliner);
  1265. smalltalk.addMethod(
  1266. smalltalk.method({
  1267. selector: "send",
  1268. category: 'accessing',
  1269. fn: function (){
  1270. var self=this;
  1271. return smalltalk.withContext(function($ctx1) {
  1272. var $1;
  1273. $1=self["@send"];
  1274. return $1;
  1275. }, function($ctx1) {$ctx1.fill(self,"send",{},smalltalk.IRSendInliner)})},
  1276. args: [],
  1277. source: "send\x0a\x09^ send",
  1278. messageSends: [],
  1279. referencedClasses: []
  1280. }),
  1281. smalltalk.IRSendInliner);
  1282. smalltalk.addMethod(
  1283. smalltalk.method({
  1284. selector: "send:",
  1285. category: 'accessing',
  1286. fn: function (anIRSend){
  1287. var self=this;
  1288. return smalltalk.withContext(function($ctx1) {
  1289. self["@send"]=anIRSend;
  1290. return self}, function($ctx1) {$ctx1.fill(self,"send:",{anIRSend:anIRSend},smalltalk.IRSendInliner)})},
  1291. args: ["anIRSend"],
  1292. source: "send: anIRSend\x0a\x09send := anIRSend",
  1293. messageSends: [],
  1294. referencedClasses: []
  1295. }),
  1296. smalltalk.IRSendInliner);
  1297. smalltalk.addMethod(
  1298. smalltalk.method({
  1299. selector: "translator",
  1300. category: 'accessing',
  1301. fn: function (){
  1302. var self=this;
  1303. return smalltalk.withContext(function($ctx1) {
  1304. var $1;
  1305. $1=self["@translator"];
  1306. return $1;
  1307. }, function($ctx1) {$ctx1.fill(self,"translator",{},smalltalk.IRSendInliner)})},
  1308. args: [],
  1309. source: "translator\x0a\x09^ translator",
  1310. messageSends: [],
  1311. referencedClasses: []
  1312. }),
  1313. smalltalk.IRSendInliner);
  1314. smalltalk.addMethod(
  1315. smalltalk.method({
  1316. selector: "translator:",
  1317. category: 'accessing',
  1318. fn: function (anASTTranslator){
  1319. var self=this;
  1320. return smalltalk.withContext(function($ctx1) {
  1321. self["@translator"]=anASTTranslator;
  1322. return self}, function($ctx1) {$ctx1.fill(self,"translator:",{anASTTranslator:anASTTranslator},smalltalk.IRSendInliner)})},
  1323. args: ["anASTTranslator"],
  1324. source: "translator: anASTTranslator\x0a\x09translator := anASTTranslator",
  1325. messageSends: [],
  1326. referencedClasses: []
  1327. }),
  1328. smalltalk.IRSendInliner);
  1329. smalltalk.addMethod(
  1330. smalltalk.method({
  1331. selector: "inlinedSelectors",
  1332. category: 'accessing',
  1333. fn: function (){
  1334. var self=this;
  1335. return smalltalk.withContext(function($ctx1) {
  1336. var $1;
  1337. $1=["ifTrue:", "ifFalse:", "ifTrue:ifFalse:", "ifFalse:ifTrue:", "ifNil:", "ifNotNil:", "ifNil:ifNotNil:", "ifNotNil:ifNil:"];
  1338. return $1;
  1339. }, function($ctx1) {$ctx1.fill(self,"inlinedSelectors",{},smalltalk.IRSendInliner.klass)})},
  1340. args: [],
  1341. source: "inlinedSelectors\x0a\x09^ #('ifTrue:' 'ifFalse:' 'ifTrue:ifFalse:' 'ifFalse:ifTrue:' 'ifNil:' 'ifNotNil:' 'ifNil:ifNotNil:' 'ifNotNil:ifNil:')",
  1342. messageSends: [],
  1343. referencedClasses: []
  1344. }),
  1345. smalltalk.IRSendInliner.klass);
  1346. smalltalk.addMethod(
  1347. smalltalk.method({
  1348. selector: "shouldInline:",
  1349. category: 'accessing',
  1350. fn: function (anIRInstruction){
  1351. var self=this;
  1352. return smalltalk.withContext(function($ctx1) {
  1353. var $early={};
  1354. try {
  1355. if(! smalltalk.assert(_st(self._inlinedSelectors())._includes_(_st(anIRInstruction)._selector()))){
  1356. return false;
  1357. };
  1358. _st(_st(_st(anIRInstruction)._instructions())._allButFirst())._do_((function(each){
  1359. return smalltalk.withContext(function($ctx2) {
  1360. if(! smalltalk.assert(_st(each)._isClosure())){
  1361. throw $early=[false];
  1362. };
  1363. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)})}));
  1364. return true;
  1365. }
  1366. catch(e) {if(e===$early)return e[0]; throw e}
  1367. }, function($ctx1) {$ctx1.fill(self,"shouldInline:",{anIRInstruction:anIRInstruction},smalltalk.IRSendInliner.klass)})},
  1368. args: ["anIRInstruction"],
  1369. source: "shouldInline: anIRInstruction\x0a\x09(self inlinedSelectors includes: anIRInstruction selector) ifFalse: [ ^ false ].\x0a\x09anIRInstruction instructions allButFirst do: [ :each |\x0a\x09\x09each isClosure ifFalse: [ ^ false ]].\x0a\x09^ true",
  1370. messageSends: ["ifFalse:", "includes:", "inlinedSelectors", "selector", "do:", "allButFirst", "instructions", "isClosure"],
  1371. referencedClasses: []
  1372. }),
  1373. smalltalk.IRSendInliner.klass);
  1374. smalltalk.addClass('IRAssignmentInliner', smalltalk.IRSendInliner, ['assignment'], 'Compiler-Inlining');
  1375. smalltalk.IRAssignmentInliner.comment="I inline message sends together with assignments by moving them around into the inline closure instructions.\x0a\x0a##Example\x0a\x0a\x09foo\x0a\x09\x09| a |\x0a\x09\x09a := true ifTrue: [ 1 ]\x0a\x0aWill produce:\x0a\x0a\x09if(smalltalk.assert(true) {\x0a\x09\x09a = 1;\x0a\x09};";
  1376. smalltalk.addMethod(
  1377. smalltalk.method({
  1378. selector: "assignment",
  1379. category: 'accessing',
  1380. fn: function (){
  1381. var self=this;
  1382. return smalltalk.withContext(function($ctx1) {
  1383. var $1;
  1384. $1=self["@assignment"];
  1385. return $1;
  1386. }, function($ctx1) {$ctx1.fill(self,"assignment",{},smalltalk.IRAssignmentInliner)})},
  1387. args: [],
  1388. source: "assignment\x0a\x09^ assignment",
  1389. messageSends: [],
  1390. referencedClasses: []
  1391. }),
  1392. smalltalk.IRAssignmentInliner);
  1393. smalltalk.addMethod(
  1394. smalltalk.method({
  1395. selector: "assignment:",
  1396. category: 'accessing',
  1397. fn: function (aNode){
  1398. var self=this;
  1399. return smalltalk.withContext(function($ctx1) {
  1400. self["@assignment"]=aNode;
  1401. return self}, function($ctx1) {$ctx1.fill(self,"assignment:",{aNode:aNode},smalltalk.IRAssignmentInliner)})},
  1402. args: ["aNode"],
  1403. source: "assignment: aNode\x0a\x09assignment := aNode",
  1404. messageSends: [],
  1405. referencedClasses: []
  1406. }),
  1407. smalltalk.IRAssignmentInliner);
  1408. smalltalk.addMethod(
  1409. smalltalk.method({
  1410. selector: "inlineAssignment:",
  1411. category: 'inlining',
  1412. fn: function (anIRAssignment){
  1413. var self=this;
  1414. var inlinedAssignment;
  1415. function $IRInlinedAssignment(){return smalltalk.IRInlinedAssignment||(typeof IRInlinedAssignment=="undefined"?nil:IRInlinedAssignment)}
  1416. return smalltalk.withContext(function($ctx1) {
  1417. var $1,$3,$2,$4;
  1418. self._assignment_(anIRAssignment);
  1419. inlinedAssignment=_st($IRInlinedAssignment())._new();
  1420. $1=_st(anIRAssignment)._instructions();
  1421. $ctx1.sendIdx["instructions"]=1;
  1422. _st($1)._do_((function(each){
  1423. return smalltalk.withContext(function($ctx2) {
  1424. return _st(inlinedAssignment)._add_(each);
  1425. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1426. _st(anIRAssignment)._replaceWith_(inlinedAssignment);
  1427. $3=_st(inlinedAssignment)._instructions();
  1428. $2=_st($3)._last();
  1429. self._inlineSend_($2);
  1430. $4=inlinedAssignment;
  1431. return $4;
  1432. }, function($ctx1) {$ctx1.fill(self,"inlineAssignment:",{anIRAssignment:anIRAssignment,inlinedAssignment:inlinedAssignment},smalltalk.IRAssignmentInliner)})},
  1433. args: ["anIRAssignment"],
  1434. source: "inlineAssignment: anIRAssignment\x0a\x09| inlinedAssignment |\x0a\x09self assignment: anIRAssignment.\x0a\x09inlinedAssignment := IRInlinedAssignment new.\x0a\x09anIRAssignment instructions do: [ :each |\x0a\x09\x09inlinedAssignment add: each ].\x0a\x09anIRAssignment replaceWith: inlinedAssignment.\x0a\x09self inlineSend: inlinedAssignment instructions last.\x0a\x09^ inlinedAssignment",
  1435. messageSends: ["assignment:", "new", "do:", "instructions", "add:", "replaceWith:", "inlineSend:", "last"],
  1436. referencedClasses: ["IRInlinedAssignment"]
  1437. }),
  1438. smalltalk.IRAssignmentInliner);
  1439. smalltalk.addMethod(
  1440. smalltalk.method({
  1441. selector: "inlineClosure:",
  1442. category: 'inlining',
  1443. fn: function (anIRClosure){
  1444. var self=this;
  1445. var inlinedClosure,statements;
  1446. function $IRAssignment(){return smalltalk.IRAssignment||(typeof IRAssignment=="undefined"?nil:IRAssignment)}
  1447. return smalltalk.withContext(function($ctx1) {
  1448. var $2,$1,$4,$3,$5,$7,$8,$10,$9,$11,$13,$12,$14,$6,$15;
  1449. inlinedClosure=smalltalk.IRAssignmentInliner.superclass.fn.prototype._inlineClosure_.apply(_st(self), [anIRClosure]);
  1450. $2=_st(inlinedClosure)._instructions();
  1451. $ctx1.sendIdx["instructions"]=2;
  1452. $1=_st($2)._last();
  1453. $ctx1.sendIdx["last"]=1;
  1454. statements=_st($1)._instructions();
  1455. $ctx1.sendIdx["instructions"]=1;
  1456. _st(statements)._ifNotEmpty_((function(){
  1457. return smalltalk.withContext(function($ctx2) {
  1458. $4=_st(statements)._last();
  1459. $ctx2.sendIdx["last"]=2;
  1460. $3=_st($4)._canBeAssigned();
  1461. if(smalltalk.assert($3)){
  1462. $5=_st(statements)._last();
  1463. $ctx2.sendIdx["last"]=3;
  1464. $7=_st($IRAssignment())._new();
  1465. $8=$7;
  1466. $10=_st(self._assignment())._instructions();
  1467. $9=_st($10)._first();
  1468. _st($8)._add_($9);
  1469. $ctx2.sendIdx["add:"]=1;
  1470. $11=$7;
  1471. $13=_st(statements)._last();
  1472. $12=_st($13)._copy();
  1473. _st($11)._add_($12);
  1474. $14=_st($7)._yourself();
  1475. $6=$14;
  1476. return _st($5)._replaceWith_($6);
  1477. };
  1478. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  1479. $15=inlinedClosure;
  1480. return $15;
  1481. }, function($ctx1) {$ctx1.fill(self,"inlineClosure:",{anIRClosure:anIRClosure,inlinedClosure:inlinedClosure,statements:statements},smalltalk.IRAssignmentInliner)})},
  1482. args: ["anIRClosure"],
  1483. source: "inlineClosure: anIRClosure\x0a\x09| inlinedClosure statements |\x0a\x0a\x09inlinedClosure := super inlineClosure: anIRClosure.\x0a\x09statements := inlinedClosure instructions last instructions.\x0a\x09\x0a\x09statements ifNotEmpty: [\x0a\x09\x09statements last canBeAssigned ifTrue: [\x0a\x09\x09\x09statements last replaceWith: (IRAssignment new\x0a\x09\x09\x09\x09add: self assignment instructions first;\x0a\x09\x09\x09\x09add: statements last copy;\x0a\x09\x09\x09\x09yourself) ] ].\x0a\x0a\x09^ inlinedClosure",
  1484. messageSends: ["inlineClosure:", "instructions", "last", "ifNotEmpty:", "ifTrue:", "canBeAssigned", "replaceWith:", "add:", "new", "first", "assignment", "copy", "yourself"],
  1485. referencedClasses: ["IRAssignment"]
  1486. }),
  1487. smalltalk.IRAssignmentInliner);
  1488. smalltalk.addClass('IRReturnInliner', smalltalk.IRSendInliner, [], 'Compiler-Inlining');
  1489. smalltalk.IRReturnInliner.comment="I inline message sends with inlined closure together with a return instruction.";
  1490. smalltalk.addMethod(
  1491. smalltalk.method({
  1492. selector: "inlineClosure:",
  1493. category: 'inlining',
  1494. fn: function (anIRClosure){
  1495. var self=this;
  1496. var closure,statements;
  1497. function $IRReturn(){return smalltalk.IRReturn||(typeof IRReturn=="undefined"?nil:IRReturn)}
  1498. return smalltalk.withContext(function($ctx1) {
  1499. var $2,$1,$4,$3,$5,$7,$8,$10,$9,$11,$6,$12;
  1500. closure=smalltalk.IRReturnInliner.superclass.fn.prototype._inlineClosure_.apply(_st(self), [anIRClosure]);
  1501. $2=_st(closure)._instructions();
  1502. $1=_st($2)._last();
  1503. $ctx1.sendIdx["last"]=1;
  1504. statements=_st($1)._instructions();
  1505. $ctx1.sendIdx["instructions"]=1;
  1506. _st(statements)._ifNotEmpty_((function(){
  1507. return smalltalk.withContext(function($ctx2) {
  1508. $4=_st(statements)._last();
  1509. $ctx2.sendIdx["last"]=2;
  1510. $3=_st($4)._isReturn();
  1511. if(! smalltalk.assert($3)){
  1512. $5=_st(statements)._last();
  1513. $ctx2.sendIdx["last"]=3;
  1514. $7=_st($IRReturn())._new();
  1515. $8=$7;
  1516. $10=_st(statements)._last();
  1517. $9=_st($10)._copy();
  1518. _st($8)._add_($9);
  1519. $11=_st($7)._yourself();
  1520. $6=$11;
  1521. return _st($5)._replaceWith_($6);
  1522. };
  1523. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  1524. $12=closure;
  1525. return $12;
  1526. }, function($ctx1) {$ctx1.fill(self,"inlineClosure:",{anIRClosure:anIRClosure,closure:closure,statements:statements},smalltalk.IRReturnInliner)})},
  1527. args: ["anIRClosure"],
  1528. source: "inlineClosure: anIRClosure\x0a\x09| closure statements |\x0a\x0a\x09closure := super inlineClosure: anIRClosure.\x0a\x09statements := closure instructions last instructions.\x0a\x09\x0a\x09statements ifNotEmpty: [\x0a\x09\x09statements last isReturn\x0a\x09\x09\x09ifFalse: [ statements last replaceWith: (IRReturn new\x0a\x09\x09\x09\x09add: statements last copy;\x0a\x09\x09\x09\x09yourself)] ].\x0a\x0a\x09^ closure",
  1529. messageSends: ["inlineClosure:", "instructions", "last", "ifNotEmpty:", "ifFalse:", "isReturn", "replaceWith:", "add:", "new", "copy", "yourself"],
  1530. referencedClasses: ["IRReturn"]
  1531. }),
  1532. smalltalk.IRReturnInliner);
  1533. smalltalk.addMethod(
  1534. smalltalk.method({
  1535. selector: "inlineReturn:",
  1536. category: 'inlining',
  1537. fn: function (anIRReturn){
  1538. var self=this;
  1539. var return_;
  1540. return smalltalk.withContext(function($ctx1) {
  1541. var $1,$3,$2,$4;
  1542. return_=self._inlinedReturn();
  1543. $1=_st(anIRReturn)._instructions();
  1544. $ctx1.sendIdx["instructions"]=1;
  1545. _st($1)._do_((function(each){
  1546. return smalltalk.withContext(function($ctx2) {
  1547. return _st(return_)._add_(each);
  1548. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1549. _st(anIRReturn)._replaceWith_(return_);
  1550. $3=_st(return_)._instructions();
  1551. $2=_st($3)._last();
  1552. self._inlineSend_($2);
  1553. $4=return_;
  1554. return $4;
  1555. }, function($ctx1) {$ctx1.fill(self,"inlineReturn:",{anIRReturn:anIRReturn,return_:return_},smalltalk.IRReturnInliner)})},
  1556. args: ["anIRReturn"],
  1557. source: "inlineReturn: anIRReturn\x0a\x09| return |\x0a\x09return := self inlinedReturn.\x0a\x09anIRReturn instructions do: [ :each |\x0a\x09\x09return add: each ].\x0a\x09anIRReturn replaceWith: return.\x0a\x09self inlineSend: return instructions last.\x0a\x09^ return",
  1558. messageSends: ["inlinedReturn", "do:", "instructions", "add:", "replaceWith:", "inlineSend:", "last"],
  1559. referencedClasses: []
  1560. }),
  1561. smalltalk.IRReturnInliner);
  1562. smalltalk.addMethod(
  1563. smalltalk.method({
  1564. selector: "inlinedReturn",
  1565. category: 'factory',
  1566. fn: function (){
  1567. var self=this;
  1568. function $IRInlinedReturn(){return smalltalk.IRInlinedReturn||(typeof IRInlinedReturn=="undefined"?nil:IRInlinedReturn)}
  1569. return smalltalk.withContext(function($ctx1) {
  1570. var $1;
  1571. $1=_st($IRInlinedReturn())._new();
  1572. return $1;
  1573. }, function($ctx1) {$ctx1.fill(self,"inlinedReturn",{},smalltalk.IRReturnInliner)})},
  1574. args: [],
  1575. source: "inlinedReturn\x0a\x09^ IRInlinedReturn new",
  1576. messageSends: ["new"],
  1577. referencedClasses: ["IRInlinedReturn"]
  1578. }),
  1579. smalltalk.IRReturnInliner);
  1580. smalltalk.addClass('InliningCodeGenerator', smalltalk.CodeGenerator, [], 'Compiler-Inlining');
  1581. smalltalk.InliningCodeGenerator.comment="I am a specialized code generator that uses inlining to produce more optimized JavaScript output";
  1582. smalltalk.addMethod(
  1583. smalltalk.method({
  1584. selector: "compileNode:",
  1585. category: 'compiling',
  1586. fn: function (aNode){
  1587. var self=this;
  1588. var ir,stream;
  1589. return smalltalk.withContext(function($ctx1) {
  1590. var $2,$3,$1;
  1591. _st(self._semanticAnalyzer())._visit_(aNode);
  1592. $ctx1.sendIdx["visit:"]=1;
  1593. ir=_st(self._translator())._visit_(aNode);
  1594. $ctx1.sendIdx["visit:"]=2;
  1595. _st(self._inliner())._visit_(ir);
  1596. $ctx1.sendIdx["visit:"]=3;
  1597. $2=self._irTranslator();
  1598. _st($2)._currentClass_(self._currentClass());
  1599. _st($2)._visit_(ir);
  1600. $3=_st($2)._contents();
  1601. $1=$3;
  1602. return $1;
  1603. }, function($ctx1) {$ctx1.fill(self,"compileNode:",{aNode:aNode,ir:ir,stream:stream},smalltalk.InliningCodeGenerator)})},
  1604. args: ["aNode"],
  1605. source: "compileNode: aNode\x0a\x09| ir stream |\x0a\x0a\x09self semanticAnalyzer visit: aNode.\x0a\x09ir := self translator visit: aNode.\x0a\x09self inliner visit: ir.\x0a\x0a\x09^ self irTranslator\x0a\x09\x09currentClass: self currentClass;\x0a\x09\x09visit: ir;\x0a\x09\x09contents",
  1606. messageSends: ["visit:", "semanticAnalyzer", "translator", "inliner", "currentClass:", "irTranslator", "currentClass", "contents"],
  1607. referencedClasses: []
  1608. }),
  1609. smalltalk.InliningCodeGenerator);
  1610. smalltalk.addMethod(
  1611. smalltalk.method({
  1612. selector: "inliner",
  1613. category: 'compiling',
  1614. fn: function (){
  1615. var self=this;
  1616. function $IRInliner(){return smalltalk.IRInliner||(typeof IRInliner=="undefined"?nil:IRInliner)}
  1617. return smalltalk.withContext(function($ctx1) {
  1618. var $1;
  1619. $1=_st($IRInliner())._new();
  1620. return $1;
  1621. }, function($ctx1) {$ctx1.fill(self,"inliner",{},smalltalk.InliningCodeGenerator)})},
  1622. args: [],
  1623. source: "inliner\x0a\x09^ IRInliner new",
  1624. messageSends: ["new"],
  1625. referencedClasses: ["IRInliner"]
  1626. }),
  1627. smalltalk.InliningCodeGenerator);
  1628. smalltalk.addMethod(
  1629. smalltalk.method({
  1630. selector: "irTranslator",
  1631. category: 'compiling',
  1632. fn: function (){
  1633. var self=this;
  1634. function $IRInliningJSTranslator(){return smalltalk.IRInliningJSTranslator||(typeof IRInliningJSTranslator=="undefined"?nil:IRInliningJSTranslator)}
  1635. return smalltalk.withContext(function($ctx1) {
  1636. var $1;
  1637. $1=_st($IRInliningJSTranslator())._new();
  1638. return $1;
  1639. }, function($ctx1) {$ctx1.fill(self,"irTranslator",{},smalltalk.InliningCodeGenerator)})},
  1640. args: [],
  1641. source: "irTranslator\x0a\x09^ IRInliningJSTranslator new",
  1642. messageSends: ["new"],
  1643. referencedClasses: ["IRInliningJSTranslator"]
  1644. }),
  1645. smalltalk.InliningCodeGenerator);
  1646. });