2
0

Compiler-Tests.js 40 KB

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