Compiler-Inlining.js 70 KB

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