Compiler-Tests.deploy.js 19 KB

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