Compiler-Tests.js 77 KB

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