Compiler-Tests.js 91 KB

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