Compiler-Tests.js 86 KB

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