Compiler-Tests.deploy.js 23 KB

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