Compiler-Tests.deploy.js 25 KB

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