2
0

Compiler-Tests.js 39 KB

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