Compiler-Tests.js 86 KB

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