Compiler-Tests.js 67 KB

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