Compiler-Tests.js 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  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. "_testMessageSend",
  345. smalltalk.method({
  346. selector: "testMessageSend",
  347. category: 'tests',
  348. fn: function (){
  349. var self=this;
  350. return smalltalk.withContext(function($ctx1) { _st(self)._interpret_("foo 1 + 2");
  351. _st(_st(self)._interpreter())._step();
  352. _st(_st(self)._interpreter())._step();
  353. _st(_st(self)._interpreter())._step();
  354. _st(self)._assert_equals_(_st(_st(_st(self)._interpreter())._currentNode())._value(),(1));
  355. _st(_st(self)._interpreter())._step();
  356. _st(self)._assert_equals_(_st(_st(_st(self)._interpreter())._currentNode())._value(),(2));
  357. _st(_st(self)._interpreter())._step();
  358. _st(self)._assert_equals_(_st(_st(self)._interpreter())._result(),(3));
  359. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSend",{}, smalltalk.ASTSteppingInterpreterTest)})},
  360. args: [],
  361. source: "testMessageSend\x0a\x09self interpret: 'foo 1 + 2'.\x0a \x0a \x22SequenceNode\x22\x0a self interpreter step.\x0a \x0a \x22SendNode\x22\x0a self interpreter step.\x0a \x0a \x22ValueNode\x22\x0a self interpreter step.\x0a self assert: self interpreter currentNode value equals: 1.\x0a \x0a \x22ValueNode\x22\x0a self interpreter step.\x0a self assert: self interpreter currentNode value equals: 2.\x0a \x0a \x22Result\x22\x0a self interpreter step.\x0a self assert: self interpreter result equals: 3\x0a\x09",
  362. messageSends: ["interpret:", "step", "interpreter", "assert:equals:", "value", "currentNode", "result"],
  363. referencedClasses: []
  364. }),
  365. smalltalk.ASTSteppingInterpreterTest);
  366. smalltalk.addMethod(
  367. "_testSimpleStepping",
  368. smalltalk.method({
  369. selector: "testSimpleStepping",
  370. category: 'tests',
  371. fn: function (){
  372. var self=this;
  373. return smalltalk.withContext(function($ctx1) { _st(self)._interpret_("foo 1");
  374. _st(_st(self)._interpreter())._step();
  375. _st(self)._assert_(_st(_st(_st(self)._interpreter())._result())._isNil());
  376. _st(_st(self)._interpreter())._step();
  377. _st(self)._assert_equals_(_st(_st(self)._interpreter())._result(),(1));
  378. return self}, function($ctx1) {$ctx1.fill(self,"testSimpleStepping",{}, smalltalk.ASTSteppingInterpreterTest)})},
  379. args: [],
  380. 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",
  381. messageSends: ["interpret:", "step", "interpreter", "assert:", "isNil", "result", "assert:equals:"],
  382. referencedClasses: []
  383. }),
  384. smalltalk.ASTSteppingInterpreterTest);
  385. smalltalk.addClass('CodeGeneratorTest', smalltalk.TestCase, ['receiver'], 'Compiler-Tests');
  386. smalltalk.addMethod(
  387. "_codeGeneratorClass",
  388. smalltalk.method({
  389. selector: "codeGeneratorClass",
  390. category: 'accessing',
  391. fn: function (){
  392. var self=this;
  393. return smalltalk.withContext(function($ctx1) { var $1;
  394. $1=(smalltalk.CodeGenerator || CodeGenerator);
  395. return $1;
  396. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{}, smalltalk.CodeGeneratorTest)})},
  397. args: [],
  398. source: "codeGeneratorClass\x0a\x09^ CodeGenerator",
  399. messageSends: [],
  400. referencedClasses: ["CodeGenerator"]
  401. }),
  402. smalltalk.CodeGeneratorTest);
  403. smalltalk.addMethod(
  404. "_compiler",
  405. smalltalk.method({
  406. selector: "compiler",
  407. category: 'factory',
  408. fn: function (){
  409. var self=this;
  410. return smalltalk.withContext(function($ctx1) { var $2,$3,$1;
  411. $2=_st((smalltalk.Compiler || Compiler))._new();
  412. _st($2)._codeGeneratorClass_(_st(self)._codeGeneratorClass());
  413. $3=_st($2)._yourself();
  414. $1=$3;
  415. return $1;
  416. }, function($ctx1) {$ctx1.fill(self,"compiler",{}, smalltalk.CodeGeneratorTest)})},
  417. args: [],
  418. source: "compiler\x0a\x09^ Compiler new\x0a\x09\x09codeGeneratorClass: self codeGeneratorClass;\x0a\x09\x09yourself",
  419. messageSends: ["codeGeneratorClass:", "codeGeneratorClass", "new", "yourself"],
  420. referencedClasses: ["Compiler"]
  421. }),
  422. smalltalk.CodeGeneratorTest);
  423. smalltalk.addMethod(
  424. "_setUp",
  425. smalltalk.method({
  426. selector: "setUp",
  427. category: 'initialization',
  428. fn: function (){
  429. var self=this;
  430. return smalltalk.withContext(function($ctx1) { self["@receiver"]=_st(_st(self)._targetClass())._new();
  431. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{}, smalltalk.CodeGeneratorTest)})},
  432. args: [],
  433. source: "setUp\x0a\x09receiver := self targetClass new",
  434. messageSends: ["new", "targetClass"],
  435. referencedClasses: []
  436. }),
  437. smalltalk.CodeGeneratorTest);
  438. smalltalk.addMethod(
  439. "_should_return_",
  440. smalltalk.method({
  441. selector: "should:return:",
  442. category: 'testing',
  443. fn: function (aString,anObject){
  444. var self=this;
  445. var method,result;
  446. return smalltalk.withContext(function($ctx1) { method=_st(_st(self)._compiler())._install_forClass_category_(aString,_st(self)._targetClass(),"tests");
  447. result=_st(self["@receiver"])._perform_(_st(method)._selector());
  448. _st(_st(self)._targetClass())._removeCompiledMethod_(method);
  449. _st(self)._assert_equals_(anObject,result);
  450. return self}, function($ctx1) {$ctx1.fill(self,"should:return:",{aString:aString,anObject:anObject,method:method,result:result}, smalltalk.CodeGeneratorTest)})},
  451. args: ["aString", "anObject"],
  452. 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",
  453. messageSends: ["install:forClass:category:", "targetClass", "compiler", "perform:", "selector", "removeCompiledMethod:", "assert:equals:"],
  454. referencedClasses: []
  455. }),
  456. smalltalk.CodeGeneratorTest);
  457. smalltalk.addMethod(
  458. "_targetClass",
  459. smalltalk.method({
  460. selector: "targetClass",
  461. category: 'accessing',
  462. fn: function (){
  463. var self=this;
  464. return smalltalk.withContext(function($ctx1) { var $1;
  465. $1=(smalltalk.DoIt || DoIt);
  466. return $1;
  467. }, function($ctx1) {$ctx1.fill(self,"targetClass",{}, smalltalk.CodeGeneratorTest)})},
  468. args: [],
  469. source: "targetClass\x0a\x09^ DoIt",
  470. messageSends: [],
  471. referencedClasses: ["DoIt"]
  472. }),
  473. smalltalk.CodeGeneratorTest);
  474. smalltalk.addMethod(
  475. "_tearDown",
  476. smalltalk.method({
  477. selector: "tearDown",
  478. category: 'initialization',
  479. fn: function (){
  480. var self=this;
  481. return smalltalk.withContext(function($ctx1) { return self}, function($ctx1) {$ctx1.fill(self,"tearDown",{}, smalltalk.CodeGeneratorTest)})},
  482. args: [],
  483. source: "tearDown\x0a\x09\x22receiver := nil\x22",
  484. messageSends: [],
  485. referencedClasses: []
  486. }),
  487. smalltalk.CodeGeneratorTest);
  488. smalltalk.addMethod(
  489. "_testAssignment",
  490. smalltalk.method({
  491. selector: "testAssignment",
  492. category: 'tests',
  493. fn: function (){
  494. var self=this;
  495. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo | a | a := true ifTrue: [ 1 ]. ^ a",(1));
  496. _st(self)._should_return_("foo | a | a := false ifTrue: [ 1 ]. ^ a",nil);
  497. _st(self)._should_return_("foo | a | ^ a := true ifTrue: [ 1 ]",(1));
  498. return self}, function($ctx1) {$ctx1.fill(self,"testAssignment",{}, smalltalk.CodeGeneratorTest)})},
  499. args: [],
  500. 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 ",
  501. messageSends: ["should:return:"],
  502. referencedClasses: []
  503. }),
  504. smalltalk.CodeGeneratorTest);
  505. smalltalk.addMethod(
  506. "_testBlockReturn",
  507. smalltalk.method({
  508. selector: "testBlockReturn",
  509. category: 'tests',
  510. fn: function (){
  511. var self=this;
  512. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo ^ #(1 2 3) collect: [ :each | true ifTrue: [ each + 1 ] ]",[(2), (3), (4)]);
  513. _st(self)._should_return_("foo ^ #(1 2 3) collect: [ :each | false ifFalse: [ each + 1 ] ]",[(2), (3), (4)]);
  514. _st(self)._should_return_("foo ^ #(1 2 3) collect: [ :each | each odd ifTrue: [ each + 1 ] ifFalse: [ each - 1 ] ]",[(2), (1), (4)]);
  515. return self}, function($ctx1) {$ctx1.fill(self,"testBlockReturn",{}, smalltalk.CodeGeneratorTest)})},
  516. args: [],
  517. 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).",
  518. messageSends: ["should:return:"],
  519. referencedClasses: []
  520. }),
  521. smalltalk.CodeGeneratorTest);
  522. smalltalk.addMethod(
  523. "_testCascades",
  524. smalltalk.method({
  525. selector: "testCascades",
  526. category: 'tests',
  527. fn: function (){
  528. var self=this;
  529. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo ^ Array new add: 3; add: 4; yourself",[(3), (4)]);
  530. return self}, function($ctx1) {$ctx1.fill(self,"testCascades",{}, smalltalk.CodeGeneratorTest)})},
  531. args: [],
  532. source: "testCascades\x0a\x09\x0a\x09self should: 'foo ^ Array new add: 3; add: 4; yourself' return: #(3 4)",
  533. messageSends: ["should:return:"],
  534. referencedClasses: []
  535. }),
  536. smalltalk.CodeGeneratorTest);
  537. smalltalk.addMethod(
  538. "_testDynamicArrayElementsOrdered",
  539. smalltalk.method({
  540. selector: "testDynamicArrayElementsOrdered",
  541. category: 'tests',
  542. fn: function (){
  543. var self=this;
  544. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo\x0a | x |\x0a x := 1.\x0a ^ { x. true ifTrue: [ x := 2 ] }\x0a",[(1), (2)]);
  545. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicArrayElementsOrdered",{}, smalltalk.CodeGeneratorTest)})},
  546. args: [],
  547. source: "testDynamicArrayElementsOrdered\x0a\x09self should: 'foo\x0a | x |\x0a x := 1.\x0a ^ { x. true ifTrue: [ x := 2 ] }\x0a' return: #(1 2).\x0a",
  548. messageSends: ["should:return:"],
  549. referencedClasses: []
  550. }),
  551. smalltalk.CodeGeneratorTest);
  552. smalltalk.addMethod(
  553. "_testDynamicDictionaryElementsOrdered",
  554. smalltalk.method({
  555. selector: "testDynamicDictionaryElementsOrdered",
  556. category: 'tests',
  557. fn: function (){
  558. var self=this;
  559. 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))]));
  560. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicDictionaryElementsOrdered",{}, smalltalk.CodeGeneratorTest)})},
  561. args: [],
  562. 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",
  563. messageSends: ["should:return:", "->"],
  564. referencedClasses: []
  565. }),
  566. smalltalk.CodeGeneratorTest);
  567. smalltalk.addMethod(
  568. "_testInnerTemporalDependentElementsOrdered",
  569. smalltalk.method({
  570. selector: "testInnerTemporalDependentElementsOrdered",
  571. category: 'tests',
  572. fn: function (){
  573. var self=this;
  574. 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))]);
  575. _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))]);
  576. _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))]);
  577. _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))]));
  578. return self}, function($ctx1) {$ctx1.fill(self,"testInnerTemporalDependentElementsOrdered",{}, smalltalk.CodeGeneratorTest)})},
  579. args: [],
  580. 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",
  581. messageSends: ["should:return:", "->"],
  582. referencedClasses: ["Array"]
  583. }),
  584. smalltalk.CodeGeneratorTest);
  585. smalltalk.addMethod(
  586. "_testLiterals",
  587. smalltalk.method({
  588. selector: "testLiterals",
  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 ^ 'hello'","hello");
  594. _st(self)._should_return_("foo ^ #(1 2 3 4)",[(1), (2), (3), (4)]);
  595. _st(self)._should_return_("foo ^ {1. [:x | x ] value: 2. 3. [4] value}",[(1), (2), (3), (4)]);
  596. _st(self)._should_return_("foo ^ true",true);
  597. _st(self)._should_return_("foo ^ false",false);
  598. _st(self)._should_return_("foo ^ #{1->2. 3->4}",smalltalk.HashedCollection._fromPairs_([_st((1)).__minus_gt((2)),_st((3)).__minus_gt((4))]));
  599. _st(self)._should_return_("foo ^ #hello",smalltalk.symbolFor("hello"));
  600. _st(self)._should_return_("foo ^ -123.456",(-123.456));
  601. return self}, function($ctx1) {$ctx1.fill(self,"testLiterals",{}, smalltalk.CodeGeneratorTest)})},
  602. args: [],
  603. 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",
  604. messageSends: ["should:return:", "->"],
  605. referencedClasses: []
  606. }),
  607. smalltalk.CodeGeneratorTest);
  608. smalltalk.addMethod(
  609. "_testLocalReturn",
  610. smalltalk.method({
  611. selector: "testLocalReturn",
  612. category: 'tests',
  613. fn: function (){
  614. var self=this;
  615. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo ^ 1",(1));
  616. _st(self)._should_return_("foo ^ 1 + 1",(2));
  617. _st(self)._should_return_("foo ",self["@receiver"]);
  618. _st(self)._should_return_("foo self asString",self["@receiver"]);
  619. _st(self)._should_return_("foo | a b | a := 1. b := 2. ^ a + b",(3));
  620. return self}, function($ctx1) {$ctx1.fill(self,"testLocalReturn",{}, smalltalk.CodeGeneratorTest)})},
  621. args: [],
  622. 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",
  623. messageSends: ["should:return:"],
  624. referencedClasses: []
  625. }),
  626. smalltalk.CodeGeneratorTest);
  627. smalltalk.addMethod(
  628. "_testMessageSends",
  629. smalltalk.method({
  630. selector: "testMessageSends",
  631. category: 'tests',
  632. fn: function (){
  633. var self=this;
  634. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo ^ 1 asString","1");
  635. _st(self)._should_return_("foo ^ 1 + 1",(2));
  636. _st(self)._should_return_("foo ^ 1 + 2 * 3",(9));
  637. _st(self)._should_return_("foo ^ 1 to: 3",[(1), (2), (3)]);
  638. _st(self)._should_return_("foo ^ 1 to: 5 by: 2",[(1), (3), (5)]);
  639. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSends",{}, smalltalk.CodeGeneratorTest)})},
  640. args: [],
  641. 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)",
  642. messageSends: ["should:return:"],
  643. referencedClasses: []
  644. }),
  645. smalltalk.CodeGeneratorTest);
  646. smalltalk.addMethod(
  647. "_testNestedIfTrue",
  648. smalltalk.method({
  649. selector: "testNestedIfTrue",
  650. category: 'tests',
  651. fn: function (){
  652. var self=this;
  653. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]",(1));
  654. _st(self)._should_return_("foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]",nil);
  655. _st(self)._should_return_("foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]",(1));
  656. _st(self)._should_return_("foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]",self["@receiver"]);
  657. return self}, function($ctx1) {$ctx1.fill(self,"testNestedIfTrue",{}, smalltalk.CodeGeneratorTest)})},
  658. args: [],
  659. 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.",
  660. messageSends: ["should:return:"],
  661. referencedClasses: []
  662. }),
  663. smalltalk.CodeGeneratorTest);
  664. smalltalk.addMethod(
  665. "_testNonLocalReturn",
  666. smalltalk.method({
  667. selector: "testNonLocalReturn",
  668. category: 'tests',
  669. fn: function (){
  670. var self=this;
  671. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo [ ^ 1 ] value",(1));
  672. _st(self)._should_return_("foo [ ^ 1 + 1 ] value",(2));
  673. _st(self)._should_return_("foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt",(3));
  674. _st(self)._should_return_("foo [ :x | ^ x + x ] value: 4. ^ 2",(8));
  675. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn",{}, smalltalk.CodeGeneratorTest)})},
  676. args: [],
  677. 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",
  678. messageSends: ["should:return:"],
  679. referencedClasses: []
  680. }),
  681. smalltalk.CodeGeneratorTest);
  682. smalltalk.addMethod(
  683. "_testSendReceiverAndArgumentsOrdered",
  684. smalltalk.method({
  685. selector: "testSendReceiverAndArgumentsOrdered",
  686. category: 'tests',
  687. fn: function (){
  688. var self=this;
  689. 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)]);
  690. _st(self)._should_return_("foo\x0a | x |\x0a x := Array.\x0a ^ x with: x with: (true ifTrue: [ x := 2 ])\x0a",[(smalltalk.Array || Array),(2)]);
  691. return self}, function($ctx1) {$ctx1.fill(self,"testSendReceiverAndArgumentsOrdered",{}, smalltalk.CodeGeneratorTest)})},
  692. args: [],
  693. 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",
  694. messageSends: ["should:return:"],
  695. referencedClasses: ["Array"]
  696. }),
  697. smalltalk.CodeGeneratorTest);
  698. smalltalk.addMethod(
  699. "_testifFalse",
  700. smalltalk.method({
  701. selector: "testifFalse",
  702. category: 'tests',
  703. fn: function (){
  704. var self=this;
  705. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo true ifFalse: [ ^ 1 ]",self["@receiver"]);
  706. _st(self)._should_return_("foo false ifFalse: [ ^ 2 ]",(2));
  707. _st(self)._should_return_("foo ^ true ifFalse: [ 1 ]",nil);
  708. _st(self)._should_return_("foo ^ false ifFalse: [ 2 ]",(2));
  709. return self}, function($ctx1) {$ctx1.fill(self,"testifFalse",{}, smalltalk.CodeGeneratorTest)})},
  710. args: [],
  711. 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.",
  712. messageSends: ["should:return:"],
  713. referencedClasses: []
  714. }),
  715. smalltalk.CodeGeneratorTest);
  716. smalltalk.addMethod(
  717. "_testifFalseIfTrue",
  718. smalltalk.method({
  719. selector: "testifFalseIfTrue",
  720. category: 'tests',
  721. fn: function (){
  722. var self=this;
  723. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]",(2));
  724. _st(self)._should_return_("foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]",(2));
  725. _st(self)._should_return_("foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]",(2));
  726. _st(self)._should_return_("foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]",(2));
  727. return self}, function($ctx1) {$ctx1.fill(self,"testifFalseIfTrue",{}, smalltalk.CodeGeneratorTest)})},
  728. args: [],
  729. 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.",
  730. messageSends: ["should:return:"],
  731. referencedClasses: []
  732. }),
  733. smalltalk.CodeGeneratorTest);
  734. smalltalk.addMethod(
  735. "_testifNil",
  736. smalltalk.method({
  737. selector: "testifNil",
  738. category: 'tests',
  739. fn: function (){
  740. var self=this;
  741. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo ^ 1 ifNil: [ 2 ]",(1));
  742. _st(self)._should_return_("foo ^ nil ifNil: [ 2 ]",(2));
  743. _st(self)._should_return_("foo 1 ifNil: [ ^ 2 ]",self["@receiver"]);
  744. _st(self)._should_return_("foo nil ifNil: [ ^ 2 ]",(2));
  745. return self}, function($ctx1) {$ctx1.fill(self,"testifNil",{}, smalltalk.CodeGeneratorTest)})},
  746. args: [],
  747. 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.",
  748. messageSends: ["should:return:"],
  749. referencedClasses: []
  750. }),
  751. smalltalk.CodeGeneratorTest);
  752. smalltalk.addMethod(
  753. "_testifNilIfNotNil",
  754. smalltalk.method({
  755. selector: "testifNilIfNotNil",
  756. category: 'tests',
  757. fn: function (){
  758. var self=this;
  759. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]",(3));
  760. _st(self)._should_return_("foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]",(2));
  761. _st(self)._should_return_("foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(3));
  762. _st(self)._should_return_("foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(2));
  763. return self}, function($ctx1) {$ctx1.fill(self,"testifNilIfNotNil",{}, smalltalk.CodeGeneratorTest)})},
  764. args: [],
  765. 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.",
  766. messageSends: ["should:return:"],
  767. referencedClasses: []
  768. }),
  769. smalltalk.CodeGeneratorTest);
  770. smalltalk.addMethod(
  771. "_testifNotNil",
  772. smalltalk.method({
  773. selector: "testifNotNil",
  774. category: 'tests',
  775. fn: function (){
  776. var self=this;
  777. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo ^ 1 ifNotNil: [ 2 ]",(2));
  778. _st(self)._should_return_("foo ^ nil ifNotNil: [ 2 ]",nil);
  779. _st(self)._should_return_("foo 1 ifNotNil: [ ^ 2 ]",(2));
  780. _st(self)._should_return_("foo nil ifNotNil: [ ^ 2 ]",self["@receiver"]);
  781. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNil",{}, smalltalk.CodeGeneratorTest)})},
  782. args: [],
  783. 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.",
  784. messageSends: ["should:return:"],
  785. referencedClasses: []
  786. }),
  787. smalltalk.CodeGeneratorTest);
  788. smalltalk.addMethod(
  789. "_testifTrue",
  790. smalltalk.method({
  791. selector: "testifTrue",
  792. category: 'tests',
  793. fn: function (){
  794. var self=this;
  795. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo false ifTrue: [ ^ 1 ]",self["@receiver"]);
  796. _st(self)._should_return_("foo true ifTrue: [ ^ 2 ]",(2));
  797. _st(self)._should_return_("foo ^ false ifTrue: [ 1 ]",nil);
  798. _st(self)._should_return_("foo ^ true ifTrue: [ 2 ]",(2));
  799. return self}, function($ctx1) {$ctx1.fill(self,"testifTrue",{}, smalltalk.CodeGeneratorTest)})},
  800. args: [],
  801. 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.",
  802. messageSends: ["should:return:"],
  803. referencedClasses: []
  804. }),
  805. smalltalk.CodeGeneratorTest);
  806. smalltalk.addMethod(
  807. "_testifTrueIfFalse",
  808. smalltalk.method({
  809. selector: "testifTrueIfFalse",
  810. category: 'tests',
  811. fn: function (){
  812. var self=this;
  813. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]",(2));
  814. _st(self)._should_return_("foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]",(1));
  815. _st(self)._should_return_("foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]",(1));
  816. _st(self)._should_return_("foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]",(2));
  817. return self}, function($ctx1) {$ctx1.fill(self,"testifTrueIfFalse",{}, smalltalk.CodeGeneratorTest)})},
  818. args: [],
  819. 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.",
  820. messageSends: ["should:return:"],
  821. referencedClasses: []
  822. }),
  823. smalltalk.CodeGeneratorTest);
  824. smalltalk.addClass('InliningCodeGeneratorTest', smalltalk.CodeGeneratorTest, [], 'Compiler-Tests');
  825. smalltalk.addMethod(
  826. "_codeGeneratorClass",
  827. smalltalk.method({
  828. selector: "codeGeneratorClass",
  829. category: 'accessing',
  830. fn: function (){
  831. var self=this;
  832. return smalltalk.withContext(function($ctx1) { var $1;
  833. $1=(smalltalk.InliningCodeGenerator || InliningCodeGenerator);
  834. return $1;
  835. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{}, smalltalk.InliningCodeGeneratorTest)})},
  836. args: [],
  837. source: "codeGeneratorClass\x0a\x09^ InliningCodeGenerator",
  838. messageSends: [],
  839. referencedClasses: ["InliningCodeGenerator"]
  840. }),
  841. smalltalk.InliningCodeGeneratorTest);
  842. smalltalk.addClass('ScopeVarTest', smalltalk.TestCase, [], 'Compiler-Tests');
  843. smalltalk.addMethod(
  844. "_testClassRefVar",
  845. smalltalk.method({
  846. selector: "testClassRefVar",
  847. category: 'tests',
  848. fn: function (){
  849. var self=this;
  850. var node;
  851. return smalltalk.withContext(function($ctx1) { var $1,$2;
  852. $1=_st((smalltalk.ClassReferenceNode || ClassReferenceNode))._new();
  853. _st($1)._value_("Object");
  854. $2=_st($1)._yourself();
  855. node=$2;
  856. _st(_st((smalltalk.SemanticAnalyzer || SemanticAnalyzer))._new())._visit_(node);
  857. _st(self)._assert_(_st(_st(node)._binding())._isClassRefVar());
  858. return self}, function($ctx1) {$ctx1.fill(self,"testClassRefVar",{node:node}, smalltalk.ScopeVarTest)})},
  859. args: [],
  860. 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",
  861. messageSends: ["value:", "new", "yourself", "visit:", "assert:", "isClassRefVar", "binding"],
  862. referencedClasses: ["ClassReferenceNode", "SemanticAnalyzer"]
  863. }),
  864. smalltalk.ScopeVarTest);
  865. smalltalk.addMethod(
  866. "_testInstanceVar",
  867. smalltalk.method({
  868. selector: "testInstanceVar",
  869. category: 'tests',
  870. fn: function (){
  871. var self=this;
  872. var node,scope;
  873. return smalltalk.withContext(function($ctx1) { var $1,$2;
  874. $1=_st((smalltalk.VariableNode || VariableNode))._new();
  875. _st($1)._value_("bzzz");
  876. $2=_st($1)._yourself();
  877. node=$2;
  878. scope=_st((smalltalk.MethodLexicalScope || MethodLexicalScope))._new();
  879. _st(scope)._addIVar_("bzzz");
  880. _st(self)._assert_(_st(_st(scope)._bindingFor_(node))._isInstanceVar());
  881. return self}, function($ctx1) {$ctx1.fill(self,"testInstanceVar",{node:node,scope:scope}, smalltalk.ScopeVarTest)})},
  882. args: [],
  883. 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",
  884. messageSends: ["value:", "new", "yourself", "addIVar:", "assert:", "isInstanceVar", "bindingFor:"],
  885. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  886. }),
  887. smalltalk.ScopeVarTest);
  888. smalltalk.addMethod(
  889. "_testPseudoVar",
  890. smalltalk.method({
  891. selector: "testPseudoVar",
  892. category: 'tests',
  893. fn: function (){
  894. var self=this;
  895. var node,pseudoVars;
  896. return smalltalk.withContext(function($ctx1) { var $1,$2;
  897. pseudoVars=["self", "super", "true", "false", "nil"];
  898. _st(pseudoVars)._do_((function(each){
  899. return smalltalk.withContext(function($ctx2) { $1=_st((smalltalk.VariableNode || VariableNode))._new();
  900. _st($1)._value_(each);
  901. $2=_st($1)._yourself();
  902. node=$2;
  903. node;
  904. return _st(self)._assert_(_st(_st(_st((smalltalk.MethodLexicalScope || MethodLexicalScope))._new())._bindingFor_(node))._isPseudoVar());
  905. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  906. return self}, function($ctx1) {$ctx1.fill(self,"testPseudoVar",{node:node,pseudoVars:pseudoVars}, smalltalk.ScopeVarTest)})},
  907. args: [],
  908. 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 ]",
  909. messageSends: ["do:", "value:", "new", "yourself", "assert:", "isPseudoVar", "bindingFor:"],
  910. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  911. }),
  912. smalltalk.ScopeVarTest);
  913. smalltalk.addMethod(
  914. "_testTempVar",
  915. smalltalk.method({
  916. selector: "testTempVar",
  917. category: 'tests',
  918. fn: function (){
  919. var self=this;
  920. var node,scope;
  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. scope=_st((smalltalk.MethodLexicalScope || MethodLexicalScope))._new();
  927. _st(scope)._addTemp_("bzzz");
  928. _st(self)._assert_(_st(_st(scope)._bindingFor_(node))._isTempVar());
  929. return self}, function($ctx1) {$ctx1.fill(self,"testTempVar",{node:node,scope:scope}, smalltalk.ScopeVarTest)})},
  930. args: [],
  931. 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",
  932. messageSends: ["value:", "new", "yourself", "addTemp:", "assert:", "isTempVar", "bindingFor:"],
  933. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  934. }),
  935. smalltalk.ScopeVarTest);
  936. smalltalk.addMethod(
  937. "_testUnknownVar",
  938. smalltalk.method({
  939. selector: "testUnknownVar",
  940. category: 'tests',
  941. fn: function (){
  942. var self=this;
  943. var node;
  944. return smalltalk.withContext(function($ctx1) { var $1,$2;
  945. $1=_st((smalltalk.VariableNode || VariableNode))._new();
  946. _st($1)._value_("bzzz");
  947. $2=_st($1)._yourself();
  948. node=$2;
  949. _st(self)._assert_(_st(_st(_st((smalltalk.MethodLexicalScope || MethodLexicalScope))._new())._bindingFor_(node))._isNil());
  950. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVar",{node:node}, smalltalk.ScopeVarTest)})},
  951. args: [],
  952. source: "testUnknownVar\x0a\x09| node |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09self assert: (MethodLexicalScope new bindingFor: node) isNil",
  953. messageSends: ["value:", "new", "yourself", "assert:", "isNil", "bindingFor:"],
  954. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  955. }),
  956. smalltalk.ScopeVarTest);
  957. smalltalk.addClass('SemanticAnalyzerTest', smalltalk.TestCase, ['analyzer'], 'Compiler-Tests');
  958. smalltalk.addMethod(
  959. "_setUp",
  960. smalltalk.method({
  961. selector: "setUp",
  962. category: 'running',
  963. fn: function (){
  964. var self=this;
  965. return smalltalk.withContext(function($ctx1) { self["@analyzer"]=_st((smalltalk.SemanticAnalyzer || SemanticAnalyzer))._on_((smalltalk.Object || Object));
  966. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{}, smalltalk.SemanticAnalyzerTest)})},
  967. args: [],
  968. source: "setUp\x0a\x09analyzer := SemanticAnalyzer on: Object",
  969. messageSends: ["on:"],
  970. referencedClasses: ["Object", "SemanticAnalyzer"]
  971. }),
  972. smalltalk.SemanticAnalyzerTest);
  973. smalltalk.addMethod(
  974. "_testAssignment",
  975. smalltalk.method({
  976. selector: "testAssignment",
  977. category: 'tests',
  978. fn: function (){
  979. var self=this;
  980. var src,ast;
  981. return smalltalk.withContext(function($ctx1) { src="foo self := 1";
  982. ast=_st(smalltalk)._parse_(src);
  983. _st(self)._should_raise_((function(){
  984. return smalltalk.withContext(function($ctx2) { return _st(self["@analyzer"])._visit_(ast);
  985. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),(smalltalk.InvalidAssignmentError || InvalidAssignmentError));
  986. return self}, function($ctx1) {$ctx1.fill(self,"testAssignment",{src:src,ast:ast}, smalltalk.SemanticAnalyzerTest)})},
  987. args: [],
  988. 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",
  989. messageSends: ["parse:", "should:raise:", "visit:"],
  990. referencedClasses: ["InvalidAssignmentError"]
  991. }),
  992. smalltalk.SemanticAnalyzerTest);
  993. smalltalk.addMethod(
  994. "_testNonLocalReturn",
  995. smalltalk.method({
  996. selector: "testNonLocalReturn",
  997. category: 'tests',
  998. fn: function (){
  999. var self=this;
  1000. var src,ast;
  1001. return smalltalk.withContext(function($ctx1) { src="foo | a | a + 1. ^ a";
  1002. ast=_st(smalltalk)._parse_(src);
  1003. _st(self["@analyzer"])._visit_(ast);
  1004. _st(self)._deny_(_st(_st(ast)._scope())._hasNonLocalReturn());
  1005. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn",{src:src,ast:ast}, smalltalk.SemanticAnalyzerTest)})},
  1006. args: [],
  1007. 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",
  1008. messageSends: ["parse:", "visit:", "deny:", "hasNonLocalReturn", "scope"],
  1009. referencedClasses: []
  1010. }),
  1011. smalltalk.SemanticAnalyzerTest);
  1012. smalltalk.addMethod(
  1013. "_testNonLocalReturn2",
  1014. smalltalk.method({
  1015. selector: "testNonLocalReturn2",
  1016. category: 'tests',
  1017. fn: function (){
  1018. var self=this;
  1019. var src,ast;
  1020. return smalltalk.withContext(function($ctx1) { src="foo | a | a + 1. [ [ ^ a] ]";
  1021. ast=_st(smalltalk)._parse_(src);
  1022. _st(self["@analyzer"])._visit_(ast);
  1023. _st(self)._assert_(_st(_st(ast)._scope())._hasNonLocalReturn());
  1024. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn2",{src:src,ast:ast}, smalltalk.SemanticAnalyzerTest)})},
  1025. args: [],
  1026. 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",
  1027. messageSends: ["parse:", "visit:", "assert:", "hasNonLocalReturn", "scope"],
  1028. referencedClasses: []
  1029. }),
  1030. smalltalk.SemanticAnalyzerTest);
  1031. smalltalk.addMethod(
  1032. "_testScope",
  1033. smalltalk.method({
  1034. selector: "testScope",
  1035. category: 'tests',
  1036. fn: function (){
  1037. var self=this;
  1038. var src,ast;
  1039. return smalltalk.withContext(function($ctx1) { src="foo | a | a + 1. [ | b | b := a ]";
  1040. ast=_st(smalltalk)._parse_(src);
  1041. _st(self["@analyzer"])._visit_(ast);
  1042. _st(self)._deny_(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._last())._scope()).__eq_eq(_st(ast)._scope()));
  1043. return self}, function($ctx1) {$ctx1.fill(self,"testScope",{src:src,ast:ast}, smalltalk.SemanticAnalyzerTest)})},
  1044. args: [],
  1045. 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.",
  1046. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "last", "nodes", "first"],
  1047. referencedClasses: []
  1048. }),
  1049. smalltalk.SemanticAnalyzerTest);
  1050. smalltalk.addMethod(
  1051. "_testScope2",
  1052. smalltalk.method({
  1053. selector: "testScope2",
  1054. category: 'tests',
  1055. fn: function (){
  1056. var self=this;
  1057. var src,ast;
  1058. return smalltalk.withContext(function($ctx1) { src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1059. ast=_st(smalltalk)._parse_(src);
  1060. _st(self["@analyzer"])._visit_(ast);
  1061. _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()));
  1062. return self}, function($ctx1) {$ctx1.fill(self,"testScope2",{src:src,ast:ast}, smalltalk.SemanticAnalyzerTest)})},
  1063. args: [],
  1064. 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.",
  1065. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "first", "nodes", "last"],
  1066. referencedClasses: []
  1067. }),
  1068. smalltalk.SemanticAnalyzerTest);
  1069. smalltalk.addMethod(
  1070. "_testScopeLevel",
  1071. smalltalk.method({
  1072. selector: "testScopeLevel",
  1073. category: 'tests',
  1074. fn: function (){
  1075. var self=this;
  1076. var src,ast;
  1077. return smalltalk.withContext(function($ctx1) { src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1078. ast=_st(smalltalk)._parse_(src);
  1079. _st(self["@analyzer"])._visit_(ast);
  1080. _st(self)._assert_(_st(_st(_st(ast)._scope())._scopeLevel()).__eq((1)));
  1081. _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)));
  1082. return self}, function($ctx1) {$ctx1.fill(self,"testScopeLevel",{src:src,ast:ast}, smalltalk.SemanticAnalyzerTest)})},
  1083. args: [],
  1084. 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",
  1085. messageSends: ["parse:", "visit:", "assert:", "=", "scopeLevel", "scope", "first", "nodes", "last"],
  1086. referencedClasses: []
  1087. }),
  1088. smalltalk.SemanticAnalyzerTest);
  1089. smalltalk.addMethod(
  1090. "_testUnknownVariables",
  1091. smalltalk.method({
  1092. selector: "testUnknownVariables",
  1093. category: 'tests',
  1094. fn: function (){
  1095. var self=this;
  1096. var src,ast;
  1097. return smalltalk.withContext(function($ctx1) { src="foo | a | b + a";
  1098. ast=_st(smalltalk)._parse_(src);
  1099. _st(self)._should_raise_((function(){
  1100. return smalltalk.withContext(function($ctx2) { return _st(self["@analyzer"])._visit_(ast);
  1101. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),(smalltalk.UnknownVariableError || UnknownVariableError));
  1102. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariables",{src:src,ast:ast}, smalltalk.SemanticAnalyzerTest)})},
  1103. args: [],
  1104. 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",
  1105. messageSends: ["parse:", "should:raise:", "visit:"],
  1106. referencedClasses: ["UnknownVariableError"]
  1107. }),
  1108. smalltalk.SemanticAnalyzerTest);
  1109. smalltalk.addMethod(
  1110. "_testUnknownVariablesWithScope",
  1111. smalltalk.method({
  1112. selector: "testUnknownVariablesWithScope",
  1113. category: 'tests',
  1114. fn: function (){
  1115. var self=this;
  1116. var src,ast;
  1117. return smalltalk.withContext(function($ctx1) { src="foo | a b | [ c + 1. [ a + 1. d + 1 ]]";
  1118. ast=_st(smalltalk)._parse_(src);
  1119. _st(self)._should_raise_((function(){
  1120. return smalltalk.withContext(function($ctx2) { return _st(self["@analyzer"])._visit_(ast);
  1121. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),(smalltalk.UnknownVariableError || UnknownVariableError));
  1122. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariablesWithScope",{src:src,ast:ast}, smalltalk.SemanticAnalyzerTest)})},
  1123. args: [],
  1124. 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",
  1125. messageSends: ["parse:", "should:raise:", "visit:"],
  1126. referencedClasses: ["UnknownVariableError"]
  1127. }),
  1128. smalltalk.SemanticAnalyzerTest);
  1129. smalltalk.addMethod(
  1130. "_testVariableShadowing",
  1131. smalltalk.method({
  1132. selector: "testVariableShadowing",
  1133. category: 'tests',
  1134. fn: function (){
  1135. var self=this;
  1136. var src,ast;
  1137. return smalltalk.withContext(function($ctx1) { src="foo | a | a + 1";
  1138. ast=_st(smalltalk)._parse_(src);
  1139. _st(self["@analyzer"])._visit_(ast);
  1140. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing",{src:src,ast:ast}, smalltalk.SemanticAnalyzerTest)})},
  1141. args: [],
  1142. source: "testVariableShadowing\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1143. messageSends: ["parse:", "visit:"],
  1144. referencedClasses: []
  1145. }),
  1146. smalltalk.SemanticAnalyzerTest);
  1147. smalltalk.addMethod(
  1148. "_testVariableShadowing2",
  1149. smalltalk.method({
  1150. selector: "testVariableShadowing2",
  1151. category: 'tests',
  1152. fn: function (){
  1153. var self=this;
  1154. var src,ast;
  1155. return smalltalk.withContext(function($ctx1) { src="foo | a | a + 1. [ | a | a := 2 ]";
  1156. ast=_st(smalltalk)._parse_(src);
  1157. _st(self)._should_raise_((function(){
  1158. return smalltalk.withContext(function($ctx2) { return _st(self["@analyzer"])._visit_(ast);
  1159. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),(smalltalk.ShadowingVariableError || ShadowingVariableError));
  1160. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing2",{src:src,ast:ast}, smalltalk.SemanticAnalyzerTest)})},
  1161. args: [],
  1162. 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",
  1163. messageSends: ["parse:", "should:raise:", "visit:"],
  1164. referencedClasses: ["ShadowingVariableError"]
  1165. }),
  1166. smalltalk.SemanticAnalyzerTest);
  1167. smalltalk.addMethod(
  1168. "_testVariableShadowing3",
  1169. smalltalk.method({
  1170. selector: "testVariableShadowing3",
  1171. category: 'tests',
  1172. fn: function (){
  1173. var self=this;
  1174. var src,ast;
  1175. return smalltalk.withContext(function($ctx1) { src="foo | a | a + 1. [ | b | b := 2 ]";
  1176. ast=_st(smalltalk)._parse_(src);
  1177. _st(self["@analyzer"])._visit_(ast);
  1178. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing3",{src:src,ast:ast}, smalltalk.SemanticAnalyzerTest)})},
  1179. args: [],
  1180. source: "testVariableShadowing3\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | b | b := 2 ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1181. messageSends: ["parse:", "visit:"],
  1182. referencedClasses: []
  1183. }),
  1184. smalltalk.SemanticAnalyzerTest);
  1185. smalltalk.addMethod(
  1186. "_testVariableShadowing4",
  1187. smalltalk.method({
  1188. selector: "testVariableShadowing4",
  1189. category: 'tests',
  1190. fn: function (){
  1191. var self=this;
  1192. var src,ast;
  1193. return smalltalk.withContext(function($ctx1) { src="foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]";
  1194. ast=_st(smalltalk)._parse_(src);
  1195. _st(self["@analyzer"])._visit_(ast);
  1196. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing4",{src:src,ast:ast}, smalltalk.SemanticAnalyzerTest)})},
  1197. args: [],
  1198. source: "testVariableShadowing4\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1199. messageSends: ["parse:", "visit:"],
  1200. referencedClasses: []
  1201. }),
  1202. smalltalk.SemanticAnalyzerTest);
  1203. smalltalk.addMethod(
  1204. "_testVariableShadowing5",
  1205. smalltalk.method({
  1206. selector: "testVariableShadowing5",
  1207. category: 'tests',
  1208. fn: function (){
  1209. var self=this;
  1210. var src,ast;
  1211. return smalltalk.withContext(function($ctx1) { src="foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]";
  1212. ast=_st(smalltalk)._parse_(src);
  1213. _st(self)._should_raise_((function(){
  1214. return smalltalk.withContext(function($ctx2) { return _st(self["@analyzer"])._visit_(ast);
  1215. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),(smalltalk.ShadowingVariableError || ShadowingVariableError));
  1216. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing5",{src:src,ast:ast}, smalltalk.SemanticAnalyzerTest)})},
  1217. args: [],
  1218. 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",
  1219. messageSends: ["parse:", "should:raise:", "visit:"],
  1220. referencedClasses: ["ShadowingVariableError"]
  1221. }),
  1222. smalltalk.SemanticAnalyzerTest);
  1223. smalltalk.addMethod(
  1224. "_testVariablesLookup",
  1225. smalltalk.method({
  1226. selector: "testVariablesLookup",
  1227. category: 'tests',
  1228. fn: function (){
  1229. var self=this;
  1230. var src,ast;
  1231. return smalltalk.withContext(function($ctx1) { src="foo | a | a + 1. [ | b | b := a ]";
  1232. ast=_st(smalltalk)._parse_(src);
  1233. _st(self["@analyzer"])._visit_(ast);
  1234. _st(self)._assert_(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._first())._receiver())._binding())._isTempVar());
  1235. _st(self)._assert_(_st(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._first())._receiver())._binding())._scope()).__eq_eq(_st(ast)._scope()));
  1236. _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());
  1237. _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()));
  1238. return self}, function($ctx1) {$ctx1.fill(self,"testVariablesLookup",{src:src,ast:ast}, smalltalk.SemanticAnalyzerTest)})},
  1239. args: [],
  1240. 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.",
  1241. messageSends: ["parse:", "visit:", "assert:", "isTempVar", "binding", "receiver", "first", "nodes", "==", "scope", "left", "last"],
  1242. referencedClasses: []
  1243. }),
  1244. smalltalk.SemanticAnalyzerTest);