Compiler-Inlining.js 57 KB

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