2
0

Compiler-Tests.js 77 KB

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