Compiler-Tests.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  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. "_testDynamicArrayElementsOrdered",
  159. smalltalk.method({
  160. selector: "testDynamicArrayElementsOrdered",
  161. category: 'tests',
  162. fn: function (){
  163. var self=this;
  164. smalltalk.send(self,"_should_return_",["foo\x0a | x |\x0a x := 1.\x0a ^ { x. true ifTrue: [ x := 2 ] }\x0a",[(1), (2)]]);
  165. return self},
  166. args: [],
  167. source: "testDynamicArrayElementsOrdered\x0a\x09self should: 'foo\x0a | x |\x0a x := 1.\x0a ^ { x. true ifTrue: [ x := 2 ] }\x0a' return: #(1 2).\x0a",
  168. messageSends: ["should:return:"],
  169. referencedClasses: []
  170. }),
  171. smalltalk.CodeGeneratorTest);
  172. smalltalk.addMethod(
  173. "_testDynamicDictionaryElementsOrdered",
  174. smalltalk.method({
  175. selector: "testDynamicDictionaryElementsOrdered",
  176. category: 'tests',
  177. fn: function (){
  178. var self=this;
  179. smalltalk.send(self,"_should_return_",["foo\x0a | x |\x0a x := 'foo'->1.\x0a ^ #{ x. (true ifTrue: [ x := 'bar'->2 ]) }\x0a",smalltalk.HashedCollection._fromPairs_([smalltalk.send("foo","__minus_gt",[(1)]),smalltalk.send("bar","__minus_gt",[(2)])])]);
  180. return self},
  181. args: [],
  182. source: "testDynamicDictionaryElementsOrdered\x0a\x09self should: 'foo\x0a | x |\x0a x := ''foo''->1.\x0a ^ #{ x. (true ifTrue: [ x := ''bar''->2 ]) }\x0a' return: #{'foo'->1. 'bar'->2}.\x0a",
  183. messageSends: ["should:return:", "->"],
  184. referencedClasses: []
  185. }),
  186. smalltalk.CodeGeneratorTest);
  187. smalltalk.addMethod(
  188. "_testDynamicDictionaryInnerElementsOrdered",
  189. smalltalk.method({
  190. selector: "testDynamicDictionaryInnerElementsOrdered",
  191. category: 'tests',
  192. fn: function (){
  193. var self=this;
  194. return self},
  195. args: [],
  196. source: "testDynamicDictionaryInnerElementsOrdered\x0a\x22This test is commented out.\x0aThe treatment that help in case of send node,\x0adynamic array node and testDynamicDictionaryElementsOrdered\x0acases, does not help here\x22\x0a\x0a\x22\x09self should: 'foo\x0a | x |\x0a x := 1.\x0a ^ #{ ''foo''->x. ''bar''->(true ifTrue: [ x := 2 ]) }\x0a' return: #{'foo'->1. 'bar'->2}.\x0a\x22",
  197. messageSends: [],
  198. referencedClasses: []
  199. }),
  200. smalltalk.CodeGeneratorTest);
  201. smalltalk.addMethod(
  202. "_testLiterals",
  203. smalltalk.method({
  204. selector: "testLiterals",
  205. category: 'tests',
  206. fn: function () {
  207. var self = this;
  208. smalltalk.send(self, "_should_return_", ["foo ^ 1", 1]);
  209. smalltalk.send(self, "_should_return_", ["foo ^ 'hello'", "hello"]);
  210. smalltalk.send(self, "_should_return_", ["foo ^ #(1 2 3 4)", [1, 2, 3, 4]]);
  211. smalltalk.send(self, "_should_return_", ["foo ^ {1. [:x | x ] value: 2. 3. [4] value}", [1, 2, 3, 4]]);
  212. smalltalk.send(self, "_should_return_", ["foo ^ true", true]);
  213. smalltalk.send(self, "_should_return_", ["foo ^ false", false]);
  214. 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])])]);
  215. smalltalk.send(self, "_should_return_", ["foo ^ #hello", smalltalk.symbolFor("hello")]);
  216. smalltalk.send(self, "_should_return_", ["foo ^ -123.456", -123.456]);
  217. return self;
  218. },
  219. args: [],
  220. 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",
  221. messageSends: ["should:return:", "->"],
  222. referencedClasses: []
  223. }),
  224. smalltalk.CodeGeneratorTest);
  225. smalltalk.addMethod(
  226. "_testLocalReturn",
  227. smalltalk.method({
  228. selector: "testLocalReturn",
  229. category: 'tests',
  230. fn: function () {
  231. var self = this;
  232. smalltalk.send(self, "_should_return_", ["foo ^ 1", 1]);
  233. smalltalk.send(self, "_should_return_", ["foo ^ 1 + 1", 2]);
  234. smalltalk.send(self, "_should_return_", ["foo ", self['@receiver']]);
  235. smalltalk.send(self, "_should_return_", ["foo self asString", self['@receiver']]);
  236. smalltalk.send(self, "_should_return_", ["foo | a b | a := 1. b := 2. ^ a + b", 3]);
  237. return self;
  238. },
  239. args: [],
  240. 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",
  241. messageSends: ["should:return:"],
  242. referencedClasses: []
  243. }),
  244. smalltalk.CodeGeneratorTest);
  245. smalltalk.addMethod(
  246. "_testMessageSends",
  247. smalltalk.method({
  248. selector: "testMessageSends",
  249. category: 'tests',
  250. fn: function () {
  251. var self = this;
  252. smalltalk.send(self, "_should_return_", ["foo ^ 1 asString", "1"]);
  253. smalltalk.send(self, "_should_return_", ["foo ^ 1 + 1", 2]);
  254. smalltalk.send(self, "_should_return_", ["foo ^ 1 + 2 * 3", 9]);
  255. smalltalk.send(self, "_should_return_", ["foo ^ 1 to: 3", [1, 2, 3]]);
  256. smalltalk.send(self, "_should_return_", ["foo ^ 1 to: 5 by: 2", [1, 3, 5]]);
  257. return self;
  258. },
  259. args: [],
  260. 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)",
  261. messageSends: ["should:return:"],
  262. referencedClasses: []
  263. }),
  264. smalltalk.CodeGeneratorTest);
  265. smalltalk.addMethod(
  266. "_testNestedIfTrue",
  267. smalltalk.method({
  268. selector: "testNestedIfTrue",
  269. category: 'tests',
  270. fn: function () {
  271. var self = this;
  272. smalltalk.send(self, "_should_return_", ["foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]", 1]);
  273. smalltalk.send(self, "_should_return_", ["foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]", nil]);
  274. smalltalk.send(self, "_should_return_", ["foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]", 1]);
  275. smalltalk.send(self, "_should_return_", ["foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]", self['@receiver']]);
  276. return self;
  277. },
  278. args: [],
  279. 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.",
  280. messageSends: ["should:return:"],
  281. referencedClasses: []
  282. }),
  283. smalltalk.CodeGeneratorTest);
  284. smalltalk.addMethod(
  285. "_testNonLocalReturn",
  286. smalltalk.method({
  287. selector: "testNonLocalReturn",
  288. category: 'tests',
  289. fn: function () {
  290. var self = this;
  291. smalltalk.send(self, "_should_return_", ["foo [ ^ 1 ] value", 1]);
  292. smalltalk.send(self, "_should_return_", ["foo [ ^ 1 + 1 ] value", 2]);
  293. smalltalk.send(self, "_should_return_", ["foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt", 3]);
  294. smalltalk.send(self, "_should_return_", ["foo [ :x | ^ x + x ] value: 4. ^ 2", 8]);
  295. return self;
  296. },
  297. args: [],
  298. 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",
  299. messageSends: ["should:return:"],
  300. referencedClasses: []
  301. }),
  302. smalltalk.CodeGeneratorTest);
  303. smalltalk.addMethod(
  304. "_testSendReceiverAndArgumentsOrdered",
  305. smalltalk.method({
  306. selector: "testSendReceiverAndArgumentsOrdered",
  307. category: 'tests',
  308. fn: function (){
  309. var self=this;
  310. smalltalk.send(self,"_should_return_",["foo\x0a | x |\x0a x := 1.\x0a ^ Array with: x with: (true ifTrue: [ x := 2 ])\x0a",[(1), (2)]]);
  311. 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)]]);
  312. return self},
  313. args: [],
  314. 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",
  315. messageSends: ["should:return:"],
  316. referencedClasses: ["Array"]
  317. }),
  318. smalltalk.CodeGeneratorTest);
  319. smalltalk.addMethod(
  320. "_testifFalse",
  321. smalltalk.method({
  322. selector: "testifFalse",
  323. category: 'tests',
  324. fn: function () {
  325. var self = this;
  326. smalltalk.send(self, "_should_return_", ["foo true ifFalse: [ ^ 1 ]", self['@receiver']]);
  327. smalltalk.send(self, "_should_return_", ["foo false ifFalse: [ ^ 2 ]", 2]);
  328. smalltalk.send(self, "_should_return_", ["foo ^ true ifFalse: [ 1 ]", nil]);
  329. smalltalk.send(self, "_should_return_", ["foo ^ false ifFalse: [ 2 ]", 2]);
  330. return self;
  331. },
  332. args: [],
  333. 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.",
  334. messageSends: ["should:return:"],
  335. referencedClasses: []
  336. }),
  337. smalltalk.CodeGeneratorTest);
  338. smalltalk.addMethod(
  339. "_testifFalseIfTrue",
  340. smalltalk.method({
  341. selector: "testifFalseIfTrue",
  342. category: 'tests',
  343. fn: function () {
  344. var self = this;
  345. smalltalk.send(self, "_should_return_", ["foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]", 2]);
  346. smalltalk.send(self, "_should_return_", ["foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]", 2]);
  347. smalltalk.send(self, "_should_return_", ["foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]", 2]);
  348. smalltalk.send(self, "_should_return_", ["foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]", 2]);
  349. return self;
  350. },
  351. args: [],
  352. 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.",
  353. messageSends: ["should:return:"],
  354. referencedClasses: []
  355. }),
  356. smalltalk.CodeGeneratorTest);
  357. smalltalk.addMethod(
  358. "_testifNil",
  359. smalltalk.method({
  360. selector: "testifNil",
  361. category: 'tests',
  362. fn: function () {
  363. var self = this;
  364. smalltalk.send(self, "_should_return_", ["foo ^ 1 ifNil: [ 2 ]", 1]);
  365. smalltalk.send(self, "_should_return_", ["foo ^ nil ifNil: [ 2 ]", 2]);
  366. smalltalk.send(self, "_should_return_", ["foo 1 ifNil: [ ^ 2 ]", self['@receiver']]);
  367. smalltalk.send(self, "_should_return_", ["foo nil ifNil: [ ^ 2 ]", 2]);
  368. return self;
  369. },
  370. args: [],
  371. 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.",
  372. messageSends: ["should:return:"],
  373. referencedClasses: []
  374. }),
  375. smalltalk.CodeGeneratorTest);
  376. smalltalk.addMethod(
  377. "_testifNilIfNotNil",
  378. smalltalk.method({
  379. selector: "testifNilIfNotNil",
  380. category: 'tests',
  381. fn: function () {
  382. var self = this;
  383. smalltalk.send(self, "_should_return_", ["foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]", 3]);
  384. smalltalk.send(self, "_should_return_", ["foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]", 2]);
  385. smalltalk.send(self, "_should_return_", ["foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]", 3]);
  386. smalltalk.send(self, "_should_return_", ["foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]", 2]);
  387. return self;
  388. },
  389. args: [],
  390. 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.",
  391. messageSends: ["should:return:"],
  392. referencedClasses: []
  393. }),
  394. smalltalk.CodeGeneratorTest);
  395. smalltalk.addMethod(
  396. "_testifNotNil",
  397. smalltalk.method({
  398. selector: "testifNotNil",
  399. category: 'tests',
  400. fn: function () {
  401. var self = this;
  402. smalltalk.send(self, "_should_return_", ["foo ^ 1 ifNotNil: [ 2 ]", 2]);
  403. smalltalk.send(self, "_should_return_", ["foo ^ nil ifNotNil: [ 2 ]", nil]);
  404. smalltalk.send(self, "_should_return_", ["foo 1 ifNotNil: [ ^ 2 ]", 2]);
  405. smalltalk.send(self, "_should_return_", ["foo nil ifNotNil: [ ^ 2 ]", self['@receiver']]);
  406. return self;
  407. },
  408. args: [],
  409. 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.",
  410. messageSends: ["should:return:"],
  411. referencedClasses: []
  412. }),
  413. smalltalk.CodeGeneratorTest);
  414. smalltalk.addMethod(
  415. "_testifTrue",
  416. smalltalk.method({
  417. selector: "testifTrue",
  418. category: 'tests',
  419. fn: function () {
  420. var self = this;
  421. smalltalk.send(self, "_should_return_", ["foo false ifTrue: [ ^ 1 ]", self['@receiver']]);
  422. smalltalk.send(self, "_should_return_", ["foo true ifTrue: [ ^ 2 ]", 2]);
  423. smalltalk.send(self, "_should_return_", ["foo ^ false ifTrue: [ 1 ]", nil]);
  424. smalltalk.send(self, "_should_return_", ["foo ^ true ifTrue: [ 2 ]", 2]);
  425. return self;
  426. },
  427. args: [],
  428. 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.",
  429. messageSends: ["should:return:"],
  430. referencedClasses: []
  431. }),
  432. smalltalk.CodeGeneratorTest);
  433. smalltalk.addMethod(
  434. "_testifTrueIfFalse",
  435. smalltalk.method({
  436. selector: "testifTrueIfFalse",
  437. category: 'tests',
  438. fn: function () {
  439. var self = this;
  440. smalltalk.send(self, "_should_return_", ["foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]", 2]);
  441. smalltalk.send(self, "_should_return_", ["foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]", 1]);
  442. smalltalk.send(self, "_should_return_", ["foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]", 1]);
  443. smalltalk.send(self, "_should_return_", ["foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]", 2]);
  444. return self;
  445. },
  446. args: [],
  447. 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.",
  448. messageSends: ["should:return:"],
  449. referencedClasses: []
  450. }),
  451. smalltalk.CodeGeneratorTest);
  452. smalltalk.addClass('InliningCodeGeneratorTest', smalltalk.CodeGeneratorTest, [], 'Compiler-Tests');
  453. smalltalk.addMethod(
  454. "_codeGeneratorClass",
  455. smalltalk.method({
  456. selector: "codeGeneratorClass",
  457. category: 'accessing',
  458. fn: function () {
  459. var self = this;
  460. return smalltalk.InliningCodeGenerator || InliningCodeGenerator;
  461. },
  462. args: [],
  463. source: "codeGeneratorClass\x0a\x09^ InliningCodeGenerator",
  464. messageSends: [],
  465. referencedClasses: ["InliningCodeGenerator"]
  466. }),
  467. smalltalk.InliningCodeGeneratorTest);
  468. smalltalk.addClass('ScopeVarTest', smalltalk.TestCase, [], 'Compiler-Tests');
  469. smalltalk.addMethod(
  470. "_testClassRefVar",
  471. smalltalk.method({
  472. selector: "testClassRefVar",
  473. category: 'tests',
  474. fn: function () {
  475. var self = this;
  476. var $1, $2;
  477. var node;
  478. $1 = smalltalk.send(smalltalk.ClassReferenceNode || ClassReferenceNode, "_new", []);
  479. smalltalk.send($1, "_value_", ["Object"]);
  480. $2 = smalltalk.send($1, "_yourself", []);
  481. node = $2;
  482. smalltalk.send(smalltalk.send(smalltalk.SemanticAnalyzer || SemanticAnalyzer, "_new", []), "_visit_", [node]);
  483. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(node, "_binding", []), "_isClassRefVar", [])]);
  484. return self;
  485. },
  486. args: [],
  487. 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",
  488. messageSends: ["value:", "new", "yourself", "visit:", "assert:", "isClassRefVar", "binding"],
  489. referencedClasses: ["ClassReferenceNode", "SemanticAnalyzer"]
  490. }),
  491. smalltalk.ScopeVarTest);
  492. smalltalk.addMethod(
  493. "_testInstanceVar",
  494. smalltalk.method({
  495. selector: "testInstanceVar",
  496. category: 'tests',
  497. fn: function () {
  498. var self = this;
  499. var $1, $2;
  500. var node;
  501. var scope;
  502. $1 = smalltalk.send(smalltalk.VariableNode || VariableNode, "_new", []);
  503. smalltalk.send($1, "_value_", ["bzzz"]);
  504. $2 = smalltalk.send($1, "_yourself", []);
  505. node = $2;
  506. scope = smalltalk.send(smalltalk.MethodLexicalScope || MethodLexicalScope, "_new", []);
  507. smalltalk.send(scope, "_addIVar_", ["bzzz"]);
  508. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(scope, "_bindingFor_", [node]), "_isInstanceVar", [])]);
  509. return self;
  510. },
  511. args: [],
  512. 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",
  513. messageSends: ["value:", "new", "yourself", "addIVar:", "assert:", "isInstanceVar", "bindingFor:"],
  514. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  515. }),
  516. smalltalk.ScopeVarTest);
  517. smalltalk.addMethod(
  518. "_testPseudoVar",
  519. smalltalk.method({
  520. selector: "testPseudoVar",
  521. category: 'tests',
  522. fn: function () {
  523. var self = this;
  524. var $1, $2;
  525. var node;
  526. var pseudoVars;
  527. pseudoVars = ["self", "super", "true", "false", "nil"];
  528. 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", [])]);}]);
  529. return self;
  530. },
  531. args: [],
  532. 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 ]",
  533. messageSends: ["do:", "value:", "new", "yourself", "assert:", "isPseudoVar", "bindingFor:"],
  534. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  535. }),
  536. smalltalk.ScopeVarTest);
  537. smalltalk.addMethod(
  538. "_testTempVar",
  539. smalltalk.method({
  540. selector: "testTempVar",
  541. category: 'tests',
  542. fn: function () {
  543. var self = this;
  544. var $1, $2;
  545. var node;
  546. var scope;
  547. $1 = smalltalk.send(smalltalk.VariableNode || VariableNode, "_new", []);
  548. smalltalk.send($1, "_value_", ["bzzz"]);
  549. $2 = smalltalk.send($1, "_yourself", []);
  550. node = $2;
  551. scope = smalltalk.send(smalltalk.MethodLexicalScope || MethodLexicalScope, "_new", []);
  552. smalltalk.send(scope, "_addTemp_", ["bzzz"]);
  553. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(scope, "_bindingFor_", [node]), "_isTempVar", [])]);
  554. return self;
  555. },
  556. args: [],
  557. 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",
  558. messageSends: ["value:", "new", "yourself", "addTemp:", "assert:", "isTempVar", "bindingFor:"],
  559. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  560. }),
  561. smalltalk.ScopeVarTest);
  562. smalltalk.addMethod(
  563. "_testUnknownVar",
  564. smalltalk.method({
  565. selector: "testUnknownVar",
  566. category: 'tests',
  567. fn: function () {
  568. var self = this;
  569. var $1, $2;
  570. var node;
  571. $1 = smalltalk.send(smalltalk.VariableNode || VariableNode, "_new", []);
  572. smalltalk.send($1, "_value_", ["bzzz"]);
  573. $2 = smalltalk.send($1, "_yourself", []);
  574. node = $2;
  575. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.MethodLexicalScope || MethodLexicalScope, "_new", []), "_bindingFor_", [node]), "_isNil", [])]);
  576. return self;
  577. },
  578. args: [],
  579. source: "testUnknownVar\x0a\x09| node |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09self assert: (MethodLexicalScope new bindingFor: node) isNil",
  580. messageSends: ["value:", "new", "yourself", "assert:", "isNil", "bindingFor:"],
  581. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  582. }),
  583. smalltalk.ScopeVarTest);
  584. smalltalk.addClass('SemanticAnalyzerTest', smalltalk.TestCase, ['analyzer'], 'Compiler-Tests');
  585. smalltalk.addMethod(
  586. "_setUp",
  587. smalltalk.method({
  588. selector: "setUp",
  589. category: 'running',
  590. fn: function () {
  591. var self = this;
  592. self['@analyzer'] = smalltalk.send(smalltalk.SemanticAnalyzer || SemanticAnalyzer, "_on_", [smalltalk.Object || Object]);
  593. return self;
  594. },
  595. args: [],
  596. source: "setUp\x0a\x09analyzer := SemanticAnalyzer on: Object",
  597. messageSends: ["on:"],
  598. referencedClasses: ["Object", "SemanticAnalyzer"]
  599. }),
  600. smalltalk.SemanticAnalyzerTest);
  601. smalltalk.addMethod(
  602. "_testAssignment",
  603. smalltalk.method({
  604. selector: "testAssignment",
  605. category: 'tests',
  606. fn: function () {
  607. var self = this;
  608. var src;
  609. var ast;
  610. src = "foo self := 1";
  611. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  612. smalltalk.send(self, "_should_raise_", [function () {return smalltalk.send(self['@analyzer'], "_visit_", [ast]);}, smalltalk.InvalidAssignmentError || InvalidAssignmentError]);
  613. return self;
  614. },
  615. args: [],
  616. 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",
  617. messageSends: ["parse:", "should:raise:", "visit:"],
  618. referencedClasses: ["InvalidAssignmentError"]
  619. }),
  620. smalltalk.SemanticAnalyzerTest);
  621. smalltalk.addMethod(
  622. "_testNonLocalReturn",
  623. smalltalk.method({
  624. selector: "testNonLocalReturn",
  625. category: 'tests',
  626. fn: function () {
  627. var self = this;
  628. var src;
  629. var ast;
  630. src = "foo | a | a + 1. ^ a";
  631. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  632. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  633. smalltalk.send(self, "_deny_", [smalltalk.send(smalltalk.send(ast, "_scope", []), "_hasNonLocalReturn", [])]);
  634. return self;
  635. },
  636. args: [],
  637. 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",
  638. messageSends: ["parse:", "visit:", "deny:", "hasNonLocalReturn", "scope"],
  639. referencedClasses: []
  640. }),
  641. smalltalk.SemanticAnalyzerTest);
  642. smalltalk.addMethod(
  643. "_testNonLocalReturn2",
  644. smalltalk.method({
  645. selector: "testNonLocalReturn2",
  646. category: 'tests',
  647. fn: function () {
  648. var self = this;
  649. var src;
  650. var ast;
  651. src = "foo | a | a + 1. [\xA0[ ^ a]\xA0]";
  652. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  653. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  654. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(ast, "_scope", []), "_hasNonLocalReturn", [])]);
  655. return self;
  656. },
  657. args: [],
  658. 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",
  659. messageSends: ["parse:", "visit:", "assert:", "hasNonLocalReturn", "scope"],
  660. referencedClasses: []
  661. }),
  662. smalltalk.SemanticAnalyzerTest);
  663. smalltalk.addMethod(
  664. "_testScope",
  665. smalltalk.method({
  666. selector: "testScope",
  667. category: 'tests',
  668. fn: function () {
  669. var self = this;
  670. var src;
  671. var ast;
  672. src = "foo | a | a + 1. [ | b | b := a ]";
  673. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  674. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  675. 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", [])])]);
  676. return self;
  677. },
  678. args: [],
  679. 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.",
  680. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "last", "nodes", "first"],
  681. referencedClasses: []
  682. }),
  683. smalltalk.SemanticAnalyzerTest);
  684. smalltalk.addMethod(
  685. "_testScope2",
  686. smalltalk.method({
  687. selector: "testScope2",
  688. category: 'tests',
  689. fn: function () {
  690. var self = this;
  691. var src;
  692. var ast;
  693. src = "foo | a | a + 1. [ [ | b | b := a\xA0] ]";
  694. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  695. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  696. 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", [])])]);
  697. return self;
  698. },
  699. args: [],
  700. 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.",
  701. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "first", "nodes", "last"],
  702. referencedClasses: []
  703. }),
  704. smalltalk.SemanticAnalyzerTest);
  705. smalltalk.addMethod(
  706. "_testScopeLevel",
  707. smalltalk.method({
  708. selector: "testScopeLevel",
  709. category: 'tests',
  710. fn: function () {
  711. var self = this;
  712. var src;
  713. var ast;
  714. src = "foo | a | a + 1. [ [ | b | b := a\xA0] ]";
  715. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  716. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  717. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(smalltalk.send(ast, "_scope", []), "_scopeLevel", []), "__eq", [1])]);
  718. 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])]);
  719. return self;
  720. },
  721. args: [],
  722. 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",
  723. messageSends: ["parse:", "visit:", "assert:", "=", "scopeLevel", "scope", "first", "nodes", "last"],
  724. referencedClasses: []
  725. }),
  726. smalltalk.SemanticAnalyzerTest);
  727. smalltalk.addMethod(
  728. "_testUnknownVariables",
  729. smalltalk.method({
  730. selector: "testUnknownVariables",
  731. category: 'tests',
  732. fn: function () {
  733. var self = this;
  734. var src;
  735. var ast;
  736. src = "foo | a | b + a";
  737. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  738. smalltalk.send(self, "_should_raise_", [function () {return smalltalk.send(self['@analyzer'], "_visit_", [ast]);}, smalltalk.UnknownVariableError || UnknownVariableError]);
  739. return self;
  740. },
  741. args: [],
  742. 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",
  743. messageSends: ["parse:", "should:raise:", "visit:"],
  744. referencedClasses: ["UnknownVariableError"]
  745. }),
  746. smalltalk.SemanticAnalyzerTest);
  747. smalltalk.addMethod(
  748. "_testUnknownVariablesDefinedInJS",
  749. smalltalk.method({
  750. selector: "testUnknownVariablesDefinedInJS",
  751. category: 'tests',
  752. fn: function () {
  753. var self = this;
  754. var someVariable = 1;
  755. smalltalk.send(self, "_shouldnt_raise_", [function () {return smalltalk.send(smalltalk, "_parse_", ["foo someVariable"]);}, smalltalk.UnknownVariableError || UnknownVariableError]);
  756. return self;
  757. },
  758. args: [],
  759. source: "testUnknownVariablesDefinedInJS\x0a\x0a\x09< var someVariable = 1 >.\x0a\x0a\x09self shouldnt: [ smalltalk parse: 'foo someVariable' ] raise: UnknownVariableError",
  760. messageSends: ["shouldnt:raise:", "parse:"],
  761. referencedClasses: ["UnknownVariableError"]
  762. }),
  763. smalltalk.SemanticAnalyzerTest);
  764. smalltalk.addMethod(
  765. "_testUnknownVariablesWithScope",
  766. smalltalk.method({
  767. selector: "testUnknownVariablesWithScope",
  768. category: 'tests',
  769. fn: function () {
  770. var self = this;
  771. var src;
  772. var ast;
  773. src = "foo | a b | [ c + 1. [ a + 1. d + 1 ]]";
  774. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  775. smalltalk.send(self, "_should_raise_", [function () {return smalltalk.send(self['@analyzer'], "_visit_", [ast]);}, smalltalk.UnknownVariableError || UnknownVariableError]);
  776. return self;
  777. },
  778. args: [],
  779. 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",
  780. messageSends: ["parse:", "should:raise:", "visit:"],
  781. referencedClasses: ["UnknownVariableError"]
  782. }),
  783. smalltalk.SemanticAnalyzerTest);
  784. smalltalk.addMethod(
  785. "_testVariableShadowing",
  786. smalltalk.method({
  787. selector: "testVariableShadowing",
  788. category: 'tests',
  789. fn: function () {
  790. var self = this;
  791. var src;
  792. var ast;
  793. src = "foo | a | a + 1";
  794. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  795. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  796. return self;
  797. },
  798. args: [],
  799. source: "testVariableShadowing\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  800. messageSends: ["parse:", "visit:"],
  801. referencedClasses: []
  802. }),
  803. smalltalk.SemanticAnalyzerTest);
  804. smalltalk.addMethod(
  805. "_testVariableShadowing2",
  806. smalltalk.method({
  807. selector: "testVariableShadowing2",
  808. category: 'tests',
  809. fn: function () {
  810. var self = this;
  811. var src;
  812. var ast;
  813. src = "foo | a | a + 1. [ | a | a := 2 ]";
  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: "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",
  820. messageSends: ["parse:", "should:raise:", "visit:"],
  821. referencedClasses: ["ShadowingVariableError"]
  822. }),
  823. smalltalk.SemanticAnalyzerTest);
  824. smalltalk.addMethod(
  825. "_testVariableShadowing3",
  826. smalltalk.method({
  827. selector: "testVariableShadowing3",
  828. category: 'tests',
  829. fn: function () {
  830. var self = this;
  831. var src;
  832. var ast;
  833. src = "foo | a | a + 1. [ | b | b := 2 ]";
  834. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  835. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  836. return self;
  837. },
  838. args: [],
  839. source: "testVariableShadowing3\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | b | b := 2 ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  840. messageSends: ["parse:", "visit:"],
  841. referencedClasses: []
  842. }),
  843. smalltalk.SemanticAnalyzerTest);
  844. smalltalk.addMethod(
  845. "_testVariableShadowing4",
  846. smalltalk.method({
  847. selector: "testVariableShadowing4",
  848. category: 'tests',
  849. fn: function () {
  850. var self = this;
  851. var src;
  852. var ast;
  853. src = "foo | a | a + 1. [ [\xA0[ | b | b := 2 ]\xA0]\xA0]";
  854. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  855. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  856. return self;
  857. },
  858. args: [],
  859. source: "testVariableShadowing4\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  860. messageSends: ["parse:", "visit:"],
  861. referencedClasses: []
  862. }),
  863. smalltalk.SemanticAnalyzerTest);
  864. smalltalk.addMethod(
  865. "_testVariableShadowing5",
  866. smalltalk.method({
  867. selector: "testVariableShadowing5",
  868. category: 'tests',
  869. fn: function () {
  870. var self = this;
  871. var src;
  872. var ast;
  873. src = "foo | a | a + 1. [ [\xA0[ | a | a := 2 ]\xA0]\xA0]";
  874. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  875. smalltalk.send(self, "_should_raise_", [function () {return smalltalk.send(self['@analyzer'], "_visit_", [ast]);}, smalltalk.ShadowingVariableError || ShadowingVariableError]);
  876. return self;
  877. },
  878. args: [],
  879. 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",
  880. messageSends: ["parse:", "should:raise:", "visit:"],
  881. referencedClasses: ["ShadowingVariableError"]
  882. }),
  883. smalltalk.SemanticAnalyzerTest);
  884. smalltalk.addMethod(
  885. "_testVariablesLookup",
  886. smalltalk.method({
  887. selector: "testVariablesLookup",
  888. category: 'tests',
  889. fn: function () {
  890. var self = this;
  891. var src;
  892. var ast;
  893. src = "foo | a | a + 1. [ | b | b := a ]";
  894. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  895. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  896. 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", [])]);
  897. 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", [])])]);
  898. 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", [])]);
  899. 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", [])])]);
  900. return self;
  901. },
  902. args: [],
  903. 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.",
  904. messageSends: ["parse:", "visit:", "assert:", "isTempVar", "binding", "receiver", "first", "nodes", "==", "scope", "left", "last"],
  905. referencedClasses: []
  906. }),
  907. smalltalk.SemanticAnalyzerTest);