1
0

Compiler-Tests.js 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811
  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('CodeGeneratorTest', globals.ASTParsingTest, ['receiver'], 'Compiler-Tests');
  257. smalltalk.addMethod(
  258. smalltalk.method({
  259. selector: "codeGeneratorClass",
  260. protocol: 'accessing',
  261. fn: function (){
  262. var self=this;
  263. function $CodeGenerator(){return globals.CodeGenerator||(typeof CodeGenerator=="undefined"?nil:CodeGenerator)}
  264. return $CodeGenerator();
  265. },
  266. args: [],
  267. source: "codeGeneratorClass\x0a\x09^ CodeGenerator",
  268. messageSends: [],
  269. referencedClasses: ["CodeGenerator"]
  270. }),
  271. globals.CodeGeneratorTest);
  272. smalltalk.addMethod(
  273. smalltalk.method({
  274. selector: "compiler",
  275. protocol: 'factory',
  276. fn: function (){
  277. var self=this;
  278. function $Compiler(){return globals.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  279. return smalltalk.withContext(function($ctx1) {
  280. var $2,$3,$1;
  281. $2=_st($Compiler())._new();
  282. _st($2)._codeGeneratorClass_(self._codeGeneratorClass());
  283. $3=_st($2)._yourself();
  284. $1=$3;
  285. return $1;
  286. }, function($ctx1) {$ctx1.fill(self,"compiler",{},globals.CodeGeneratorTest)})},
  287. args: [],
  288. source: "compiler\x0a\x09^ Compiler new\x0a\x09\x09codeGeneratorClass: self codeGeneratorClass;\x0a\x09\x09yourself",
  289. messageSends: ["codeGeneratorClass:", "new", "codeGeneratorClass", "yourself"],
  290. referencedClasses: ["Compiler"]
  291. }),
  292. globals.CodeGeneratorTest);
  293. smalltalk.addMethod(
  294. smalltalk.method({
  295. selector: "setUp",
  296. protocol: 'initialization',
  297. fn: function (){
  298. var self=this;
  299. function $DoIt(){return globals.DoIt||(typeof DoIt=="undefined"?nil:DoIt)}
  300. return smalltalk.withContext(function($ctx1) {
  301. self["@receiver"]=_st($DoIt())._new();
  302. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},globals.CodeGeneratorTest)})},
  303. args: [],
  304. source: "setUp\x0a\x09receiver := DoIt new",
  305. messageSends: ["new"],
  306. referencedClasses: ["DoIt"]
  307. }),
  308. globals.CodeGeneratorTest);
  309. smalltalk.addMethod(
  310. smalltalk.method({
  311. selector: "should:receiver:return:",
  312. protocol: 'testing',
  313. fn: function (aString,anObject,aResult){
  314. var self=this;
  315. var method,result;
  316. return smalltalk.withContext(function($ctx1) {
  317. var $1,$2;
  318. self["@receiver"]=anObject;
  319. $1=self._compiler();
  320. $2=_st(anObject)._class();
  321. $ctx1.sendIdx["class"]=1;
  322. method=_st($1)._install_forClass_protocol_(aString,$2,"tests");
  323. result=_st(self["@receiver"])._perform_(_st(method)._selector());
  324. _st(_st(anObject)._class())._removeCompiledMethod_(method);
  325. self._assert_equals_(aResult,result);
  326. return self}, function($ctx1) {$ctx1.fill(self,"should:receiver:return:",{aString:aString,anObject:anObject,aResult:aResult,method:method,result:result},globals.CodeGeneratorTest)})},
  327. args: ["aString", "anObject", "aResult"],
  328. 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",
  329. messageSends: ["install:forClass:protocol:", "compiler", "class", "perform:", "selector", "removeCompiledMethod:", "assert:equals:"],
  330. referencedClasses: []
  331. }),
  332. globals.CodeGeneratorTest);
  333. smalltalk.addMethod(
  334. smalltalk.method({
  335. selector: "should:return:",
  336. protocol: 'testing',
  337. fn: function (aString,anObject){
  338. var self=this;
  339. return smalltalk.withContext(function($ctx1) {
  340. var $1;
  341. $1=self._should_receiver_return_(aString,self["@receiver"],anObject);
  342. return $1;
  343. }, function($ctx1) {$ctx1.fill(self,"should:return:",{aString:aString,anObject:anObject},globals.CodeGeneratorTest)})},
  344. args: ["aString", "anObject"],
  345. source: "should: aString return: anObject\x0a\x09^ self \x0a\x09\x09should: aString \x0a\x09\x09receiver: receiver \x0a\x09\x09return: anObject",
  346. messageSends: ["should:receiver:return:"],
  347. referencedClasses: []
  348. }),
  349. globals.CodeGeneratorTest);
  350. smalltalk.addMethod(
  351. smalltalk.method({
  352. selector: "tearDown",
  353. protocol: 'initialization',
  354. fn: function (){
  355. var self=this;
  356. return self},
  357. args: [],
  358. source: "tearDown\x0a\x09\x22receiver := nil\x22",
  359. messageSends: [],
  360. referencedClasses: []
  361. }),
  362. globals.CodeGeneratorTest);
  363. smalltalk.addMethod(
  364. smalltalk.method({
  365. selector: "testAssignment",
  366. protocol: 'tests',
  367. fn: function (){
  368. var self=this;
  369. return smalltalk.withContext(function($ctx1) {
  370. self._should_return_("foo | a | a := true ifTrue: [ 1 ]. ^ a",(1));
  371. $ctx1.sendIdx["should:return:"]=1;
  372. self._should_return_("foo | a | a := false ifTrue: [ 1 ]. ^ a",nil);
  373. $ctx1.sendIdx["should:return:"]=2;
  374. self._should_return_("foo | a | ^ a := true ifTrue: [ 1 ]",(1));
  375. return self}, function($ctx1) {$ctx1.fill(self,"testAssignment",{},globals.CodeGeneratorTest)})},
  376. args: [],
  377. 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",
  378. messageSends: ["should:return:"],
  379. referencedClasses: []
  380. }),
  381. globals.CodeGeneratorTest);
  382. smalltalk.addMethod(
  383. smalltalk.method({
  384. selector: "testBackslashSelectors",
  385. protocol: 'tests',
  386. fn: function (){
  387. var self=this;
  388. return smalltalk.withContext(function($ctx1) {
  389. self._should_return_("\x5c arg ^ 4",(4));
  390. $ctx1.sendIdx["should:return:"]=1;
  391. self._should_return_("\x5c\x5c arg ^ 42",(42));
  392. return self}, function($ctx1) {$ctx1.fill(self,"testBackslashSelectors",{},globals.CodeGeneratorTest)})},
  393. args: [],
  394. source: "testBackslashSelectors\x0a\x09\x0a\x09self should: '\x5c arg ^ 4' return: 4.\x0a\x09self should: '\x5c\x5c arg ^ 42' return: 42",
  395. messageSends: ["should:return:"],
  396. referencedClasses: []
  397. }),
  398. globals.CodeGeneratorTest);
  399. smalltalk.addMethod(
  400. smalltalk.method({
  401. selector: "testBlockReturn",
  402. protocol: 'tests',
  403. fn: function (){
  404. var self=this;
  405. return smalltalk.withContext(function($ctx1) {
  406. self._should_return_("foo ^ #(1 2 3) collect: [ :each | true ifTrue: [ each + 1 ] ]",[(2), (3), (4)]);
  407. $ctx1.sendIdx["should:return:"]=1;
  408. self._should_return_("foo ^ #(1 2 3) collect: [ :each | false ifFalse: [ each + 1 ] ]",[(2), (3), (4)]);
  409. $ctx1.sendIdx["should:return:"]=2;
  410. self._should_return_("foo ^ #(1 2 3) collect: [ :each | each odd ifTrue: [ each + 1 ] ifFalse: [ each - 1 ] ]",[(2), (1), (4)]);
  411. return self}, function($ctx1) {$ctx1.fill(self,"testBlockReturn",{},globals.CodeGeneratorTest)})},
  412. args: [],
  413. 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).",
  414. messageSends: ["should:return:"],
  415. referencedClasses: []
  416. }),
  417. globals.CodeGeneratorTest);
  418. smalltalk.addMethod(
  419. smalltalk.method({
  420. selector: "testCascades",
  421. protocol: 'tests',
  422. fn: function (){
  423. var self=this;
  424. return smalltalk.withContext(function($ctx1) {
  425. self._should_return_("foo ^ Array new add: 3; add: 4; yourself",[(3), (4)]);
  426. return self}, function($ctx1) {$ctx1.fill(self,"testCascades",{},globals.CodeGeneratorTest)})},
  427. args: [],
  428. source: "testCascades\x0a\x09\x0a\x09self should: 'foo ^ Array new add: 3; add: 4; yourself' return: #(3 4)",
  429. messageSends: ["should:return:"],
  430. referencedClasses: []
  431. }),
  432. globals.CodeGeneratorTest);
  433. smalltalk.addMethod(
  434. smalltalk.method({
  435. selector: "testCascadesWithInlining",
  436. protocol: 'tests',
  437. fn: function (){
  438. var self=this;
  439. return smalltalk.withContext(function($ctx1) {
  440. self._should_return_("foo ^ true ifTrue: [ 1 ] ifFalse: [ 2 ]",(1));
  441. $ctx1.sendIdx["should:return:"]=1;
  442. self._should_return_("foo ^ false ifTrue: [ 1 ] ifFalse: [ 2 ]",(2));
  443. return self}, function($ctx1) {$ctx1.fill(self,"testCascadesWithInlining",{},globals.CodeGeneratorTest)})},
  444. args: [],
  445. 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",
  446. messageSends: ["should:return:"],
  447. referencedClasses: []
  448. }),
  449. globals.CodeGeneratorTest);
  450. smalltalk.addMethod(
  451. smalltalk.method({
  452. selector: "testDynamicArrayElementsOrdered",
  453. protocol: 'tests',
  454. fn: function (){
  455. var self=this;
  456. return smalltalk.withContext(function($ctx1) {
  457. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { x. x := 2 }\x0a",[(1), (2)]);
  458. $ctx1.sendIdx["should:return:"]=1;
  459. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { x. true ifTrue: [ x := 2 ] }\x0a",[(1), (2)]);
  460. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicArrayElementsOrdered",{},globals.CodeGeneratorTest)})},
  461. args: [],
  462. 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).",
  463. messageSends: ["should:return:"],
  464. referencedClasses: []
  465. }),
  466. globals.CodeGeneratorTest);
  467. smalltalk.addMethod(
  468. smalltalk.method({
  469. selector: "testDynamicDictionaryElementsOrdered",
  470. protocol: 'tests',
  471. fn: function (){
  472. var self=this;
  473. return smalltalk.withContext(function($ctx1) {
  474. 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)]));
  475. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicDictionaryElementsOrdered",{},globals.CodeGeneratorTest)})},
  476. args: [],
  477. 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}.",
  478. messageSends: ["should:return:"],
  479. referencedClasses: []
  480. }),
  481. globals.CodeGeneratorTest);
  482. smalltalk.addMethod(
  483. smalltalk.method({
  484. selector: "testDynamicDictionaryWithMoreArrows",
  485. protocol: 'tests',
  486. fn: function (){
  487. var self=this;
  488. function $HashedCollection(){return globals.HashedCollection||(typeof HashedCollection=="undefined"?nil:HashedCollection)}
  489. return smalltalk.withContext(function($ctx1) {
  490. var $2,$1;
  491. $2=_st((1).__minus_gt((2))).__minus_gt((3));
  492. $ctx1.sendIdx["->"]=1;
  493. $1=_st($HashedCollection())._with_($2);
  494. self._should_return_("foo ^ #{1->2->3}",$1);
  495. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicDictionaryWithMoreArrows",{},globals.CodeGeneratorTest)})},
  496. args: [],
  497. source: "testDynamicDictionaryWithMoreArrows\x0a\x09self should: 'foo ^ #{1->2->3}' return: (HashedCollection with: 1->2->3)",
  498. messageSends: ["should:return:", "with:", "->"],
  499. referencedClasses: ["HashedCollection"]
  500. }),
  501. globals.CodeGeneratorTest);
  502. smalltalk.addMethod(
  503. smalltalk.method({
  504. selector: "testGlobalVar",
  505. protocol: 'tests',
  506. fn: function (){
  507. var self=this;
  508. function $BlockClosure(){return globals.BlockClosure||(typeof BlockClosure=="undefined"?nil:BlockClosure)}
  509. return smalltalk.withContext(function($ctx1) {
  510. self._should_return_("foo ^ eval class",$BlockClosure());
  511. $ctx1.sendIdx["should:return:"]=1;
  512. self._should_return_("foo ^ Math cos: 0",(1));
  513. $ctx1.sendIdx["should:return:"]=2;
  514. self._should_return_("foo ^ NonExistingVar",nil);
  515. return self}, function($ctx1) {$ctx1.fill(self,"testGlobalVar",{},globals.CodeGeneratorTest)})},
  516. args: [],
  517. 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",
  518. messageSends: ["should:return:"],
  519. referencedClasses: ["BlockClosure"]
  520. }),
  521. globals.CodeGeneratorTest);
  522. smalltalk.addMethod(
  523. smalltalk.method({
  524. selector: "testInnerTemporalDependentElementsOrdered",
  525. protocol: 'tests',
  526. fn: function (){
  527. var self=this;
  528. function $Array(){return globals.Array||(typeof Array=="undefined"?nil:Array)}
  529. return smalltalk.withContext(function($ctx1) {
  530. var $2,$3,$1,$5,$6,$4,$8,$9,$7,$11,$10;
  531. $2="foo".__minus_gt($Array());
  532. $ctx1.sendIdx["->"]=1;
  533. $3="bar".__minus_gt((2));
  534. $ctx1.sendIdx["->"]=2;
  535. $1=[$2,$3];
  536. self._should_return_("foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: 'foo'->x with: 'bar'->(x := 2)\x0a",$1);
  537. $ctx1.sendIdx["should:return:"]=1;
  538. $5="foo".__minus_gt($Array());
  539. $ctx1.sendIdx["->"]=3;
  540. $6="bar".__minus_gt((2));
  541. $ctx1.sendIdx["->"]=4;
  542. $4=[$5,$6];
  543. self._should_return_("foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: 'foo'->x with: 'bar'->(true ifTrue: [ x := 2 ])\x0a",$4);
  544. $ctx1.sendIdx["should:return:"]=2;
  545. $8="foo".__minus_gt((1));
  546. $ctx1.sendIdx["->"]=5;
  547. $9="bar".__minus_gt((2));
  548. $ctx1.sendIdx["->"]=6;
  549. $7=[$8,$9];
  550. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ Array with: 'foo'->x with: 'bar'->(true ifTrue: [ x := 2 ])\x0a",$7);
  551. $ctx1.sendIdx["should:return:"]=3;
  552. $11="foo".__minus_gt((1));
  553. $ctx1.sendIdx["->"]=7;
  554. $10=[$11,"bar".__minus_gt((2))];
  555. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { 'foo'->x. 'bar'->(true ifTrue: [ x := 2 ]) }\x0a",$10);
  556. $ctx1.sendIdx["should:return:"]=4;
  557. 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)]));
  558. return self}, function($ctx1) {$ctx1.fill(self,"testInnerTemporalDependentElementsOrdered",{},globals.CodeGeneratorTest)})},
  559. args: [],
  560. 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}.",
  561. messageSends: ["should:return:", "->"],
  562. referencedClasses: ["Array"]
  563. }),
  564. globals.CodeGeneratorTest);
  565. smalltalk.addMethod(
  566. smalltalk.method({
  567. selector: "testJSStatement",
  568. protocol: 'tests',
  569. fn: function (){
  570. var self=this;
  571. return smalltalk.withContext(function($ctx1) {
  572. self._should_return_("foo <return 2+3>",(5));
  573. return self}, function($ctx1) {$ctx1.fill(self,"testJSStatement",{},globals.CodeGeneratorTest)})},
  574. args: [],
  575. source: "testJSStatement\x0a\x09self should: 'foo <return 2+3>' return: 5",
  576. messageSends: ["should:return:"],
  577. referencedClasses: []
  578. }),
  579. globals.CodeGeneratorTest);
  580. smalltalk.addMethod(
  581. smalltalk.method({
  582. selector: "testLiterals",
  583. protocol: 'tests',
  584. fn: function (){
  585. var self=this;
  586. return smalltalk.withContext(function($ctx1) {
  587. self._should_return_("foo ^ 1",(1));
  588. $ctx1.sendIdx["should:return:"]=1;
  589. self._should_return_("foo ^ 'hello'","hello");
  590. $ctx1.sendIdx["should:return:"]=2;
  591. self._should_return_("foo ^ #(1 2 3 4)",[(1), (2), (3), (4)]);
  592. $ctx1.sendIdx["should:return:"]=3;
  593. self._should_return_("foo ^ {1. [:x | x ] value: 2. 3. [4] value}",[(1), (2), (3), (4)]);
  594. $ctx1.sendIdx["should:return:"]=4;
  595. self._should_return_("foo ^ true",true);
  596. $ctx1.sendIdx["should:return:"]=5;
  597. self._should_return_("foo ^ false",false);
  598. $ctx1.sendIdx["should:return:"]=6;
  599. self._should_return_("foo ^ #{1->2. 3->4}",globals.HashedCollection._newFromPairs_([(1),(2),(3),(4)]));
  600. $ctx1.sendIdx["should:return:"]=7;
  601. self._should_return_("foo ^ #hello","hello");
  602. $ctx1.sendIdx["should:return:"]=8;
  603. self._should_return_("foo ^ -123.456",(-123.456));
  604. $ctx1.sendIdx["should:return:"]=9;
  605. self._should_return_("foo ^ -2.5e4",(-25000));
  606. return self}, function($ctx1) {$ctx1.fill(self,"testLiterals",{},globals.CodeGeneratorTest)})},
  607. args: [],
  608. source: "testLiterals\x0a\x09self should: 'foo ^ 1' return: 1.\x0a\x09self should: 'foo ^ ''hello''' return: 'hello'.\x0a\x09self should: 'foo ^ #(1 2 3 4)' return: #(1 2 3 4).\x0a\x09self should: 'foo ^ {1. [:x | x ] value: 2. 3. [4] value}' return: #(1 2 3 4).\x0a\x09self should: 'foo ^ true' return: true.\x0a\x09self should: 'foo ^ false' return: false.\x0a\x09self should: 'foo ^ #{1->2. 3->4}' return: #{1->2. 3->4}.\x0a\x09self should: 'foo ^ #hello' return: #hello.\x0a\x09self should: 'foo ^ -123.456' return: -123.456.\x0a\x09self should: 'foo ^ -2.5e4' return: -25000.",
  609. messageSends: ["should:return:"],
  610. referencedClasses: []
  611. }),
  612. globals.CodeGeneratorTest);
  613. smalltalk.addMethod(
  614. smalltalk.method({
  615. selector: "testLocalReturn",
  616. protocol: 'tests',
  617. fn: function (){
  618. var self=this;
  619. return smalltalk.withContext(function($ctx1) {
  620. self._should_return_("foo ^ 1",(1));
  621. $ctx1.sendIdx["should:return:"]=1;
  622. self._should_return_("foo ^ 1 + 1",(2));
  623. $ctx1.sendIdx["should:return:"]=2;
  624. self._should_return_("foo ",self["@receiver"]);
  625. $ctx1.sendIdx["should:return:"]=3;
  626. self._should_return_("foo self asString",self["@receiver"]);
  627. $ctx1.sendIdx["should:return:"]=4;
  628. self._should_return_("foo | a b | a := 1. b := 2. ^ a + b",(3));
  629. return self}, function($ctx1) {$ctx1.fill(self,"testLocalReturn",{},globals.CodeGeneratorTest)})},
  630. args: [],
  631. 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",
  632. messageSends: ["should:return:"],
  633. referencedClasses: []
  634. }),
  635. globals.CodeGeneratorTest);
  636. smalltalk.addMethod(
  637. smalltalk.method({
  638. selector: "testMessageSends",
  639. protocol: 'tests',
  640. fn: function (){
  641. var self=this;
  642. return smalltalk.withContext(function($ctx1) {
  643. self._should_return_("foo ^ 1 asString","1");
  644. $ctx1.sendIdx["should:return:"]=1;
  645. self._should_return_("foo ^ 1 + 1",(2));
  646. $ctx1.sendIdx["should:return:"]=2;
  647. self._should_return_("foo ^ 1 + 2 * 3",(9));
  648. $ctx1.sendIdx["should:return:"]=3;
  649. self._should_return_("foo ^ 1 to: 3",[(1), (2), (3)]);
  650. $ctx1.sendIdx["should:return:"]=4;
  651. self._should_return_("foo ^ 1 to: 5 by: 2",[(1), (3), (5)]);
  652. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSends",{},globals.CodeGeneratorTest)})},
  653. args: [],
  654. 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)",
  655. messageSends: ["should:return:"],
  656. referencedClasses: []
  657. }),
  658. globals.CodeGeneratorTest);
  659. smalltalk.addMethod(
  660. smalltalk.method({
  661. selector: "testMultipleSequences",
  662. protocol: 'tests',
  663. fn: function (){
  664. var self=this;
  665. return smalltalk.withContext(function($ctx1) {
  666. self._should_return_("foo | a b c | a := 2. b := 3. c := a + b. ^ c * 6",(30));
  667. return self}, function($ctx1) {$ctx1.fill(self,"testMultipleSequences",{},globals.CodeGeneratorTest)})},
  668. args: [],
  669. source: "testMultipleSequences\x0a\x09self should: 'foo | a b c | a := 2. b := 3. c := a + b. ^ c * 6' return: 30",
  670. messageSends: ["should:return:"],
  671. referencedClasses: []
  672. }),
  673. globals.CodeGeneratorTest);
  674. smalltalk.addMethod(
  675. smalltalk.method({
  676. selector: "testMutableLiterals",
  677. protocol: 'tests',
  678. fn: function (){
  679. var self=this;
  680. return smalltalk.withContext(function($ctx1) {
  681. self._should_return_("foo ^ #( 1 2 ) at: 1 put: 3; yourself",[(3), (2)]);
  682. return self}, function($ctx1) {$ctx1.fill(self,"testMutableLiterals",{},globals.CodeGeneratorTest)})},
  683. args: [],
  684. 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)",
  685. messageSends: ["should:return:"],
  686. referencedClasses: []
  687. }),
  688. globals.CodeGeneratorTest);
  689. smalltalk.addMethod(
  690. smalltalk.method({
  691. selector: "testNestedIfTrue",
  692. protocol: 'tests',
  693. fn: function (){
  694. var self=this;
  695. return smalltalk.withContext(function($ctx1) {
  696. self._should_return_("foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]",(1));
  697. $ctx1.sendIdx["should:return:"]=1;
  698. self._should_return_("foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]",nil);
  699. $ctx1.sendIdx["should:return:"]=2;
  700. self._should_return_("foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]",(1));
  701. $ctx1.sendIdx["should:return:"]=3;
  702. self._should_return_("foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]",self["@receiver"]);
  703. return self}, function($ctx1) {$ctx1.fill(self,"testNestedIfTrue",{},globals.CodeGeneratorTest)})},
  704. args: [],
  705. 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.",
  706. messageSends: ["should:return:"],
  707. referencedClasses: []
  708. }),
  709. globals.CodeGeneratorTest);
  710. smalltalk.addMethod(
  711. smalltalk.method({
  712. selector: "testNestedSends",
  713. protocol: 'tests',
  714. fn: function (){
  715. var self=this;
  716. function $Point(){return globals.Point||(typeof Point=="undefined"?nil:Point)}
  717. return smalltalk.withContext(function($ctx1) {
  718. self._should_return_("foo ^ (Point x: (Point x: 2 y: 3) y: 4) asString",_st(_st($Point())._x_y_((2).__at((3)),(4)))._asString());
  719. return self}, function($ctx1) {$ctx1.fill(self,"testNestedSends",{},globals.CodeGeneratorTest)})},
  720. args: [],
  721. source: "testNestedSends\x0a\x09self should: 'foo ^ (Point x: (Point x: 2 y: 3) y: 4) asString' return: (Point x: (2@3) y: 4) asString",
  722. messageSends: ["should:return:", "asString", "x:y:", "@"],
  723. referencedClasses: ["Point"]
  724. }),
  725. globals.CodeGeneratorTest);
  726. smalltalk.addMethod(
  727. smalltalk.method({
  728. selector: "testNonLocalReturn",
  729. protocol: 'tests',
  730. fn: function (){
  731. var self=this;
  732. return smalltalk.withContext(function($ctx1) {
  733. self._should_return_("foo [ ^ 1 ] value",(1));
  734. $ctx1.sendIdx["should:return:"]=1;
  735. self._should_return_("foo [ ^ 1 + 1 ] value",(2));
  736. $ctx1.sendIdx["should:return:"]=2;
  737. self._should_return_("foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt",(3));
  738. $ctx1.sendIdx["should:return:"]=3;
  739. self._should_return_("foo [ :x | ^ x + x ] value: 4. ^ 2",(8));
  740. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn",{},globals.CodeGeneratorTest)})},
  741. args: [],
  742. 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",
  743. messageSends: ["should:return:"],
  744. referencedClasses: []
  745. }),
  746. globals.CodeGeneratorTest);
  747. smalltalk.addMethod(
  748. smalltalk.method({
  749. selector: "testPascalCaseGlobal",
  750. protocol: 'tests',
  751. fn: function (){
  752. var self=this;
  753. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  754. return smalltalk.withContext(function($ctx1) {
  755. self._should_return_("foo ^Object",_st(_st($Smalltalk())._globals())._at_("Object"));
  756. $ctx1.sendIdx["should:return:"]=1;
  757. self._should_return_("foo ^NonExistent",nil);
  758. return self}, function($ctx1) {$ctx1.fill(self,"testPascalCaseGlobal",{},globals.CodeGeneratorTest)})},
  759. args: [],
  760. source: "testPascalCaseGlobal\x0a\x09self should: 'foo ^Object' return: (Smalltalk globals at: 'Object').\x0a\x09self should: 'foo ^NonExistent' return: nil",
  761. messageSends: ["should:return:", "at:", "globals"],
  762. referencedClasses: ["Smalltalk"]
  763. }),
  764. globals.CodeGeneratorTest);
  765. smalltalk.addMethod(
  766. smalltalk.method({
  767. selector: "testSendReceiverAndArgumentsOrdered",
  768. protocol: 'tests',
  769. fn: function (){
  770. var self=this;
  771. function $Array(){return globals.Array||(typeof Array=="undefined"?nil:Array)}
  772. return smalltalk.withContext(function($ctx1) {
  773. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ Array with: x with: (true ifTrue: [ x := 2 ])\x0a",[(1), (2)]);
  774. $ctx1.sendIdx["should:return:"]=1;
  775. self._should_return_("foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: x with: (true ifTrue: [ x := 2 ])\x0a",[$Array(),(2)]);
  776. return self}, function($ctx1) {$ctx1.fill(self,"testSendReceiverAndArgumentsOrdered",{},globals.CodeGeneratorTest)})},
  777. args: [],
  778. 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}.",
  779. messageSends: ["should:return:"],
  780. referencedClasses: ["Array"]
  781. }),
  782. globals.CodeGeneratorTest);
  783. smalltalk.addMethod(
  784. smalltalk.method({
  785. selector: "testSuperSend",
  786. protocol: 'tests',
  787. fn: function (){
  788. var self=this;
  789. return smalltalk.withContext(function($ctx1) {
  790. self._should_receiver_return_("foo ^ super isBoolean",true,false);
  791. return self}, function($ctx1) {$ctx1.fill(self,"testSuperSend",{},globals.CodeGeneratorTest)})},
  792. args: [],
  793. source: "testSuperSend\x0a\x09self \x0a\x09\x09should: 'foo ^ super isBoolean' \x0a\x09\x09receiver: true\x0a\x09\x09return: false",
  794. messageSends: ["should:receiver:return:"],
  795. referencedClasses: []
  796. }),
  797. globals.CodeGeneratorTest);
  798. smalltalk.addMethod(
  799. smalltalk.method({
  800. selector: "testTempVariables",
  801. protocol: 'tests',
  802. fn: function (){
  803. var self=this;
  804. return smalltalk.withContext(function($ctx1) {
  805. self._should_return_("foo | a | ^ a",nil);
  806. $ctx1.sendIdx["should:return:"]=1;
  807. self._should_return_("foo | AVariable | ^ AVariable",nil);
  808. $ctx1.sendIdx["should:return:"]=2;
  809. self._should_return_("foo | a b c | ^ c",nil);
  810. $ctx1.sendIdx["should:return:"]=3;
  811. self._should_return_("foo | a | [ | d | ^ d ] value",nil);
  812. $ctx1.sendIdx["should:return:"]=4;
  813. self._should_return_("foo | a | a:= 1. ^ a",(1));
  814. $ctx1.sendIdx["should:return:"]=5;
  815. self._should_return_("foo | AVariable | AVariable := 1. ^ AVariable",(1));
  816. return self}, function($ctx1) {$ctx1.fill(self,"testTempVariables",{},globals.CodeGeneratorTest)})},
  817. args: [],
  818. 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.",
  819. messageSends: ["should:return:"],
  820. referencedClasses: []
  821. }),
  822. globals.CodeGeneratorTest);
  823. smalltalk.addMethod(
  824. smalltalk.method({
  825. selector: "testThisContext",
  826. protocol: 'tests',
  827. fn: function (){
  828. var self=this;
  829. return smalltalk.withContext(function($ctx1) {
  830. self._should_return_("foo ^ [ thisContext ] value outerContext == thisContext",true);
  831. return self}, function($ctx1) {$ctx1.fill(self,"testThisContext",{},globals.CodeGeneratorTest)})},
  832. args: [],
  833. source: "testThisContext\x0a\x09self should: 'foo ^ [ thisContext ] value outerContext == thisContext' return: true",
  834. messageSends: ["should:return:"],
  835. referencedClasses: []
  836. }),
  837. globals.CodeGeneratorTest);
  838. smalltalk.addMethod(
  839. smalltalk.method({
  840. selector: "testifFalse",
  841. protocol: 'tests',
  842. fn: function (){
  843. var self=this;
  844. return smalltalk.withContext(function($ctx1) {
  845. self._should_return_("foo true ifFalse: [ ^ 1 ]",self["@receiver"]);
  846. $ctx1.sendIdx["should:return:"]=1;
  847. self._should_return_("foo false ifFalse: [ ^ 2 ]",(2));
  848. $ctx1.sendIdx["should:return:"]=2;
  849. self._should_return_("foo ^ true ifFalse: [ 1 ]",nil);
  850. $ctx1.sendIdx["should:return:"]=3;
  851. self._should_return_("foo ^ false ifFalse: [ 2 ]",(2));
  852. return self}, function($ctx1) {$ctx1.fill(self,"testifFalse",{},globals.CodeGeneratorTest)})},
  853. args: [],
  854. 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.",
  855. messageSends: ["should:return:"],
  856. referencedClasses: []
  857. }),
  858. globals.CodeGeneratorTest);
  859. smalltalk.addMethod(
  860. smalltalk.method({
  861. selector: "testifFalseIfTrue",
  862. protocol: 'tests',
  863. fn: function (){
  864. var self=this;
  865. return smalltalk.withContext(function($ctx1) {
  866. self._should_return_("foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]",(2));
  867. $ctx1.sendIdx["should:return:"]=1;
  868. self._should_return_("foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]",(2));
  869. $ctx1.sendIdx["should:return:"]=2;
  870. self._should_return_("foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]",(2));
  871. $ctx1.sendIdx["should:return:"]=3;
  872. self._should_return_("foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]",(2));
  873. return self}, function($ctx1) {$ctx1.fill(self,"testifFalseIfTrue",{},globals.CodeGeneratorTest)})},
  874. args: [],
  875. 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.",
  876. messageSends: ["should:return:"],
  877. referencedClasses: []
  878. }),
  879. globals.CodeGeneratorTest);
  880. smalltalk.addMethod(
  881. smalltalk.method({
  882. selector: "testifNil",
  883. protocol: 'tests',
  884. fn: function (){
  885. var self=this;
  886. return smalltalk.withContext(function($ctx1) {
  887. self._should_return_("foo ^ 1 ifNil: [ 2 ]",(1));
  888. $ctx1.sendIdx["should:return:"]=1;
  889. self._should_return_("foo ^ nil ifNil: [ 2 ]",(2));
  890. $ctx1.sendIdx["should:return:"]=2;
  891. self._should_return_("foo 1 ifNil: [ ^ 2 ]",self["@receiver"]);
  892. $ctx1.sendIdx["should:return:"]=3;
  893. self._should_return_("foo nil ifNil: [ ^ 2 ]",(2));
  894. return self}, function($ctx1) {$ctx1.fill(self,"testifNil",{},globals.CodeGeneratorTest)})},
  895. args: [],
  896. 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.",
  897. messageSends: ["should:return:"],
  898. referencedClasses: []
  899. }),
  900. globals.CodeGeneratorTest);
  901. smalltalk.addMethod(
  902. smalltalk.method({
  903. selector: "testifNilIfNotNil",
  904. protocol: 'tests',
  905. fn: function (){
  906. var self=this;
  907. return smalltalk.withContext(function($ctx1) {
  908. self._should_return_("foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]",(3));
  909. $ctx1.sendIdx["should:return:"]=1;
  910. self._should_return_("foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]",(2));
  911. $ctx1.sendIdx["should:return:"]=2;
  912. self._should_return_("foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(3));
  913. $ctx1.sendIdx["should:return:"]=3;
  914. self._should_return_("foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(2));
  915. return self}, function($ctx1) {$ctx1.fill(self,"testifNilIfNotNil",{},globals.CodeGeneratorTest)})},
  916. args: [],
  917. 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.",
  918. messageSends: ["should:return:"],
  919. referencedClasses: []
  920. }),
  921. globals.CodeGeneratorTest);
  922. smalltalk.addMethod(
  923. smalltalk.method({
  924. selector: "testifNotNil",
  925. protocol: 'tests',
  926. fn: function (){
  927. var self=this;
  928. return smalltalk.withContext(function($ctx1) {
  929. self._should_return_("foo ^ 1 ifNotNil: [ 2 ]",(2));
  930. $ctx1.sendIdx["should:return:"]=1;
  931. self._should_return_("foo ^ nil ifNotNil: [ 2 ]",nil);
  932. $ctx1.sendIdx["should:return:"]=2;
  933. self._should_return_("foo 1 ifNotNil: [ ^ 2 ]",(2));
  934. $ctx1.sendIdx["should:return:"]=3;
  935. self._should_return_("foo nil ifNotNil: [ ^ 2 ]",self["@receiver"]);
  936. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNil",{},globals.CodeGeneratorTest)})},
  937. args: [],
  938. 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.",
  939. messageSends: ["should:return:"],
  940. referencedClasses: []
  941. }),
  942. globals.CodeGeneratorTest);
  943. smalltalk.addMethod(
  944. smalltalk.method({
  945. selector: "testifNotNilWithArgument",
  946. protocol: 'tests',
  947. fn: function (){
  948. var self=this;
  949. return smalltalk.withContext(function($ctx1) {
  950. self._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ]",(3));
  951. $ctx1.sendIdx["should:return:"]=1;
  952. self._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ]",nil);
  953. $ctx1.sendIdx["should:return:"]=2;
  954. self._should_return_("foo ^ 1 ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(3));
  955. $ctx1.sendIdx["should:return:"]=3;
  956. self._should_return_("foo ^ nil ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(5));
  957. $ctx1.sendIdx["should:return:"]=4;
  958. self._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(3));
  959. $ctx1.sendIdx["should:return:"]=5;
  960. self._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(5));
  961. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNilWithArgument",{},globals.CodeGeneratorTest)})},
  962. args: [],
  963. 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",
  964. messageSends: ["should:return:"],
  965. referencedClasses: []
  966. }),
  967. globals.CodeGeneratorTest);
  968. smalltalk.addMethod(
  969. smalltalk.method({
  970. selector: "testifTrue",
  971. protocol: 'tests',
  972. fn: function (){
  973. var self=this;
  974. return smalltalk.withContext(function($ctx1) {
  975. self._should_return_("foo false ifTrue: [ ^ 1 ]",self["@receiver"]);
  976. $ctx1.sendIdx["should:return:"]=1;
  977. self._should_return_("foo true ifTrue: [ ^ 2 ]",(2));
  978. $ctx1.sendIdx["should:return:"]=2;
  979. self._should_return_("foo ^ false ifTrue: [ 1 ]",nil);
  980. $ctx1.sendIdx["should:return:"]=3;
  981. self._should_return_("foo ^ true ifTrue: [ 2 ]",(2));
  982. return self}, function($ctx1) {$ctx1.fill(self,"testifTrue",{},globals.CodeGeneratorTest)})},
  983. args: [],
  984. 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.",
  985. messageSends: ["should:return:"],
  986. referencedClasses: []
  987. }),
  988. globals.CodeGeneratorTest);
  989. smalltalk.addMethod(
  990. smalltalk.method({
  991. selector: "testifTrueIfFalse",
  992. protocol: 'tests',
  993. fn: function (){
  994. var self=this;
  995. return smalltalk.withContext(function($ctx1) {
  996. self._should_return_("foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]",(2));
  997. $ctx1.sendIdx["should:return:"]=1;
  998. self._should_return_("foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]",(1));
  999. $ctx1.sendIdx["should:return:"]=2;
  1000. self._should_return_("foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]",(1));
  1001. $ctx1.sendIdx["should:return:"]=3;
  1002. self._should_return_("foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]",(2));
  1003. return self}, function($ctx1) {$ctx1.fill(self,"testifTrueIfFalse",{},globals.CodeGeneratorTest)})},
  1004. args: [],
  1005. 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.",
  1006. messageSends: ["should:return:"],
  1007. referencedClasses: []
  1008. }),
  1009. globals.CodeGeneratorTest);
  1010. smalltalk.addClass('InliningCodeGeneratorTest', globals.CodeGeneratorTest, [], 'Compiler-Tests');
  1011. smalltalk.addMethod(
  1012. smalltalk.method({
  1013. selector: "codeGeneratorClass",
  1014. protocol: 'accessing',
  1015. fn: function (){
  1016. var self=this;
  1017. function $InliningCodeGenerator(){return globals.InliningCodeGenerator||(typeof InliningCodeGenerator=="undefined"?nil:InliningCodeGenerator)}
  1018. return $InliningCodeGenerator();
  1019. },
  1020. args: [],
  1021. source: "codeGeneratorClass\x0a\x09^ InliningCodeGenerator",
  1022. messageSends: [],
  1023. referencedClasses: ["InliningCodeGenerator"]
  1024. }),
  1025. globals.InliningCodeGeneratorTest);
  1026. smalltalk.addClass('InterpreterTest', globals.CodeGeneratorTest, [], 'Compiler-Tests');
  1027. smalltalk.addMethod(
  1028. smalltalk.method({
  1029. selector: "analyze:forClass:",
  1030. protocol: 'parsing',
  1031. fn: function (aNode,aClass){
  1032. var self=this;
  1033. function $SemanticAnalyzer(){return globals.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1034. return smalltalk.withContext(function($ctx1) {
  1035. _st(_st($SemanticAnalyzer())._on_(aClass))._visit_(aNode);
  1036. return aNode;
  1037. }, function($ctx1) {$ctx1.fill(self,"analyze:forClass:",{aNode:aNode,aClass:aClass},globals.InterpreterTest)})},
  1038. args: ["aNode", "aClass"],
  1039. source: "analyze: aNode forClass: aClass\x0a\x09(SemanticAnalyzer on: aClass) visit: aNode.\x0a\x09^ aNode",
  1040. messageSends: ["visit:", "on:"],
  1041. referencedClasses: ["SemanticAnalyzer"]
  1042. }),
  1043. globals.InterpreterTest);
  1044. smalltalk.addMethod(
  1045. smalltalk.method({
  1046. selector: "interpret:receiver:withArguments:",
  1047. protocol: 'private',
  1048. fn: function (aString,anObject,aDictionary){
  1049. var self=this;
  1050. var ctx,interpreter;
  1051. function $ASTInterpreter(){return globals.ASTInterpreter||(typeof ASTInterpreter=="undefined"?nil:ASTInterpreter)}
  1052. function $AIContext(){return globals.AIContext||(typeof AIContext=="undefined"?nil:AIContext)}
  1053. return smalltalk.withContext(function($ctx1) {
  1054. var $1,$2,$4,$5,$3;
  1055. interpreter=_st($ASTInterpreter())._new();
  1056. $ctx1.sendIdx["new"]=1;
  1057. $1=_st($AIContext())._new();
  1058. _st($1)._receiver_(anObject);
  1059. _st($1)._interpreter_(interpreter);
  1060. $2=_st($1)._yourself();
  1061. ctx=$2;
  1062. _st(aDictionary)._keysAndValuesDo_((function(key,value){
  1063. return smalltalk.withContext(function($ctx2) {
  1064. return _st(ctx)._localAt_put_(key,value);
  1065. }, function($ctx2) {$ctx2.fillBlock({key:key,value:value},$ctx1,1)})}));
  1066. $4=interpreter;
  1067. _st($4)._context_(ctx);
  1068. _st($4)._interpret_(_st(self._parse_forClass_(aString,_st(anObject)._class()))._nextChild());
  1069. _st($4)._proceed();
  1070. $5=_st($4)._result();
  1071. $3=$5;
  1072. return $3;
  1073. }, function($ctx1) {$ctx1.fill(self,"interpret:receiver:withArguments:",{aString:aString,anObject:anObject,aDictionary:aDictionary,ctx:ctx,interpreter:interpreter},globals.InterpreterTest)})},
  1074. args: ["aString", "anObject", "aDictionary"],
  1075. source: "interpret: aString receiver: anObject withArguments: aDictionary\x0a\x09\x22The food is a methodNode. Interpret the sequenceNode only\x22\x0a\x09\x0a\x09| ctx interpreter |\x0a\x09\x0a\x09interpreter := ASTInterpreter new.\x0a\x09\x0a\x09ctx := AIContext new\x0a\x09\x09receiver: anObject;\x0a\x09\x09interpreter: interpreter;\x0a\x09\x09yourself.\x0a\x09aDictionary keysAndValuesDo: [ :key :value |\x0a\x09\x09ctx localAt: key put: value ].\x0a\x09\x0a\x09^ interpreter\x0a\x09\x09context: ctx;\x0a\x09\x09interpret: (self parse: aString forClass: anObject class) nextChild;\x0a\x09\x09proceed;\x0a\x09\x09result",
  1076. messageSends: ["new", "receiver:", "interpreter:", "yourself", "keysAndValuesDo:", "localAt:put:", "context:", "interpret:", "nextChild", "parse:forClass:", "class", "proceed", "result"],
  1077. referencedClasses: ["ASTInterpreter", "AIContext"]
  1078. }),
  1079. globals.InterpreterTest);
  1080. smalltalk.addMethod(
  1081. smalltalk.method({
  1082. selector: "parse:",
  1083. protocol: 'parsing',
  1084. fn: function (aString){
  1085. var self=this;
  1086. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1087. return smalltalk.withContext(function($ctx1) {
  1088. var $1;
  1089. $1=_st($Smalltalk())._parse_(aString);
  1090. return $1;
  1091. }, function($ctx1) {$ctx1.fill(self,"parse:",{aString:aString},globals.InterpreterTest)})},
  1092. args: ["aString"],
  1093. source: "parse: aString\x0a\x09^ Smalltalk parse: aString",
  1094. messageSends: ["parse:"],
  1095. referencedClasses: ["Smalltalk"]
  1096. }),
  1097. globals.InterpreterTest);
  1098. smalltalk.addMethod(
  1099. smalltalk.method({
  1100. selector: "parse:forClass:",
  1101. protocol: 'parsing',
  1102. fn: function (aString,aClass){
  1103. var self=this;
  1104. return smalltalk.withContext(function($ctx1) {
  1105. var $1;
  1106. $1=self._analyze_forClass_(self._parse_(aString),aClass);
  1107. return $1;
  1108. }, function($ctx1) {$ctx1.fill(self,"parse:forClass:",{aString:aString,aClass:aClass},globals.InterpreterTest)})},
  1109. args: ["aString", "aClass"],
  1110. source: "parse: aString forClass: aClass\x0a\x09^ self analyze: (self parse: aString) forClass: aClass",
  1111. messageSends: ["analyze:forClass:", "parse:"],
  1112. referencedClasses: []
  1113. }),
  1114. globals.InterpreterTest);
  1115. smalltalk.addMethod(
  1116. smalltalk.method({
  1117. selector: "should:receiver:return:",
  1118. protocol: 'testing',
  1119. fn: function (aString,anObject,aResult){
  1120. var self=this;
  1121. return smalltalk.withContext(function($ctx1) {
  1122. var $1;
  1123. self["@receiver"]=anObject;
  1124. $1=self._assert_equals_(self._interpret_receiver_withArguments_(aString,self["@receiver"],globals.HashedCollection._newFromPairs_([])),aResult);
  1125. return $1;
  1126. }, function($ctx1) {$ctx1.fill(self,"should:receiver:return:",{aString:aString,anObject:anObject,aResult:aResult},globals.InterpreterTest)})},
  1127. args: ["aString", "anObject", "aResult"],
  1128. 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",
  1129. messageSends: ["assert:equals:", "interpret:receiver:withArguments:"],
  1130. referencedClasses: []
  1131. }),
  1132. globals.InterpreterTest);
  1133. smalltalk.addMethod(
  1134. smalltalk.method({
  1135. selector: "should:return:",
  1136. protocol: 'testing',
  1137. fn: function (aString,anObject){
  1138. var self=this;
  1139. return smalltalk.withContext(function($ctx1) {
  1140. var $1;
  1141. $1=self._should_receiver_return_(aString,self["@receiver"],anObject);
  1142. return $1;
  1143. }, function($ctx1) {$ctx1.fill(self,"should:return:",{aString:aString,anObject:anObject},globals.InterpreterTest)})},
  1144. args: ["aString", "anObject"],
  1145. source: "should: aString return: anObject\x0a\x09^ self \x0a\x09\x09should: aString\x0a\x09\x09receiver: receiver\x0a\x09\x09return: anObject",
  1146. messageSends: ["should:receiver:return:"],
  1147. referencedClasses: []
  1148. }),
  1149. globals.InterpreterTest);
  1150. smalltalk.addClass('ScopeVarTest', globals.TestCase, [], 'Compiler-Tests');
  1151. smalltalk.addMethod(
  1152. smalltalk.method({
  1153. selector: "testClassRefVar",
  1154. protocol: 'tests',
  1155. fn: function (){
  1156. var self=this;
  1157. var node;
  1158. function $VariableNode(){return globals.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1159. function $SemanticAnalyzer(){return globals.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1160. function $MethodLexicalScope(){return globals.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1161. return smalltalk.withContext(function($ctx1) {
  1162. var $1,$2,$3,$4;
  1163. $1=_st($VariableNode())._new();
  1164. $ctx1.sendIdx["new"]=1;
  1165. _st($1)._value_("Object");
  1166. $2=_st($1)._yourself();
  1167. node=$2;
  1168. $3=_st($SemanticAnalyzer())._new();
  1169. $ctx1.sendIdx["new"]=2;
  1170. _st($3)._pushScope_(_st($MethodLexicalScope())._new());
  1171. $4=_st($3)._visit_(node);
  1172. self._assert_(_st(_st(node)._binding())._isClassRefVar());
  1173. return self}, function($ctx1) {$ctx1.fill(self,"testClassRefVar",{node:node},globals.ScopeVarTest)})},
  1174. args: [],
  1175. 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",
  1176. messageSends: ["value:", "new", "yourself", "pushScope:", "visit:", "assert:", "isClassRefVar", "binding"],
  1177. referencedClasses: ["VariableNode", "SemanticAnalyzer", "MethodLexicalScope"]
  1178. }),
  1179. globals.ScopeVarTest);
  1180. smalltalk.addMethod(
  1181. smalltalk.method({
  1182. selector: "testInstanceVar",
  1183. protocol: 'tests',
  1184. fn: function (){
  1185. var self=this;
  1186. var node,scope;
  1187. function $VariableNode(){return globals.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1188. function $MethodLexicalScope(){return globals.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1189. return smalltalk.withContext(function($ctx1) {
  1190. var $1,$2;
  1191. $1=_st($VariableNode())._new();
  1192. $ctx1.sendIdx["new"]=1;
  1193. _st($1)._value_("bzzz");
  1194. $2=_st($1)._yourself();
  1195. node=$2;
  1196. scope=_st($MethodLexicalScope())._new();
  1197. _st(scope)._addIVar_("bzzz");
  1198. self._assert_(_st(_st(scope)._bindingFor_(node))._isInstanceVar());
  1199. return self}, function($ctx1) {$ctx1.fill(self,"testInstanceVar",{node:node,scope:scope},globals.ScopeVarTest)})},
  1200. args: [],
  1201. 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",
  1202. messageSends: ["value:", "new", "yourself", "addIVar:", "assert:", "isInstanceVar", "bindingFor:"],
  1203. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1204. }),
  1205. globals.ScopeVarTest);
  1206. smalltalk.addMethod(
  1207. smalltalk.method({
  1208. selector: "testPseudoVar",
  1209. protocol: 'tests',
  1210. fn: function (){
  1211. var self=this;
  1212. var node,pseudoVars;
  1213. function $VariableNode(){return globals.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1214. function $MethodLexicalScope(){return globals.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1215. return smalltalk.withContext(function($ctx1) {
  1216. var $1,$2;
  1217. pseudoVars=["self", "super", "true", "false", "nil"];
  1218. _st(pseudoVars)._do_((function(each){
  1219. return smalltalk.withContext(function($ctx2) {
  1220. $1=_st($VariableNode())._new();
  1221. $ctx2.sendIdx["new"]=1;
  1222. _st($1)._value_(each);
  1223. $2=_st($1)._yourself();
  1224. node=$2;
  1225. node;
  1226. return self._assert_(_st(_st(_st($MethodLexicalScope())._new())._bindingFor_(node))._isPseudoVar());
  1227. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1228. return self}, function($ctx1) {$ctx1.fill(self,"testPseudoVar",{node:node,pseudoVars:pseudoVars},globals.ScopeVarTest)})},
  1229. args: [],
  1230. 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 ]",
  1231. messageSends: ["do:", "value:", "new", "yourself", "assert:", "isPseudoVar", "bindingFor:"],
  1232. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1233. }),
  1234. globals.ScopeVarTest);
  1235. smalltalk.addMethod(
  1236. smalltalk.method({
  1237. selector: "testTempVar",
  1238. protocol: 'tests',
  1239. fn: function (){
  1240. var self=this;
  1241. var node,scope;
  1242. function $VariableNode(){return globals.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1243. function $MethodLexicalScope(){return globals.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1244. return smalltalk.withContext(function($ctx1) {
  1245. var $1,$2;
  1246. $1=_st($VariableNode())._new();
  1247. $ctx1.sendIdx["new"]=1;
  1248. _st($1)._value_("bzzz");
  1249. $2=_st($1)._yourself();
  1250. node=$2;
  1251. scope=_st($MethodLexicalScope())._new();
  1252. _st(scope)._addTemp_("bzzz");
  1253. self._assert_(_st(_st(scope)._bindingFor_(node))._isTempVar());
  1254. return self}, function($ctx1) {$ctx1.fill(self,"testTempVar",{node:node,scope:scope},globals.ScopeVarTest)})},
  1255. args: [],
  1256. 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",
  1257. messageSends: ["value:", "new", "yourself", "addTemp:", "assert:", "isTempVar", "bindingFor:"],
  1258. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1259. }),
  1260. globals.ScopeVarTest);
  1261. smalltalk.addMethod(
  1262. smalltalk.method({
  1263. selector: "testUnknownVar",
  1264. protocol: 'tests',
  1265. fn: function (){
  1266. var self=this;
  1267. var node;
  1268. function $VariableNode(){return globals.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1269. function $MethodLexicalScope(){return globals.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1270. return smalltalk.withContext(function($ctx1) {
  1271. var $1,$2;
  1272. $1=_st($VariableNode())._new();
  1273. $ctx1.sendIdx["new"]=1;
  1274. _st($1)._value_("bzzz");
  1275. $2=_st($1)._yourself();
  1276. node=$2;
  1277. self._assert_(_st(_st(_st($MethodLexicalScope())._new())._bindingFor_(node))._isNil());
  1278. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVar",{node:node},globals.ScopeVarTest)})},
  1279. args: [],
  1280. source: "testUnknownVar\x0a\x09| node |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09self assert: (MethodLexicalScope new bindingFor: node) isNil",
  1281. messageSends: ["value:", "new", "yourself", "assert:", "isNil", "bindingFor:"],
  1282. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1283. }),
  1284. globals.ScopeVarTest);
  1285. smalltalk.addClass('SemanticAnalyzerTest', globals.TestCase, ['analyzer'], 'Compiler-Tests');
  1286. smalltalk.addMethod(
  1287. smalltalk.method({
  1288. selector: "setUp",
  1289. protocol: 'running',
  1290. fn: function (){
  1291. var self=this;
  1292. function $SemanticAnalyzer(){return globals.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1293. function $Object(){return globals.Object||(typeof Object=="undefined"?nil:Object)}
  1294. return smalltalk.withContext(function($ctx1) {
  1295. self["@analyzer"]=_st($SemanticAnalyzer())._on_($Object());
  1296. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},globals.SemanticAnalyzerTest)})},
  1297. args: [],
  1298. source: "setUp\x0a\x09analyzer := SemanticAnalyzer on: Object",
  1299. messageSends: ["on:"],
  1300. referencedClasses: ["SemanticAnalyzer", "Object"]
  1301. }),
  1302. globals.SemanticAnalyzerTest);
  1303. smalltalk.addMethod(
  1304. smalltalk.method({
  1305. selector: "testAssignment",
  1306. protocol: 'tests',
  1307. fn: function (){
  1308. var self=this;
  1309. var src,ast;
  1310. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1311. function $InvalidAssignmentError(){return globals.InvalidAssignmentError||(typeof InvalidAssignmentError=="undefined"?nil:InvalidAssignmentError)}
  1312. return smalltalk.withContext(function($ctx1) {
  1313. src="foo self := 1";
  1314. ast=_st($Smalltalk())._parse_(src);
  1315. self._should_raise_((function(){
  1316. return smalltalk.withContext(function($ctx2) {
  1317. return _st(self["@analyzer"])._visit_(ast);
  1318. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$InvalidAssignmentError());
  1319. return self}, function($ctx1) {$ctx1.fill(self,"testAssignment",{src:src,ast:ast},globals.SemanticAnalyzerTest)})},
  1320. args: [],
  1321. 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",
  1322. messageSends: ["parse:", "should:raise:", "visit:"],
  1323. referencedClasses: ["Smalltalk", "InvalidAssignmentError"]
  1324. }),
  1325. globals.SemanticAnalyzerTest);
  1326. smalltalk.addMethod(
  1327. smalltalk.method({
  1328. selector: "testNonLocalReturn",
  1329. protocol: 'tests',
  1330. fn: function (){
  1331. var self=this;
  1332. var src,ast;
  1333. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1334. return smalltalk.withContext(function($ctx1) {
  1335. src="foo | a | a + 1. ^ a";
  1336. ast=_st($Smalltalk())._parse_(src);
  1337. _st(self["@analyzer"])._visit_(ast);
  1338. self._deny_(_st(_st(ast)._scope())._hasNonLocalReturn());
  1339. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn",{src:src,ast:ast},globals.SemanticAnalyzerTest)})},
  1340. args: [],
  1341. 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",
  1342. messageSends: ["parse:", "visit:", "deny:", "hasNonLocalReturn", "scope"],
  1343. referencedClasses: ["Smalltalk"]
  1344. }),
  1345. globals.SemanticAnalyzerTest);
  1346. smalltalk.addMethod(
  1347. smalltalk.method({
  1348. selector: "testNonLocalReturn2",
  1349. protocol: 'tests',
  1350. fn: function (){
  1351. var self=this;
  1352. var src,ast;
  1353. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1354. return smalltalk.withContext(function($ctx1) {
  1355. src="foo | a | a + 1. [ [ ^ a] ]";
  1356. ast=_st($Smalltalk())._parse_(src);
  1357. _st(self["@analyzer"])._visit_(ast);
  1358. self._assert_(_st(_st(ast)._scope())._hasNonLocalReturn());
  1359. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn2",{src:src,ast:ast},globals.SemanticAnalyzerTest)})},
  1360. args: [],
  1361. 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",
  1362. messageSends: ["parse:", "visit:", "assert:", "hasNonLocalReturn", "scope"],
  1363. referencedClasses: ["Smalltalk"]
  1364. }),
  1365. globals.SemanticAnalyzerTest);
  1366. smalltalk.addMethod(
  1367. smalltalk.method({
  1368. selector: "testScope",
  1369. protocol: 'tests',
  1370. fn: function (){
  1371. var self=this;
  1372. var src,ast;
  1373. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1374. return smalltalk.withContext(function($ctx1) {
  1375. var $4,$3,$2,$1;
  1376. src="foo | a | a + 1. [ | b | b := a ]";
  1377. ast=_st($Smalltalk())._parse_(src);
  1378. _st(self["@analyzer"])._visit_(ast);
  1379. $4=_st(_st(_st(ast)._nodes())._first())._nodes();
  1380. $ctx1.sendIdx["nodes"]=1;
  1381. $3=_st($4)._last();
  1382. $2=_st($3)._scope();
  1383. $ctx1.sendIdx["scope"]=1;
  1384. $1=_st($2).__eq_eq(_st(ast)._scope());
  1385. self._deny_($1);
  1386. return self}, function($ctx1) {$ctx1.fill(self,"testScope",{src:src,ast:ast},globals.SemanticAnalyzerTest)})},
  1387. args: [],
  1388. 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.",
  1389. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "last", "nodes", "first"],
  1390. referencedClasses: ["Smalltalk"]
  1391. }),
  1392. globals.SemanticAnalyzerTest);
  1393. smalltalk.addMethod(
  1394. smalltalk.method({
  1395. selector: "testScope2",
  1396. protocol: 'tests',
  1397. fn: function (){
  1398. var self=this;
  1399. var src,ast;
  1400. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1401. return smalltalk.withContext(function($ctx1) {
  1402. var $8,$7,$6,$5,$4,$3,$2,$1;
  1403. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1404. ast=_st($Smalltalk())._parse_(src);
  1405. _st(self["@analyzer"])._visit_(ast);
  1406. $8=_st(_st(_st(ast)._nodes())._first())._nodes();
  1407. $ctx1.sendIdx["nodes"]=3;
  1408. $7=_st($8)._last();
  1409. $6=_st($7)._nodes();
  1410. $ctx1.sendIdx["nodes"]=2;
  1411. $5=_st($6)._first();
  1412. $ctx1.sendIdx["first"]=2;
  1413. $4=_st($5)._nodes();
  1414. $ctx1.sendIdx["nodes"]=1;
  1415. $3=_st($4)._first();
  1416. $ctx1.sendIdx["first"]=1;
  1417. $2=_st($3)._scope();
  1418. $ctx1.sendIdx["scope"]=1;
  1419. $1=_st($2).__eq_eq(_st(ast)._scope());
  1420. self._deny_($1);
  1421. return self}, function($ctx1) {$ctx1.fill(self,"testScope2",{src:src,ast:ast},globals.SemanticAnalyzerTest)})},
  1422. args: [],
  1423. 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.",
  1424. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "first", "nodes", "last"],
  1425. referencedClasses: ["Smalltalk"]
  1426. }),
  1427. globals.SemanticAnalyzerTest);
  1428. smalltalk.addMethod(
  1429. smalltalk.method({
  1430. selector: "testScopeLevel",
  1431. protocol: 'tests',
  1432. fn: function (){
  1433. var self=this;
  1434. var src,ast;
  1435. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1436. return smalltalk.withContext(function($ctx1) {
  1437. var $2,$1,$10,$9,$8,$7,$6,$5,$4,$3;
  1438. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1439. ast=_st($Smalltalk())._parse_(src);
  1440. _st(self["@analyzer"])._visit_(ast);
  1441. $2=_st(ast)._scope();
  1442. $ctx1.sendIdx["scope"]=1;
  1443. $1=_st($2)._scopeLevel();
  1444. $ctx1.sendIdx["scopeLevel"]=1;
  1445. self._assert_equals_($1,(1));
  1446. $ctx1.sendIdx["assert:equals:"]=1;
  1447. $10=_st(_st(_st(ast)._nodes())._first())._nodes();
  1448. $ctx1.sendIdx["nodes"]=3;
  1449. $9=_st($10)._last();
  1450. $8=_st($9)._nodes();
  1451. $ctx1.sendIdx["nodes"]=2;
  1452. $7=_st($8)._first();
  1453. $ctx1.sendIdx["first"]=2;
  1454. $6=_st($7)._nodes();
  1455. $ctx1.sendIdx["nodes"]=1;
  1456. $5=_st($6)._first();
  1457. $ctx1.sendIdx["first"]=1;
  1458. $4=_st($5)._scope();
  1459. $3=_st($4)._scopeLevel();
  1460. self._assert_equals_($3,(3));
  1461. return self}, function($ctx1) {$ctx1.fill(self,"testScopeLevel",{src:src,ast:ast},globals.SemanticAnalyzerTest)})},
  1462. args: [],
  1463. 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",
  1464. messageSends: ["parse:", "visit:", "assert:equals:", "scopeLevel", "scope", "first", "nodes", "last"],
  1465. referencedClasses: ["Smalltalk"]
  1466. }),
  1467. globals.SemanticAnalyzerTest);
  1468. smalltalk.addMethod(
  1469. smalltalk.method({
  1470. selector: "testUnknownVariables",
  1471. protocol: 'tests',
  1472. fn: function (){
  1473. var self=this;
  1474. var src,ast;
  1475. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1476. function $UnknownVariableError(){return globals.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1477. return smalltalk.withContext(function($ctx1) {
  1478. src="foo | a | b + a";
  1479. ast=_st($Smalltalk())._parse_(src);
  1480. self._should_raise_((function(){
  1481. return smalltalk.withContext(function($ctx2) {
  1482. return _st(self["@analyzer"])._visit_(ast);
  1483. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$UnknownVariableError());
  1484. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariables",{src:src,ast:ast},globals.SemanticAnalyzerTest)})},
  1485. args: [],
  1486. 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",
  1487. messageSends: ["parse:", "should:raise:", "visit:"],
  1488. referencedClasses: ["Smalltalk", "UnknownVariableError"]
  1489. }),
  1490. globals.SemanticAnalyzerTest);
  1491. smalltalk.addMethod(
  1492. smalltalk.method({
  1493. selector: "testUnknownVariablesWithScope",
  1494. protocol: 'tests',
  1495. fn: function (){
  1496. var self=this;
  1497. var src,ast;
  1498. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1499. function $UnknownVariableError(){return globals.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1500. return smalltalk.withContext(function($ctx1) {
  1501. src="foo | a b | [ c + 1. [ a + 1. d + 1 ]]";
  1502. ast=_st($Smalltalk())._parse_(src);
  1503. self._should_raise_((function(){
  1504. return smalltalk.withContext(function($ctx2) {
  1505. return _st(self["@analyzer"])._visit_(ast);
  1506. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$UnknownVariableError());
  1507. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariablesWithScope",{src:src,ast:ast},globals.SemanticAnalyzerTest)})},
  1508. args: [],
  1509. 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",
  1510. messageSends: ["parse:", "should:raise:", "visit:"],
  1511. referencedClasses: ["Smalltalk", "UnknownVariableError"]
  1512. }),
  1513. globals.SemanticAnalyzerTest);
  1514. smalltalk.addMethod(
  1515. smalltalk.method({
  1516. selector: "testVariableShadowing",
  1517. protocol: 'tests',
  1518. fn: function (){
  1519. var self=this;
  1520. var src,ast;
  1521. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1522. return smalltalk.withContext(function($ctx1) {
  1523. src="foo | a | a + 1";
  1524. ast=_st($Smalltalk())._parse_(src);
  1525. _st(self["@analyzer"])._visit_(ast);
  1526. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing",{src:src,ast:ast},globals.SemanticAnalyzerTest)})},
  1527. args: [],
  1528. source: "testVariableShadowing\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1'.\x0a\x09ast := Smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1529. messageSends: ["parse:", "visit:"],
  1530. referencedClasses: ["Smalltalk"]
  1531. }),
  1532. globals.SemanticAnalyzerTest);
  1533. smalltalk.addMethod(
  1534. smalltalk.method({
  1535. selector: "testVariableShadowing2",
  1536. protocol: 'tests',
  1537. fn: function (){
  1538. var self=this;
  1539. var src,ast;
  1540. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1541. function $ShadowingVariableError(){return globals.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1542. return smalltalk.withContext(function($ctx1) {
  1543. src="foo | a | a + 1. [ | a | a := 2 ]";
  1544. ast=_st($Smalltalk())._parse_(src);
  1545. self._should_raise_((function(){
  1546. return smalltalk.withContext(function($ctx2) {
  1547. return _st(self["@analyzer"])._visit_(ast);
  1548. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$ShadowingVariableError());
  1549. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing2",{src:src,ast:ast},globals.SemanticAnalyzerTest)})},
  1550. args: [],
  1551. 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",
  1552. messageSends: ["parse:", "should:raise:", "visit:"],
  1553. referencedClasses: ["Smalltalk", "ShadowingVariableError"]
  1554. }),
  1555. globals.SemanticAnalyzerTest);
  1556. smalltalk.addMethod(
  1557. smalltalk.method({
  1558. selector: "testVariableShadowing3",
  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. src="foo | a | a + 1. [ | b | b := 2 ]";
  1566. ast=_st($Smalltalk())._parse_(src);
  1567. _st(self["@analyzer"])._visit_(ast);
  1568. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing3",{src:src,ast:ast},globals.SemanticAnalyzerTest)})},
  1569. args: [],
  1570. source: "testVariableShadowing3\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | b | b := 2 ]'.\x0a\x09ast := Smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1571. messageSends: ["parse:", "visit:"],
  1572. referencedClasses: ["Smalltalk"]
  1573. }),
  1574. globals.SemanticAnalyzerTest);
  1575. smalltalk.addMethod(
  1576. smalltalk.method({
  1577. selector: "testVariableShadowing4",
  1578. protocol: 'tests',
  1579. fn: function (){
  1580. var self=this;
  1581. var src,ast;
  1582. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1583. return smalltalk.withContext(function($ctx1) {
  1584. src="foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]";
  1585. ast=_st($Smalltalk())._parse_(src);
  1586. _st(self["@analyzer"])._visit_(ast);
  1587. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing4",{src:src,ast:ast},globals.SemanticAnalyzerTest)})},
  1588. args: [],
  1589. source: "testVariableShadowing4\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.\x0a\x09ast := Smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1590. messageSends: ["parse:", "visit:"],
  1591. referencedClasses: ["Smalltalk"]
  1592. }),
  1593. globals.SemanticAnalyzerTest);
  1594. smalltalk.addMethod(
  1595. smalltalk.method({
  1596. selector: "testVariableShadowing5",
  1597. protocol: 'tests',
  1598. fn: function (){
  1599. var self=this;
  1600. var src,ast;
  1601. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1602. function $ShadowingVariableError(){return globals.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1603. return smalltalk.withContext(function($ctx1) {
  1604. src="foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]";
  1605. ast=_st($Smalltalk())._parse_(src);
  1606. self._should_raise_((function(){
  1607. return smalltalk.withContext(function($ctx2) {
  1608. return _st(self["@analyzer"])._visit_(ast);
  1609. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$ShadowingVariableError());
  1610. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing5",{src:src,ast:ast},globals.SemanticAnalyzerTest)})},
  1611. args: [],
  1612. 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",
  1613. messageSends: ["parse:", "should:raise:", "visit:"],
  1614. referencedClasses: ["Smalltalk", "ShadowingVariableError"]
  1615. }),
  1616. globals.SemanticAnalyzerTest);
  1617. smalltalk.addMethod(
  1618. smalltalk.method({
  1619. selector: "testVariablesLookup",
  1620. protocol: 'tests',
  1621. fn: function (){
  1622. var self=this;
  1623. var src,ast;
  1624. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1625. return smalltalk.withContext(function($ctx1) {
  1626. 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;
  1627. src="foo | a | a + 1. [ | b | b := a ]";
  1628. ast=_st($Smalltalk())._parse_(src);
  1629. _st(self["@analyzer"])._visit_(ast);
  1630. $7=_st(ast)._nodes();
  1631. $ctx1.sendIdx["nodes"]=2;
  1632. $6=_st($7)._first();
  1633. $ctx1.sendIdx["first"]=2;
  1634. $5=_st($6)._nodes();
  1635. $ctx1.sendIdx["nodes"]=1;
  1636. $4=_st($5)._first();
  1637. $ctx1.sendIdx["first"]=1;
  1638. $3=_st($4)._receiver();
  1639. $ctx1.sendIdx["receiver"]=1;
  1640. $2=_st($3)._binding();
  1641. $ctx1.sendIdx["binding"]=1;
  1642. $1=_st($2)._isTempVar();
  1643. $ctx1.sendIdx["isTempVar"]=1;
  1644. self._assert_($1);
  1645. $ctx1.sendIdx["assert:"]=1;
  1646. $15=_st(ast)._nodes();
  1647. $ctx1.sendIdx["nodes"]=4;
  1648. $14=_st($15)._first();
  1649. $ctx1.sendIdx["first"]=4;
  1650. $13=_st($14)._nodes();
  1651. $ctx1.sendIdx["nodes"]=3;
  1652. $12=_st($13)._first();
  1653. $ctx1.sendIdx["first"]=3;
  1654. $11=_st($12)._receiver();
  1655. $10=_st($11)._binding();
  1656. $ctx1.sendIdx["binding"]=2;
  1657. $9=_st($10)._scope();
  1658. $ctx1.sendIdx["scope"]=1;
  1659. $16=_st(ast)._scope();
  1660. $ctx1.sendIdx["scope"]=2;
  1661. $8=_st($9).__eq_eq($16);
  1662. $ctx1.sendIdx["=="]=1;
  1663. self._assert_($8);
  1664. $ctx1.sendIdx["assert:"]=2;
  1665. $27=_st(ast)._nodes();
  1666. $ctx1.sendIdx["nodes"]=8;
  1667. $26=_st($27)._first();
  1668. $ctx1.sendIdx["first"]=7;
  1669. $25=_st($26)._nodes();
  1670. $ctx1.sendIdx["nodes"]=7;
  1671. $24=_st($25)._last();
  1672. $ctx1.sendIdx["last"]=1;
  1673. $23=_st($24)._nodes();
  1674. $ctx1.sendIdx["nodes"]=6;
  1675. $22=_st($23)._first();
  1676. $ctx1.sendIdx["first"]=6;
  1677. $21=_st($22)._nodes();
  1678. $ctx1.sendIdx["nodes"]=5;
  1679. $20=_st($21)._first();
  1680. $ctx1.sendIdx["first"]=5;
  1681. $19=_st($20)._left();
  1682. $ctx1.sendIdx["left"]=1;
  1683. $18=_st($19)._binding();
  1684. $ctx1.sendIdx["binding"]=3;
  1685. $17=_st($18)._isTempVar();
  1686. self._assert_($17);
  1687. $ctx1.sendIdx["assert:"]=3;
  1688. $39=_st(ast)._nodes();
  1689. $ctx1.sendIdx["nodes"]=12;
  1690. $38=_st($39)._first();
  1691. $ctx1.sendIdx["first"]=10;
  1692. $37=_st($38)._nodes();
  1693. $ctx1.sendIdx["nodes"]=11;
  1694. $36=_st($37)._last();
  1695. $ctx1.sendIdx["last"]=2;
  1696. $35=_st($36)._nodes();
  1697. $ctx1.sendIdx["nodes"]=10;
  1698. $34=_st($35)._first();
  1699. $ctx1.sendIdx["first"]=9;
  1700. $33=_st($34)._nodes();
  1701. $ctx1.sendIdx["nodes"]=9;
  1702. $32=_st($33)._first();
  1703. $ctx1.sendIdx["first"]=8;
  1704. $31=_st($32)._left();
  1705. $30=_st($31)._binding();
  1706. $29=_st($30)._scope();
  1707. $ctx1.sendIdx["scope"]=3;
  1708. $42=_st(_st(_st(ast)._nodes())._first())._nodes();
  1709. $ctx1.sendIdx["nodes"]=13;
  1710. $41=_st($42)._last();
  1711. $40=_st($41)._scope();
  1712. $28=_st($29).__eq_eq($40);
  1713. self._assert_($28);
  1714. return self}, function($ctx1) {$ctx1.fill(self,"testVariablesLookup",{src:src,ast:ast},globals.SemanticAnalyzerTest)})},
  1715. args: [],
  1716. 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.",
  1717. messageSends: ["parse:", "visit:", "assert:", "isTempVar", "binding", "receiver", "first", "nodes", "==", "scope", "left", "last"],
  1718. referencedClasses: ["Smalltalk"]
  1719. }),
  1720. globals.SemanticAnalyzerTest);
  1721. });