2
0

Compiler-Tests.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  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. "_testifFalse",
  261. smalltalk.method({
  262. selector: "testifFalse",
  263. category: 'tests',
  264. fn: function () {
  265. var self = this;
  266. smalltalk.send(self, "_should_return_", ["foo true ifFalse: [ ^ 1 ]", self['@receiver']]);
  267. smalltalk.send(self, "_should_return_", ["foo false ifFalse: [ ^ 2 ]", 2]);
  268. smalltalk.send(self, "_should_return_", ["foo ^ true ifFalse: [ 1 ]", nil]);
  269. smalltalk.send(self, "_should_return_", ["foo ^ false ifFalse: [ 2 ]", 2]);
  270. return self;
  271. },
  272. args: [],
  273. 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.",
  274. messageSends: ["should:return:"],
  275. referencedClasses: []
  276. }),
  277. smalltalk.CodeGeneratorTest);
  278. smalltalk.addMethod(
  279. "_testifFalseIfTrue",
  280. smalltalk.method({
  281. selector: "testifFalseIfTrue",
  282. category: 'tests',
  283. fn: function () {
  284. var self = this;
  285. smalltalk.send(self, "_should_return_", ["foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]", 2]);
  286. smalltalk.send(self, "_should_return_", ["foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]", 2]);
  287. smalltalk.send(self, "_should_return_", ["foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]", 2]);
  288. smalltalk.send(self, "_should_return_", ["foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]", 2]);
  289. return self;
  290. },
  291. args: [],
  292. 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.",
  293. messageSends: ["should:return:"],
  294. referencedClasses: []
  295. }),
  296. smalltalk.CodeGeneratorTest);
  297. smalltalk.addMethod(
  298. "_testifNil",
  299. smalltalk.method({
  300. selector: "testifNil",
  301. category: 'tests',
  302. fn: function () {
  303. var self = this;
  304. smalltalk.send(self, "_should_return_", ["foo ^ 1 ifNil: [ 2 ]", 1]);
  305. smalltalk.send(self, "_should_return_", ["foo ^ nil ifNil: [ 2 ]", 2]);
  306. smalltalk.send(self, "_should_return_", ["foo 1 ifNil: [ ^ 2 ]", self['@receiver']]);
  307. smalltalk.send(self, "_should_return_", ["foo nil ifNil: [ ^ 2 ]", 2]);
  308. return self;
  309. },
  310. args: [],
  311. 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.",
  312. messageSends: ["should:return:"],
  313. referencedClasses: []
  314. }),
  315. smalltalk.CodeGeneratorTest);
  316. smalltalk.addMethod(
  317. "_testifNilIfNotNil",
  318. smalltalk.method({
  319. selector: "testifNilIfNotNil",
  320. category: 'tests',
  321. fn: function () {
  322. var self = this;
  323. smalltalk.send(self, "_should_return_", ["foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]", 3]);
  324. smalltalk.send(self, "_should_return_", ["foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]", 2]);
  325. smalltalk.send(self, "_should_return_", ["foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]", 3]);
  326. smalltalk.send(self, "_should_return_", ["foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]", 2]);
  327. return self;
  328. },
  329. args: [],
  330. 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.",
  331. messageSends: ["should:return:"],
  332. referencedClasses: []
  333. }),
  334. smalltalk.CodeGeneratorTest);
  335. smalltalk.addMethod(
  336. "_testifNotNil",
  337. smalltalk.method({
  338. selector: "testifNotNil",
  339. category: 'tests',
  340. fn: function () {
  341. var self = this;
  342. smalltalk.send(self, "_should_return_", ["foo ^ 1 ifNotNil: [ 2 ]", 2]);
  343. smalltalk.send(self, "_should_return_", ["foo ^ nil ifNotNil: [ 2 ]", nil]);
  344. smalltalk.send(self, "_should_return_", ["foo 1 ifNotNil: [ ^ 2 ]", 2]);
  345. smalltalk.send(self, "_should_return_", ["foo nil ifNotNil: [ ^ 2 ]", self['@receiver']]);
  346. return self;
  347. },
  348. args: [],
  349. 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.",
  350. messageSends: ["should:return:"],
  351. referencedClasses: []
  352. }),
  353. smalltalk.CodeGeneratorTest);
  354. smalltalk.addMethod(
  355. "_testifTrue",
  356. smalltalk.method({
  357. selector: "testifTrue",
  358. category: 'tests',
  359. fn: function () {
  360. var self = this;
  361. smalltalk.send(self, "_should_return_", ["foo false ifTrue: [ ^ 1 ]", self['@receiver']]);
  362. smalltalk.send(self, "_should_return_", ["foo true ifTrue: [ ^ 2 ]", 2]);
  363. smalltalk.send(self, "_should_return_", ["foo ^ false ifTrue: [ 1 ]", nil]);
  364. smalltalk.send(self, "_should_return_", ["foo ^ true ifTrue: [ 2 ]", 2]);
  365. return self;
  366. },
  367. args: [],
  368. 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.",
  369. messageSends: ["should:return:"],
  370. referencedClasses: []
  371. }),
  372. smalltalk.CodeGeneratorTest);
  373. smalltalk.addMethod(
  374. "_testifTrueIfFalse",
  375. smalltalk.method({
  376. selector: "testifTrueIfFalse",
  377. category: 'tests',
  378. fn: function () {
  379. var self = this;
  380. smalltalk.send(self, "_should_return_", ["foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]", 2]);
  381. smalltalk.send(self, "_should_return_", ["foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]", 1]);
  382. smalltalk.send(self, "_should_return_", ["foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]", 1]);
  383. smalltalk.send(self, "_should_return_", ["foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]", 2]);
  384. return self;
  385. },
  386. args: [],
  387. 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.",
  388. messageSends: ["should:return:"],
  389. referencedClasses: []
  390. }),
  391. smalltalk.CodeGeneratorTest);
  392. smalltalk.addClass('InliningCodeGeneratorTest', smalltalk.CodeGeneratorTest, [], 'Compiler-Tests');
  393. smalltalk.addMethod(
  394. "_codeGeneratorClass",
  395. smalltalk.method({
  396. selector: "codeGeneratorClass",
  397. category: 'accessing',
  398. fn: function () {
  399. var self = this;
  400. return smalltalk.InliningCodeGenerator || InliningCodeGenerator;
  401. },
  402. args: [],
  403. source: "codeGeneratorClass\x0a\x09^ InliningCodeGenerator",
  404. messageSends: [],
  405. referencedClasses: ["InliningCodeGenerator"]
  406. }),
  407. smalltalk.InliningCodeGeneratorTest);
  408. smalltalk.addClass('ScopeVarTest', smalltalk.TestCase, [], 'Compiler-Tests');
  409. smalltalk.addMethod(
  410. "_testClassRefVar",
  411. smalltalk.method({
  412. selector: "testClassRefVar",
  413. category: 'tests',
  414. fn: function () {
  415. var self = this;
  416. var $1, $2;
  417. var node;
  418. $1 = smalltalk.send(smalltalk.ClassReferenceNode || ClassReferenceNode, "_new", []);
  419. smalltalk.send($1, "_value_", ["Object"]);
  420. $2 = smalltalk.send($1, "_yourself", []);
  421. node = $2;
  422. smalltalk.send(smalltalk.send(smalltalk.SemanticAnalyzer || SemanticAnalyzer, "_new", []), "_visit_", [node]);
  423. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(node, "_binding", []), "_isClassRefVar", [])]);
  424. return self;
  425. },
  426. args: [],
  427. 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",
  428. messageSends: ["value:", "new", "yourself", "visit:", "assert:", "isClassRefVar", "binding"],
  429. referencedClasses: ["ClassReferenceNode", "SemanticAnalyzer"]
  430. }),
  431. smalltalk.ScopeVarTest);
  432. smalltalk.addMethod(
  433. "_testInstanceVar",
  434. smalltalk.method({
  435. selector: "testInstanceVar",
  436. category: 'tests',
  437. fn: function () {
  438. var self = this;
  439. var $1, $2;
  440. var node;
  441. var scope;
  442. $1 = smalltalk.send(smalltalk.VariableNode || VariableNode, "_new", []);
  443. smalltalk.send($1, "_value_", ["bzzz"]);
  444. $2 = smalltalk.send($1, "_yourself", []);
  445. node = $2;
  446. scope = smalltalk.send(smalltalk.MethodLexicalScope || MethodLexicalScope, "_new", []);
  447. smalltalk.send(scope, "_addIVar_", ["bzzz"]);
  448. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(scope, "_bindingFor_", [node]), "_isInstanceVar", [])]);
  449. return self;
  450. },
  451. args: [],
  452. 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",
  453. messageSends: ["value:", "new", "yourself", "addIVar:", "assert:", "isInstanceVar", "bindingFor:"],
  454. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  455. }),
  456. smalltalk.ScopeVarTest);
  457. smalltalk.addMethod(
  458. "_testPseudoVar",
  459. smalltalk.method({
  460. selector: "testPseudoVar",
  461. category: 'tests',
  462. fn: function () {
  463. var self = this;
  464. var $1, $2;
  465. var node;
  466. var pseudoVars;
  467. pseudoVars = ["self", "super", "true", "false", "nil"];
  468. 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", [])]);}]);
  469. return self;
  470. },
  471. args: [],
  472. 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 ]",
  473. messageSends: ["do:", "value:", "new", "yourself", "assert:", "isPseudoVar", "bindingFor:"],
  474. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  475. }),
  476. smalltalk.ScopeVarTest);
  477. smalltalk.addMethod(
  478. "_testTempVar",
  479. smalltalk.method({
  480. selector: "testTempVar",
  481. category: 'tests',
  482. fn: function () {
  483. var self = this;
  484. var $1, $2;
  485. var node;
  486. var scope;
  487. $1 = smalltalk.send(smalltalk.VariableNode || VariableNode, "_new", []);
  488. smalltalk.send($1, "_value_", ["bzzz"]);
  489. $2 = smalltalk.send($1, "_yourself", []);
  490. node = $2;
  491. scope = smalltalk.send(smalltalk.MethodLexicalScope || MethodLexicalScope, "_new", []);
  492. smalltalk.send(scope, "_addTemp_", ["bzzz"]);
  493. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(scope, "_bindingFor_", [node]), "_isTempVar", [])]);
  494. return self;
  495. },
  496. args: [],
  497. 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",
  498. messageSends: ["value:", "new", "yourself", "addTemp:", "assert:", "isTempVar", "bindingFor:"],
  499. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  500. }),
  501. smalltalk.ScopeVarTest);
  502. smalltalk.addMethod(
  503. "_testUnknownVar",
  504. smalltalk.method({
  505. selector: "testUnknownVar",
  506. category: 'tests',
  507. fn: function () {
  508. var self = this;
  509. var $1, $2;
  510. var node;
  511. $1 = smalltalk.send(smalltalk.VariableNode || VariableNode, "_new", []);
  512. smalltalk.send($1, "_value_", ["bzzz"]);
  513. $2 = smalltalk.send($1, "_yourself", []);
  514. node = $2;
  515. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.MethodLexicalScope || MethodLexicalScope, "_new", []), "_bindingFor_", [node]), "_isNil", [])]);
  516. return self;
  517. },
  518. args: [],
  519. source: "testUnknownVar\x0a\x09| node |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09self assert: (MethodLexicalScope new bindingFor: node) isNil",
  520. messageSends: ["value:", "new", "yourself", "assert:", "isNil", "bindingFor:"],
  521. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  522. }),
  523. smalltalk.ScopeVarTest);
  524. smalltalk.addClass('SemanticAnalyzerTest', smalltalk.TestCase, ['analyzer'], 'Compiler-Tests');
  525. smalltalk.addMethod(
  526. "_setUp",
  527. smalltalk.method({
  528. selector: "setUp",
  529. category: 'running',
  530. fn: function () {
  531. var self = this;
  532. self['@analyzer'] = smalltalk.send(smalltalk.SemanticAnalyzer || SemanticAnalyzer, "_on_", [smalltalk.Object || Object]);
  533. return self;
  534. },
  535. args: [],
  536. source: "setUp\x0a\x09analyzer := SemanticAnalyzer on: Object",
  537. messageSends: ["on:"],
  538. referencedClasses: ["Object", "SemanticAnalyzer"]
  539. }),
  540. smalltalk.SemanticAnalyzerTest);
  541. smalltalk.addMethod(
  542. "_testAssignment",
  543. smalltalk.method({
  544. selector: "testAssignment",
  545. category: 'tests',
  546. fn: function () {
  547. var self = this;
  548. var src;
  549. var ast;
  550. src = "foo self := 1";
  551. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  552. smalltalk.send(self, "_should_raise_", [function () {return smalltalk.send(self['@analyzer'], "_visit_", [ast]);}, smalltalk.InvalidAssignmentError || InvalidAssignmentError]);
  553. return self;
  554. },
  555. args: [],
  556. 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",
  557. messageSends: ["parse:", "should:raise:", "visit:"],
  558. referencedClasses: ["InvalidAssignmentError"]
  559. }),
  560. smalltalk.SemanticAnalyzerTest);
  561. smalltalk.addMethod(
  562. "_testNonLocalReturn",
  563. smalltalk.method({
  564. selector: "testNonLocalReturn",
  565. category: 'tests',
  566. fn: function () {
  567. var self = this;
  568. var src;
  569. var ast;
  570. src = "foo | a | a + 1. ^ a";
  571. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  572. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  573. smalltalk.send(self, "_deny_", [smalltalk.send(smalltalk.send(ast, "_scope", []), "_hasNonLocalReturn", [])]);
  574. return self;
  575. },
  576. args: [],
  577. 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",
  578. messageSends: ["parse:", "visit:", "deny:", "hasNonLocalReturn", "scope"],
  579. referencedClasses: []
  580. }),
  581. smalltalk.SemanticAnalyzerTest);
  582. smalltalk.addMethod(
  583. "_testNonLocalReturn2",
  584. smalltalk.method({
  585. selector: "testNonLocalReturn2",
  586. category: 'tests',
  587. fn: function () {
  588. var self = this;
  589. var src;
  590. var ast;
  591. src = "foo | a | a + 1. [\xA0[ ^ a]\xA0]";
  592. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  593. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  594. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(ast, "_scope", []), "_hasNonLocalReturn", [])]);
  595. return self;
  596. },
  597. args: [],
  598. 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",
  599. messageSends: ["parse:", "visit:", "assert:", "hasNonLocalReturn", "scope"],
  600. referencedClasses: []
  601. }),
  602. smalltalk.SemanticAnalyzerTest);
  603. smalltalk.addMethod(
  604. "_testScope",
  605. smalltalk.method({
  606. selector: "testScope",
  607. category: 'tests',
  608. fn: function () {
  609. var self = this;
  610. var src;
  611. var ast;
  612. src = "foo | a | a + 1. [ | b | b := a ]";
  613. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  614. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  615. 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", [])])]);
  616. return self;
  617. },
  618. args: [],
  619. 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.",
  620. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "last", "nodes", "first"],
  621. referencedClasses: []
  622. }),
  623. smalltalk.SemanticAnalyzerTest);
  624. smalltalk.addMethod(
  625. "_testScope2",
  626. smalltalk.method({
  627. selector: "testScope2",
  628. category: 'tests',
  629. fn: function () {
  630. var self = this;
  631. var src;
  632. var ast;
  633. src = "foo | a | a + 1. [ [ | b | b := a\xA0] ]";
  634. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  635. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  636. 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", [])])]);
  637. return self;
  638. },
  639. args: [],
  640. 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.",
  641. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "first", "nodes", "last"],
  642. referencedClasses: []
  643. }),
  644. smalltalk.SemanticAnalyzerTest);
  645. smalltalk.addMethod(
  646. "_testScopeLevel",
  647. smalltalk.method({
  648. selector: "testScopeLevel",
  649. category: 'tests',
  650. fn: function () {
  651. var self = this;
  652. var src;
  653. var ast;
  654. src = "foo | a | a + 1. [ [ | b | b := a\xA0] ]";
  655. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  656. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  657. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(smalltalk.send(ast, "_scope", []), "_scopeLevel", []), "__eq", [1])]);
  658. 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])]);
  659. return self;
  660. },
  661. args: [],
  662. 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",
  663. messageSends: ["parse:", "visit:", "assert:", "=", "scopeLevel", "scope", "first", "nodes", "last"],
  664. referencedClasses: []
  665. }),
  666. smalltalk.SemanticAnalyzerTest);
  667. smalltalk.addMethod(
  668. "_testUnknownVariables",
  669. smalltalk.method({
  670. selector: "testUnknownVariables",
  671. category: 'tests',
  672. fn: function () {
  673. var self = this;
  674. var src;
  675. var ast;
  676. src = "foo | a | b + a";
  677. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  678. smalltalk.send(self, "_should_raise_", [function () {return smalltalk.send(self['@analyzer'], "_visit_", [ast]);}, smalltalk.UnknownVariableError || UnknownVariableError]);
  679. return self;
  680. },
  681. args: [],
  682. 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",
  683. messageSends: ["parse:", "should:raise:", "visit:"],
  684. referencedClasses: ["UnknownVariableError"]
  685. }),
  686. smalltalk.SemanticAnalyzerTest);
  687. smalltalk.addMethod(
  688. "_testUnknownVariablesDefinedInJS",
  689. smalltalk.method({
  690. selector: "testUnknownVariablesDefinedInJS",
  691. category: 'tests',
  692. fn: function () {
  693. var self = this;
  694. var someVariable = 1;
  695. smalltalk.send(self, "_shouldnt_raise_", [function () {return smalltalk.send(smalltalk, "_parse_", ["foo someVariable"]);}, smalltalk.UnknownVariableError || UnknownVariableError]);
  696. return self;
  697. },
  698. args: [],
  699. source: "testUnknownVariablesDefinedInJS\x0a\x0a\x09< var someVariable = 1 >.\x0a\x0a\x09self shouldnt: [ smalltalk parse: 'foo someVariable' ] raise: UnknownVariableError",
  700. messageSends: ["shouldnt:raise:", "parse:"],
  701. referencedClasses: ["UnknownVariableError"]
  702. }),
  703. smalltalk.SemanticAnalyzerTest);
  704. smalltalk.addMethod(
  705. "_testUnknownVariablesWithScope",
  706. smalltalk.method({
  707. selector: "testUnknownVariablesWithScope",
  708. category: 'tests',
  709. fn: function () {
  710. var self = this;
  711. var src;
  712. var ast;
  713. src = "foo | a b | [ c + 1. [ a + 1. d + 1 ]]";
  714. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  715. smalltalk.send(self, "_should_raise_", [function () {return smalltalk.send(self['@analyzer'], "_visit_", [ast]);}, smalltalk.UnknownVariableError || UnknownVariableError]);
  716. return self;
  717. },
  718. args: [],
  719. 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",
  720. messageSends: ["parse:", "should:raise:", "visit:"],
  721. referencedClasses: ["UnknownVariableError"]
  722. }),
  723. smalltalk.SemanticAnalyzerTest);
  724. smalltalk.addMethod(
  725. "_testVariableShadowing",
  726. smalltalk.method({
  727. selector: "testVariableShadowing",
  728. category: 'tests',
  729. fn: function () {
  730. var self = this;
  731. var src;
  732. var ast;
  733. src = "foo | a | a + 1";
  734. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  735. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  736. return self;
  737. },
  738. args: [],
  739. source: "testVariableShadowing\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  740. messageSends: ["parse:", "visit:"],
  741. referencedClasses: []
  742. }),
  743. smalltalk.SemanticAnalyzerTest);
  744. smalltalk.addMethod(
  745. "_testVariableShadowing2",
  746. smalltalk.method({
  747. selector: "testVariableShadowing2",
  748. category: 'tests',
  749. fn: function () {
  750. var self = this;
  751. var src;
  752. var ast;
  753. src = "foo | a | a + 1. [ | a | a := 2 ]";
  754. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  755. smalltalk.send(self, "_should_raise_", [function () {return smalltalk.send(self['@analyzer'], "_visit_", [ast]);}, smalltalk.ShadowingVariableError || ShadowingVariableError]);
  756. return self;
  757. },
  758. args: [],
  759. 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",
  760. messageSends: ["parse:", "should:raise:", "visit:"],
  761. referencedClasses: ["ShadowingVariableError"]
  762. }),
  763. smalltalk.SemanticAnalyzerTest);
  764. smalltalk.addMethod(
  765. "_testVariableShadowing3",
  766. smalltalk.method({
  767. selector: "testVariableShadowing3",
  768. category: 'tests',
  769. fn: function () {
  770. var self = this;
  771. var src;
  772. var ast;
  773. src = "foo | a | a + 1. [ | b | b := 2 ]";
  774. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  775. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  776. return self;
  777. },
  778. args: [],
  779. source: "testVariableShadowing3\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | b | b := 2 ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  780. messageSends: ["parse:", "visit:"],
  781. referencedClasses: []
  782. }),
  783. smalltalk.SemanticAnalyzerTest);
  784. smalltalk.addMethod(
  785. "_testVariableShadowing4",
  786. smalltalk.method({
  787. selector: "testVariableShadowing4",
  788. category: 'tests',
  789. fn: function () {
  790. var self = this;
  791. var src;
  792. var ast;
  793. src = "foo | a | a + 1. [ [\xA0[ | b | b := 2 ]\xA0]\xA0]";
  794. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  795. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  796. return self;
  797. },
  798. args: [],
  799. source: "testVariableShadowing4\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  800. messageSends: ["parse:", "visit:"],
  801. referencedClasses: []
  802. }),
  803. smalltalk.SemanticAnalyzerTest);
  804. smalltalk.addMethod(
  805. "_testVariableShadowing5",
  806. smalltalk.method({
  807. selector: "testVariableShadowing5",
  808. category: 'tests',
  809. fn: function () {
  810. var self = this;
  811. var src;
  812. var ast;
  813. src = "foo | a | a + 1. [ [\xA0[ | a | a := 2 ]\xA0]\xA0]";
  814. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  815. smalltalk.send(self, "_should_raise_", [function () {return smalltalk.send(self['@analyzer'], "_visit_", [ast]);}, smalltalk.ShadowingVariableError || ShadowingVariableError]);
  816. return self;
  817. },
  818. args: [],
  819. 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",
  820. messageSends: ["parse:", "should:raise:", "visit:"],
  821. referencedClasses: ["ShadowingVariableError"]
  822. }),
  823. smalltalk.SemanticAnalyzerTest);
  824. smalltalk.addMethod(
  825. "_testVariablesLookup",
  826. smalltalk.method({
  827. selector: "testVariablesLookup",
  828. category: 'tests',
  829. fn: function () {
  830. var self = this;
  831. var src;
  832. var ast;
  833. src = "foo | a | a + 1. [ | b | b := a ]";
  834. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  835. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  836. 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", [])]);
  837. 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", [])])]);
  838. 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", [])]);
  839. 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", [])])]);
  840. return self;
  841. },
  842. args: [],
  843. 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.",
  844. messageSends: ["parse:", "visit:", "assert:", "isTempVar", "binding", "receiver", "first", "nodes", "==", "scope", "left", "last"],
  845. referencedClasses: []
  846. }),
  847. smalltalk.SemanticAnalyzerTest);