Compiler-Tests.js 75 KB

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