Compiler-Tests.js 67 KB

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