Compiler-Inlining.js 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746
  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=($ctx1.supercall = true, globals.IRInliner.superclass.fn.prototype._visitIRNonLocalReturn_.apply(_st(self), [anIRNonLocalReturn]));
  480. $ctx1.supercall = false;
  481. return $9;
  482. }, function($ctx1) {$ctx1.fill(self,"transformNonLocalReturn:",{anIRNonLocalReturn:anIRNonLocalReturn,localReturn:localReturn},globals.IRInliner)})},
  483. args: ["anIRNonLocalReturn"],
  484. 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",
  485. messageSends: ["ifTrue:", "canInlineNonLocalReturns", "scope", "removeNonLocalReturn:", "methodScope", "scope:", "new", "yourself", "do:", "instructions", "add:", "replaceWith:", "visitIRNonLocalReturn:"],
  486. referencedClasses: ["IRReturn"]
  487. }),
  488. globals.IRInliner);
  489. smalltalk.addMethod(
  490. smalltalk.method({
  491. selector: "visitIRAssignment:",
  492. protocol: 'visiting',
  493. fn: function (anIRAssignment){
  494. var self=this;
  495. return smalltalk.withContext(function($ctx1) {
  496. var $2,$1;
  497. $2=self._shouldInlineAssignment_(anIRAssignment);
  498. if(smalltalk.assert($2)){
  499. $1=_st(self._assignmentInliner())._inlineAssignment_(anIRAssignment);
  500. } else {
  501. $1=($ctx1.supercall = true, globals.IRInliner.superclass.fn.prototype._visitIRAssignment_.apply(_st(self), [anIRAssignment]));
  502. $ctx1.supercall = false;
  503. };
  504. return $1;
  505. }, function($ctx1) {$ctx1.fill(self,"visitIRAssignment:",{anIRAssignment:anIRAssignment},globals.IRInliner)})},
  506. args: ["anIRAssignment"],
  507. source: "visitIRAssignment: anIRAssignment\x0a\x09^ (self shouldInlineAssignment: anIRAssignment)\x0a\x09\x09ifTrue: [ self assignmentInliner inlineAssignment: anIRAssignment ]\x0a\x09\x09ifFalse: [ super visitIRAssignment: anIRAssignment ]",
  508. messageSends: ["ifTrue:ifFalse:", "shouldInlineAssignment:", "inlineAssignment:", "assignmentInliner", "visitIRAssignment:"],
  509. referencedClasses: []
  510. }),
  511. globals.IRInliner);
  512. smalltalk.addMethod(
  513. smalltalk.method({
  514. selector: "visitIRNonLocalReturn:",
  515. protocol: 'visiting',
  516. fn: function (anIRNonLocalReturn){
  517. var self=this;
  518. return smalltalk.withContext(function($ctx1) {
  519. var $1;
  520. $1=self._transformNonLocalReturn_(anIRNonLocalReturn);
  521. return $1;
  522. }, function($ctx1) {$ctx1.fill(self,"visitIRNonLocalReturn:",{anIRNonLocalReturn:anIRNonLocalReturn},globals.IRInliner)})},
  523. args: ["anIRNonLocalReturn"],
  524. source: "visitIRNonLocalReturn: anIRNonLocalReturn\x0a\x09^ self transformNonLocalReturn: anIRNonLocalReturn",
  525. messageSends: ["transformNonLocalReturn:"],
  526. referencedClasses: []
  527. }),
  528. globals.IRInliner);
  529. smalltalk.addMethod(
  530. smalltalk.method({
  531. selector: "visitIRReturn:",
  532. protocol: 'visiting',
  533. fn: function (anIRReturn){
  534. var self=this;
  535. return smalltalk.withContext(function($ctx1) {
  536. var $2,$1;
  537. $2=self._shouldInlineReturn_(anIRReturn);
  538. if(smalltalk.assert($2)){
  539. $1=_st(self._returnInliner())._inlineReturn_(anIRReturn);
  540. } else {
  541. $1=($ctx1.supercall = true, globals.IRInliner.superclass.fn.prototype._visitIRReturn_.apply(_st(self), [anIRReturn]));
  542. $ctx1.supercall = false;
  543. };
  544. return $1;
  545. }, function($ctx1) {$ctx1.fill(self,"visitIRReturn:",{anIRReturn:anIRReturn},globals.IRInliner)})},
  546. args: ["anIRReturn"],
  547. source: "visitIRReturn: anIRReturn\x0a\x09^ (self shouldInlineReturn: anIRReturn)\x0a\x09\x09ifTrue: [ self returnInliner inlineReturn: anIRReturn ]\x0a\x09\x09ifFalse: [ super visitIRReturn: anIRReturn ]",
  548. messageSends: ["ifTrue:ifFalse:", "shouldInlineReturn:", "inlineReturn:", "returnInliner", "visitIRReturn:"],
  549. referencedClasses: []
  550. }),
  551. globals.IRInliner);
  552. smalltalk.addMethod(
  553. smalltalk.method({
  554. selector: "visitIRSend:",
  555. protocol: 'visiting',
  556. fn: function (anIRSend){
  557. var self=this;
  558. return smalltalk.withContext(function($ctx1) {
  559. var $2,$1;
  560. $2=self._shouldInlineSend_(anIRSend);
  561. if(smalltalk.assert($2)){
  562. $1=_st(self._sendInliner())._inlineSend_(anIRSend);
  563. } else {
  564. $1=($ctx1.supercall = true, globals.IRInliner.superclass.fn.prototype._visitIRSend_.apply(_st(self), [anIRSend]));
  565. $ctx1.supercall = false;
  566. };
  567. return $1;
  568. }, function($ctx1) {$ctx1.fill(self,"visitIRSend:",{anIRSend:anIRSend},globals.IRInliner)})},
  569. args: ["anIRSend"],
  570. source: "visitIRSend: anIRSend\x0a\x09^ (self shouldInlineSend: anIRSend)\x0a\x09\x09ifTrue: [ self sendInliner inlineSend: anIRSend ]\x0a\x09\x09ifFalse: [ super visitIRSend: anIRSend ]",
  571. messageSends: ["ifTrue:ifFalse:", "shouldInlineSend:", "inlineSend:", "sendInliner", "visitIRSend:"],
  572. referencedClasses: []
  573. }),
  574. globals.IRInliner);
  575. smalltalk.addClass('IRInliningJSTranslator', globals.IRJSTranslator, [], 'Compiler-Inlining');
  576. globals.IRInliningJSTranslator.comment="I am a specialized JavaScript translator able to write inlined IR instructions to JavaScript stream (`JSStream` instance).";
  577. smalltalk.addMethod(
  578. smalltalk.method({
  579. selector: "visitIRInlinedAssignment:",
  580. protocol: 'visiting',
  581. fn: function (anIRInlinedAssignment){
  582. var self=this;
  583. return smalltalk.withContext(function($ctx1) {
  584. self._visit_(_st(_st(anIRInlinedAssignment)._instructions())._last());
  585. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedAssignment:",{anIRInlinedAssignment:anIRInlinedAssignment},globals.IRInliningJSTranslator)})},
  586. args: ["anIRInlinedAssignment"],
  587. source: "visitIRInlinedAssignment: anIRInlinedAssignment\x0a\x09self visit: anIRInlinedAssignment instructions last",
  588. messageSends: ["visit:", "last", "instructions"],
  589. referencedClasses: []
  590. }),
  591. globals.IRInliningJSTranslator);
  592. smalltalk.addMethod(
  593. smalltalk.method({
  594. selector: "visitIRInlinedClosure:",
  595. protocol: 'visiting',
  596. fn: function (anIRInlinedClosure){
  597. var self=this;
  598. return smalltalk.withContext(function($ctx1) {
  599. _st(self._stream())._nextPutVars_(_st(_st(anIRInlinedClosure)._tempDeclarations())._collect_((function(each){
  600. return smalltalk.withContext(function($ctx2) {
  601. return _st(_st(each)._name())._asVariableName();
  602. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})})));
  603. _st(_st(anIRInlinedClosure)._instructions())._do_((function(each){
  604. return smalltalk.withContext(function($ctx2) {
  605. return self._visit_(each);
  606. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)})}));
  607. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedClosure:",{anIRInlinedClosure:anIRInlinedClosure},globals.IRInliningJSTranslator)})},
  608. args: ["anIRInlinedClosure"],
  609. 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 ]",
  610. messageSends: ["nextPutVars:", "stream", "collect:", "tempDeclarations", "asVariableName", "name", "do:", "instructions", "visit:"],
  611. referencedClasses: []
  612. }),
  613. globals.IRInliningJSTranslator);
  614. smalltalk.addMethod(
  615. smalltalk.method({
  616. selector: "visitIRInlinedIfFalse:",
  617. protocol: 'visiting',
  618. fn: function (anIRInlinedIfFalse){
  619. var self=this;
  620. return smalltalk.withContext(function($ctx1) {
  621. var $1,$2,$4,$3;
  622. $1=self._stream();
  623. $ctx1.sendIdx["stream"]=1;
  624. _st($1)._nextPutIf_with_((function(){
  625. return smalltalk.withContext(function($ctx2) {
  626. $2=self._stream();
  627. $ctx2.sendIdx["stream"]=2;
  628. _st($2)._nextPutAll_("! smalltalk.assert(");
  629. $ctx2.sendIdx["nextPutAll:"]=1;
  630. $4=_st(anIRInlinedIfFalse)._instructions();
  631. $ctx2.sendIdx["instructions"]=1;
  632. $3=_st($4)._first();
  633. self._visit_($3);
  634. $ctx2.sendIdx["visit:"]=1;
  635. return _st(self._stream())._nextPutAll_(")");
  636. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),(function(){
  637. return smalltalk.withContext(function($ctx2) {
  638. return self._visit_(_st(_st(anIRInlinedIfFalse)._instructions())._last());
  639. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  640. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedIfFalse:",{anIRInlinedIfFalse:anIRInlinedIfFalse},globals.IRInliningJSTranslator)})},
  641. args: ["anIRInlinedIfFalse"],
  642. 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 ]",
  643. messageSends: ["nextPutIf:with:", "stream", "nextPutAll:", "visit:", "first", "instructions", "last"],
  644. referencedClasses: []
  645. }),
  646. globals.IRInliningJSTranslator);
  647. smalltalk.addMethod(
  648. smalltalk.method({
  649. selector: "visitIRInlinedIfNilIfNotNil:",
  650. protocol: 'visiting',
  651. fn: function (anIRInlinedIfNilIfNotNil){
  652. var self=this;
  653. return smalltalk.withContext(function($ctx1) {
  654. var $1,$2,$3,$5,$4,$7,$6;
  655. $1=self._stream();
  656. $ctx1.sendIdx["stream"]=1;
  657. _st($1)._nextPutIfElse_with_with_((function(){
  658. return smalltalk.withContext(function($ctx2) {
  659. $2=self._stream();
  660. $ctx2.sendIdx["stream"]=2;
  661. $3=_st("(".__comma(_st(anIRInlinedIfNilIfNotNil)._receiverInternalVariableName())).__comma(" = ");
  662. $ctx2.sendIdx[","]=1;
  663. _st($2)._nextPutAll_($3);
  664. $ctx2.sendIdx["nextPutAll:"]=1;
  665. $5=_st(anIRInlinedIfNilIfNotNil)._instructions();
  666. $ctx2.sendIdx["instructions"]=1;
  667. $4=_st($5)._first();
  668. self._visit_($4);
  669. $ctx2.sendIdx["visit:"]=1;
  670. return _st(self._stream())._nextPutAll_(") == null || $receiver.isNil");
  671. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),(function(){
  672. return smalltalk.withContext(function($ctx2) {
  673. $7=_st(anIRInlinedIfNilIfNotNil)._instructions();
  674. $ctx2.sendIdx["instructions"]=2;
  675. $6=_st($7)._second();
  676. return self._visit_($6);
  677. $ctx2.sendIdx["visit:"]=2;
  678. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}),(function(){
  679. return smalltalk.withContext(function($ctx2) {
  680. return self._visit_(_st(_st(anIRInlinedIfNilIfNotNil)._instructions())._third());
  681. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)})}));
  682. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedIfNilIfNotNil:",{anIRInlinedIfNilIfNotNil:anIRInlinedIfNilIfNotNil},globals.IRInliningJSTranslator)})},
  683. args: ["anIRInlinedIfNilIfNotNil"],
  684. 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 ]",
  685. messageSends: ["nextPutIfElse:with:with:", "stream", "nextPutAll:", ",", "receiverInternalVariableName", "visit:", "first", "instructions", "second", "third"],
  686. referencedClasses: []
  687. }),
  688. globals.IRInliningJSTranslator);
  689. smalltalk.addMethod(
  690. smalltalk.method({
  691. selector: "visitIRInlinedIfTrue:",
  692. protocol: 'visiting',
  693. fn: function (anIRInlinedIfTrue){
  694. var self=this;
  695. return smalltalk.withContext(function($ctx1) {
  696. var $1,$2,$4,$3;
  697. $1=self._stream();
  698. $ctx1.sendIdx["stream"]=1;
  699. _st($1)._nextPutIf_with_((function(){
  700. return smalltalk.withContext(function($ctx2) {
  701. $2=self._stream();
  702. $ctx2.sendIdx["stream"]=2;
  703. _st($2)._nextPutAll_("smalltalk.assert(");
  704. $ctx2.sendIdx["nextPutAll:"]=1;
  705. $4=_st(anIRInlinedIfTrue)._instructions();
  706. $ctx2.sendIdx["instructions"]=1;
  707. $3=_st($4)._first();
  708. self._visit_($3);
  709. $ctx2.sendIdx["visit:"]=1;
  710. return _st(self._stream())._nextPutAll_(")");
  711. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),(function(){
  712. return smalltalk.withContext(function($ctx2) {
  713. return self._visit_(_st(_st(anIRInlinedIfTrue)._instructions())._last());
  714. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  715. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedIfTrue:",{anIRInlinedIfTrue:anIRInlinedIfTrue},globals.IRInliningJSTranslator)})},
  716. args: ["anIRInlinedIfTrue"],
  717. 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 ]",
  718. messageSends: ["nextPutIf:with:", "stream", "nextPutAll:", "visit:", "first", "instructions", "last"],
  719. referencedClasses: []
  720. }),
  721. globals.IRInliningJSTranslator);
  722. smalltalk.addMethod(
  723. smalltalk.method({
  724. selector: "visitIRInlinedIfTrueIfFalse:",
  725. protocol: 'visiting',
  726. fn: function (anIRInlinedIfTrueIfFalse){
  727. var self=this;
  728. return smalltalk.withContext(function($ctx1) {
  729. var $1,$2,$4,$3,$6,$5;
  730. $1=self._stream();
  731. $ctx1.sendIdx["stream"]=1;
  732. _st($1)._nextPutIfElse_with_with_((function(){
  733. return smalltalk.withContext(function($ctx2) {
  734. $2=self._stream();
  735. $ctx2.sendIdx["stream"]=2;
  736. _st($2)._nextPutAll_("smalltalk.assert(");
  737. $ctx2.sendIdx["nextPutAll:"]=1;
  738. $4=_st(anIRInlinedIfTrueIfFalse)._instructions();
  739. $ctx2.sendIdx["instructions"]=1;
  740. $3=_st($4)._first();
  741. self._visit_($3);
  742. $ctx2.sendIdx["visit:"]=1;
  743. return _st(self._stream())._nextPutAll_(")");
  744. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),(function(){
  745. return smalltalk.withContext(function($ctx2) {
  746. $6=_st(anIRInlinedIfTrueIfFalse)._instructions();
  747. $ctx2.sendIdx["instructions"]=2;
  748. $5=_st($6)._second();
  749. return self._visit_($5);
  750. $ctx2.sendIdx["visit:"]=2;
  751. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}),(function(){
  752. return smalltalk.withContext(function($ctx2) {
  753. return self._visit_(_st(_st(anIRInlinedIfTrueIfFalse)._instructions())._third());
  754. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)})}));
  755. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedIfTrueIfFalse:",{anIRInlinedIfTrueIfFalse:anIRInlinedIfTrueIfFalse},globals.IRInliningJSTranslator)})},
  756. args: ["anIRInlinedIfTrueIfFalse"],
  757. 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 ]",
  758. messageSends: ["nextPutIfElse:with:with:", "stream", "nextPutAll:", "visit:", "first", "instructions", "second", "third"],
  759. referencedClasses: []
  760. }),
  761. globals.IRInliningJSTranslator);
  762. smalltalk.addMethod(
  763. smalltalk.method({
  764. selector: "visitIRInlinedNonLocalReturn:",
  765. protocol: 'visiting',
  766. fn: function (anIRInlinedReturn){
  767. var self=this;
  768. return smalltalk.withContext(function($ctx1) {
  769. var $1;
  770. $1=self._stream();
  771. $ctx1.sendIdx["stream"]=1;
  772. _st($1)._nextPutStatementWith_((function(){
  773. return smalltalk.withContext(function($ctx2) {
  774. return self._visit_(_st(_st(anIRInlinedReturn)._instructions())._last());
  775. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  776. _st(self._stream())._nextPutNonLocalReturnWith_((function(){
  777. }));
  778. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedNonLocalReturn:",{anIRInlinedReturn:anIRInlinedReturn},globals.IRInliningJSTranslator)})},
  779. args: ["anIRInlinedReturn"],
  780. source: "visitIRInlinedNonLocalReturn: anIRInlinedReturn\x0a\x09self stream nextPutStatementWith: [\x0a\x09\x09self visit: anIRInlinedReturn instructions last ].\x0a\x09self stream nextPutNonLocalReturnWith: [ ]",
  781. messageSends: ["nextPutStatementWith:", "stream", "visit:", "last", "instructions", "nextPutNonLocalReturnWith:"],
  782. referencedClasses: []
  783. }),
  784. globals.IRInliningJSTranslator);
  785. smalltalk.addMethod(
  786. smalltalk.method({
  787. selector: "visitIRInlinedReturn:",
  788. protocol: 'visiting',
  789. fn: function (anIRInlinedReturn){
  790. var self=this;
  791. return smalltalk.withContext(function($ctx1) {
  792. self._visit_(_st(_st(anIRInlinedReturn)._instructions())._last());
  793. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedReturn:",{anIRInlinedReturn:anIRInlinedReturn},globals.IRInliningJSTranslator)})},
  794. args: ["anIRInlinedReturn"],
  795. source: "visitIRInlinedReturn: anIRInlinedReturn\x0a\x09self visit: anIRInlinedReturn instructions last",
  796. messageSends: ["visit:", "last", "instructions"],
  797. referencedClasses: []
  798. }),
  799. globals.IRInliningJSTranslator);
  800. smalltalk.addMethod(
  801. smalltalk.method({
  802. selector: "visitIRInlinedSequence:",
  803. protocol: 'visiting',
  804. fn: function (anIRInlinedSequence){
  805. var self=this;
  806. return smalltalk.withContext(function($ctx1) {
  807. _st(_st(anIRInlinedSequence)._instructions())._do_((function(each){
  808. return smalltalk.withContext(function($ctx2) {
  809. return _st(self._stream())._nextPutStatementWith_((function(){
  810. return smalltalk.withContext(function($ctx3) {
  811. return self._visit_(each);
  812. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
  813. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  814. return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedSequence:",{anIRInlinedSequence:anIRInlinedSequence},globals.IRInliningJSTranslator)})},
  815. args: ["anIRInlinedSequence"],
  816. source: "visitIRInlinedSequence: anIRInlinedSequence\x0a\x09anIRInlinedSequence instructions do: [ :each |\x0a\x09\x09self stream nextPutStatementWith: [ self visit: each ]]",
  817. messageSends: ["do:", "instructions", "nextPutStatementWith:", "stream", "visit:"],
  818. referencedClasses: []
  819. }),
  820. globals.IRInliningJSTranslator);
  821. smalltalk.addClass('IRSendInliner', globals.Object, ['send', 'translator'], 'Compiler-Inlining');
  822. globals.IRSendInliner.comment="I inline some message sends and block closure arguments. I heavily rely on #perform: to dispatch inlining methods.";
  823. smalltalk.addMethod(
  824. smalltalk.method({
  825. selector: "ifFalse:",
  826. protocol: 'inlining',
  827. fn: function (anIRInstruction){
  828. var self=this;
  829. function $IRInlinedIfFalse(){return globals.IRInlinedIfFalse||(typeof IRInlinedIfFalse=="undefined"?nil:IRInlinedIfFalse)}
  830. return smalltalk.withContext(function($ctx1) {
  831. var $1;
  832. $1=self._inlinedSend_with_(_st($IRInlinedIfFalse())._new(),anIRInstruction);
  833. return $1;
  834. }, function($ctx1) {$ctx1.fill(self,"ifFalse:",{anIRInstruction:anIRInstruction},globals.IRSendInliner)})},
  835. args: ["anIRInstruction"],
  836. source: "ifFalse: anIRInstruction\x0a\x09^ self inlinedSend: IRInlinedIfFalse new with: anIRInstruction",
  837. messageSends: ["inlinedSend:with:", "new"],
  838. referencedClasses: ["IRInlinedIfFalse"]
  839. }),
  840. globals.IRSendInliner);
  841. smalltalk.addMethod(
  842. smalltalk.method({
  843. selector: "ifFalse:ifTrue:",
  844. protocol: 'inlining',
  845. fn: function (anIRInstruction,anotherIRInstruction){
  846. var self=this;
  847. return smalltalk.withContext(function($ctx1) {
  848. var $1;
  849. $1=self._perform_withArguments_("ifTrue:ifFalse:",[anotherIRInstruction,anIRInstruction]);
  850. return $1;
  851. }, function($ctx1) {$ctx1.fill(self,"ifFalse:ifTrue:",{anIRInstruction:anIRInstruction,anotherIRInstruction:anotherIRInstruction},globals.IRSendInliner)})},
  852. args: ["anIRInstruction", "anotherIRInstruction"],
  853. source: "ifFalse: anIRInstruction ifTrue: anotherIRInstruction\x0a\x09^ self perform: #ifTrue:ifFalse: withArguments: { anotherIRInstruction. anIRInstruction }",
  854. messageSends: ["perform:withArguments:"],
  855. referencedClasses: []
  856. }),
  857. globals.IRSendInliner);
  858. smalltalk.addMethod(
  859. smalltalk.method({
  860. selector: "ifNil:",
  861. protocol: 'inlining',
  862. fn: function (anIRInstruction){
  863. var self=this;
  864. function $IRInlinedIfNilIfNotNil(){return globals.IRInlinedIfNilIfNotNil||(typeof IRInlinedIfNilIfNotNil=="undefined"?nil:IRInlinedIfNilIfNotNil)}
  865. function $IRClosure(){return globals.IRClosure||(typeof IRClosure=="undefined"?nil:IRClosure)}
  866. function $IRBlockSequence(){return globals.IRBlockSequence||(typeof IRBlockSequence=="undefined"?nil:IRBlockSequence)}
  867. return smalltalk.withContext(function($ctx1) {
  868. var $2,$4,$5,$7,$8,$6,$9,$3,$1;
  869. $2=_st($IRInlinedIfNilIfNotNil())._new();
  870. $ctx1.sendIdx["new"]=1;
  871. $4=_st($IRClosure())._new();
  872. $ctx1.sendIdx["new"]=2;
  873. _st($4)._scope_(_st(_st(anIRInstruction)._scope())._copy());
  874. $5=$4;
  875. $7=_st($IRBlockSequence())._new();
  876. _st($7)._add_(_st(_st(self._send())._instructions())._first());
  877. $8=_st($7)._yourself();
  878. $ctx1.sendIdx["yourself"]=1;
  879. $6=$8;
  880. _st($5)._add_($6);
  881. $ctx1.sendIdx["add:"]=1;
  882. $9=_st($4)._yourself();
  883. $3=$9;
  884. $1=self._inlinedSend_with_with_($2,anIRInstruction,$3);
  885. return $1;
  886. }, function($ctx1) {$ctx1.fill(self,"ifNil:",{anIRInstruction:anIRInstruction},globals.IRSendInliner)})},
  887. args: ["anIRInstruction"],
  888. 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)",
  889. messageSends: ["inlinedSend:with:with:", "new", "scope:", "copy", "scope", "add:", "first", "instructions", "send", "yourself"],
  890. referencedClasses: ["IRInlinedIfNilIfNotNil", "IRClosure", "IRBlockSequence"]
  891. }),
  892. globals.IRSendInliner);
  893. smalltalk.addMethod(
  894. smalltalk.method({
  895. selector: "ifNil:ifNotNil:",
  896. protocol: 'inlining',
  897. fn: function (anIRInstruction,anotherIRInstruction){
  898. var self=this;
  899. function $IRInlinedIfNilIfNotNil(){return globals.IRInlinedIfNilIfNotNil||(typeof IRInlinedIfNilIfNotNil=="undefined"?nil:IRInlinedIfNilIfNotNil)}
  900. return smalltalk.withContext(function($ctx1) {
  901. var $1;
  902. $1=self._inlinedSend_with_with_(_st($IRInlinedIfNilIfNotNil())._new(),anIRInstruction,anotherIRInstruction);
  903. return $1;
  904. }, function($ctx1) {$ctx1.fill(self,"ifNil:ifNotNil:",{anIRInstruction:anIRInstruction,anotherIRInstruction:anotherIRInstruction},globals.IRSendInliner)})},
  905. args: ["anIRInstruction", "anotherIRInstruction"],
  906. source: "ifNil: anIRInstruction ifNotNil: anotherIRInstruction\x0a\x09^ self inlinedSend: IRInlinedIfNilIfNotNil new with: anIRInstruction with: anotherIRInstruction",
  907. messageSends: ["inlinedSend:with:with:", "new"],
  908. referencedClasses: ["IRInlinedIfNilIfNotNil"]
  909. }),
  910. globals.IRSendInliner);
  911. smalltalk.addMethod(
  912. smalltalk.method({
  913. selector: "ifNotNil:",
  914. protocol: 'inlining',
  915. fn: function (anIRInstruction){
  916. var self=this;
  917. function $IRInlinedIfNilIfNotNil(){return globals.IRInlinedIfNilIfNotNil||(typeof IRInlinedIfNilIfNotNil=="undefined"?nil:IRInlinedIfNilIfNotNil)}
  918. function $IRClosure(){return globals.IRClosure||(typeof IRClosure=="undefined"?nil:IRClosure)}
  919. function $IRBlockSequence(){return globals.IRBlockSequence||(typeof IRBlockSequence=="undefined"?nil:IRBlockSequence)}
  920. return smalltalk.withContext(function($ctx1) {
  921. var $2,$4,$5,$7,$8,$6,$9,$3,$1;
  922. $2=_st($IRInlinedIfNilIfNotNil())._new();
  923. $ctx1.sendIdx["new"]=1;
  924. $4=_st($IRClosure())._new();
  925. $ctx1.sendIdx["new"]=2;
  926. _st($4)._scope_(_st(_st(anIRInstruction)._scope())._copy());
  927. $5=$4;
  928. $7=_st($IRBlockSequence())._new();
  929. _st($7)._add_(_st(_st(self._send())._instructions())._first());
  930. $8=_st($7)._yourself();
  931. $ctx1.sendIdx["yourself"]=1;
  932. $6=$8;
  933. _st($5)._add_($6);
  934. $ctx1.sendIdx["add:"]=1;
  935. $9=_st($4)._yourself();
  936. $3=$9;
  937. $1=self._inlinedSend_with_with_($2,$3,anIRInstruction);
  938. return $1;
  939. }, function($ctx1) {$ctx1.fill(self,"ifNotNil:",{anIRInstruction:anIRInstruction},globals.IRSendInliner)})},
  940. args: ["anIRInstruction"],
  941. 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",
  942. messageSends: ["inlinedSend:with:with:", "new", "scope:", "copy", "scope", "add:", "first", "instructions", "send", "yourself"],
  943. referencedClasses: ["IRInlinedIfNilIfNotNil", "IRClosure", "IRBlockSequence"]
  944. }),
  945. globals.IRSendInliner);
  946. smalltalk.addMethod(
  947. smalltalk.method({
  948. selector: "ifNotNil:ifNil:",
  949. protocol: 'inlining',
  950. fn: function (anIRInstruction,anotherIRInstruction){
  951. var self=this;
  952. function $IRInlinedIfNilIfNotNil(){return globals.IRInlinedIfNilIfNotNil||(typeof IRInlinedIfNilIfNotNil=="undefined"?nil:IRInlinedIfNilIfNotNil)}
  953. return smalltalk.withContext(function($ctx1) {
  954. var $1;
  955. $1=self._inlinedSend_with_with_(_st($IRInlinedIfNilIfNotNil())._new(),anotherIRInstruction,anIRInstruction);
  956. return $1;
  957. }, function($ctx1) {$ctx1.fill(self,"ifNotNil:ifNil:",{anIRInstruction:anIRInstruction,anotherIRInstruction:anotherIRInstruction},globals.IRSendInliner)})},
  958. args: ["anIRInstruction", "anotherIRInstruction"],
  959. source: "ifNotNil: anIRInstruction ifNil: anotherIRInstruction\x0a\x09^ self inlinedSend: IRInlinedIfNilIfNotNil new with: anotherIRInstruction with: anIRInstruction",
  960. messageSends: ["inlinedSend:with:with:", "new"],
  961. referencedClasses: ["IRInlinedIfNilIfNotNil"]
  962. }),
  963. globals.IRSendInliner);
  964. smalltalk.addMethod(
  965. smalltalk.method({
  966. selector: "ifTrue:",
  967. protocol: 'inlining',
  968. fn: function (anIRInstruction){
  969. var self=this;
  970. function $IRInlinedIfTrue(){return globals.IRInlinedIfTrue||(typeof IRInlinedIfTrue=="undefined"?nil:IRInlinedIfTrue)}
  971. return smalltalk.withContext(function($ctx1) {
  972. var $1;
  973. $1=self._inlinedSend_with_(_st($IRInlinedIfTrue())._new(),anIRInstruction);
  974. return $1;
  975. }, function($ctx1) {$ctx1.fill(self,"ifTrue:",{anIRInstruction:anIRInstruction},globals.IRSendInliner)})},
  976. args: ["anIRInstruction"],
  977. source: "ifTrue: anIRInstruction\x0a\x09^ self inlinedSend: IRInlinedIfTrue new with: anIRInstruction",
  978. messageSends: ["inlinedSend:with:", "new"],
  979. referencedClasses: ["IRInlinedIfTrue"]
  980. }),
  981. globals.IRSendInliner);
  982. smalltalk.addMethod(
  983. smalltalk.method({
  984. selector: "ifTrue:ifFalse:",
  985. protocol: 'inlining',
  986. fn: function (anIRInstruction,anotherIRInstruction){
  987. var self=this;
  988. function $IRInlinedIfTrueIfFalse(){return globals.IRInlinedIfTrueIfFalse||(typeof IRInlinedIfTrueIfFalse=="undefined"?nil:IRInlinedIfTrueIfFalse)}
  989. return smalltalk.withContext(function($ctx1) {
  990. var $1;
  991. $1=self._inlinedSend_with_with_(_st($IRInlinedIfTrueIfFalse())._new(),anIRInstruction,anotherIRInstruction);
  992. return $1;
  993. }, function($ctx1) {$ctx1.fill(self,"ifTrue:ifFalse:",{anIRInstruction:anIRInstruction,anotherIRInstruction:anotherIRInstruction},globals.IRSendInliner)})},
  994. args: ["anIRInstruction", "anotherIRInstruction"],
  995. source: "ifTrue: anIRInstruction ifFalse: anotherIRInstruction\x0a\x09^ self inlinedSend: IRInlinedIfTrueIfFalse new with: anIRInstruction with: anotherIRInstruction",
  996. messageSends: ["inlinedSend:with:with:", "new"],
  997. referencedClasses: ["IRInlinedIfTrueIfFalse"]
  998. }),
  999. globals.IRSendInliner);
  1000. smalltalk.addMethod(
  1001. smalltalk.method({
  1002. selector: "inlineClosure:",
  1003. protocol: 'inlining',
  1004. fn: function (anIRClosure){
  1005. var self=this;
  1006. var inlinedClosure,sequence,statements;
  1007. function $IRTempDeclaration(){return globals.IRTempDeclaration||(typeof IRTempDeclaration=="undefined"?nil:IRTempDeclaration)}
  1008. function $IRAssignment(){return globals.IRAssignment||(typeof IRAssignment=="undefined"?nil:IRAssignment)}
  1009. function $IRVariable(){return globals.IRVariable||(typeof IRVariable=="undefined"?nil:IRVariable)}
  1010. function $AliasVar(){return globals.AliasVar||(typeof AliasVar=="undefined"?nil:AliasVar)}
  1011. return smalltalk.withContext(function($ctx1) {
  1012. 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;
  1013. inlinedClosure=self._inlinedClosure();
  1014. $1=inlinedClosure;
  1015. $2=$1;
  1016. $3=_st(anIRClosure)._scope();
  1017. $ctx1.sendIdx["scope"]=1;
  1018. _st($2)._scope_($3);
  1019. $ctx1.sendIdx["scope:"]=1;
  1020. $4=_st($1)._parent_(_st(anIRClosure)._parent());
  1021. _st(_st(anIRClosure)._tempDeclarations())._do_((function(each){
  1022. return smalltalk.withContext(function($ctx2) {
  1023. return _st(inlinedClosure)._add_(each);
  1024. $ctx2.sendIdx["add:"]=1;
  1025. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1026. $ctx1.sendIdx["do:"]=1;
  1027. sequence=self._inlinedSequence();
  1028. _st(_st(anIRClosure)._arguments())._do_((function(each){
  1029. return smalltalk.withContext(function($ctx2) {
  1030. $5=inlinedClosure;
  1031. $7=_st($IRTempDeclaration())._new();
  1032. $ctx2.sendIdx["new"]=1;
  1033. _st($7)._name_(each);
  1034. $ctx2.sendIdx["name:"]=1;
  1035. $8=_st($7)._yourself();
  1036. $ctx2.sendIdx["yourself"]=1;
  1037. $6=$8;
  1038. _st($5)._add_($6);
  1039. $ctx2.sendIdx["add:"]=2;
  1040. $9=sequence;
  1041. $11=_st($IRAssignment())._new();
  1042. $ctx2.sendIdx["new"]=2;
  1043. $12=$11;
  1044. $14=_st($IRVariable())._new();
  1045. $ctx2.sendIdx["new"]=3;
  1046. $16=_st($AliasVar())._new();
  1047. $ctx2.sendIdx["new"]=4;
  1048. $17=$16;
  1049. $18=_st(inlinedClosure)._scope();
  1050. $ctx2.sendIdx["scope"]=2;
  1051. _st($17)._scope_($18);
  1052. $ctx2.sendIdx["scope:"]=2;
  1053. _st($16)._name_(each);
  1054. $ctx2.sendIdx["name:"]=2;
  1055. $19=_st($16)._yourself();
  1056. $ctx2.sendIdx["yourself"]=2;
  1057. $15=$19;
  1058. $13=_st($14)._variable_($15);
  1059. $ctx2.sendIdx["variable:"]=1;
  1060. _st($12)._add_($13);
  1061. $ctx2.sendIdx["add:"]=4;
  1062. $20=$11;
  1063. $22=_st($IRVariable())._new();
  1064. $ctx2.sendIdx["new"]=5;
  1065. $24=_st($AliasVar())._new();
  1066. _st($24)._scope_(_st(inlinedClosure)._scope());
  1067. _st($24)._name_("$receiver");
  1068. $25=_st($24)._yourself();
  1069. $ctx2.sendIdx["yourself"]=3;
  1070. $23=$25;
  1071. $21=_st($22)._variable_($23);
  1072. _st($20)._add_($21);
  1073. $ctx2.sendIdx["add:"]=5;
  1074. $26=_st($11)._yourself();
  1075. $10=$26;
  1076. return _st($9)._add_($10);
  1077. $ctx2.sendIdx["add:"]=3;
  1078. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)})}));
  1079. $ctx1.sendIdx["do:"]=2;
  1080. _st(inlinedClosure)._add_(sequence);
  1081. $ctx1.sendIdx["add:"]=6;
  1082. $28=_st(anIRClosure)._instructions();
  1083. $ctx1.sendIdx["instructions"]=2;
  1084. $27=_st($28)._last();
  1085. $ctx1.sendIdx["last"]=1;
  1086. statements=_st($27)._instructions();
  1087. $ctx1.sendIdx["instructions"]=1;
  1088. _st(statements)._ifNotEmpty_((function(){
  1089. return smalltalk.withContext(function($ctx2) {
  1090. _st(_st(statements)._allButLast())._do_((function(each){
  1091. return smalltalk.withContext(function($ctx3) {
  1092. return _st(sequence)._add_(each);
  1093. $ctx3.sendIdx["add:"]=7;
  1094. }, function($ctx3) {$ctx3.fillBlock({each:each},$ctx2,4)})}));
  1095. $31=_st(statements)._last();
  1096. $ctx2.sendIdx["last"]=2;
  1097. $30=_st($31)._isReturn();
  1098. $29=_st($30)._and_((function(){
  1099. return smalltalk.withContext(function($ctx3) {
  1100. $32=_st(statements)._last();
  1101. $ctx3.sendIdx["last"]=3;
  1102. return _st($32)._isBlockReturn();
  1103. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,5)})}));
  1104. if(smalltalk.assert($29)){
  1105. $33=sequence;
  1106. $36=_st(statements)._last();
  1107. $ctx2.sendIdx["last"]=4;
  1108. $35=_st($36)._instructions();
  1109. $34=_st($35)._first();
  1110. return _st($33)._add_($34);
  1111. $ctx2.sendIdx["add:"]=8;
  1112. } else {
  1113. return _st(sequence)._add_(_st(statements)._last());
  1114. };
  1115. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)})}));
  1116. $37=inlinedClosure;
  1117. return $37;
  1118. }, function($ctx1) {$ctx1.fill(self,"inlineClosure:",{anIRClosure:anIRClosure,inlinedClosure:inlinedClosure,sequence:sequence,statements:statements},globals.IRSendInliner)})},
  1119. args: ["anIRClosure"],
  1120. 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",
  1121. 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"],
  1122. referencedClasses: ["IRTempDeclaration", "IRAssignment", "IRVariable", "AliasVar"]
  1123. }),
  1124. globals.IRSendInliner);
  1125. smalltalk.addMethod(
  1126. smalltalk.method({
  1127. selector: "inlineSend:",
  1128. protocol: 'inlining',
  1129. fn: function (anIRSend){
  1130. var self=this;
  1131. return smalltalk.withContext(function($ctx1) {
  1132. var $3,$2,$1;
  1133. self._send_(anIRSend);
  1134. $3=self._send();
  1135. $ctx1.sendIdx["send"]=1;
  1136. $2=_st($3)._selector();
  1137. $1=self._perform_withArguments_($2,_st(_st(self._send())._instructions())._allButFirst());
  1138. return $1;
  1139. }, function($ctx1) {$ctx1.fill(self,"inlineSend:",{anIRSend:anIRSend},globals.IRSendInliner)})},
  1140. args: ["anIRSend"],
  1141. source: "inlineSend: anIRSend\x0a\x09self send: anIRSend.\x0a\x09^ self\x0a\x09\x09perform: self send selector\x0a\x09\x09withArguments: self send instructions allButFirst",
  1142. messageSends: ["send:", "perform:withArguments:", "selector", "send", "allButFirst", "instructions"],
  1143. referencedClasses: []
  1144. }),
  1145. globals.IRSendInliner);
  1146. smalltalk.addMethod(
  1147. smalltalk.method({
  1148. selector: "inlinedClosure",
  1149. protocol: 'factory',
  1150. fn: function (){
  1151. var self=this;
  1152. function $IRInlinedClosure(){return globals.IRInlinedClosure||(typeof IRInlinedClosure=="undefined"?nil:IRInlinedClosure)}
  1153. return smalltalk.withContext(function($ctx1) {
  1154. var $1;
  1155. $1=_st($IRInlinedClosure())._new();
  1156. return $1;
  1157. }, function($ctx1) {$ctx1.fill(self,"inlinedClosure",{},globals.IRSendInliner)})},
  1158. args: [],
  1159. source: "inlinedClosure\x0a\x09^ IRInlinedClosure new",
  1160. messageSends: ["new"],
  1161. referencedClasses: ["IRInlinedClosure"]
  1162. }),
  1163. globals.IRSendInliner);
  1164. smalltalk.addMethod(
  1165. smalltalk.method({
  1166. selector: "inlinedSend:with:",
  1167. protocol: 'inlining',
  1168. fn: function (inlinedSend,anIRInstruction){
  1169. var self=this;
  1170. var inlinedClosure;
  1171. return smalltalk.withContext(function($ctx1) {
  1172. var $1,$2,$5,$4,$3,$6,$7;
  1173. $1=_st(anIRInstruction)._isClosure();
  1174. if(! smalltalk.assert($1)){
  1175. self._inliningError_("Message argument should be a block");
  1176. $ctx1.sendIdx["inliningError:"]=1;
  1177. };
  1178. $2=_st(_st(_st(anIRInstruction)._arguments())._size()).__eq((0));
  1179. if(! smalltalk.assert($2)){
  1180. self._inliningError_("Inlined block should have zero argument");
  1181. };
  1182. inlinedClosure=_st(self._translator())._visit_(self._inlineClosure_(anIRInstruction));
  1183. $5=self._send();
  1184. $ctx1.sendIdx["send"]=1;
  1185. $4=_st($5)._instructions();
  1186. $3=_st($4)._first();
  1187. _st(inlinedSend)._add_($3);
  1188. $ctx1.sendIdx["add:"]=1;
  1189. $6=_st(inlinedSend)._add_(inlinedClosure);
  1190. _st(self._send())._replaceWith_(inlinedSend);
  1191. $7=_st(_st(inlinedSend)._method())._internalVariables();
  1192. $ctx1.sendIdx["internalVariables"]=1;
  1193. _st($7)._addAll_(_st(inlinedSend)._internalVariables());
  1194. return inlinedSend;
  1195. }, function($ctx1) {$ctx1.fill(self,"inlinedSend:with:",{inlinedSend:inlinedSend,anIRInstruction:anIRInstruction,inlinedClosure:inlinedClosure},globals.IRSendInliner)})},
  1196. args: ["inlinedSend", "anIRInstruction"],
  1197. 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",
  1198. messageSends: ["ifFalse:", "isClosure", "inliningError:", "=", "size", "arguments", "visit:", "translator", "inlineClosure:", "add:", "first", "instructions", "send", "replaceWith:", "addAll:", "internalVariables", "method"],
  1199. referencedClasses: []
  1200. }),
  1201. globals.IRSendInliner);
  1202. smalltalk.addMethod(
  1203. smalltalk.method({
  1204. selector: "inlinedSend:with:with:",
  1205. protocol: 'inlining',
  1206. fn: function (inlinedSend,anIRInstruction,anotherIRInstruction){
  1207. var self=this;
  1208. var inlinedClosure1,inlinedClosure2;
  1209. return smalltalk.withContext(function($ctx1) {
  1210. var $1,$2,$3,$4,$7,$6,$5,$8,$9;
  1211. $1=_st(anIRInstruction)._isClosure();
  1212. $ctx1.sendIdx["isClosure"]=1;
  1213. if(! smalltalk.assert($1)){
  1214. self._inliningError_("Message argument should be a block");
  1215. $ctx1.sendIdx["inliningError:"]=1;
  1216. };
  1217. $2=_st(anotherIRInstruction)._isClosure();
  1218. if(! smalltalk.assert($2)){
  1219. self._inliningError_("Message argument should be a block");
  1220. };
  1221. $3=self._translator();
  1222. $ctx1.sendIdx["translator"]=1;
  1223. $4=self._inlineClosure_(anIRInstruction);
  1224. $ctx1.sendIdx["inlineClosure:"]=1;
  1225. inlinedClosure1=_st($3)._visit_($4);
  1226. $ctx1.sendIdx["visit:"]=1;
  1227. inlinedClosure2=_st(self._translator())._visit_(self._inlineClosure_(anotherIRInstruction));
  1228. $7=self._send();
  1229. $ctx1.sendIdx["send"]=1;
  1230. $6=_st($7)._instructions();
  1231. $5=_st($6)._first();
  1232. _st(inlinedSend)._add_($5);
  1233. $ctx1.sendIdx["add:"]=1;
  1234. _st(inlinedSend)._add_(inlinedClosure1);
  1235. $ctx1.sendIdx["add:"]=2;
  1236. $8=_st(inlinedSend)._add_(inlinedClosure2);
  1237. _st(self._send())._replaceWith_(inlinedSend);
  1238. $9=_st(_st(inlinedSend)._method())._internalVariables();
  1239. $ctx1.sendIdx["internalVariables"]=1;
  1240. _st($9)._addAll_(_st(inlinedSend)._internalVariables());
  1241. return inlinedSend;
  1242. }, function($ctx1) {$ctx1.fill(self,"inlinedSend:with:with:",{inlinedSend:inlinedSend,anIRInstruction:anIRInstruction,anotherIRInstruction:anotherIRInstruction,inlinedClosure1:inlinedClosure1,inlinedClosure2:inlinedClosure2},globals.IRSendInliner)})},
  1243. args: ["inlinedSend", "anIRInstruction", "anotherIRInstruction"],
  1244. 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",
  1245. messageSends: ["ifFalse:", "isClosure", "inliningError:", "visit:", "translator", "inlineClosure:", "add:", "first", "instructions", "send", "replaceWith:", "addAll:", "internalVariables", "method"],
  1246. referencedClasses: []
  1247. }),
  1248. globals.IRSendInliner);
  1249. smalltalk.addMethod(
  1250. smalltalk.method({
  1251. selector: "inlinedSequence",
  1252. protocol: 'factory',
  1253. fn: function (){
  1254. var self=this;
  1255. function $IRInlinedSequence(){return globals.IRInlinedSequence||(typeof IRInlinedSequence=="undefined"?nil:IRInlinedSequence)}
  1256. return smalltalk.withContext(function($ctx1) {
  1257. var $1;
  1258. $1=_st($IRInlinedSequence())._new();
  1259. return $1;
  1260. }, function($ctx1) {$ctx1.fill(self,"inlinedSequence",{},globals.IRSendInliner)})},
  1261. args: [],
  1262. source: "inlinedSequence\x0a\x09^ IRInlinedSequence new",
  1263. messageSends: ["new"],
  1264. referencedClasses: ["IRInlinedSequence"]
  1265. }),
  1266. globals.IRSendInliner);
  1267. smalltalk.addMethod(
  1268. smalltalk.method({
  1269. selector: "inliningError:",
  1270. protocol: 'error handling',
  1271. fn: function (aString){
  1272. var self=this;
  1273. function $InliningError(){return globals.InliningError||(typeof InliningError=="undefined"?nil:InliningError)}
  1274. return smalltalk.withContext(function($ctx1) {
  1275. _st($InliningError())._signal_(aString);
  1276. return self}, function($ctx1) {$ctx1.fill(self,"inliningError:",{aString:aString},globals.IRSendInliner)})},
  1277. args: ["aString"],
  1278. source: "inliningError: aString\x0a\x09InliningError signal: aString",
  1279. messageSends: ["signal:"],
  1280. referencedClasses: ["InliningError"]
  1281. }),
  1282. globals.IRSendInliner);
  1283. smalltalk.addMethod(
  1284. smalltalk.method({
  1285. selector: "send",
  1286. protocol: 'accessing',
  1287. fn: function (){
  1288. var self=this;
  1289. var $1;
  1290. $1=self["@send"];
  1291. return $1;
  1292. },
  1293. args: [],
  1294. source: "send\x0a\x09^ send",
  1295. messageSends: [],
  1296. referencedClasses: []
  1297. }),
  1298. globals.IRSendInliner);
  1299. smalltalk.addMethod(
  1300. smalltalk.method({
  1301. selector: "send:",
  1302. protocol: 'accessing',
  1303. fn: function (anIRSend){
  1304. var self=this;
  1305. self["@send"]=anIRSend;
  1306. return self},
  1307. args: ["anIRSend"],
  1308. source: "send: anIRSend\x0a\x09send := anIRSend",
  1309. messageSends: [],
  1310. referencedClasses: []
  1311. }),
  1312. globals.IRSendInliner);
  1313. smalltalk.addMethod(
  1314. smalltalk.method({
  1315. selector: "translator",
  1316. protocol: 'accessing',
  1317. fn: function (){
  1318. var self=this;
  1319. var $1;
  1320. $1=self["@translator"];
  1321. return $1;
  1322. },
  1323. args: [],
  1324. source: "translator\x0a\x09^ translator",
  1325. messageSends: [],
  1326. referencedClasses: []
  1327. }),
  1328. globals.IRSendInliner);
  1329. smalltalk.addMethod(
  1330. smalltalk.method({
  1331. selector: "translator:",
  1332. protocol: 'accessing',
  1333. fn: function (anASTTranslator){
  1334. var self=this;
  1335. self["@translator"]=anASTTranslator;
  1336. return self},
  1337. args: ["anASTTranslator"],
  1338. source: "translator: anASTTranslator\x0a\x09translator := anASTTranslator",
  1339. messageSends: [],
  1340. referencedClasses: []
  1341. }),
  1342. globals.IRSendInliner);
  1343. smalltalk.addMethod(
  1344. smalltalk.method({
  1345. selector: "inlinedSelectors",
  1346. protocol: 'accessing',
  1347. fn: function (){
  1348. var self=this;
  1349. var $1;
  1350. $1=["ifTrue:", "ifFalse:", "ifTrue:ifFalse:", "ifFalse:ifTrue:", "ifNil:", "ifNotNil:", "ifNil:ifNotNil:", "ifNotNil:ifNil:"];
  1351. return $1;
  1352. },
  1353. args: [],
  1354. source: "inlinedSelectors\x0a\x09^ #('ifTrue:' 'ifFalse:' 'ifTrue:ifFalse:' 'ifFalse:ifTrue:' 'ifNil:' 'ifNotNil:' 'ifNil:ifNotNil:' 'ifNotNil:ifNil:')",
  1355. messageSends: [],
  1356. referencedClasses: []
  1357. }),
  1358. globals.IRSendInliner.klass);
  1359. smalltalk.addMethod(
  1360. smalltalk.method({
  1361. selector: "shouldInline:",
  1362. protocol: 'accessing',
  1363. fn: function (anIRInstruction){
  1364. var self=this;
  1365. return smalltalk.withContext(function($ctx1) {
  1366. var $1,$2;
  1367. var $early={};
  1368. try {
  1369. $1=_st(self._inlinedSelectors())._includes_(_st(anIRInstruction)._selector());
  1370. if(! smalltalk.assert($1)){
  1371. return false;
  1372. };
  1373. _st(_st(_st(anIRInstruction)._instructions())._allButFirst())._do_((function(each){
  1374. return smalltalk.withContext(function($ctx2) {
  1375. $2=_st(each)._isClosure();
  1376. if(! smalltalk.assert($2)){
  1377. throw $early=[false];
  1378. };
  1379. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)})}));
  1380. return true;
  1381. }
  1382. catch(e) {if(e===$early)return e[0]; throw e}
  1383. }, function($ctx1) {$ctx1.fill(self,"shouldInline:",{anIRInstruction:anIRInstruction},globals.IRSendInliner.klass)})},
  1384. args: ["anIRInstruction"],
  1385. 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",
  1386. messageSends: ["ifFalse:", "includes:", "inlinedSelectors", "selector", "do:", "allButFirst", "instructions", "isClosure"],
  1387. referencedClasses: []
  1388. }),
  1389. globals.IRSendInliner.klass);
  1390. smalltalk.addClass('IRAssignmentInliner', globals.IRSendInliner, ['assignment'], 'Compiler-Inlining');
  1391. 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};";
  1392. smalltalk.addMethod(
  1393. smalltalk.method({
  1394. selector: "assignment",
  1395. protocol: 'accessing',
  1396. fn: function (){
  1397. var self=this;
  1398. var $1;
  1399. $1=self["@assignment"];
  1400. return $1;
  1401. },
  1402. args: [],
  1403. source: "assignment\x0a\x09^ assignment",
  1404. messageSends: [],
  1405. referencedClasses: []
  1406. }),
  1407. globals.IRAssignmentInliner);
  1408. smalltalk.addMethod(
  1409. smalltalk.method({
  1410. selector: "assignment:",
  1411. protocol: 'accessing',
  1412. fn: function (aNode){
  1413. var self=this;
  1414. self["@assignment"]=aNode;
  1415. return self},
  1416. args: ["aNode"],
  1417. source: "assignment: aNode\x0a\x09assignment := aNode",
  1418. messageSends: [],
  1419. referencedClasses: []
  1420. }),
  1421. globals.IRAssignmentInliner);
  1422. smalltalk.addMethod(
  1423. smalltalk.method({
  1424. selector: "inlineAssignment:",
  1425. protocol: 'inlining',
  1426. fn: function (anIRAssignment){
  1427. var self=this;
  1428. var inlinedAssignment;
  1429. function $IRInlinedAssignment(){return globals.IRInlinedAssignment||(typeof IRInlinedAssignment=="undefined"?nil:IRInlinedAssignment)}
  1430. return smalltalk.withContext(function($ctx1) {
  1431. var $1,$2;
  1432. self._assignment_(anIRAssignment);
  1433. inlinedAssignment=_st($IRInlinedAssignment())._new();
  1434. $1=_st(anIRAssignment)._instructions();
  1435. $ctx1.sendIdx["instructions"]=1;
  1436. _st($1)._do_((function(each){
  1437. return smalltalk.withContext(function($ctx2) {
  1438. return _st(inlinedAssignment)._add_(each);
  1439. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1440. _st(anIRAssignment)._replaceWith_(inlinedAssignment);
  1441. self._inlineSend_(_st(_st(inlinedAssignment)._instructions())._last());
  1442. $2=inlinedAssignment;
  1443. return $2;
  1444. }, function($ctx1) {$ctx1.fill(self,"inlineAssignment:",{anIRAssignment:anIRAssignment,inlinedAssignment:inlinedAssignment},globals.IRAssignmentInliner)})},
  1445. args: ["anIRAssignment"],
  1446. 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",
  1447. messageSends: ["assignment:", "new", "do:", "instructions", "add:", "replaceWith:", "inlineSend:", "last"],
  1448. referencedClasses: ["IRInlinedAssignment"]
  1449. }),
  1450. globals.IRAssignmentInliner);
  1451. smalltalk.addMethod(
  1452. smalltalk.method({
  1453. selector: "inlineClosure:",
  1454. protocol: 'inlining',
  1455. fn: function (anIRClosure){
  1456. var self=this;
  1457. var inlinedClosure,statements;
  1458. function $IRAssignment(){return globals.IRAssignment||(typeof IRAssignment=="undefined"?nil:IRAssignment)}
  1459. return smalltalk.withContext(function($ctx1) {
  1460. var $2,$1,$4,$3,$5,$7,$8,$6,$9;
  1461. inlinedClosure=($ctx1.supercall = true, globals.IRAssignmentInliner.superclass.fn.prototype._inlineClosure_.apply(_st(self), [anIRClosure]));
  1462. $ctx1.supercall = false;
  1463. $2=_st(inlinedClosure)._instructions();
  1464. $ctx1.sendIdx["instructions"]=2;
  1465. $1=_st($2)._last();
  1466. $ctx1.sendIdx["last"]=1;
  1467. statements=_st($1)._instructions();
  1468. $ctx1.sendIdx["instructions"]=1;
  1469. _st(statements)._ifNotEmpty_((function(){
  1470. return smalltalk.withContext(function($ctx2) {
  1471. $4=_st(statements)._last();
  1472. $ctx2.sendIdx["last"]=2;
  1473. $3=_st($4)._canBeAssigned();
  1474. if(smalltalk.assert($3)){
  1475. $5=_st(statements)._last();
  1476. $ctx2.sendIdx["last"]=3;
  1477. $7=_st($IRAssignment())._new();
  1478. _st($7)._add_(_st(_st(self._assignment())._instructions())._first());
  1479. $ctx2.sendIdx["add:"]=1;
  1480. _st($7)._add_(_st(_st(statements)._last())._copy());
  1481. $8=_st($7)._yourself();
  1482. $6=$8;
  1483. return _st($5)._replaceWith_($6);
  1484. };
  1485. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  1486. $9=inlinedClosure;
  1487. return $9;
  1488. }, function($ctx1) {$ctx1.fill(self,"inlineClosure:",{anIRClosure:anIRClosure,inlinedClosure:inlinedClosure,statements:statements},globals.IRAssignmentInliner)})},
  1489. args: ["anIRClosure"],
  1490. 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",
  1491. messageSends: ["inlineClosure:", "instructions", "last", "ifNotEmpty:", "ifTrue:", "canBeAssigned", "replaceWith:", "add:", "new", "first", "assignment", "copy", "yourself"],
  1492. referencedClasses: ["IRAssignment"]
  1493. }),
  1494. globals.IRAssignmentInliner);
  1495. smalltalk.addClass('IRReturnInliner', globals.IRSendInliner, [], 'Compiler-Inlining');
  1496. globals.IRReturnInliner.comment="I inline message sends with inlined closure together with a return instruction.";
  1497. smalltalk.addMethod(
  1498. smalltalk.method({
  1499. selector: "inlineClosure:",
  1500. protocol: 'inlining',
  1501. fn: function (anIRClosure){
  1502. var self=this;
  1503. var closure,statements;
  1504. function $IRReturn(){return globals.IRReturn||(typeof IRReturn=="undefined"?nil:IRReturn)}
  1505. return smalltalk.withContext(function($ctx1) {
  1506. var $1,$3,$2,$4,$5,$6,$7;
  1507. closure=($ctx1.supercall = true, globals.IRReturnInliner.superclass.fn.prototype._inlineClosure_.apply(_st(self), [anIRClosure]));
  1508. $ctx1.supercall = false;
  1509. $1=_st(_st(closure)._instructions())._last();
  1510. $ctx1.sendIdx["last"]=1;
  1511. statements=_st($1)._instructions();
  1512. $ctx1.sendIdx["instructions"]=1;
  1513. _st(statements)._ifNotEmpty_((function(){
  1514. return smalltalk.withContext(function($ctx2) {
  1515. $3=_st(statements)._last();
  1516. $ctx2.sendIdx["last"]=2;
  1517. $2=_st($3)._isReturn();
  1518. if(! smalltalk.assert($2)){
  1519. $4=_st(statements)._last();
  1520. $ctx2.sendIdx["last"]=3;
  1521. $5=_st($IRReturn())._new();
  1522. _st($5)._add_(_st(_st(statements)._last())._copy());
  1523. $6=_st($5)._yourself();
  1524. return _st($4)._replaceWith_($6);
  1525. };
  1526. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  1527. $7=closure;
  1528. return $7;
  1529. }, function($ctx1) {$ctx1.fill(self,"inlineClosure:",{anIRClosure:anIRClosure,closure:closure,statements:statements},globals.IRReturnInliner)})},
  1530. args: ["anIRClosure"],
  1531. 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",
  1532. messageSends: ["inlineClosure:", "instructions", "last", "ifNotEmpty:", "ifFalse:", "isReturn", "replaceWith:", "add:", "new", "copy", "yourself"],
  1533. referencedClasses: ["IRReturn"]
  1534. }),
  1535. globals.IRReturnInliner);
  1536. smalltalk.addMethod(
  1537. smalltalk.method({
  1538. selector: "inlineReturn:",
  1539. protocol: 'inlining',
  1540. fn: function (anIRReturn){
  1541. var self=this;
  1542. var return_;
  1543. return smalltalk.withContext(function($ctx1) {
  1544. var $1,$2;
  1545. return_=self._inlinedReturn();
  1546. $1=_st(anIRReturn)._instructions();
  1547. $ctx1.sendIdx["instructions"]=1;
  1548. _st($1)._do_((function(each){
  1549. return smalltalk.withContext(function($ctx2) {
  1550. return _st(return_)._add_(each);
  1551. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1552. _st(anIRReturn)._replaceWith_(return_);
  1553. self._inlineSend_(_st(_st(return_)._instructions())._last());
  1554. $2=return_;
  1555. return $2;
  1556. }, function($ctx1) {$ctx1.fill(self,"inlineReturn:",{anIRReturn:anIRReturn,return_:return_},globals.IRReturnInliner)})},
  1557. args: ["anIRReturn"],
  1558. 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",
  1559. messageSends: ["inlinedReturn", "do:", "instructions", "add:", "replaceWith:", "inlineSend:", "last"],
  1560. referencedClasses: []
  1561. }),
  1562. globals.IRReturnInliner);
  1563. smalltalk.addMethod(
  1564. smalltalk.method({
  1565. selector: "inlinedReturn",
  1566. protocol: 'factory',
  1567. fn: function (){
  1568. var self=this;
  1569. function $IRInlinedReturn(){return globals.IRInlinedReturn||(typeof IRInlinedReturn=="undefined"?nil:IRInlinedReturn)}
  1570. return smalltalk.withContext(function($ctx1) {
  1571. var $1;
  1572. $1=_st($IRInlinedReturn())._new();
  1573. return $1;
  1574. }, function($ctx1) {$ctx1.fill(self,"inlinedReturn",{},globals.IRReturnInliner)})},
  1575. args: [],
  1576. source: "inlinedReturn\x0a\x09^ IRInlinedReturn new",
  1577. messageSends: ["new"],
  1578. referencedClasses: ["IRInlinedReturn"]
  1579. }),
  1580. globals.IRReturnInliner);
  1581. smalltalk.addClass('InliningCodeGenerator', globals.CodeGenerator, [], 'Compiler-Inlining');
  1582. globals.InliningCodeGenerator.comment="I am a specialized code generator that uses inlining to produce more optimized JavaScript output";
  1583. smalltalk.addMethod(
  1584. smalltalk.method({
  1585. selector: "compileNode:",
  1586. protocol: 'compiling',
  1587. fn: function (aNode){
  1588. var self=this;
  1589. var ir,stream;
  1590. return smalltalk.withContext(function($ctx1) {
  1591. var $2,$3,$1;
  1592. _st(self._semanticAnalyzer())._visit_(aNode);
  1593. $ctx1.sendIdx["visit:"]=1;
  1594. ir=_st(self._translator())._visit_(aNode);
  1595. $ctx1.sendIdx["visit:"]=2;
  1596. _st(self._inliner())._visit_(ir);
  1597. $ctx1.sendIdx["visit:"]=3;
  1598. $2=self._irTranslator();
  1599. _st($2)._currentClass_(self._currentClass());
  1600. _st($2)._visit_(ir);
  1601. $3=_st($2)._contents();
  1602. $1=$3;
  1603. return $1;
  1604. }, function($ctx1) {$ctx1.fill(self,"compileNode:",{aNode:aNode,ir:ir,stream:stream},globals.InliningCodeGenerator)})},
  1605. args: ["aNode"],
  1606. 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",
  1607. messageSends: ["visit:", "semanticAnalyzer", "translator", "inliner", "currentClass:", "irTranslator", "currentClass", "contents"],
  1608. referencedClasses: []
  1609. }),
  1610. globals.InliningCodeGenerator);
  1611. smalltalk.addMethod(
  1612. smalltalk.method({
  1613. selector: "inliner",
  1614. protocol: 'compiling',
  1615. fn: function (){
  1616. var self=this;
  1617. function $IRInliner(){return globals.IRInliner||(typeof IRInliner=="undefined"?nil:IRInliner)}
  1618. return smalltalk.withContext(function($ctx1) {
  1619. var $1;
  1620. $1=_st($IRInliner())._new();
  1621. return $1;
  1622. }, function($ctx1) {$ctx1.fill(self,"inliner",{},globals.InliningCodeGenerator)})},
  1623. args: [],
  1624. source: "inliner\x0a\x09^ IRInliner new",
  1625. messageSends: ["new"],
  1626. referencedClasses: ["IRInliner"]
  1627. }),
  1628. globals.InliningCodeGenerator);
  1629. smalltalk.addMethod(
  1630. smalltalk.method({
  1631. selector: "irTranslator",
  1632. protocol: 'compiling',
  1633. fn: function (){
  1634. var self=this;
  1635. function $IRInliningJSTranslator(){return globals.IRInliningJSTranslator||(typeof IRInliningJSTranslator=="undefined"?nil:IRInliningJSTranslator)}
  1636. return smalltalk.withContext(function($ctx1) {
  1637. var $1;
  1638. $1=_st($IRInliningJSTranslator())._new();
  1639. return $1;
  1640. }, function($ctx1) {$ctx1.fill(self,"irTranslator",{},globals.InliningCodeGenerator)})},
  1641. args: [],
  1642. source: "irTranslator\x0a\x09^ IRInliningJSTranslator new",
  1643. messageSends: ["new"],
  1644. referencedClasses: ["IRInliningJSTranslator"]
  1645. }),
  1646. globals.InliningCodeGenerator);
  1647. });