Compiler-Tests.deploy.js 21 KB

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