1
0

Compiler-Tests.js 92 KB

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