1
0

Compiler-Tests.deploy.js 30 KB

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