1
0

Compiler-Tests.deploy.js 31 KB

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