Compiler-Tests.deploy.js 21 KB

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