Compiler-Tests.js 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670
  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('ASTVisitorTest', 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.ASTVisitorTest)})},
  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.ASTVisitorTest);
  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.ASTVisitorTest)})},
  36. args: ["aString"],
  37. source: "parse: aString\x0a\x09^ Smalltalk current parse: aString",
  38. messageSends: ["parse:", "current"],
  39. referencedClasses: ["Smalltalk"]
  40. }),
  41. smalltalk.ASTVisitorTest);
  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.ASTVisitorTest)})},
  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.ASTVisitorTest);
  59. smalltalk.addClass('ASTPCNodeVisitorTest', smalltalk.ASTVisitorTest, [], '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('AbstractASTInterpreterTest', smalltalk.ASTVisitorTest, [], 'Compiler-Tests');
  219. smalltalk.addMethod(
  220. smalltalk.method({
  221. selector: "interpret:",
  222. category: 'interpreting',
  223. fn: function (aString){
  224. var self=this;
  225. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  226. return smalltalk.withContext(function($ctx1) {
  227. var $1;
  228. $1=self._interpret_withArguments_(aString,_st($Dictionary())._new());
  229. return $1;
  230. }, function($ctx1) {$ctx1.fill(self,"interpret:",{aString:aString},smalltalk.AbstractASTInterpreterTest)})},
  231. args: ["aString"],
  232. source: "interpret: aString\x0a\x09^ self\x0a\x09\x09interpret: aString\x0a\x09\x09withArguments: Dictionary new",
  233. messageSends: ["interpret:withArguments:", "new"],
  234. referencedClasses: ["Dictionary"]
  235. }),
  236. smalltalk.AbstractASTInterpreterTest);
  237. smalltalk.addMethod(
  238. smalltalk.method({
  239. selector: "interpret:receiver:withArguments:",
  240. category: 'interpreting',
  241. fn: function (aString,anObject,aDictionary){
  242. var self=this;
  243. var ctx;
  244. function $AIContext(){return smalltalk.AIContext||(typeof AIContext=="undefined"?nil:AIContext)}
  245. return smalltalk.withContext(function($ctx1) {
  246. var $2,$3,$1;
  247. ctx=_st($AIContext())._new();
  248. _st(ctx)._receiver_(anObject);
  249. _st(aDictionary)._keysAndValuesDo_((function(key,value){
  250. return smalltalk.withContext(function($ctx2) {
  251. return _st(ctx)._localAt_put_(key,value);
  252. }, function($ctx2) {$ctx2.fillBlock({key:key,value:value},$ctx1)})}));
  253. $2=self._interpreter();
  254. _st($2)._context_(ctx);
  255. _st($2)._interpret_(_st(_st(self._parse_forClass_(aString,_st(anObject)._class()))._nodes())._first());
  256. $3=_st($2)._result();
  257. $1=$3;
  258. return $1;
  259. }, function($ctx1) {$ctx1.fill(self,"interpret:receiver:withArguments:",{aString:aString,anObject:anObject,aDictionary:aDictionary,ctx:ctx},smalltalk.AbstractASTInterpreterTest)})},
  260. args: ["aString", "anObject", "aDictionary"],
  261. source: "interpret: aString receiver: anObject withArguments: aDictionary\x0a\x09\x22The food is a methodNode. Interpret the sequenceNode only\x22\x0a\x09\x0a\x09| ctx |\x0a\x09\x0a\x09ctx := AIContext new.\x0a\x09ctx receiver: anObject.\x0a\x09aDictionary keysAndValuesDo: [ :key :value |\x0a\x09\x09ctx localAt: key put: value ].\x0a\x09\x0a\x09^ self interpreter\x0a\x09\x09context: ctx;\x0a\x09\x09interpret: (self parse: aString forClass: anObject class)\x0a\x09\x09\x09nodes first;\x0a\x09\x09result",
  262. messageSends: ["new", "receiver:", "keysAndValuesDo:", "localAt:put:", "context:", "interpreter", "interpret:", "first", "nodes", "parse:forClass:", "class", "result"],
  263. referencedClasses: ["AIContext"]
  264. }),
  265. smalltalk.AbstractASTInterpreterTest);
  266. smalltalk.addMethod(
  267. smalltalk.method({
  268. selector: "interpret:withArguments:",
  269. category: 'interpreting',
  270. fn: function (aString,aDictionary){
  271. var self=this;
  272. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  273. return smalltalk.withContext(function($ctx1) {
  274. var $1;
  275. $1=self._interpret_receiver_withArguments_(aString,_st($Object())._new(),aDictionary);
  276. return $1;
  277. }, function($ctx1) {$ctx1.fill(self,"interpret:withArguments:",{aString:aString,aDictionary:aDictionary},smalltalk.AbstractASTInterpreterTest)})},
  278. args: ["aString", "aDictionary"],
  279. source: "interpret: aString withArguments: aDictionary\x0a\x09^ self\x0a\x09\x09interpret: aString\x0a\x09\x09receiver: Object new\x0a\x09\x09withArguments: aDictionary",
  280. messageSends: ["interpret:receiver:withArguments:", "new"],
  281. referencedClasses: ["Object"]
  282. }),
  283. smalltalk.AbstractASTInterpreterTest);
  284. smalltalk.addMethod(
  285. smalltalk.method({
  286. selector: "interpreter",
  287. category: 'accessing',
  288. fn: function (){
  289. var self=this;
  290. return smalltalk.withContext(function($ctx1) {
  291. var $1;
  292. $1=self._subclassResponsibility();
  293. return $1;
  294. }, function($ctx1) {$ctx1.fill(self,"interpreter",{},smalltalk.AbstractASTInterpreterTest)})},
  295. args: [],
  296. source: "interpreter\x0a\x09^ self subclassResponsibility",
  297. messageSends: ["subclassResponsibility"],
  298. referencedClasses: []
  299. }),
  300. smalltalk.AbstractASTInterpreterTest);
  301. smalltalk.addClass('ASTInterpreterTest', smalltalk.AbstractASTInterpreterTest, [], 'Compiler-Tests');
  302. smalltalk.addMethod(
  303. smalltalk.method({
  304. selector: "interpreter",
  305. category: 'accessing',
  306. fn: function (){
  307. var self=this;
  308. function $ASTInterpreter(){return smalltalk.ASTInterpreter||(typeof ASTInterpreter=="undefined"?nil:ASTInterpreter)}
  309. return smalltalk.withContext(function($ctx1) {
  310. var $1;
  311. $1=_st($ASTInterpreter())._new();
  312. return $1;
  313. }, function($ctx1) {$ctx1.fill(self,"interpreter",{},smalltalk.ASTInterpreterTest)})},
  314. args: [],
  315. source: "interpreter\x0a\x09^ ASTInterpreter new",
  316. messageSends: ["new"],
  317. referencedClasses: ["ASTInterpreter"]
  318. }),
  319. smalltalk.ASTInterpreterTest);
  320. smalltalk.addMethod(
  321. smalltalk.method({
  322. selector: "testBinarySend",
  323. category: 'tests',
  324. fn: function (){
  325. var self=this;
  326. return smalltalk.withContext(function($ctx1) {
  327. self._assert_equals_(self._interpret_("foo 2+3+4"),(9));
  328. return self}, function($ctx1) {$ctx1.fill(self,"testBinarySend",{},smalltalk.ASTInterpreterTest)})},
  329. args: [],
  330. source: "testBinarySend\x0a\x09self assert: (self interpret: 'foo 2+3+4') equals: 9",
  331. messageSends: ["assert:equals:", "interpret:"],
  332. referencedClasses: []
  333. }),
  334. smalltalk.ASTInterpreterTest);
  335. smalltalk.addMethod(
  336. smalltalk.method({
  337. selector: "testBlockLiteral",
  338. category: 'tests',
  339. fn: function (){
  340. var self=this;
  341. return smalltalk.withContext(function($ctx1) {
  342. self._assert_equals_(self._interpret_("foo ^ true ifTrue: [ 1 ] ifFalse: [ 2 ]"),(1));
  343. self._assert_equals_(self._interpret_("foo true ifTrue: [ ^ 1 ] ifFalse: [ 2 ]"),(1));
  344. self._assert_equals_(self._interpret_("foo ^ false ifTrue: [ 1 ] ifFalse: [ 2 ]"),(2));
  345. return self}, function($ctx1) {$ctx1.fill(self,"testBlockLiteral",{},smalltalk.ASTInterpreterTest)})},
  346. args: [],
  347. source: "testBlockLiteral\x0a\x09self assert: (self interpret: 'foo ^ true ifTrue: [ 1 ] ifFalse: [ 2 ]') equals: 1.\x0a\x09self assert: (self interpret: 'foo true ifTrue: [ ^ 1 ] ifFalse: [ 2 ]') equals: 1.\x0a\x09self assert: (self interpret: 'foo ^ false ifTrue: [ 1 ] ifFalse: [ 2 ]') equals: 2",
  348. messageSends: ["assert:equals:", "interpret:"],
  349. referencedClasses: []
  350. }),
  351. smalltalk.ASTInterpreterTest);
  352. smalltalk.addMethod(
  353. smalltalk.method({
  354. selector: "testCascade",
  355. category: 'tests',
  356. fn: function (){
  357. var self=this;
  358. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  359. return smalltalk.withContext(function($ctx1) {
  360. self._assert_equals_(self._interpret_("foo ^ OrderedCollection new add: 2; add: 3; yourself"),_st($OrderedCollection())._with_with_((2),(3)));
  361. return self}, function($ctx1) {$ctx1.fill(self,"testCascade",{},smalltalk.ASTInterpreterTest)})},
  362. args: [],
  363. source: "testCascade\x0a\x09self assert: (self interpret: 'foo ^ OrderedCollection new add: 2; add: 3; yourself') equals: (OrderedCollection with: 2 with: 3)",
  364. messageSends: ["assert:equals:", "interpret:", "with:with:"],
  365. referencedClasses: ["OrderedCollection"]
  366. }),
  367. smalltalk.ASTInterpreterTest);
  368. smalltalk.addMethod(
  369. smalltalk.method({
  370. selector: "testDynamicArray",
  371. category: 'tests',
  372. fn: function (){
  373. var self=this;
  374. return smalltalk.withContext(function($ctx1) {
  375. self._assert_equals_(self._interpret_("foo ^ {1+1. 2+2}"),[(2), (4)]);
  376. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicArray",{},smalltalk.ASTInterpreterTest)})},
  377. args: [],
  378. source: "testDynamicArray\x0a\x09self assert: (self interpret: 'foo ^ {1+1. 2+2}') equals: #(2 4)",
  379. messageSends: ["assert:equals:", "interpret:"],
  380. referencedClasses: []
  381. }),
  382. smalltalk.ASTInterpreterTest);
  383. smalltalk.addMethod(
  384. smalltalk.method({
  385. selector: "testDynamicDictionary",
  386. category: 'tests',
  387. fn: function (){
  388. var self=this;
  389. return smalltalk.withContext(function($ctx1) {
  390. self._assert_equals_(self._interpret_("foo ^ #{1->1. 2->3}"),smalltalk.HashedCollection._from_([(1).__minus_gt((1)),(2).__minus_gt((3))]));
  391. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicDictionary",{},smalltalk.ASTInterpreterTest)})},
  392. args: [],
  393. source: "testDynamicDictionary\x0a\x09self assert: (self interpret: 'foo ^ #{1->1. 2->3}') equals: #{1->1. 2->3}",
  394. messageSends: ["assert:equals:", "interpret:", "->"],
  395. referencedClasses: []
  396. }),
  397. smalltalk.ASTInterpreterTest);
  398. smalltalk.addMethod(
  399. smalltalk.method({
  400. selector: "testInlinedJSStatement",
  401. category: 'tests',
  402. fn: function (){
  403. var self=this;
  404. return smalltalk.withContext(function($ctx1) {
  405. self._assert_equals_(self._interpret_("foo <return 2+3>"),(5));
  406. self._assert_equals_(self._interpret_withArguments_("foo: anInteger <return 2 + anInteger>",smalltalk.HashedCollection._from_(["anInteger".__minus_gt((3))])),(5));
  407. return self}, function($ctx1) {$ctx1.fill(self,"testInlinedJSStatement",{},smalltalk.ASTInterpreterTest)})},
  408. args: [],
  409. source: "testInlinedJSStatement\x0a\x09self assert: (self interpret: 'foo <return 2+3>') equals: 5.\x0a\x09\x0a\x09self\x0a\x09\x09assert: (self\x0a\x09\x09\x09interpret: 'foo: anInteger <return 2 + anInteger>'\x0a\x09\x09\x09withArguments: #{ 'anInteger' -> 3})\x0a\x09\x09equals: 5",
  410. messageSends: ["assert:equals:", "interpret:", "interpret:withArguments:", "->"],
  411. referencedClasses: []
  412. }),
  413. smalltalk.ASTInterpreterTest);
  414. smalltalk.addMethod(
  415. smalltalk.method({
  416. selector: "testInstVarAccess",
  417. category: 'tests',
  418. fn: function (){
  419. var self=this;
  420. return smalltalk.withContext(function($ctx1) {
  421. self._assert_equals_(self._interpret_receiver_withArguments_("foo ^ x",(2).__at((3)),smalltalk.HashedCollection._from_([])),(2));
  422. return self}, function($ctx1) {$ctx1.fill(self,"testInstVarAccess",{},smalltalk.ASTInterpreterTest)})},
  423. args: [],
  424. source: "testInstVarAccess\x0a\x09self\x0a\x09\x09assert: (self\x0a\x09\x09\x09interpret: 'foo ^ x'\x0a\x09\x09\x09receiver: 2@3\x0a\x09\x09\x09withArguments: #{})\x0a\x09\x09equals: 2",
  425. messageSends: ["assert:equals:", "interpret:receiver:withArguments:", "@"],
  426. referencedClasses: []
  427. }),
  428. smalltalk.ASTInterpreterTest);
  429. smalltalk.addMethod(
  430. smalltalk.method({
  431. selector: "testInstVarAssignment",
  432. category: 'tests',
  433. fn: function (){
  434. var self=this;
  435. function $Point(){return smalltalk.Point||(typeof Point=="undefined"?nil:Point)}
  436. return smalltalk.withContext(function($ctx1) {
  437. self._assert_equals_(self._interpret_receiver_withArguments_("foo: anInteger x := anInteger. ^ x",_st($Point())._new(),smalltalk.HashedCollection._from_(["anInteger".__minus_gt((2))])),(2));
  438. return self}, function($ctx1) {$ctx1.fill(self,"testInstVarAssignment",{},smalltalk.ASTInterpreterTest)})},
  439. args: [],
  440. source: "testInstVarAssignment\x0a\x09self\x0a\x09\x09assert: (self\x0a\x09\x09\x09interpret: 'foo: anInteger x := anInteger. ^ x'\x0a\x09\x09\x09receiver: Point new\x0a\x09\x09\x09withArguments: #{'anInteger' -> 2})\x0a\x09\x09equals: 2",
  441. messageSends: ["assert:equals:", "interpret:receiver:withArguments:", "new", "->"],
  442. referencedClasses: ["Point"]
  443. }),
  444. smalltalk.ASTInterpreterTest);
  445. smalltalk.addMethod(
  446. smalltalk.method({
  447. selector: "testNonlocalReturn",
  448. category: 'tests',
  449. fn: function (){
  450. var self=this;
  451. return smalltalk.withContext(function($ctx1) {
  452. self._assert_equals_(self._interpret_("foo true ifTrue: [ ^ 1 ]. ^2"),(1));
  453. return self}, function($ctx1) {$ctx1.fill(self,"testNonlocalReturn",{},smalltalk.ASTInterpreterTest)})},
  454. args: [],
  455. source: "testNonlocalReturn\x0a\x09self assert: (self interpret: 'foo true ifTrue: [ ^ 1 ]. ^2') equals: 1",
  456. messageSends: ["assert:equals:", "interpret:"],
  457. referencedClasses: []
  458. }),
  459. smalltalk.ASTInterpreterTest);
  460. smalltalk.addMethod(
  461. smalltalk.method({
  462. selector: "testReceiver",
  463. category: 'tests',
  464. fn: function (){
  465. var self=this;
  466. return smalltalk.withContext(function($ctx1) {
  467. self._assert_equals_(self._interpret_receiver_withArguments_("foo ^ self",(2).__at((3)),smalltalk.HashedCollection._from_([])),(2).__at((3)));
  468. return self}, function($ctx1) {$ctx1.fill(self,"testReceiver",{},smalltalk.ASTInterpreterTest)})},
  469. args: [],
  470. source: "testReceiver\x0a\x09self\x0a\x09\x09assert: (self\x0a\x09\x09\x09interpret: 'foo ^ self'\x0a\x09\x09\x09receiver: 2@3\x0a\x09\x09\x09withArguments: #{})\x0a\x09\x09equals: 2@3",
  471. messageSends: ["assert:equals:", "interpret:receiver:withArguments:", "@"],
  472. referencedClasses: []
  473. }),
  474. smalltalk.ASTInterpreterTest);
  475. smalltalk.addMethod(
  476. smalltalk.method({
  477. selector: "testSuper",
  478. category: 'tests',
  479. fn: function (){
  480. var self=this;
  481. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  482. return smalltalk.withContext(function($ctx1) {
  483. self._assert_equals_(self._interpret_receiver_withArguments_("foo ^ super isBoolean",true,_st($Dictionary())._new()),false);
  484. return self}, function($ctx1) {$ctx1.fill(self,"testSuper",{},smalltalk.ASTInterpreterTest)})},
  485. args: [],
  486. source: "testSuper\x0a\x09self \x0a\x09\x09assert: (self \x0a\x09\x09\x09interpret: 'foo ^ super isBoolean' \x0a\x09\x09\x09receiver: true \x0a\x09\x09\x09withArguments: Dictionary new) \x0a\x09\x09equals: false",
  487. messageSends: ["assert:equals:", "interpret:receiver:withArguments:", "new"],
  488. referencedClasses: ["Dictionary"]
  489. }),
  490. smalltalk.ASTInterpreterTest);
  491. smalltalk.addMethod(
  492. smalltalk.method({
  493. selector: "testTempAssignment",
  494. category: 'tests',
  495. fn: function (){
  496. var self=this;
  497. return smalltalk.withContext(function($ctx1) {
  498. self._assert_equals_(self._interpret_("foo | a | a := 2. ^ a"),(2));
  499. return self}, function($ctx1) {$ctx1.fill(self,"testTempAssignment",{},smalltalk.ASTInterpreterTest)})},
  500. args: [],
  501. source: "testTempAssignment\x0a\x09self assert: (self interpret: 'foo | a | a := 2. ^ a') equals: 2",
  502. messageSends: ["assert:equals:", "interpret:"],
  503. referencedClasses: []
  504. }),
  505. smalltalk.ASTInterpreterTest);
  506. smalltalk.addMethod(
  507. smalltalk.method({
  508. selector: "testThisContext",
  509. category: 'tests',
  510. fn: function (){
  511. var self=this;
  512. return smalltalk.withContext(function($ctx1) {
  513. self._assert_(_st(_st(self._interpret_("foo ^ thisContext"))._outerContext())._isNil());
  514. self._assert_(_st(_st(self._interpret_("foo ^ [ thisContext ] value"))._outerContext())._notNil());
  515. self._assert_(self._interpret_("foo ^ [ thisContext ] value outerContext == thisContext"));
  516. return self}, function($ctx1) {$ctx1.fill(self,"testThisContext",{},smalltalk.ASTInterpreterTest)})},
  517. args: [],
  518. source: "testThisContext\x0a\x09self assert: (self interpret: 'foo ^ thisContext') outerContext isNil.\x0a\x09self assert: (self interpret: 'foo ^ [ thisContext ] value') outerContext notNil.\x0a\x09self assert: (self interpret: 'foo ^ [ thisContext ] value outerContext == thisContext')",
  519. messageSends: ["assert:", "isNil", "outerContext", "interpret:", "notNil"],
  520. referencedClasses: []
  521. }),
  522. smalltalk.ASTInterpreterTest);
  523. smalltalk.addClass('ASTSteppingInterpreterTest', smalltalk.AbstractASTInterpreterTest, ['interpreter'], 'Compiler-Tests');
  524. smalltalk.addMethod(
  525. smalltalk.method({
  526. selector: "interpreter",
  527. category: 'accessing',
  528. fn: function (){
  529. var self=this;
  530. function $ASTSteppingInterpreter(){return smalltalk.ASTSteppingInterpreter||(typeof ASTSteppingInterpreter=="undefined"?nil:ASTSteppingInterpreter)}
  531. return smalltalk.withContext(function($ctx1) {
  532. var $2,$1;
  533. $2=self["@interpreter"];
  534. if(($receiver = $2) == nil || $receiver == undefined){
  535. self["@interpreter"]=_st($ASTSteppingInterpreter())._new();
  536. $1=self["@interpreter"];
  537. } else {
  538. $1=$2;
  539. };
  540. return $1;
  541. }, function($ctx1) {$ctx1.fill(self,"interpreter",{},smalltalk.ASTSteppingInterpreterTest)})},
  542. args: [],
  543. source: "interpreter\x0a\x09^ interpreter ifNil: [ interpreter := ASTSteppingInterpreter new ]",
  544. messageSends: ["ifNil:", "new"],
  545. referencedClasses: ["ASTSteppingInterpreter"]
  546. }),
  547. smalltalk.ASTSteppingInterpreterTest);
  548. smalltalk.addMethod(
  549. smalltalk.method({
  550. selector: "testAtEnd",
  551. category: 'tests',
  552. fn: function (){
  553. var self=this;
  554. return smalltalk.withContext(function($ctx1) {
  555. self._interpret_("foo 1 + 2");
  556. self._deny_(_st(self._interpreter())._atEnd());
  557. _st(self._interpreter())._step();
  558. self._deny_(_st(self._interpreter())._atEnd());
  559. _st(self._interpreter())._step();
  560. self._deny_(_st(self._interpreter())._atEnd());
  561. _st(self._interpreter())._step();
  562. self._deny_(_st(self._interpreter())._atEnd());
  563. _st(self._interpreter())._step();
  564. self._assert_(_st(self._interpreter())._atEnd());
  565. return self}, function($ctx1) {$ctx1.fill(self,"testAtEnd",{},smalltalk.ASTSteppingInterpreterTest)})},
  566. args: [],
  567. source: "testAtEnd\x0a\x09self interpret: 'foo 1 + 2'.\x0a\x09self deny: self interpreter atEnd.\x0a\x0a\x09self interpreter step.\x0a\x09self deny: self interpreter atEnd.\x0a\x09\x0a\x09self interpreter step.\x0a\x09self deny: self interpreter atEnd.\x0a\x09\x0a\x09self interpreter step.\x0a\x09self deny: self interpreter atEnd.\x0a\x09\x0a\x09self interpreter step.\x0a\x09self assert: self interpreter atEnd",
  568. messageSends: ["interpret:", "deny:", "atEnd", "interpreter", "step", "assert:"],
  569. referencedClasses: []
  570. }),
  571. smalltalk.ASTSteppingInterpreterTest);
  572. smalltalk.addMethod(
  573. smalltalk.method({
  574. selector: "testMessageSend",
  575. category: 'tests',
  576. fn: function (){
  577. var self=this;
  578. return smalltalk.withContext(function($ctx1) {
  579. self._interpret_("foo 1 + 2");
  580. _st(self._interpreter())._step();
  581. _st(self._interpreter())._step();
  582. _st(self._interpreter())._step();
  583. self._assert_equals_(_st(_st(self._interpreter())._currentNode())._value(),(1));
  584. _st(self._interpreter())._step();
  585. self._assert_equals_(_st(_st(self._interpreter())._currentNode())._value(),(2));
  586. _st(self._interpreter())._step();
  587. self._assert_equals_(_st(self._interpreter())._result(),(3));
  588. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSend",{},smalltalk.ASTSteppingInterpreterTest)})},
  589. args: [],
  590. source: "testMessageSend\x0a\x09self interpret: 'foo 1 + 2'.\x0a\x09\x0a\x09\x22SequenceNode\x22\x0a\x09self interpreter step.\x0a\x09\x0a\x09\x22SendNode\x22\x0a\x09self interpreter step.\x0a\x09\x0a\x09\x22ValueNode\x22\x0a\x09self interpreter step.\x0a\x09self assert: self interpreter currentNode value equals: 1.\x0a\x09\x0a\x09\x22ValueNode\x22\x0a\x09self interpreter step.\x0a\x09self assert: self interpreter currentNode value equals: 2.\x0a\x09\x0a\x09\x22Result\x22\x0a\x09self interpreter step.\x0a\x09self assert: self interpreter result equals: 3",
  591. messageSends: ["interpret:", "step", "interpreter", "assert:equals:", "value", "currentNode", "result"],
  592. referencedClasses: []
  593. }),
  594. smalltalk.ASTSteppingInterpreterTest);
  595. smalltalk.addMethod(
  596. smalltalk.method({
  597. selector: "testSimpleStepping",
  598. category: 'tests',
  599. fn: function (){
  600. var self=this;
  601. return smalltalk.withContext(function($ctx1) {
  602. self._interpret_("foo 1");
  603. _st(self._interpreter())._step();
  604. self._assert_(_st(_st(self._interpreter())._result())._isNil());
  605. _st(self._interpreter())._step();
  606. self._assert_equals_(_st(self._interpreter())._result(),(1));
  607. return self}, function($ctx1) {$ctx1.fill(self,"testSimpleStepping",{},smalltalk.ASTSteppingInterpreterTest)})},
  608. args: [],
  609. source: "testSimpleStepping\x0a\x09self interpret: 'foo 1'.\x0a\x09\x0a\x09\x22SequenceNode\x22\x0a\x09self interpreter step.\x0a\x09\x0a\x09self assert: self interpreter result isNil.\x0a\x09\x0a\x09\x22ValueNode\x22\x0a\x09self interpreter step.\x0a\x09\x0a\x09self assert: self interpreter result equals: 1",
  610. messageSends: ["interpret:", "step", "interpreter", "assert:", "isNil", "result", "assert:equals:"],
  611. referencedClasses: []
  612. }),
  613. smalltalk.ASTSteppingInterpreterTest);
  614. smalltalk.addClass('CodeGeneratorTest', smalltalk.TestCase, ['receiver'], 'Compiler-Tests');
  615. smalltalk.addMethod(
  616. smalltalk.method({
  617. selector: "codeGeneratorClass",
  618. category: 'accessing',
  619. fn: function (){
  620. var self=this;
  621. function $CodeGenerator(){return smalltalk.CodeGenerator||(typeof CodeGenerator=="undefined"?nil:CodeGenerator)}
  622. return smalltalk.withContext(function($ctx1) {
  623. var $1;
  624. $1=$CodeGenerator();
  625. return $1;
  626. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{},smalltalk.CodeGeneratorTest)})},
  627. args: [],
  628. source: "codeGeneratorClass\x0a\x09^ CodeGenerator",
  629. messageSends: [],
  630. referencedClasses: ["CodeGenerator"]
  631. }),
  632. smalltalk.CodeGeneratorTest);
  633. smalltalk.addMethod(
  634. smalltalk.method({
  635. selector: "compiler",
  636. category: 'factory',
  637. fn: function (){
  638. var self=this;
  639. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  640. return smalltalk.withContext(function($ctx1) {
  641. var $2,$3,$1;
  642. $2=_st($Compiler())._new();
  643. _st($2)._codeGeneratorClass_(self._codeGeneratorClass());
  644. $3=_st($2)._yourself();
  645. $1=$3;
  646. return $1;
  647. }, function($ctx1) {$ctx1.fill(self,"compiler",{},smalltalk.CodeGeneratorTest)})},
  648. args: [],
  649. source: "compiler\x0a\x09^ Compiler new\x0a\x09\x09codeGeneratorClass: self codeGeneratorClass;\x0a\x09\x09yourself",
  650. messageSends: ["codeGeneratorClass:", "codeGeneratorClass", "new", "yourself"],
  651. referencedClasses: ["Compiler"]
  652. }),
  653. smalltalk.CodeGeneratorTest);
  654. smalltalk.addMethod(
  655. smalltalk.method({
  656. selector: "setUp",
  657. category: 'initialization',
  658. fn: function (){
  659. var self=this;
  660. return smalltalk.withContext(function($ctx1) {
  661. self["@receiver"]=_st(self._targetClass())._new();
  662. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},smalltalk.CodeGeneratorTest)})},
  663. args: [],
  664. source: "setUp\x0a\x09receiver := self targetClass new",
  665. messageSends: ["new", "targetClass"],
  666. referencedClasses: []
  667. }),
  668. smalltalk.CodeGeneratorTest);
  669. smalltalk.addMethod(
  670. smalltalk.method({
  671. selector: "should:return:",
  672. category: 'testing',
  673. fn: function (aString,anObject){
  674. var self=this;
  675. var method,result;
  676. return smalltalk.withContext(function($ctx1) {
  677. method=_st(self._compiler())._install_forClass_category_(aString,self._targetClass(),"tests");
  678. result=_st(self["@receiver"])._perform_(_st(method)._selector());
  679. _st(self._targetClass())._removeCompiledMethod_(method);
  680. self._assert_equals_(anObject,result);
  681. return self}, function($ctx1) {$ctx1.fill(self,"should:return:",{aString:aString,anObject:anObject,method:method,result:result},smalltalk.CodeGeneratorTest)})},
  682. args: ["aString", "anObject"],
  683. source: "should: aString return: anObject\x0a\x09| method result |\x0a\x0a\x09method := self compiler install: aString forClass: self targetClass category: 'tests'.\x0a\x09result := receiver perform: method selector.\x0a\x09self targetClass removeCompiledMethod: method.\x0a\x09self assert: anObject equals: result",
  684. messageSends: ["install:forClass:category:", "targetClass", "compiler", "perform:", "selector", "removeCompiledMethod:", "assert:equals:"],
  685. referencedClasses: []
  686. }),
  687. smalltalk.CodeGeneratorTest);
  688. smalltalk.addMethod(
  689. smalltalk.method({
  690. selector: "targetClass",
  691. category: 'accessing',
  692. fn: function (){
  693. var self=this;
  694. function $DoIt(){return smalltalk.DoIt||(typeof DoIt=="undefined"?nil:DoIt)}
  695. return smalltalk.withContext(function($ctx1) {
  696. var $1;
  697. $1=$DoIt();
  698. return $1;
  699. }, function($ctx1) {$ctx1.fill(self,"targetClass",{},smalltalk.CodeGeneratorTest)})},
  700. args: [],
  701. source: "targetClass\x0a\x09^ DoIt",
  702. messageSends: [],
  703. referencedClasses: ["DoIt"]
  704. }),
  705. smalltalk.CodeGeneratorTest);
  706. smalltalk.addMethod(
  707. smalltalk.method({
  708. selector: "tearDown",
  709. category: 'initialization',
  710. fn: function (){
  711. var self=this;
  712. return smalltalk.withContext(function($ctx1) {
  713. return self}, function($ctx1) {$ctx1.fill(self,"tearDown",{},smalltalk.CodeGeneratorTest)})},
  714. args: [],
  715. source: "tearDown\x0a\x09\x22receiver := nil\x22",
  716. messageSends: [],
  717. referencedClasses: []
  718. }),
  719. smalltalk.CodeGeneratorTest);
  720. smalltalk.addMethod(
  721. smalltalk.method({
  722. selector: "testAssignment",
  723. category: 'tests',
  724. fn: function (){
  725. var self=this;
  726. return smalltalk.withContext(function($ctx1) {
  727. self._should_return_("foo | a | a := true ifTrue: [ 1 ]. ^ a",(1));
  728. self._should_return_("foo | a | a := false ifTrue: [ 1 ]. ^ a",nil);
  729. self._should_return_("foo | a | ^ a := true ifTrue: [ 1 ]",(1));
  730. return self}, function($ctx1) {$ctx1.fill(self,"testAssignment",{},smalltalk.CodeGeneratorTest)})},
  731. args: [],
  732. 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",
  733. messageSends: ["should:return:"],
  734. referencedClasses: []
  735. }),
  736. smalltalk.CodeGeneratorTest);
  737. smalltalk.addMethod(
  738. smalltalk.method({
  739. selector: "testBackslashSelectors",
  740. category: 'tests',
  741. fn: function (){
  742. var self=this;
  743. return smalltalk.withContext(function($ctx1) {
  744. self._should_return_("\x5c arg ^ 4",(4));
  745. self._should_return_("\x5c\x5c arg ^ 42",(42));
  746. return self}, function($ctx1) {$ctx1.fill(self,"testBackslashSelectors",{},smalltalk.CodeGeneratorTest)})},
  747. args: [],
  748. source: "testBackslashSelectors\x0a\x09\x0a\x09self should: '\x5c arg ^ 4' return: 4.\x0a\x09self should: '\x5c\x5c arg ^ 42' return: 42",
  749. messageSends: ["should:return:"],
  750. referencedClasses: []
  751. }),
  752. smalltalk.CodeGeneratorTest);
  753. smalltalk.addMethod(
  754. smalltalk.method({
  755. selector: "testBlockReturn",
  756. category: 'tests',
  757. fn: function (){
  758. var self=this;
  759. return smalltalk.withContext(function($ctx1) {
  760. self._should_return_("foo ^ #(1 2 3) collect: [ :each | true ifTrue: [ each + 1 ] ]",[(2), (3), (4)]);
  761. self._should_return_("foo ^ #(1 2 3) collect: [ :each | false ifFalse: [ each + 1 ] ]",[(2), (3), (4)]);
  762. self._should_return_("foo ^ #(1 2 3) collect: [ :each | each odd ifTrue: [ each + 1 ] ifFalse: [ each - 1 ] ]",[(2), (1), (4)]);
  763. return self}, function($ctx1) {$ctx1.fill(self,"testBlockReturn",{},smalltalk.CodeGeneratorTest)})},
  764. args: [],
  765. 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).",
  766. messageSends: ["should:return:"],
  767. referencedClasses: []
  768. }),
  769. smalltalk.CodeGeneratorTest);
  770. smalltalk.addMethod(
  771. smalltalk.method({
  772. selector: "testCascades",
  773. category: 'tests',
  774. fn: function (){
  775. var self=this;
  776. return smalltalk.withContext(function($ctx1) {
  777. self._should_return_("foo ^ Array new add: 3; add: 4; yourself",[(3), (4)]);
  778. return self}, function($ctx1) {$ctx1.fill(self,"testCascades",{},smalltalk.CodeGeneratorTest)})},
  779. args: [],
  780. source: "testCascades\x0a\x09\x0a\x09self should: 'foo ^ Array new add: 3; add: 4; yourself' return: #(3 4)",
  781. messageSends: ["should:return:"],
  782. referencedClasses: []
  783. }),
  784. smalltalk.CodeGeneratorTest);
  785. smalltalk.addMethod(
  786. smalltalk.method({
  787. selector: "testDynamicArrayElementsOrdered",
  788. category: 'tests',
  789. fn: function (){
  790. var self=this;
  791. return smalltalk.withContext(function($ctx1) {
  792. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { x. true ifTrue: [ x := 2 ] }\x0a",[(1), (2)]);
  793. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicArrayElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  794. args: [],
  795. source: "testDynamicArrayElementsOrdered\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { x. true ifTrue: [ x := 2 ] }\x0a' return: #(1 2).",
  796. messageSends: ["should:return:"],
  797. referencedClasses: []
  798. }),
  799. smalltalk.CodeGeneratorTest);
  800. smalltalk.addMethod(
  801. smalltalk.method({
  802. selector: "testDynamicDictionaryElementsOrdered",
  803. category: 'tests',
  804. fn: function (){
  805. var self=this;
  806. return smalltalk.withContext(function($ctx1) {
  807. 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))]));
  808. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicDictionaryElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  809. args: [],
  810. 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}.",
  811. messageSends: ["should:return:", "->"],
  812. referencedClasses: []
  813. }),
  814. smalltalk.CodeGeneratorTest);
  815. smalltalk.addMethod(
  816. smalltalk.method({
  817. selector: "testInnerTemporalDependentElementsOrdered",
  818. category: 'tests',
  819. fn: function (){
  820. var self=this;
  821. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  822. return smalltalk.withContext(function($ctx1) {
  823. 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))]);
  824. 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))]);
  825. 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))]);
  826. 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))]));
  827. return self}, function($ctx1) {$ctx1.fill(self,"testInnerTemporalDependentElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  828. args: [],
  829. 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}.",
  830. messageSends: ["should:return:", "->"],
  831. referencedClasses: ["Array"]
  832. }),
  833. smalltalk.CodeGeneratorTest);
  834. smalltalk.addMethod(
  835. smalltalk.method({
  836. selector: "testLiterals",
  837. category: 'tests',
  838. fn: function (){
  839. var self=this;
  840. return smalltalk.withContext(function($ctx1) {
  841. self._should_return_("foo ^ 1",(1));
  842. self._should_return_("foo ^ 'hello'","hello");
  843. self._should_return_("foo ^ #(1 2 3 4)",[(1), (2), (3), (4)]);
  844. self._should_return_("foo ^ {1. [:x | x ] value: 2. 3. [4] value}",[(1), (2), (3), (4)]);
  845. self._should_return_("foo ^ true",true);
  846. self._should_return_("foo ^ false",false);
  847. self._should_return_("foo ^ #{1->2. 3->4}",smalltalk.HashedCollection._from_([(1).__minus_gt((2)),(3).__minus_gt((4))]));
  848. self._should_return_("foo ^ #hello","hello");
  849. self._should_return_("foo ^ -123.456",(-123.456));
  850. return self}, function($ctx1) {$ctx1.fill(self,"testLiterals",{},smalltalk.CodeGeneratorTest)})},
  851. args: [],
  852. 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",
  853. messageSends: ["should:return:", "->"],
  854. referencedClasses: []
  855. }),
  856. smalltalk.CodeGeneratorTest);
  857. smalltalk.addMethod(
  858. smalltalk.method({
  859. selector: "testLocalReturn",
  860. category: 'tests',
  861. fn: function (){
  862. var self=this;
  863. return smalltalk.withContext(function($ctx1) {
  864. self._should_return_("foo ^ 1",(1));
  865. self._should_return_("foo ^ 1 + 1",(2));
  866. self._should_return_("foo ",self["@receiver"]);
  867. self._should_return_("foo self asString",self["@receiver"]);
  868. self._should_return_("foo | a b | a := 1. b := 2. ^ a + b",(3));
  869. return self}, function($ctx1) {$ctx1.fill(self,"testLocalReturn",{},smalltalk.CodeGeneratorTest)})},
  870. args: [],
  871. 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",
  872. messageSends: ["should:return:"],
  873. referencedClasses: []
  874. }),
  875. smalltalk.CodeGeneratorTest);
  876. smalltalk.addMethod(
  877. smalltalk.method({
  878. selector: "testMessageSends",
  879. category: 'tests',
  880. fn: function (){
  881. var self=this;
  882. return smalltalk.withContext(function($ctx1) {
  883. self._should_return_("foo ^ 1 asString","1");
  884. self._should_return_("foo ^ 1 + 1",(2));
  885. self._should_return_("foo ^ 1 + 2 * 3",(9));
  886. self._should_return_("foo ^ 1 to: 3",[(1), (2), (3)]);
  887. self._should_return_("foo ^ 1 to: 5 by: 2",[(1), (3), (5)]);
  888. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSends",{},smalltalk.CodeGeneratorTest)})},
  889. args: [],
  890. 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)",
  891. messageSends: ["should:return:"],
  892. referencedClasses: []
  893. }),
  894. smalltalk.CodeGeneratorTest);
  895. smalltalk.addMethod(
  896. smalltalk.method({
  897. selector: "testMutableLiterals",
  898. category: 'tests',
  899. fn: function (){
  900. var self=this;
  901. return smalltalk.withContext(function($ctx1) {
  902. self._should_return_("foo ^ #( 1 2 ) at: 1 put: 3; yourself",[(3), (2)]);
  903. return self}, function($ctx1) {$ctx1.fill(self,"testMutableLiterals",{},smalltalk.CodeGeneratorTest)})},
  904. args: [],
  905. 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)",
  906. messageSends: ["should:return:"],
  907. referencedClasses: []
  908. }),
  909. smalltalk.CodeGeneratorTest);
  910. smalltalk.addMethod(
  911. smalltalk.method({
  912. selector: "testNestedIfTrue",
  913. category: 'tests',
  914. fn: function (){
  915. var self=this;
  916. return smalltalk.withContext(function($ctx1) {
  917. self._should_return_("foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]",(1));
  918. self._should_return_("foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]",nil);
  919. self._should_return_("foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]",(1));
  920. self._should_return_("foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]",self["@receiver"]);
  921. return self}, function($ctx1) {$ctx1.fill(self,"testNestedIfTrue",{},smalltalk.CodeGeneratorTest)})},
  922. args: [],
  923. 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.",
  924. messageSends: ["should:return:"],
  925. referencedClasses: []
  926. }),
  927. smalltalk.CodeGeneratorTest);
  928. smalltalk.addMethod(
  929. smalltalk.method({
  930. selector: "testNonLocalReturn",
  931. category: 'tests',
  932. fn: function (){
  933. var self=this;
  934. return smalltalk.withContext(function($ctx1) {
  935. self._should_return_("foo [ ^ 1 ] value",(1));
  936. self._should_return_("foo [ ^ 1 + 1 ] value",(2));
  937. self._should_return_("foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt",(3));
  938. self._should_return_("foo [ :x | ^ x + x ] value: 4. ^ 2",(8));
  939. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn",{},smalltalk.CodeGeneratorTest)})},
  940. args: [],
  941. 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",
  942. messageSends: ["should:return:"],
  943. referencedClasses: []
  944. }),
  945. smalltalk.CodeGeneratorTest);
  946. smalltalk.addMethod(
  947. smalltalk.method({
  948. selector: "testPascalCaseGlobal",
  949. category: 'tests',
  950. fn: function (){
  951. var self=this;
  952. return smalltalk.withContext(function($ctx1) {
  953. self._should_return_("foo ^Object",_st(smalltalk)._at_("Object"));
  954. self._should_return_("foo ^NonExistent",nil);
  955. return self}, function($ctx1) {$ctx1.fill(self,"testPascalCaseGlobal",{},smalltalk.CodeGeneratorTest)})},
  956. args: [],
  957. source: "testPascalCaseGlobal\x0a\x09self should: 'foo ^Object' return: (smalltalk at: 'Object').\x0a\x09self should: 'foo ^NonExistent' return: nil",
  958. messageSends: ["should:return:", "at:"],
  959. referencedClasses: []
  960. }),
  961. smalltalk.CodeGeneratorTest);
  962. smalltalk.addMethod(
  963. smalltalk.method({
  964. selector: "testSendReceiverAndArgumentsOrdered",
  965. category: 'tests',
  966. fn: function (){
  967. var self=this;
  968. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  969. return smalltalk.withContext(function($ctx1) {
  970. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ Array with: x with: (true ifTrue: [ x := 2 ])\x0a",[(1), (2)]);
  971. self._should_return_("foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: x with: (true ifTrue: [ x := 2 ])\x0a",[$Array(),(2)]);
  972. return self}, function($ctx1) {$ctx1.fill(self,"testSendReceiverAndArgumentsOrdered",{},smalltalk.CodeGeneratorTest)})},
  973. args: [],
  974. 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}.",
  975. messageSends: ["should:return:"],
  976. referencedClasses: ["Array"]
  977. }),
  978. smalltalk.CodeGeneratorTest);
  979. smalltalk.addMethod(
  980. smalltalk.method({
  981. selector: "testifFalse",
  982. category: 'tests',
  983. fn: function (){
  984. var self=this;
  985. return smalltalk.withContext(function($ctx1) {
  986. self._should_return_("foo true ifFalse: [ ^ 1 ]",self["@receiver"]);
  987. self._should_return_("foo false ifFalse: [ ^ 2 ]",(2));
  988. self._should_return_("foo ^ true ifFalse: [ 1 ]",nil);
  989. self._should_return_("foo ^ false ifFalse: [ 2 ]",(2));
  990. return self}, function($ctx1) {$ctx1.fill(self,"testifFalse",{},smalltalk.CodeGeneratorTest)})},
  991. args: [],
  992. 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.",
  993. messageSends: ["should:return:"],
  994. referencedClasses: []
  995. }),
  996. smalltalk.CodeGeneratorTest);
  997. smalltalk.addMethod(
  998. smalltalk.method({
  999. selector: "testifFalseIfTrue",
  1000. category: 'tests',
  1001. fn: function (){
  1002. var self=this;
  1003. return smalltalk.withContext(function($ctx1) {
  1004. self._should_return_("foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]",(2));
  1005. self._should_return_("foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]",(2));
  1006. self._should_return_("foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]",(2));
  1007. self._should_return_("foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]",(2));
  1008. return self}, function($ctx1) {$ctx1.fill(self,"testifFalseIfTrue",{},smalltalk.CodeGeneratorTest)})},
  1009. args: [],
  1010. 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.",
  1011. messageSends: ["should:return:"],
  1012. referencedClasses: []
  1013. }),
  1014. smalltalk.CodeGeneratorTest);
  1015. smalltalk.addMethod(
  1016. smalltalk.method({
  1017. selector: "testifNil",
  1018. category: 'tests',
  1019. fn: function (){
  1020. var self=this;
  1021. return smalltalk.withContext(function($ctx1) {
  1022. self._should_return_("foo ^ 1 ifNil: [ 2 ]",(1));
  1023. self._should_return_("foo ^ nil ifNil: [ 2 ]",(2));
  1024. self._should_return_("foo 1 ifNil: [ ^ 2 ]",self["@receiver"]);
  1025. self._should_return_("foo nil ifNil: [ ^ 2 ]",(2));
  1026. return self}, function($ctx1) {$ctx1.fill(self,"testifNil",{},smalltalk.CodeGeneratorTest)})},
  1027. args: [],
  1028. 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.",
  1029. messageSends: ["should:return:"],
  1030. referencedClasses: []
  1031. }),
  1032. smalltalk.CodeGeneratorTest);
  1033. smalltalk.addMethod(
  1034. smalltalk.method({
  1035. selector: "testifNilIfNotNil",
  1036. category: 'tests',
  1037. fn: function (){
  1038. var self=this;
  1039. return smalltalk.withContext(function($ctx1) {
  1040. self._should_return_("foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]",(3));
  1041. self._should_return_("foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]",(2));
  1042. self._should_return_("foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(3));
  1043. self._should_return_("foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(2));
  1044. return self}, function($ctx1) {$ctx1.fill(self,"testifNilIfNotNil",{},smalltalk.CodeGeneratorTest)})},
  1045. args: [],
  1046. 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.",
  1047. messageSends: ["should:return:"],
  1048. referencedClasses: []
  1049. }),
  1050. smalltalk.CodeGeneratorTest);
  1051. smalltalk.addMethod(
  1052. smalltalk.method({
  1053. selector: "testifNotNil",
  1054. category: 'tests',
  1055. fn: function (){
  1056. var self=this;
  1057. return smalltalk.withContext(function($ctx1) {
  1058. self._should_return_("foo ^ 1 ifNotNil: [ 2 ]",(2));
  1059. self._should_return_("foo ^ nil ifNotNil: [ 2 ]",nil);
  1060. self._should_return_("foo 1 ifNotNil: [ ^ 2 ]",(2));
  1061. self._should_return_("foo nil ifNotNil: [ ^ 2 ]",self["@receiver"]);
  1062. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNil",{},smalltalk.CodeGeneratorTest)})},
  1063. args: [],
  1064. 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.",
  1065. messageSends: ["should:return:"],
  1066. referencedClasses: []
  1067. }),
  1068. smalltalk.CodeGeneratorTest);
  1069. smalltalk.addMethod(
  1070. smalltalk.method({
  1071. selector: "testifNotNilWithArgument",
  1072. category: 'tests',
  1073. fn: function (){
  1074. var self=this;
  1075. return smalltalk.withContext(function($ctx1) {
  1076. self._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ]",(3));
  1077. self._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ]",nil);
  1078. self._should_return_("foo ^ 1 ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(3));
  1079. self._should_return_("foo ^ nil ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(5));
  1080. self._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(3));
  1081. self._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(5));
  1082. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNilWithArgument",{},smalltalk.CodeGeneratorTest)})},
  1083. args: [],
  1084. 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",
  1085. messageSends: ["should:return:"],
  1086. referencedClasses: []
  1087. }),
  1088. smalltalk.CodeGeneratorTest);
  1089. smalltalk.addMethod(
  1090. smalltalk.method({
  1091. selector: "testifTrue",
  1092. category: 'tests',
  1093. fn: function (){
  1094. var self=this;
  1095. return smalltalk.withContext(function($ctx1) {
  1096. self._should_return_("foo false ifTrue: [ ^ 1 ]",self["@receiver"]);
  1097. self._should_return_("foo true ifTrue: [ ^ 2 ]",(2));
  1098. self._should_return_("foo ^ false ifTrue: [ 1 ]",nil);
  1099. self._should_return_("foo ^ true ifTrue: [ 2 ]",(2));
  1100. return self}, function($ctx1) {$ctx1.fill(self,"testifTrue",{},smalltalk.CodeGeneratorTest)})},
  1101. args: [],
  1102. 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.",
  1103. messageSends: ["should:return:"],
  1104. referencedClasses: []
  1105. }),
  1106. smalltalk.CodeGeneratorTest);
  1107. smalltalk.addMethod(
  1108. smalltalk.method({
  1109. selector: "testifTrueIfFalse",
  1110. category: 'tests',
  1111. fn: function (){
  1112. var self=this;
  1113. return smalltalk.withContext(function($ctx1) {
  1114. self._should_return_("foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]",(2));
  1115. self._should_return_("foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]",(1));
  1116. self._should_return_("foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]",(1));
  1117. self._should_return_("foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]",(2));
  1118. return self}, function($ctx1) {$ctx1.fill(self,"testifTrueIfFalse",{},smalltalk.CodeGeneratorTest)})},
  1119. args: [],
  1120. 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.",
  1121. messageSends: ["should:return:"],
  1122. referencedClasses: []
  1123. }),
  1124. smalltalk.CodeGeneratorTest);
  1125. smalltalk.addClass('InliningCodeGeneratorTest', smalltalk.CodeGeneratorTest, [], 'Compiler-Tests');
  1126. smalltalk.addMethod(
  1127. smalltalk.method({
  1128. selector: "codeGeneratorClass",
  1129. category: 'accessing',
  1130. fn: function (){
  1131. var self=this;
  1132. function $InliningCodeGenerator(){return smalltalk.InliningCodeGenerator||(typeof InliningCodeGenerator=="undefined"?nil:InliningCodeGenerator)}
  1133. return smalltalk.withContext(function($ctx1) {
  1134. var $1;
  1135. $1=$InliningCodeGenerator();
  1136. return $1;
  1137. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{},smalltalk.InliningCodeGeneratorTest)})},
  1138. args: [],
  1139. source: "codeGeneratorClass\x0a\x09^ InliningCodeGenerator",
  1140. messageSends: [],
  1141. referencedClasses: ["InliningCodeGenerator"]
  1142. }),
  1143. smalltalk.InliningCodeGeneratorTest);
  1144. smalltalk.addClass('ScopeVarTest', smalltalk.TestCase, [], 'Compiler-Tests');
  1145. smalltalk.addMethod(
  1146. smalltalk.method({
  1147. selector: "testClassRefVar",
  1148. category: 'tests',
  1149. fn: function (){
  1150. var self=this;
  1151. var node;
  1152. function $ClassReferenceNode(){return smalltalk.ClassReferenceNode||(typeof ClassReferenceNode=="undefined"?nil:ClassReferenceNode)}
  1153. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1154. return smalltalk.withContext(function($ctx1) {
  1155. var $1,$2;
  1156. $1=_st($ClassReferenceNode())._new();
  1157. _st($1)._value_("Object");
  1158. $2=_st($1)._yourself();
  1159. node=$2;
  1160. _st(_st($SemanticAnalyzer())._new())._visit_(node);
  1161. self._assert_(_st(_st(node)._binding())._isClassRefVar());
  1162. return self}, function($ctx1) {$ctx1.fill(self,"testClassRefVar",{node:node},smalltalk.ScopeVarTest)})},
  1163. args: [],
  1164. source: "testClassRefVar\x0a\x09| node |\x0a\x09node := ClassReferenceNode new\x0a\x09\x09value: 'Object';\x0a\x09\x09yourself.\x0a\x09SemanticAnalyzer new visit: node.\x0a\x09self assert: node binding isClassRefVar",
  1165. messageSends: ["value:", "new", "yourself", "visit:", "assert:", "isClassRefVar", "binding"],
  1166. referencedClasses: ["ClassReferenceNode", "SemanticAnalyzer"]
  1167. }),
  1168. smalltalk.ScopeVarTest);
  1169. smalltalk.addMethod(
  1170. smalltalk.method({
  1171. selector: "testInstanceVar",
  1172. category: 'tests',
  1173. fn: function (){
  1174. var self=this;
  1175. var node,scope;
  1176. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1177. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1178. return smalltalk.withContext(function($ctx1) {
  1179. var $1,$2;
  1180. $1=_st($VariableNode())._new();
  1181. _st($1)._value_("bzzz");
  1182. $2=_st($1)._yourself();
  1183. node=$2;
  1184. scope=_st($MethodLexicalScope())._new();
  1185. _st(scope)._addIVar_("bzzz");
  1186. self._assert_(_st(_st(scope)._bindingFor_(node))._isInstanceVar());
  1187. return self}, function($ctx1) {$ctx1.fill(self,"testInstanceVar",{node:node,scope:scope},smalltalk.ScopeVarTest)})},
  1188. args: [],
  1189. 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",
  1190. messageSends: ["value:", "new", "yourself", "addIVar:", "assert:", "isInstanceVar", "bindingFor:"],
  1191. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1192. }),
  1193. smalltalk.ScopeVarTest);
  1194. smalltalk.addMethod(
  1195. smalltalk.method({
  1196. selector: "testPseudoVar",
  1197. category: 'tests',
  1198. fn: function (){
  1199. var self=this;
  1200. var node,pseudoVars;
  1201. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1202. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1203. return smalltalk.withContext(function($ctx1) {
  1204. var $1,$2;
  1205. pseudoVars=["self", "super", "true", "false", "nil"];
  1206. _st(pseudoVars)._do_((function(each){
  1207. return smalltalk.withContext(function($ctx2) {
  1208. $1=_st($VariableNode())._new();
  1209. _st($1)._value_(each);
  1210. $2=_st($1)._yourself();
  1211. node=$2;
  1212. node;
  1213. return self._assert_(_st(_st(_st($MethodLexicalScope())._new())._bindingFor_(node))._isPseudoVar());
  1214. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  1215. return self}, function($ctx1) {$ctx1.fill(self,"testPseudoVar",{node:node,pseudoVars:pseudoVars},smalltalk.ScopeVarTest)})},
  1216. args: [],
  1217. 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 ]",
  1218. messageSends: ["do:", "value:", "new", "yourself", "assert:", "isPseudoVar", "bindingFor:"],
  1219. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1220. }),
  1221. smalltalk.ScopeVarTest);
  1222. smalltalk.addMethod(
  1223. smalltalk.method({
  1224. selector: "testTempVar",
  1225. category: 'tests',
  1226. fn: function (){
  1227. var self=this;
  1228. var node,scope;
  1229. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1230. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1231. return smalltalk.withContext(function($ctx1) {
  1232. var $1,$2;
  1233. $1=_st($VariableNode())._new();
  1234. _st($1)._value_("bzzz");
  1235. $2=_st($1)._yourself();
  1236. node=$2;
  1237. scope=_st($MethodLexicalScope())._new();
  1238. _st(scope)._addTemp_("bzzz");
  1239. self._assert_(_st(_st(scope)._bindingFor_(node))._isTempVar());
  1240. return self}, function($ctx1) {$ctx1.fill(self,"testTempVar",{node:node,scope:scope},smalltalk.ScopeVarTest)})},
  1241. args: [],
  1242. 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",
  1243. messageSends: ["value:", "new", "yourself", "addTemp:", "assert:", "isTempVar", "bindingFor:"],
  1244. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1245. }),
  1246. smalltalk.ScopeVarTest);
  1247. smalltalk.addMethod(
  1248. smalltalk.method({
  1249. selector: "testUnknownVar",
  1250. category: 'tests',
  1251. fn: function (){
  1252. var self=this;
  1253. var node;
  1254. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1255. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1256. return smalltalk.withContext(function($ctx1) {
  1257. var $1,$2;
  1258. $1=_st($VariableNode())._new();
  1259. _st($1)._value_("bzzz");
  1260. $2=_st($1)._yourself();
  1261. node=$2;
  1262. self._assert_(_st(_st(_st($MethodLexicalScope())._new())._bindingFor_(node))._isNil());
  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 $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  1278. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  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: ["Object", "SemanticAnalyzer"]
  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)})}),$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. src="foo | a | a + 1. [ | b | b := a ]";
  1357. ast=_st(smalltalk)._parse_(src);
  1358. _st(self["@analyzer"])._visit_(ast);
  1359. self._deny_(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._last())._scope()).__eq_eq(_st(ast)._scope()));
  1360. return self}, function($ctx1) {$ctx1.fill(self,"testScope",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1361. args: [],
  1362. source: "testScope\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | a + 1. [ | b | b := a ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self deny: ast nodes first nodes last scope == ast scope.",
  1363. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "last", "nodes", "first"],
  1364. referencedClasses: []
  1365. }),
  1366. smalltalk.SemanticAnalyzerTest);
  1367. smalltalk.addMethod(
  1368. smalltalk.method({
  1369. selector: "testScope2",
  1370. category: 'tests',
  1371. fn: function (){
  1372. var self=this;
  1373. var src,ast;
  1374. return smalltalk.withContext(function($ctx1) {
  1375. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1376. ast=_st(smalltalk)._parse_(src);
  1377. _st(self["@analyzer"])._visit_(ast);
  1378. 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()));
  1379. return self}, function($ctx1) {$ctx1.fill(self,"testScope2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1380. args: [],
  1381. 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.",
  1382. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "first", "nodes", "last"],
  1383. referencedClasses: []
  1384. }),
  1385. smalltalk.SemanticAnalyzerTest);
  1386. smalltalk.addMethod(
  1387. smalltalk.method({
  1388. selector: "testScopeLevel",
  1389. category: 'tests',
  1390. fn: function (){
  1391. var self=this;
  1392. var src,ast;
  1393. return smalltalk.withContext(function($ctx1) {
  1394. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1395. ast=_st(smalltalk)._parse_(src);
  1396. _st(self["@analyzer"])._visit_(ast);
  1397. self._assert_equals_(_st(_st(ast)._scope())._scopeLevel(),(1));
  1398. 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));
  1399. return self}, function($ctx1) {$ctx1.fill(self,"testScopeLevel",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1400. args: [],
  1401. 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",
  1402. messageSends: ["parse:", "visit:", "assert:equals:", "scopeLevel", "scope", "first", "nodes", "last"],
  1403. referencedClasses: []
  1404. }),
  1405. smalltalk.SemanticAnalyzerTest);
  1406. smalltalk.addMethod(
  1407. smalltalk.method({
  1408. selector: "testUnknownVariables",
  1409. category: 'tests',
  1410. fn: function (){
  1411. var self=this;
  1412. var src,ast;
  1413. function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1414. return smalltalk.withContext(function($ctx1) {
  1415. src="foo | a | b + a";
  1416. ast=_st(smalltalk)._parse_(src);
  1417. self._should_raise_((function(){
  1418. return smalltalk.withContext(function($ctx2) {
  1419. return _st(self["@analyzer"])._visit_(ast);
  1420. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$UnknownVariableError());
  1421. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariables",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1422. args: [],
  1423. 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",
  1424. messageSends: ["parse:", "should:raise:", "visit:"],
  1425. referencedClasses: ["UnknownVariableError"]
  1426. }),
  1427. smalltalk.SemanticAnalyzerTest);
  1428. smalltalk.addMethod(
  1429. smalltalk.method({
  1430. selector: "testUnknownVariablesWithScope",
  1431. category: 'tests',
  1432. fn: function (){
  1433. var self=this;
  1434. var src,ast;
  1435. function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1436. return smalltalk.withContext(function($ctx1) {
  1437. src="foo | a b | [ c + 1. [ a + 1. d + 1 ]]";
  1438. ast=_st(smalltalk)._parse_(src);
  1439. self._should_raise_((function(){
  1440. return smalltalk.withContext(function($ctx2) {
  1441. return _st(self["@analyzer"])._visit_(ast);
  1442. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$UnknownVariableError());
  1443. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariablesWithScope",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1444. args: [],
  1445. 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",
  1446. messageSends: ["parse:", "should:raise:", "visit:"],
  1447. referencedClasses: ["UnknownVariableError"]
  1448. }),
  1449. smalltalk.SemanticAnalyzerTest);
  1450. smalltalk.addMethod(
  1451. smalltalk.method({
  1452. selector: "testVariableShadowing",
  1453. category: 'tests',
  1454. fn: function (){
  1455. var self=this;
  1456. var src,ast;
  1457. return smalltalk.withContext(function($ctx1) {
  1458. src="foo | a | a + 1";
  1459. ast=_st(smalltalk)._parse_(src);
  1460. _st(self["@analyzer"])._visit_(ast);
  1461. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1462. args: [],
  1463. source: "testVariableShadowing\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1464. messageSends: ["parse:", "visit:"],
  1465. referencedClasses: []
  1466. }),
  1467. smalltalk.SemanticAnalyzerTest);
  1468. smalltalk.addMethod(
  1469. smalltalk.method({
  1470. selector: "testVariableShadowing2",
  1471. category: 'tests',
  1472. fn: function (){
  1473. var self=this;
  1474. var src,ast;
  1475. function $ShadowingVariableError(){return smalltalk.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1476. return smalltalk.withContext(function($ctx1) {
  1477. src="foo | a | a + 1. [ | a | a := 2 ]";
  1478. ast=_st(smalltalk)._parse_(src);
  1479. self._should_raise_((function(){
  1480. return smalltalk.withContext(function($ctx2) {
  1481. return _st(self["@analyzer"])._visit_(ast);
  1482. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$ShadowingVariableError());
  1483. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1484. args: [],
  1485. 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",
  1486. messageSends: ["parse:", "should:raise:", "visit:"],
  1487. referencedClasses: ["ShadowingVariableError"]
  1488. }),
  1489. smalltalk.SemanticAnalyzerTest);
  1490. smalltalk.addMethod(
  1491. smalltalk.method({
  1492. selector: "testVariableShadowing3",
  1493. category: 'tests',
  1494. fn: function (){
  1495. var self=this;
  1496. var src,ast;
  1497. return smalltalk.withContext(function($ctx1) {
  1498. src="foo | a | a + 1. [ | b | b := 2 ]";
  1499. ast=_st(smalltalk)._parse_(src);
  1500. _st(self["@analyzer"])._visit_(ast);
  1501. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing3",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1502. args: [],
  1503. source: "testVariableShadowing3\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | b | b := 2 ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1504. messageSends: ["parse:", "visit:"],
  1505. referencedClasses: []
  1506. }),
  1507. smalltalk.SemanticAnalyzerTest);
  1508. smalltalk.addMethod(
  1509. smalltalk.method({
  1510. selector: "testVariableShadowing4",
  1511. category: 'tests',
  1512. fn: function (){
  1513. var self=this;
  1514. var src,ast;
  1515. return smalltalk.withContext(function($ctx1) {
  1516. src="foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]";
  1517. ast=_st(smalltalk)._parse_(src);
  1518. _st(self["@analyzer"])._visit_(ast);
  1519. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing4",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1520. args: [],
  1521. source: "testVariableShadowing4\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1522. messageSends: ["parse:", "visit:"],
  1523. referencedClasses: []
  1524. }),
  1525. smalltalk.SemanticAnalyzerTest);
  1526. smalltalk.addMethod(
  1527. smalltalk.method({
  1528. selector: "testVariableShadowing5",
  1529. category: 'tests',
  1530. fn: function (){
  1531. var self=this;
  1532. var src,ast;
  1533. function $ShadowingVariableError(){return smalltalk.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1534. return smalltalk.withContext(function($ctx1) {
  1535. src="foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]";
  1536. ast=_st(smalltalk)._parse_(src);
  1537. self._should_raise_((function(){
  1538. return smalltalk.withContext(function($ctx2) {
  1539. return _st(self["@analyzer"])._visit_(ast);
  1540. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$ShadowingVariableError());
  1541. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing5",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1542. args: [],
  1543. 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",
  1544. messageSends: ["parse:", "should:raise:", "visit:"],
  1545. referencedClasses: ["ShadowingVariableError"]
  1546. }),
  1547. smalltalk.SemanticAnalyzerTest);
  1548. smalltalk.addMethod(
  1549. smalltalk.method({
  1550. selector: "testVariablesLookup",
  1551. category: 'tests',
  1552. fn: function (){
  1553. var self=this;
  1554. var src,ast;
  1555. return smalltalk.withContext(function($ctx1) {
  1556. src="foo | a | a + 1. [ | b | b := a ]";
  1557. ast=_st(smalltalk)._parse_(src);
  1558. _st(self["@analyzer"])._visit_(ast);
  1559. self._assert_(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._first())._receiver())._binding())._isTempVar());
  1560. self._assert_(_st(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._first())._receiver())._binding())._scope()).__eq_eq(_st(ast)._scope()));
  1561. 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());
  1562. 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()));
  1563. return self}, function($ctx1) {$ctx1.fill(self,"testVariablesLookup",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1564. args: [],
  1565. 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.",
  1566. messageSends: ["parse:", "visit:", "assert:", "isTempVar", "binding", "receiver", "first", "nodes", "==", "scope", "left", "last"],
  1567. referencedClasses: []
  1568. }),
  1569. smalltalk.SemanticAnalyzerTest);
  1570. });