Compiler-Tests.js 36 KB

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