Compiler-Inlining.js 70 KB

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