Compiler-Tests.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927
  1. smalltalk.addPackage('Compiler-Tests', {});
  2. smalltalk.addClass('CodeGeneratorTest', smalltalk.TestCase, ['receiver'], 'Compiler-Tests');
  3. smalltalk.addMethod(
  4. "_codeGeneratorClass",
  5. smalltalk.method({
  6. selector: "codeGeneratorClass",
  7. category: 'accessing',
  8. fn: function (){
  9. var self=this;
  10. return smalltalk.withContext(function($ctx1) { return (smalltalk.CodeGenerator || CodeGenerator);
  11. }, self, "codeGeneratorClass", [], smalltalk.CodeGeneratorTest)},
  12. args: [],
  13. source: "codeGeneratorClass\x0a\x09^ CodeGenerator",
  14. messageSends: [],
  15. referencedClasses: ["CodeGenerator"]
  16. }),
  17. smalltalk.CodeGeneratorTest);
  18. smalltalk.addMethod(
  19. "_compiler",
  20. smalltalk.method({
  21. selector: "compiler",
  22. category: 'factory',
  23. fn: function (){
  24. var self=this;
  25. return smalltalk.withContext(function($ctx1) { var $2,$3,$1;
  26. $2=_st((smalltalk.Compiler || Compiler))._new();
  27. _st($2)._codeGeneratorClass_(_st(self)._codeGeneratorClass());
  28. $3=_st($2)._yourself();
  29. $1=$3;
  30. return $1;
  31. }, self, "compiler", [], smalltalk.CodeGeneratorTest)},
  32. args: [],
  33. source: "compiler\x0a\x09^ Compiler new\x0a\x09\x09codeGeneratorClass: self codeGeneratorClass;\x0a\x09\x09yourself",
  34. messageSends: ["codeGeneratorClass:", "codeGeneratorClass", "new", "yourself"],
  35. referencedClasses: ["Compiler"]
  36. }),
  37. smalltalk.CodeGeneratorTest);
  38. smalltalk.addMethod(
  39. "_setUp",
  40. smalltalk.method({
  41. selector: "setUp",
  42. category: 'initialization',
  43. fn: function (){
  44. var self=this;
  45. return smalltalk.withContext(function($ctx1) { self["@receiver"]=_st(_st(self)._targetClass())._new();
  46. return self}, self, "setUp", [], smalltalk.CodeGeneratorTest)},
  47. args: [],
  48. source: "setUp\x0a\x09receiver := self targetClass new",
  49. messageSends: ["new", "targetClass"],
  50. referencedClasses: []
  51. }),
  52. smalltalk.CodeGeneratorTest);
  53. smalltalk.addMethod(
  54. "_should_return_",
  55. smalltalk.method({
  56. selector: "should:return:",
  57. category: 'testing',
  58. fn: function (aString,anObject){
  59. var self=this;
  60. return smalltalk.withContext(function($ctx1) { $ctx1.method=nil;
  61. $ctx1.result=nil;
  62. $ctx1.locals.method=_st(_st(self)._compiler())._install_forClass_category_(aString,_st(self)._targetClass(),"tests");
  63. $ctx1.locals.result=_st(self["@receiver"])._perform_(_st($ctx1.locals.method)._selector());
  64. _st(_st(self)._targetClass())._removeCompiledMethod_($ctx1.locals.method);
  65. _st(self)._assert_equals_(anObject,$ctx1.locals.result);
  66. return self}, self, "should:return:", [aString,anObject], smalltalk.CodeGeneratorTest)},
  67. args: ["aString", "anObject"],
  68. 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",
  69. messageSends: ["install:forClass:category:", "targetClass", "compiler", "perform:", "selector", "removeCompiledMethod:", "assert:equals:"],
  70. referencedClasses: []
  71. }),
  72. smalltalk.CodeGeneratorTest);
  73. smalltalk.addMethod(
  74. "_targetClass",
  75. smalltalk.method({
  76. selector: "targetClass",
  77. category: 'accessing',
  78. fn: function (){
  79. var self=this;
  80. return smalltalk.withContext(function($ctx1) { return (smalltalk.DoIt || DoIt);
  81. }, self, "targetClass", [], smalltalk.CodeGeneratorTest)},
  82. args: [],
  83. source: "targetClass\x0a\x09^ DoIt",
  84. messageSends: [],
  85. referencedClasses: ["DoIt"]
  86. }),
  87. smalltalk.CodeGeneratorTest);
  88. smalltalk.addMethod(
  89. "_tearDown",
  90. smalltalk.method({
  91. selector: "tearDown",
  92. category: 'initialization',
  93. fn: function (){
  94. var self=this;
  95. return smalltalk.withContext(function($ctx1) { return self}, self, "tearDown", [], smalltalk.CodeGeneratorTest)},
  96. args: [],
  97. source: "tearDown\x0a\x09\x22receiver := nil\x22",
  98. messageSends: [],
  99. referencedClasses: []
  100. }),
  101. smalltalk.CodeGeneratorTest);
  102. smalltalk.addMethod(
  103. "_testAssignment",
  104. smalltalk.method({
  105. selector: "testAssignment",
  106. category: 'tests',
  107. fn: function (){
  108. var self=this;
  109. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo | a | a := true ifTrue: [ 1 ]. ^ a",(1));
  110. _st(self)._should_return_("foo | a | a := false ifTrue: [ 1 ]. ^ a",nil);
  111. _st(self)._should_return_("foo | a | ^ a := true ifTrue: [ 1 ]",(1));
  112. return self}, self, "testAssignment", [], smalltalk.CodeGeneratorTest)},
  113. args: [],
  114. 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 ",
  115. messageSends: ["should:return:"],
  116. referencedClasses: []
  117. }),
  118. smalltalk.CodeGeneratorTest);
  119. smalltalk.addMethod(
  120. "_testBlockReturn",
  121. smalltalk.method({
  122. selector: "testBlockReturn",
  123. category: 'tests',
  124. fn: function (){
  125. var self=this;
  126. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo ^ #(1 2 3) collect: [ :each | true ifTrue: [ each + 1 ] ]",[(2), (3), (4)]);
  127. _st(self)._should_return_("foo ^ #(1 2 3) collect: [ :each | false ifFalse: [ each + 1 ] ]",[(2), (3), (4)]);
  128. _st(self)._should_return_("foo ^ #(1 2 3) collect: [ :each | each odd ifTrue: [ each + 1 ] ifFalse: [ each - 1 ] ]",[(2), (1), (4)]);
  129. return self}, self, "testBlockReturn", [], smalltalk.CodeGeneratorTest)},
  130. args: [],
  131. 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).",
  132. messageSends: ["should:return:"],
  133. referencedClasses: []
  134. }),
  135. smalltalk.CodeGeneratorTest);
  136. smalltalk.addMethod(
  137. "_testCascades",
  138. smalltalk.method({
  139. selector: "testCascades",
  140. category: 'tests',
  141. fn: function (){
  142. var self=this;
  143. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo ^ Array new add: 3; add: 4; yourself",[(3), (4)]);
  144. return self}, self, "testCascades", [], smalltalk.CodeGeneratorTest)},
  145. args: [],
  146. source: "testCascades\x0a\x09\x0a\x09self should: 'foo ^ Array new add: 3; add: 4; yourself' return: #(3 4)",
  147. messageSends: ["should:return:"],
  148. referencedClasses: []
  149. }),
  150. smalltalk.CodeGeneratorTest);
  151. smalltalk.addMethod(
  152. "_testDynamicArrayElementsOrdered",
  153. smalltalk.method({
  154. selector: "testDynamicArrayElementsOrdered",
  155. category: 'tests',
  156. fn: function (){
  157. var self=this;
  158. smalltalk.send(self,"_should_return_",["foo\x0a | x |\x0a x := 1.\x0a ^ { x. true ifTrue: [ x := 2 ] }\x0a",[(1), (2)]]);
  159. return self},
  160. args: [],
  161. source: "testDynamicArrayElementsOrdered\x0a\x09self should: 'foo\x0a | x |\x0a x := 1.\x0a ^ { x. true ifTrue: [ x := 2 ] }\x0a' return: #(1 2).\x0a",
  162. messageSends: ["should:return:"],
  163. referencedClasses: []
  164. }),
  165. smalltalk.CodeGeneratorTest);
  166. smalltalk.addMethod(
  167. "_testDynamicDictionaryElementsOrdered",
  168. smalltalk.method({
  169. selector: "testDynamicDictionaryElementsOrdered",
  170. category: 'tests',
  171. fn: function (){
  172. var self=this;
  173. smalltalk.send(self,"_should_return_",["foo\x0a | x |\x0a x := 'foo'->1.\x0a ^ #{ x. (true ifTrue: [ x := 'bar'->2 ]) }\x0a",smalltalk.HashedCollection._fromPairs_([smalltalk.send("foo","__minus_gt",[(1)]),smalltalk.send("bar","__minus_gt",[(2)])])]);
  174. return self},
  175. args: [],
  176. 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",
  177. messageSends: ["should:return:", "->"],
  178. referencedClasses: []
  179. }),
  180. smalltalk.CodeGeneratorTest);
  181. smalltalk.addMethod(
  182. "_testInnerTemporalDependentElementsOrdered",
  183. smalltalk.method({
  184. selector: "testInnerTemporalDependentElementsOrdered",
  185. category: 'tests',
  186. fn: function (){
  187. var self=this;
  188. smalltalk.send(self,"_should_return_",["foo\x0a | x |\x0a x := Array.\x0a ^ x with: 'foo'->x with: 'bar'->(true ifTrue: [ x := 2 ])\x0a",[smalltalk.send("foo","__minus_gt",[(smalltalk.Array || Array)]),smalltalk.send("bar","__minus_gt",[(2)])]]);
  189. smalltalk.send(self,"_should_return_",["foo\x0a | x |\x0a x := 1.\x0a ^ Array with: 'foo'->x with: 'bar'->(true ifTrue: [ x := 2 ])\x0a",[smalltalk.send("foo","__minus_gt",[(1)]),smalltalk.send("bar","__minus_gt",[(2)])]]);
  190. smalltalk.send(self,"_should_return_",["foo\x0a | x |\x0a x := 1.\x0a ^ { 'foo'->x. 'bar'->(true ifTrue: [ x := 2 ]) }\x0a",[smalltalk.send("foo","__minus_gt",[(1)]),smalltalk.send("bar","__minus_gt",[(2)])]]);
  191. smalltalk.send(self,"_should_return_",["foo\x0a | x |\x0a x := 1.\x0a ^ #{ 'foo'->x. 'bar'->(true ifTrue: [ x := 2 ]) }\x0a",smalltalk.HashedCollection._fromPairs_([smalltalk.send("foo","__minus_gt",[(1)]),smalltalk.send("bar","__minus_gt",[(2)])])]);
  192. return self},
  193. args: [],
  194. 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",
  195. messageSends: ["should:return:", "->"],
  196. referencedClasses: ["Array"]
  197. }),
  198. smalltalk.CodeGeneratorTest);
  199. smalltalk.addMethod(
  200. "_testLiterals",
  201. smalltalk.method({
  202. selector: "testLiterals",
  203. category: 'tests',
  204. fn: function (){
  205. var self=this;
  206. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo ^ 1",(1));
  207. _st(self)._should_return_("foo ^ 'hello'","hello");
  208. _st(self)._should_return_("foo ^ #(1 2 3 4)",[(1), (2), (3), (4)]);
  209. _st(self)._should_return_("foo ^ {1. [:x | x ] value: 2. 3. [4] value}",[(1), (2), (3), (4)]);
  210. _st(self)._should_return_("foo ^ true",true);
  211. _st(self)._should_return_("foo ^ false",false);
  212. _st(self)._should_return_("foo ^ #{1->2. 3->4}",smalltalk.HashedCollection._fromPairs_([_st((1)).__minus_gt((2)),_st((3)).__minus_gt((4))]));
  213. _st(self)._should_return_("foo ^ #hello",smalltalk.symbolFor("hello"));
  214. _st(self)._should_return_("foo ^ -123.456",(-123.456));
  215. return self}, self, "testLiterals", [], smalltalk.CodeGeneratorTest)},
  216. args: [],
  217. 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",
  218. messageSends: ["should:return:", "->"],
  219. referencedClasses: []
  220. }),
  221. smalltalk.CodeGeneratorTest);
  222. smalltalk.addMethod(
  223. "_testLocalReturn",
  224. smalltalk.method({
  225. selector: "testLocalReturn",
  226. category: 'tests',
  227. fn: function (){
  228. var self=this;
  229. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo ^ 1",(1));
  230. _st(self)._should_return_("foo ^ 1 + 1",(2));
  231. _st(self)._should_return_("foo ",self["@receiver"]);
  232. _st(self)._should_return_("foo self asString",self["@receiver"]);
  233. _st(self)._should_return_("foo | a b | a := 1. b := 2. ^ a + b",(3));
  234. return self}, self, "testLocalReturn", [], smalltalk.CodeGeneratorTest)},
  235. args: [],
  236. 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",
  237. messageSends: ["should:return:"],
  238. referencedClasses: []
  239. }),
  240. smalltalk.CodeGeneratorTest);
  241. smalltalk.addMethod(
  242. "_testMessageSends",
  243. smalltalk.method({
  244. selector: "testMessageSends",
  245. category: 'tests',
  246. fn: function (){
  247. var self=this;
  248. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo ^ 1 asString","1");
  249. _st(self)._should_return_("foo ^ 1 + 1",(2));
  250. _st(self)._should_return_("foo ^ 1 + 2 * 3",(9));
  251. _st(self)._should_return_("foo ^ 1 to: 3",[(1), (2), (3)]);
  252. _st(self)._should_return_("foo ^ 1 to: 5 by: 2",[(1), (3), (5)]);
  253. return self}, self, "testMessageSends", [], smalltalk.CodeGeneratorTest)},
  254. args: [],
  255. 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)",
  256. messageSends: ["should:return:"],
  257. referencedClasses: []
  258. }),
  259. smalltalk.CodeGeneratorTest);
  260. smalltalk.addMethod(
  261. "_testNestedIfTrue",
  262. smalltalk.method({
  263. selector: "testNestedIfTrue",
  264. category: 'tests',
  265. fn: function (){
  266. var self=this;
  267. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]",(1));
  268. _st(self)._should_return_("foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]",nil);
  269. _st(self)._should_return_("foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]",(1));
  270. _st(self)._should_return_("foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]",self["@receiver"]);
  271. return self}, self, "testNestedIfTrue", [], smalltalk.CodeGeneratorTest)},
  272. args: [],
  273. 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.",
  274. messageSends: ["should:return:"],
  275. referencedClasses: []
  276. }),
  277. smalltalk.CodeGeneratorTest);
  278. smalltalk.addMethod(
  279. "_testNonLocalReturn",
  280. smalltalk.method({
  281. selector: "testNonLocalReturn",
  282. category: 'tests',
  283. fn: function (){
  284. var self=this;
  285. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo [ ^ 1 ] value",(1));
  286. _st(self)._should_return_("foo [ ^ 1 + 1 ] value",(2));
  287. _st(self)._should_return_("foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt",(3));
  288. _st(self)._should_return_("foo [ :x | ^ x + x ] value: 4. ^ 2",(8));
  289. return self}, self, "testNonLocalReturn", [], smalltalk.CodeGeneratorTest)},
  290. args: [],
  291. 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",
  292. messageSends: ["should:return:"],
  293. referencedClasses: []
  294. }),
  295. smalltalk.CodeGeneratorTest);
  296. smalltalk.addMethod(
  297. "_testSendReceiverAndArgumentsOrdered",
  298. smalltalk.method({
  299. selector: "testSendReceiverAndArgumentsOrdered",
  300. category: 'tests',
  301. fn: function (){
  302. var self=this;
  303. smalltalk.send(self,"_should_return_",["foo\x0a | x |\x0a x := 1.\x0a ^ Array with: x with: (true ifTrue: [ x := 2 ])\x0a",[(1), (2)]]);
  304. smalltalk.send(self,"_should_return_",["foo\x0a | x |\x0a x := Array.\x0a ^ x with: x with: (true ifTrue: [ x := 2 ])\x0a",[(smalltalk.Array || Array),(2)]]);
  305. return self},
  306. args: [],
  307. 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",
  308. messageSends: ["should:return:"],
  309. referencedClasses: ["Array"]
  310. }),
  311. smalltalk.CodeGeneratorTest);
  312. smalltalk.addMethod(
  313. "_testifFalse",
  314. smalltalk.method({
  315. selector: "testifFalse",
  316. category: 'tests',
  317. fn: function (){
  318. var self=this;
  319. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo true ifFalse: [ ^ 1 ]",self["@receiver"]);
  320. _st(self)._should_return_("foo false ifFalse: [ ^ 2 ]",(2));
  321. _st(self)._should_return_("foo ^ true ifFalse: [ 1 ]",nil);
  322. _st(self)._should_return_("foo ^ false ifFalse: [ 2 ]",(2));
  323. return self}, self, "testifFalse", [], smalltalk.CodeGeneratorTest)},
  324. args: [],
  325. 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.",
  326. messageSends: ["should:return:"],
  327. referencedClasses: []
  328. }),
  329. smalltalk.CodeGeneratorTest);
  330. smalltalk.addMethod(
  331. "_testifFalseIfTrue",
  332. smalltalk.method({
  333. selector: "testifFalseIfTrue",
  334. category: 'tests',
  335. fn: function (){
  336. var self=this;
  337. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]",(2));
  338. _st(self)._should_return_("foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]",(2));
  339. _st(self)._should_return_("foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]",(2));
  340. _st(self)._should_return_("foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]",(2));
  341. return self}, self, "testifFalseIfTrue", [], smalltalk.CodeGeneratorTest)},
  342. args: [],
  343. 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.",
  344. messageSends: ["should:return:"],
  345. referencedClasses: []
  346. }),
  347. smalltalk.CodeGeneratorTest);
  348. smalltalk.addMethod(
  349. "_testifNil",
  350. smalltalk.method({
  351. selector: "testifNil",
  352. category: 'tests',
  353. fn: function (){
  354. var self=this;
  355. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo ^ 1 ifNil: [ 2 ]",(1));
  356. _st(self)._should_return_("foo ^ nil ifNil: [ 2 ]",(2));
  357. _st(self)._should_return_("foo 1 ifNil: [ ^ 2 ]",self["@receiver"]);
  358. _st(self)._should_return_("foo nil ifNil: [ ^ 2 ]",(2));
  359. return self}, self, "testifNil", [], smalltalk.CodeGeneratorTest)},
  360. args: [],
  361. 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.",
  362. messageSends: ["should:return:"],
  363. referencedClasses: []
  364. }),
  365. smalltalk.CodeGeneratorTest);
  366. smalltalk.addMethod(
  367. "_testifNilIfNotNil",
  368. smalltalk.method({
  369. selector: "testifNilIfNotNil",
  370. category: 'tests',
  371. fn: function (){
  372. var self=this;
  373. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]",(3));
  374. _st(self)._should_return_("foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]",(2));
  375. _st(self)._should_return_("foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(3));
  376. _st(self)._should_return_("foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(2));
  377. return self}, self, "testifNilIfNotNil", [], smalltalk.CodeGeneratorTest)},
  378. args: [],
  379. 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.",
  380. messageSends: ["should:return:"],
  381. referencedClasses: []
  382. }),
  383. smalltalk.CodeGeneratorTest);
  384. smalltalk.addMethod(
  385. "_testifNotNil",
  386. smalltalk.method({
  387. selector: "testifNotNil",
  388. category: 'tests',
  389. fn: function (){
  390. var self=this;
  391. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo ^ 1 ifNotNil: [ 2 ]",(2));
  392. _st(self)._should_return_("foo ^ nil ifNotNil: [ 2 ]",nil);
  393. _st(self)._should_return_("foo 1 ifNotNil: [ ^ 2 ]",(2));
  394. _st(self)._should_return_("foo nil ifNotNil: [ ^ 2 ]",self["@receiver"]);
  395. return self}, self, "testifNotNil", [], smalltalk.CodeGeneratorTest)},
  396. args: [],
  397. 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.",
  398. messageSends: ["should:return:"],
  399. referencedClasses: []
  400. }),
  401. smalltalk.CodeGeneratorTest);
  402. smalltalk.addMethod(
  403. "_testifTrue",
  404. smalltalk.method({
  405. selector: "testifTrue",
  406. category: 'tests',
  407. fn: function (){
  408. var self=this;
  409. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo false ifTrue: [ ^ 1 ]",self["@receiver"]);
  410. _st(self)._should_return_("foo true ifTrue: [ ^ 2 ]",(2));
  411. _st(self)._should_return_("foo ^ false ifTrue: [ 1 ]",nil);
  412. _st(self)._should_return_("foo ^ true ifTrue: [ 2 ]",(2));
  413. return self}, self, "testifTrue", [], smalltalk.CodeGeneratorTest)},
  414. args: [],
  415. 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.",
  416. messageSends: ["should:return:"],
  417. referencedClasses: []
  418. }),
  419. smalltalk.CodeGeneratorTest);
  420. smalltalk.addMethod(
  421. "_testifTrueIfFalse",
  422. smalltalk.method({
  423. selector: "testifTrueIfFalse",
  424. category: 'tests',
  425. fn: function (){
  426. var self=this;
  427. return smalltalk.withContext(function($ctx1) { _st(self)._should_return_("foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]",(2));
  428. _st(self)._should_return_("foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]",(1));
  429. _st(self)._should_return_("foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]",(1));
  430. _st(self)._should_return_("foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]",(2));
  431. return self}, self, "testifTrueIfFalse", [], smalltalk.CodeGeneratorTest)},
  432. args: [],
  433. 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.",
  434. messageSends: ["should:return:"],
  435. referencedClasses: []
  436. }),
  437. smalltalk.CodeGeneratorTest);
  438. smalltalk.addClass('InliningCodeGeneratorTest', smalltalk.CodeGeneratorTest, [], 'Compiler-Tests');
  439. smalltalk.addMethod(
  440. "_codeGeneratorClass",
  441. smalltalk.method({
  442. selector: "codeGeneratorClass",
  443. category: 'accessing',
  444. fn: function (){
  445. var self=this;
  446. return smalltalk.withContext(function($ctx1) { return (smalltalk.InliningCodeGenerator || InliningCodeGenerator);
  447. }, self, "codeGeneratorClass", [], smalltalk.InliningCodeGeneratorTest)},
  448. args: [],
  449. source: "codeGeneratorClass\x0a\x09^ InliningCodeGenerator",
  450. messageSends: [],
  451. referencedClasses: ["InliningCodeGenerator"]
  452. }),
  453. smalltalk.InliningCodeGeneratorTest);
  454. smalltalk.addClass('ScopeVarTest', smalltalk.TestCase, [], 'Compiler-Tests');
  455. smalltalk.addMethod(
  456. "_testClassRefVar",
  457. smalltalk.method({
  458. selector: "testClassRefVar",
  459. category: 'tests',
  460. fn: function (){
  461. var self=this;
  462. return smalltalk.withContext(function($ctx1) { var $1,$2;
  463. $ctx1.node=nil;
  464. $1=_st((smalltalk.ClassReferenceNode || ClassReferenceNode))._new();
  465. _st($1)._value_("Object");
  466. $2=_st($1)._yourself();
  467. $ctx1.locals.node=$2;
  468. _st(_st((smalltalk.SemanticAnalyzer || SemanticAnalyzer))._new())._visit_($ctx1.locals.node);
  469. _st(self)._assert_(_st(_st($ctx1.locals.node)._binding())._isClassRefVar());
  470. return self}, self, "testClassRefVar", [], smalltalk.ScopeVarTest)},
  471. args: [],
  472. 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",
  473. messageSends: ["value:", "new", "yourself", "visit:", "assert:", "isClassRefVar", "binding"],
  474. referencedClasses: ["ClassReferenceNode", "SemanticAnalyzer"]
  475. }),
  476. smalltalk.ScopeVarTest);
  477. smalltalk.addMethod(
  478. "_testInstanceVar",
  479. smalltalk.method({
  480. selector: "testInstanceVar",
  481. category: 'tests',
  482. fn: function (){
  483. var self=this;
  484. return smalltalk.withContext(function($ctx1) { var $1,$2;
  485. $ctx1.node=nil;
  486. $ctx1.scope=nil;
  487. $1=_st((smalltalk.VariableNode || VariableNode))._new();
  488. _st($1)._value_("bzzz");
  489. $2=_st($1)._yourself();
  490. $ctx1.locals.node=$2;
  491. $ctx1.locals.scope=_st((smalltalk.MethodLexicalScope || MethodLexicalScope))._new();
  492. _st($ctx1.locals.scope)._addIVar_("bzzz");
  493. _st(self)._assert_(_st(_st($ctx1.locals.scope)._bindingFor_($ctx1.locals.node))._isInstanceVar());
  494. return self}, self, "testInstanceVar", [], smalltalk.ScopeVarTest)},
  495. args: [],
  496. 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",
  497. messageSends: ["value:", "new", "yourself", "addIVar:", "assert:", "isInstanceVar", "bindingFor:"],
  498. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  499. }),
  500. smalltalk.ScopeVarTest);
  501. smalltalk.addMethod(
  502. "_testPseudoVar",
  503. smalltalk.method({
  504. selector: "testPseudoVar",
  505. category: 'tests',
  506. fn: function (){
  507. var self=this;
  508. return smalltalk.withContext(function($ctx1) { var $1,$2;
  509. $ctx1.node=nil;
  510. $ctx1.pseudoVars=nil;
  511. $ctx1.locals.pseudoVars=["self", "super", "true", "false", "nil"];
  512. _st($ctx1.locals.pseudoVars)._do_((function(each){
  513. return smalltalk.withContext(function($ctx2) { $1=_st((smalltalk.VariableNode || VariableNode))._new();
  514. _st($1)._value_(each);
  515. $2=_st($1)._yourself();
  516. $ctx1.locals.node=$2;
  517. $ctx1.locals.node;
  518. return _st(self)._assert_(_st(_st(_st((smalltalk.MethodLexicalScope || MethodLexicalScope))._new())._bindingFor_($ctx1.locals.node))._isPseudoVar());
  519. })}));
  520. return self}, self, "testPseudoVar", [], smalltalk.ScopeVarTest)},
  521. args: [],
  522. 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 ]",
  523. messageSends: ["do:", "value:", "new", "yourself", "assert:", "isPseudoVar", "bindingFor:"],
  524. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  525. }),
  526. smalltalk.ScopeVarTest);
  527. smalltalk.addMethod(
  528. "_testTempVar",
  529. smalltalk.method({
  530. selector: "testTempVar",
  531. category: 'tests',
  532. fn: function (){
  533. var self=this;
  534. return smalltalk.withContext(function($ctx1) { var $1,$2;
  535. $ctx1.node=nil;
  536. $ctx1.scope=nil;
  537. $1=_st((smalltalk.VariableNode || VariableNode))._new();
  538. _st($1)._value_("bzzz");
  539. $2=_st($1)._yourself();
  540. $ctx1.locals.node=$2;
  541. $ctx1.locals.scope=_st((smalltalk.MethodLexicalScope || MethodLexicalScope))._new();
  542. _st($ctx1.locals.scope)._addTemp_("bzzz");
  543. _st(self)._assert_(_st(_st($ctx1.locals.scope)._bindingFor_($ctx1.locals.node))._isTempVar());
  544. return self}, self, "testTempVar", [], smalltalk.ScopeVarTest)},
  545. args: [],
  546. 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",
  547. messageSends: ["value:", "new", "yourself", "addTemp:", "assert:", "isTempVar", "bindingFor:"],
  548. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  549. }),
  550. smalltalk.ScopeVarTest);
  551. smalltalk.addMethod(
  552. "_testUnknownVar",
  553. smalltalk.method({
  554. selector: "testUnknownVar",
  555. category: 'tests',
  556. fn: function (){
  557. var self=this;
  558. return smalltalk.withContext(function($ctx1) { var $1,$2;
  559. $ctx1.node=nil;
  560. $1=_st((smalltalk.VariableNode || VariableNode))._new();
  561. _st($1)._value_("bzzz");
  562. $2=_st($1)._yourself();
  563. $ctx1.locals.node=$2;
  564. _st(self)._assert_(_st(_st(_st((smalltalk.MethodLexicalScope || MethodLexicalScope))._new())._bindingFor_($ctx1.locals.node))._isNil());
  565. return self}, self, "testUnknownVar", [], smalltalk.ScopeVarTest)},
  566. args: [],
  567. source: "testUnknownVar\x0a\x09| node |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09self assert: (MethodLexicalScope new bindingFor: node) isNil",
  568. messageSends: ["value:", "new", "yourself", "assert:", "isNil", "bindingFor:"],
  569. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  570. }),
  571. smalltalk.ScopeVarTest);
  572. smalltalk.addClass('SemanticAnalyzerTest', smalltalk.TestCase, ['analyzer'], 'Compiler-Tests');
  573. smalltalk.addMethod(
  574. "_setUp",
  575. smalltalk.method({
  576. selector: "setUp",
  577. category: 'running',
  578. fn: function (){
  579. var self=this;
  580. return smalltalk.withContext(function($ctx1) { self["@analyzer"]=_st((smalltalk.SemanticAnalyzer || SemanticAnalyzer))._on_((smalltalk.Object || Object));
  581. return self}, self, "setUp", [], smalltalk.SemanticAnalyzerTest)},
  582. args: [],
  583. source: "setUp\x0a\x09analyzer := SemanticAnalyzer on: Object",
  584. messageSends: ["on:"],
  585. referencedClasses: ["Object", "SemanticAnalyzer"]
  586. }),
  587. smalltalk.SemanticAnalyzerTest);
  588. smalltalk.addMethod(
  589. "_testAssignment",
  590. smalltalk.method({
  591. selector: "testAssignment",
  592. category: 'tests',
  593. fn: function (){
  594. var self=this;
  595. return smalltalk.withContext(function($ctx1) { $ctx1.src=nil;
  596. $ctx1.ast=nil;
  597. $ctx1.locals.src="foo self := 1";
  598. $ctx1.locals.ast=_st(smalltalk)._parse_($ctx1.locals.src);
  599. _st(self)._should_raise_((function(){
  600. return smalltalk.withContext(function($ctx2) { return _st(self["@analyzer"])._visit_($ctx1.locals.ast);
  601. })}),(smalltalk.InvalidAssignmentError || InvalidAssignmentError));
  602. return self}, self, "testAssignment", [], smalltalk.SemanticAnalyzerTest)},
  603. args: [],
  604. 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",
  605. messageSends: ["parse:", "should:raise:", "visit:"],
  606. referencedClasses: ["InvalidAssignmentError"]
  607. }),
  608. smalltalk.SemanticAnalyzerTest);
  609. smalltalk.addMethod(
  610. "_testNonLocalReturn",
  611. smalltalk.method({
  612. selector: "testNonLocalReturn",
  613. category: 'tests',
  614. fn: function (){
  615. var self=this;
  616. return smalltalk.withContext(function($ctx1) { $ctx1.src=nil;
  617. $ctx1.ast=nil;
  618. $ctx1.locals.src="foo | a | a + 1. ^ a";
  619. $ctx1.locals.ast=_st(smalltalk)._parse_($ctx1.locals.src);
  620. _st(self["@analyzer"])._visit_($ctx1.locals.ast);
  621. _st(self)._deny_(_st(_st($ctx1.locals.ast)._scope())._hasNonLocalReturn());
  622. return self}, self, "testNonLocalReturn", [], smalltalk.SemanticAnalyzerTest)},
  623. args: [],
  624. 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",
  625. messageSends: ["parse:", "visit:", "deny:", "hasNonLocalReturn", "scope"],
  626. referencedClasses: []
  627. }),
  628. smalltalk.SemanticAnalyzerTest);
  629. smalltalk.addMethod(
  630. "_testNonLocalReturn2",
  631. smalltalk.method({
  632. selector: "testNonLocalReturn2",
  633. category: 'tests',
  634. fn: function (){
  635. var self=this;
  636. return smalltalk.withContext(function($ctx1) { $ctx1.src=nil;
  637. $ctx1.ast=nil;
  638. $ctx1.locals.src="foo | a | a + 1. [ [ ^ a] ]";
  639. $ctx1.locals.ast=_st(smalltalk)._parse_($ctx1.locals.src);
  640. _st(self["@analyzer"])._visit_($ctx1.locals.ast);
  641. _st(self)._assert_(_st(_st($ctx1.locals.ast)._scope())._hasNonLocalReturn());
  642. return self}, self, "testNonLocalReturn2", [], smalltalk.SemanticAnalyzerTest)},
  643. args: [],
  644. 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",
  645. messageSends: ["parse:", "visit:", "assert:", "hasNonLocalReturn", "scope"],
  646. referencedClasses: []
  647. }),
  648. smalltalk.SemanticAnalyzerTest);
  649. smalltalk.addMethod(
  650. "_testScope",
  651. smalltalk.method({
  652. selector: "testScope",
  653. category: 'tests',
  654. fn: function (){
  655. var self=this;
  656. return smalltalk.withContext(function($ctx1) { $ctx1.src=nil;
  657. $ctx1.ast=nil;
  658. $ctx1.locals.src="foo | a | a + 1. [ | b | b := a ]";
  659. $ctx1.locals.ast=_st(smalltalk)._parse_($ctx1.locals.src);
  660. _st(self["@analyzer"])._visit_($ctx1.locals.ast);
  661. _st(self)._deny_(_st(_st(_st(_st(_st(_st($ctx1.locals.ast)._nodes())._first())._nodes())._last())._scope()).__eq_eq(_st($ctx1.locals.ast)._scope()));
  662. return self}, self, "testScope", [], smalltalk.SemanticAnalyzerTest)},
  663. args: [],
  664. 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.",
  665. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "last", "nodes", "first"],
  666. referencedClasses: []
  667. }),
  668. smalltalk.SemanticAnalyzerTest);
  669. smalltalk.addMethod(
  670. "_testScope2",
  671. smalltalk.method({
  672. selector: "testScope2",
  673. category: 'tests',
  674. fn: function (){
  675. var self=this;
  676. return smalltalk.withContext(function($ctx1) { $ctx1.src=nil;
  677. $ctx1.ast=nil;
  678. $ctx1.locals.src="foo | a | a + 1. [ [ | b | b := a ] ]";
  679. $ctx1.locals.ast=_st(smalltalk)._parse_($ctx1.locals.src);
  680. _st(self["@analyzer"])._visit_($ctx1.locals.ast);
  681. _st(self)._deny_(_st(_st(_st(_st(_st(_st(_st(_st(_st(_st($ctx1.locals.ast)._nodes())._first())._nodes())._last())._nodes())._first())._nodes())._first())._scope()).__eq_eq(_st($ctx1.locals.ast)._scope()));
  682. return self}, self, "testScope2", [], smalltalk.SemanticAnalyzerTest)},
  683. args: [],
  684. 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.",
  685. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "first", "nodes", "last"],
  686. referencedClasses: []
  687. }),
  688. smalltalk.SemanticAnalyzerTest);
  689. smalltalk.addMethod(
  690. "_testScopeLevel",
  691. smalltalk.method({
  692. selector: "testScopeLevel",
  693. category: 'tests',
  694. fn: function (){
  695. var self=this;
  696. return smalltalk.withContext(function($ctx1) { $ctx1.src=nil;
  697. $ctx1.ast=nil;
  698. $ctx1.locals.src="foo | a | a + 1. [ [ | b | b := a ] ]";
  699. $ctx1.locals.ast=_st(smalltalk)._parse_($ctx1.locals.src);
  700. _st(self["@analyzer"])._visit_($ctx1.locals.ast);
  701. _st(self)._assert_(_st(_st(_st($ctx1.locals.ast)._scope())._scopeLevel()).__eq((1)));
  702. _st(self)._assert_(_st(_st(_st(_st(_st(_st(_st(_st(_st(_st(_st($ctx1.locals.ast)._nodes())._first())._nodes())._last())._nodes())._first())._nodes())._first())._scope())._scopeLevel()).__eq((3)));
  703. return self}, self, "testScopeLevel", [], smalltalk.SemanticAnalyzerTest)},
  704. args: [],
  705. 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",
  706. messageSends: ["parse:", "visit:", "assert:", "=", "scopeLevel", "scope", "first", "nodes", "last"],
  707. referencedClasses: []
  708. }),
  709. smalltalk.SemanticAnalyzerTest);
  710. smalltalk.addMethod(
  711. "_testUnknownVariables",
  712. smalltalk.method({
  713. selector: "testUnknownVariables",
  714. category: 'tests',
  715. fn: function (){
  716. var self=this;
  717. return smalltalk.withContext(function($ctx1) { $ctx1.src=nil;
  718. $ctx1.ast=nil;
  719. $ctx1.locals.src="foo | a | b + a";
  720. $ctx1.locals.ast=_st(smalltalk)._parse_($ctx1.locals.src);
  721. _st(self)._should_raise_((function(){
  722. return smalltalk.withContext(function($ctx2) { return _st(self["@analyzer"])._visit_($ctx1.locals.ast);
  723. })}),(smalltalk.UnknownVariableError || UnknownVariableError));
  724. return self}, self, "testUnknownVariables", [], smalltalk.SemanticAnalyzerTest)},
  725. args: [],
  726. 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",
  727. messageSends: ["parse:", "should:raise:", "visit:"],
  728. referencedClasses: ["UnknownVariableError"]
  729. }),
  730. smalltalk.SemanticAnalyzerTest);
  731. smalltalk.addMethod(
  732. "_testUnknownVariablesWithScope",
  733. smalltalk.method({
  734. selector: "testUnknownVariablesWithScope",
  735. category: 'tests',
  736. fn: function (){
  737. var self=this;
  738. return smalltalk.withContext(function($ctx1) { $ctx1.src=nil;
  739. $ctx1.ast=nil;
  740. $ctx1.locals.src="foo | a b | [ c + 1. [ a + 1. d + 1 ]]";
  741. $ctx1.locals.ast=_st(smalltalk)._parse_($ctx1.locals.src);
  742. _st(self)._should_raise_((function(){
  743. return smalltalk.withContext(function($ctx2) { return _st(self["@analyzer"])._visit_($ctx1.locals.ast);
  744. })}),(smalltalk.UnknownVariableError || UnknownVariableError));
  745. return self}, self, "testUnknownVariablesWithScope", [], smalltalk.SemanticAnalyzerTest)},
  746. args: [],
  747. 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",
  748. messageSends: ["parse:", "should:raise:", "visit:"],
  749. referencedClasses: ["UnknownVariableError"]
  750. }),
  751. smalltalk.SemanticAnalyzerTest);
  752. smalltalk.addMethod(
  753. "_testVariableShadowing",
  754. smalltalk.method({
  755. selector: "testVariableShadowing",
  756. category: 'tests',
  757. fn: function (){
  758. var self=this;
  759. return smalltalk.withContext(function($ctx1) { $ctx1.src=nil;
  760. $ctx1.ast=nil;
  761. $ctx1.locals.src="foo | a | a + 1";
  762. $ctx1.locals.ast=_st(smalltalk)._parse_($ctx1.locals.src);
  763. _st(self["@analyzer"])._visit_($ctx1.locals.ast);
  764. return self}, self, "testVariableShadowing", [], smalltalk.SemanticAnalyzerTest)},
  765. args: [],
  766. source: "testVariableShadowing\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  767. messageSends: ["parse:", "visit:"],
  768. referencedClasses: []
  769. }),
  770. smalltalk.SemanticAnalyzerTest);
  771. smalltalk.addMethod(
  772. "_testVariableShadowing2",
  773. smalltalk.method({
  774. selector: "testVariableShadowing2",
  775. category: 'tests',
  776. fn: function (){
  777. var self=this;
  778. return smalltalk.withContext(function($ctx1) { $ctx1.src=nil;
  779. $ctx1.ast=nil;
  780. $ctx1.locals.src="foo | a | a + 1. [ | a | a := 2 ]";
  781. $ctx1.locals.ast=_st(smalltalk)._parse_($ctx1.locals.src);
  782. _st(self)._should_raise_((function(){
  783. return smalltalk.withContext(function($ctx2) { return _st(self["@analyzer"])._visit_($ctx1.locals.ast);
  784. })}),(smalltalk.ShadowingVariableError || ShadowingVariableError));
  785. return self}, self, "testVariableShadowing2", [], smalltalk.SemanticAnalyzerTest)},
  786. args: [],
  787. 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",
  788. messageSends: ["parse:", "should:raise:", "visit:"],
  789. referencedClasses: ["ShadowingVariableError"]
  790. }),
  791. smalltalk.SemanticAnalyzerTest);
  792. smalltalk.addMethod(
  793. "_testVariableShadowing3",
  794. smalltalk.method({
  795. selector: "testVariableShadowing3",
  796. category: 'tests',
  797. fn: function (){
  798. var self=this;
  799. return smalltalk.withContext(function($ctx1) { $ctx1.src=nil;
  800. $ctx1.ast=nil;
  801. $ctx1.locals.src="foo | a | a + 1. [ | b | b := 2 ]";
  802. $ctx1.locals.ast=_st(smalltalk)._parse_($ctx1.locals.src);
  803. _st(self["@analyzer"])._visit_($ctx1.locals.ast);
  804. return self}, self, "testVariableShadowing3", [], smalltalk.SemanticAnalyzerTest)},
  805. args: [],
  806. source: "testVariableShadowing3\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | b | b := 2 ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  807. messageSends: ["parse:", "visit:"],
  808. referencedClasses: []
  809. }),
  810. smalltalk.SemanticAnalyzerTest);
  811. smalltalk.addMethod(
  812. "_testVariableShadowing4",
  813. smalltalk.method({
  814. selector: "testVariableShadowing4",
  815. category: 'tests',
  816. fn: function (){
  817. var self=this;
  818. return smalltalk.withContext(function($ctx1) { $ctx1.src=nil;
  819. $ctx1.ast=nil;
  820. $ctx1.locals.src="foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]";
  821. $ctx1.locals.ast=_st(smalltalk)._parse_($ctx1.locals.src);
  822. _st(self["@analyzer"])._visit_($ctx1.locals.ast);
  823. return self}, self, "testVariableShadowing4", [], smalltalk.SemanticAnalyzerTest)},
  824. args: [],
  825. source: "testVariableShadowing4\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  826. messageSends: ["parse:", "visit:"],
  827. referencedClasses: []
  828. }),
  829. smalltalk.SemanticAnalyzerTest);
  830. smalltalk.addMethod(
  831. "_testVariableShadowing5",
  832. smalltalk.method({
  833. selector: "testVariableShadowing5",
  834. category: 'tests',
  835. fn: function (){
  836. var self=this;
  837. return smalltalk.withContext(function($ctx1) { $ctx1.src=nil;
  838. $ctx1.ast=nil;
  839. $ctx1.locals.src="foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]";
  840. $ctx1.locals.ast=_st(smalltalk)._parse_($ctx1.locals.src);
  841. _st(self)._should_raise_((function(){
  842. return smalltalk.withContext(function($ctx2) { return _st(self["@analyzer"])._visit_($ctx1.locals.ast);
  843. })}),(smalltalk.ShadowingVariableError || ShadowingVariableError));
  844. return self}, self, "testVariableShadowing5", [], smalltalk.SemanticAnalyzerTest)},
  845. args: [],
  846. 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",
  847. messageSends: ["parse:", "should:raise:", "visit:"],
  848. referencedClasses: ["ShadowingVariableError"]
  849. }),
  850. smalltalk.SemanticAnalyzerTest);
  851. smalltalk.addMethod(
  852. "_testVariablesLookup",
  853. smalltalk.method({
  854. selector: "testVariablesLookup",
  855. category: 'tests',
  856. fn: function (){
  857. var self=this;
  858. return smalltalk.withContext(function($ctx1) { $ctx1.src=nil;
  859. $ctx1.ast=nil;
  860. $ctx1.locals.src="foo | a | a + 1. [ | b | b := a ]";
  861. $ctx1.locals.ast=_st(smalltalk)._parse_($ctx1.locals.src);
  862. _st(self["@analyzer"])._visit_($ctx1.locals.ast);
  863. _st(self)._assert_(_st(_st(_st(_st(_st(_st(_st($ctx1.locals.ast)._nodes())._first())._nodes())._first())._receiver())._binding())._isTempVar());
  864. _st(self)._assert_(_st(_st(_st(_st(_st(_st(_st(_st($ctx1.locals.ast)._nodes())._first())._nodes())._first())._receiver())._binding())._scope()).__eq_eq(_st($ctx1.locals.ast)._scope()));
  865. _st(self)._assert_(_st(_st(_st(_st(_st(_st(_st(_st(_st(_st(_st($ctx1.locals.ast)._nodes())._first())._nodes())._last())._nodes())._first())._nodes())._first())._left())._binding())._isTempVar());
  866. _st(self)._assert_(_st(_st(_st(_st(_st(_st(_st(_st(_st(_st(_st(_st($ctx1.locals.ast)._nodes())._first())._nodes())._last())._nodes())._first())._nodes())._first())._left())._binding())._scope()).__eq_eq(_st(_st(_st(_st(_st($ctx1.locals.ast)._nodes())._first())._nodes())._last())._scope()));
  867. return self}, self, "testVariablesLookup", [], smalltalk.SemanticAnalyzerTest)},
  868. args: [],
  869. 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.",
  870. messageSends: ["parse:", "visit:", "assert:", "isTempVar", "binding", "receiver", "first", "nodes", "==", "scope", "left", "last"],
  871. referencedClasses: []
  872. }),
  873. smalltalk.SemanticAnalyzerTest);