Compiler-Tests.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  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.CodeGenerator || CodeGenerator);
  11. },
  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. var $2,$3,$1;
  26. $2=smalltalk.send((smalltalk.Compiler || Compiler),"_new",[]);
  27. smalltalk.send($2,"_codeGeneratorClass_",[smalltalk.send(self,"_codeGeneratorClass",[])]);
  28. $3=smalltalk.send($2,"_yourself",[]);
  29. $1=$3;
  30. return $1;
  31. },
  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. self["@receiver"]=smalltalk.send(smalltalk.send(self,"_targetClass",[]),"_new",[]);
  46. return self},
  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. var method;
  61. var result;
  62. method=smalltalk.send(smalltalk.send(self,"_compiler",[]),"_install_forClass_category_",[aString,smalltalk.send(self,"_targetClass",[]),"tests"]);
  63. result=smalltalk.send(self["@receiver"],"_perform_",[smalltalk.send(method,"_selector",[])]);
  64. smalltalk.send(smalltalk.send(self,"_targetClass",[]),"_removeCompiledMethod_",[method]);
  65. smalltalk.send(self,"_assert_equals_",[anObject,result]);
  66. return self},
  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.DoIt || DoIt);
  81. },
  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 self},
  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. smalltalk.send(self,"_should_return_",["foo | a | a := true ifTrue: [ 1 ]. ^ a",(1)]);
  110. smalltalk.send(self,"_should_return_",["foo | a | a := false ifTrue: [ 1 ]. ^ a",nil]);
  111. smalltalk.send(self,"_should_return_",["foo | a | ^ a := true ifTrue: [ 1 ]",(1)]);
  112. return self},
  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. smalltalk.send(self,"_should_return_",["foo ^ #(1 2 3) collect: [ :each | true ifTrue: [ each + 1 ] ]",[(2), (3), (4)]]);
  127. smalltalk.send(self,"_should_return_",["foo ^ #(1 2 3) collect: [ :each | false ifFalse: [ each + 1 ] ]",[(2), (3), (4)]]);
  128. smalltalk.send(self,"_should_return_",["foo ^ #(1 2 3) collect: [ :each | each odd ifTrue: [ each + 1 ] ifFalse: [ each - 1 ] ]",[(2), (1), (4)]]);
  129. return self},
  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. smalltalk.send(self,"_should_return_",["foo ^ Array new add: 3; add: 4; yourself",[(3), (4)]]);
  144. return self},
  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. smalltalk.send(self,"_should_return_",["foo ^ 1",(1)]);
  159. smalltalk.send(self,"_should_return_",["foo ^ 'hello'","hello"]);
  160. smalltalk.send(self,"_should_return_",["foo ^ #(1 2 3 4)",[(1), (2), (3), (4)]]);
  161. smalltalk.send(self,"_should_return_",["foo ^ {1. [:x | x ] value: 2. 3. [4] value}",[(1), (2), (3), (4)]]);
  162. smalltalk.send(self,"_should_return_",["foo ^ true",true]);
  163. smalltalk.send(self,"_should_return_",["foo ^ false",false]);
  164. smalltalk.send(self,"_should_return_",["foo ^ #{1->2. 3->4}",smalltalk.HashedCollection._fromPairs_([smalltalk.send((1),"__minus_gt",[(2)]),smalltalk.send((3),"__minus_gt",[(4)])])]);
  165. smalltalk.send(self,"_should_return_",["foo ^ #hello",smalltalk.symbolFor("hello")]);
  166. smalltalk.send(self,"_should_return_",["foo ^ -123.456",(-123.456)]);
  167. return self},
  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. smalltalk.send(self,"_should_return_",["foo ^ 1",(1)]);
  182. smalltalk.send(self,"_should_return_",["foo ^ 1 + 1",(2)]);
  183. smalltalk.send(self,"_should_return_",["foo ",self["@receiver"]]);
  184. smalltalk.send(self,"_should_return_",["foo self asString",self["@receiver"]]);
  185. smalltalk.send(self,"_should_return_",["foo | a b | a := 1. b := 2. ^ a + b",(3)]);
  186. return self},
  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. smalltalk.send(self,"_should_return_",["foo ^ 1 asString","1"]);
  201. smalltalk.send(self,"_should_return_",["foo ^ 1 + 1",(2)]);
  202. smalltalk.send(self,"_should_return_",["foo ^ 1 + 2 * 3",(9)]);
  203. smalltalk.send(self,"_should_return_",["foo ^ 1 to: 3",[(1), (2), (3)]]);
  204. smalltalk.send(self,"_should_return_",["foo ^ 1 to: 5 by: 2",[(1), (3), (5)]]);
  205. return self},
  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. smalltalk.send(self,"_should_return_",["foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]",(1)]);
  220. smalltalk.send(self,"_should_return_",["foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]",nil]);
  221. smalltalk.send(self,"_should_return_",["foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]",(1)]);
  222. smalltalk.send(self,"_should_return_",["foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]",self["@receiver"]]);
  223. return self},
  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. smalltalk.send(self,"_should_return_",["foo [ ^ 1 ] value",(1)]);
  238. smalltalk.send(self,"_should_return_",["foo [ ^ 1 + 1 ] value",(2)]);
  239. smalltalk.send(self,"_should_return_",["foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt",(3)]);
  240. smalltalk.send(self,"_should_return_",["foo [ :x | ^ x + x ] value: 4. ^ 2",(8)]);
  241. return self},
  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. "_testifFalse",
  250. smalltalk.method({
  251. selector: "testifFalse",
  252. category: 'tests',
  253. fn: function (){
  254. var self=this;
  255. smalltalk.send(self,"_should_return_",["foo true ifFalse: [ ^ 1 ]",self["@receiver"]]);
  256. smalltalk.send(self,"_should_return_",["foo false ifFalse: [ ^ 2 ]",(2)]);
  257. smalltalk.send(self,"_should_return_",["foo ^ true ifFalse: [ 1 ]",nil]);
  258. smalltalk.send(self,"_should_return_",["foo ^ false ifFalse: [ 2 ]",(2)]);
  259. return self},
  260. args: [],
  261. 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.",
  262. messageSends: ["should:return:"],
  263. referencedClasses: []
  264. }),
  265. smalltalk.CodeGeneratorTest);
  266. smalltalk.addMethod(
  267. "_testifFalseIfTrue",
  268. smalltalk.method({
  269. selector: "testifFalseIfTrue",
  270. category: 'tests',
  271. fn: function (){
  272. var self=this;
  273. smalltalk.send(self,"_should_return_",["foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]",(2)]);
  274. smalltalk.send(self,"_should_return_",["foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]",(2)]);
  275. smalltalk.send(self,"_should_return_",["foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]",(2)]);
  276. smalltalk.send(self,"_should_return_",["foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]",(2)]);
  277. return self},
  278. args: [],
  279. 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.",
  280. messageSends: ["should:return:"],
  281. referencedClasses: []
  282. }),
  283. smalltalk.CodeGeneratorTest);
  284. smalltalk.addMethod(
  285. "_testifNil",
  286. smalltalk.method({
  287. selector: "testifNil",
  288. category: 'tests',
  289. fn: function (){
  290. var self=this;
  291. smalltalk.send(self,"_should_return_",["foo ^ 1 ifNil: [ 2 ]",(1)]);
  292. smalltalk.send(self,"_should_return_",["foo ^ nil ifNil: [ 2 ]",(2)]);
  293. smalltalk.send(self,"_should_return_",["foo 1 ifNil: [ ^ 2 ]",self["@receiver"]]);
  294. smalltalk.send(self,"_should_return_",["foo nil ifNil: [ ^ 2 ]",(2)]);
  295. return self},
  296. args: [],
  297. 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.",
  298. messageSends: ["should:return:"],
  299. referencedClasses: []
  300. }),
  301. smalltalk.CodeGeneratorTest);
  302. smalltalk.addMethod(
  303. "_testifNilIfNotNil",
  304. smalltalk.method({
  305. selector: "testifNilIfNotNil",
  306. category: 'tests',
  307. fn: function (){
  308. var self=this;
  309. smalltalk.send(self,"_should_return_",["foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]",(3)]);
  310. smalltalk.send(self,"_should_return_",["foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]",(2)]);
  311. smalltalk.send(self,"_should_return_",["foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(3)]);
  312. smalltalk.send(self,"_should_return_",["foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(2)]);
  313. return self},
  314. args: [],
  315. 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.",
  316. messageSends: ["should:return:"],
  317. referencedClasses: []
  318. }),
  319. smalltalk.CodeGeneratorTest);
  320. smalltalk.addMethod(
  321. "_testifNotNil",
  322. smalltalk.method({
  323. selector: "testifNotNil",
  324. category: 'tests',
  325. fn: function (){
  326. var self=this;
  327. smalltalk.send(self,"_should_return_",["foo ^ 1 ifNotNil: [ 2 ]",(2)]);
  328. smalltalk.send(self,"_should_return_",["foo ^ nil ifNotNil: [ 2 ]",nil]);
  329. smalltalk.send(self,"_should_return_",["foo 1 ifNotNil: [ ^ 2 ]",(2)]);
  330. smalltalk.send(self,"_should_return_",["foo nil ifNotNil: [ ^ 2 ]",self["@receiver"]]);
  331. return self},
  332. args: [],
  333. 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.",
  334. messageSends: ["should:return:"],
  335. referencedClasses: []
  336. }),
  337. smalltalk.CodeGeneratorTest);
  338. smalltalk.addMethod(
  339. "_testifTrue",
  340. smalltalk.method({
  341. selector: "testifTrue",
  342. category: 'tests',
  343. fn: function (){
  344. var self=this;
  345. smalltalk.send(self,"_should_return_",["foo false ifTrue: [ ^ 1 ]",self["@receiver"]]);
  346. smalltalk.send(self,"_should_return_",["foo true ifTrue: [ ^ 2 ]",(2)]);
  347. smalltalk.send(self,"_should_return_",["foo ^ false ifTrue: [ 1 ]",nil]);
  348. smalltalk.send(self,"_should_return_",["foo ^ true ifTrue: [ 2 ]",(2)]);
  349. return self},
  350. args: [],
  351. 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.",
  352. messageSends: ["should:return:"],
  353. referencedClasses: []
  354. }),
  355. smalltalk.CodeGeneratorTest);
  356. smalltalk.addMethod(
  357. "_testifTrueIfFalse",
  358. smalltalk.method({
  359. selector: "testifTrueIfFalse",
  360. category: 'tests',
  361. fn: function (){
  362. var self=this;
  363. smalltalk.send(self,"_should_return_",["foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]",(2)]);
  364. smalltalk.send(self,"_should_return_",["foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]",(1)]);
  365. smalltalk.send(self,"_should_return_",["foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]",(1)]);
  366. smalltalk.send(self,"_should_return_",["foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]",(2)]);
  367. return self},
  368. args: [],
  369. 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.",
  370. messageSends: ["should:return:"],
  371. referencedClasses: []
  372. }),
  373. smalltalk.CodeGeneratorTest);
  374. smalltalk.addClass('InliningCodeGeneratorTest', smalltalk.CodeGeneratorTest, [], 'Compiler-Tests');
  375. smalltalk.addMethod(
  376. "_codeGeneratorClass",
  377. smalltalk.method({
  378. selector: "codeGeneratorClass",
  379. category: 'accessing',
  380. fn: function (){
  381. var self=this;
  382. return (smalltalk.InliningCodeGenerator || InliningCodeGenerator);
  383. },
  384. args: [],
  385. source: "codeGeneratorClass\x0a\x09^ InliningCodeGenerator",
  386. messageSends: [],
  387. referencedClasses: ["InliningCodeGenerator"]
  388. }),
  389. smalltalk.InliningCodeGeneratorTest);
  390. smalltalk.addClass('ScopeVarTest', smalltalk.TestCase, [], 'Compiler-Tests');
  391. smalltalk.addMethod(
  392. "_testClassRefVar",
  393. smalltalk.method({
  394. selector: "testClassRefVar",
  395. category: 'tests',
  396. fn: function (){
  397. var self=this;
  398. var $1,$2;
  399. var node;
  400. $1=smalltalk.send((smalltalk.ClassReferenceNode || ClassReferenceNode),"_new",[]);
  401. smalltalk.send($1,"_value_",["Object"]);
  402. $2=smalltalk.send($1,"_yourself",[]);
  403. node=$2;
  404. smalltalk.send(smalltalk.send((smalltalk.SemanticAnalyzer || SemanticAnalyzer),"_new",[]),"_visit_",[node]);
  405. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(node,"_binding",[]),"_isClassRefVar",[])]);
  406. return self},
  407. args: [],
  408. 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",
  409. messageSends: ["value:", "new", "yourself", "visit:", "assert:", "isClassRefVar", "binding"],
  410. referencedClasses: ["ClassReferenceNode", "SemanticAnalyzer"]
  411. }),
  412. smalltalk.ScopeVarTest);
  413. smalltalk.addMethod(
  414. "_testInstanceVar",
  415. smalltalk.method({
  416. selector: "testInstanceVar",
  417. category: 'tests',
  418. fn: function (){
  419. var self=this;
  420. var $1,$2;
  421. var node;
  422. var scope;
  423. $1=smalltalk.send((smalltalk.VariableNode || VariableNode),"_new",[]);
  424. smalltalk.send($1,"_value_",["bzzz"]);
  425. $2=smalltalk.send($1,"_yourself",[]);
  426. node=$2;
  427. scope=smalltalk.send((smalltalk.MethodLexicalScope || MethodLexicalScope),"_new",[]);
  428. smalltalk.send(scope,"_addIVar_",["bzzz"]);
  429. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(scope,"_bindingFor_",[node]),"_isInstanceVar",[])]);
  430. return self},
  431. args: [],
  432. 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",
  433. messageSends: ["value:", "new", "yourself", "addIVar:", "assert:", "isInstanceVar", "bindingFor:"],
  434. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  435. }),
  436. smalltalk.ScopeVarTest);
  437. smalltalk.addMethod(
  438. "_testPseudoVar",
  439. smalltalk.method({
  440. selector: "testPseudoVar",
  441. category: 'tests',
  442. fn: function (){
  443. var self=this;
  444. var $1,$2;
  445. var node;
  446. var pseudoVars;
  447. pseudoVars=["self", "super", "true", "false", "nil"];
  448. smalltalk.send(pseudoVars,"_do_",[(function(each){
  449. $1=smalltalk.send((smalltalk.VariableNode || VariableNode),"_new",[]);
  450. smalltalk.send($1,"_value_",[each]);
  451. $2=smalltalk.send($1,"_yourself",[]);
  452. node=$2;
  453. node;
  454. return smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(smalltalk.send((smalltalk.MethodLexicalScope || MethodLexicalScope),"_new",[]),"_bindingFor_",[node]),"_isPseudoVar",[])]);
  455. })]);
  456. return self},
  457. args: [],
  458. 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 ]",
  459. messageSends: ["do:", "value:", "new", "yourself", "assert:", "isPseudoVar", "bindingFor:"],
  460. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  461. }),
  462. smalltalk.ScopeVarTest);
  463. smalltalk.addMethod(
  464. "_testTempVar",
  465. smalltalk.method({
  466. selector: "testTempVar",
  467. category: 'tests',
  468. fn: function (){
  469. var self=this;
  470. var $1,$2;
  471. var node;
  472. var scope;
  473. $1=smalltalk.send((smalltalk.VariableNode || VariableNode),"_new",[]);
  474. smalltalk.send($1,"_value_",["bzzz"]);
  475. $2=smalltalk.send($1,"_yourself",[]);
  476. node=$2;
  477. scope=smalltalk.send((smalltalk.MethodLexicalScope || MethodLexicalScope),"_new",[]);
  478. smalltalk.send(scope,"_addTemp_",["bzzz"]);
  479. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(scope,"_bindingFor_",[node]),"_isTempVar",[])]);
  480. return self},
  481. args: [],
  482. 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",
  483. messageSends: ["value:", "new", "yourself", "addTemp:", "assert:", "isTempVar", "bindingFor:"],
  484. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  485. }),
  486. smalltalk.ScopeVarTest);
  487. smalltalk.addMethod(
  488. "_testUnknownVar",
  489. smalltalk.method({
  490. selector: "testUnknownVar",
  491. category: 'tests',
  492. fn: function (){
  493. var self=this;
  494. var $1,$2;
  495. var node;
  496. $1=smalltalk.send((smalltalk.VariableNode || VariableNode),"_new",[]);
  497. smalltalk.send($1,"_value_",["bzzz"]);
  498. $2=smalltalk.send($1,"_yourself",[]);
  499. node=$2;
  500. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(smalltalk.send((smalltalk.MethodLexicalScope || MethodLexicalScope),"_new",[]),"_bindingFor_",[node]),"_isNil",[])]);
  501. return self},
  502. args: [],
  503. source: "testUnknownVar\x0a\x09| node |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09self assert: (MethodLexicalScope new bindingFor: node) isNil",
  504. messageSends: ["value:", "new", "yourself", "assert:", "isNil", "bindingFor:"],
  505. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  506. }),
  507. smalltalk.ScopeVarTest);
  508. smalltalk.addClass('SemanticAnalyzerTest', smalltalk.TestCase, ['analyzer'], 'Compiler-Tests');
  509. smalltalk.addMethod(
  510. "_setUp",
  511. smalltalk.method({
  512. selector: "setUp",
  513. category: 'running',
  514. fn: function (){
  515. var self=this;
  516. self["@analyzer"]=smalltalk.send((smalltalk.SemanticAnalyzer || SemanticAnalyzer),"_on_",[(smalltalk.Object || Object)]);
  517. return self},
  518. args: [],
  519. source: "setUp\x0a\x09analyzer := SemanticAnalyzer on: Object",
  520. messageSends: ["on:"],
  521. referencedClasses: ["Object", "SemanticAnalyzer"]
  522. }),
  523. smalltalk.SemanticAnalyzerTest);
  524. smalltalk.addMethod(
  525. "_testAssignment",
  526. smalltalk.method({
  527. selector: "testAssignment",
  528. category: 'tests',
  529. fn: function (){
  530. var self=this;
  531. var src;
  532. var ast;
  533. src="foo self := 1";
  534. ast=smalltalk.send(smalltalk,"_parse_",[src]);
  535. smalltalk.send(self,"_should_raise_",[(function(){
  536. return smalltalk.send(self["@analyzer"],"_visit_",[ast]);
  537. }),(smalltalk.InvalidAssignmentError || InvalidAssignmentError)]);
  538. return self},
  539. args: [],
  540. 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",
  541. messageSends: ["parse:", "should:raise:", "visit:"],
  542. referencedClasses: ["InvalidAssignmentError"]
  543. }),
  544. smalltalk.SemanticAnalyzerTest);
  545. smalltalk.addMethod(
  546. "_testNonLocalReturn",
  547. smalltalk.method({
  548. selector: "testNonLocalReturn",
  549. category: 'tests',
  550. fn: function (){
  551. var self=this;
  552. var src;
  553. var ast;
  554. src="foo | a | a + 1. ^ a";
  555. ast=smalltalk.send(smalltalk,"_parse_",[src]);
  556. smalltalk.send(self["@analyzer"],"_visit_",[ast]);
  557. smalltalk.send(self,"_deny_",[smalltalk.send(smalltalk.send(ast,"_scope",[]),"_hasNonLocalReturn",[])]);
  558. return self},
  559. args: [],
  560. 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",
  561. messageSends: ["parse:", "visit:", "deny:", "hasNonLocalReturn", "scope"],
  562. referencedClasses: []
  563. }),
  564. smalltalk.SemanticAnalyzerTest);
  565. smalltalk.addMethod(
  566. "_testNonLocalReturn2",
  567. smalltalk.method({
  568. selector: "testNonLocalReturn2",
  569. category: 'tests',
  570. fn: function (){
  571. var self=this;
  572. var src;
  573. var ast;
  574. src="foo | a | a + 1. [ [ ^ a] ]";
  575. ast=smalltalk.send(smalltalk,"_parse_",[src]);
  576. smalltalk.send(self["@analyzer"],"_visit_",[ast]);
  577. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(ast,"_scope",[]),"_hasNonLocalReturn",[])]);
  578. return self},
  579. args: [],
  580. 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",
  581. messageSends: ["parse:", "visit:", "assert:", "hasNonLocalReturn", "scope"],
  582. referencedClasses: []
  583. }),
  584. smalltalk.SemanticAnalyzerTest);
  585. smalltalk.addMethod(
  586. "_testScope",
  587. smalltalk.method({
  588. selector: "testScope",
  589. category: 'tests',
  590. fn: function (){
  591. var self=this;
  592. var src;
  593. var ast;
  594. src="foo | a | a + 1. [ | b | b := a ]";
  595. ast=smalltalk.send(smalltalk,"_parse_",[src]);
  596. smalltalk.send(self["@analyzer"],"_visit_",[ast]);
  597. smalltalk.send(self,"_deny_",[smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(ast,"_nodes",[]),"_first",[]),"_nodes",[]),"_last",[]),"_scope",[]),"__eq_eq",[smalltalk.send(ast,"_scope",[])])]);
  598. return self},
  599. args: [],
  600. 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.",
  601. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "last", "nodes", "first"],
  602. referencedClasses: []
  603. }),
  604. smalltalk.SemanticAnalyzerTest);
  605. smalltalk.addMethod(
  606. "_testScope2",
  607. smalltalk.method({
  608. selector: "testScope2",
  609. category: 'tests',
  610. fn: function (){
  611. var self=this;
  612. var src;
  613. var ast;
  614. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  615. ast=smalltalk.send(smalltalk,"_parse_",[src]);
  616. smalltalk.send(self["@analyzer"],"_visit_",[ast]);
  617. smalltalk.send(self,"_deny_",[smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(ast,"_nodes",[]),"_first",[]),"_nodes",[]),"_last",[]),"_nodes",[]),"_first",[]),"_nodes",[]),"_first",[]),"_scope",[]),"__eq_eq",[smalltalk.send(ast,"_scope",[])])]);
  618. return self},
  619. args: [],
  620. 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.",
  621. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "first", "nodes", "last"],
  622. referencedClasses: []
  623. }),
  624. smalltalk.SemanticAnalyzerTest);
  625. smalltalk.addMethod(
  626. "_testScopeLevel",
  627. smalltalk.method({
  628. selector: "testScopeLevel",
  629. category: 'tests',
  630. fn: function (){
  631. var self=this;
  632. var src;
  633. var ast;
  634. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  635. ast=smalltalk.send(smalltalk,"_parse_",[src]);
  636. smalltalk.send(self["@analyzer"],"_visit_",[ast]);
  637. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(smalltalk.send(ast,"_scope",[]),"_scopeLevel",[]),"__eq",[(1)])]);
  638. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(ast,"_nodes",[]),"_first",[]),"_nodes",[]),"_last",[]),"_nodes",[]),"_first",[]),"_nodes",[]),"_first",[]),"_scope",[]),"_scopeLevel",[]),"__eq",[(3)])]);
  639. return self},
  640. args: [],
  641. 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",
  642. messageSends: ["parse:", "visit:", "assert:", "=", "scopeLevel", "scope", "first", "nodes", "last"],
  643. referencedClasses: []
  644. }),
  645. smalltalk.SemanticAnalyzerTest);
  646. smalltalk.addMethod(
  647. "_testUnknownVariables",
  648. smalltalk.method({
  649. selector: "testUnknownVariables",
  650. category: 'tests',
  651. fn: function (){
  652. var self=this;
  653. var src;
  654. var ast;
  655. src="foo | a | b + a";
  656. ast=smalltalk.send(smalltalk,"_parse_",[src]);
  657. smalltalk.send(self["@analyzer"],"_visit_",[ast]);
  658. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(smalltalk.send(ast,"_scope",[]),"_unknownVariables",[]),"__eq",[["b"]])]);
  659. return self},
  660. args: [],
  661. source: "testUnknownVariables\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a | b + a'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self assert: ast scope unknownVariables = #('b')",
  662. messageSends: ["parse:", "visit:", "assert:", "=", "unknownVariables", "scope"],
  663. referencedClasses: []
  664. }),
  665. smalltalk.SemanticAnalyzerTest);
  666. smalltalk.addMethod(
  667. "_testUnknownVariablesWithScope",
  668. smalltalk.method({
  669. selector: "testUnknownVariablesWithScope",
  670. category: 'tests',
  671. fn: function (){
  672. var self=this;
  673. var src;
  674. var ast;
  675. src="foo | a b | [ c + 1. [ a + 1. d + 1 ]]";
  676. ast=smalltalk.send(smalltalk,"_parse_",[src]);
  677. smalltalk.send(self["@analyzer"],"_visit_",[ast]);
  678. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(smalltalk.send(ast,"_scope",[]),"_unknownVariables",[]),"__eq",[["c", "d"]])]);
  679. return self},
  680. args: [],
  681. source: "testUnknownVariablesWithScope\x0a\x09| src ast |\x0a\x0a\x09src := 'foo | a b | [ c + 1. [ a + 1. d + 1 ]]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast.\x0a\x0a\x09self assert: ast scope unknownVariables = #('c' 'd' )",
  682. messageSends: ["parse:", "visit:", "assert:", "=", "unknownVariables", "scope"],
  683. referencedClasses: []
  684. }),
  685. smalltalk.SemanticAnalyzerTest);
  686. smalltalk.addMethod(
  687. "_testVariableShadowing",
  688. smalltalk.method({
  689. selector: "testVariableShadowing",
  690. category: 'tests',
  691. fn: function (){
  692. var self=this;
  693. var src;
  694. var ast;
  695. src="foo | a | a + 1";
  696. ast=smalltalk.send(smalltalk,"_parse_",[src]);
  697. smalltalk.send(self["@analyzer"],"_visit_",[ast]);
  698. return self},
  699. args: [],
  700. source: "testVariableShadowing\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  701. messageSends: ["parse:", "visit:"],
  702. referencedClasses: []
  703. }),
  704. smalltalk.SemanticAnalyzerTest);
  705. smalltalk.addMethod(
  706. "_testVariableShadowing2",
  707. smalltalk.method({
  708. selector: "testVariableShadowing2",
  709. category: 'tests',
  710. fn: function (){
  711. var self=this;
  712. var src;
  713. var ast;
  714. src="foo | a | a + 1. [ | a | a := 2 ]";
  715. ast=smalltalk.send(smalltalk,"_parse_",[src]);
  716. smalltalk.send(self,"_should_raise_",[(function(){
  717. return smalltalk.send(self["@analyzer"],"_visit_",[ast]);
  718. }),(smalltalk.ShadowingVariableError || ShadowingVariableError)]);
  719. return self},
  720. args: [],
  721. 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",
  722. messageSends: ["parse:", "should:raise:", "visit:"],
  723. referencedClasses: ["ShadowingVariableError"]
  724. }),
  725. smalltalk.SemanticAnalyzerTest);
  726. smalltalk.addMethod(
  727. "_testVariableShadowing3",
  728. smalltalk.method({
  729. selector: "testVariableShadowing3",
  730. category: 'tests',
  731. fn: function (){
  732. var self=this;
  733. var src;
  734. var ast;
  735. src="foo | a | a + 1. [ | b | b := 2 ]";
  736. ast=smalltalk.send(smalltalk,"_parse_",[src]);
  737. smalltalk.send(self["@analyzer"],"_visit_",[ast]);
  738. return self},
  739. args: [],
  740. source: "testVariableShadowing3\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | b | b := 2 ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  741. messageSends: ["parse:", "visit:"],
  742. referencedClasses: []
  743. }),
  744. smalltalk.SemanticAnalyzerTest);
  745. smalltalk.addMethod(
  746. "_testVariableShadowing4",
  747. smalltalk.method({
  748. selector: "testVariableShadowing4",
  749. category: 'tests',
  750. fn: function (){
  751. var self=this;
  752. var src;
  753. var ast;
  754. src="foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]";
  755. ast=smalltalk.send(smalltalk,"_parse_",[src]);
  756. smalltalk.send(self["@analyzer"],"_visit_",[ast]);
  757. return self},
  758. args: [],
  759. source: "testVariableShadowing4\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  760. messageSends: ["parse:", "visit:"],
  761. referencedClasses: []
  762. }),
  763. smalltalk.SemanticAnalyzerTest);
  764. smalltalk.addMethod(
  765. "_testVariableShadowing5",
  766. smalltalk.method({
  767. selector: "testVariableShadowing5",
  768. category: 'tests',
  769. fn: function (){
  770. var self=this;
  771. var src;
  772. var ast;
  773. src="foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]";
  774. ast=smalltalk.send(smalltalk,"_parse_",[src]);
  775. smalltalk.send(self,"_should_raise_",[(function(){
  776. return smalltalk.send(self["@analyzer"],"_visit_",[ast]);
  777. }),(smalltalk.ShadowingVariableError || ShadowingVariableError)]);
  778. return self},
  779. args: [],
  780. 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",
  781. messageSends: ["parse:", "should:raise:", "visit:"],
  782. referencedClasses: ["ShadowingVariableError"]
  783. }),
  784. smalltalk.SemanticAnalyzerTest);
  785. smalltalk.addMethod(
  786. "_testVariablesLookup",
  787. smalltalk.method({
  788. selector: "testVariablesLookup",
  789. category: 'tests',
  790. fn: function (){
  791. var self=this;
  792. var src;
  793. var ast;
  794. src="foo | a | a + 1. [ | b | b := a ]";
  795. ast=smalltalk.send(smalltalk,"_parse_",[src]);
  796. smalltalk.send(self["@analyzer"],"_visit_",[ast]);
  797. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(ast,"_nodes",[]),"_first",[]),"_nodes",[]),"_first",[]),"_receiver",[]),"_binding",[]),"_isTempVar",[])]);
  798. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(ast,"_nodes",[]),"_first",[]),"_nodes",[]),"_first",[]),"_receiver",[]),"_binding",[]),"_scope",[]),"__eq_eq",[smalltalk.send(ast,"_scope",[])])]);
  799. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(ast,"_nodes",[]),"_first",[]),"_nodes",[]),"_last",[]),"_nodes",[]),"_first",[]),"_nodes",[]),"_first",[]),"_left",[]),"_binding",[]),"_isTempVar",[])]);
  800. smalltalk.send(self,"_assert_",[smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(ast,"_nodes",[]),"_first",[]),"_nodes",[]),"_last",[]),"_nodes",[]),"_first",[]),"_nodes",[]),"_first",[]),"_left",[]),"_binding",[]),"_scope",[]),"__eq_eq",[smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(ast,"_nodes",[]),"_first",[]),"_nodes",[]),"_last",[]),"_scope",[])])]);
  801. return self},
  802. args: [],
  803. 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.",
  804. messageSends: ["parse:", "visit:", "assert:", "isTempVar", "binding", "receiver", "first", "nodes", "==", "scope", "left", "last"],
  805. referencedClasses: []
  806. }),
  807. smalltalk.SemanticAnalyzerTest);