2
0

Compiler-Tests.deploy.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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. "_testLiterals",
  114. smalltalk.method({
  115. selector: "testLiterals",
  116. fn: function () {
  117. var self = this;
  118. smalltalk.send(self, "_should_return_", ["foo ^ 1", 1]);
  119. smalltalk.send(self, "_should_return_", ["foo ^ 'hello'", "hello"]);
  120. smalltalk.send(self, "_should_return_", ["foo ^ #(1 2 3 4)", [1, 2, 3, 4]]);
  121. smalltalk.send(self, "_should_return_", ["foo ^ {1. [:x | x ] value: 2. 3. [4] value}", [1, 2, 3, 4]]);
  122. smalltalk.send(self, "_should_return_", ["foo ^ true", true]);
  123. smalltalk.send(self, "_should_return_", ["foo ^ false", false]);
  124. 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])])]);
  125. smalltalk.send(self, "_should_return_", ["foo ^ #hello", smalltalk.symbolFor("hello")]);
  126. smalltalk.send(self, "_should_return_", ["foo ^ -123.456", -123.456]);
  127. return self;
  128. }
  129. }),
  130. smalltalk.CodeGeneratorTest);
  131. smalltalk.addMethod(
  132. "_testLocalReturn",
  133. smalltalk.method({
  134. selector: "testLocalReturn",
  135. fn: function () {
  136. var self = this;
  137. smalltalk.send(self, "_should_return_", ["foo ^ 1", 1]);
  138. smalltalk.send(self, "_should_return_", ["foo ^ 1 + 1", 2]);
  139. smalltalk.send(self, "_should_return_", ["foo ", self['@receiver']]);
  140. smalltalk.send(self, "_should_return_", ["foo self asString", self['@receiver']]);
  141. smalltalk.send(self, "_should_return_", ["foo | a b | a := 1. b := 2. ^ a + b", 3]);
  142. return self;
  143. }
  144. }),
  145. smalltalk.CodeGeneratorTest);
  146. smalltalk.addMethod(
  147. "_testMessageSends",
  148. smalltalk.method({
  149. selector: "testMessageSends",
  150. fn: function () {
  151. var self = this;
  152. smalltalk.send(self, "_should_return_", ["foo ^ 1 asString", "1"]);
  153. smalltalk.send(self, "_should_return_", ["foo ^ 1 + 1", 2]);
  154. smalltalk.send(self, "_should_return_", ["foo ^ 1 + 2 * 3", 9]);
  155. smalltalk.send(self, "_should_return_", ["foo ^ 1 to: 3", [1, 2, 3]]);
  156. smalltalk.send(self, "_should_return_", ["foo ^ 1 to: 5 by: 2", [1, 3, 5]]);
  157. return self;
  158. }
  159. }),
  160. smalltalk.CodeGeneratorTest);
  161. smalltalk.addMethod(
  162. "_testNestedIfTrue",
  163. smalltalk.method({
  164. selector: "testNestedIfTrue",
  165. fn: function () {
  166. var self = this;
  167. smalltalk.send(self, "_should_return_", ["foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]", 1]);
  168. smalltalk.send(self, "_should_return_", ["foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]", nil]);
  169. smalltalk.send(self, "_should_return_", ["foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]", 1]);
  170. smalltalk.send(self, "_should_return_", ["foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]", self['@receiver']]);
  171. return self;
  172. }
  173. }),
  174. smalltalk.CodeGeneratorTest);
  175. smalltalk.addMethod(
  176. "_testNonLocalReturn",
  177. smalltalk.method({
  178. selector: "testNonLocalReturn",
  179. fn: function () {
  180. var self = this;
  181. smalltalk.send(self, "_should_return_", ["foo [ ^ 1 ] value", 1]);
  182. smalltalk.send(self, "_should_return_", ["foo [ ^ 1 + 1 ] value", 2]);
  183. smalltalk.send(self, "_should_return_", ["foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt", 3]);
  184. smalltalk.send(self, "_should_return_", ["foo [ :x | ^ x + x ] value: 4. ^ 2", 8]);
  185. return self;
  186. }
  187. }),
  188. smalltalk.CodeGeneratorTest);
  189. smalltalk.addMethod(
  190. "_testifFalse",
  191. smalltalk.method({
  192. selector: "testifFalse",
  193. fn: function () {
  194. var self = this;
  195. smalltalk.send(self, "_should_return_", ["foo true ifFalse: [ ^ 1 ]", self['@receiver']]);
  196. smalltalk.send(self, "_should_return_", ["foo false ifFalse: [ ^ 2 ]", 2]);
  197. smalltalk.send(self, "_should_return_", ["foo ^ true ifFalse: [ 1 ]", nil]);
  198. smalltalk.send(self, "_should_return_", ["foo ^ false ifFalse: [ 2 ]", 2]);
  199. return self;
  200. }
  201. }),
  202. smalltalk.CodeGeneratorTest);
  203. smalltalk.addMethod(
  204. "_testifFalseIfTrue",
  205. smalltalk.method({
  206. selector: "testifFalseIfTrue",
  207. fn: function () {
  208. var self = this;
  209. smalltalk.send(self, "_should_return_", ["foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]", 2]);
  210. smalltalk.send(self, "_should_return_", ["foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]", 2]);
  211. smalltalk.send(self, "_should_return_", ["foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]", 2]);
  212. smalltalk.send(self, "_should_return_", ["foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]", 2]);
  213. return self;
  214. }
  215. }),
  216. smalltalk.CodeGeneratorTest);
  217. smalltalk.addMethod(
  218. "_testifNil",
  219. smalltalk.method({
  220. selector: "testifNil",
  221. fn: function () {
  222. var self = this;
  223. smalltalk.send(self, "_should_return_", ["foo ^ 1 ifNil: [ 2 ]", 1]);
  224. smalltalk.send(self, "_should_return_", ["foo ^ nil ifNil: [ 2 ]", 2]);
  225. smalltalk.send(self, "_should_return_", ["foo 1 ifNil: [ ^ 2 ]", self['@receiver']]);
  226. smalltalk.send(self, "_should_return_", ["foo nil ifNil: [ ^ 2 ]", 2]);
  227. return self;
  228. }
  229. }),
  230. smalltalk.CodeGeneratorTest);
  231. smalltalk.addMethod(
  232. "_testifNilIfNotNil",
  233. smalltalk.method({
  234. selector: "testifNilIfNotNil",
  235. fn: function () {
  236. var self = this;
  237. smalltalk.send(self, "_should_return_", ["foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]", 3]);
  238. smalltalk.send(self, "_should_return_", ["foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]", 2]);
  239. smalltalk.send(self, "_should_return_", ["foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]", 3]);
  240. smalltalk.send(self, "_should_return_", ["foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]", 2]);
  241. return self;
  242. }
  243. }),
  244. smalltalk.CodeGeneratorTest);
  245. smalltalk.addMethod(
  246. "_testifNotNil",
  247. smalltalk.method({
  248. selector: "testifNotNil",
  249. fn: function () {
  250. var self = this;
  251. smalltalk.send(self, "_should_return_", ["foo ^ 1 ifNotNil: [ 2 ]", 2]);
  252. smalltalk.send(self, "_should_return_", ["foo ^ nil ifNotNil: [ 2 ]", nil]);
  253. smalltalk.send(self, "_should_return_", ["foo 1 ifNotNil: [ ^ 2 ]", 2]);
  254. smalltalk.send(self, "_should_return_", ["foo nil ifNotNil: [ ^ 2 ]", self['@receiver']]);
  255. return self;
  256. }
  257. }),
  258. smalltalk.CodeGeneratorTest);
  259. smalltalk.addMethod(
  260. "_testifTrue",
  261. smalltalk.method({
  262. selector: "testifTrue",
  263. fn: function () {
  264. var self = this;
  265. smalltalk.send(self, "_should_return_", ["foo false ifTrue: [ ^ 1 ]", self['@receiver']]);
  266. smalltalk.send(self, "_should_return_", ["foo true ifTrue: [ ^ 2 ]", 2]);
  267. smalltalk.send(self, "_should_return_", ["foo ^ false ifTrue: [ 1 ]", nil]);
  268. smalltalk.send(self, "_should_return_", ["foo ^ true ifTrue: [ 2 ]", 2]);
  269. return self;
  270. }
  271. }),
  272. smalltalk.CodeGeneratorTest);
  273. smalltalk.addMethod(
  274. "_testifTrueIfFalse",
  275. smalltalk.method({
  276. selector: "testifTrueIfFalse",
  277. fn: function () {
  278. var self = this;
  279. smalltalk.send(self, "_should_return_", ["foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]", 2]);
  280. smalltalk.send(self, "_should_return_", ["foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]", 1]);
  281. smalltalk.send(self, "_should_return_", ["foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]", 1]);
  282. smalltalk.send(self, "_should_return_", ["foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]", 2]);
  283. return self;
  284. }
  285. }),
  286. smalltalk.CodeGeneratorTest);
  287. smalltalk.addClass('InliningCodeGeneratorTest', smalltalk.CodeGeneratorTest, [], 'Compiler-Tests');
  288. smalltalk.addMethod(
  289. "_codeGeneratorClass",
  290. smalltalk.method({
  291. selector: "codeGeneratorClass",
  292. fn: function () {
  293. var self = this;
  294. return smalltalk.InliningCodeGenerator || InliningCodeGenerator;
  295. }
  296. }),
  297. smalltalk.InliningCodeGeneratorTest);
  298. smalltalk.addClass('ScopeVarTest', smalltalk.TestCase, [], 'Compiler-Tests');
  299. smalltalk.addMethod(
  300. "_testClassRefVar",
  301. smalltalk.method({
  302. selector: "testClassRefVar",
  303. fn: function () {
  304. var self = this;
  305. var $1, $2;
  306. var node;
  307. $1 = smalltalk.send(smalltalk.ClassReferenceNode || ClassReferenceNode, "_new", []);
  308. smalltalk.send($1, "_value_", ["Object"]);
  309. $2 = smalltalk.send($1, "_yourself", []);
  310. node = $2;
  311. smalltalk.send(smalltalk.send(smalltalk.SemanticAnalyzer || SemanticAnalyzer, "_new", []), "_visit_", [node]);
  312. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(node, "_binding", []), "_isClassRefVar", [])]);
  313. return self;
  314. }
  315. }),
  316. smalltalk.ScopeVarTest);
  317. smalltalk.addMethod(
  318. "_testInstanceVar",
  319. smalltalk.method({
  320. selector: "testInstanceVar",
  321. fn: function () {
  322. var self = this;
  323. var $1, $2;
  324. var node;
  325. var scope;
  326. $1 = smalltalk.send(smalltalk.VariableNode || VariableNode, "_new", []);
  327. smalltalk.send($1, "_value_", ["bzzz"]);
  328. $2 = smalltalk.send($1, "_yourself", []);
  329. node = $2;
  330. scope = smalltalk.send(smalltalk.MethodLexicalScope || MethodLexicalScope, "_new", []);
  331. smalltalk.send(scope, "_addIVar_", ["bzzz"]);
  332. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(scope, "_bindingFor_", [node]), "_isInstanceVar", [])]);
  333. return self;
  334. }
  335. }),
  336. smalltalk.ScopeVarTest);
  337. smalltalk.addMethod(
  338. "_testPseudoVar",
  339. smalltalk.method({
  340. selector: "testPseudoVar",
  341. fn: function () {
  342. var self = this;
  343. var $1, $2;
  344. var node;
  345. var pseudoVars;
  346. pseudoVars = ["self", "super", "true", "false", "nil"];
  347. 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", [])]);}]);
  348. return self;
  349. }
  350. }),
  351. smalltalk.ScopeVarTest);
  352. smalltalk.addMethod(
  353. "_testTempVar",
  354. smalltalk.method({
  355. selector: "testTempVar",
  356. fn: function () {
  357. var self = this;
  358. var $1, $2;
  359. var node;
  360. var scope;
  361. $1 = smalltalk.send(smalltalk.VariableNode || VariableNode, "_new", []);
  362. smalltalk.send($1, "_value_", ["bzzz"]);
  363. $2 = smalltalk.send($1, "_yourself", []);
  364. node = $2;
  365. scope = smalltalk.send(smalltalk.MethodLexicalScope || MethodLexicalScope, "_new", []);
  366. smalltalk.send(scope, "_addTemp_", ["bzzz"]);
  367. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(scope, "_bindingFor_", [node]), "_isTempVar", [])]);
  368. return self;
  369. }
  370. }),
  371. smalltalk.ScopeVarTest);
  372. smalltalk.addMethod(
  373. "_testUnknownVar",
  374. smalltalk.method({
  375. selector: "testUnknownVar",
  376. fn: function () {
  377. var self = this;
  378. var $1, $2;
  379. var node;
  380. $1 = smalltalk.send(smalltalk.VariableNode || VariableNode, "_new", []);
  381. smalltalk.send($1, "_value_", ["bzzz"]);
  382. $2 = smalltalk.send($1, "_yourself", []);
  383. node = $2;
  384. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.MethodLexicalScope || MethodLexicalScope, "_new", []), "_bindingFor_", [node]), "_isNil", [])]);
  385. return self;
  386. }
  387. }),
  388. smalltalk.ScopeVarTest);
  389. smalltalk.addClass('SemanticAnalyzerTest', smalltalk.TestCase, ['analyzer'], 'Compiler-Tests');
  390. smalltalk.addMethod(
  391. "_setUp",
  392. smalltalk.method({
  393. selector: "setUp",
  394. fn: function () {
  395. var self = this;
  396. self['@analyzer'] = smalltalk.send(smalltalk.SemanticAnalyzer || SemanticAnalyzer, "_on_", [smalltalk.Object || Object]);
  397. return self;
  398. }
  399. }),
  400. smalltalk.SemanticAnalyzerTest);
  401. smalltalk.addMethod(
  402. "_testAssignment",
  403. smalltalk.method({
  404. selector: "testAssignment",
  405. fn: function () {
  406. var self = this;
  407. var src;
  408. var ast;
  409. src = "foo self := 1";
  410. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  411. smalltalk.send(self, "_should_raise_", [function () {return smalltalk.send(self['@analyzer'], "_visit_", [ast]);}, smalltalk.InvalidAssignmentError || InvalidAssignmentError]);
  412. return self;
  413. }
  414. }),
  415. smalltalk.SemanticAnalyzerTest);
  416. smalltalk.addMethod(
  417. "_testNonLocalReturn",
  418. smalltalk.method({
  419. selector: "testNonLocalReturn",
  420. fn: function () {
  421. var self = this;
  422. var src;
  423. var ast;
  424. src = "foo | a | a + 1. ^ a";
  425. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  426. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  427. smalltalk.send(self, "_deny_", [smalltalk.send(smalltalk.send(ast, "_scope", []), "_hasNonLocalReturn", [])]);
  428. return self;
  429. }
  430. }),
  431. smalltalk.SemanticAnalyzerTest);
  432. smalltalk.addMethod(
  433. "_testNonLocalReturn2",
  434. smalltalk.method({
  435. selector: "testNonLocalReturn2",
  436. fn: function () {
  437. var self = this;
  438. var src;
  439. var ast;
  440. src = "foo | a | a + 1. [\xA0[ ^ a]\xA0]";
  441. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  442. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  443. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(ast, "_scope", []), "_hasNonLocalReturn", [])]);
  444. return self;
  445. }
  446. }),
  447. smalltalk.SemanticAnalyzerTest);
  448. smalltalk.addMethod(
  449. "_testScope",
  450. smalltalk.method({
  451. selector: "testScope",
  452. fn: function () {
  453. var self = this;
  454. var src;
  455. var ast;
  456. src = "foo | a | a + 1. [ | b | b := a ]";
  457. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  458. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  459. 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", [])])]);
  460. return self;
  461. }
  462. }),
  463. smalltalk.SemanticAnalyzerTest);
  464. smalltalk.addMethod(
  465. "_testScope2",
  466. smalltalk.method({
  467. selector: "testScope2",
  468. fn: function () {
  469. var self = this;
  470. var src;
  471. var ast;
  472. src = "foo | a | a + 1. [ [ | b | b := a\xA0] ]";
  473. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  474. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  475. 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", [])])]);
  476. return self;
  477. }
  478. }),
  479. smalltalk.SemanticAnalyzerTest);
  480. smalltalk.addMethod(
  481. "_testScopeLevel",
  482. smalltalk.method({
  483. selector: "testScopeLevel",
  484. fn: function () {
  485. var self = this;
  486. var src;
  487. var ast;
  488. src = "foo | a | a + 1. [ [ | b | b := a\xA0] ]";
  489. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  490. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  491. smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(smalltalk.send(ast, "_scope", []), "_scopeLevel", []), "__eq", [1])]);
  492. 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])]);
  493. return self;
  494. }
  495. }),
  496. smalltalk.SemanticAnalyzerTest);
  497. smalltalk.addMethod(
  498. "_testUnknownVariables",
  499. smalltalk.method({
  500. selector: "testUnknownVariables",
  501. fn: function () {
  502. var self = this;
  503. var src;
  504. var ast;
  505. src = "foo | a | b + a";
  506. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  507. smalltalk.send(self, "_should_raise_", [function () {return smalltalk.send(self['@analyzer'], "_visit_", [ast]);}, smalltalk.UnknownVariableError || UnknownVariableError]);
  508. return self;
  509. }
  510. }),
  511. smalltalk.SemanticAnalyzerTest);
  512. smalltalk.addMethod(
  513. "_testUnknownVariablesDefinedInJS",
  514. smalltalk.method({
  515. selector: "testUnknownVariablesDefinedInJS",
  516. fn: function () {
  517. var self = this;
  518. var someVariable = 1;
  519. smalltalk.send(self, "_shouldnt_raise_", [function () {return smalltalk.send(smalltalk, "_parse_", ["foo someVariable"]);}, smalltalk.UnknownVariableError || UnknownVariableError]);
  520. return self;
  521. }
  522. }),
  523. smalltalk.SemanticAnalyzerTest);
  524. smalltalk.addMethod(
  525. "_testUnknownVariablesWithScope",
  526. smalltalk.method({
  527. selector: "testUnknownVariablesWithScope",
  528. fn: function () {
  529. var self = this;
  530. var src;
  531. var ast;
  532. src = "foo | a b | [ c + 1. [ a + 1. d + 1 ]]";
  533. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  534. smalltalk.send(self, "_should_raise_", [function () {return smalltalk.send(self['@analyzer'], "_visit_", [ast]);}, smalltalk.UnknownVariableError || UnknownVariableError]);
  535. return self;
  536. }
  537. }),
  538. smalltalk.SemanticAnalyzerTest);
  539. smalltalk.addMethod(
  540. "_testVariableShadowing",
  541. smalltalk.method({
  542. selector: "testVariableShadowing",
  543. fn: function () {
  544. var self = this;
  545. var src;
  546. var ast;
  547. src = "foo | a | a + 1";
  548. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  549. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  550. return self;
  551. }
  552. }),
  553. smalltalk.SemanticAnalyzerTest);
  554. smalltalk.addMethod(
  555. "_testVariableShadowing2",
  556. smalltalk.method({
  557. selector: "testVariableShadowing2",
  558. fn: function () {
  559. var self = this;
  560. var src;
  561. var ast;
  562. src = "foo | a | a + 1. [ | a | a := 2 ]";
  563. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  564. smalltalk.send(self, "_should_raise_", [function () {return smalltalk.send(self['@analyzer'], "_visit_", [ast]);}, smalltalk.ShadowingVariableError || ShadowingVariableError]);
  565. return self;
  566. }
  567. }),
  568. smalltalk.SemanticAnalyzerTest);
  569. smalltalk.addMethod(
  570. "_testVariableShadowing3",
  571. smalltalk.method({
  572. selector: "testVariableShadowing3",
  573. fn: function () {
  574. var self = this;
  575. var src;
  576. var ast;
  577. src = "foo | a | a + 1. [ | b | b := 2 ]";
  578. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  579. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  580. return self;
  581. }
  582. }),
  583. smalltalk.SemanticAnalyzerTest);
  584. smalltalk.addMethod(
  585. "_testVariableShadowing4",
  586. smalltalk.method({
  587. selector: "testVariableShadowing4",
  588. fn: function () {
  589. var self = this;
  590. var src;
  591. var ast;
  592. src = "foo | a | a + 1. [ [\xA0[ | b | b := 2 ]\xA0]\xA0]";
  593. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  594. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  595. return self;
  596. }
  597. }),
  598. smalltalk.SemanticAnalyzerTest);
  599. smalltalk.addMethod(
  600. "_testVariableShadowing5",
  601. smalltalk.method({
  602. selector: "testVariableShadowing5",
  603. fn: function () {
  604. var self = this;
  605. var src;
  606. var ast;
  607. src = "foo | a | a + 1. [ [\xA0[ | a | a := 2 ]\xA0]\xA0]";
  608. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  609. smalltalk.send(self, "_should_raise_", [function () {return smalltalk.send(self['@analyzer'], "_visit_", [ast]);}, smalltalk.ShadowingVariableError || ShadowingVariableError]);
  610. return self;
  611. }
  612. }),
  613. smalltalk.SemanticAnalyzerTest);
  614. smalltalk.addMethod(
  615. "_testVariablesLookup",
  616. smalltalk.method({
  617. selector: "testVariablesLookup",
  618. fn: function () {
  619. var self = this;
  620. var src;
  621. var ast;
  622. src = "foo | a | a + 1. [ | b | b := a ]";
  623. ast = smalltalk.send(smalltalk, "_parse_", [src]);
  624. smalltalk.send(self['@analyzer'], "_visit_", [ast]);
  625. 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", [])]);
  626. 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", [])])]);
  627. 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", [])]);
  628. 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", [])])]);
  629. return self;
  630. }
  631. }),
  632. smalltalk.SemanticAnalyzerTest);