Compiler-Tests.js 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001
  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: 'interpreting',
  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: "testMultipleSequences",
  804. category: 'tests',
  805. fn: function (){
  806. var self=this;
  807. return smalltalk.withContext(function($ctx1) {
  808. self._assert_equals_(self._interpret_("foo | a b c | a := 2. b := 3. c := a + b. ^ c * 6"),(30));
  809. return self}, function($ctx1) {$ctx1.fill(self,"testMultipleSequences",{},smalltalk.InterpreterTest)})},
  810. args: [],
  811. source: "testMultipleSequences\x0a\x09self assert: (self interpret: 'foo | a b c | a := 2. b := 3. c := a + b. ^ c * 6') equals: 30",
  812. messageSends: ["assert:equals:", "interpret:"],
  813. referencedClasses: []
  814. }),
  815. smalltalk.InterpreterTest);
  816. smalltalk.addMethod(
  817. smalltalk.method({
  818. selector: "testNestedSends",
  819. category: 'tests',
  820. fn: function (){
  821. var self=this;
  822. function $Point(){return smalltalk.Point||(typeof Point=="undefined"?nil:Point)}
  823. return smalltalk.withContext(function($ctx1) {
  824. self._assert_equals_(self._interpret_("foo ^ (Point x: (Point x: 2 y: 3) y: 4) asString"),_st(_st($Point())._x_y_((2).__at((3)),(4)))._asString());
  825. return self}, function($ctx1) {$ctx1.fill(self,"testNestedSends",{},smalltalk.InterpreterTest)})},
  826. args: [],
  827. source: "testNestedSends\x0a\x09self assert: (self interpret: 'foo ^ (Point x: (Point x: 2 y: 3) y: 4) asString') equals: (Point x: (2@3) y: 4) asString",
  828. messageSends: ["assert:equals:", "interpret:", "asString", "x:y:", "@"],
  829. referencedClasses: ["Point"]
  830. }),
  831. smalltalk.InterpreterTest);
  832. smalltalk.addMethod(
  833. smalltalk.method({
  834. selector: "testNonlocalReturn",
  835. category: 'tests',
  836. fn: function (){
  837. var self=this;
  838. return smalltalk.withContext(function($ctx1) {
  839. self._assert_equals_(self._interpret_("foo true ifTrue: [ ^ 1 ]. ^2"),(1));
  840. return self}, function($ctx1) {$ctx1.fill(self,"testNonlocalReturn",{},smalltalk.InterpreterTest)})},
  841. args: [],
  842. source: "testNonlocalReturn\x0a\x09self assert: (self interpret: 'foo true ifTrue: [ ^ 1 ]. ^2') equals: 1",
  843. messageSends: ["assert:equals:", "interpret:"],
  844. referencedClasses: []
  845. }),
  846. smalltalk.InterpreterTest);
  847. smalltalk.addMethod(
  848. smalltalk.method({
  849. selector: "testReceiver",
  850. category: 'tests',
  851. fn: function (){
  852. var self=this;
  853. return smalltalk.withContext(function($ctx1) {
  854. self._assert_equals_(self._interpret_receiver_withArguments_("foo ^ self",(2).__at((3)),smalltalk.HashedCollection._fromPairs_([])),(2).__at((3)));
  855. return self}, function($ctx1) {$ctx1.fill(self,"testReceiver",{},smalltalk.InterpreterTest)})},
  856. args: [],
  857. 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",
  858. messageSends: ["assert:equals:", "interpret:receiver:withArguments:", "@"],
  859. referencedClasses: []
  860. }),
  861. smalltalk.InterpreterTest);
  862. smalltalk.addMethod(
  863. smalltalk.method({
  864. selector: "testSuper",
  865. category: 'tests',
  866. fn: function (){
  867. var self=this;
  868. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  869. return smalltalk.withContext(function($ctx1) {
  870. self._assert_equals_(self._interpret_receiver_withArguments_("foo ^ super isBoolean",true,_st($Dictionary())._new()),false);
  871. return self}, function($ctx1) {$ctx1.fill(self,"testSuper",{},smalltalk.InterpreterTest)})},
  872. args: [],
  873. 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",
  874. messageSends: ["assert:equals:", "interpret:receiver:withArguments:", "new"],
  875. referencedClasses: ["Dictionary"]
  876. }),
  877. smalltalk.InterpreterTest);
  878. smalltalk.addMethod(
  879. smalltalk.method({
  880. selector: "testTempAssignment",
  881. category: 'tests',
  882. fn: function (){
  883. var self=this;
  884. return smalltalk.withContext(function($ctx1) {
  885. self._assert_equals_(self._interpret_("foo | a | a := 2. ^ a"),(2));
  886. return self}, function($ctx1) {$ctx1.fill(self,"testTempAssignment",{},smalltalk.InterpreterTest)})},
  887. args: [],
  888. source: "testTempAssignment\x0a\x09self assert: (self interpret: 'foo | a | a := 2. ^ a') equals: 2",
  889. messageSends: ["assert:equals:", "interpret:"],
  890. referencedClasses: []
  891. }),
  892. smalltalk.InterpreterTest);
  893. smalltalk.addMethod(
  894. smalltalk.method({
  895. selector: "testThisContext",
  896. category: 'tests',
  897. fn: function (){
  898. var self=this;
  899. return smalltalk.withContext(function($ctx1) {
  900. self._assert_(_st(_st(self._interpret_("foo ^ thisContext"))._outerContext())._isNil());
  901. self._assert_(_st(_st(self._interpret_("foo ^ [ thisContext ] value"))._outerContext())._notNil());
  902. self._assert_(self._interpret_("foo ^ [ thisContext ] value outerContext == thisContext"));
  903. return self}, function($ctx1) {$ctx1.fill(self,"testThisContext",{},smalltalk.InterpreterTest)})},
  904. args: [],
  905. 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')",
  906. messageSends: ["assert:", "isNil", "outerContext", "interpret:", "notNil"],
  907. referencedClasses: []
  908. }),
  909. smalltalk.InterpreterTest);
  910. smalltalk.addMethod(
  911. smalltalk.method({
  912. selector: "testUnarySend",
  913. category: 'tests',
  914. fn: function (){
  915. var self=this;
  916. return smalltalk.withContext(function($ctx1) {
  917. self._assert_equals_(self._interpret_("foo ^ 1 asString"),"1");
  918. return self}, function($ctx1) {$ctx1.fill(self,"testUnarySend",{},smalltalk.InterpreterTest)})},
  919. args: [],
  920. source: "testUnarySend\x0a\x09self assert: (self interpret: 'foo ^ 1 asString') equals: '1'",
  921. messageSends: ["assert:equals:", "interpret:"],
  922. referencedClasses: []
  923. }),
  924. smalltalk.InterpreterTest);
  925. smalltalk.addClass('CodeGeneratorTest', smalltalk.TestCase, ['receiver'], 'Compiler-Tests');
  926. smalltalk.addMethod(
  927. smalltalk.method({
  928. selector: "codeGeneratorClass",
  929. category: 'accessing',
  930. fn: function (){
  931. var self=this;
  932. function $CodeGenerator(){return smalltalk.CodeGenerator||(typeof CodeGenerator=="undefined"?nil:CodeGenerator)}
  933. return smalltalk.withContext(function($ctx1) {
  934. var $1;
  935. $1=$CodeGenerator();
  936. return $1;
  937. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{},smalltalk.CodeGeneratorTest)})},
  938. args: [],
  939. source: "codeGeneratorClass\x0a\x09^ CodeGenerator",
  940. messageSends: [],
  941. referencedClasses: ["CodeGenerator"]
  942. }),
  943. smalltalk.CodeGeneratorTest);
  944. smalltalk.addMethod(
  945. smalltalk.method({
  946. selector: "compiler",
  947. category: 'factory',
  948. fn: function (){
  949. var self=this;
  950. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  951. return smalltalk.withContext(function($ctx1) {
  952. var $2,$3,$1;
  953. $2=_st($Compiler())._new();
  954. _st($2)._codeGeneratorClass_(self._codeGeneratorClass());
  955. $3=_st($2)._yourself();
  956. $1=$3;
  957. return $1;
  958. }, function($ctx1) {$ctx1.fill(self,"compiler",{},smalltalk.CodeGeneratorTest)})},
  959. args: [],
  960. source: "compiler\x0a\x09^ Compiler new\x0a\x09\x09codeGeneratorClass: self codeGeneratorClass;\x0a\x09\x09yourself",
  961. messageSends: ["codeGeneratorClass:", "codeGeneratorClass", "new", "yourself"],
  962. referencedClasses: ["Compiler"]
  963. }),
  964. smalltalk.CodeGeneratorTest);
  965. smalltalk.addMethod(
  966. smalltalk.method({
  967. selector: "setUp",
  968. category: 'initialization',
  969. fn: function (){
  970. var self=this;
  971. return smalltalk.withContext(function($ctx1) {
  972. self["@receiver"]=_st(self._targetClass())._new();
  973. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},smalltalk.CodeGeneratorTest)})},
  974. args: [],
  975. source: "setUp\x0a\x09receiver := self targetClass new",
  976. messageSends: ["new", "targetClass"],
  977. referencedClasses: []
  978. }),
  979. smalltalk.CodeGeneratorTest);
  980. smalltalk.addMethod(
  981. smalltalk.method({
  982. selector: "should:return:",
  983. category: 'testing',
  984. fn: function (aString,anObject){
  985. var self=this;
  986. var method,result;
  987. return smalltalk.withContext(function($ctx1) {
  988. method=_st(self._compiler())._install_forClass_category_(aString,self._targetClass(),"tests");
  989. result=_st(self["@receiver"])._perform_(_st(method)._selector());
  990. _st(self._targetClass())._removeCompiledMethod_(method);
  991. self._assert_equals_(anObject,result);
  992. return self}, function($ctx1) {$ctx1.fill(self,"should:return:",{aString:aString,anObject:anObject,method:method,result:result},smalltalk.CodeGeneratorTest)})},
  993. args: ["aString", "anObject"],
  994. 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",
  995. messageSends: ["install:forClass:category:", "targetClass", "compiler", "perform:", "selector", "removeCompiledMethod:", "assert:equals:"],
  996. referencedClasses: []
  997. }),
  998. smalltalk.CodeGeneratorTest);
  999. smalltalk.addMethod(
  1000. smalltalk.method({
  1001. selector: "targetClass",
  1002. category: 'accessing',
  1003. fn: function (){
  1004. var self=this;
  1005. function $DoIt(){return smalltalk.DoIt||(typeof DoIt=="undefined"?nil:DoIt)}
  1006. return smalltalk.withContext(function($ctx1) {
  1007. var $1;
  1008. $1=$DoIt();
  1009. return $1;
  1010. }, function($ctx1) {$ctx1.fill(self,"targetClass",{},smalltalk.CodeGeneratorTest)})},
  1011. args: [],
  1012. source: "targetClass\x0a\x09^ DoIt",
  1013. messageSends: [],
  1014. referencedClasses: ["DoIt"]
  1015. }),
  1016. smalltalk.CodeGeneratorTest);
  1017. smalltalk.addMethod(
  1018. smalltalk.method({
  1019. selector: "tearDown",
  1020. category: 'initialization',
  1021. fn: function (){
  1022. var self=this;
  1023. return smalltalk.withContext(function($ctx1) {
  1024. return self}, function($ctx1) {$ctx1.fill(self,"tearDown",{},smalltalk.CodeGeneratorTest)})},
  1025. args: [],
  1026. source: "tearDown\x0a\x09\x22receiver := nil\x22",
  1027. messageSends: [],
  1028. referencedClasses: []
  1029. }),
  1030. smalltalk.CodeGeneratorTest);
  1031. smalltalk.addMethod(
  1032. smalltalk.method({
  1033. selector: "testAssignment",
  1034. category: 'tests',
  1035. fn: function (){
  1036. var self=this;
  1037. return smalltalk.withContext(function($ctx1) {
  1038. self._should_return_("foo | a | a := true ifTrue: [ 1 ]. ^ a",(1));
  1039. self._should_return_("foo | a | a := false ifTrue: [ 1 ]. ^ a",nil);
  1040. self._should_return_("foo | a | ^ a := true ifTrue: [ 1 ]",(1));
  1041. return self}, function($ctx1) {$ctx1.fill(self,"testAssignment",{},smalltalk.CodeGeneratorTest)})},
  1042. args: [],
  1043. 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",
  1044. messageSends: ["should:return:"],
  1045. referencedClasses: []
  1046. }),
  1047. smalltalk.CodeGeneratorTest);
  1048. smalltalk.addMethod(
  1049. smalltalk.method({
  1050. selector: "testBackslashSelectors",
  1051. category: 'tests',
  1052. fn: function (){
  1053. var self=this;
  1054. return smalltalk.withContext(function($ctx1) {
  1055. self._should_return_("\x5c arg ^ 4",(4));
  1056. self._should_return_("\x5c\x5c arg ^ 42",(42));
  1057. return self}, function($ctx1) {$ctx1.fill(self,"testBackslashSelectors",{},smalltalk.CodeGeneratorTest)})},
  1058. args: [],
  1059. source: "testBackslashSelectors\x0a\x09\x0a\x09self should: '\x5c arg ^ 4' return: 4.\x0a\x09self should: '\x5c\x5c arg ^ 42' return: 42",
  1060. messageSends: ["should:return:"],
  1061. referencedClasses: []
  1062. }),
  1063. smalltalk.CodeGeneratorTest);
  1064. smalltalk.addMethod(
  1065. smalltalk.method({
  1066. selector: "testBlockReturn",
  1067. category: 'tests',
  1068. fn: function (){
  1069. var self=this;
  1070. return smalltalk.withContext(function($ctx1) {
  1071. self._should_return_("foo ^ #(1 2 3) collect: [ :each | true ifTrue: [ each + 1 ] ]",[(2), (3), (4)]);
  1072. self._should_return_("foo ^ #(1 2 3) collect: [ :each | false ifFalse: [ each + 1 ] ]",[(2), (3), (4)]);
  1073. self._should_return_("foo ^ #(1 2 3) collect: [ :each | each odd ifTrue: [ each + 1 ] ifFalse: [ each - 1 ] ]",[(2), (1), (4)]);
  1074. return self}, function($ctx1) {$ctx1.fill(self,"testBlockReturn",{},smalltalk.CodeGeneratorTest)})},
  1075. args: [],
  1076. 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).",
  1077. messageSends: ["should:return:"],
  1078. referencedClasses: []
  1079. }),
  1080. smalltalk.CodeGeneratorTest);
  1081. smalltalk.addMethod(
  1082. smalltalk.method({
  1083. selector: "testCascades",
  1084. category: 'tests',
  1085. fn: function (){
  1086. var self=this;
  1087. return smalltalk.withContext(function($ctx1) {
  1088. self._should_return_("foo ^ Array new add: 3; add: 4; yourself",[(3), (4)]);
  1089. return self}, function($ctx1) {$ctx1.fill(self,"testCascades",{},smalltalk.CodeGeneratorTest)})},
  1090. args: [],
  1091. source: "testCascades\x0a\x09\x0a\x09self should: 'foo ^ Array new add: 3; add: 4; yourself' return: #(3 4)",
  1092. messageSends: ["should:return:"],
  1093. referencedClasses: []
  1094. }),
  1095. smalltalk.CodeGeneratorTest);
  1096. smalltalk.addMethod(
  1097. smalltalk.method({
  1098. selector: "testDynamicArrayElementsOrdered",
  1099. category: 'tests',
  1100. fn: function (){
  1101. var self=this;
  1102. return smalltalk.withContext(function($ctx1) {
  1103. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { x. true ifTrue: [ x := 2 ] }\x0a",[(1), (2)]);
  1104. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicArrayElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  1105. args: [],
  1106. source: "testDynamicArrayElementsOrdered\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { x. true ifTrue: [ x := 2 ] }\x0a' return: #(1 2).",
  1107. messageSends: ["should:return:"],
  1108. referencedClasses: []
  1109. }),
  1110. smalltalk.CodeGeneratorTest);
  1111. smalltalk.addMethod(
  1112. smalltalk.method({
  1113. selector: "testDynamicDictionaryElementsOrdered",
  1114. category: 'tests',
  1115. fn: function (){
  1116. var self=this;
  1117. return smalltalk.withContext(function($ctx1) {
  1118. 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))]));
  1119. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicDictionaryElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  1120. args: [],
  1121. 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}.",
  1122. messageSends: ["should:return:", "->"],
  1123. referencedClasses: []
  1124. }),
  1125. smalltalk.CodeGeneratorTest);
  1126. smalltalk.addMethod(
  1127. smalltalk.method({
  1128. selector: "testInnerTemporalDependentElementsOrdered",
  1129. category: 'tests',
  1130. fn: function (){
  1131. var self=this;
  1132. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  1133. return smalltalk.withContext(function($ctx1) {
  1134. 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))]);
  1135. 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))]);
  1136. 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))]);
  1137. 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))]));
  1138. return self}, function($ctx1) {$ctx1.fill(self,"testInnerTemporalDependentElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  1139. args: [],
  1140. 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}.",
  1141. messageSends: ["should:return:", "->"],
  1142. referencedClasses: ["Array"]
  1143. }),
  1144. smalltalk.CodeGeneratorTest);
  1145. smalltalk.addMethod(
  1146. smalltalk.method({
  1147. selector: "testLiterals",
  1148. category: 'tests',
  1149. fn: function (){
  1150. var self=this;
  1151. return smalltalk.withContext(function($ctx1) {
  1152. self._should_return_("foo ^ 1",(1));
  1153. self._should_return_("foo ^ 'hello'","hello");
  1154. self._should_return_("foo ^ #(1 2 3 4)",[(1), (2), (3), (4)]);
  1155. self._should_return_("foo ^ {1. [:x | x ] value: 2. 3. [4] value}",[(1), (2), (3), (4)]);
  1156. self._should_return_("foo ^ true",true);
  1157. self._should_return_("foo ^ false",false);
  1158. self._should_return_("foo ^ #{1->2. 3->4}",smalltalk.HashedCollection._fromPairs_([(1).__minus_gt((2)),(3).__minus_gt((4))]));
  1159. self._should_return_("foo ^ #hello","hello");
  1160. self._should_return_("foo ^ -123.456",(-123.456));
  1161. return self}, function($ctx1) {$ctx1.fill(self,"testLiterals",{},smalltalk.CodeGeneratorTest)})},
  1162. args: [],
  1163. 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",
  1164. messageSends: ["should:return:", "->"],
  1165. referencedClasses: []
  1166. }),
  1167. smalltalk.CodeGeneratorTest);
  1168. smalltalk.addMethod(
  1169. smalltalk.method({
  1170. selector: "testLocalReturn",
  1171. category: 'tests',
  1172. fn: function (){
  1173. var self=this;
  1174. return smalltalk.withContext(function($ctx1) {
  1175. self._should_return_("foo ^ 1",(1));
  1176. self._should_return_("foo ^ 1 + 1",(2));
  1177. self._should_return_("foo ",self["@receiver"]);
  1178. self._should_return_("foo self asString",self["@receiver"]);
  1179. self._should_return_("foo | a b | a := 1. b := 2. ^ a + b",(3));
  1180. return self}, function($ctx1) {$ctx1.fill(self,"testLocalReturn",{},smalltalk.CodeGeneratorTest)})},
  1181. args: [],
  1182. 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",
  1183. messageSends: ["should:return:"],
  1184. referencedClasses: []
  1185. }),
  1186. smalltalk.CodeGeneratorTest);
  1187. smalltalk.addMethod(
  1188. smalltalk.method({
  1189. selector: "testMessageSends",
  1190. category: 'tests',
  1191. fn: function (){
  1192. var self=this;
  1193. return smalltalk.withContext(function($ctx1) {
  1194. self._should_return_("foo ^ 1 asString","1");
  1195. self._should_return_("foo ^ 1 + 1",(2));
  1196. self._should_return_("foo ^ 1 + 2 * 3",(9));
  1197. self._should_return_("foo ^ 1 to: 3",[(1), (2), (3)]);
  1198. self._should_return_("foo ^ 1 to: 5 by: 2",[(1), (3), (5)]);
  1199. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSends",{},smalltalk.CodeGeneratorTest)})},
  1200. args: [],
  1201. 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)",
  1202. messageSends: ["should:return:"],
  1203. referencedClasses: []
  1204. }),
  1205. smalltalk.CodeGeneratorTest);
  1206. smalltalk.addMethod(
  1207. smalltalk.method({
  1208. selector: "testMutableLiterals",
  1209. category: 'tests',
  1210. fn: function (){
  1211. var self=this;
  1212. return smalltalk.withContext(function($ctx1) {
  1213. self._should_return_("foo ^ #( 1 2 ) at: 1 put: 3; yourself",[(3), (2)]);
  1214. return self}, function($ctx1) {$ctx1.fill(self,"testMutableLiterals",{},smalltalk.CodeGeneratorTest)})},
  1215. args: [],
  1216. 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)",
  1217. messageSends: ["should:return:"],
  1218. referencedClasses: []
  1219. }),
  1220. smalltalk.CodeGeneratorTest);
  1221. smalltalk.addMethod(
  1222. smalltalk.method({
  1223. selector: "testNestedIfTrue",
  1224. category: 'tests',
  1225. fn: function (){
  1226. var self=this;
  1227. return smalltalk.withContext(function($ctx1) {
  1228. self._should_return_("foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]",(1));
  1229. self._should_return_("foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]",nil);
  1230. self._should_return_("foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]",(1));
  1231. self._should_return_("foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]",self["@receiver"]);
  1232. return self}, function($ctx1) {$ctx1.fill(self,"testNestedIfTrue",{},smalltalk.CodeGeneratorTest)})},
  1233. args: [],
  1234. 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.",
  1235. messageSends: ["should:return:"],
  1236. referencedClasses: []
  1237. }),
  1238. smalltalk.CodeGeneratorTest);
  1239. smalltalk.addMethod(
  1240. smalltalk.method({
  1241. selector: "testNonLocalReturn",
  1242. category: 'tests',
  1243. fn: function (){
  1244. var self=this;
  1245. return smalltalk.withContext(function($ctx1) {
  1246. self._should_return_("foo [ ^ 1 ] value",(1));
  1247. self._should_return_("foo [ ^ 1 + 1 ] value",(2));
  1248. self._should_return_("foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt",(3));
  1249. self._should_return_("foo [ :x | ^ x + x ] value: 4. ^ 2",(8));
  1250. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn",{},smalltalk.CodeGeneratorTest)})},
  1251. args: [],
  1252. 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",
  1253. messageSends: ["should:return:"],
  1254. referencedClasses: []
  1255. }),
  1256. smalltalk.CodeGeneratorTest);
  1257. smalltalk.addMethod(
  1258. smalltalk.method({
  1259. selector: "testPascalCaseGlobal",
  1260. category: 'tests',
  1261. fn: function (){
  1262. var self=this;
  1263. return smalltalk.withContext(function($ctx1) {
  1264. self._should_return_("foo ^Object",_st(smalltalk)._at_("Object"));
  1265. self._should_return_("foo ^NonExistent",nil);
  1266. return self}, function($ctx1) {$ctx1.fill(self,"testPascalCaseGlobal",{},smalltalk.CodeGeneratorTest)})},
  1267. args: [],
  1268. source: "testPascalCaseGlobal\x0a\x09self should: 'foo ^Object' return: (smalltalk at: 'Object').\x0a\x09self should: 'foo ^NonExistent' return: nil",
  1269. messageSends: ["should:return:", "at:"],
  1270. referencedClasses: []
  1271. }),
  1272. smalltalk.CodeGeneratorTest);
  1273. smalltalk.addMethod(
  1274. smalltalk.method({
  1275. selector: "testSendReceiverAndArgumentsOrdered",
  1276. category: 'tests',
  1277. fn: function (){
  1278. var self=this;
  1279. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  1280. return smalltalk.withContext(function($ctx1) {
  1281. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ Array with: x with: (true ifTrue: [ x := 2 ])\x0a",[(1), (2)]);
  1282. self._should_return_("foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: x with: (true ifTrue: [ x := 2 ])\x0a",[$Array(),(2)]);
  1283. return self}, function($ctx1) {$ctx1.fill(self,"testSendReceiverAndArgumentsOrdered",{},smalltalk.CodeGeneratorTest)})},
  1284. args: [],
  1285. 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}.",
  1286. messageSends: ["should:return:"],
  1287. referencedClasses: ["Array"]
  1288. }),
  1289. smalltalk.CodeGeneratorTest);
  1290. smalltalk.addMethod(
  1291. smalltalk.method({
  1292. selector: "testifFalse",
  1293. category: 'tests',
  1294. fn: function (){
  1295. var self=this;
  1296. return smalltalk.withContext(function($ctx1) {
  1297. self._should_return_("foo true ifFalse: [ ^ 1 ]",self["@receiver"]);
  1298. self._should_return_("foo false ifFalse: [ ^ 2 ]",(2));
  1299. self._should_return_("foo ^ true ifFalse: [ 1 ]",nil);
  1300. self._should_return_("foo ^ false ifFalse: [ 2 ]",(2));
  1301. return self}, function($ctx1) {$ctx1.fill(self,"testifFalse",{},smalltalk.CodeGeneratorTest)})},
  1302. args: [],
  1303. 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.",
  1304. messageSends: ["should:return:"],
  1305. referencedClasses: []
  1306. }),
  1307. smalltalk.CodeGeneratorTest);
  1308. smalltalk.addMethod(
  1309. smalltalk.method({
  1310. selector: "testifFalseIfTrue",
  1311. category: 'tests',
  1312. fn: function (){
  1313. var self=this;
  1314. return smalltalk.withContext(function($ctx1) {
  1315. self._should_return_("foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]",(2));
  1316. self._should_return_("foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]",(2));
  1317. self._should_return_("foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]",(2));
  1318. self._should_return_("foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]",(2));
  1319. return self}, function($ctx1) {$ctx1.fill(self,"testifFalseIfTrue",{},smalltalk.CodeGeneratorTest)})},
  1320. args: [],
  1321. 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.",
  1322. messageSends: ["should:return:"],
  1323. referencedClasses: []
  1324. }),
  1325. smalltalk.CodeGeneratorTest);
  1326. smalltalk.addMethod(
  1327. smalltalk.method({
  1328. selector: "testifNil",
  1329. category: 'tests',
  1330. fn: function (){
  1331. var self=this;
  1332. return smalltalk.withContext(function($ctx1) {
  1333. self._should_return_("foo ^ 1 ifNil: [ 2 ]",(1));
  1334. self._should_return_("foo ^ nil ifNil: [ 2 ]",(2));
  1335. self._should_return_("foo 1 ifNil: [ ^ 2 ]",self["@receiver"]);
  1336. self._should_return_("foo nil ifNil: [ ^ 2 ]",(2));
  1337. return self}, function($ctx1) {$ctx1.fill(self,"testifNil",{},smalltalk.CodeGeneratorTest)})},
  1338. args: [],
  1339. 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.",
  1340. messageSends: ["should:return:"],
  1341. referencedClasses: []
  1342. }),
  1343. smalltalk.CodeGeneratorTest);
  1344. smalltalk.addMethod(
  1345. smalltalk.method({
  1346. selector: "testifNilIfNotNil",
  1347. category: 'tests',
  1348. fn: function (){
  1349. var self=this;
  1350. return smalltalk.withContext(function($ctx1) {
  1351. self._should_return_("foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]",(3));
  1352. self._should_return_("foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]",(2));
  1353. self._should_return_("foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(3));
  1354. self._should_return_("foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(2));
  1355. return self}, function($ctx1) {$ctx1.fill(self,"testifNilIfNotNil",{},smalltalk.CodeGeneratorTest)})},
  1356. args: [],
  1357. 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.",
  1358. messageSends: ["should:return:"],
  1359. referencedClasses: []
  1360. }),
  1361. smalltalk.CodeGeneratorTest);
  1362. smalltalk.addMethod(
  1363. smalltalk.method({
  1364. selector: "testifNotNil",
  1365. category: 'tests',
  1366. fn: function (){
  1367. var self=this;
  1368. return smalltalk.withContext(function($ctx1) {
  1369. self._should_return_("foo ^ 1 ifNotNil: [ 2 ]",(2));
  1370. self._should_return_("foo ^ nil ifNotNil: [ 2 ]",nil);
  1371. self._should_return_("foo 1 ifNotNil: [ ^ 2 ]",(2));
  1372. self._should_return_("foo nil ifNotNil: [ ^ 2 ]",self["@receiver"]);
  1373. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNil",{},smalltalk.CodeGeneratorTest)})},
  1374. args: [],
  1375. 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.",
  1376. messageSends: ["should:return:"],
  1377. referencedClasses: []
  1378. }),
  1379. smalltalk.CodeGeneratorTest);
  1380. smalltalk.addMethod(
  1381. smalltalk.method({
  1382. selector: "testifNotNilWithArgument",
  1383. category: 'tests',
  1384. fn: function (){
  1385. var self=this;
  1386. return smalltalk.withContext(function($ctx1) {
  1387. self._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ]",(3));
  1388. self._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ]",nil);
  1389. self._should_return_("foo ^ 1 ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(3));
  1390. self._should_return_("foo ^ nil ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(5));
  1391. self._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(3));
  1392. self._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(5));
  1393. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNilWithArgument",{},smalltalk.CodeGeneratorTest)})},
  1394. args: [],
  1395. 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",
  1396. messageSends: ["should:return:"],
  1397. referencedClasses: []
  1398. }),
  1399. smalltalk.CodeGeneratorTest);
  1400. smalltalk.addMethod(
  1401. smalltalk.method({
  1402. selector: "testifTrue",
  1403. category: 'tests',
  1404. fn: function (){
  1405. var self=this;
  1406. return smalltalk.withContext(function($ctx1) {
  1407. self._should_return_("foo false ifTrue: [ ^ 1 ]",self["@receiver"]);
  1408. self._should_return_("foo true ifTrue: [ ^ 2 ]",(2));
  1409. self._should_return_("foo ^ false ifTrue: [ 1 ]",nil);
  1410. self._should_return_("foo ^ true ifTrue: [ 2 ]",(2));
  1411. return self}, function($ctx1) {$ctx1.fill(self,"testifTrue",{},smalltalk.CodeGeneratorTest)})},
  1412. args: [],
  1413. 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.",
  1414. messageSends: ["should:return:"],
  1415. referencedClasses: []
  1416. }),
  1417. smalltalk.CodeGeneratorTest);
  1418. smalltalk.addMethod(
  1419. smalltalk.method({
  1420. selector: "testifTrueIfFalse",
  1421. category: 'tests',
  1422. fn: function (){
  1423. var self=this;
  1424. return smalltalk.withContext(function($ctx1) {
  1425. self._should_return_("foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]",(2));
  1426. self._should_return_("foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]",(1));
  1427. self._should_return_("foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]",(1));
  1428. self._should_return_("foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]",(2));
  1429. return self}, function($ctx1) {$ctx1.fill(self,"testifTrueIfFalse",{},smalltalk.CodeGeneratorTest)})},
  1430. args: [],
  1431. 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.",
  1432. messageSends: ["should:return:"],
  1433. referencedClasses: []
  1434. }),
  1435. smalltalk.CodeGeneratorTest);
  1436. smalltalk.addClass('InliningCodeGeneratorTest', smalltalk.CodeGeneratorTest, [], 'Compiler-Tests');
  1437. smalltalk.addMethod(
  1438. smalltalk.method({
  1439. selector: "codeGeneratorClass",
  1440. category: 'accessing',
  1441. fn: function (){
  1442. var self=this;
  1443. function $InliningCodeGenerator(){return smalltalk.InliningCodeGenerator||(typeof InliningCodeGenerator=="undefined"?nil:InliningCodeGenerator)}
  1444. return smalltalk.withContext(function($ctx1) {
  1445. var $1;
  1446. $1=$InliningCodeGenerator();
  1447. return $1;
  1448. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{},smalltalk.InliningCodeGeneratorTest)})},
  1449. args: [],
  1450. source: "codeGeneratorClass\x0a\x09^ InliningCodeGenerator",
  1451. messageSends: [],
  1452. referencedClasses: ["InliningCodeGenerator"]
  1453. }),
  1454. smalltalk.InliningCodeGeneratorTest);
  1455. smalltalk.addClass('ScopeVarTest', smalltalk.TestCase, [], 'Compiler-Tests');
  1456. smalltalk.addMethod(
  1457. smalltalk.method({
  1458. selector: "testClassRefVar",
  1459. category: 'tests',
  1460. fn: function (){
  1461. var self=this;
  1462. var node;
  1463. function $ClassReferenceNode(){return smalltalk.ClassReferenceNode||(typeof ClassReferenceNode=="undefined"?nil:ClassReferenceNode)}
  1464. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1465. return smalltalk.withContext(function($ctx1) {
  1466. var $1,$2;
  1467. $1=_st($ClassReferenceNode())._new();
  1468. _st($1)._value_("Object");
  1469. $2=_st($1)._yourself();
  1470. node=$2;
  1471. _st(_st($SemanticAnalyzer())._new())._visit_(node);
  1472. self._assert_(_st(_st(node)._binding())._isClassRefVar());
  1473. return self}, function($ctx1) {$ctx1.fill(self,"testClassRefVar",{node:node},smalltalk.ScopeVarTest)})},
  1474. args: [],
  1475. 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",
  1476. messageSends: ["value:", "new", "yourself", "visit:", "assert:", "isClassRefVar", "binding"],
  1477. referencedClasses: ["ClassReferenceNode", "SemanticAnalyzer"]
  1478. }),
  1479. smalltalk.ScopeVarTest);
  1480. smalltalk.addMethod(
  1481. smalltalk.method({
  1482. selector: "testInstanceVar",
  1483. category: 'tests',
  1484. fn: function (){
  1485. var self=this;
  1486. var node,scope;
  1487. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1488. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1489. return smalltalk.withContext(function($ctx1) {
  1490. var $1,$2;
  1491. $1=_st($VariableNode())._new();
  1492. _st($1)._value_("bzzz");
  1493. $2=_st($1)._yourself();
  1494. node=$2;
  1495. scope=_st($MethodLexicalScope())._new();
  1496. _st(scope)._addIVar_("bzzz");
  1497. self._assert_(_st(_st(scope)._bindingFor_(node))._isInstanceVar());
  1498. return self}, function($ctx1) {$ctx1.fill(self,"testInstanceVar",{node:node,scope:scope},smalltalk.ScopeVarTest)})},
  1499. args: [],
  1500. 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",
  1501. messageSends: ["value:", "new", "yourself", "addIVar:", "assert:", "isInstanceVar", "bindingFor:"],
  1502. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1503. }),
  1504. smalltalk.ScopeVarTest);
  1505. smalltalk.addMethod(
  1506. smalltalk.method({
  1507. selector: "testPseudoVar",
  1508. category: 'tests',
  1509. fn: function (){
  1510. var self=this;
  1511. var node,pseudoVars;
  1512. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1513. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1514. return smalltalk.withContext(function($ctx1) {
  1515. var $1,$2;
  1516. pseudoVars=["self", "super", "true", "false", "nil"];
  1517. _st(pseudoVars)._do_((function(each){
  1518. return smalltalk.withContext(function($ctx2) {
  1519. $1=_st($VariableNode())._new();
  1520. _st($1)._value_(each);
  1521. $2=_st($1)._yourself();
  1522. node=$2;
  1523. node;
  1524. return self._assert_(_st(_st(_st($MethodLexicalScope())._new())._bindingFor_(node))._isPseudoVar());
  1525. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  1526. return self}, function($ctx1) {$ctx1.fill(self,"testPseudoVar",{node:node,pseudoVars:pseudoVars},smalltalk.ScopeVarTest)})},
  1527. args: [],
  1528. 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 ]",
  1529. messageSends: ["do:", "value:", "new", "yourself", "assert:", "isPseudoVar", "bindingFor:"],
  1530. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1531. }),
  1532. smalltalk.ScopeVarTest);
  1533. smalltalk.addMethod(
  1534. smalltalk.method({
  1535. selector: "testTempVar",
  1536. category: 'tests',
  1537. fn: function (){
  1538. var self=this;
  1539. var node,scope;
  1540. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1541. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1542. return smalltalk.withContext(function($ctx1) {
  1543. var $1,$2;
  1544. $1=_st($VariableNode())._new();
  1545. _st($1)._value_("bzzz");
  1546. $2=_st($1)._yourself();
  1547. node=$2;
  1548. scope=_st($MethodLexicalScope())._new();
  1549. _st(scope)._addTemp_("bzzz");
  1550. self._assert_(_st(_st(scope)._bindingFor_(node))._isTempVar());
  1551. return self}, function($ctx1) {$ctx1.fill(self,"testTempVar",{node:node,scope:scope},smalltalk.ScopeVarTest)})},
  1552. args: [],
  1553. 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",
  1554. messageSends: ["value:", "new", "yourself", "addTemp:", "assert:", "isTempVar", "bindingFor:"],
  1555. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1556. }),
  1557. smalltalk.ScopeVarTest);
  1558. smalltalk.addMethod(
  1559. smalltalk.method({
  1560. selector: "testUnknownVar",
  1561. category: 'tests',
  1562. fn: function (){
  1563. var self=this;
  1564. var node;
  1565. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1566. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1567. return smalltalk.withContext(function($ctx1) {
  1568. var $1,$2;
  1569. $1=_st($VariableNode())._new();
  1570. _st($1)._value_("bzzz");
  1571. $2=_st($1)._yourself();
  1572. node=$2;
  1573. self._assert_(_st(_st(_st($MethodLexicalScope())._new())._bindingFor_(node))._isNil());
  1574. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVar",{node:node},smalltalk.ScopeVarTest)})},
  1575. args: [],
  1576. source: "testUnknownVar\x0a\x09| node |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09self assert: (MethodLexicalScope new bindingFor: node) isNil",
  1577. messageSends: ["value:", "new", "yourself", "assert:", "isNil", "bindingFor:"],
  1578. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1579. }),
  1580. smalltalk.ScopeVarTest);
  1581. smalltalk.addClass('SemanticAnalyzerTest', smalltalk.TestCase, ['analyzer'], 'Compiler-Tests');
  1582. smalltalk.addMethod(
  1583. smalltalk.method({
  1584. selector: "setUp",
  1585. category: 'running',
  1586. fn: function (){
  1587. var self=this;
  1588. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  1589. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1590. return smalltalk.withContext(function($ctx1) {
  1591. self["@analyzer"]=_st($SemanticAnalyzer())._on_($Object());
  1592. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},smalltalk.SemanticAnalyzerTest)})},
  1593. args: [],
  1594. source: "setUp\x0a\x09analyzer := SemanticAnalyzer on: Object",
  1595. messageSends: ["on:"],
  1596. referencedClasses: ["Object", "SemanticAnalyzer"]
  1597. }),
  1598. smalltalk.SemanticAnalyzerTest);
  1599. smalltalk.addMethod(
  1600. smalltalk.method({
  1601. selector: "testAssignment",
  1602. category: 'tests',
  1603. fn: function (){
  1604. var self=this;
  1605. var src,ast;
  1606. function $InvalidAssignmentError(){return smalltalk.InvalidAssignmentError||(typeof InvalidAssignmentError=="undefined"?nil:InvalidAssignmentError)}
  1607. return smalltalk.withContext(function($ctx1) {
  1608. src="foo self := 1";
  1609. ast=_st(smalltalk)._parse_(src);
  1610. self._should_raise_((function(){
  1611. return smalltalk.withContext(function($ctx2) {
  1612. return _st(self["@analyzer"])._visit_(ast);
  1613. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$InvalidAssignmentError());
  1614. return self}, function($ctx1) {$ctx1.fill(self,"testAssignment",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1615. args: [],
  1616. 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",
  1617. messageSends: ["parse:", "should:raise:", "visit:"],
  1618. referencedClasses: ["InvalidAssignmentError"]
  1619. }),
  1620. smalltalk.SemanticAnalyzerTest);
  1621. smalltalk.addMethod(
  1622. smalltalk.method({
  1623. selector: "testNonLocalReturn",
  1624. category: 'tests',
  1625. fn: function (){
  1626. var self=this;
  1627. var src,ast;
  1628. return smalltalk.withContext(function($ctx1) {
  1629. src="foo | a | a + 1. ^ a";
  1630. ast=_st(smalltalk)._parse_(src);
  1631. _st(self["@analyzer"])._visit_(ast);
  1632. self._deny_(_st(_st(ast)._scope())._hasNonLocalReturn());
  1633. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1634. args: [],
  1635. 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",
  1636. messageSends: ["parse:", "visit:", "deny:", "hasNonLocalReturn", "scope"],
  1637. referencedClasses: []
  1638. }),
  1639. smalltalk.SemanticAnalyzerTest);
  1640. smalltalk.addMethod(
  1641. smalltalk.method({
  1642. selector: "testNonLocalReturn2",
  1643. category: 'tests',
  1644. fn: function (){
  1645. var self=this;
  1646. var src,ast;
  1647. return smalltalk.withContext(function($ctx1) {
  1648. src="foo | a | a + 1. [ [ ^ a] ]";
  1649. ast=_st(smalltalk)._parse_(src);
  1650. _st(self["@analyzer"])._visit_(ast);
  1651. self._assert_(_st(_st(ast)._scope())._hasNonLocalReturn());
  1652. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1653. args: [],
  1654. 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",
  1655. messageSends: ["parse:", "visit:", "assert:", "hasNonLocalReturn", "scope"],
  1656. referencedClasses: []
  1657. }),
  1658. smalltalk.SemanticAnalyzerTest);
  1659. smalltalk.addMethod(
  1660. smalltalk.method({
  1661. selector: "testScope",
  1662. category: 'tests',
  1663. fn: function (){
  1664. var self=this;
  1665. var src,ast;
  1666. return smalltalk.withContext(function($ctx1) {
  1667. src="foo | a | a + 1. [ | b | b := a ]";
  1668. ast=_st(smalltalk)._parse_(src);
  1669. _st(self["@analyzer"])._visit_(ast);
  1670. self._deny_(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._last())._scope()).__eq_eq(_st(ast)._scope()));
  1671. return self}, function($ctx1) {$ctx1.fill(self,"testScope",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1672. args: [],
  1673. 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.",
  1674. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "last", "nodes", "first"],
  1675. referencedClasses: []
  1676. }),
  1677. smalltalk.SemanticAnalyzerTest);
  1678. smalltalk.addMethod(
  1679. smalltalk.method({
  1680. selector: "testScope2",
  1681. category: 'tests',
  1682. fn: function (){
  1683. var self=this;
  1684. var src,ast;
  1685. return smalltalk.withContext(function($ctx1) {
  1686. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1687. ast=_st(smalltalk)._parse_(src);
  1688. _st(self["@analyzer"])._visit_(ast);
  1689. 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()));
  1690. return self}, function($ctx1) {$ctx1.fill(self,"testScope2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1691. args: [],
  1692. 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.",
  1693. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "first", "nodes", "last"],
  1694. referencedClasses: []
  1695. }),
  1696. smalltalk.SemanticAnalyzerTest);
  1697. smalltalk.addMethod(
  1698. smalltalk.method({
  1699. selector: "testScopeLevel",
  1700. category: 'tests',
  1701. fn: function (){
  1702. var self=this;
  1703. var src,ast;
  1704. return smalltalk.withContext(function($ctx1) {
  1705. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1706. ast=_st(smalltalk)._parse_(src);
  1707. _st(self["@analyzer"])._visit_(ast);
  1708. self._assert_equals_(_st(_st(ast)._scope())._scopeLevel(),(1));
  1709. 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));
  1710. return self}, function($ctx1) {$ctx1.fill(self,"testScopeLevel",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1711. args: [],
  1712. 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",
  1713. messageSends: ["parse:", "visit:", "assert:equals:", "scopeLevel", "scope", "first", "nodes", "last"],
  1714. referencedClasses: []
  1715. }),
  1716. smalltalk.SemanticAnalyzerTest);
  1717. smalltalk.addMethod(
  1718. smalltalk.method({
  1719. selector: "testUnknownVariables",
  1720. category: 'tests',
  1721. fn: function (){
  1722. var self=this;
  1723. var src,ast;
  1724. function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1725. return smalltalk.withContext(function($ctx1) {
  1726. src="foo | a | b + a";
  1727. ast=_st(smalltalk)._parse_(src);
  1728. self._should_raise_((function(){
  1729. return smalltalk.withContext(function($ctx2) {
  1730. return _st(self["@analyzer"])._visit_(ast);
  1731. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$UnknownVariableError());
  1732. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariables",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1733. args: [],
  1734. 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",
  1735. messageSends: ["parse:", "should:raise:", "visit:"],
  1736. referencedClasses: ["UnknownVariableError"]
  1737. }),
  1738. smalltalk.SemanticAnalyzerTest);
  1739. smalltalk.addMethod(
  1740. smalltalk.method({
  1741. selector: "testUnknownVariablesWithScope",
  1742. category: 'tests',
  1743. fn: function (){
  1744. var self=this;
  1745. var src,ast;
  1746. function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1747. return smalltalk.withContext(function($ctx1) {
  1748. src="foo | a b | [ c + 1. [ a + 1. d + 1 ]]";
  1749. ast=_st(smalltalk)._parse_(src);
  1750. self._should_raise_((function(){
  1751. return smalltalk.withContext(function($ctx2) {
  1752. return _st(self["@analyzer"])._visit_(ast);
  1753. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$UnknownVariableError());
  1754. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariablesWithScope",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1755. args: [],
  1756. 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",
  1757. messageSends: ["parse:", "should:raise:", "visit:"],
  1758. referencedClasses: ["UnknownVariableError"]
  1759. }),
  1760. smalltalk.SemanticAnalyzerTest);
  1761. smalltalk.addMethod(
  1762. smalltalk.method({
  1763. selector: "testVariableShadowing",
  1764. category: 'tests',
  1765. fn: function (){
  1766. var self=this;
  1767. var src,ast;
  1768. return smalltalk.withContext(function($ctx1) {
  1769. src="foo | a | a + 1";
  1770. ast=_st(smalltalk)._parse_(src);
  1771. _st(self["@analyzer"])._visit_(ast);
  1772. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1773. args: [],
  1774. source: "testVariableShadowing\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1775. messageSends: ["parse:", "visit:"],
  1776. referencedClasses: []
  1777. }),
  1778. smalltalk.SemanticAnalyzerTest);
  1779. smalltalk.addMethod(
  1780. smalltalk.method({
  1781. selector: "testVariableShadowing2",
  1782. category: 'tests',
  1783. fn: function (){
  1784. var self=this;
  1785. var src,ast;
  1786. function $ShadowingVariableError(){return smalltalk.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1787. return smalltalk.withContext(function($ctx1) {
  1788. src="foo | a | a + 1. [ | a | a := 2 ]";
  1789. ast=_st(smalltalk)._parse_(src);
  1790. self._should_raise_((function(){
  1791. return smalltalk.withContext(function($ctx2) {
  1792. return _st(self["@analyzer"])._visit_(ast);
  1793. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$ShadowingVariableError());
  1794. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1795. args: [],
  1796. 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",
  1797. messageSends: ["parse:", "should:raise:", "visit:"],
  1798. referencedClasses: ["ShadowingVariableError"]
  1799. }),
  1800. smalltalk.SemanticAnalyzerTest);
  1801. smalltalk.addMethod(
  1802. smalltalk.method({
  1803. selector: "testVariableShadowing3",
  1804. category: 'tests',
  1805. fn: function (){
  1806. var self=this;
  1807. var src,ast;
  1808. return smalltalk.withContext(function($ctx1) {
  1809. src="foo | a | a + 1. [ | b | b := 2 ]";
  1810. ast=_st(smalltalk)._parse_(src);
  1811. _st(self["@analyzer"])._visit_(ast);
  1812. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing3",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1813. args: [],
  1814. source: "testVariableShadowing3\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | b | b := 2 ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1815. messageSends: ["parse:", "visit:"],
  1816. referencedClasses: []
  1817. }),
  1818. smalltalk.SemanticAnalyzerTest);
  1819. smalltalk.addMethod(
  1820. smalltalk.method({
  1821. selector: "testVariableShadowing4",
  1822. category: 'tests',
  1823. fn: function (){
  1824. var self=this;
  1825. var src,ast;
  1826. return smalltalk.withContext(function($ctx1) {
  1827. src="foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]";
  1828. ast=_st(smalltalk)._parse_(src);
  1829. _st(self["@analyzer"])._visit_(ast);
  1830. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing4",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1831. args: [],
  1832. source: "testVariableShadowing4\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1833. messageSends: ["parse:", "visit:"],
  1834. referencedClasses: []
  1835. }),
  1836. smalltalk.SemanticAnalyzerTest);
  1837. smalltalk.addMethod(
  1838. smalltalk.method({
  1839. selector: "testVariableShadowing5",
  1840. category: 'tests',
  1841. fn: function (){
  1842. var self=this;
  1843. var src,ast;
  1844. function $ShadowingVariableError(){return smalltalk.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1845. return smalltalk.withContext(function($ctx1) {
  1846. src="foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]";
  1847. ast=_st(smalltalk)._parse_(src);
  1848. self._should_raise_((function(){
  1849. return smalltalk.withContext(function($ctx2) {
  1850. return _st(self["@analyzer"])._visit_(ast);
  1851. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$ShadowingVariableError());
  1852. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing5",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1853. args: [],
  1854. 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",
  1855. messageSends: ["parse:", "should:raise:", "visit:"],
  1856. referencedClasses: ["ShadowingVariableError"]
  1857. }),
  1858. smalltalk.SemanticAnalyzerTest);
  1859. smalltalk.addMethod(
  1860. smalltalk.method({
  1861. selector: "testVariablesLookup",
  1862. category: 'tests',
  1863. fn: function (){
  1864. var self=this;
  1865. var src,ast;
  1866. return smalltalk.withContext(function($ctx1) {
  1867. src="foo | a | a + 1. [ | b | b := a ]";
  1868. ast=_st(smalltalk)._parse_(src);
  1869. _st(self["@analyzer"])._visit_(ast);
  1870. self._assert_(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._first())._receiver())._binding())._isTempVar());
  1871. self._assert_(_st(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._first())._receiver())._binding())._scope()).__eq_eq(_st(ast)._scope()));
  1872. 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());
  1873. 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()));
  1874. return self}, function($ctx1) {$ctx1.fill(self,"testVariablesLookup",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1875. args: [],
  1876. 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.",
  1877. messageSends: ["parse:", "visit:", "assert:", "isTempVar", "binding", "receiver", "first", "nodes", "==", "scope", "left", "last"],
  1878. referencedClasses: []
  1879. }),
  1880. smalltalk.SemanticAnalyzerTest);