Compiler-Tests.js 86 KB

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