Compiler-Tests.js 47 KB

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