Compiler-Tests.js 75 KB

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