Compiler-Tests.deploy.js 25 KB

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