Compiler-Tests.js 42 KB

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