Compiler-Tests.js 88 KB

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