Compiler-Inlining.js 66 KB

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