Compiler-Inlining.js 66 KB

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