Compiler-Inlining.js 70 KB

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