2
0

Compiler-Tests.js 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806
  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. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  749. return smalltalk.withContext(function($ctx1) {
  750. self._should_return_("foo ^Object",_st(_st($Smalltalk())._current())._at_("Object"));
  751. $ctx1.sendIdx["should:return:"]=1;
  752. self._should_return_("foo ^NonExistent",nil);
  753. return self}, function($ctx1) {$ctx1.fill(self,"testPascalCaseGlobal",{},smalltalk.CodeGeneratorTest)})},
  754. args: [],
  755. source: "testPascalCaseGlobal\x0a\x09self should: 'foo ^Object' return: (Smalltalk current at: 'Object').\x0a\x09self should: 'foo ^NonExistent' return: nil",
  756. messageSends: ["should:return:", "at:", "current"],
  757. referencedClasses: ["Smalltalk"]
  758. }),
  759. smalltalk.CodeGeneratorTest);
  760. smalltalk.addMethod(
  761. smalltalk.method({
  762. selector: "testSendReceiverAndArgumentsOrdered",
  763. protocol: 'tests',
  764. fn: function (){
  765. var self=this;
  766. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  767. return smalltalk.withContext(function($ctx1) {
  768. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ Array with: x with: (true ifTrue: [ x := 2 ])\x0a",[(1), (2)]);
  769. $ctx1.sendIdx["should:return:"]=1;
  770. self._should_return_("foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: x with: (true ifTrue: [ x := 2 ])\x0a",[$Array(),(2)]);
  771. return self}, function($ctx1) {$ctx1.fill(self,"testSendReceiverAndArgumentsOrdered",{},smalltalk.CodeGeneratorTest)})},
  772. args: [],
  773. 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}.",
  774. messageSends: ["should:return:"],
  775. referencedClasses: ["Array"]
  776. }),
  777. smalltalk.CodeGeneratorTest);
  778. smalltalk.addMethod(
  779. smalltalk.method({
  780. selector: "testSuperSend",
  781. protocol: 'tests',
  782. fn: function (){
  783. var self=this;
  784. return smalltalk.withContext(function($ctx1) {
  785. self._should_receiver_return_("foo ^ super isBoolean",true,false);
  786. return self}, function($ctx1) {$ctx1.fill(self,"testSuperSend",{},smalltalk.CodeGeneratorTest)})},
  787. args: [],
  788. source: "testSuperSend\x0a\x09self \x0a\x09\x09should: 'foo ^ super isBoolean' \x0a\x09\x09receiver: true\x0a\x09\x09return: false",
  789. messageSends: ["should:receiver:return:"],
  790. referencedClasses: []
  791. }),
  792. smalltalk.CodeGeneratorTest);
  793. smalltalk.addMethod(
  794. smalltalk.method({
  795. selector: "testTempVariables",
  796. protocol: 'tests',
  797. fn: function (){
  798. var self=this;
  799. return smalltalk.withContext(function($ctx1) {
  800. self._should_return_("foo | a | ^ a",nil);
  801. $ctx1.sendIdx["should:return:"]=1;
  802. self._should_return_("foo | AVariable | ^ AVariable",nil);
  803. $ctx1.sendIdx["should:return:"]=2;
  804. self._should_return_("foo | a b c | ^ c",nil);
  805. $ctx1.sendIdx["should:return:"]=3;
  806. self._should_return_("foo | a | [ | d | ^ d ] value",nil);
  807. $ctx1.sendIdx["should:return:"]=4;
  808. self._should_return_("foo | a | a:= 1. ^ a",(1));
  809. $ctx1.sendIdx["should:return:"]=5;
  810. self._should_return_("foo | AVariable | AVariable := 1. ^ AVariable",(1));
  811. return self}, function($ctx1) {$ctx1.fill(self,"testTempVariables",{},smalltalk.CodeGeneratorTest)})},
  812. args: [],
  813. 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.",
  814. messageSends: ["should:return:"],
  815. referencedClasses: []
  816. }),
  817. smalltalk.CodeGeneratorTest);
  818. smalltalk.addMethod(
  819. smalltalk.method({
  820. selector: "testThisContext",
  821. protocol: 'tests',
  822. fn: function (){
  823. var self=this;
  824. return smalltalk.withContext(function($ctx1) {
  825. self._should_return_("foo ^ [ thisContext ] value outerContext == thisContext",true);
  826. return self}, function($ctx1) {$ctx1.fill(self,"testThisContext",{},smalltalk.CodeGeneratorTest)})},
  827. args: [],
  828. source: "testThisContext\x0a\x09self should: 'foo ^ [ thisContext ] value outerContext == thisContext' return: true",
  829. messageSends: ["should:return:"],
  830. referencedClasses: []
  831. }),
  832. smalltalk.CodeGeneratorTest);
  833. smalltalk.addMethod(
  834. smalltalk.method({
  835. selector: "testifFalse",
  836. protocol: 'tests',
  837. fn: function (){
  838. var self=this;
  839. return smalltalk.withContext(function($ctx1) {
  840. self._should_return_("foo true ifFalse: [ ^ 1 ]",self["@receiver"]);
  841. $ctx1.sendIdx["should:return:"]=1;
  842. self._should_return_("foo false ifFalse: [ ^ 2 ]",(2));
  843. $ctx1.sendIdx["should:return:"]=2;
  844. self._should_return_("foo ^ true ifFalse: [ 1 ]",nil);
  845. $ctx1.sendIdx["should:return:"]=3;
  846. self._should_return_("foo ^ false ifFalse: [ 2 ]",(2));
  847. return self}, function($ctx1) {$ctx1.fill(self,"testifFalse",{},smalltalk.CodeGeneratorTest)})},
  848. args: [],
  849. 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.",
  850. messageSends: ["should:return:"],
  851. referencedClasses: []
  852. }),
  853. smalltalk.CodeGeneratorTest);
  854. smalltalk.addMethod(
  855. smalltalk.method({
  856. selector: "testifFalseIfTrue",
  857. protocol: 'tests',
  858. fn: function (){
  859. var self=this;
  860. return smalltalk.withContext(function($ctx1) {
  861. self._should_return_("foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]",(2));
  862. $ctx1.sendIdx["should:return:"]=1;
  863. self._should_return_("foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]",(2));
  864. $ctx1.sendIdx["should:return:"]=2;
  865. self._should_return_("foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]",(2));
  866. $ctx1.sendIdx["should:return:"]=3;
  867. self._should_return_("foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]",(2));
  868. return self}, function($ctx1) {$ctx1.fill(self,"testifFalseIfTrue",{},smalltalk.CodeGeneratorTest)})},
  869. args: [],
  870. 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.",
  871. messageSends: ["should:return:"],
  872. referencedClasses: []
  873. }),
  874. smalltalk.CodeGeneratorTest);
  875. smalltalk.addMethod(
  876. smalltalk.method({
  877. selector: "testifNil",
  878. protocol: 'tests',
  879. fn: function (){
  880. var self=this;
  881. return smalltalk.withContext(function($ctx1) {
  882. self._should_return_("foo ^ 1 ifNil: [ 2 ]",(1));
  883. $ctx1.sendIdx["should:return:"]=1;
  884. self._should_return_("foo ^ nil ifNil: [ 2 ]",(2));
  885. $ctx1.sendIdx["should:return:"]=2;
  886. self._should_return_("foo 1 ifNil: [ ^ 2 ]",self["@receiver"]);
  887. $ctx1.sendIdx["should:return:"]=3;
  888. self._should_return_("foo nil ifNil: [ ^ 2 ]",(2));
  889. return self}, function($ctx1) {$ctx1.fill(self,"testifNil",{},smalltalk.CodeGeneratorTest)})},
  890. args: [],
  891. 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.",
  892. messageSends: ["should:return:"],
  893. referencedClasses: []
  894. }),
  895. smalltalk.CodeGeneratorTest);
  896. smalltalk.addMethod(
  897. smalltalk.method({
  898. selector: "testifNilIfNotNil",
  899. protocol: 'tests',
  900. fn: function (){
  901. var self=this;
  902. return smalltalk.withContext(function($ctx1) {
  903. self._should_return_("foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]",(3));
  904. $ctx1.sendIdx["should:return:"]=1;
  905. self._should_return_("foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]",(2));
  906. $ctx1.sendIdx["should:return:"]=2;
  907. self._should_return_("foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(3));
  908. $ctx1.sendIdx["should:return:"]=3;
  909. self._should_return_("foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(2));
  910. return self}, function($ctx1) {$ctx1.fill(self,"testifNilIfNotNil",{},smalltalk.CodeGeneratorTest)})},
  911. args: [],
  912. 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.",
  913. messageSends: ["should:return:"],
  914. referencedClasses: []
  915. }),
  916. smalltalk.CodeGeneratorTest);
  917. smalltalk.addMethod(
  918. smalltalk.method({
  919. selector: "testifNotNil",
  920. protocol: 'tests',
  921. fn: function (){
  922. var self=this;
  923. return smalltalk.withContext(function($ctx1) {
  924. self._should_return_("foo ^ 1 ifNotNil: [ 2 ]",(2));
  925. $ctx1.sendIdx["should:return:"]=1;
  926. self._should_return_("foo ^ nil ifNotNil: [ 2 ]",nil);
  927. $ctx1.sendIdx["should:return:"]=2;
  928. self._should_return_("foo 1 ifNotNil: [ ^ 2 ]",(2));
  929. $ctx1.sendIdx["should:return:"]=3;
  930. self._should_return_("foo nil ifNotNil: [ ^ 2 ]",self["@receiver"]);
  931. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNil",{},smalltalk.CodeGeneratorTest)})},
  932. args: [],
  933. 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.",
  934. messageSends: ["should:return:"],
  935. referencedClasses: []
  936. }),
  937. smalltalk.CodeGeneratorTest);
  938. smalltalk.addMethod(
  939. smalltalk.method({
  940. selector: "testifNotNilWithArgument",
  941. protocol: 'tests',
  942. fn: function (){
  943. var self=this;
  944. return smalltalk.withContext(function($ctx1) {
  945. self._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ]",(3));
  946. $ctx1.sendIdx["should:return:"]=1;
  947. self._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ]",nil);
  948. $ctx1.sendIdx["should:return:"]=2;
  949. self._should_return_("foo ^ 1 ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(3));
  950. $ctx1.sendIdx["should:return:"]=3;
  951. self._should_return_("foo ^ nil ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(5));
  952. $ctx1.sendIdx["should:return:"]=4;
  953. self._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(3));
  954. $ctx1.sendIdx["should:return:"]=5;
  955. self._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(5));
  956. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNilWithArgument",{},smalltalk.CodeGeneratorTest)})},
  957. args: [],
  958. 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",
  959. messageSends: ["should:return:"],
  960. referencedClasses: []
  961. }),
  962. smalltalk.CodeGeneratorTest);
  963. smalltalk.addMethod(
  964. smalltalk.method({
  965. selector: "testifTrue",
  966. protocol: 'tests',
  967. fn: function (){
  968. var self=this;
  969. return smalltalk.withContext(function($ctx1) {
  970. self._should_return_("foo false ifTrue: [ ^ 1 ]",self["@receiver"]);
  971. $ctx1.sendIdx["should:return:"]=1;
  972. self._should_return_("foo true ifTrue: [ ^ 2 ]",(2));
  973. $ctx1.sendIdx["should:return:"]=2;
  974. self._should_return_("foo ^ false ifTrue: [ 1 ]",nil);
  975. $ctx1.sendIdx["should:return:"]=3;
  976. self._should_return_("foo ^ true ifTrue: [ 2 ]",(2));
  977. return self}, function($ctx1) {$ctx1.fill(self,"testifTrue",{},smalltalk.CodeGeneratorTest)})},
  978. args: [],
  979. 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.",
  980. messageSends: ["should:return:"],
  981. referencedClasses: []
  982. }),
  983. smalltalk.CodeGeneratorTest);
  984. smalltalk.addMethod(
  985. smalltalk.method({
  986. selector: "testifTrueIfFalse",
  987. protocol: 'tests',
  988. fn: function (){
  989. var self=this;
  990. return smalltalk.withContext(function($ctx1) {
  991. self._should_return_("foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]",(2));
  992. $ctx1.sendIdx["should:return:"]=1;
  993. self._should_return_("foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]",(1));
  994. $ctx1.sendIdx["should:return:"]=2;
  995. self._should_return_("foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]",(1));
  996. $ctx1.sendIdx["should:return:"]=3;
  997. self._should_return_("foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]",(2));
  998. return self}, function($ctx1) {$ctx1.fill(self,"testifTrueIfFalse",{},smalltalk.CodeGeneratorTest)})},
  999. args: [],
  1000. 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.",
  1001. messageSends: ["should:return:"],
  1002. referencedClasses: []
  1003. }),
  1004. smalltalk.CodeGeneratorTest);
  1005. smalltalk.addClass('InliningCodeGeneratorTest', smalltalk.CodeGeneratorTest, [], 'Compiler-Tests');
  1006. smalltalk.addMethod(
  1007. smalltalk.method({
  1008. selector: "codeGeneratorClass",
  1009. protocol: 'accessing',
  1010. fn: function (){
  1011. var self=this;
  1012. function $InliningCodeGenerator(){return smalltalk.InliningCodeGenerator||(typeof InliningCodeGenerator=="undefined"?nil:InliningCodeGenerator)}
  1013. return smalltalk.withContext(function($ctx1) {
  1014. return $InliningCodeGenerator();
  1015. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{},smalltalk.InliningCodeGeneratorTest)})},
  1016. args: [],
  1017. source: "codeGeneratorClass\x0a\x09^ InliningCodeGenerator",
  1018. messageSends: [],
  1019. referencedClasses: ["InliningCodeGenerator"]
  1020. }),
  1021. smalltalk.InliningCodeGeneratorTest);
  1022. smalltalk.addClass('InterpreterTest', smalltalk.CodeGeneratorTest, [], 'Compiler-Tests');
  1023. smalltalk.addMethod(
  1024. smalltalk.method({
  1025. selector: "analyze:forClass:",
  1026. protocol: 'parsing',
  1027. fn: function (aNode,aClass){
  1028. var self=this;
  1029. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1030. return smalltalk.withContext(function($ctx1) {
  1031. _st(_st($SemanticAnalyzer())._on_(aClass))._visit_(aNode);
  1032. return aNode;
  1033. }, function($ctx1) {$ctx1.fill(self,"analyze:forClass:",{aNode:aNode,aClass:aClass},smalltalk.InterpreterTest)})},
  1034. args: ["aNode", "aClass"],
  1035. source: "analyze: aNode forClass: aClass\x0a\x09(SemanticAnalyzer on: aClass) visit: aNode.\x0a\x09^ aNode",
  1036. messageSends: ["visit:", "on:"],
  1037. referencedClasses: ["SemanticAnalyzer"]
  1038. }),
  1039. smalltalk.InterpreterTest);
  1040. smalltalk.addMethod(
  1041. smalltalk.method({
  1042. selector: "interpret:receiver:withArguments:",
  1043. protocol: 'private',
  1044. fn: function (aString,anObject,aDictionary){
  1045. var self=this;
  1046. var ctx,interpreter;
  1047. function $ASTInterpreter(){return smalltalk.ASTInterpreter||(typeof ASTInterpreter=="undefined"?nil:ASTInterpreter)}
  1048. function $AIContext(){return smalltalk.AIContext||(typeof AIContext=="undefined"?nil:AIContext)}
  1049. return smalltalk.withContext(function($ctx1) {
  1050. var $1,$2,$4,$5,$3;
  1051. interpreter=_st($ASTInterpreter())._new();
  1052. $ctx1.sendIdx["new"]=1;
  1053. $1=_st($AIContext())._new();
  1054. _st($1)._receiver_(anObject);
  1055. _st($1)._interpreter_(interpreter);
  1056. $2=_st($1)._yourself();
  1057. ctx=$2;
  1058. _st(aDictionary)._keysAndValuesDo_((function(key,value){
  1059. return smalltalk.withContext(function($ctx2) {
  1060. return _st(ctx)._localAt_put_(key,value);
  1061. }, function($ctx2) {$ctx2.fillBlock({key:key,value:value},$ctx1,1)})}));
  1062. $4=interpreter;
  1063. _st($4)._context_(ctx);
  1064. _st($4)._interpret_(_st(self._parse_forClass_(aString,_st(anObject)._class()))._nextChild());
  1065. _st($4)._proceed();
  1066. $5=_st($4)._result();
  1067. $3=$5;
  1068. return $3;
  1069. }, function($ctx1) {$ctx1.fill(self,"interpret:receiver:withArguments:",{aString:aString,anObject:anObject,aDictionary:aDictionary,ctx:ctx,interpreter:interpreter},smalltalk.InterpreterTest)})},
  1070. args: ["aString", "anObject", "aDictionary"],
  1071. 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",
  1072. messageSends: ["new", "receiver:", "interpreter:", "yourself", "keysAndValuesDo:", "localAt:put:", "context:", "interpret:", "nextChild", "parse:forClass:", "class", "proceed", "result"],
  1073. referencedClasses: ["ASTInterpreter", "AIContext"]
  1074. }),
  1075. smalltalk.InterpreterTest);
  1076. smalltalk.addMethod(
  1077. smalltalk.method({
  1078. selector: "parse:",
  1079. protocol: 'parsing',
  1080. fn: function (aString){
  1081. var self=this;
  1082. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1083. return smalltalk.withContext(function($ctx1) {
  1084. var $1;
  1085. $1=_st(_st($Smalltalk())._current())._parse_(aString);
  1086. return $1;
  1087. }, function($ctx1) {$ctx1.fill(self,"parse:",{aString:aString},smalltalk.InterpreterTest)})},
  1088. args: ["aString"],
  1089. source: "parse: aString\x0a\x09^ Smalltalk current parse: aString",
  1090. messageSends: ["parse:", "current"],
  1091. referencedClasses: ["Smalltalk"]
  1092. }),
  1093. smalltalk.InterpreterTest);
  1094. smalltalk.addMethod(
  1095. smalltalk.method({
  1096. selector: "parse:forClass:",
  1097. protocol: 'parsing',
  1098. fn: function (aString,aClass){
  1099. var self=this;
  1100. return smalltalk.withContext(function($ctx1) {
  1101. var $1;
  1102. $1=self._analyze_forClass_(self._parse_(aString),aClass);
  1103. return $1;
  1104. }, function($ctx1) {$ctx1.fill(self,"parse:forClass:",{aString:aString,aClass:aClass},smalltalk.InterpreterTest)})},
  1105. args: ["aString", "aClass"],
  1106. source: "parse: aString forClass: aClass\x0a\x09^ self analyze: (self parse: aString) forClass: aClass",
  1107. messageSends: ["analyze:forClass:", "parse:"],
  1108. referencedClasses: []
  1109. }),
  1110. smalltalk.InterpreterTest);
  1111. smalltalk.addMethod(
  1112. smalltalk.method({
  1113. selector: "should:receiver:return:",
  1114. protocol: 'testing',
  1115. fn: function (aString,anObject,aResult){
  1116. var self=this;
  1117. return smalltalk.withContext(function($ctx1) {
  1118. var $1;
  1119. self["@receiver"]=anObject;
  1120. $1=self._assert_equals_(self._interpret_receiver_withArguments_(aString,self["@receiver"],smalltalk.HashedCollection._from_([])),aResult);
  1121. return $1;
  1122. }, function($ctx1) {$ctx1.fill(self,"should:receiver:return:",{aString:aString,anObject:anObject,aResult:aResult},smalltalk.InterpreterTest)})},
  1123. args: ["aString", "anObject", "aResult"],
  1124. 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",
  1125. messageSends: ["assert:equals:", "interpret:receiver:withArguments:"],
  1126. referencedClasses: []
  1127. }),
  1128. smalltalk.InterpreterTest);
  1129. smalltalk.addMethod(
  1130. smalltalk.method({
  1131. selector: "should:return:",
  1132. protocol: 'testing',
  1133. fn: function (aString,anObject){
  1134. var self=this;
  1135. return smalltalk.withContext(function($ctx1) {
  1136. var $1;
  1137. $1=self._should_receiver_return_(aString,self["@receiver"],anObject);
  1138. return $1;
  1139. }, function($ctx1) {$ctx1.fill(self,"should:return:",{aString:aString,anObject:anObject},smalltalk.InterpreterTest)})},
  1140. args: ["aString", "anObject"],
  1141. source: "should: aString return: anObject\x0a\x09^ self \x0a\x09\x09should: aString\x0a\x09\x09receiver: receiver\x0a\x09\x09return: anObject",
  1142. messageSends: ["should:receiver:return:"],
  1143. referencedClasses: []
  1144. }),
  1145. smalltalk.InterpreterTest);
  1146. smalltalk.addClass('ScopeVarTest', smalltalk.TestCase, [], 'Compiler-Tests');
  1147. smalltalk.addMethod(
  1148. smalltalk.method({
  1149. selector: "testClassRefVar",
  1150. protocol: 'tests',
  1151. fn: function (){
  1152. var self=this;
  1153. var node;
  1154. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1155. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1156. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1157. return smalltalk.withContext(function($ctx1) {
  1158. var $1,$2,$3,$4;
  1159. $1=_st($VariableNode())._new();
  1160. $ctx1.sendIdx["new"]=1;
  1161. _st($1)._value_("Object");
  1162. $2=_st($1)._yourself();
  1163. node=$2;
  1164. $3=_st($SemanticAnalyzer())._new();
  1165. $ctx1.sendIdx["new"]=2;
  1166. _st($3)._pushScope_(_st($MethodLexicalScope())._new());
  1167. $4=_st($3)._visit_(node);
  1168. self._assert_(_st(_st(node)._binding())._isClassRefVar());
  1169. return self}, function($ctx1) {$ctx1.fill(self,"testClassRefVar",{node:node},smalltalk.ScopeVarTest)})},
  1170. args: [],
  1171. 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",
  1172. messageSends: ["value:", "new", "yourself", "pushScope:", "visit:", "assert:", "isClassRefVar", "binding"],
  1173. referencedClasses: ["VariableNode", "SemanticAnalyzer", "MethodLexicalScope"]
  1174. }),
  1175. smalltalk.ScopeVarTest);
  1176. smalltalk.addMethod(
  1177. smalltalk.method({
  1178. selector: "testInstanceVar",
  1179. protocol: 'tests',
  1180. fn: function (){
  1181. var self=this;
  1182. var node,scope;
  1183. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1184. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1185. return smalltalk.withContext(function($ctx1) {
  1186. var $1,$2;
  1187. $1=_st($VariableNode())._new();
  1188. $ctx1.sendIdx["new"]=1;
  1189. _st($1)._value_("bzzz");
  1190. $2=_st($1)._yourself();
  1191. node=$2;
  1192. scope=_st($MethodLexicalScope())._new();
  1193. _st(scope)._addIVar_("bzzz");
  1194. self._assert_(_st(_st(scope)._bindingFor_(node))._isInstanceVar());
  1195. return self}, function($ctx1) {$ctx1.fill(self,"testInstanceVar",{node:node,scope:scope},smalltalk.ScopeVarTest)})},
  1196. args: [],
  1197. 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",
  1198. messageSends: ["value:", "new", "yourself", "addIVar:", "assert:", "isInstanceVar", "bindingFor:"],
  1199. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1200. }),
  1201. smalltalk.ScopeVarTest);
  1202. smalltalk.addMethod(
  1203. smalltalk.method({
  1204. selector: "testPseudoVar",
  1205. protocol: 'tests',
  1206. fn: function (){
  1207. var self=this;
  1208. var node,pseudoVars;
  1209. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1210. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1211. return smalltalk.withContext(function($ctx1) {
  1212. var $1,$2;
  1213. pseudoVars=["self", "super", "true", "false", "nil"];
  1214. _st(pseudoVars)._do_((function(each){
  1215. return smalltalk.withContext(function($ctx2) {
  1216. $1=_st($VariableNode())._new();
  1217. $ctx2.sendIdx["new"]=1;
  1218. _st($1)._value_(each);
  1219. $2=_st($1)._yourself();
  1220. node=$2;
  1221. node;
  1222. return self._assert_(_st(_st(_st($MethodLexicalScope())._new())._bindingFor_(node))._isPseudoVar());
  1223. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1224. return self}, function($ctx1) {$ctx1.fill(self,"testPseudoVar",{node:node,pseudoVars:pseudoVars},smalltalk.ScopeVarTest)})},
  1225. args: [],
  1226. 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 ]",
  1227. messageSends: ["do:", "value:", "new", "yourself", "assert:", "isPseudoVar", "bindingFor:"],
  1228. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1229. }),
  1230. smalltalk.ScopeVarTest);
  1231. smalltalk.addMethod(
  1232. smalltalk.method({
  1233. selector: "testTempVar",
  1234. protocol: 'tests',
  1235. fn: function (){
  1236. var self=this;
  1237. var node,scope;
  1238. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1239. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1240. return smalltalk.withContext(function($ctx1) {
  1241. var $1,$2;
  1242. $1=_st($VariableNode())._new();
  1243. $ctx1.sendIdx["new"]=1;
  1244. _st($1)._value_("bzzz");
  1245. $2=_st($1)._yourself();
  1246. node=$2;
  1247. scope=_st($MethodLexicalScope())._new();
  1248. _st(scope)._addTemp_("bzzz");
  1249. self._assert_(_st(_st(scope)._bindingFor_(node))._isTempVar());
  1250. return self}, function($ctx1) {$ctx1.fill(self,"testTempVar",{node:node,scope:scope},smalltalk.ScopeVarTest)})},
  1251. args: [],
  1252. 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",
  1253. messageSends: ["value:", "new", "yourself", "addTemp:", "assert:", "isTempVar", "bindingFor:"],
  1254. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1255. }),
  1256. smalltalk.ScopeVarTest);
  1257. smalltalk.addMethod(
  1258. smalltalk.method({
  1259. selector: "testUnknownVar",
  1260. protocol: 'tests',
  1261. fn: function (){
  1262. var self=this;
  1263. var node;
  1264. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1265. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1266. return smalltalk.withContext(function($ctx1) {
  1267. var $1,$2;
  1268. $1=_st($VariableNode())._new();
  1269. $ctx1.sendIdx["new"]=1;
  1270. _st($1)._value_("bzzz");
  1271. $2=_st($1)._yourself();
  1272. node=$2;
  1273. self._assert_(_st(_st(_st($MethodLexicalScope())._new())._bindingFor_(node))._isNil());
  1274. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVar",{node:node},smalltalk.ScopeVarTest)})},
  1275. args: [],
  1276. source: "testUnknownVar\x0a\x09| node |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09self assert: (MethodLexicalScope new bindingFor: node) isNil",
  1277. messageSends: ["value:", "new", "yourself", "assert:", "isNil", "bindingFor:"],
  1278. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1279. }),
  1280. smalltalk.ScopeVarTest);
  1281. smalltalk.addClass('SemanticAnalyzerTest', smalltalk.TestCase, ['analyzer'], 'Compiler-Tests');
  1282. smalltalk.addMethod(
  1283. smalltalk.method({
  1284. selector: "setUp",
  1285. protocol: 'running',
  1286. fn: function (){
  1287. var self=this;
  1288. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1289. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  1290. return smalltalk.withContext(function($ctx1) {
  1291. self["@analyzer"]=_st($SemanticAnalyzer())._on_($Object());
  1292. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},smalltalk.SemanticAnalyzerTest)})},
  1293. args: [],
  1294. source: "setUp\x0a\x09analyzer := SemanticAnalyzer on: Object",
  1295. messageSends: ["on:"],
  1296. referencedClasses: ["SemanticAnalyzer", "Object"]
  1297. }),
  1298. smalltalk.SemanticAnalyzerTest);
  1299. smalltalk.addMethod(
  1300. smalltalk.method({
  1301. selector: "testAssignment",
  1302. protocol: 'tests',
  1303. fn: function (){
  1304. var self=this;
  1305. var src,ast;
  1306. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1307. function $InvalidAssignmentError(){return smalltalk.InvalidAssignmentError||(typeof InvalidAssignmentError=="undefined"?nil:InvalidAssignmentError)}
  1308. return smalltalk.withContext(function($ctx1) {
  1309. src="foo self := 1";
  1310. ast=_st(_st($Smalltalk())._current())._parse_(src);
  1311. self._should_raise_((function(){
  1312. return smalltalk.withContext(function($ctx2) {
  1313. return _st(self["@analyzer"])._visit_(ast);
  1314. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$InvalidAssignmentError());
  1315. return self}, function($ctx1) {$ctx1.fill(self,"testAssignment",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1316. args: [],
  1317. source: "testAssignment\x0a\x09| src ast |\x0a\x0a\x09src := 'foo self := 1'.\x0a\x09ast := Smalltalk current parse: src.\x0a\x09self should: [analyzer visit: ast] raise: InvalidAssignmentError",
  1318. messageSends: ["parse:", "current", "should:raise:", "visit:"],
  1319. referencedClasses: ["Smalltalk", "InvalidAssignmentError"]
  1320. }),
  1321. smalltalk.SemanticAnalyzerTest);
  1322. smalltalk.addMethod(
  1323. smalltalk.method({
  1324. selector: "testNonLocalReturn",
  1325. protocol: 'tests',
  1326. fn: function (){
  1327. var self=this;
  1328. var src,ast;
  1329. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1330. return smalltalk.withContext(function($ctx1) {
  1331. src="foo | a | a + 1. ^ a";
  1332. ast=_st(_st($Smalltalk())._current())._parse_(src);
  1333. _st(self["@analyzer"])._visit_(ast);
  1334. self._deny_(_st(_st(ast)._scope())._hasNonLocalReturn());
  1335. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1336. args: [],
  1337. source: "testNonLocalReturn\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. ^ a'.\x0a\x09ast := Smalltalk current parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self deny: ast scope hasNonLocalReturn",
  1338. messageSends: ["parse:", "current", "visit:", "deny:", "hasNonLocalReturn", "scope"],
  1339. referencedClasses: ["Smalltalk"]
  1340. }),
  1341. smalltalk.SemanticAnalyzerTest);
  1342. smalltalk.addMethod(
  1343. smalltalk.method({
  1344. selector: "testNonLocalReturn2",
  1345. protocol: 'tests',
  1346. fn: function (){
  1347. var self=this;
  1348. var src,ast;
  1349. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1350. return smalltalk.withContext(function($ctx1) {
  1351. src="foo | a | a + 1. [ [ ^ a] ]";
  1352. ast=_st(_st($Smalltalk())._current())._parse_(src);
  1353. _st(self["@analyzer"])._visit_(ast);
  1354. self._assert_(_st(_st(ast)._scope())._hasNonLocalReturn());
  1355. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1356. args: [],
  1357. source: "testNonLocalReturn2\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ [ ^ a] ]'.\x0a\x09ast := Smalltalk current parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self assert: ast scope hasNonLocalReturn",
  1358. messageSends: ["parse:", "current", "visit:", "assert:", "hasNonLocalReturn", "scope"],
  1359. referencedClasses: ["Smalltalk"]
  1360. }),
  1361. smalltalk.SemanticAnalyzerTest);
  1362. smalltalk.addMethod(
  1363. smalltalk.method({
  1364. selector: "testScope",
  1365. protocol: 'tests',
  1366. fn: function (){
  1367. var self=this;
  1368. var src,ast;
  1369. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1370. return smalltalk.withContext(function($ctx1) {
  1371. var $4,$3,$2,$1;
  1372. src="foo | a | a + 1. [ | b | b := a ]";
  1373. ast=_st(_st($Smalltalk())._current())._parse_(src);
  1374. _st(self["@analyzer"])._visit_(ast);
  1375. $4=_st(_st(_st(ast)._nodes())._first())._nodes();
  1376. $ctx1.sendIdx["nodes"]=1;
  1377. $3=_st($4)._last();
  1378. $2=_st($3)._scope();
  1379. $ctx1.sendIdx["scope"]=1;
  1380. $1=_st($2).__eq_eq(_st(ast)._scope());
  1381. self._deny_($1);
  1382. return self}, function($ctx1) {$ctx1.fill(self,"testScope",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1383. args: [],
  1384. source: "testScope\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ | b | b := a ]'.\x0a\x09ast := Smalltalk current parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self deny: ast nodes first nodes last scope == ast scope.",
  1385. messageSends: ["parse:", "current", "visit:", "deny:", "==", "scope", "last", "nodes", "first"],
  1386. referencedClasses: ["Smalltalk"]
  1387. }),
  1388. smalltalk.SemanticAnalyzerTest);
  1389. smalltalk.addMethod(
  1390. smalltalk.method({
  1391. selector: "testScope2",
  1392. protocol: 'tests',
  1393. fn: function (){
  1394. var self=this;
  1395. var src,ast;
  1396. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1397. return smalltalk.withContext(function($ctx1) {
  1398. var $8,$7,$6,$5,$4,$3,$2,$1;
  1399. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1400. ast=_st(_st($Smalltalk())._current())._parse_(src);
  1401. _st(self["@analyzer"])._visit_(ast);
  1402. $8=_st(_st(_st(ast)._nodes())._first())._nodes();
  1403. $ctx1.sendIdx["nodes"]=3;
  1404. $7=_st($8)._last();
  1405. $6=_st($7)._nodes();
  1406. $ctx1.sendIdx["nodes"]=2;
  1407. $5=_st($6)._first();
  1408. $ctx1.sendIdx["first"]=2;
  1409. $4=_st($5)._nodes();
  1410. $ctx1.sendIdx["nodes"]=1;
  1411. $3=_st($4)._first();
  1412. $ctx1.sendIdx["first"]=1;
  1413. $2=_st($3)._scope();
  1414. $ctx1.sendIdx["scope"]=1;
  1415. $1=_st($2).__eq_eq(_st(ast)._scope());
  1416. self._deny_($1);
  1417. return self}, function($ctx1) {$ctx1.fill(self,"testScope2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1418. args: [],
  1419. source: "testScope2\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ [ | b | b := a ] ]'.\x0a\x09ast := Smalltalk current parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self deny: ast nodes first nodes last nodes first nodes first scope == ast scope.",
  1420. messageSends: ["parse:", "current", "visit:", "deny:", "==", "scope", "first", "nodes", "last"],
  1421. referencedClasses: ["Smalltalk"]
  1422. }),
  1423. smalltalk.SemanticAnalyzerTest);
  1424. smalltalk.addMethod(
  1425. smalltalk.method({
  1426. selector: "testScopeLevel",
  1427. protocol: 'tests',
  1428. fn: function (){
  1429. var self=this;
  1430. var src,ast;
  1431. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1432. return smalltalk.withContext(function($ctx1) {
  1433. var $2,$1,$10,$9,$8,$7,$6,$5,$4,$3;
  1434. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1435. ast=_st(_st($Smalltalk())._current())._parse_(src);
  1436. _st(self["@analyzer"])._visit_(ast);
  1437. $2=_st(ast)._scope();
  1438. $ctx1.sendIdx["scope"]=1;
  1439. $1=_st($2)._scopeLevel();
  1440. $ctx1.sendIdx["scopeLevel"]=1;
  1441. self._assert_equals_($1,(1));
  1442. $ctx1.sendIdx["assert:equals:"]=1;
  1443. $10=_st(_st(_st(ast)._nodes())._first())._nodes();
  1444. $ctx1.sendIdx["nodes"]=3;
  1445. $9=_st($10)._last();
  1446. $8=_st($9)._nodes();
  1447. $ctx1.sendIdx["nodes"]=2;
  1448. $7=_st($8)._first();
  1449. $ctx1.sendIdx["first"]=2;
  1450. $6=_st($7)._nodes();
  1451. $ctx1.sendIdx["nodes"]=1;
  1452. $5=_st($6)._first();
  1453. $ctx1.sendIdx["first"]=1;
  1454. $4=_st($5)._scope();
  1455. $3=_st($4)._scopeLevel();
  1456. self._assert_equals_($3,(3));
  1457. return self}, function($ctx1) {$ctx1.fill(self,"testScopeLevel",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1458. args: [],
  1459. source: "testScopeLevel\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ [ | b | b := a ] ]'.\x0a\x09ast := Smalltalk current 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",
  1460. messageSends: ["parse:", "current", "visit:", "assert:equals:", "scopeLevel", "scope", "first", "nodes", "last"],
  1461. referencedClasses: ["Smalltalk"]
  1462. }),
  1463. smalltalk.SemanticAnalyzerTest);
  1464. smalltalk.addMethod(
  1465. smalltalk.method({
  1466. selector: "testUnknownVariables",
  1467. protocol: 'tests',
  1468. fn: function (){
  1469. var self=this;
  1470. var src,ast;
  1471. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1472. function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1473. return smalltalk.withContext(function($ctx1) {
  1474. src="foo | a | b + a";
  1475. ast=_st(_st($Smalltalk())._current())._parse_(src);
  1476. self._should_raise_((function(){
  1477. return smalltalk.withContext(function($ctx2) {
  1478. return _st(self["@analyzer"])._visit_(ast);
  1479. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$UnknownVariableError());
  1480. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariables",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1481. args: [],
  1482. source: "testUnknownVariables\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | b + a'.\x0a\x09ast := Smalltalk current parse: src.\x0a\x0a\x09self should: [ analyzer visit: ast ] raise: UnknownVariableError",
  1483. messageSends: ["parse:", "current", "should:raise:", "visit:"],
  1484. referencedClasses: ["Smalltalk", "UnknownVariableError"]
  1485. }),
  1486. smalltalk.SemanticAnalyzerTest);
  1487. smalltalk.addMethod(
  1488. smalltalk.method({
  1489. selector: "testUnknownVariablesWithScope",
  1490. protocol: 'tests',
  1491. fn: function (){
  1492. var self=this;
  1493. var src,ast;
  1494. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1495. function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1496. return smalltalk.withContext(function($ctx1) {
  1497. src="foo | a b | [ c + 1. [ a + 1. d + 1 ]]";
  1498. ast=_st(_st($Smalltalk())._current())._parse_(src);
  1499. self._should_raise_((function(){
  1500. return smalltalk.withContext(function($ctx2) {
  1501. return _st(self["@analyzer"])._visit_(ast);
  1502. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$UnknownVariableError());
  1503. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariablesWithScope",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1504. args: [],
  1505. source: "testUnknownVariablesWithScope\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a b | [ c + 1. [ a + 1. d + 1 ]]'.\x0a\x09ast := Smalltalk current parse: src.\x0a\x09\x0a\x09self should: [ analyzer visit: ast ] raise: UnknownVariableError",
  1506. messageSends: ["parse:", "current", "should:raise:", "visit:"],
  1507. referencedClasses: ["Smalltalk", "UnknownVariableError"]
  1508. }),
  1509. smalltalk.SemanticAnalyzerTest);
  1510. smalltalk.addMethod(
  1511. smalltalk.method({
  1512. selector: "testVariableShadowing",
  1513. protocol: 'tests',
  1514. fn: function (){
  1515. var self=this;
  1516. var src,ast;
  1517. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1518. return smalltalk.withContext(function($ctx1) {
  1519. src="foo | a | a + 1";
  1520. ast=_st(_st($Smalltalk())._current())._parse_(src);
  1521. _st(self["@analyzer"])._visit_(ast);
  1522. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1523. args: [],
  1524. source: "testVariableShadowing\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1'.\x0a\x09ast := Smalltalk current parse: src.\x0a\x09analyzer visit: ast",
  1525. messageSends: ["parse:", "current", "visit:"],
  1526. referencedClasses: ["Smalltalk"]
  1527. }),
  1528. smalltalk.SemanticAnalyzerTest);
  1529. smalltalk.addMethod(
  1530. smalltalk.method({
  1531. selector: "testVariableShadowing2",
  1532. protocol: 'tests',
  1533. fn: function (){
  1534. var self=this;
  1535. var src,ast;
  1536. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1537. function $ShadowingVariableError(){return smalltalk.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1538. return smalltalk.withContext(function($ctx1) {
  1539. src="foo | a | a + 1. [ | a | a := 2 ]";
  1540. ast=_st(_st($Smalltalk())._current())._parse_(src);
  1541. self._should_raise_((function(){
  1542. return smalltalk.withContext(function($ctx2) {
  1543. return _st(self["@analyzer"])._visit_(ast);
  1544. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$ShadowingVariableError());
  1545. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1546. args: [],
  1547. source: "testVariableShadowing2\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | a | a := 2 ]'.\x0a\x09ast := Smalltalk current parse: src.\x0a\x09self should: [analyzer visit: ast] raise: ShadowingVariableError",
  1548. messageSends: ["parse:", "current", "should:raise:", "visit:"],
  1549. referencedClasses: ["Smalltalk", "ShadowingVariableError"]
  1550. }),
  1551. smalltalk.SemanticAnalyzerTest);
  1552. smalltalk.addMethod(
  1553. smalltalk.method({
  1554. selector: "testVariableShadowing3",
  1555. protocol: 'tests',
  1556. fn: function (){
  1557. var self=this;
  1558. var src,ast;
  1559. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1560. return smalltalk.withContext(function($ctx1) {
  1561. src="foo | a | a + 1. [ | b | b := 2 ]";
  1562. ast=_st(_st($Smalltalk())._current())._parse_(src);
  1563. _st(self["@analyzer"])._visit_(ast);
  1564. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing3",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1565. args: [],
  1566. source: "testVariableShadowing3\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | b | b := 2 ]'.\x0a\x09ast := Smalltalk current parse: src.\x0a\x09analyzer visit: ast",
  1567. messageSends: ["parse:", "current", "visit:"],
  1568. referencedClasses: ["Smalltalk"]
  1569. }),
  1570. smalltalk.SemanticAnalyzerTest);
  1571. smalltalk.addMethod(
  1572. smalltalk.method({
  1573. selector: "testVariableShadowing4",
  1574. protocol: 'tests',
  1575. fn: function (){
  1576. var self=this;
  1577. var src,ast;
  1578. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1579. return smalltalk.withContext(function($ctx1) {
  1580. src="foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]";
  1581. ast=_st(_st($Smalltalk())._current())._parse_(src);
  1582. _st(self["@analyzer"])._visit_(ast);
  1583. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing4",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1584. args: [],
  1585. source: "testVariableShadowing4\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.\x0a\x09ast := Smalltalk current parse: src.\x0a\x09analyzer visit: ast",
  1586. messageSends: ["parse:", "current", "visit:"],
  1587. referencedClasses: ["Smalltalk"]
  1588. }),
  1589. smalltalk.SemanticAnalyzerTest);
  1590. smalltalk.addMethod(
  1591. smalltalk.method({
  1592. selector: "testVariableShadowing5",
  1593. protocol: 'tests',
  1594. fn: function (){
  1595. var self=this;
  1596. var src,ast;
  1597. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1598. function $ShadowingVariableError(){return smalltalk.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1599. return smalltalk.withContext(function($ctx1) {
  1600. src="foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]";
  1601. ast=_st(_st($Smalltalk())._current())._parse_(src);
  1602. self._should_raise_((function(){
  1603. return smalltalk.withContext(function($ctx2) {
  1604. return _st(self["@analyzer"])._visit_(ast);
  1605. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$ShadowingVariableError());
  1606. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing5",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1607. args: [],
  1608. source: "testVariableShadowing5\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]'.\x0a\x09ast := Smalltalk current parse: src.\x0a\x09self should: [analyzer visit: ast] raise: ShadowingVariableError",
  1609. messageSends: ["parse:", "current", "should:raise:", "visit:"],
  1610. referencedClasses: ["Smalltalk", "ShadowingVariableError"]
  1611. }),
  1612. smalltalk.SemanticAnalyzerTest);
  1613. smalltalk.addMethod(
  1614. smalltalk.method({
  1615. selector: "testVariablesLookup",
  1616. protocol: 'tests',
  1617. fn: function (){
  1618. var self=this;
  1619. var src,ast;
  1620. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1621. return smalltalk.withContext(function($ctx1) {
  1622. 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;
  1623. src="foo | a | a + 1. [ | b | b := a ]";
  1624. ast=_st(_st($Smalltalk())._current())._parse_(src);
  1625. _st(self["@analyzer"])._visit_(ast);
  1626. $7=_st(ast)._nodes();
  1627. $ctx1.sendIdx["nodes"]=2;
  1628. $6=_st($7)._first();
  1629. $ctx1.sendIdx["first"]=2;
  1630. $5=_st($6)._nodes();
  1631. $ctx1.sendIdx["nodes"]=1;
  1632. $4=_st($5)._first();
  1633. $ctx1.sendIdx["first"]=1;
  1634. $3=_st($4)._receiver();
  1635. $ctx1.sendIdx["receiver"]=1;
  1636. $2=_st($3)._binding();
  1637. $ctx1.sendIdx["binding"]=1;
  1638. $1=_st($2)._isTempVar();
  1639. $ctx1.sendIdx["isTempVar"]=1;
  1640. self._assert_($1);
  1641. $ctx1.sendIdx["assert:"]=1;
  1642. $15=_st(ast)._nodes();
  1643. $ctx1.sendIdx["nodes"]=4;
  1644. $14=_st($15)._first();
  1645. $ctx1.sendIdx["first"]=4;
  1646. $13=_st($14)._nodes();
  1647. $ctx1.sendIdx["nodes"]=3;
  1648. $12=_st($13)._first();
  1649. $ctx1.sendIdx["first"]=3;
  1650. $11=_st($12)._receiver();
  1651. $10=_st($11)._binding();
  1652. $ctx1.sendIdx["binding"]=2;
  1653. $9=_st($10)._scope();
  1654. $ctx1.sendIdx["scope"]=1;
  1655. $16=_st(ast)._scope();
  1656. $ctx1.sendIdx["scope"]=2;
  1657. $8=_st($9).__eq_eq($16);
  1658. $ctx1.sendIdx["=="]=1;
  1659. self._assert_($8);
  1660. $ctx1.sendIdx["assert:"]=2;
  1661. $27=_st(ast)._nodes();
  1662. $ctx1.sendIdx["nodes"]=8;
  1663. $26=_st($27)._first();
  1664. $ctx1.sendIdx["first"]=7;
  1665. $25=_st($26)._nodes();
  1666. $ctx1.sendIdx["nodes"]=7;
  1667. $24=_st($25)._last();
  1668. $ctx1.sendIdx["last"]=1;
  1669. $23=_st($24)._nodes();
  1670. $ctx1.sendIdx["nodes"]=6;
  1671. $22=_st($23)._first();
  1672. $ctx1.sendIdx["first"]=6;
  1673. $21=_st($22)._nodes();
  1674. $ctx1.sendIdx["nodes"]=5;
  1675. $20=_st($21)._first();
  1676. $ctx1.sendIdx["first"]=5;
  1677. $19=_st($20)._left();
  1678. $ctx1.sendIdx["left"]=1;
  1679. $18=_st($19)._binding();
  1680. $ctx1.sendIdx["binding"]=3;
  1681. $17=_st($18)._isTempVar();
  1682. self._assert_($17);
  1683. $ctx1.sendIdx["assert:"]=3;
  1684. $39=_st(ast)._nodes();
  1685. $ctx1.sendIdx["nodes"]=12;
  1686. $38=_st($39)._first();
  1687. $ctx1.sendIdx["first"]=10;
  1688. $37=_st($38)._nodes();
  1689. $ctx1.sendIdx["nodes"]=11;
  1690. $36=_st($37)._last();
  1691. $ctx1.sendIdx["last"]=2;
  1692. $35=_st($36)._nodes();
  1693. $ctx1.sendIdx["nodes"]=10;
  1694. $34=_st($35)._first();
  1695. $ctx1.sendIdx["first"]=9;
  1696. $33=_st($34)._nodes();
  1697. $ctx1.sendIdx["nodes"]=9;
  1698. $32=_st($33)._first();
  1699. $ctx1.sendIdx["first"]=8;
  1700. $31=_st($32)._left();
  1701. $30=_st($31)._binding();
  1702. $29=_st($30)._scope();
  1703. $ctx1.sendIdx["scope"]=3;
  1704. $42=_st(_st(_st(ast)._nodes())._first())._nodes();
  1705. $ctx1.sendIdx["nodes"]=13;
  1706. $41=_st($42)._last();
  1707. $40=_st($41)._scope();
  1708. $28=_st($29).__eq_eq($40);
  1709. self._assert_($28);
  1710. return self}, function($ctx1) {$ctx1.fill(self,"testVariablesLookup",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1711. args: [],
  1712. source: "testVariablesLookup\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ | b | b := a ]'.\x0a\x09ast := Smalltalk current 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.",
  1713. messageSends: ["parse:", "current", "visit:", "assert:", "isTempVar", "binding", "receiver", "first", "nodes", "==", "scope", "left", "last"],
  1714. referencedClasses: ["Smalltalk"]
  1715. }),
  1716. smalltalk.SemanticAnalyzerTest);
  1717. });