Compiler-Tests.js 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773
  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. category: '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. category: '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. category: '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. category: '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. category: '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. category: '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. category: '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. category: '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. category: '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. category: '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. category: '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. category: '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. category: '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. category: '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. category: '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_category_(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 category: 'tests'.\x0a\x09result := receiver perform: method selector.\x0a\x09anObject class removeCompiledMethod: method.\x0a\x09self assert: aResult equals: result",
  330. messageSends: ["install:forClass:category:", "compiler", "class", "perform:", "selector", "removeCompiledMethod:", "assert:equals:"],
  331. referencedClasses: []
  332. }),
  333. smalltalk.CodeGeneratorTest);
  334. smalltalk.addMethod(
  335. smalltalk.method({
  336. selector: "should:return:",
  337. category: '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. category: '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. category: '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. category: '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. category: '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. category: '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: "testDynamicArrayElementsOrdered",
  438. category: 'tests',
  439. fn: function (){
  440. var self=this;
  441. return smalltalk.withContext(function($ctx1) {
  442. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { x. x := 2 }\x0a",[(1), (2)]);
  443. $ctx1.sendIdx["should:return:"]=1;
  444. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { x. true ifTrue: [ x := 2 ] }\x0a",[(1), (2)]);
  445. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicArrayElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  446. args: [],
  447. 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).",
  448. messageSends: ["should:return:"],
  449. referencedClasses: []
  450. }),
  451. smalltalk.CodeGeneratorTest);
  452. smalltalk.addMethod(
  453. smalltalk.method({
  454. selector: "testDynamicDictionaryElementsOrdered",
  455. category: 'tests',
  456. fn: function (){
  457. var self=this;
  458. return smalltalk.withContext(function($ctx1) {
  459. var $2,$1;
  460. $2="foo".__minus_gt((1));
  461. $ctx1.sendIdx["->"]=1;
  462. $1=smalltalk.HashedCollection._from_([$2,"bar".__minus_gt((2))]);
  463. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 'foo'->1.\x0a\x09^ #{ x. (true ifTrue: [ x := 'bar'->2 ]) }\x0a",$1);
  464. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicDictionaryElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  465. args: [],
  466. 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}.",
  467. messageSends: ["should:return:", "->"],
  468. referencedClasses: []
  469. }),
  470. smalltalk.CodeGeneratorTest);
  471. smalltalk.addMethod(
  472. smalltalk.method({
  473. selector: "testGlobalVar",
  474. category: 'tests',
  475. fn: function (){
  476. var self=this;
  477. function $BlockClosure(){return smalltalk.BlockClosure||(typeof BlockClosure=="undefined"?nil:BlockClosure)}
  478. return smalltalk.withContext(function($ctx1) {
  479. self._should_return_("foo ^ eval class",$BlockClosure());
  480. $ctx1.sendIdx["should:return:"]=1;
  481. self._should_return_("foo ^ Math cos: 0",(1));
  482. $ctx1.sendIdx["should:return:"]=2;
  483. self._should_return_("foo ^ NonExistingVar",nil);
  484. return self}, function($ctx1) {$ctx1.fill(self,"testGlobalVar",{},smalltalk.CodeGeneratorTest)})},
  485. args: [],
  486. 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",
  487. messageSends: ["should:return:"],
  488. referencedClasses: ["BlockClosure"]
  489. }),
  490. smalltalk.CodeGeneratorTest);
  491. smalltalk.addMethod(
  492. smalltalk.method({
  493. selector: "testInnerTemporalDependentElementsOrdered",
  494. category: 'tests',
  495. fn: function (){
  496. var self=this;
  497. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  498. return smalltalk.withContext(function($ctx1) {
  499. var $2,$3,$1,$5,$6,$4,$8,$9,$7,$11,$12,$10,$14,$13;
  500. $2="foo".__minus_gt($Array());
  501. $ctx1.sendIdx["->"]=1;
  502. $3="bar".__minus_gt((2));
  503. $ctx1.sendIdx["->"]=2;
  504. $1=[$2,$3];
  505. self._should_return_("foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: 'foo'->x with: 'bar'->(x := 2)\x0a",$1);
  506. $ctx1.sendIdx["should:return:"]=1;
  507. $5="foo".__minus_gt($Array());
  508. $ctx1.sendIdx["->"]=3;
  509. $6="bar".__minus_gt((2));
  510. $ctx1.sendIdx["->"]=4;
  511. $4=[$5,$6];
  512. self._should_return_("foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: 'foo'->x with: 'bar'->(true ifTrue: [ x := 2 ])\x0a",$4);
  513. $ctx1.sendIdx["should:return:"]=2;
  514. $8="foo".__minus_gt((1));
  515. $ctx1.sendIdx["->"]=5;
  516. $9="bar".__minus_gt((2));
  517. $ctx1.sendIdx["->"]=6;
  518. $7=[$8,$9];
  519. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ Array with: 'foo'->x with: 'bar'->(true ifTrue: [ x := 2 ])\x0a",$7);
  520. $ctx1.sendIdx["should:return:"]=3;
  521. $11="foo".__minus_gt((1));
  522. $ctx1.sendIdx["->"]=7;
  523. $12="bar".__minus_gt((2));
  524. $ctx1.sendIdx["->"]=8;
  525. $10=[$11,$12];
  526. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { 'foo'->x. 'bar'->(true ifTrue: [ x := 2 ]) }\x0a",$10);
  527. $ctx1.sendIdx["should:return:"]=4;
  528. $14="foo".__minus_gt((1));
  529. $ctx1.sendIdx["->"]=9;
  530. $13=smalltalk.HashedCollection._from_([$14,"bar".__minus_gt((2))]);
  531. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ #{ 'foo'->x. 'bar'->(true ifTrue: [ x := 2 ]) }\x0a",$13);
  532. return self}, function($ctx1) {$ctx1.fill(self,"testInnerTemporalDependentElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  533. args: [],
  534. 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}.",
  535. messageSends: ["should:return:", "->"],
  536. referencedClasses: ["Array"]
  537. }),
  538. smalltalk.CodeGeneratorTest);
  539. smalltalk.addMethod(
  540. smalltalk.method({
  541. selector: "testJSStatement",
  542. category: 'tests',
  543. fn: function (){
  544. var self=this;
  545. return smalltalk.withContext(function($ctx1) {
  546. self._should_return_("foo <return 2+3>",(5));
  547. return self}, function($ctx1) {$ctx1.fill(self,"testJSStatement",{},smalltalk.CodeGeneratorTest)})},
  548. args: [],
  549. source: "testJSStatement\x0a\x09self should: 'foo <return 2+3>' return: 5",
  550. messageSends: ["should:return:"],
  551. referencedClasses: []
  552. }),
  553. smalltalk.CodeGeneratorTest);
  554. smalltalk.addMethod(
  555. smalltalk.method({
  556. selector: "testLiterals",
  557. category: 'tests',
  558. fn: function (){
  559. var self=this;
  560. return smalltalk.withContext(function($ctx1) {
  561. var $2,$1;
  562. self._should_return_("foo ^ 1",(1));
  563. $ctx1.sendIdx["should:return:"]=1;
  564. self._should_return_("foo ^ 'hello'","hello");
  565. $ctx1.sendIdx["should:return:"]=2;
  566. self._should_return_("foo ^ #(1 2 3 4)",[(1), (2), (3), (4)]);
  567. $ctx1.sendIdx["should:return:"]=3;
  568. self._should_return_("foo ^ {1. [:x | x ] value: 2. 3. [4] value}",[(1), (2), (3), (4)]);
  569. $ctx1.sendIdx["should:return:"]=4;
  570. self._should_return_("foo ^ true",true);
  571. $ctx1.sendIdx["should:return:"]=5;
  572. self._should_return_("foo ^ false",false);
  573. $ctx1.sendIdx["should:return:"]=6;
  574. $2=(1).__minus_gt((2));
  575. $ctx1.sendIdx["->"]=1;
  576. $1=smalltalk.HashedCollection._from_([$2,(3).__minus_gt((4))]);
  577. self._should_return_("foo ^ #{1->2. 3->4}",$1);
  578. $ctx1.sendIdx["should:return:"]=7;
  579. self._should_return_("foo ^ #hello","hello");
  580. $ctx1.sendIdx["should:return:"]=8;
  581. self._should_return_("foo ^ -123.456",(-123.456));
  582. $ctx1.sendIdx["should:return:"]=9;
  583. self._should_return_("foo ^ -2.5e4",(-25000));
  584. return self}, function($ctx1) {$ctx1.fill(self,"testLiterals",{},smalltalk.CodeGeneratorTest)})},
  585. args: [],
  586. 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.",
  587. messageSends: ["should:return:", "->"],
  588. referencedClasses: []
  589. }),
  590. smalltalk.CodeGeneratorTest);
  591. smalltalk.addMethod(
  592. smalltalk.method({
  593. selector: "testLocalReturn",
  594. category: 'tests',
  595. fn: function (){
  596. var self=this;
  597. return smalltalk.withContext(function($ctx1) {
  598. self._should_return_("foo ^ 1",(1));
  599. $ctx1.sendIdx["should:return:"]=1;
  600. self._should_return_("foo ^ 1 + 1",(2));
  601. $ctx1.sendIdx["should:return:"]=2;
  602. self._should_return_("foo ",self["@receiver"]);
  603. $ctx1.sendIdx["should:return:"]=3;
  604. self._should_return_("foo self asString",self["@receiver"]);
  605. $ctx1.sendIdx["should:return:"]=4;
  606. self._should_return_("foo | a b | a := 1. b := 2. ^ a + b",(3));
  607. return self}, function($ctx1) {$ctx1.fill(self,"testLocalReturn",{},smalltalk.CodeGeneratorTest)})},
  608. args: [],
  609. 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",
  610. messageSends: ["should:return:"],
  611. referencedClasses: []
  612. }),
  613. smalltalk.CodeGeneratorTest);
  614. smalltalk.addMethod(
  615. smalltalk.method({
  616. selector: "testMessageSends",
  617. category: 'tests',
  618. fn: function (){
  619. var self=this;
  620. return smalltalk.withContext(function($ctx1) {
  621. self._should_return_("foo ^ 1 asString","1");
  622. $ctx1.sendIdx["should:return:"]=1;
  623. self._should_return_("foo ^ 1 + 1",(2));
  624. $ctx1.sendIdx["should:return:"]=2;
  625. self._should_return_("foo ^ 1 + 2 * 3",(9));
  626. $ctx1.sendIdx["should:return:"]=3;
  627. self._should_return_("foo ^ 1 to: 3",[(1), (2), (3)]);
  628. $ctx1.sendIdx["should:return:"]=4;
  629. self._should_return_("foo ^ 1 to: 5 by: 2",[(1), (3), (5)]);
  630. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSends",{},smalltalk.CodeGeneratorTest)})},
  631. args: [],
  632. 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)",
  633. messageSends: ["should:return:"],
  634. referencedClasses: []
  635. }),
  636. smalltalk.CodeGeneratorTest);
  637. smalltalk.addMethod(
  638. smalltalk.method({
  639. selector: "testMultipleSequences",
  640. category: 'tests',
  641. fn: function (){
  642. var self=this;
  643. return smalltalk.withContext(function($ctx1) {
  644. self._should_return_("foo | a b c | a := 2. b := 3. c := a + b. ^ c * 6",(30));
  645. return self}, function($ctx1) {$ctx1.fill(self,"testMultipleSequences",{},smalltalk.CodeGeneratorTest)})},
  646. args: [],
  647. source: "testMultipleSequences\x0a\x09self should: 'foo | a b c | a := 2. b := 3. c := a + b. ^ c * 6' return: 30",
  648. messageSends: ["should:return:"],
  649. referencedClasses: []
  650. }),
  651. smalltalk.CodeGeneratorTest);
  652. smalltalk.addMethod(
  653. smalltalk.method({
  654. selector: "testMutableLiterals",
  655. category: 'tests',
  656. fn: function (){
  657. var self=this;
  658. return smalltalk.withContext(function($ctx1) {
  659. self._should_return_("foo ^ #( 1 2 ) at: 1 put: 3; yourself",[(3), (2)]);
  660. return self}, function($ctx1) {$ctx1.fill(self,"testMutableLiterals",{},smalltalk.CodeGeneratorTest)})},
  661. args: [],
  662. 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)",
  663. messageSends: ["should:return:"],
  664. referencedClasses: []
  665. }),
  666. smalltalk.CodeGeneratorTest);
  667. smalltalk.addMethod(
  668. smalltalk.method({
  669. selector: "testNestedIfTrue",
  670. category: 'tests',
  671. fn: function (){
  672. var self=this;
  673. return smalltalk.withContext(function($ctx1) {
  674. self._should_return_("foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]",(1));
  675. $ctx1.sendIdx["should:return:"]=1;
  676. self._should_return_("foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]",nil);
  677. $ctx1.sendIdx["should:return:"]=2;
  678. self._should_return_("foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]",(1));
  679. $ctx1.sendIdx["should:return:"]=3;
  680. self._should_return_("foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]",self["@receiver"]);
  681. return self}, function($ctx1) {$ctx1.fill(self,"testNestedIfTrue",{},smalltalk.CodeGeneratorTest)})},
  682. args: [],
  683. 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.",
  684. messageSends: ["should:return:"],
  685. referencedClasses: []
  686. }),
  687. smalltalk.CodeGeneratorTest);
  688. smalltalk.addMethod(
  689. smalltalk.method({
  690. selector: "testNestedSends",
  691. category: 'tests',
  692. fn: function (){
  693. var self=this;
  694. function $Point(){return smalltalk.Point||(typeof Point=="undefined"?nil:Point)}
  695. return smalltalk.withContext(function($ctx1) {
  696. self._should_return_("foo ^ (Point x: (Point x: 2 y: 3) y: 4) asString",_st(_st($Point())._x_y_((2).__at((3)),(4)))._asString());
  697. return self}, function($ctx1) {$ctx1.fill(self,"testNestedSends",{},smalltalk.CodeGeneratorTest)})},
  698. args: [],
  699. source: "testNestedSends\x0a\x09self should: 'foo ^ (Point x: (Point x: 2 y: 3) y: 4) asString' return: (Point x: (2@3) y: 4) asString",
  700. messageSends: ["should:return:", "asString", "x:y:", "@"],
  701. referencedClasses: ["Point"]
  702. }),
  703. smalltalk.CodeGeneratorTest);
  704. smalltalk.addMethod(
  705. smalltalk.method({
  706. selector: "testNonLocalReturn",
  707. category: 'tests',
  708. fn: function (){
  709. var self=this;
  710. return smalltalk.withContext(function($ctx1) {
  711. self._should_return_("foo [ ^ 1 ] value",(1));
  712. $ctx1.sendIdx["should:return:"]=1;
  713. self._should_return_("foo [ ^ 1 + 1 ] value",(2));
  714. $ctx1.sendIdx["should:return:"]=2;
  715. self._should_return_("foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt",(3));
  716. $ctx1.sendIdx["should:return:"]=3;
  717. self._should_return_("foo [ :x | ^ x + x ] value: 4. ^ 2",(8));
  718. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn",{},smalltalk.CodeGeneratorTest)})},
  719. args: [],
  720. 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",
  721. messageSends: ["should:return:"],
  722. referencedClasses: []
  723. }),
  724. smalltalk.CodeGeneratorTest);
  725. smalltalk.addMethod(
  726. smalltalk.method({
  727. selector: "testPascalCaseGlobal",
  728. category: 'tests',
  729. fn: function (){
  730. var self=this;
  731. return smalltalk.withContext(function($ctx1) {
  732. self._should_return_("foo ^Object",_st(smalltalk)._at_("Object"));
  733. $ctx1.sendIdx["should:return:"]=1;
  734. self._should_return_("foo ^NonExistent",nil);
  735. return self}, function($ctx1) {$ctx1.fill(self,"testPascalCaseGlobal",{},smalltalk.CodeGeneratorTest)})},
  736. args: [],
  737. source: "testPascalCaseGlobal\x0a\x09self should: 'foo ^Object' return: (smalltalk at: 'Object').\x0a\x09self should: 'foo ^NonExistent' return: nil",
  738. messageSends: ["should:return:", "at:"],
  739. referencedClasses: []
  740. }),
  741. smalltalk.CodeGeneratorTest);
  742. smalltalk.addMethod(
  743. smalltalk.method({
  744. selector: "testSendReceiverAndArgumentsOrdered",
  745. category: 'tests',
  746. fn: function (){
  747. var self=this;
  748. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  749. return smalltalk.withContext(function($ctx1) {
  750. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ Array with: x with: (true ifTrue: [ x := 2 ])\x0a",[(1), (2)]);
  751. $ctx1.sendIdx["should:return:"]=1;
  752. self._should_return_("foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: x with: (true ifTrue: [ x := 2 ])\x0a",[$Array(),(2)]);
  753. return self}, function($ctx1) {$ctx1.fill(self,"testSendReceiverAndArgumentsOrdered",{},smalltalk.CodeGeneratorTest)})},
  754. args: [],
  755. 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}.",
  756. messageSends: ["should:return:"],
  757. referencedClasses: ["Array"]
  758. }),
  759. smalltalk.CodeGeneratorTest);
  760. smalltalk.addMethod(
  761. smalltalk.method({
  762. selector: "testSuperSend",
  763. category: 'tests',
  764. fn: function (){
  765. var self=this;
  766. return smalltalk.withContext(function($ctx1) {
  767. self._should_receiver_return_("foo ^ super isBoolean",true,false);
  768. return self}, function($ctx1) {$ctx1.fill(self,"testSuperSend",{},smalltalk.CodeGeneratorTest)})},
  769. args: [],
  770. source: "testSuperSend\x0a\x09self \x0a\x09\x09should: 'foo ^ super isBoolean' \x0a\x09\x09receiver: true\x0a\x09\x09return: false",
  771. messageSends: ["should:receiver:return:"],
  772. referencedClasses: []
  773. }),
  774. smalltalk.CodeGeneratorTest);
  775. smalltalk.addMethod(
  776. smalltalk.method({
  777. selector: "testTempVariables",
  778. category: 'tests',
  779. fn: function (){
  780. var self=this;
  781. return smalltalk.withContext(function($ctx1) {
  782. self._should_return_("foo | a | ^ a",nil);
  783. $ctx1.sendIdx["should:return:"]=1;
  784. self._should_return_("foo | AVariable | ^ AVariable",nil);
  785. $ctx1.sendIdx["should:return:"]=2;
  786. self._should_return_("foo | a b c | ^ c",nil);
  787. $ctx1.sendIdx["should:return:"]=3;
  788. self._should_return_("foo | a | [ | d | ^ d ] value",nil);
  789. $ctx1.sendIdx["should:return:"]=4;
  790. self._should_return_("foo | a | a:= 1. ^ a",(1));
  791. $ctx1.sendIdx["should:return:"]=5;
  792. self._should_return_("foo | AVariable | AVariable := 1. ^ AVariable",(1));
  793. return self}, function($ctx1) {$ctx1.fill(self,"testTempVariables",{},smalltalk.CodeGeneratorTest)})},
  794. args: [],
  795. 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.\x09",
  796. messageSends: ["should:return:"],
  797. referencedClasses: []
  798. }),
  799. smalltalk.CodeGeneratorTest);
  800. smalltalk.addMethod(
  801. smalltalk.method({
  802. selector: "testThisContext",
  803. category: 'tests',
  804. fn: function (){
  805. var self=this;
  806. return smalltalk.withContext(function($ctx1) {
  807. self._should_return_("foo ^ [ thisContext ] value outerContext == thisContext",true);
  808. return self}, function($ctx1) {$ctx1.fill(self,"testThisContext",{},smalltalk.CodeGeneratorTest)})},
  809. args: [],
  810. source: "testThisContext\x0a\x09self should: 'foo ^ [ thisContext ] value outerContext == thisContext' return: true",
  811. messageSends: ["should:return:"],
  812. referencedClasses: []
  813. }),
  814. smalltalk.CodeGeneratorTest);
  815. smalltalk.addMethod(
  816. smalltalk.method({
  817. selector: "testifFalse",
  818. category: 'tests',
  819. fn: function (){
  820. var self=this;
  821. return smalltalk.withContext(function($ctx1) {
  822. self._should_return_("foo true ifFalse: [ ^ 1 ]",self["@receiver"]);
  823. $ctx1.sendIdx["should:return:"]=1;
  824. self._should_return_("foo false ifFalse: [ ^ 2 ]",(2));
  825. $ctx1.sendIdx["should:return:"]=2;
  826. self._should_return_("foo ^ true ifFalse: [ 1 ]",nil);
  827. $ctx1.sendIdx["should:return:"]=3;
  828. self._should_return_("foo ^ false ifFalse: [ 2 ]",(2));
  829. return self}, function($ctx1) {$ctx1.fill(self,"testifFalse",{},smalltalk.CodeGeneratorTest)})},
  830. args: [],
  831. 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.",
  832. messageSends: ["should:return:"],
  833. referencedClasses: []
  834. }),
  835. smalltalk.CodeGeneratorTest);
  836. smalltalk.addMethod(
  837. smalltalk.method({
  838. selector: "testifFalseIfTrue",
  839. category: 'tests',
  840. fn: function (){
  841. var self=this;
  842. return smalltalk.withContext(function($ctx1) {
  843. self._should_return_("foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]",(2));
  844. $ctx1.sendIdx["should:return:"]=1;
  845. self._should_return_("foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]",(2));
  846. $ctx1.sendIdx["should:return:"]=2;
  847. self._should_return_("foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]",(2));
  848. $ctx1.sendIdx["should:return:"]=3;
  849. self._should_return_("foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]",(2));
  850. return self}, function($ctx1) {$ctx1.fill(self,"testifFalseIfTrue",{},smalltalk.CodeGeneratorTest)})},
  851. args: [],
  852. 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.",
  853. messageSends: ["should:return:"],
  854. referencedClasses: []
  855. }),
  856. smalltalk.CodeGeneratorTest);
  857. smalltalk.addMethod(
  858. smalltalk.method({
  859. selector: "testifNil",
  860. category: 'tests',
  861. fn: function (){
  862. var self=this;
  863. return smalltalk.withContext(function($ctx1) {
  864. self._should_return_("foo ^ 1 ifNil: [ 2 ]",(1));
  865. $ctx1.sendIdx["should:return:"]=1;
  866. self._should_return_("foo ^ nil ifNil: [ 2 ]",(2));
  867. $ctx1.sendIdx["should:return:"]=2;
  868. self._should_return_("foo 1 ifNil: [ ^ 2 ]",self["@receiver"]);
  869. $ctx1.sendIdx["should:return:"]=3;
  870. self._should_return_("foo nil ifNil: [ ^ 2 ]",(2));
  871. return self}, function($ctx1) {$ctx1.fill(self,"testifNil",{},smalltalk.CodeGeneratorTest)})},
  872. args: [],
  873. 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.",
  874. messageSends: ["should:return:"],
  875. referencedClasses: []
  876. }),
  877. smalltalk.CodeGeneratorTest);
  878. smalltalk.addMethod(
  879. smalltalk.method({
  880. selector: "testifNilIfNotNil",
  881. category: 'tests',
  882. fn: function (){
  883. var self=this;
  884. return smalltalk.withContext(function($ctx1) {
  885. self._should_return_("foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]",(3));
  886. $ctx1.sendIdx["should:return:"]=1;
  887. self._should_return_("foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]",(2));
  888. $ctx1.sendIdx["should:return:"]=2;
  889. self._should_return_("foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(3));
  890. $ctx1.sendIdx["should:return:"]=3;
  891. self._should_return_("foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(2));
  892. return self}, function($ctx1) {$ctx1.fill(self,"testifNilIfNotNil",{},smalltalk.CodeGeneratorTest)})},
  893. args: [],
  894. 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.",
  895. messageSends: ["should:return:"],
  896. referencedClasses: []
  897. }),
  898. smalltalk.CodeGeneratorTest);
  899. smalltalk.addMethod(
  900. smalltalk.method({
  901. selector: "testifNotNil",
  902. category: 'tests',
  903. fn: function (){
  904. var self=this;
  905. return smalltalk.withContext(function($ctx1) {
  906. self._should_return_("foo ^ 1 ifNotNil: [ 2 ]",(2));
  907. $ctx1.sendIdx["should:return:"]=1;
  908. self._should_return_("foo ^ nil ifNotNil: [ 2 ]",nil);
  909. $ctx1.sendIdx["should:return:"]=2;
  910. self._should_return_("foo 1 ifNotNil: [ ^ 2 ]",(2));
  911. $ctx1.sendIdx["should:return:"]=3;
  912. self._should_return_("foo nil ifNotNil: [ ^ 2 ]",self["@receiver"]);
  913. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNil",{},smalltalk.CodeGeneratorTest)})},
  914. args: [],
  915. 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.",
  916. messageSends: ["should:return:"],
  917. referencedClasses: []
  918. }),
  919. smalltalk.CodeGeneratorTest);
  920. smalltalk.addMethod(
  921. smalltalk.method({
  922. selector: "testifNotNilWithArgument",
  923. category: 'tests',
  924. fn: function (){
  925. var self=this;
  926. return smalltalk.withContext(function($ctx1) {
  927. self._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ]",(3));
  928. $ctx1.sendIdx["should:return:"]=1;
  929. self._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ]",nil);
  930. $ctx1.sendIdx["should:return:"]=2;
  931. self._should_return_("foo ^ 1 ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(3));
  932. $ctx1.sendIdx["should:return:"]=3;
  933. self._should_return_("foo ^ nil ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(5));
  934. $ctx1.sendIdx["should:return:"]=4;
  935. self._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(3));
  936. $ctx1.sendIdx["should:return:"]=5;
  937. self._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(5));
  938. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNilWithArgument",{},smalltalk.CodeGeneratorTest)})},
  939. args: [],
  940. 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",
  941. messageSends: ["should:return:"],
  942. referencedClasses: []
  943. }),
  944. smalltalk.CodeGeneratorTest);
  945. smalltalk.addMethod(
  946. smalltalk.method({
  947. selector: "testifTrue",
  948. category: 'tests',
  949. fn: function (){
  950. var self=this;
  951. return smalltalk.withContext(function($ctx1) {
  952. self._should_return_("foo false ifTrue: [ ^ 1 ]",self["@receiver"]);
  953. $ctx1.sendIdx["should:return:"]=1;
  954. self._should_return_("foo true ifTrue: [ ^ 2 ]",(2));
  955. $ctx1.sendIdx["should:return:"]=2;
  956. self._should_return_("foo ^ false ifTrue: [ 1 ]",nil);
  957. $ctx1.sendIdx["should:return:"]=3;
  958. self._should_return_("foo ^ true ifTrue: [ 2 ]",(2));
  959. return self}, function($ctx1) {$ctx1.fill(self,"testifTrue",{},smalltalk.CodeGeneratorTest)})},
  960. args: [],
  961. 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.",
  962. messageSends: ["should:return:"],
  963. referencedClasses: []
  964. }),
  965. smalltalk.CodeGeneratorTest);
  966. smalltalk.addMethod(
  967. smalltalk.method({
  968. selector: "testifTrueIfFalse",
  969. category: 'tests',
  970. fn: function (){
  971. var self=this;
  972. return smalltalk.withContext(function($ctx1) {
  973. self._should_return_("foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]",(2));
  974. $ctx1.sendIdx["should:return:"]=1;
  975. self._should_return_("foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]",(1));
  976. $ctx1.sendIdx["should:return:"]=2;
  977. self._should_return_("foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]",(1));
  978. $ctx1.sendIdx["should:return:"]=3;
  979. self._should_return_("foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]",(2));
  980. return self}, function($ctx1) {$ctx1.fill(self,"testifTrueIfFalse",{},smalltalk.CodeGeneratorTest)})},
  981. args: [],
  982. 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.",
  983. messageSends: ["should:return:"],
  984. referencedClasses: []
  985. }),
  986. smalltalk.CodeGeneratorTest);
  987. smalltalk.addClass('InliningCodeGeneratorTest', smalltalk.CodeGeneratorTest, [], 'Compiler-Tests');
  988. smalltalk.addMethod(
  989. smalltalk.method({
  990. selector: "codeGeneratorClass",
  991. category: 'accessing',
  992. fn: function (){
  993. var self=this;
  994. function $InliningCodeGenerator(){return smalltalk.InliningCodeGenerator||(typeof InliningCodeGenerator=="undefined"?nil:InliningCodeGenerator)}
  995. return smalltalk.withContext(function($ctx1) {
  996. return $InliningCodeGenerator();
  997. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{},smalltalk.InliningCodeGeneratorTest)})},
  998. args: [],
  999. source: "codeGeneratorClass\x0a\x09^ InliningCodeGenerator",
  1000. messageSends: [],
  1001. referencedClasses: ["InliningCodeGenerator"]
  1002. }),
  1003. smalltalk.InliningCodeGeneratorTest);
  1004. smalltalk.addClass('InterpreterTest', smalltalk.CodeGeneratorTest, [], 'Compiler-Tests');
  1005. smalltalk.addMethod(
  1006. smalltalk.method({
  1007. selector: "analyze:forClass:",
  1008. category: 'parsing',
  1009. fn: function (aNode,aClass){
  1010. var self=this;
  1011. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1012. return smalltalk.withContext(function($ctx1) {
  1013. _st(_st($SemanticAnalyzer())._on_(aClass))._visit_(aNode);
  1014. return aNode;
  1015. }, function($ctx1) {$ctx1.fill(self,"analyze:forClass:",{aNode:aNode,aClass:aClass},smalltalk.InterpreterTest)})},
  1016. args: ["aNode", "aClass"],
  1017. source: "analyze: aNode forClass: aClass\x0a\x09(SemanticAnalyzer on: aClass) visit: aNode.\x0a\x09^ aNode",
  1018. messageSends: ["visit:", "on:"],
  1019. referencedClasses: ["SemanticAnalyzer"]
  1020. }),
  1021. smalltalk.InterpreterTest);
  1022. smalltalk.addMethod(
  1023. smalltalk.method({
  1024. selector: "interpret:receiver:withArguments:",
  1025. category: 'private',
  1026. fn: function (aString,anObject,aDictionary){
  1027. var self=this;
  1028. var ctx,interpreter;
  1029. function $ASTInterpreter(){return smalltalk.ASTInterpreter||(typeof ASTInterpreter=="undefined"?nil:ASTInterpreter)}
  1030. function $AIContext(){return smalltalk.AIContext||(typeof AIContext=="undefined"?nil:AIContext)}
  1031. return smalltalk.withContext(function($ctx1) {
  1032. var $1,$2,$4,$5,$3;
  1033. interpreter=_st($ASTInterpreter())._new();
  1034. $ctx1.sendIdx["new"]=1;
  1035. $1=_st($AIContext())._new();
  1036. _st($1)._receiver_(anObject);
  1037. _st($1)._interpreter_(interpreter);
  1038. $2=_st($1)._yourself();
  1039. ctx=$2;
  1040. _st(aDictionary)._keysAndValuesDo_((function(key,value){
  1041. return smalltalk.withContext(function($ctx2) {
  1042. return _st(ctx)._localAt_put_(key,value);
  1043. }, function($ctx2) {$ctx2.fillBlock({key:key,value:value},$ctx1,1)})}));
  1044. $4=interpreter;
  1045. _st($4)._context_(ctx);
  1046. _st($4)._interpret_(_st(self._parse_forClass_(aString,_st(anObject)._class()))._nextChild());
  1047. _st($4)._proceed();
  1048. $5=_st($4)._result();
  1049. $3=$5;
  1050. return $3;
  1051. }, function($ctx1) {$ctx1.fill(self,"interpret:receiver:withArguments:",{aString:aString,anObject:anObject,aDictionary:aDictionary,ctx:ctx,interpreter:interpreter},smalltalk.InterpreterTest)})},
  1052. args: ["aString", "anObject", "aDictionary"],
  1053. 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",
  1054. messageSends: ["new", "receiver:", "interpreter:", "yourself", "keysAndValuesDo:", "localAt:put:", "context:", "interpret:", "nextChild", "parse:forClass:", "class", "proceed", "result"],
  1055. referencedClasses: ["ASTInterpreter", "AIContext"]
  1056. }),
  1057. smalltalk.InterpreterTest);
  1058. smalltalk.addMethod(
  1059. smalltalk.method({
  1060. selector: "parse:",
  1061. category: 'parsing',
  1062. fn: function (aString){
  1063. var self=this;
  1064. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1065. return smalltalk.withContext(function($ctx1) {
  1066. var $1;
  1067. $1=_st(_st($Smalltalk())._current())._parse_(aString);
  1068. return $1;
  1069. }, function($ctx1) {$ctx1.fill(self,"parse:",{aString:aString},smalltalk.InterpreterTest)})},
  1070. args: ["aString"],
  1071. source: "parse: aString\x0a\x09^ Smalltalk current parse: aString",
  1072. messageSends: ["parse:", "current"],
  1073. referencedClasses: ["Smalltalk"]
  1074. }),
  1075. smalltalk.InterpreterTest);
  1076. smalltalk.addMethod(
  1077. smalltalk.method({
  1078. selector: "parse:forClass:",
  1079. category: 'parsing',
  1080. fn: function (aString,aClass){
  1081. var self=this;
  1082. return smalltalk.withContext(function($ctx1) {
  1083. var $1;
  1084. $1=self._analyze_forClass_(self._parse_(aString),aClass);
  1085. return $1;
  1086. }, function($ctx1) {$ctx1.fill(self,"parse:forClass:",{aString:aString,aClass:aClass},smalltalk.InterpreterTest)})},
  1087. args: ["aString", "aClass"],
  1088. source: "parse: aString forClass: aClass\x0a\x09^ self analyze: (self parse: aString) forClass: aClass",
  1089. messageSends: ["analyze:forClass:", "parse:"],
  1090. referencedClasses: []
  1091. }),
  1092. smalltalk.InterpreterTest);
  1093. smalltalk.addMethod(
  1094. smalltalk.method({
  1095. selector: "should:receiver:return:",
  1096. category: 'testing',
  1097. fn: function (aString,anObject,aResult){
  1098. var self=this;
  1099. return smalltalk.withContext(function($ctx1) {
  1100. var $1;
  1101. self["@receiver"]=anObject;
  1102. $1=self._assert_equals_(self._interpret_receiver_withArguments_(aString,self["@receiver"],smalltalk.HashedCollection._from_([])),aResult);
  1103. return $1;
  1104. }, function($ctx1) {$ctx1.fill(self,"should:receiver:return:",{aString:aString,anObject:anObject,aResult:aResult},smalltalk.InterpreterTest)})},
  1105. args: ["aString", "anObject", "aResult"],
  1106. 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",
  1107. messageSends: ["assert:equals:", "interpret:receiver:withArguments:"],
  1108. referencedClasses: []
  1109. }),
  1110. smalltalk.InterpreterTest);
  1111. smalltalk.addMethod(
  1112. smalltalk.method({
  1113. selector: "should:return:",
  1114. category: 'testing',
  1115. fn: function (aString,anObject){
  1116. var self=this;
  1117. return smalltalk.withContext(function($ctx1) {
  1118. var $1;
  1119. $1=self._should_receiver_return_(aString,self["@receiver"],anObject);
  1120. return $1;
  1121. }, function($ctx1) {$ctx1.fill(self,"should:return:",{aString:aString,anObject:anObject},smalltalk.InterpreterTest)})},
  1122. args: ["aString", "anObject"],
  1123. source: "should: aString return: anObject\x0a\x09^ self \x0a\x09\x09should: aString\x0a\x09\x09receiver: receiver\x0a\x09\x09return: anObject",
  1124. messageSends: ["should:receiver:return:"],
  1125. referencedClasses: []
  1126. }),
  1127. smalltalk.InterpreterTest);
  1128. smalltalk.addClass('ScopeVarTest', smalltalk.TestCase, [], 'Compiler-Tests');
  1129. smalltalk.addMethod(
  1130. smalltalk.method({
  1131. selector: "testClassRefVar",
  1132. category: 'tests',
  1133. fn: function (){
  1134. var self=this;
  1135. var node;
  1136. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1137. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1138. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1139. return smalltalk.withContext(function($ctx1) {
  1140. var $1,$2,$3,$4;
  1141. $1=_st($VariableNode())._new();
  1142. $ctx1.sendIdx["new"]=1;
  1143. _st($1)._value_("Object");
  1144. $2=_st($1)._yourself();
  1145. node=$2;
  1146. $3=_st($SemanticAnalyzer())._new();
  1147. $ctx1.sendIdx["new"]=2;
  1148. _st($3)._pushScope_(_st($MethodLexicalScope())._new());
  1149. $4=_st($3)._visit_(node);
  1150. self._assert_(_st(_st(node)._binding())._isClassRefVar());
  1151. return self}, function($ctx1) {$ctx1.fill(self,"testClassRefVar",{node:node},smalltalk.ScopeVarTest)})},
  1152. args: [],
  1153. 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",
  1154. messageSends: ["value:", "new", "yourself", "pushScope:", "visit:", "assert:", "isClassRefVar", "binding"],
  1155. referencedClasses: ["VariableNode", "SemanticAnalyzer", "MethodLexicalScope"]
  1156. }),
  1157. smalltalk.ScopeVarTest);
  1158. smalltalk.addMethod(
  1159. smalltalk.method({
  1160. selector: "testInstanceVar",
  1161. category: 'tests',
  1162. fn: function (){
  1163. var self=this;
  1164. var node,scope;
  1165. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1166. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1167. return smalltalk.withContext(function($ctx1) {
  1168. var $1,$2;
  1169. $1=_st($VariableNode())._new();
  1170. $ctx1.sendIdx["new"]=1;
  1171. _st($1)._value_("bzzz");
  1172. $2=_st($1)._yourself();
  1173. node=$2;
  1174. scope=_st($MethodLexicalScope())._new();
  1175. _st(scope)._addIVar_("bzzz");
  1176. self._assert_(_st(_st(scope)._bindingFor_(node))._isInstanceVar());
  1177. return self}, function($ctx1) {$ctx1.fill(self,"testInstanceVar",{node:node,scope:scope},smalltalk.ScopeVarTest)})},
  1178. args: [],
  1179. 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",
  1180. messageSends: ["value:", "new", "yourself", "addIVar:", "assert:", "isInstanceVar", "bindingFor:"],
  1181. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1182. }),
  1183. smalltalk.ScopeVarTest);
  1184. smalltalk.addMethod(
  1185. smalltalk.method({
  1186. selector: "testPseudoVar",
  1187. category: 'tests',
  1188. fn: function (){
  1189. var self=this;
  1190. var node,pseudoVars;
  1191. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1192. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1193. return smalltalk.withContext(function($ctx1) {
  1194. var $1,$2;
  1195. pseudoVars=["self", "super", "true", "false", "nil"];
  1196. _st(pseudoVars)._do_((function(each){
  1197. return smalltalk.withContext(function($ctx2) {
  1198. $1=_st($VariableNode())._new();
  1199. $ctx2.sendIdx["new"]=1;
  1200. _st($1)._value_(each);
  1201. $2=_st($1)._yourself();
  1202. node=$2;
  1203. node;
  1204. return self._assert_(_st(_st(_st($MethodLexicalScope())._new())._bindingFor_(node))._isPseudoVar());
  1205. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1206. return self}, function($ctx1) {$ctx1.fill(self,"testPseudoVar",{node:node,pseudoVars:pseudoVars},smalltalk.ScopeVarTest)})},
  1207. args: [],
  1208. 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 ]",
  1209. messageSends: ["do:", "value:", "new", "yourself", "assert:", "isPseudoVar", "bindingFor:"],
  1210. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1211. }),
  1212. smalltalk.ScopeVarTest);
  1213. smalltalk.addMethod(
  1214. smalltalk.method({
  1215. selector: "testTempVar",
  1216. category: 'tests',
  1217. fn: function (){
  1218. var self=this;
  1219. var node,scope;
  1220. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1221. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1222. return smalltalk.withContext(function($ctx1) {
  1223. var $1,$2;
  1224. $1=_st($VariableNode())._new();
  1225. $ctx1.sendIdx["new"]=1;
  1226. _st($1)._value_("bzzz");
  1227. $2=_st($1)._yourself();
  1228. node=$2;
  1229. scope=_st($MethodLexicalScope())._new();
  1230. _st(scope)._addTemp_("bzzz");
  1231. self._assert_(_st(_st(scope)._bindingFor_(node))._isTempVar());
  1232. return self}, function($ctx1) {$ctx1.fill(self,"testTempVar",{node:node,scope:scope},smalltalk.ScopeVarTest)})},
  1233. args: [],
  1234. 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",
  1235. messageSends: ["value:", "new", "yourself", "addTemp:", "assert:", "isTempVar", "bindingFor:"],
  1236. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1237. }),
  1238. smalltalk.ScopeVarTest);
  1239. smalltalk.addMethod(
  1240. smalltalk.method({
  1241. selector: "testUnknownVar",
  1242. category: 'tests',
  1243. fn: function (){
  1244. var self=this;
  1245. var node;
  1246. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1247. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1248. return smalltalk.withContext(function($ctx1) {
  1249. var $1,$2;
  1250. $1=_st($VariableNode())._new();
  1251. $ctx1.sendIdx["new"]=1;
  1252. _st($1)._value_("bzzz");
  1253. $2=_st($1)._yourself();
  1254. node=$2;
  1255. self._assert_(_st(_st(_st($MethodLexicalScope())._new())._bindingFor_(node))._isNil());
  1256. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVar",{node:node},smalltalk.ScopeVarTest)})},
  1257. args: [],
  1258. source: "testUnknownVar\x0a\x09| node |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09self assert: (MethodLexicalScope new bindingFor: node) isNil",
  1259. messageSends: ["value:", "new", "yourself", "assert:", "isNil", "bindingFor:"],
  1260. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1261. }),
  1262. smalltalk.ScopeVarTest);
  1263. smalltalk.addClass('SemanticAnalyzerTest', smalltalk.TestCase, ['analyzer'], 'Compiler-Tests');
  1264. smalltalk.addMethod(
  1265. smalltalk.method({
  1266. selector: "setUp",
  1267. category: 'running',
  1268. fn: function (){
  1269. var self=this;
  1270. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1271. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  1272. return smalltalk.withContext(function($ctx1) {
  1273. self["@analyzer"]=_st($SemanticAnalyzer())._on_($Object());
  1274. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},smalltalk.SemanticAnalyzerTest)})},
  1275. args: [],
  1276. source: "setUp\x0a\x09analyzer := SemanticAnalyzer on: Object",
  1277. messageSends: ["on:"],
  1278. referencedClasses: ["SemanticAnalyzer", "Object"]
  1279. }),
  1280. smalltalk.SemanticAnalyzerTest);
  1281. smalltalk.addMethod(
  1282. smalltalk.method({
  1283. selector: "testAssignment",
  1284. category: 'tests',
  1285. fn: function (){
  1286. var self=this;
  1287. var src,ast;
  1288. function $InvalidAssignmentError(){return smalltalk.InvalidAssignmentError||(typeof InvalidAssignmentError=="undefined"?nil:InvalidAssignmentError)}
  1289. return smalltalk.withContext(function($ctx1) {
  1290. src="foo self := 1";
  1291. ast=_st(smalltalk)._parse_(src);
  1292. self._should_raise_((function(){
  1293. return smalltalk.withContext(function($ctx2) {
  1294. return _st(self["@analyzer"])._visit_(ast);
  1295. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$InvalidAssignmentError());
  1296. return self}, function($ctx1) {$ctx1.fill(self,"testAssignment",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1297. args: [],
  1298. source: "testAssignment\x0a\x09| src ast |\x0a\x0a\x09src := 'foo self := 1'.\x0a\x09ast := smalltalk parse: src.\x0a\x09self should: [analyzer visit: ast] raise: InvalidAssignmentError",
  1299. messageSends: ["parse:", "should:raise:", "visit:"],
  1300. referencedClasses: ["InvalidAssignmentError"]
  1301. }),
  1302. smalltalk.SemanticAnalyzerTest);
  1303. smalltalk.addMethod(
  1304. smalltalk.method({
  1305. selector: "testNonLocalReturn",
  1306. category: 'tests',
  1307. fn: function (){
  1308. var self=this;
  1309. var src,ast;
  1310. return smalltalk.withContext(function($ctx1) {
  1311. src="foo | a | a + 1. ^ a";
  1312. ast=_st(smalltalk)._parse_(src);
  1313. _st(self["@analyzer"])._visit_(ast);
  1314. self._deny_(_st(_st(ast)._scope())._hasNonLocalReturn());
  1315. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1316. args: [],
  1317. source: "testNonLocalReturn\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. ^ a'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self deny: ast scope hasNonLocalReturn",
  1318. messageSends: ["parse:", "visit:", "deny:", "hasNonLocalReturn", "scope"],
  1319. referencedClasses: []
  1320. }),
  1321. smalltalk.SemanticAnalyzerTest);
  1322. smalltalk.addMethod(
  1323. smalltalk.method({
  1324. selector: "testNonLocalReturn2",
  1325. category: 'tests',
  1326. fn: function (){
  1327. var self=this;
  1328. var src,ast;
  1329. return smalltalk.withContext(function($ctx1) {
  1330. src="foo | a | a + 1. [ [ ^ a] ]";
  1331. ast=_st(smalltalk)._parse_(src);
  1332. _st(self["@analyzer"])._visit_(ast);
  1333. self._assert_(_st(_st(ast)._scope())._hasNonLocalReturn());
  1334. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1335. args: [],
  1336. source: "testNonLocalReturn2\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ [ ^ a] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self assert: ast scope hasNonLocalReturn",
  1337. messageSends: ["parse:", "visit:", "assert:", "hasNonLocalReturn", "scope"],
  1338. referencedClasses: []
  1339. }),
  1340. smalltalk.SemanticAnalyzerTest);
  1341. smalltalk.addMethod(
  1342. smalltalk.method({
  1343. selector: "testScope",
  1344. category: 'tests',
  1345. fn: function (){
  1346. var self=this;
  1347. var src,ast;
  1348. return smalltalk.withContext(function($ctx1) {
  1349. var $4,$3,$2,$1;
  1350. src="foo | a | a + 1. [ | b | b := a ]";
  1351. ast=_st(smalltalk)._parse_(src);
  1352. _st(self["@analyzer"])._visit_(ast);
  1353. $4=_st(_st(_st(ast)._nodes())._first())._nodes();
  1354. $ctx1.sendIdx["nodes"]=1;
  1355. $3=_st($4)._last();
  1356. $2=_st($3)._scope();
  1357. $ctx1.sendIdx["scope"]=1;
  1358. $1=_st($2).__eq_eq(_st(ast)._scope());
  1359. self._deny_($1);
  1360. return self}, function($ctx1) {$ctx1.fill(self,"testScope",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1361. args: [],
  1362. source: "testScope\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ | b | b := a ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self deny: ast nodes first nodes last scope == ast scope.",
  1363. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "last", "nodes", "first"],
  1364. referencedClasses: []
  1365. }),
  1366. smalltalk.SemanticAnalyzerTest);
  1367. smalltalk.addMethod(
  1368. smalltalk.method({
  1369. selector: "testScope2",
  1370. category: 'tests',
  1371. fn: function (){
  1372. var self=this;
  1373. var src,ast;
  1374. return smalltalk.withContext(function($ctx1) {
  1375. var $8,$7,$6,$5,$4,$3,$2,$1;
  1376. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1377. ast=_st(smalltalk)._parse_(src);
  1378. _st(self["@analyzer"])._visit_(ast);
  1379. $8=_st(_st(_st(ast)._nodes())._first())._nodes();
  1380. $ctx1.sendIdx["nodes"]=3;
  1381. $7=_st($8)._last();
  1382. $6=_st($7)._nodes();
  1383. $ctx1.sendIdx["nodes"]=2;
  1384. $5=_st($6)._first();
  1385. $ctx1.sendIdx["first"]=2;
  1386. $4=_st($5)._nodes();
  1387. $ctx1.sendIdx["nodes"]=1;
  1388. $3=_st($4)._first();
  1389. $ctx1.sendIdx["first"]=1;
  1390. $2=_st($3)._scope();
  1391. $ctx1.sendIdx["scope"]=1;
  1392. $1=_st($2).__eq_eq(_st(ast)._scope());
  1393. self._deny_($1);
  1394. return self}, function($ctx1) {$ctx1.fill(self,"testScope2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1395. args: [],
  1396. source: "testScope2\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ [ | b | b := a ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self deny: ast nodes first nodes last nodes first nodes first scope == ast scope.",
  1397. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "first", "nodes", "last"],
  1398. referencedClasses: []
  1399. }),
  1400. smalltalk.SemanticAnalyzerTest);
  1401. smalltalk.addMethod(
  1402. smalltalk.method({
  1403. selector: "testScopeLevel",
  1404. category: 'tests',
  1405. fn: function (){
  1406. var self=this;
  1407. var src,ast;
  1408. return smalltalk.withContext(function($ctx1) {
  1409. var $2,$1,$10,$9,$8,$7,$6,$5,$4,$3;
  1410. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1411. ast=_st(smalltalk)._parse_(src);
  1412. _st(self["@analyzer"])._visit_(ast);
  1413. $2=_st(ast)._scope();
  1414. $ctx1.sendIdx["scope"]=1;
  1415. $1=_st($2)._scopeLevel();
  1416. $ctx1.sendIdx["scopeLevel"]=1;
  1417. self._assert_equals_($1,(1));
  1418. $ctx1.sendIdx["assert:equals:"]=1;
  1419. $10=_st(_st(_st(ast)._nodes())._first())._nodes();
  1420. $ctx1.sendIdx["nodes"]=3;
  1421. $9=_st($10)._last();
  1422. $8=_st($9)._nodes();
  1423. $ctx1.sendIdx["nodes"]=2;
  1424. $7=_st($8)._first();
  1425. $ctx1.sendIdx["first"]=2;
  1426. $6=_st($7)._nodes();
  1427. $ctx1.sendIdx["nodes"]=1;
  1428. $5=_st($6)._first();
  1429. $ctx1.sendIdx["first"]=1;
  1430. $4=_st($5)._scope();
  1431. $3=_st($4)._scopeLevel();
  1432. self._assert_equals_($3,(3));
  1433. return self}, function($ctx1) {$ctx1.fill(self,"testScopeLevel",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1434. args: [],
  1435. source: "testScopeLevel\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ [ | b | b := a ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self assert: ast scope scopeLevel equals: 1.\x0a\x09self assert: ast nodes first nodes last nodes first nodes first scope scopeLevel equals: 3",
  1436. messageSends: ["parse:", "visit:", "assert:equals:", "scopeLevel", "scope", "first", "nodes", "last"],
  1437. referencedClasses: []
  1438. }),
  1439. smalltalk.SemanticAnalyzerTest);
  1440. smalltalk.addMethod(
  1441. smalltalk.method({
  1442. selector: "testUnknownVariables",
  1443. category: 'tests',
  1444. fn: function (){
  1445. var self=this;
  1446. var src,ast;
  1447. function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1448. return smalltalk.withContext(function($ctx1) {
  1449. src="foo | a | b + a";
  1450. ast=_st(smalltalk)._parse_(src);
  1451. self._should_raise_((function(){
  1452. return smalltalk.withContext(function($ctx2) {
  1453. return _st(self["@analyzer"])._visit_(ast);
  1454. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$UnknownVariableError());
  1455. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariables",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1456. args: [],
  1457. source: "testUnknownVariables\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | b + a'.\x0a\x09ast := smalltalk parse: src.\x0a\x0a\x09self should: [ analyzer visit: ast ] raise: UnknownVariableError",
  1458. messageSends: ["parse:", "should:raise:", "visit:"],
  1459. referencedClasses: ["UnknownVariableError"]
  1460. }),
  1461. smalltalk.SemanticAnalyzerTest);
  1462. smalltalk.addMethod(
  1463. smalltalk.method({
  1464. selector: "testUnknownVariablesWithScope",
  1465. category: 'tests',
  1466. fn: function (){
  1467. var self=this;
  1468. var src,ast;
  1469. function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1470. return smalltalk.withContext(function($ctx1) {
  1471. src="foo | a b | [ c + 1. [ a + 1. d + 1 ]]";
  1472. ast=_st(smalltalk)._parse_(src);
  1473. self._should_raise_((function(){
  1474. return smalltalk.withContext(function($ctx2) {
  1475. return _st(self["@analyzer"])._visit_(ast);
  1476. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$UnknownVariableError());
  1477. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariablesWithScope",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1478. args: [],
  1479. source: "testUnknownVariablesWithScope\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a b | [ c + 1. [ a + 1. d + 1 ]]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09\x0a\x09self should: [ analyzer visit: ast ] raise: UnknownVariableError",
  1480. messageSends: ["parse:", "should:raise:", "visit:"],
  1481. referencedClasses: ["UnknownVariableError"]
  1482. }),
  1483. smalltalk.SemanticAnalyzerTest);
  1484. smalltalk.addMethod(
  1485. smalltalk.method({
  1486. selector: "testVariableShadowing",
  1487. category: 'tests',
  1488. fn: function (){
  1489. var self=this;
  1490. var src,ast;
  1491. return smalltalk.withContext(function($ctx1) {
  1492. src="foo | a | a + 1";
  1493. ast=_st(smalltalk)._parse_(src);
  1494. _st(self["@analyzer"])._visit_(ast);
  1495. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1496. args: [],
  1497. source: "testVariableShadowing\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1498. messageSends: ["parse:", "visit:"],
  1499. referencedClasses: []
  1500. }),
  1501. smalltalk.SemanticAnalyzerTest);
  1502. smalltalk.addMethod(
  1503. smalltalk.method({
  1504. selector: "testVariableShadowing2",
  1505. category: 'tests',
  1506. fn: function (){
  1507. var self=this;
  1508. var src,ast;
  1509. function $ShadowingVariableError(){return smalltalk.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1510. return smalltalk.withContext(function($ctx1) {
  1511. src="foo | a | a + 1. [ | a | a := 2 ]";
  1512. ast=_st(smalltalk)._parse_(src);
  1513. self._should_raise_((function(){
  1514. return smalltalk.withContext(function($ctx2) {
  1515. return _st(self["@analyzer"])._visit_(ast);
  1516. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$ShadowingVariableError());
  1517. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1518. args: [],
  1519. source: "testVariableShadowing2\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | a | a := 2 ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09self should: [analyzer visit: ast] raise: ShadowingVariableError",
  1520. messageSends: ["parse:", "should:raise:", "visit:"],
  1521. referencedClasses: ["ShadowingVariableError"]
  1522. }),
  1523. smalltalk.SemanticAnalyzerTest);
  1524. smalltalk.addMethod(
  1525. smalltalk.method({
  1526. selector: "testVariableShadowing3",
  1527. category: 'tests',
  1528. fn: function (){
  1529. var self=this;
  1530. var src,ast;
  1531. return smalltalk.withContext(function($ctx1) {
  1532. src="foo | a | a + 1. [ | b | b := 2 ]";
  1533. ast=_st(smalltalk)._parse_(src);
  1534. _st(self["@analyzer"])._visit_(ast);
  1535. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing3",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1536. args: [],
  1537. source: "testVariableShadowing3\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | b | b := 2 ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1538. messageSends: ["parse:", "visit:"],
  1539. referencedClasses: []
  1540. }),
  1541. smalltalk.SemanticAnalyzerTest);
  1542. smalltalk.addMethod(
  1543. smalltalk.method({
  1544. selector: "testVariableShadowing4",
  1545. category: 'tests',
  1546. fn: function (){
  1547. var self=this;
  1548. var src,ast;
  1549. return smalltalk.withContext(function($ctx1) {
  1550. src="foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]";
  1551. ast=_st(smalltalk)._parse_(src);
  1552. _st(self["@analyzer"])._visit_(ast);
  1553. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing4",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1554. args: [],
  1555. source: "testVariableShadowing4\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1556. messageSends: ["parse:", "visit:"],
  1557. referencedClasses: []
  1558. }),
  1559. smalltalk.SemanticAnalyzerTest);
  1560. smalltalk.addMethod(
  1561. smalltalk.method({
  1562. selector: "testVariableShadowing5",
  1563. category: 'tests',
  1564. fn: function (){
  1565. var self=this;
  1566. var src,ast;
  1567. function $ShadowingVariableError(){return smalltalk.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1568. return smalltalk.withContext(function($ctx1) {
  1569. src="foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]";
  1570. ast=_st(smalltalk)._parse_(src);
  1571. self._should_raise_((function(){
  1572. return smalltalk.withContext(function($ctx2) {
  1573. return _st(self["@analyzer"])._visit_(ast);
  1574. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$ShadowingVariableError());
  1575. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing5",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1576. args: [],
  1577. source: "testVariableShadowing5\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09self should: [analyzer visit: ast] raise: ShadowingVariableError",
  1578. messageSends: ["parse:", "should:raise:", "visit:"],
  1579. referencedClasses: ["ShadowingVariableError"]
  1580. }),
  1581. smalltalk.SemanticAnalyzerTest);
  1582. smalltalk.addMethod(
  1583. smalltalk.method({
  1584. selector: "testVariablesLookup",
  1585. category: 'tests',
  1586. fn: function (){
  1587. var self=this;
  1588. var src,ast;
  1589. return smalltalk.withContext(function($ctx1) {
  1590. 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;
  1591. src="foo | a | a + 1. [ | b | b := a ]";
  1592. ast=_st(smalltalk)._parse_(src);
  1593. _st(self["@analyzer"])._visit_(ast);
  1594. $7=_st(ast)._nodes();
  1595. $ctx1.sendIdx["nodes"]=2;
  1596. $6=_st($7)._first();
  1597. $ctx1.sendIdx["first"]=2;
  1598. $5=_st($6)._nodes();
  1599. $ctx1.sendIdx["nodes"]=1;
  1600. $4=_st($5)._first();
  1601. $ctx1.sendIdx["first"]=1;
  1602. $3=_st($4)._receiver();
  1603. $ctx1.sendIdx["receiver"]=1;
  1604. $2=_st($3)._binding();
  1605. $ctx1.sendIdx["binding"]=1;
  1606. $1=_st($2)._isTempVar();
  1607. $ctx1.sendIdx["isTempVar"]=1;
  1608. self._assert_($1);
  1609. $ctx1.sendIdx["assert:"]=1;
  1610. $15=_st(ast)._nodes();
  1611. $ctx1.sendIdx["nodes"]=4;
  1612. $14=_st($15)._first();
  1613. $ctx1.sendIdx["first"]=4;
  1614. $13=_st($14)._nodes();
  1615. $ctx1.sendIdx["nodes"]=3;
  1616. $12=_st($13)._first();
  1617. $ctx1.sendIdx["first"]=3;
  1618. $11=_st($12)._receiver();
  1619. $10=_st($11)._binding();
  1620. $ctx1.sendIdx["binding"]=2;
  1621. $9=_st($10)._scope();
  1622. $ctx1.sendIdx["scope"]=1;
  1623. $16=_st(ast)._scope();
  1624. $ctx1.sendIdx["scope"]=2;
  1625. $8=_st($9).__eq_eq($16);
  1626. $ctx1.sendIdx["=="]=1;
  1627. self._assert_($8);
  1628. $ctx1.sendIdx["assert:"]=2;
  1629. $27=_st(ast)._nodes();
  1630. $ctx1.sendIdx["nodes"]=8;
  1631. $26=_st($27)._first();
  1632. $ctx1.sendIdx["first"]=7;
  1633. $25=_st($26)._nodes();
  1634. $ctx1.sendIdx["nodes"]=7;
  1635. $24=_st($25)._last();
  1636. $ctx1.sendIdx["last"]=1;
  1637. $23=_st($24)._nodes();
  1638. $ctx1.sendIdx["nodes"]=6;
  1639. $22=_st($23)._first();
  1640. $ctx1.sendIdx["first"]=6;
  1641. $21=_st($22)._nodes();
  1642. $ctx1.sendIdx["nodes"]=5;
  1643. $20=_st($21)._first();
  1644. $ctx1.sendIdx["first"]=5;
  1645. $19=_st($20)._left();
  1646. $ctx1.sendIdx["left"]=1;
  1647. $18=_st($19)._binding();
  1648. $ctx1.sendIdx["binding"]=3;
  1649. $17=_st($18)._isTempVar();
  1650. self._assert_($17);
  1651. $ctx1.sendIdx["assert:"]=3;
  1652. $39=_st(ast)._nodes();
  1653. $ctx1.sendIdx["nodes"]=12;
  1654. $38=_st($39)._first();
  1655. $ctx1.sendIdx["first"]=10;
  1656. $37=_st($38)._nodes();
  1657. $ctx1.sendIdx["nodes"]=11;
  1658. $36=_st($37)._last();
  1659. $ctx1.sendIdx["last"]=2;
  1660. $35=_st($36)._nodes();
  1661. $ctx1.sendIdx["nodes"]=10;
  1662. $34=_st($35)._first();
  1663. $ctx1.sendIdx["first"]=9;
  1664. $33=_st($34)._nodes();
  1665. $ctx1.sendIdx["nodes"]=9;
  1666. $32=_st($33)._first();
  1667. $ctx1.sendIdx["first"]=8;
  1668. $31=_st($32)._left();
  1669. $30=_st($31)._binding();
  1670. $29=_st($30)._scope();
  1671. $ctx1.sendIdx["scope"]=3;
  1672. $42=_st(_st(_st(ast)._nodes())._first())._nodes();
  1673. $ctx1.sendIdx["nodes"]=13;
  1674. $41=_st($42)._last();
  1675. $40=_st($41)._scope();
  1676. $28=_st($29).__eq_eq($40);
  1677. self._assert_($28);
  1678. return self}, function($ctx1) {$ctx1.fill(self,"testVariablesLookup",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1679. args: [],
  1680. source: "testVariablesLookup\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ | b | b := a ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09\x22Binding for `a` in the message send\x22\x0a\x09self assert: ast nodes first nodes first receiver binding isTempVar.\x0a\x09self assert: ast nodes first nodes first receiver binding scope == ast scope.\x0a\x0a\x09\x22Binding for `b`\x22\x0a\x09self assert: ast nodes first nodes last nodes first nodes first left binding isTempVar.\x0a\x09self assert: ast nodes first nodes last nodes first nodes first left binding scope == ast nodes first nodes last scope.",
  1681. messageSends: ["parse:", "visit:", "assert:", "isTempVar", "binding", "receiver", "first", "nodes", "==", "scope", "left", "last"],
  1682. referencedClasses: []
  1683. }),
  1684. smalltalk.SemanticAnalyzerTest);
  1685. });