Compiler-Tests.js 77 KB

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