Compiler-Tests.deploy.js 22 KB

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