1
0

Compiler-Tests.deploy.js 24 KB

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