1
0

Compiler-Inlining.js 66 KB

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