Compiler-Tests.deploy.js 27 KB

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