Compiler-Tests.js 86 KB

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