Compiler-Tests.js 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791
  1. define("amber_core/Compiler-Tests", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_core/SUnit"], function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Compiler-Tests');
  3. smalltalk.packages["Compiler-Tests"].transport = {"type":"amd","amdNamespace":"amber_core"};
  4. smalltalk.addClass('ASTParsingTest', smalltalk.TestCase, [], 'Compiler-Tests');
  5. smalltalk.addMethod(
  6. smalltalk.method({
  7. selector: "analyze:forClass:",
  8. protocol: 'convenience',
  9. fn: function (aNode,aClass){
  10. var self=this;
  11. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  12. return smalltalk.withContext(function($ctx1) {
  13. _st(_st($SemanticAnalyzer())._on_(aClass))._visit_(aNode);
  14. return aNode;
  15. }, function($ctx1) {$ctx1.fill(self,"analyze:forClass:",{aNode:aNode,aClass:aClass},smalltalk.ASTParsingTest)})},
  16. args: ["aNode", "aClass"],
  17. source: "analyze: aNode forClass: aClass\x0a\x09(SemanticAnalyzer on: aClass) visit: aNode.\x0a\x09^ aNode",
  18. messageSends: ["visit:", "on:"],
  19. referencedClasses: ["SemanticAnalyzer"]
  20. }),
  21. smalltalk.ASTParsingTest);
  22. smalltalk.addMethod(
  23. smalltalk.method({
  24. selector: "parse:",
  25. protocol: 'parsing',
  26. fn: function (aString){
  27. var self=this;
  28. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  29. return smalltalk.withContext(function($ctx1) {
  30. var $1;
  31. $1=_st(_st($Smalltalk())._current())._parse_(aString);
  32. return $1;
  33. }, function($ctx1) {$ctx1.fill(self,"parse:",{aString:aString},smalltalk.ASTParsingTest)})},
  34. args: ["aString"],
  35. source: "parse: aString\x0a\x09^ Smalltalk current parse: aString",
  36. messageSends: ["parse:", "current"],
  37. referencedClasses: ["Smalltalk"]
  38. }),
  39. smalltalk.ASTParsingTest);
  40. smalltalk.addMethod(
  41. smalltalk.method({
  42. selector: "parse:forClass:",
  43. protocol: 'parsing',
  44. fn: function (aString,aClass){
  45. var self=this;
  46. return smalltalk.withContext(function($ctx1) {
  47. var $1;
  48. $1=self._analyze_forClass_(self._parse_(aString),aClass);
  49. return $1;
  50. }, function($ctx1) {$ctx1.fill(self,"parse:forClass:",{aString:aString,aClass:aClass},smalltalk.ASTParsingTest)})},
  51. args: ["aString", "aClass"],
  52. source: "parse: aString forClass: aClass\x0a\x09^ self analyze: (self parse: aString) forClass: aClass",
  53. messageSends: ["analyze:forClass:", "parse:"],
  54. referencedClasses: []
  55. }),
  56. smalltalk.ASTParsingTest);
  57. smalltalk.addClass('ASTPCNodeVisitorTest', smalltalk.ASTParsingTest, [], 'Compiler-Tests');
  58. smalltalk.addMethod(
  59. smalltalk.method({
  60. selector: "astPCNodeVisitor",
  61. protocol: 'factory',
  62. fn: function (){
  63. var self=this;
  64. function $ASTPCNodeVisitor(){return smalltalk.ASTPCNodeVisitor||(typeof ASTPCNodeVisitor=="undefined"?nil:ASTPCNodeVisitor)}
  65. function $AIContext(){return smalltalk.AIContext||(typeof AIContext=="undefined"?nil:AIContext)}
  66. return smalltalk.withContext(function($ctx1) {
  67. var $2,$3,$4,$5,$1;
  68. $2=_st($ASTPCNodeVisitor())._new();
  69. $ctx1.sendIdx["new"]=1;
  70. $3=$2;
  71. $4=_st(_st($AIContext())._new())._yourself();
  72. $ctx1.sendIdx["yourself"]=1;
  73. _st($3)._context_($4);
  74. $5=_st($2)._yourself();
  75. $1=$5;
  76. return $1;
  77. }, function($ctx1) {$ctx1.fill(self,"astPCNodeVisitor",{},smalltalk.ASTPCNodeVisitorTest)})},
  78. args: [],
  79. source: "astPCNodeVisitor\x0a\x09^ ASTPCNodeVisitor new\x0a\x09\x09context: (AIContext new\x0a\x09\x09\x09yourself);\x0a\x09\x09yourself",
  80. messageSends: ["context:", "new", "yourself"],
  81. referencedClasses: ["ASTPCNodeVisitor", "AIContext"]
  82. }),
  83. smalltalk.ASTPCNodeVisitorTest);
  84. smalltalk.addMethod(
  85. smalltalk.method({
  86. selector: "astPCNodeVisitorForSelector:",
  87. protocol: 'factory',
  88. fn: function (aString){
  89. var self=this;
  90. function $ASTPCNodeVisitor(){return smalltalk.ASTPCNodeVisitor||(typeof ASTPCNodeVisitor=="undefined"?nil:ASTPCNodeVisitor)}
  91. function $AIContext(){return smalltalk.AIContext||(typeof AIContext=="undefined"?nil:AIContext)}
  92. return smalltalk.withContext(function($ctx1) {
  93. var $2,$3,$4,$5,$1;
  94. $2=_st($ASTPCNodeVisitor())._new();
  95. $ctx1.sendIdx["new"]=1;
  96. _st($2)._selector_(aString);
  97. $3=$2;
  98. $4=_st(_st($AIContext())._new())._yourself();
  99. $ctx1.sendIdx["yourself"]=1;
  100. _st($3)._context_($4);
  101. $5=_st($2)._yourself();
  102. $1=$5;
  103. return $1;
  104. }, function($ctx1) {$ctx1.fill(self,"astPCNodeVisitorForSelector:",{aString:aString},smalltalk.ASTPCNodeVisitorTest)})},
  105. args: ["aString"],
  106. source: "astPCNodeVisitorForSelector: aString\x0a\x09^ ASTPCNodeVisitor new\x0a\x09\x09selector: aString;\x0a\x09\x09context: (AIContext new\x0a\x09\x09\x09yourself);\x0a\x09\x09yourself",
  107. messageSends: ["selector:", "new", "context:", "yourself"],
  108. referencedClasses: ["ASTPCNodeVisitor", "AIContext"]
  109. }),
  110. smalltalk.ASTPCNodeVisitorTest);
  111. smalltalk.addMethod(
  112. smalltalk.method({
  113. selector: "testJSStatementNode",
  114. protocol: 'tests',
  115. fn: function (){
  116. var self=this;
  117. var ast,visitor;
  118. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  119. return smalltalk.withContext(function($ctx1) {
  120. var $1,$2;
  121. ast=self._parse_forClass_("foo <consolee.log(1)>",$Object());
  122. $1=self._astPCNodeVisitor();
  123. _st($1)._visit_(ast);
  124. $2=_st($1)._currentNode();
  125. self._assert_(_st($2)._isJSStatementNode());
  126. return self}, function($ctx1) {$ctx1.fill(self,"testJSStatementNode",{ast:ast,visitor:visitor},smalltalk.ASTPCNodeVisitorTest)})},
  127. args: [],
  128. source: "testJSStatementNode\x0a\x09| ast visitor |\x0a\x09\x0a\x09ast := self parse: 'foo <consolee.log(1)>' forClass: Object.\x0a\x09self assert: (self astPCNodeVisitor\x0a\x09\x09visit: ast;\x0a\x09\x09currentNode) isJSStatementNode",
  129. messageSends: ["parse:forClass:", "assert:", "isJSStatementNode", "visit:", "astPCNodeVisitor", "currentNode"],
  130. referencedClasses: ["Object"]
  131. }),
  132. smalltalk.ASTPCNodeVisitorTest);
  133. smalltalk.addMethod(
  134. smalltalk.method({
  135. selector: "testMessageSend",
  136. protocol: 'tests',
  137. fn: function (){
  138. var self=this;
  139. var ast;
  140. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  141. return smalltalk.withContext(function($ctx1) {
  142. var $1,$2;
  143. ast=self._parse_forClass_("foo self asString yourself. ^ self asBoolean",$Object());
  144. $1=self._astPCNodeVisitorForSelector_("yourself");
  145. _st($1)._visit_(ast);
  146. $2=_st($1)._currentNode();
  147. self._assert_equals_(_st($2)._selector(),"yourself");
  148. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSend",{ast:ast},smalltalk.ASTPCNodeVisitorTest)})},
  149. args: [],
  150. source: "testMessageSend\x0a\x09| ast |\x0a\x09\x0a\x09ast := self parse: 'foo self asString yourself. ^ self asBoolean' forClass: Object.\x0a\x09self assert: ((self astPCNodeVisitorForSelector: 'yourself')\x0a\x09\x09visit: ast;\x0a\x09\x09currentNode) selector equals: 'yourself'",
  151. messageSends: ["parse:forClass:", "assert:equals:", "selector", "visit:", "astPCNodeVisitorForSelector:", "currentNode"],
  152. referencedClasses: ["Object"]
  153. }),
  154. smalltalk.ASTPCNodeVisitorTest);
  155. smalltalk.addMethod(
  156. smalltalk.method({
  157. selector: "testMessageSendWithBlocks",
  158. protocol: 'tests',
  159. fn: function (){
  160. var self=this;
  161. var ast;
  162. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  163. return smalltalk.withContext(function($ctx1) {
  164. var $1,$2;
  165. ast=self._parse_forClass_("foo true ifTrue: [ [ self asString yourself ] value. ]. ^ self asBoolean",$Object());
  166. $1=self._astPCNodeVisitorForSelector_("yourself");
  167. _st($1)._visit_(ast);
  168. $2=_st($1)._currentNode();
  169. self._assert_equals_(_st($2)._selector(),"yourself");
  170. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSendWithBlocks",{ast:ast},smalltalk.ASTPCNodeVisitorTest)})},
  171. args: [],
  172. source: "testMessageSendWithBlocks\x0a\x09| ast |\x0a\x09\x0a\x09ast := self parse: 'foo true ifTrue: [ [ self asString yourself ] value. ]. ^ self asBoolean' forClass: Object.\x0a\x09self assert: ((self astPCNodeVisitorForSelector: 'yourself')\x0a\x09\x09visit: ast;\x0a\x09\x09currentNode) selector equals: 'yourself'",
  173. messageSends: ["parse:forClass:", "assert:equals:", "selector", "visit:", "astPCNodeVisitorForSelector:", "currentNode"],
  174. referencedClasses: ["Object"]
  175. }),
  176. smalltalk.ASTPCNodeVisitorTest);
  177. smalltalk.addMethod(
  178. smalltalk.method({
  179. selector: "testMessageSendWithInlining",
  180. protocol: 'tests',
  181. fn: function (){
  182. var self=this;
  183. var ast;
  184. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  185. return smalltalk.withContext(function($ctx1) {
  186. var $3,$4,$2,$1,$5,$6;
  187. ast=self._parse_forClass_("foo true ifTrue: [ self asString yourself ]. ^ self asBoolean",$Object());
  188. $ctx1.sendIdx["parse:forClass:"]=1;
  189. $3=self._astPCNodeVisitorForSelector_("yourself");
  190. $ctx1.sendIdx["astPCNodeVisitorForSelector:"]=1;
  191. _st($3)._visit_(ast);
  192. $ctx1.sendIdx["visit:"]=1;
  193. $4=_st($3)._currentNode();
  194. $ctx1.sendIdx["currentNode"]=1;
  195. $2=$4;
  196. $1=_st($2)._selector();
  197. $ctx1.sendIdx["selector"]=1;
  198. self._assert_equals_($1,"yourself");
  199. $ctx1.sendIdx["assert:equals:"]=1;
  200. ast=self._parse_forClass_("foo true ifTrue: [ self asString yourself ]. ^ self asBoolean",$Object());
  201. $5=self._astPCNodeVisitorForSelector_("asBoolean");
  202. _st($5)._visit_(ast);
  203. $6=_st($5)._currentNode();
  204. self._assert_equals_(_st($6)._selector(),"asBoolean");
  205. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSendWithInlining",{ast:ast},smalltalk.ASTPCNodeVisitorTest)})},
  206. args: [],
  207. source: "testMessageSendWithInlining\x0a\x09| ast |\x0a\x09\x0a\x09ast := self parse: 'foo true ifTrue: [ self asString yourself ]. ^ self asBoolean' forClass: Object.\x0a\x09self assert: ((self astPCNodeVisitorForSelector: 'yourself')\x0a\x09\x09visit: ast;\x0a\x09\x09currentNode) selector equals: 'yourself'.\x0a\x09\x09\x0a\x09ast := self parse: 'foo true ifTrue: [ self asString yourself ]. ^ self asBoolean' forClass: Object.\x0a\x09self assert: ((self astPCNodeVisitorForSelector: 'asBoolean')\x0a\x09\x09visit: ast;\x0a\x09\x09currentNode) selector equals: 'asBoolean'",
  208. messageSends: ["parse:forClass:", "assert:equals:", "selector", "visit:", "astPCNodeVisitorForSelector:", "currentNode"],
  209. referencedClasses: ["Object"]
  210. }),
  211. smalltalk.ASTPCNodeVisitorTest);
  212. smalltalk.addMethod(
  213. smalltalk.method({
  214. selector: "testNoMessageSend",
  215. protocol: 'tests',
  216. fn: function (){
  217. var self=this;
  218. var ast;
  219. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  220. return smalltalk.withContext(function($ctx1) {
  221. var $1,$2;
  222. ast=self._parse_forClass_("foo ^ self",$Object());
  223. $1=self._astPCNodeVisitor();
  224. _st($1)._visit_(ast);
  225. $2=_st($1)._currentNode();
  226. self._assert_(_st($2)._isNil());
  227. return self}, function($ctx1) {$ctx1.fill(self,"testNoMessageSend",{ast:ast},smalltalk.ASTPCNodeVisitorTest)})},
  228. args: [],
  229. source: "testNoMessageSend\x0a\x09| ast |\x0a\x09\x0a\x09ast := self parse: 'foo ^ self' forClass: Object.\x0a\x09self assert: (self astPCNodeVisitor\x0a\x09\x09visit: ast;\x0a\x09\x09currentNode) isNil",
  230. messageSends: ["parse:forClass:", "assert:", "isNil", "visit:", "astPCNodeVisitor", "currentNode"],
  231. referencedClasses: ["Object"]
  232. }),
  233. smalltalk.ASTPCNodeVisitorTest);
  234. smalltalk.addMethod(
  235. smalltalk.method({
  236. selector: "testPC",
  237. protocol: 'tests',
  238. fn: function (){
  239. var self=this;
  240. var ast,visitor;
  241. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  242. return smalltalk.withContext(function($ctx1) {
  243. var $1,$2;
  244. ast=self._parse_forClass_("foo <console.log(1)>",$Object());
  245. $1=self._astPCNodeVisitor();
  246. _st($1)._visit_(ast);
  247. $2=_st($1)._currentNode();
  248. self._assert_(_st($2)._isJSStatementNode());
  249. return self}, function($ctx1) {$ctx1.fill(self,"testPC",{ast:ast,visitor:visitor},smalltalk.ASTPCNodeVisitorTest)})},
  250. args: [],
  251. source: "testPC\x0a\x09| ast visitor |\x0a\x09\x0a\x09ast := self parse: 'foo <console.log(1)>' forClass: Object.\x0a\x09self assert: (self astPCNodeVisitor\x0a\x09\x09visit: ast;\x0a\x09\x09currentNode) isJSStatementNode",
  252. messageSends: ["parse:forClass:", "assert:", "isJSStatementNode", "visit:", "astPCNodeVisitor", "currentNode"],
  253. referencedClasses: ["Object"]
  254. }),
  255. smalltalk.ASTPCNodeVisitorTest);
  256. smalltalk.addClass('CodeGeneratorTest', smalltalk.ASTParsingTest, ['receiver'], 'Compiler-Tests');
  257. smalltalk.addMethod(
  258. smalltalk.method({
  259. selector: "codeGeneratorClass",
  260. protocol: 'accessing',
  261. fn: function (){
  262. var self=this;
  263. function $CodeGenerator(){return smalltalk.CodeGenerator||(typeof CodeGenerator=="undefined"?nil:CodeGenerator)}
  264. return smalltalk.withContext(function($ctx1) {
  265. return $CodeGenerator();
  266. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{},smalltalk.CodeGeneratorTest)})},
  267. args: [],
  268. source: "codeGeneratorClass\x0a\x09^ CodeGenerator",
  269. messageSends: [],
  270. referencedClasses: ["CodeGenerator"]
  271. }),
  272. smalltalk.CodeGeneratorTest);
  273. smalltalk.addMethod(
  274. smalltalk.method({
  275. selector: "compiler",
  276. protocol: 'factory',
  277. fn: function (){
  278. var self=this;
  279. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  280. return smalltalk.withContext(function($ctx1) {
  281. var $2,$3,$1;
  282. $2=_st($Compiler())._new();
  283. _st($2)._codeGeneratorClass_(self._codeGeneratorClass());
  284. $3=_st($2)._yourself();
  285. $1=$3;
  286. return $1;
  287. }, function($ctx1) {$ctx1.fill(self,"compiler",{},smalltalk.CodeGeneratorTest)})},
  288. args: [],
  289. source: "compiler\x0a\x09^ Compiler new\x0a\x09\x09codeGeneratorClass: self codeGeneratorClass;\x0a\x09\x09yourself",
  290. messageSends: ["codeGeneratorClass:", "new", "codeGeneratorClass", "yourself"],
  291. referencedClasses: ["Compiler"]
  292. }),
  293. smalltalk.CodeGeneratorTest);
  294. smalltalk.addMethod(
  295. smalltalk.method({
  296. selector: "setUp",
  297. protocol: 'initialization',
  298. fn: function (){
  299. var self=this;
  300. function $DoIt(){return smalltalk.DoIt||(typeof DoIt=="undefined"?nil:DoIt)}
  301. return smalltalk.withContext(function($ctx1) {
  302. self["@receiver"]=_st($DoIt())._new();
  303. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},smalltalk.CodeGeneratorTest)})},
  304. args: [],
  305. source: "setUp\x0a\x09receiver := DoIt new",
  306. messageSends: ["new"],
  307. referencedClasses: ["DoIt"]
  308. }),
  309. smalltalk.CodeGeneratorTest);
  310. smalltalk.addMethod(
  311. smalltalk.method({
  312. selector: "should:receiver:return:",
  313. protocol: 'testing',
  314. fn: function (aString,anObject,aResult){
  315. var self=this;
  316. var method,result;
  317. return smalltalk.withContext(function($ctx1) {
  318. var $1,$2;
  319. self["@receiver"]=anObject;
  320. $1=self._compiler();
  321. $2=_st(anObject)._class();
  322. $ctx1.sendIdx["class"]=1;
  323. method=_st($1)._install_forClass_protocol_(aString,$2,"tests");
  324. result=_st(self["@receiver"])._perform_(_st(method)._selector());
  325. _st(_st(anObject)._class())._removeCompiledMethod_(method);
  326. self._assert_equals_(aResult,result);
  327. return self}, function($ctx1) {$ctx1.fill(self,"should:receiver:return:",{aString:aString,anObject:anObject,aResult:aResult,method:method,result:result},smalltalk.CodeGeneratorTest)})},
  328. args: ["aString", "anObject", "aResult"],
  329. source: "should: aString receiver: anObject return: aResult\x0a\x09| method result |\x0a\x0a\x09receiver := anObject.\x0a\x09method := self compiler install: aString forClass: anObject class protocol: 'tests'.\x0a\x09result := receiver perform: method selector.\x0a\x09anObject class removeCompiledMethod: method.\x0a\x09self assert: aResult equals: result",
  330. messageSends: ["install:forClass:protocol:", "compiler", "class", "perform:", "selector", "removeCompiledMethod:", "assert:equals:"],
  331. referencedClasses: []
  332. }),
  333. smalltalk.CodeGeneratorTest);
  334. smalltalk.addMethod(
  335. smalltalk.method({
  336. selector: "should:return:",
  337. protocol: 'testing',
  338. fn: function (aString,anObject){
  339. var self=this;
  340. return smalltalk.withContext(function($ctx1) {
  341. var $1;
  342. $1=self._should_receiver_return_(aString,self["@receiver"],anObject);
  343. return $1;
  344. }, function($ctx1) {$ctx1.fill(self,"should:return:",{aString:aString,anObject:anObject},smalltalk.CodeGeneratorTest)})},
  345. args: ["aString", "anObject"],
  346. source: "should: aString return: anObject\x0a\x09^ self \x0a\x09\x09should: aString \x0a\x09\x09receiver: receiver \x0a\x09\x09return: anObject",
  347. messageSends: ["should:receiver:return:"],
  348. referencedClasses: []
  349. }),
  350. smalltalk.CodeGeneratorTest);
  351. smalltalk.addMethod(
  352. smalltalk.method({
  353. selector: "tearDown",
  354. protocol: 'initialization',
  355. fn: function (){
  356. var self=this;
  357. return smalltalk.withContext(function($ctx1) {
  358. return self}, function($ctx1) {$ctx1.fill(self,"tearDown",{},smalltalk.CodeGeneratorTest)})},
  359. args: [],
  360. source: "tearDown\x0a\x09\x22receiver := nil\x22",
  361. messageSends: [],
  362. referencedClasses: []
  363. }),
  364. smalltalk.CodeGeneratorTest);
  365. smalltalk.addMethod(
  366. smalltalk.method({
  367. selector: "testAssignment",
  368. protocol: 'tests',
  369. fn: function (){
  370. var self=this;
  371. return smalltalk.withContext(function($ctx1) {
  372. self._should_return_("foo | a | a := true ifTrue: [ 1 ]. ^ a",(1));
  373. $ctx1.sendIdx["should:return:"]=1;
  374. self._should_return_("foo | a | a := false ifTrue: [ 1 ]. ^ a",nil);
  375. $ctx1.sendIdx["should:return:"]=2;
  376. self._should_return_("foo | a | ^ a := true ifTrue: [ 1 ]",(1));
  377. return self}, function($ctx1) {$ctx1.fill(self,"testAssignment",{},smalltalk.CodeGeneratorTest)})},
  378. args: [],
  379. source: "testAssignment\x0a\x09self should: 'foo | a | a := true ifTrue: [ 1 ]. ^ a' return: 1.\x0a\x09self should: 'foo | a | a := false ifTrue: [ 1 ]. ^ a' return: nil.\x0a\x0a\x09self should: 'foo | a | ^ a := true ifTrue: [ 1 ]' return: 1",
  380. messageSends: ["should:return:"],
  381. referencedClasses: []
  382. }),
  383. smalltalk.CodeGeneratorTest);
  384. smalltalk.addMethod(
  385. smalltalk.method({
  386. selector: "testBackslashSelectors",
  387. protocol: 'tests',
  388. fn: function (){
  389. var self=this;
  390. return smalltalk.withContext(function($ctx1) {
  391. self._should_return_("\x5c arg ^ 4",(4));
  392. $ctx1.sendIdx["should:return:"]=1;
  393. self._should_return_("\x5c\x5c arg ^ 42",(42));
  394. return self}, function($ctx1) {$ctx1.fill(self,"testBackslashSelectors",{},smalltalk.CodeGeneratorTest)})},
  395. args: [],
  396. source: "testBackslashSelectors\x0a\x09\x0a\x09self should: '\x5c arg ^ 4' return: 4.\x0a\x09self should: '\x5c\x5c arg ^ 42' return: 42",
  397. messageSends: ["should:return:"],
  398. referencedClasses: []
  399. }),
  400. smalltalk.CodeGeneratorTest);
  401. smalltalk.addMethod(
  402. smalltalk.method({
  403. selector: "testBlockReturn",
  404. protocol: 'tests',
  405. fn: function (){
  406. var self=this;
  407. return smalltalk.withContext(function($ctx1) {
  408. self._should_return_("foo ^ #(1 2 3) collect: [ :each | true ifTrue: [ each + 1 ] ]",[(2), (3), (4)]);
  409. $ctx1.sendIdx["should:return:"]=1;
  410. self._should_return_("foo ^ #(1 2 3) collect: [ :each | false ifFalse: [ each + 1 ] ]",[(2), (3), (4)]);
  411. $ctx1.sendIdx["should:return:"]=2;
  412. self._should_return_("foo ^ #(1 2 3) collect: [ :each | each odd ifTrue: [ each + 1 ] ifFalse: [ each - 1 ] ]",[(2), (1), (4)]);
  413. return self}, function($ctx1) {$ctx1.fill(self,"testBlockReturn",{},smalltalk.CodeGeneratorTest)})},
  414. args: [],
  415. source: "testBlockReturn\x0a\x09self should: 'foo ^ #(1 2 3) collect: [ :each | true ifTrue: [ each + 1 ] ]' return: #(2 3 4).\x0a\x09self should: 'foo ^ #(1 2 3) collect: [ :each | false ifFalse: [ each + 1 ] ]' return: #(2 3 4).\x0a\x09self should: 'foo ^ #(1 2 3) collect: [ :each | each odd ifTrue: [ each + 1 ] ifFalse: [ each - 1 ] ]' return: #(2 1 4).",
  416. messageSends: ["should:return:"],
  417. referencedClasses: []
  418. }),
  419. smalltalk.CodeGeneratorTest);
  420. smalltalk.addMethod(
  421. smalltalk.method({
  422. selector: "testCascades",
  423. protocol: 'tests',
  424. fn: function (){
  425. var self=this;
  426. return smalltalk.withContext(function($ctx1) {
  427. self._should_return_("foo ^ Array new add: 3; add: 4; yourself",[(3), (4)]);
  428. return self}, function($ctx1) {$ctx1.fill(self,"testCascades",{},smalltalk.CodeGeneratorTest)})},
  429. args: [],
  430. source: "testCascades\x0a\x09\x0a\x09self should: 'foo ^ Array new add: 3; add: 4; yourself' return: #(3 4)",
  431. messageSends: ["should:return:"],
  432. referencedClasses: []
  433. }),
  434. smalltalk.CodeGeneratorTest);
  435. smalltalk.addMethod(
  436. smalltalk.method({
  437. selector: "testCascadesWithInlining",
  438. protocol: 'tests',
  439. fn: function (){
  440. var self=this;
  441. return smalltalk.withContext(function($ctx1) {
  442. self._should_return_("foo ^ true ifTrue: [ 1 ] ifFalse: [ 2 ]",(1));
  443. $ctx1.sendIdx["should:return:"]=1;
  444. self._should_return_("foo ^ false ifTrue: [ 1 ] ifFalse: [ 2 ]",(2));
  445. return self}, function($ctx1) {$ctx1.fill(self,"testCascadesWithInlining",{},smalltalk.CodeGeneratorTest)})},
  446. args: [],
  447. source: "testCascadesWithInlining\x0a\x09\x0a\x09self should: 'foo ^ true ifTrue: [ 1 ] ifFalse: [ 2 ]' return: 1.\x0a\x09self should: 'foo ^ false ifTrue: [ 1 ] ifFalse: [ 2 ]' return: 2",
  448. messageSends: ["should:return:"],
  449. referencedClasses: []
  450. }),
  451. smalltalk.CodeGeneratorTest);
  452. smalltalk.addMethod(
  453. smalltalk.method({
  454. selector: "testDynamicArrayElementsOrdered",
  455. protocol: 'tests',
  456. fn: function (){
  457. var self=this;
  458. return smalltalk.withContext(function($ctx1) {
  459. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { x. x := 2 }\x0a",[(1), (2)]);
  460. $ctx1.sendIdx["should:return:"]=1;
  461. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { x. true ifTrue: [ x := 2 ] }\x0a",[(1), (2)]);
  462. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicArrayElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  463. args: [],
  464. source: "testDynamicArrayElementsOrdered\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { x. x := 2 }\x0a' return: #(1 2).\x0a\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { x. true ifTrue: [ x := 2 ] }\x0a' return: #(1 2).",
  465. messageSends: ["should:return:"],
  466. referencedClasses: []
  467. }),
  468. smalltalk.CodeGeneratorTest);
  469. smalltalk.addMethod(
  470. smalltalk.method({
  471. selector: "testDynamicDictionaryElementsOrdered",
  472. protocol: 'tests',
  473. fn: function (){
  474. var self=this;
  475. return smalltalk.withContext(function($ctx1) {
  476. var $2,$1;
  477. $2="foo".__minus_gt((1));
  478. $ctx1.sendIdx["->"]=1;
  479. $1=smalltalk.HashedCollection._from_([$2,"bar".__minus_gt((2))]);
  480. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 'foo'->1.\x0a\x09^ #{ x. (true ifTrue: [ x := 'bar'->2 ]) }\x0a",$1);
  481. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicDictionaryElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  482. args: [],
  483. source: "testDynamicDictionaryElementsOrdered\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := ''foo''->1.\x0a\x09^ #{ x. (true ifTrue: [ x := ''bar''->2 ]) }\x0a' return: #{'foo'->1. 'bar'->2}.",
  484. messageSends: ["should:return:", "->"],
  485. referencedClasses: []
  486. }),
  487. smalltalk.CodeGeneratorTest);
  488. smalltalk.addMethod(
  489. smalltalk.method({
  490. selector: "testGlobalVar",
  491. protocol: 'tests',
  492. fn: function (){
  493. var self=this;
  494. function $BlockClosure(){return smalltalk.BlockClosure||(typeof BlockClosure=="undefined"?nil:BlockClosure)}
  495. return smalltalk.withContext(function($ctx1) {
  496. self._should_return_("foo ^ eval class",$BlockClosure());
  497. $ctx1.sendIdx["should:return:"]=1;
  498. self._should_return_("foo ^ Math cos: 0",(1));
  499. $ctx1.sendIdx["should:return:"]=2;
  500. self._should_return_("foo ^ NonExistingVar",nil);
  501. return self}, function($ctx1) {$ctx1.fill(self,"testGlobalVar",{},smalltalk.CodeGeneratorTest)})},
  502. args: [],
  503. source: "testGlobalVar\x0a\x09self should: 'foo ^ eval class' return: BlockClosure.\x0a\x09self should: 'foo ^ Math cos: 0' return: 1.\x0a\x09self should: 'foo ^ NonExistingVar' return: nil",
  504. messageSends: ["should:return:"],
  505. referencedClasses: ["BlockClosure"]
  506. }),
  507. smalltalk.CodeGeneratorTest);
  508. smalltalk.addMethod(
  509. smalltalk.method({
  510. selector: "testInnerTemporalDependentElementsOrdered",
  511. protocol: 'tests',
  512. fn: function (){
  513. var self=this;
  514. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  515. return smalltalk.withContext(function($ctx1) {
  516. var $2,$3,$1,$5,$6,$4,$8,$9,$7,$11,$12,$10,$14,$13;
  517. $2="foo".__minus_gt($Array());
  518. $ctx1.sendIdx["->"]=1;
  519. $3="bar".__minus_gt((2));
  520. $ctx1.sendIdx["->"]=2;
  521. $1=[$2,$3];
  522. self._should_return_("foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: 'foo'->x with: 'bar'->(x := 2)\x0a",$1);
  523. $ctx1.sendIdx["should:return:"]=1;
  524. $5="foo".__minus_gt($Array());
  525. $ctx1.sendIdx["->"]=3;
  526. $6="bar".__minus_gt((2));
  527. $ctx1.sendIdx["->"]=4;
  528. $4=[$5,$6];
  529. self._should_return_("foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: 'foo'->x with: 'bar'->(true ifTrue: [ x := 2 ])\x0a",$4);
  530. $ctx1.sendIdx["should:return:"]=2;
  531. $8="foo".__minus_gt((1));
  532. $ctx1.sendIdx["->"]=5;
  533. $9="bar".__minus_gt((2));
  534. $ctx1.sendIdx["->"]=6;
  535. $7=[$8,$9];
  536. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ Array with: 'foo'->x with: 'bar'->(true ifTrue: [ x := 2 ])\x0a",$7);
  537. $ctx1.sendIdx["should:return:"]=3;
  538. $11="foo".__minus_gt((1));
  539. $ctx1.sendIdx["->"]=7;
  540. $12="bar".__minus_gt((2));
  541. $ctx1.sendIdx["->"]=8;
  542. $10=[$11,$12];
  543. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { 'foo'->x. 'bar'->(true ifTrue: [ x := 2 ]) }\x0a",$10);
  544. $ctx1.sendIdx["should:return:"]=4;
  545. $14="foo".__minus_gt((1));
  546. $ctx1.sendIdx["->"]=9;
  547. $13=smalltalk.HashedCollection._from_([$14,"bar".__minus_gt((2))]);
  548. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ #{ 'foo'->x. 'bar'->(true ifTrue: [ x := 2 ]) }\x0a",$13);
  549. return self}, function($ctx1) {$ctx1.fill(self,"testInnerTemporalDependentElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  550. args: [],
  551. source: "testInnerTemporalDependentElementsOrdered\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: ''foo''->x with: ''bar''->(x := 2)\x0a' return: {'foo'->Array. 'bar'->2}.\x0a\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: ''foo''->x with: ''bar''->(true ifTrue: [ x := 2 ])\x0a' return: {'foo'->Array. 'bar'->2}.\x0a\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ Array with: ''foo''->x with: ''bar''->(true ifTrue: [ x := 2 ])\x0a' return: {'foo'->1. 'bar'->2}.\x0a\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { ''foo''->x. ''bar''->(true ifTrue: [ x := 2 ]) }\x0a' return: {'foo'->1. 'bar'->2}.\x0a\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ #{ ''foo''->x. ''bar''->(true ifTrue: [ x := 2 ]) }\x0a' return: #{'foo'->1. 'bar'->2}.",
  552. messageSends: ["should:return:", "->"],
  553. referencedClasses: ["Array"]
  554. }),
  555. smalltalk.CodeGeneratorTest);
  556. smalltalk.addMethod(
  557. smalltalk.method({
  558. selector: "testJSStatement",
  559. protocol: 'tests',
  560. fn: function (){
  561. var self=this;
  562. return smalltalk.withContext(function($ctx1) {
  563. self._should_return_("foo <return 2+3>",(5));
  564. return self}, function($ctx1) {$ctx1.fill(self,"testJSStatement",{},smalltalk.CodeGeneratorTest)})},
  565. args: [],
  566. source: "testJSStatement\x0a\x09self should: 'foo <return 2+3>' return: 5",
  567. messageSends: ["should:return:"],
  568. referencedClasses: []
  569. }),
  570. smalltalk.CodeGeneratorTest);
  571. smalltalk.addMethod(
  572. smalltalk.method({
  573. selector: "testLiterals",
  574. protocol: 'tests',
  575. fn: function (){
  576. var self=this;
  577. return smalltalk.withContext(function($ctx1) {
  578. var $2,$1;
  579. self._should_return_("foo ^ 1",(1));
  580. $ctx1.sendIdx["should:return:"]=1;
  581. self._should_return_("foo ^ 'hello'","hello");
  582. $ctx1.sendIdx["should:return:"]=2;
  583. self._should_return_("foo ^ #(1 2 3 4)",[(1), (2), (3), (4)]);
  584. $ctx1.sendIdx["should:return:"]=3;
  585. self._should_return_("foo ^ {1. [:x | x ] value: 2. 3. [4] value}",[(1), (2), (3), (4)]);
  586. $ctx1.sendIdx["should:return:"]=4;
  587. self._should_return_("foo ^ true",true);
  588. $ctx1.sendIdx["should:return:"]=5;
  589. self._should_return_("foo ^ false",false);
  590. $ctx1.sendIdx["should:return:"]=6;
  591. $2=(1).__minus_gt((2));
  592. $ctx1.sendIdx["->"]=1;
  593. $1=smalltalk.HashedCollection._from_([$2,(3).__minus_gt((4))]);
  594. self._should_return_("foo ^ #{1->2. 3->4}",$1);
  595. $ctx1.sendIdx["should:return:"]=7;
  596. self._should_return_("foo ^ #hello","hello");
  597. $ctx1.sendIdx["should:return:"]=8;
  598. self._should_return_("foo ^ -123.456",(-123.456));
  599. $ctx1.sendIdx["should:return:"]=9;
  600. self._should_return_("foo ^ -2.5e4",(-25000));
  601. return self}, function($ctx1) {$ctx1.fill(self,"testLiterals",{},smalltalk.CodeGeneratorTest)})},
  602. args: [],
  603. source: "testLiterals\x0a\x09self should: 'foo ^ 1' return: 1.\x0a\x09self should: 'foo ^ ''hello''' return: 'hello'.\x0a\x09self should: 'foo ^ #(1 2 3 4)' return: #(1 2 3 4).\x0a\x09self should: 'foo ^ {1. [:x | x ] value: 2. 3. [4] value}' return: #(1 2 3 4).\x0a\x09self should: 'foo ^ true' return: true.\x0a\x09self should: 'foo ^ false' return: false.\x0a\x09self should: 'foo ^ #{1->2. 3->4}' return: #{1->2. 3->4}.\x0a\x09self should: 'foo ^ #hello' return: #hello.\x0a\x09self should: 'foo ^ -123.456' return: -123.456.\x0a\x09self should: 'foo ^ -2.5e4' return: -25000.",
  604. messageSends: ["should:return:", "->"],
  605. referencedClasses: []
  606. }),
  607. smalltalk.CodeGeneratorTest);
  608. smalltalk.addMethod(
  609. smalltalk.method({
  610. selector: "testLocalReturn",
  611. protocol: 'tests',
  612. fn: function (){
  613. var self=this;
  614. return smalltalk.withContext(function($ctx1) {
  615. self._should_return_("foo ^ 1",(1));
  616. $ctx1.sendIdx["should:return:"]=1;
  617. self._should_return_("foo ^ 1 + 1",(2));
  618. $ctx1.sendIdx["should:return:"]=2;
  619. self._should_return_("foo ",self["@receiver"]);
  620. $ctx1.sendIdx["should:return:"]=3;
  621. self._should_return_("foo self asString",self["@receiver"]);
  622. $ctx1.sendIdx["should:return:"]=4;
  623. self._should_return_("foo | a b | a := 1. b := 2. ^ a + b",(3));
  624. return self}, function($ctx1) {$ctx1.fill(self,"testLocalReturn",{},smalltalk.CodeGeneratorTest)})},
  625. args: [],
  626. source: "testLocalReturn\x0a\x09self should: 'foo ^ 1' return: 1.\x0a\x09self should: 'foo ^ 1 + 1' return: 2.\x0a\x09self should: 'foo ' return: receiver.\x0a\x09self should: 'foo self asString' return: receiver.\x0a\x09self should: 'foo | a b | a := 1. b := 2. ^ a + b' return: 3",
  627. messageSends: ["should:return:"],
  628. referencedClasses: []
  629. }),
  630. smalltalk.CodeGeneratorTest);
  631. smalltalk.addMethod(
  632. smalltalk.method({
  633. selector: "testMessageSends",
  634. protocol: 'tests',
  635. fn: function (){
  636. var self=this;
  637. return smalltalk.withContext(function($ctx1) {
  638. self._should_return_("foo ^ 1 asString","1");
  639. $ctx1.sendIdx["should:return:"]=1;
  640. self._should_return_("foo ^ 1 + 1",(2));
  641. $ctx1.sendIdx["should:return:"]=2;
  642. self._should_return_("foo ^ 1 + 2 * 3",(9));
  643. $ctx1.sendIdx["should:return:"]=3;
  644. self._should_return_("foo ^ 1 to: 3",[(1), (2), (3)]);
  645. $ctx1.sendIdx["should:return:"]=4;
  646. self._should_return_("foo ^ 1 to: 5 by: 2",[(1), (3), (5)]);
  647. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSends",{},smalltalk.CodeGeneratorTest)})},
  648. args: [],
  649. source: "testMessageSends\x0a\x09self should: 'foo ^ 1 asString' return: '1'.\x0a\x0a\x09self should: 'foo ^ 1 + 1' return: 2.\x0a\x09self should: 'foo ^ 1 + 2 * 3' return: 9.\x0a\x0a\x09self should: 'foo ^ 1 to: 3' return: #(1 2 3).\x0a\x09self should: 'foo ^ 1 to: 5 by: 2' return: #(1 3 5)",
  650. messageSends: ["should:return:"],
  651. referencedClasses: []
  652. }),
  653. smalltalk.CodeGeneratorTest);
  654. smalltalk.addMethod(
  655. smalltalk.method({
  656. selector: "testMultipleSequences",
  657. protocol: 'tests',
  658. fn: function (){
  659. var self=this;
  660. return smalltalk.withContext(function($ctx1) {
  661. self._should_return_("foo | a b c | a := 2. b := 3. c := a + b. ^ c * 6",(30));
  662. return self}, function($ctx1) {$ctx1.fill(self,"testMultipleSequences",{},smalltalk.CodeGeneratorTest)})},
  663. args: [],
  664. source: "testMultipleSequences\x0a\x09self should: 'foo | a b c | a := 2. b := 3. c := a + b. ^ c * 6' return: 30",
  665. messageSends: ["should:return:"],
  666. referencedClasses: []
  667. }),
  668. smalltalk.CodeGeneratorTest);
  669. smalltalk.addMethod(
  670. smalltalk.method({
  671. selector: "testMutableLiterals",
  672. protocol: 'tests',
  673. fn: function (){
  674. var self=this;
  675. return smalltalk.withContext(function($ctx1) {
  676. self._should_return_("foo ^ #( 1 2 ) at: 1 put: 3; yourself",[(3), (2)]);
  677. return self}, function($ctx1) {$ctx1.fill(self,"testMutableLiterals",{},smalltalk.CodeGeneratorTest)})},
  678. args: [],
  679. source: "testMutableLiterals\x0a\x09\x22Mutable literals must be aliased in cascades.\x0a\x09See https://github.com/amber-smalltalk/amber/issues/428\x22\x0a\x09\x0a\x09self \x0a\x09\x09should: 'foo ^ #( 1 2 ) at: 1 put: 3; yourself' \x0a\x09\x09return: #(3 2)",
  680. messageSends: ["should:return:"],
  681. referencedClasses: []
  682. }),
  683. smalltalk.CodeGeneratorTest);
  684. smalltalk.addMethod(
  685. smalltalk.method({
  686. selector: "testNestedIfTrue",
  687. protocol: 'tests',
  688. fn: function (){
  689. var self=this;
  690. return smalltalk.withContext(function($ctx1) {
  691. self._should_return_("foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]",(1));
  692. $ctx1.sendIdx["should:return:"]=1;
  693. self._should_return_("foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]",nil);
  694. $ctx1.sendIdx["should:return:"]=2;
  695. self._should_return_("foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]",(1));
  696. $ctx1.sendIdx["should:return:"]=3;
  697. self._should_return_("foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]",self["@receiver"]);
  698. return self}, function($ctx1) {$ctx1.fill(self,"testNestedIfTrue",{},smalltalk.CodeGeneratorTest)})},
  699. args: [],
  700. source: "testNestedIfTrue\x0a\x09self should: 'foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]' return: 1.\x0a\x09self should: 'foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]' return: nil.\x0a\x0a\x09self should: 'foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]' return: 1.\x0a\x09self should: 'foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]' return: receiver.",
  701. messageSends: ["should:return:"],
  702. referencedClasses: []
  703. }),
  704. smalltalk.CodeGeneratorTest);
  705. smalltalk.addMethod(
  706. smalltalk.method({
  707. selector: "testNestedSends",
  708. protocol: 'tests',
  709. fn: function (){
  710. var self=this;
  711. function $Point(){return smalltalk.Point||(typeof Point=="undefined"?nil:Point)}
  712. return smalltalk.withContext(function($ctx1) {
  713. self._should_return_("foo ^ (Point x: (Point x: 2 y: 3) y: 4) asString",_st(_st($Point())._x_y_((2).__at((3)),(4)))._asString());
  714. return self}, function($ctx1) {$ctx1.fill(self,"testNestedSends",{},smalltalk.CodeGeneratorTest)})},
  715. args: [],
  716. source: "testNestedSends\x0a\x09self should: 'foo ^ (Point x: (Point x: 2 y: 3) y: 4) asString' return: (Point x: (2@3) y: 4) asString",
  717. messageSends: ["should:return:", "asString", "x:y:", "@"],
  718. referencedClasses: ["Point"]
  719. }),
  720. smalltalk.CodeGeneratorTest);
  721. smalltalk.addMethod(
  722. smalltalk.method({
  723. selector: "testNonLocalReturn",
  724. protocol: 'tests',
  725. fn: function (){
  726. var self=this;
  727. return smalltalk.withContext(function($ctx1) {
  728. self._should_return_("foo [ ^ 1 ] value",(1));
  729. $ctx1.sendIdx["should:return:"]=1;
  730. self._should_return_("foo [ ^ 1 + 1 ] value",(2));
  731. $ctx1.sendIdx["should:return:"]=2;
  732. self._should_return_("foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt",(3));
  733. $ctx1.sendIdx["should:return:"]=3;
  734. self._should_return_("foo [ :x | ^ x + x ] value: 4. ^ 2",(8));
  735. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn",{},smalltalk.CodeGeneratorTest)})},
  736. args: [],
  737. source: "testNonLocalReturn\x0a\x09self should: 'foo [ ^ 1 ] value' return: 1.\x0a\x09self should: 'foo [ ^ 1 + 1 ] value' return: 2.\x0a\x09self should: 'foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt' return: 3.\x0a\x09self should: 'foo [ :x | ^ x + x ] value: 4. ^ 2' return: 8",
  738. messageSends: ["should:return:"],
  739. referencedClasses: []
  740. }),
  741. smalltalk.CodeGeneratorTest);
  742. smalltalk.addMethod(
  743. smalltalk.method({
  744. selector: "testPascalCaseGlobal",
  745. protocol: 'tests',
  746. fn: function (){
  747. var self=this;
  748. return smalltalk.withContext(function($ctx1) {
  749. self._should_return_("foo ^Object",_st(smalltalk)._at_("Object"));
  750. $ctx1.sendIdx["should:return:"]=1;
  751. self._should_return_("foo ^NonExistent",nil);
  752. return self}, function($ctx1) {$ctx1.fill(self,"testPascalCaseGlobal",{},smalltalk.CodeGeneratorTest)})},
  753. args: [],
  754. source: "testPascalCaseGlobal\x0a\x09self should: 'foo ^Object' return: (smalltalk at: 'Object').\x0a\x09self should: 'foo ^NonExistent' return: nil",
  755. messageSends: ["should:return:", "at:"],
  756. referencedClasses: []
  757. }),
  758. smalltalk.CodeGeneratorTest);
  759. smalltalk.addMethod(
  760. smalltalk.method({
  761. selector: "testSendReceiverAndArgumentsOrdered",
  762. protocol: 'tests',
  763. fn: function (){
  764. var self=this;
  765. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  766. return smalltalk.withContext(function($ctx1) {
  767. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ Array with: x with: (true ifTrue: [ x := 2 ])\x0a",[(1), (2)]);
  768. $ctx1.sendIdx["should:return:"]=1;
  769. self._should_return_("foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: x with: (true ifTrue: [ x := 2 ])\x0a",[$Array(),(2)]);
  770. return self}, function($ctx1) {$ctx1.fill(self,"testSendReceiverAndArgumentsOrdered",{},smalltalk.CodeGeneratorTest)})},
  771. args: [],
  772. source: "testSendReceiverAndArgumentsOrdered\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ Array with: x with: (true ifTrue: [ x := 2 ])\x0a' return: #(1 2).\x0a\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: x with: (true ifTrue: [ x := 2 ])\x0a' return: {Array. 2}.",
  773. messageSends: ["should:return:"],
  774. referencedClasses: ["Array"]
  775. }),
  776. smalltalk.CodeGeneratorTest);
  777. smalltalk.addMethod(
  778. smalltalk.method({
  779. selector: "testSuperSend",
  780. protocol: 'tests',
  781. fn: function (){
  782. var self=this;
  783. return smalltalk.withContext(function($ctx1) {
  784. self._should_receiver_return_("foo ^ super isBoolean",true,false);
  785. return self}, function($ctx1) {$ctx1.fill(self,"testSuperSend",{},smalltalk.CodeGeneratorTest)})},
  786. args: [],
  787. source: "testSuperSend\x0a\x09self \x0a\x09\x09should: 'foo ^ super isBoolean' \x0a\x09\x09receiver: true\x0a\x09\x09return: false",
  788. messageSends: ["should:receiver:return:"],
  789. referencedClasses: []
  790. }),
  791. smalltalk.CodeGeneratorTest);
  792. smalltalk.addMethod(
  793. smalltalk.method({
  794. selector: "testTempVariables",
  795. protocol: 'tests',
  796. fn: function (){
  797. var self=this;
  798. return smalltalk.withContext(function($ctx1) {
  799. self._should_return_("foo | a | ^ a",nil);
  800. $ctx1.sendIdx["should:return:"]=1;
  801. self._should_return_("foo | AVariable | ^ AVariable",nil);
  802. $ctx1.sendIdx["should:return:"]=2;
  803. self._should_return_("foo | a b c | ^ c",nil);
  804. $ctx1.sendIdx["should:return:"]=3;
  805. self._should_return_("foo | a | [ | d | ^ d ] value",nil);
  806. $ctx1.sendIdx["should:return:"]=4;
  807. self._should_return_("foo | a | a:= 1. ^ a",(1));
  808. $ctx1.sendIdx["should:return:"]=5;
  809. self._should_return_("foo | AVariable | AVariable := 1. ^ AVariable",(1));
  810. return self}, function($ctx1) {$ctx1.fill(self,"testTempVariables",{},smalltalk.CodeGeneratorTest)})},
  811. args: [],
  812. source: "testTempVariables\x0a\x09self should: 'foo | a | ^ a' return: nil.\x0a\x09self should: 'foo | AVariable | ^ AVariable' return: nil.\x0a\x09self should: 'foo | a b c | ^ c' return: nil.\x0a\x09self should: 'foo | a | [ | d | ^ d ] value' return: nil.\x0a\x09\x0a\x09self should: 'foo | a | a:= 1. ^ a' return: 1.\x0a\x09self should: 'foo | AVariable | AVariable := 1. ^ AVariable' return: 1.",
  813. messageSends: ["should:return:"],
  814. referencedClasses: []
  815. }),
  816. smalltalk.CodeGeneratorTest);
  817. smalltalk.addMethod(
  818. smalltalk.method({
  819. selector: "testThisContext",
  820. protocol: 'tests',
  821. fn: function (){
  822. var self=this;
  823. return smalltalk.withContext(function($ctx1) {
  824. self._should_return_("foo ^ [ thisContext ] value outerContext == thisContext",true);
  825. return self}, function($ctx1) {$ctx1.fill(self,"testThisContext",{},smalltalk.CodeGeneratorTest)})},
  826. args: [],
  827. source: "testThisContext\x0a\x09self should: 'foo ^ [ thisContext ] value outerContext == thisContext' return: true",
  828. messageSends: ["should:return:"],
  829. referencedClasses: []
  830. }),
  831. smalltalk.CodeGeneratorTest);
  832. smalltalk.addMethod(
  833. smalltalk.method({
  834. selector: "testifFalse",
  835. protocol: 'tests',
  836. fn: function (){
  837. var self=this;
  838. return smalltalk.withContext(function($ctx1) {
  839. self._should_return_("foo true ifFalse: [ ^ 1 ]",self["@receiver"]);
  840. $ctx1.sendIdx["should:return:"]=1;
  841. self._should_return_("foo false ifFalse: [ ^ 2 ]",(2));
  842. $ctx1.sendIdx["should:return:"]=2;
  843. self._should_return_("foo ^ true ifFalse: [ 1 ]",nil);
  844. $ctx1.sendIdx["should:return:"]=3;
  845. self._should_return_("foo ^ false ifFalse: [ 2 ]",(2));
  846. return self}, function($ctx1) {$ctx1.fill(self,"testifFalse",{},smalltalk.CodeGeneratorTest)})},
  847. args: [],
  848. source: "testifFalse\x0a\x09self should: 'foo true ifFalse: [ ^ 1 ]' return: receiver.\x0a\x09self should: 'foo false ifFalse: [ ^ 2 ]' return: 2.\x0a\x09\x0a\x09self should: 'foo ^ true ifFalse: [ 1 ]' return: nil.\x0a\x09self should: 'foo ^ false ifFalse: [ 2 ]' return: 2.",
  849. messageSends: ["should:return:"],
  850. referencedClasses: []
  851. }),
  852. smalltalk.CodeGeneratorTest);
  853. smalltalk.addMethod(
  854. smalltalk.method({
  855. selector: "testifFalseIfTrue",
  856. protocol: 'tests',
  857. fn: function (){
  858. var self=this;
  859. return smalltalk.withContext(function($ctx1) {
  860. self._should_return_("foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]",(2));
  861. $ctx1.sendIdx["should:return:"]=1;
  862. self._should_return_("foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]",(2));
  863. $ctx1.sendIdx["should:return:"]=2;
  864. self._should_return_("foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]",(2));
  865. $ctx1.sendIdx["should:return:"]=3;
  866. self._should_return_("foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]",(2));
  867. return self}, function($ctx1) {$ctx1.fill(self,"testifFalseIfTrue",{},smalltalk.CodeGeneratorTest)})},
  868. args: [],
  869. source: "testifFalseIfTrue\x0a\x09self should: 'foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]' return: 2.\x0a\x09self should: 'foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]' return: 2.\x0a\x09\x0a\x09self should: 'foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]' return: 2.\x0a\x09self should: 'foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]' return: 2.",
  870. messageSends: ["should:return:"],
  871. referencedClasses: []
  872. }),
  873. smalltalk.CodeGeneratorTest);
  874. smalltalk.addMethod(
  875. smalltalk.method({
  876. selector: "testifNil",
  877. protocol: 'tests',
  878. fn: function (){
  879. var self=this;
  880. return smalltalk.withContext(function($ctx1) {
  881. self._should_return_("foo ^ 1 ifNil: [ 2 ]",(1));
  882. $ctx1.sendIdx["should:return:"]=1;
  883. self._should_return_("foo ^ nil ifNil: [ 2 ]",(2));
  884. $ctx1.sendIdx["should:return:"]=2;
  885. self._should_return_("foo 1 ifNil: [ ^ 2 ]",self["@receiver"]);
  886. $ctx1.sendIdx["should:return:"]=3;
  887. self._should_return_("foo nil ifNil: [ ^ 2 ]",(2));
  888. return self}, function($ctx1) {$ctx1.fill(self,"testifNil",{},smalltalk.CodeGeneratorTest)})},
  889. args: [],
  890. source: "testifNil\x0a\x09self should: 'foo ^ 1 ifNil: [ 2 ]' return: 1.\x0a\x09self should: 'foo ^ nil ifNil: [ 2 ]' return: 2.\x0a\x0a\x09self should: 'foo 1 ifNil: [ ^ 2 ]' return: receiver.\x0a\x09self should: 'foo nil ifNil: [ ^ 2 ]' return: 2.",
  891. messageSends: ["should:return:"],
  892. referencedClasses: []
  893. }),
  894. smalltalk.CodeGeneratorTest);
  895. smalltalk.addMethod(
  896. smalltalk.method({
  897. selector: "testifNilIfNotNil",
  898. protocol: 'tests',
  899. fn: function (){
  900. var self=this;
  901. return smalltalk.withContext(function($ctx1) {
  902. self._should_return_("foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]",(3));
  903. $ctx1.sendIdx["should:return:"]=1;
  904. self._should_return_("foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]",(2));
  905. $ctx1.sendIdx["should:return:"]=2;
  906. self._should_return_("foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(3));
  907. $ctx1.sendIdx["should:return:"]=3;
  908. self._should_return_("foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(2));
  909. return self}, function($ctx1) {$ctx1.fill(self,"testifNilIfNotNil",{},smalltalk.CodeGeneratorTest)})},
  910. args: [],
  911. source: "testifNilIfNotNil\x0a\x09self should: 'foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]' return: 3.\x0a\x09self should: 'foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]' return: 2.\x0a\x0a\x09self should: 'foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]' return: 3.\x0a\x09self should: 'foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]' return: 2.",
  912. messageSends: ["should:return:"],
  913. referencedClasses: []
  914. }),
  915. smalltalk.CodeGeneratorTest);
  916. smalltalk.addMethod(
  917. smalltalk.method({
  918. selector: "testifNotNil",
  919. protocol: 'tests',
  920. fn: function (){
  921. var self=this;
  922. return smalltalk.withContext(function($ctx1) {
  923. self._should_return_("foo ^ 1 ifNotNil: [ 2 ]",(2));
  924. $ctx1.sendIdx["should:return:"]=1;
  925. self._should_return_("foo ^ nil ifNotNil: [ 2 ]",nil);
  926. $ctx1.sendIdx["should:return:"]=2;
  927. self._should_return_("foo 1 ifNotNil: [ ^ 2 ]",(2));
  928. $ctx1.sendIdx["should:return:"]=3;
  929. self._should_return_("foo nil ifNotNil: [ ^ 2 ]",self["@receiver"]);
  930. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNil",{},smalltalk.CodeGeneratorTest)})},
  931. args: [],
  932. source: "testifNotNil\x0a\x09self should: 'foo ^ 1 ifNotNil: [ 2 ]' return: 2.\x0a\x09self should: 'foo ^ nil ifNotNil: [ 2 ]' return: nil.\x0a\x0a\x09self should: 'foo 1 ifNotNil: [ ^ 2 ]' return: 2.\x0a\x09self should: 'foo nil ifNotNil: [ ^ 2 ]' return: receiver.",
  933. messageSends: ["should:return:"],
  934. referencedClasses: []
  935. }),
  936. smalltalk.CodeGeneratorTest);
  937. smalltalk.addMethod(
  938. smalltalk.method({
  939. selector: "testifNotNilWithArgument",
  940. protocol: 'tests',
  941. fn: function (){
  942. var self=this;
  943. return smalltalk.withContext(function($ctx1) {
  944. self._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ]",(3));
  945. $ctx1.sendIdx["should:return:"]=1;
  946. self._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ]",nil);
  947. $ctx1.sendIdx["should:return:"]=2;
  948. self._should_return_("foo ^ 1 ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(3));
  949. $ctx1.sendIdx["should:return:"]=3;
  950. self._should_return_("foo ^ nil ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(5));
  951. $ctx1.sendIdx["should:return:"]=4;
  952. self._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(3));
  953. $ctx1.sendIdx["should:return:"]=5;
  954. self._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(5));
  955. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNilWithArgument",{},smalltalk.CodeGeneratorTest)})},
  956. args: [],
  957. source: "testifNotNilWithArgument\x0a\x09self should: 'foo ^ 1 ifNotNil: [ :val | val + 2 ]' return: 3.\x0a\x09self should: 'foo ^ nil ifNotNil: [ :val | val + 2 ]' return: nil.\x0a\x09\x0a\x09self should: 'foo ^ 1 ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]' return: 3.\x0a\x09self should: 'foo ^ nil ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]' return: 5.\x0a\x09\x0a\x09self should: 'foo ^ 1 ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]' return: 3.\x0a\x09self should: 'foo ^ nil ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]' return: 5",
  958. messageSends: ["should:return:"],
  959. referencedClasses: []
  960. }),
  961. smalltalk.CodeGeneratorTest);
  962. smalltalk.addMethod(
  963. smalltalk.method({
  964. selector: "testifTrue",
  965. protocol: 'tests',
  966. fn: function (){
  967. var self=this;
  968. return smalltalk.withContext(function($ctx1) {
  969. self._should_return_("foo false ifTrue: [ ^ 1 ]",self["@receiver"]);
  970. $ctx1.sendIdx["should:return:"]=1;
  971. self._should_return_("foo true ifTrue: [ ^ 2 ]",(2));
  972. $ctx1.sendIdx["should:return:"]=2;
  973. self._should_return_("foo ^ false ifTrue: [ 1 ]",nil);
  974. $ctx1.sendIdx["should:return:"]=3;
  975. self._should_return_("foo ^ true ifTrue: [ 2 ]",(2));
  976. return self}, function($ctx1) {$ctx1.fill(self,"testifTrue",{},smalltalk.CodeGeneratorTest)})},
  977. args: [],
  978. source: "testifTrue\x0a\x09self should: 'foo false ifTrue: [ ^ 1 ]' return: receiver.\x0a\x09self should: 'foo true ifTrue: [ ^ 2 ]' return: 2.\x0a\x09\x0a\x09self should: 'foo ^ false ifTrue: [ 1 ]' return: nil.\x0a\x09self should: 'foo ^ true ifTrue: [ 2 ]' return: 2.",
  979. messageSends: ["should:return:"],
  980. referencedClasses: []
  981. }),
  982. smalltalk.CodeGeneratorTest);
  983. smalltalk.addMethod(
  984. smalltalk.method({
  985. selector: "testifTrueIfFalse",
  986. protocol: 'tests',
  987. fn: function (){
  988. var self=this;
  989. return smalltalk.withContext(function($ctx1) {
  990. self._should_return_("foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]",(2));
  991. $ctx1.sendIdx["should:return:"]=1;
  992. self._should_return_("foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]",(1));
  993. $ctx1.sendIdx["should:return:"]=2;
  994. self._should_return_("foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]",(1));
  995. $ctx1.sendIdx["should:return:"]=3;
  996. self._should_return_("foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]",(2));
  997. return self}, function($ctx1) {$ctx1.fill(self,"testifTrueIfFalse",{},smalltalk.CodeGeneratorTest)})},
  998. args: [],
  999. source: "testifTrueIfFalse\x0a\x09self should: 'foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]' return: 2.\x0a\x09self should: 'foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]' return: 1.\x0a\x09\x0a\x09self should: 'foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]' return: 1.\x0a\x09self should: 'foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]' return: 2.",
  1000. messageSends: ["should:return:"],
  1001. referencedClasses: []
  1002. }),
  1003. smalltalk.CodeGeneratorTest);
  1004. smalltalk.addClass('InliningCodeGeneratorTest', smalltalk.CodeGeneratorTest, [], 'Compiler-Tests');
  1005. smalltalk.addMethod(
  1006. smalltalk.method({
  1007. selector: "codeGeneratorClass",
  1008. protocol: 'accessing',
  1009. fn: function (){
  1010. var self=this;
  1011. function $InliningCodeGenerator(){return smalltalk.InliningCodeGenerator||(typeof InliningCodeGenerator=="undefined"?nil:InliningCodeGenerator)}
  1012. return smalltalk.withContext(function($ctx1) {
  1013. return $InliningCodeGenerator();
  1014. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{},smalltalk.InliningCodeGeneratorTest)})},
  1015. args: [],
  1016. source: "codeGeneratorClass\x0a\x09^ InliningCodeGenerator",
  1017. messageSends: [],
  1018. referencedClasses: ["InliningCodeGenerator"]
  1019. }),
  1020. smalltalk.InliningCodeGeneratorTest);
  1021. smalltalk.addClass('InterpreterTest', smalltalk.CodeGeneratorTest, [], 'Compiler-Tests');
  1022. smalltalk.addMethod(
  1023. smalltalk.method({
  1024. selector: "analyze:forClass:",
  1025. protocol: 'parsing',
  1026. fn: function (aNode,aClass){
  1027. var self=this;
  1028. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1029. return smalltalk.withContext(function($ctx1) {
  1030. _st(_st($SemanticAnalyzer())._on_(aClass))._visit_(aNode);
  1031. return aNode;
  1032. }, function($ctx1) {$ctx1.fill(self,"analyze:forClass:",{aNode:aNode,aClass:aClass},smalltalk.InterpreterTest)})},
  1033. args: ["aNode", "aClass"],
  1034. source: "analyze: aNode forClass: aClass\x0a\x09(SemanticAnalyzer on: aClass) visit: aNode.\x0a\x09^ aNode",
  1035. messageSends: ["visit:", "on:"],
  1036. referencedClasses: ["SemanticAnalyzer"]
  1037. }),
  1038. smalltalk.InterpreterTest);
  1039. smalltalk.addMethod(
  1040. smalltalk.method({
  1041. selector: "interpret:receiver:withArguments:",
  1042. protocol: 'private',
  1043. fn: function (aString,anObject,aDictionary){
  1044. var self=this;
  1045. var ctx,interpreter;
  1046. function $ASTInterpreter(){return smalltalk.ASTInterpreter||(typeof ASTInterpreter=="undefined"?nil:ASTInterpreter)}
  1047. function $AIContext(){return smalltalk.AIContext||(typeof AIContext=="undefined"?nil:AIContext)}
  1048. return smalltalk.withContext(function($ctx1) {
  1049. var $1,$2,$4,$5,$3;
  1050. interpreter=_st($ASTInterpreter())._new();
  1051. $ctx1.sendIdx["new"]=1;
  1052. $1=_st($AIContext())._new();
  1053. _st($1)._receiver_(anObject);
  1054. _st($1)._interpreter_(interpreter);
  1055. $2=_st($1)._yourself();
  1056. ctx=$2;
  1057. _st(aDictionary)._keysAndValuesDo_((function(key,value){
  1058. return smalltalk.withContext(function($ctx2) {
  1059. return _st(ctx)._localAt_put_(key,value);
  1060. }, function($ctx2) {$ctx2.fillBlock({key:key,value:value},$ctx1,1)})}));
  1061. $4=interpreter;
  1062. _st($4)._context_(ctx);
  1063. _st($4)._interpret_(_st(self._parse_forClass_(aString,_st(anObject)._class()))._nextChild());
  1064. _st($4)._proceed();
  1065. $5=_st($4)._result();
  1066. $3=$5;
  1067. return $3;
  1068. }, function($ctx1) {$ctx1.fill(self,"interpret:receiver:withArguments:",{aString:aString,anObject:anObject,aDictionary:aDictionary,ctx:ctx,interpreter:interpreter},smalltalk.InterpreterTest)})},
  1069. args: ["aString", "anObject", "aDictionary"],
  1070. source: "interpret: aString receiver: anObject withArguments: aDictionary\x0a\x09\x22The food is a methodNode. Interpret the sequenceNode only\x22\x0a\x09\x0a\x09| ctx interpreter |\x0a\x09\x0a\x09interpreter := ASTInterpreter new.\x0a\x09\x0a\x09ctx := AIContext new\x0a\x09\x09receiver: anObject;\x0a\x09\x09interpreter: interpreter;\x0a\x09\x09yourself.\x0a\x09aDictionary keysAndValuesDo: [ :key :value |\x0a\x09\x09ctx localAt: key put: value ].\x0a\x09\x0a\x09^ interpreter\x0a\x09\x09context: ctx;\x0a\x09\x09interpret: (self parse: aString forClass: anObject class) nextChild;\x0a\x09\x09proceed;\x0a\x09\x09result",
  1071. messageSends: ["new", "receiver:", "interpreter:", "yourself", "keysAndValuesDo:", "localAt:put:", "context:", "interpret:", "nextChild", "parse:forClass:", "class", "proceed", "result"],
  1072. referencedClasses: ["ASTInterpreter", "AIContext"]
  1073. }),
  1074. smalltalk.InterpreterTest);
  1075. smalltalk.addMethod(
  1076. smalltalk.method({
  1077. selector: "parse:",
  1078. protocol: 'parsing',
  1079. fn: function (aString){
  1080. var self=this;
  1081. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1082. return smalltalk.withContext(function($ctx1) {
  1083. var $1;
  1084. $1=_st(_st($Smalltalk())._current())._parse_(aString);
  1085. return $1;
  1086. }, function($ctx1) {$ctx1.fill(self,"parse:",{aString:aString},smalltalk.InterpreterTest)})},
  1087. args: ["aString"],
  1088. source: "parse: aString\x0a\x09^ Smalltalk current parse: aString",
  1089. messageSends: ["parse:", "current"],
  1090. referencedClasses: ["Smalltalk"]
  1091. }),
  1092. smalltalk.InterpreterTest);
  1093. smalltalk.addMethod(
  1094. smalltalk.method({
  1095. selector: "parse:forClass:",
  1096. protocol: 'parsing',
  1097. fn: function (aString,aClass){
  1098. var self=this;
  1099. return smalltalk.withContext(function($ctx1) {
  1100. var $1;
  1101. $1=self._analyze_forClass_(self._parse_(aString),aClass);
  1102. return $1;
  1103. }, function($ctx1) {$ctx1.fill(self,"parse:forClass:",{aString:aString,aClass:aClass},smalltalk.InterpreterTest)})},
  1104. args: ["aString", "aClass"],
  1105. source: "parse: aString forClass: aClass\x0a\x09^ self analyze: (self parse: aString) forClass: aClass",
  1106. messageSends: ["analyze:forClass:", "parse:"],
  1107. referencedClasses: []
  1108. }),
  1109. smalltalk.InterpreterTest);
  1110. smalltalk.addMethod(
  1111. smalltalk.method({
  1112. selector: "should:receiver:return:",
  1113. protocol: 'testing',
  1114. fn: function (aString,anObject,aResult){
  1115. var self=this;
  1116. return smalltalk.withContext(function($ctx1) {
  1117. var $1;
  1118. self["@receiver"]=anObject;
  1119. $1=self._assert_equals_(self._interpret_receiver_withArguments_(aString,self["@receiver"],smalltalk.HashedCollection._from_([])),aResult);
  1120. return $1;
  1121. }, function($ctx1) {$ctx1.fill(self,"should:receiver:return:",{aString:aString,anObject:anObject,aResult:aResult},smalltalk.InterpreterTest)})},
  1122. args: ["aString", "anObject", "aResult"],
  1123. source: "should: aString receiver: anObject return: aResult\x0a\x09receiver := anObject.\x0a\x09\x0a\x09^ self \x0a\x09\x09assert: (self interpret: aString receiver: receiver withArguments: #{})\x0a\x09\x09equals: aResult",
  1124. messageSends: ["assert:equals:", "interpret:receiver:withArguments:"],
  1125. referencedClasses: []
  1126. }),
  1127. smalltalk.InterpreterTest);
  1128. smalltalk.addMethod(
  1129. smalltalk.method({
  1130. selector: "should:return:",
  1131. protocol: 'testing',
  1132. fn: function (aString,anObject){
  1133. var self=this;
  1134. return smalltalk.withContext(function($ctx1) {
  1135. var $1;
  1136. $1=self._should_receiver_return_(aString,self["@receiver"],anObject);
  1137. return $1;
  1138. }, function($ctx1) {$ctx1.fill(self,"should:return:",{aString:aString,anObject:anObject},smalltalk.InterpreterTest)})},
  1139. args: ["aString", "anObject"],
  1140. source: "should: aString return: anObject\x0a\x09^ self \x0a\x09\x09should: aString\x0a\x09\x09receiver: receiver\x0a\x09\x09return: anObject",
  1141. messageSends: ["should:receiver:return:"],
  1142. referencedClasses: []
  1143. }),
  1144. smalltalk.InterpreterTest);
  1145. smalltalk.addClass('ScopeVarTest', smalltalk.TestCase, [], 'Compiler-Tests');
  1146. smalltalk.addMethod(
  1147. smalltalk.method({
  1148. selector: "testClassRefVar",
  1149. protocol: 'tests',
  1150. fn: function (){
  1151. var self=this;
  1152. var node;
  1153. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1154. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1155. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1156. return smalltalk.withContext(function($ctx1) {
  1157. var $1,$2,$3,$4;
  1158. $1=_st($VariableNode())._new();
  1159. $ctx1.sendIdx["new"]=1;
  1160. _st($1)._value_("Object");
  1161. $2=_st($1)._yourself();
  1162. node=$2;
  1163. $3=_st($SemanticAnalyzer())._new();
  1164. $ctx1.sendIdx["new"]=2;
  1165. _st($3)._pushScope_(_st($MethodLexicalScope())._new());
  1166. $4=_st($3)._visit_(node);
  1167. self._assert_(_st(_st(node)._binding())._isClassRefVar());
  1168. return self}, function($ctx1) {$ctx1.fill(self,"testClassRefVar",{node:node},smalltalk.ScopeVarTest)})},
  1169. args: [],
  1170. source: "testClassRefVar\x0a\x09| node |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'Object';\x0a\x09\x09yourself.\x0a\x09SemanticAnalyzer new \x0a\x09\x09pushScope: MethodLexicalScope new;\x0a\x09\x09visit: node.\x0a\x09self assert: node binding isClassRefVar",
  1171. messageSends: ["value:", "new", "yourself", "pushScope:", "visit:", "assert:", "isClassRefVar", "binding"],
  1172. referencedClasses: ["VariableNode", "SemanticAnalyzer", "MethodLexicalScope"]
  1173. }),
  1174. smalltalk.ScopeVarTest);
  1175. smalltalk.addMethod(
  1176. smalltalk.method({
  1177. selector: "testInstanceVar",
  1178. protocol: 'tests',
  1179. fn: function (){
  1180. var self=this;
  1181. var node,scope;
  1182. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1183. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1184. return smalltalk.withContext(function($ctx1) {
  1185. var $1,$2;
  1186. $1=_st($VariableNode())._new();
  1187. $ctx1.sendIdx["new"]=1;
  1188. _st($1)._value_("bzzz");
  1189. $2=_st($1)._yourself();
  1190. node=$2;
  1191. scope=_st($MethodLexicalScope())._new();
  1192. _st(scope)._addIVar_("bzzz");
  1193. self._assert_(_st(_st(scope)._bindingFor_(node))._isInstanceVar());
  1194. return self}, function($ctx1) {$ctx1.fill(self,"testInstanceVar",{node:node,scope:scope},smalltalk.ScopeVarTest)})},
  1195. args: [],
  1196. source: "testInstanceVar\x0a\x09| node scope |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09scope := MethodLexicalScope new.\x0a\x09scope addIVar: 'bzzz'.\x0a\x09self assert: (scope bindingFor: node) isInstanceVar",
  1197. messageSends: ["value:", "new", "yourself", "addIVar:", "assert:", "isInstanceVar", "bindingFor:"],
  1198. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1199. }),
  1200. smalltalk.ScopeVarTest);
  1201. smalltalk.addMethod(
  1202. smalltalk.method({
  1203. selector: "testPseudoVar",
  1204. protocol: 'tests',
  1205. fn: function (){
  1206. var self=this;
  1207. var node,pseudoVars;
  1208. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1209. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1210. return smalltalk.withContext(function($ctx1) {
  1211. var $1,$2;
  1212. pseudoVars=["self", "super", "true", "false", "nil"];
  1213. _st(pseudoVars)._do_((function(each){
  1214. return smalltalk.withContext(function($ctx2) {
  1215. $1=_st($VariableNode())._new();
  1216. $ctx2.sendIdx["new"]=1;
  1217. _st($1)._value_(each);
  1218. $2=_st($1)._yourself();
  1219. node=$2;
  1220. node;
  1221. return self._assert_(_st(_st(_st($MethodLexicalScope())._new())._bindingFor_(node))._isPseudoVar());
  1222. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1223. return self}, function($ctx1) {$ctx1.fill(self,"testPseudoVar",{node:node,pseudoVars:pseudoVars},smalltalk.ScopeVarTest)})},
  1224. args: [],
  1225. source: "testPseudoVar\x0a\x09| node pseudoVars |\x0a\x09pseudoVars := #('self' 'super' 'true' 'false' 'nil').\x0a\x09pseudoVars do: [:each |\x0a\x09\x09node := VariableNode new\x0a\x09\x09value: each;\x0a\x09\x09yourself.\x0a\x09\x09self assert: (MethodLexicalScope new bindingFor: node) isPseudoVar ]",
  1226. messageSends: ["do:", "value:", "new", "yourself", "assert:", "isPseudoVar", "bindingFor:"],
  1227. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1228. }),
  1229. smalltalk.ScopeVarTest);
  1230. smalltalk.addMethod(
  1231. smalltalk.method({
  1232. selector: "testTempVar",
  1233. protocol: 'tests',
  1234. fn: function (){
  1235. var self=this;
  1236. var node,scope;
  1237. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1238. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1239. return smalltalk.withContext(function($ctx1) {
  1240. var $1,$2;
  1241. $1=_st($VariableNode())._new();
  1242. $ctx1.sendIdx["new"]=1;
  1243. _st($1)._value_("bzzz");
  1244. $2=_st($1)._yourself();
  1245. node=$2;
  1246. scope=_st($MethodLexicalScope())._new();
  1247. _st(scope)._addTemp_("bzzz");
  1248. self._assert_(_st(_st(scope)._bindingFor_(node))._isTempVar());
  1249. return self}, function($ctx1) {$ctx1.fill(self,"testTempVar",{node:node,scope:scope},smalltalk.ScopeVarTest)})},
  1250. args: [],
  1251. source: "testTempVar\x0a\x09| node scope |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09scope := MethodLexicalScope new.\x0a\x09scope addTemp: 'bzzz'.\x0a\x09self assert: (scope bindingFor: node) isTempVar",
  1252. messageSends: ["value:", "new", "yourself", "addTemp:", "assert:", "isTempVar", "bindingFor:"],
  1253. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1254. }),
  1255. smalltalk.ScopeVarTest);
  1256. smalltalk.addMethod(
  1257. smalltalk.method({
  1258. selector: "testUnknownVar",
  1259. protocol: 'tests',
  1260. fn: function (){
  1261. var self=this;
  1262. var node;
  1263. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1264. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1265. return smalltalk.withContext(function($ctx1) {
  1266. var $1,$2;
  1267. $1=_st($VariableNode())._new();
  1268. $ctx1.sendIdx["new"]=1;
  1269. _st($1)._value_("bzzz");
  1270. $2=_st($1)._yourself();
  1271. node=$2;
  1272. self._assert_(_st(_st(_st($MethodLexicalScope())._new())._bindingFor_(node))._isNil());
  1273. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVar",{node:node},smalltalk.ScopeVarTest)})},
  1274. args: [],
  1275. source: "testUnknownVar\x0a\x09| node |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09self assert: (MethodLexicalScope new bindingFor: node) isNil",
  1276. messageSends: ["value:", "new", "yourself", "assert:", "isNil", "bindingFor:"],
  1277. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1278. }),
  1279. smalltalk.ScopeVarTest);
  1280. smalltalk.addClass('SemanticAnalyzerTest', smalltalk.TestCase, ['analyzer'], 'Compiler-Tests');
  1281. smalltalk.addMethod(
  1282. smalltalk.method({
  1283. selector: "setUp",
  1284. protocol: 'running',
  1285. fn: function (){
  1286. var self=this;
  1287. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1288. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  1289. return smalltalk.withContext(function($ctx1) {
  1290. self["@analyzer"]=_st($SemanticAnalyzer())._on_($Object());
  1291. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},smalltalk.SemanticAnalyzerTest)})},
  1292. args: [],
  1293. source: "setUp\x0a\x09analyzer := SemanticAnalyzer on: Object",
  1294. messageSends: ["on:"],
  1295. referencedClasses: ["SemanticAnalyzer", "Object"]
  1296. }),
  1297. smalltalk.SemanticAnalyzerTest);
  1298. smalltalk.addMethod(
  1299. smalltalk.method({
  1300. selector: "testAssignment",
  1301. protocol: 'tests',
  1302. fn: function (){
  1303. var self=this;
  1304. var src,ast;
  1305. function $InvalidAssignmentError(){return smalltalk.InvalidAssignmentError||(typeof InvalidAssignmentError=="undefined"?nil:InvalidAssignmentError)}
  1306. return smalltalk.withContext(function($ctx1) {
  1307. src="foo self := 1";
  1308. ast=_st(smalltalk)._parse_(src);
  1309. self._should_raise_((function(){
  1310. return smalltalk.withContext(function($ctx2) {
  1311. return _st(self["@analyzer"])._visit_(ast);
  1312. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$InvalidAssignmentError());
  1313. return self}, function($ctx1) {$ctx1.fill(self,"testAssignment",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1314. args: [],
  1315. source: "testAssignment\x0a\x09| src ast |\x0a\x0a\x09src := 'foo self := 1'.\x0a\x09ast := smalltalk parse: src.\x0a\x09self should: [analyzer visit: ast] raise: InvalidAssignmentError",
  1316. messageSends: ["parse:", "should:raise:", "visit:"],
  1317. referencedClasses: ["InvalidAssignmentError"]
  1318. }),
  1319. smalltalk.SemanticAnalyzerTest);
  1320. smalltalk.addMethod(
  1321. smalltalk.method({
  1322. selector: "testNonLocalReturn",
  1323. protocol: 'tests',
  1324. fn: function (){
  1325. var self=this;
  1326. var src,ast;
  1327. return smalltalk.withContext(function($ctx1) {
  1328. src="foo | a | a + 1. ^ a";
  1329. ast=_st(smalltalk)._parse_(src);
  1330. _st(self["@analyzer"])._visit_(ast);
  1331. self._deny_(_st(_st(ast)._scope())._hasNonLocalReturn());
  1332. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1333. args: [],
  1334. source: "testNonLocalReturn\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. ^ a'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self deny: ast scope hasNonLocalReturn",
  1335. messageSends: ["parse:", "visit:", "deny:", "hasNonLocalReturn", "scope"],
  1336. referencedClasses: []
  1337. }),
  1338. smalltalk.SemanticAnalyzerTest);
  1339. smalltalk.addMethod(
  1340. smalltalk.method({
  1341. selector: "testNonLocalReturn2",
  1342. protocol: 'tests',
  1343. fn: function (){
  1344. var self=this;
  1345. var src,ast;
  1346. return smalltalk.withContext(function($ctx1) {
  1347. src="foo | a | a + 1. [ [ ^ a] ]";
  1348. ast=_st(smalltalk)._parse_(src);
  1349. _st(self["@analyzer"])._visit_(ast);
  1350. self._assert_(_st(_st(ast)._scope())._hasNonLocalReturn());
  1351. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1352. args: [],
  1353. source: "testNonLocalReturn2\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ [ ^ a] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self assert: ast scope hasNonLocalReturn",
  1354. messageSends: ["parse:", "visit:", "assert:", "hasNonLocalReturn", "scope"],
  1355. referencedClasses: []
  1356. }),
  1357. smalltalk.SemanticAnalyzerTest);
  1358. smalltalk.addMethod(
  1359. smalltalk.method({
  1360. selector: "testScope",
  1361. protocol: 'tests',
  1362. fn: function (){
  1363. var self=this;
  1364. var src,ast;
  1365. return smalltalk.withContext(function($ctx1) {
  1366. var $4,$3,$2,$1;
  1367. src="foo | a | a + 1. [ | b | b := a ]";
  1368. ast=_st(smalltalk)._parse_(src);
  1369. _st(self["@analyzer"])._visit_(ast);
  1370. $4=_st(_st(_st(ast)._nodes())._first())._nodes();
  1371. $ctx1.sendIdx["nodes"]=1;
  1372. $3=_st($4)._last();
  1373. $2=_st($3)._scope();
  1374. $ctx1.sendIdx["scope"]=1;
  1375. $1=_st($2).__eq_eq(_st(ast)._scope());
  1376. self._deny_($1);
  1377. return self}, function($ctx1) {$ctx1.fill(self,"testScope",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1378. args: [],
  1379. source: "testScope\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ | b | b := a ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self deny: ast nodes first nodes last scope == ast scope.",
  1380. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "last", "nodes", "first"],
  1381. referencedClasses: []
  1382. }),
  1383. smalltalk.SemanticAnalyzerTest);
  1384. smalltalk.addMethod(
  1385. smalltalk.method({
  1386. selector: "testScope2",
  1387. protocol: 'tests',
  1388. fn: function (){
  1389. var self=this;
  1390. var src,ast;
  1391. return smalltalk.withContext(function($ctx1) {
  1392. var $8,$7,$6,$5,$4,$3,$2,$1;
  1393. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1394. ast=_st(smalltalk)._parse_(src);
  1395. _st(self["@analyzer"])._visit_(ast);
  1396. $8=_st(_st(_st(ast)._nodes())._first())._nodes();
  1397. $ctx1.sendIdx["nodes"]=3;
  1398. $7=_st($8)._last();
  1399. $6=_st($7)._nodes();
  1400. $ctx1.sendIdx["nodes"]=2;
  1401. $5=_st($6)._first();
  1402. $ctx1.sendIdx["first"]=2;
  1403. $4=_st($5)._nodes();
  1404. $ctx1.sendIdx["nodes"]=1;
  1405. $3=_st($4)._first();
  1406. $ctx1.sendIdx["first"]=1;
  1407. $2=_st($3)._scope();
  1408. $ctx1.sendIdx["scope"]=1;
  1409. $1=_st($2).__eq_eq(_st(ast)._scope());
  1410. self._deny_($1);
  1411. return self}, function($ctx1) {$ctx1.fill(self,"testScope2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1412. args: [],
  1413. source: "testScope2\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ [ | b | b := a ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self deny: ast nodes first nodes last nodes first nodes first scope == ast scope.",
  1414. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "first", "nodes", "last"],
  1415. referencedClasses: []
  1416. }),
  1417. smalltalk.SemanticAnalyzerTest);
  1418. smalltalk.addMethod(
  1419. smalltalk.method({
  1420. selector: "testScopeLevel",
  1421. protocol: 'tests',
  1422. fn: function (){
  1423. var self=this;
  1424. var src,ast;
  1425. return smalltalk.withContext(function($ctx1) {
  1426. var $2,$1,$10,$9,$8,$7,$6,$5,$4,$3;
  1427. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1428. ast=_st(smalltalk)._parse_(src);
  1429. _st(self["@analyzer"])._visit_(ast);
  1430. $2=_st(ast)._scope();
  1431. $ctx1.sendIdx["scope"]=1;
  1432. $1=_st($2)._scopeLevel();
  1433. $ctx1.sendIdx["scopeLevel"]=1;
  1434. self._assert_equals_($1,(1));
  1435. $ctx1.sendIdx["assert:equals:"]=1;
  1436. $10=_st(_st(_st(ast)._nodes())._first())._nodes();
  1437. $ctx1.sendIdx["nodes"]=3;
  1438. $9=_st($10)._last();
  1439. $8=_st($9)._nodes();
  1440. $ctx1.sendIdx["nodes"]=2;
  1441. $7=_st($8)._first();
  1442. $ctx1.sendIdx["first"]=2;
  1443. $6=_st($7)._nodes();
  1444. $ctx1.sendIdx["nodes"]=1;
  1445. $5=_st($6)._first();
  1446. $ctx1.sendIdx["first"]=1;
  1447. $4=_st($5)._scope();
  1448. $3=_st($4)._scopeLevel();
  1449. self._assert_equals_($3,(3));
  1450. return self}, function($ctx1) {$ctx1.fill(self,"testScopeLevel",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1451. args: [],
  1452. source: "testScopeLevel\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ [ | b | b := a ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self assert: ast scope scopeLevel equals: 1.\x0a\x09self assert: ast nodes first nodes last nodes first nodes first scope scopeLevel equals: 3",
  1453. messageSends: ["parse:", "visit:", "assert:equals:", "scopeLevel", "scope", "first", "nodes", "last"],
  1454. referencedClasses: []
  1455. }),
  1456. smalltalk.SemanticAnalyzerTest);
  1457. smalltalk.addMethod(
  1458. smalltalk.method({
  1459. selector: "testUnknownVariables",
  1460. protocol: 'tests',
  1461. fn: function (){
  1462. var self=this;
  1463. var src,ast;
  1464. function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1465. return smalltalk.withContext(function($ctx1) {
  1466. src="foo | a | b + a";
  1467. ast=_st(smalltalk)._parse_(src);
  1468. self._should_raise_((function(){
  1469. return smalltalk.withContext(function($ctx2) {
  1470. return _st(self["@analyzer"])._visit_(ast);
  1471. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$UnknownVariableError());
  1472. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariables",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1473. args: [],
  1474. source: "testUnknownVariables\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | b + a'.\x0a\x09ast := smalltalk parse: src.\x0a\x0a\x09self should: [ analyzer visit: ast ] raise: UnknownVariableError",
  1475. messageSends: ["parse:", "should:raise:", "visit:"],
  1476. referencedClasses: ["UnknownVariableError"]
  1477. }),
  1478. smalltalk.SemanticAnalyzerTest);
  1479. smalltalk.addMethod(
  1480. smalltalk.method({
  1481. selector: "testUnknownVariablesWithScope",
  1482. protocol: 'tests',
  1483. fn: function (){
  1484. var self=this;
  1485. var src,ast;
  1486. function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1487. return smalltalk.withContext(function($ctx1) {
  1488. src="foo | a b | [ c + 1. [ a + 1. d + 1 ]]";
  1489. ast=_st(smalltalk)._parse_(src);
  1490. self._should_raise_((function(){
  1491. return smalltalk.withContext(function($ctx2) {
  1492. return _st(self["@analyzer"])._visit_(ast);
  1493. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$UnknownVariableError());
  1494. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariablesWithScope",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1495. args: [],
  1496. source: "testUnknownVariablesWithScope\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a b | [ c + 1. [ a + 1. d + 1 ]]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09\x0a\x09self should: [ analyzer visit: ast ] raise: UnknownVariableError",
  1497. messageSends: ["parse:", "should:raise:", "visit:"],
  1498. referencedClasses: ["UnknownVariableError"]
  1499. }),
  1500. smalltalk.SemanticAnalyzerTest);
  1501. smalltalk.addMethod(
  1502. smalltalk.method({
  1503. selector: "testVariableShadowing",
  1504. protocol: 'tests',
  1505. fn: function (){
  1506. var self=this;
  1507. var src,ast;
  1508. return smalltalk.withContext(function($ctx1) {
  1509. src="foo | a | a + 1";
  1510. ast=_st(smalltalk)._parse_(src);
  1511. _st(self["@analyzer"])._visit_(ast);
  1512. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1513. args: [],
  1514. source: "testVariableShadowing\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1515. messageSends: ["parse:", "visit:"],
  1516. referencedClasses: []
  1517. }),
  1518. smalltalk.SemanticAnalyzerTest);
  1519. smalltalk.addMethod(
  1520. smalltalk.method({
  1521. selector: "testVariableShadowing2",
  1522. protocol: 'tests',
  1523. fn: function (){
  1524. var self=this;
  1525. var src,ast;
  1526. function $ShadowingVariableError(){return smalltalk.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1527. return smalltalk.withContext(function($ctx1) {
  1528. src="foo | a | a + 1. [ | a | a := 2 ]";
  1529. ast=_st(smalltalk)._parse_(src);
  1530. self._should_raise_((function(){
  1531. return smalltalk.withContext(function($ctx2) {
  1532. return _st(self["@analyzer"])._visit_(ast);
  1533. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$ShadowingVariableError());
  1534. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1535. args: [],
  1536. source: "testVariableShadowing2\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | a | a := 2 ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09self should: [analyzer visit: ast] raise: ShadowingVariableError",
  1537. messageSends: ["parse:", "should:raise:", "visit:"],
  1538. referencedClasses: ["ShadowingVariableError"]
  1539. }),
  1540. smalltalk.SemanticAnalyzerTest);
  1541. smalltalk.addMethod(
  1542. smalltalk.method({
  1543. selector: "testVariableShadowing3",
  1544. protocol: 'tests',
  1545. fn: function (){
  1546. var self=this;
  1547. var src,ast;
  1548. return smalltalk.withContext(function($ctx1) {
  1549. src="foo | a | a + 1. [ | b | b := 2 ]";
  1550. ast=_st(smalltalk)._parse_(src);
  1551. _st(self["@analyzer"])._visit_(ast);
  1552. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing3",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1553. args: [],
  1554. source: "testVariableShadowing3\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | b | b := 2 ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1555. messageSends: ["parse:", "visit:"],
  1556. referencedClasses: []
  1557. }),
  1558. smalltalk.SemanticAnalyzerTest);
  1559. smalltalk.addMethod(
  1560. smalltalk.method({
  1561. selector: "testVariableShadowing4",
  1562. protocol: 'tests',
  1563. fn: function (){
  1564. var self=this;
  1565. var src,ast;
  1566. return smalltalk.withContext(function($ctx1) {
  1567. src="foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]";
  1568. ast=_st(smalltalk)._parse_(src);
  1569. _st(self["@analyzer"])._visit_(ast);
  1570. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing4",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1571. args: [],
  1572. source: "testVariableShadowing4\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1573. messageSends: ["parse:", "visit:"],
  1574. referencedClasses: []
  1575. }),
  1576. smalltalk.SemanticAnalyzerTest);
  1577. smalltalk.addMethod(
  1578. smalltalk.method({
  1579. selector: "testVariableShadowing5",
  1580. protocol: 'tests',
  1581. fn: function (){
  1582. var self=this;
  1583. var src,ast;
  1584. function $ShadowingVariableError(){return smalltalk.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1585. return smalltalk.withContext(function($ctx1) {
  1586. src="foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]";
  1587. ast=_st(smalltalk)._parse_(src);
  1588. self._should_raise_((function(){
  1589. return smalltalk.withContext(function($ctx2) {
  1590. return _st(self["@analyzer"])._visit_(ast);
  1591. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$ShadowingVariableError());
  1592. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing5",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1593. args: [],
  1594. source: "testVariableShadowing5\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09self should: [analyzer visit: ast] raise: ShadowingVariableError",
  1595. messageSends: ["parse:", "should:raise:", "visit:"],
  1596. referencedClasses: ["ShadowingVariableError"]
  1597. }),
  1598. smalltalk.SemanticAnalyzerTest);
  1599. smalltalk.addMethod(
  1600. smalltalk.method({
  1601. selector: "testVariablesLookup",
  1602. protocol: 'tests',
  1603. fn: function (){
  1604. var self=this;
  1605. var src,ast;
  1606. return smalltalk.withContext(function($ctx1) {
  1607. var $7,$6,$5,$4,$3,$2,$1,$15,$14,$13,$12,$11,$10,$9,$16,$8,$27,$26,$25,$24,$23,$22,$21,$20,$19,$18,$17,$39,$38,$37,$36,$35,$34,$33,$32,$31,$30,$29,$42,$41,$40,$28;
  1608. src="foo | a | a + 1. [ | b | b := a ]";
  1609. ast=_st(smalltalk)._parse_(src);
  1610. _st(self["@analyzer"])._visit_(ast);
  1611. $7=_st(ast)._nodes();
  1612. $ctx1.sendIdx["nodes"]=2;
  1613. $6=_st($7)._first();
  1614. $ctx1.sendIdx["first"]=2;
  1615. $5=_st($6)._nodes();
  1616. $ctx1.sendIdx["nodes"]=1;
  1617. $4=_st($5)._first();
  1618. $ctx1.sendIdx["first"]=1;
  1619. $3=_st($4)._receiver();
  1620. $ctx1.sendIdx["receiver"]=1;
  1621. $2=_st($3)._binding();
  1622. $ctx1.sendIdx["binding"]=1;
  1623. $1=_st($2)._isTempVar();
  1624. $ctx1.sendIdx["isTempVar"]=1;
  1625. self._assert_($1);
  1626. $ctx1.sendIdx["assert:"]=1;
  1627. $15=_st(ast)._nodes();
  1628. $ctx1.sendIdx["nodes"]=4;
  1629. $14=_st($15)._first();
  1630. $ctx1.sendIdx["first"]=4;
  1631. $13=_st($14)._nodes();
  1632. $ctx1.sendIdx["nodes"]=3;
  1633. $12=_st($13)._first();
  1634. $ctx1.sendIdx["first"]=3;
  1635. $11=_st($12)._receiver();
  1636. $10=_st($11)._binding();
  1637. $ctx1.sendIdx["binding"]=2;
  1638. $9=_st($10)._scope();
  1639. $ctx1.sendIdx["scope"]=1;
  1640. $16=_st(ast)._scope();
  1641. $ctx1.sendIdx["scope"]=2;
  1642. $8=_st($9).__eq_eq($16);
  1643. $ctx1.sendIdx["=="]=1;
  1644. self._assert_($8);
  1645. $ctx1.sendIdx["assert:"]=2;
  1646. $27=_st(ast)._nodes();
  1647. $ctx1.sendIdx["nodes"]=8;
  1648. $26=_st($27)._first();
  1649. $ctx1.sendIdx["first"]=7;
  1650. $25=_st($26)._nodes();
  1651. $ctx1.sendIdx["nodes"]=7;
  1652. $24=_st($25)._last();
  1653. $ctx1.sendIdx["last"]=1;
  1654. $23=_st($24)._nodes();
  1655. $ctx1.sendIdx["nodes"]=6;
  1656. $22=_st($23)._first();
  1657. $ctx1.sendIdx["first"]=6;
  1658. $21=_st($22)._nodes();
  1659. $ctx1.sendIdx["nodes"]=5;
  1660. $20=_st($21)._first();
  1661. $ctx1.sendIdx["first"]=5;
  1662. $19=_st($20)._left();
  1663. $ctx1.sendIdx["left"]=1;
  1664. $18=_st($19)._binding();
  1665. $ctx1.sendIdx["binding"]=3;
  1666. $17=_st($18)._isTempVar();
  1667. self._assert_($17);
  1668. $ctx1.sendIdx["assert:"]=3;
  1669. $39=_st(ast)._nodes();
  1670. $ctx1.sendIdx["nodes"]=12;
  1671. $38=_st($39)._first();
  1672. $ctx1.sendIdx["first"]=10;
  1673. $37=_st($38)._nodes();
  1674. $ctx1.sendIdx["nodes"]=11;
  1675. $36=_st($37)._last();
  1676. $ctx1.sendIdx["last"]=2;
  1677. $35=_st($36)._nodes();
  1678. $ctx1.sendIdx["nodes"]=10;
  1679. $34=_st($35)._first();
  1680. $ctx1.sendIdx["first"]=9;
  1681. $33=_st($34)._nodes();
  1682. $ctx1.sendIdx["nodes"]=9;
  1683. $32=_st($33)._first();
  1684. $ctx1.sendIdx["first"]=8;
  1685. $31=_st($32)._left();
  1686. $30=_st($31)._binding();
  1687. $29=_st($30)._scope();
  1688. $ctx1.sendIdx["scope"]=3;
  1689. $42=_st(_st(_st(ast)._nodes())._first())._nodes();
  1690. $ctx1.sendIdx["nodes"]=13;
  1691. $41=_st($42)._last();
  1692. $40=_st($41)._scope();
  1693. $28=_st($29).__eq_eq($40);
  1694. self._assert_($28);
  1695. return self}, function($ctx1) {$ctx1.fill(self,"testVariablesLookup",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1696. args: [],
  1697. source: "testVariablesLookup\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ | b | b := a ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09\x22Binding for `a` in the message send\x22\x0a\x09self assert: ast nodes first nodes first receiver binding isTempVar.\x0a\x09self assert: ast nodes first nodes first receiver binding scope == ast scope.\x0a\x0a\x09\x22Binding for `b`\x22\x0a\x09self assert: ast nodes first nodes last nodes first nodes first left binding isTempVar.\x0a\x09self assert: ast nodes first nodes last nodes first nodes first left binding scope == ast nodes first nodes last scope.",
  1698. messageSends: ["parse:", "visit:", "assert:", "isTempVar", "binding", "receiver", "first", "nodes", "==", "scope", "left", "last"],
  1699. referencedClasses: []
  1700. }),
  1701. smalltalk.SemanticAnalyzerTest);
  1702. });