Compiler-Tests.js 74 KB

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