Compiler-Tests.deploy.js 32 KB

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