1
0

Compiler-Tests.deploy.js 29 KB

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