Compiler-Tests.js 55 KB

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