Compiler-Tests.js 59 KB

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