Compiler-Tests.js 68 KB

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