Compiler-Tests.js 84 KB

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