Compiler-Tests.js 78 KB

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