Compiler-Tests.js 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496
  1. smalltalk.addPackage('Compiler-Tests');
  2. smalltalk.addClass('AbstractASTInterpreterTest', smalltalk.TestCase, [], 'Compiler-Tests');
  3. smalltalk.addMethod(
  4. smalltalk.method({
  5. selector: "analyze:forClass:",
  6. category: 'interpreting',
  7. fn: function (aNode,aClass){
  8. var self=this;
  9. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  10. return smalltalk.withContext(function($ctx1) {
  11. var $1;
  12. _st(_st($SemanticAnalyzer())._on_(aClass))._visit_(aNode);
  13. $1=aNode;
  14. return $1;
  15. }, function($ctx1) {$ctx1.fill(self,"analyze:forClass:",{aNode:aNode,aClass:aClass},smalltalk.AbstractASTInterpreterTest)})},
  16. args: ["aNode", "aClass"],
  17. source: "analyze: aNode forClass: aClass\x0a\x09(SemanticAnalyzer on: aClass) visit: aNode.\x0a\x09^ aNode",
  18. messageSends: ["visit:", "on:"],
  19. referencedClasses: ["SemanticAnalyzer"]
  20. }),
  21. smalltalk.AbstractASTInterpreterTest);
  22. smalltalk.addMethod(
  23. smalltalk.method({
  24. selector: "interpret:",
  25. category: 'interpreting',
  26. fn: function (aString){
  27. var self=this;
  28. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  29. return smalltalk.withContext(function($ctx1) {
  30. var $1;
  31. $1=_st(self)._interpret_withArguments_(aString,_st($Dictionary())._new());
  32. return $1;
  33. }, function($ctx1) {$ctx1.fill(self,"interpret:",{aString:aString},smalltalk.AbstractASTInterpreterTest)})},
  34. args: ["aString"],
  35. source: "interpret: aString\x0a\x09^ self\x0a\x09\x09interpret: aString\x0a\x09\x09withArguments: Dictionary new",
  36. messageSends: ["interpret:withArguments:", "new"],
  37. referencedClasses: ["Dictionary"]
  38. }),
  39. smalltalk.AbstractASTInterpreterTest);
  40. smalltalk.addMethod(
  41. smalltalk.method({
  42. selector: "interpret:receiver:withArguments:",
  43. category: 'interpreting',
  44. fn: function (aString,anObject,aDictionary){
  45. var self=this;
  46. var ctx;
  47. function $AIContext(){return smalltalk.AIContext||(typeof AIContext=="undefined"?nil:AIContext)}
  48. return smalltalk.withContext(function($ctx1) {
  49. var $2,$3,$1;
  50. ctx=_st($AIContext())._new();
  51. _st(ctx)._receiver_(anObject);
  52. _st(aDictionary)._keysAndValuesDo_((function(key,value){
  53. return smalltalk.withContext(function($ctx2) {
  54. return _st(ctx)._localAt_put_(key,value);
  55. }, function($ctx2) {$ctx2.fillBlock({key:key,value:value},$ctx1)})}));
  56. $2=_st(self)._interpreter();
  57. _st($2)._context_(ctx);
  58. _st($2)._interpret_(_st(_st(_st(self)._parse_forClass_(aString,_st(anObject)._class()))._nodes())._first());
  59. $3=_st($2)._result();
  60. $1=$3;
  61. return $1;
  62. }, function($ctx1) {$ctx1.fill(self,"interpret:receiver:withArguments:",{aString:aString,anObject:anObject,aDictionary:aDictionary,ctx:ctx},smalltalk.AbstractASTInterpreterTest)})},
  63. args: ["aString", "anObject", "aDictionary"],
  64. source: "interpret: aString receiver: anObject withArguments: aDictionary\x0a\x09\x22The food is a methodNode. Interpret the sequenceNode only\x22\x0a\x09\x0a\x09| ctx |\x0a\x09\x0a\x09ctx := AIContext new.\x0a\x09ctx receiver: anObject.\x0a\x09aDictionary keysAndValuesDo: [ :key :value |\x0a\x09\x09ctx localAt: key put: value ].\x0a\x09\x0a\x09^ self interpreter\x0a\x09\x09context: ctx;\x0a\x09\x09interpret: (self parse: aString forClass: anObject class)\x0a\x09\x09\x09nodes first;\x0a\x09\x09result",
  65. messageSends: ["new", "receiver:", "keysAndValuesDo:", "localAt:put:", "context:", "interpreter", "interpret:", "first", "nodes", "parse:forClass:", "class", "result"],
  66. referencedClasses: ["AIContext"]
  67. }),
  68. smalltalk.AbstractASTInterpreterTest);
  69. smalltalk.addMethod(
  70. smalltalk.method({
  71. selector: "interpret:withArguments:",
  72. category: 'interpreting',
  73. fn: function (aString,aDictionary){
  74. var self=this;
  75. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  76. return smalltalk.withContext(function($ctx1) {
  77. var $1;
  78. $1=_st(self)._interpret_receiver_withArguments_(aString,_st($Object())._new(),aDictionary);
  79. return $1;
  80. }, function($ctx1) {$ctx1.fill(self,"interpret:withArguments:",{aString:aString,aDictionary:aDictionary},smalltalk.AbstractASTInterpreterTest)})},
  81. args: ["aString", "aDictionary"],
  82. source: "interpret: aString withArguments: aDictionary\x0a\x09^ self\x0a\x09\x09interpret: aString\x0a\x09\x09receiver: Object new\x0a\x09\x09withArguments: aDictionary",
  83. messageSends: ["interpret:receiver:withArguments:", "new"],
  84. referencedClasses: ["Object"]
  85. }),
  86. smalltalk.AbstractASTInterpreterTest);
  87. smalltalk.addMethod(
  88. smalltalk.method({
  89. selector: "interpreter",
  90. category: 'accessing',
  91. fn: function (){
  92. var self=this;
  93. return smalltalk.withContext(function($ctx1) {
  94. var $1;
  95. $1=_st(self)._subclassResponsibility();
  96. return $1;
  97. }, function($ctx1) {$ctx1.fill(self,"interpreter",{},smalltalk.AbstractASTInterpreterTest)})},
  98. args: [],
  99. source: "interpreter\x0a\x09^ self subclassResponsibility",
  100. messageSends: ["subclassResponsibility"],
  101. referencedClasses: []
  102. }),
  103. smalltalk.AbstractASTInterpreterTest);
  104. smalltalk.addMethod(
  105. smalltalk.method({
  106. selector: "parse:",
  107. category: 'parsing',
  108. fn: function (aString){
  109. var self=this;
  110. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  111. return smalltalk.withContext(function($ctx1) {
  112. var $1;
  113. $1=_st(_st($Smalltalk())._current())._parse_(aString);
  114. return $1;
  115. }, function($ctx1) {$ctx1.fill(self,"parse:",{aString:aString},smalltalk.AbstractASTInterpreterTest)})},
  116. args: ["aString"],
  117. source: "parse: aString\x0a\x09^ Smalltalk current parse: aString",
  118. messageSends: ["parse:", "current"],
  119. referencedClasses: ["Smalltalk"]
  120. }),
  121. smalltalk.AbstractASTInterpreterTest);
  122. smalltalk.addMethod(
  123. smalltalk.method({
  124. selector: "parse:forClass:",
  125. category: 'parsing',
  126. fn: function (aString,aClass){
  127. var self=this;
  128. return smalltalk.withContext(function($ctx1) {
  129. var $1;
  130. $1=_st(self)._analyze_forClass_(_st(self)._parse_(aString),aClass);
  131. return $1;
  132. }, function($ctx1) {$ctx1.fill(self,"parse:forClass:",{aString:aString,aClass:aClass},smalltalk.AbstractASTInterpreterTest)})},
  133. args: ["aString", "aClass"],
  134. source: "parse: aString forClass: aClass\x0a\x09^ self analyze: (self parse: aString) forClass: aClass",
  135. messageSends: ["analyze:forClass:", "parse:"],
  136. referencedClasses: []
  137. }),
  138. smalltalk.AbstractASTInterpreterTest);
  139. smalltalk.addClass('ASTInterpreterTest', smalltalk.AbstractASTInterpreterTest, [], 'Compiler-Tests');
  140. smalltalk.addMethod(
  141. smalltalk.method({
  142. selector: "interpreter",
  143. category: 'accessing',
  144. fn: function (){
  145. var self=this;
  146. function $ASTInterpreter(){return smalltalk.ASTInterpreter||(typeof ASTInterpreter=="undefined"?nil:ASTInterpreter)}
  147. return smalltalk.withContext(function($ctx1) {
  148. var $1;
  149. $1=_st($ASTInterpreter())._new();
  150. return $1;
  151. }, function($ctx1) {$ctx1.fill(self,"interpreter",{},smalltalk.ASTInterpreterTest)})},
  152. args: [],
  153. source: "interpreter\x0a\x09^ ASTInterpreter new",
  154. messageSends: ["new"],
  155. referencedClasses: ["ASTInterpreter"]
  156. }),
  157. smalltalk.ASTInterpreterTest);
  158. smalltalk.addMethod(
  159. smalltalk.method({
  160. selector: "testBinarySend",
  161. category: 'tests',
  162. fn: function (){
  163. var self=this;
  164. return smalltalk.withContext(function($ctx1) {
  165. _st(self)._assert_equals_(_st(self)._interpret_("foo 2+3+4"),(9));
  166. return self}, function($ctx1) {$ctx1.fill(self,"testBinarySend",{},smalltalk.ASTInterpreterTest)})},
  167. args: [],
  168. source: "testBinarySend\x0a\x09self assert: (self interpret: 'foo 2+3+4') equals: 9",
  169. messageSends: ["assert:equals:", "interpret:"],
  170. referencedClasses: []
  171. }),
  172. smalltalk.ASTInterpreterTest);
  173. smalltalk.addMethod(
  174. smalltalk.method({
  175. selector: "testBlockLiteral",
  176. category: 'tests',
  177. fn: function (){
  178. var self=this;
  179. return smalltalk.withContext(function($ctx1) {
  180. _st(self)._assert_equals_(_st(self)._interpret_("foo ^ true ifTrue: [ 1 ] ifFalse: [ 2 ]"),(1));
  181. _st(self)._assert_equals_(_st(self)._interpret_("foo true ifTrue: [ ^ 1 ] ifFalse: [ 2 ]"),(1));
  182. _st(self)._assert_equals_(_st(self)._interpret_("foo ^ false ifTrue: [ 1 ] ifFalse: [ 2 ]"),(2));
  183. return self}, function($ctx1) {$ctx1.fill(self,"testBlockLiteral",{},smalltalk.ASTInterpreterTest)})},
  184. args: [],
  185. source: "testBlockLiteral\x0a\x09self assert: (self interpret: 'foo ^ true ifTrue: [ 1 ] ifFalse: [ 2 ]') equals: 1.\x0a\x09self assert: (self interpret: 'foo true ifTrue: [ ^ 1 ] ifFalse: [ 2 ]') equals: 1.\x0a\x09self assert: (self interpret: 'foo ^ false ifTrue: [ 1 ] ifFalse: [ 2 ]') equals: 2",
  186. messageSends: ["assert:equals:", "interpret:"],
  187. referencedClasses: []
  188. }),
  189. smalltalk.ASTInterpreterTest);
  190. smalltalk.addMethod(
  191. smalltalk.method({
  192. selector: "testCascade",
  193. category: 'tests',
  194. fn: function (){
  195. var self=this;
  196. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  197. return smalltalk.withContext(function($ctx1) {
  198. _st(self)._assert_equals_(_st(self)._interpret_("foo ^ OrderedCollection new add: 2; add: 3; yourself"),_st($OrderedCollection())._with_with_((2),(3)));
  199. return self}, function($ctx1) {$ctx1.fill(self,"testCascade",{},smalltalk.ASTInterpreterTest)})},
  200. args: [],
  201. source: "testCascade\x0a\x09self assert: (self interpret: 'foo ^ OrderedCollection new add: 2; add: 3; yourself') equals: (OrderedCollection with: 2 with: 3)",
  202. messageSends: ["assert:equals:", "interpret:", "with:with:"],
  203. referencedClasses: ["OrderedCollection"]
  204. }),
  205. smalltalk.ASTInterpreterTest);
  206. smalltalk.addMethod(
  207. smalltalk.method({
  208. selector: "testDynamicArray",
  209. category: 'tests',
  210. fn: function (){
  211. var self=this;
  212. return smalltalk.withContext(function($ctx1) {
  213. _st(self)._assert_equals_(_st(self)._interpret_("foo ^ {1+1. 2+2}"),[(2), (4)]);
  214. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicArray",{},smalltalk.ASTInterpreterTest)})},
  215. args: [],
  216. source: "testDynamicArray\x0a\x09self assert: (self interpret: 'foo ^ {1+1. 2+2}') equals: #(2 4)",
  217. messageSends: ["assert:equals:", "interpret:"],
  218. referencedClasses: []
  219. }),
  220. smalltalk.ASTInterpreterTest);
  221. smalltalk.addMethod(
  222. smalltalk.method({
  223. selector: "testDynamicDictionary",
  224. category: 'tests',
  225. fn: function (){
  226. var self=this;
  227. return smalltalk.withContext(function($ctx1) {
  228. _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))]));
  229. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicDictionary",{},smalltalk.ASTInterpreterTest)})},
  230. args: [],
  231. source: "testDynamicDictionary\x0a\x09self assert: (self interpret: 'foo ^ #{1->1. 2->3}') equals: #{1->1. 2->3}",
  232. messageSends: ["assert:equals:", "interpret:", "->"],
  233. referencedClasses: []
  234. }),
  235. smalltalk.ASTInterpreterTest);
  236. smalltalk.addMethod(
  237. smalltalk.method({
  238. selector: "testInlinedJSStatement",
  239. category: 'tests',
  240. fn: function (){
  241. var self=this;
  242. return smalltalk.withContext(function($ctx1) {
  243. _st(self)._assert_equals_(_st(self)._interpret_("foo <return 2+3>"),(5));
  244. _st(self)._assert_equals_(_st(self)._interpret_withArguments_("foo: anInteger <return 2 + anInteger>",smalltalk.HashedCollection._fromPairs_([_st("anInteger").__minus_gt((3))])),(5));
  245. return self}, function($ctx1) {$ctx1.fill(self,"testInlinedJSStatement",{},smalltalk.ASTInterpreterTest)})},
  246. args: [],
  247. source: "testInlinedJSStatement\x0a\x09self assert: (self interpret: 'foo <return 2+3>') equals: 5.\x0a\x09\x0a\x09self\x0a\x09\x09assert: (self\x0a\x09\x09\x09interpret: 'foo: anInteger <return 2 + anInteger>'\x0a\x09\x09\x09withArguments: #{ 'anInteger' -> 3})\x0a\x09\x09equals: 5",
  248. messageSends: ["assert:equals:", "interpret:", "interpret:withArguments:", "->"],
  249. referencedClasses: []
  250. }),
  251. smalltalk.ASTInterpreterTest);
  252. smalltalk.addMethod(
  253. smalltalk.method({
  254. selector: "testInstVarAccess",
  255. category: 'tests',
  256. fn: function (){
  257. var self=this;
  258. return smalltalk.withContext(function($ctx1) {
  259. _st(self)._assert_equals_(_st(self)._interpret_receiver_withArguments_("foo ^ x",_st((2)).__at((3)),smalltalk.HashedCollection._fromPairs_([])),(2));
  260. return self}, function($ctx1) {$ctx1.fill(self,"testInstVarAccess",{},smalltalk.ASTInterpreterTest)})},
  261. args: [],
  262. source: "testInstVarAccess\x0a\x09self\x0a\x09\x09assert: (self\x0a\x09\x09\x09interpret: 'foo ^ x'\x0a\x09\x09\x09receiver: 2@3\x0a\x09\x09\x09withArguments: #{})\x0a\x09\x09equals: 2",
  263. messageSends: ["assert:equals:", "interpret:receiver:withArguments:", "@"],
  264. referencedClasses: []
  265. }),
  266. smalltalk.ASTInterpreterTest);
  267. smalltalk.addMethod(
  268. smalltalk.method({
  269. selector: "testInstVarAssignment",
  270. category: 'tests',
  271. fn: function (){
  272. var self=this;
  273. function $Point(){return smalltalk.Point||(typeof Point=="undefined"?nil:Point)}
  274. return smalltalk.withContext(function($ctx1) {
  275. _st(self)._assert_equals_(_st(self)._interpret_receiver_withArguments_("foo: anInteger x := anInteger. ^ x",_st($Point())._new(),smalltalk.HashedCollection._fromPairs_([_st("anInteger").__minus_gt((2))])),(2));
  276. return self}, function($ctx1) {$ctx1.fill(self,"testInstVarAssignment",{},smalltalk.ASTInterpreterTest)})},
  277. args: [],
  278. source: "testInstVarAssignment\x0a\x09self\x0a\x09\x09assert: (self\x0a\x09\x09\x09interpret: 'foo: anInteger x := anInteger. ^ x'\x0a\x09\x09\x09receiver: Point new\x0a\x09\x09\x09withArguments: #{'anInteger' -> 2})\x0a\x09\x09equals: 2",
  279. messageSends: ["assert:equals:", "interpret:receiver:withArguments:", "new", "->"],
  280. referencedClasses: ["Point"]
  281. }),
  282. smalltalk.ASTInterpreterTest);
  283. smalltalk.addMethod(
  284. smalltalk.method({
  285. selector: "testNonlocalReturn",
  286. category: 'tests',
  287. fn: function (){
  288. var self=this;
  289. return smalltalk.withContext(function($ctx1) {
  290. _st(self)._assert_equals_(_st(self)._interpret_("foo true ifTrue: [ ^ 1 ]. ^2"),(1));
  291. return self}, function($ctx1) {$ctx1.fill(self,"testNonlocalReturn",{},smalltalk.ASTInterpreterTest)})},
  292. args: [],
  293. source: "testNonlocalReturn\x0a\x09self assert: (self interpret: 'foo true ifTrue: [ ^ 1 ]. ^2') equals: 1",
  294. messageSends: ["assert:equals:", "interpret:"],
  295. referencedClasses: []
  296. }),
  297. smalltalk.ASTInterpreterTest);
  298. smalltalk.addMethod(
  299. smalltalk.method({
  300. selector: "testReceiver",
  301. category: 'tests',
  302. fn: function (){
  303. var self=this;
  304. return smalltalk.withContext(function($ctx1) {
  305. _st(self)._assert_equals_(_st(self)._interpret_receiver_withArguments_("foo ^ self",_st((2)).__at((3)),smalltalk.HashedCollection._fromPairs_([])),_st((2)).__at((3)));
  306. return self}, function($ctx1) {$ctx1.fill(self,"testReceiver",{},smalltalk.ASTInterpreterTest)})},
  307. args: [],
  308. source: "testReceiver\x0a\x09self\x0a\x09\x09assert: (self\x0a\x09\x09\x09interpret: 'foo ^ self'\x0a\x09\x09\x09receiver: 2@3\x0a\x09\x09\x09withArguments: #{})\x0a\x09\x09equals: 2@3",
  309. messageSends: ["assert:equals:", "interpret:receiver:withArguments:", "@"],
  310. referencedClasses: []
  311. }),
  312. smalltalk.ASTInterpreterTest);
  313. smalltalk.addMethod(
  314. smalltalk.method({
  315. selector: "testSuper",
  316. category: 'tests',
  317. fn: function (){
  318. var self=this;
  319. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  320. return smalltalk.withContext(function($ctx1) {
  321. _st(self)._assert_equals_(_st(self)._interpret_receiver_withArguments_("foo ^ super isBoolean",true,_st($Dictionary())._new()),false);
  322. return self}, function($ctx1) {$ctx1.fill(self,"testSuper",{},smalltalk.ASTInterpreterTest)})},
  323. args: [],
  324. source: "testSuper\x0a\x09self \x0a\x09\x09assert: (self \x0a\x09\x09\x09interpret: 'foo ^ super isBoolean' \x0a\x09\x09\x09receiver: true \x0a\x09\x09\x09withArguments: Dictionary new) \x0a\x09\x09equals: false",
  325. messageSends: ["assert:equals:", "interpret:receiver:withArguments:", "new"],
  326. referencedClasses: ["Dictionary"]
  327. }),
  328. smalltalk.ASTInterpreterTest);
  329. smalltalk.addMethod(
  330. smalltalk.method({
  331. selector: "testTempAssignment",
  332. category: 'tests',
  333. fn: function (){
  334. var self=this;
  335. return smalltalk.withContext(function($ctx1) {
  336. _st(self)._assert_equals_(_st(self)._interpret_("foo | a | a := 2. ^ a"),(2));
  337. return self}, function($ctx1) {$ctx1.fill(self,"testTempAssignment",{},smalltalk.ASTInterpreterTest)})},
  338. args: [],
  339. source: "testTempAssignment\x0a\x09self assert: (self interpret: 'foo | a | a := 2. ^ a') equals: 2",
  340. messageSends: ["assert:equals:", "interpret:"],
  341. referencedClasses: []
  342. }),
  343. smalltalk.ASTInterpreterTest);
  344. smalltalk.addMethod(
  345. smalltalk.method({
  346. selector: "testThisContext",
  347. category: 'tests',
  348. fn: function (){
  349. var self=this;
  350. return smalltalk.withContext(function($ctx1) {
  351. _st(self)._assert_(_st(_st(_st(self)._interpret_("foo ^ thisContext"))._outerContext())._isNil());
  352. _st(self)._assert_(_st(_st(_st(self)._interpret_("foo ^ [ thisContext ] value"))._outerContext())._notNil());
  353. _st(self)._assert_(_st(self)._interpret_("foo ^ [ thisContext ] value outerContext == thisContext"));
  354. return self}, function($ctx1) {$ctx1.fill(self,"testThisContext",{},smalltalk.ASTInterpreterTest)})},
  355. args: [],
  356. source: "testThisContext\x0a\x09self assert: (self interpret: 'foo ^ thisContext') outerContext isNil.\x0a\x09self assert: (self interpret: 'foo ^ [ thisContext ] value') outerContext notNil.\x0a\x09self assert: (self interpret: 'foo ^ [ thisContext ] value outerContext == thisContext')",
  357. messageSends: ["assert:", "isNil", "outerContext", "interpret:", "notNil"],
  358. referencedClasses: []
  359. }),
  360. smalltalk.ASTInterpreterTest);
  361. smalltalk.addClass('ASTSteppingInterpreterTest', smalltalk.AbstractASTInterpreterTest, ['interpreter'], 'Compiler-Tests');
  362. smalltalk.addMethod(
  363. smalltalk.method({
  364. selector: "interpreter",
  365. category: 'accessing',
  366. fn: function (){
  367. var self=this;
  368. function $ASTSteppingInterpreter(){return smalltalk.ASTSteppingInterpreter||(typeof ASTSteppingInterpreter=="undefined"?nil:ASTSteppingInterpreter)}
  369. return smalltalk.withContext(function($ctx1) {
  370. var $2,$1;
  371. $2=self["@interpreter"];
  372. if(($receiver = $2) == nil || $receiver == undefined){
  373. self["@interpreter"]=_st($ASTSteppingInterpreter())._new();
  374. $1=self["@interpreter"];
  375. } else {
  376. $1=$2;
  377. };
  378. return $1;
  379. }, function($ctx1) {$ctx1.fill(self,"interpreter",{},smalltalk.ASTSteppingInterpreterTest)})},
  380. args: [],
  381. source: "interpreter\x0a\x09^ interpreter ifNil: [ interpreter := ASTSteppingInterpreter new ]",
  382. messageSends: ["ifNil:", "new"],
  383. referencedClasses: ["ASTSteppingInterpreter"]
  384. }),
  385. smalltalk.ASTSteppingInterpreterTest);
  386. smalltalk.addMethod(
  387. smalltalk.method({
  388. selector: "testAtEnd",
  389. category: 'tests',
  390. fn: function (){
  391. var self=this;
  392. return smalltalk.withContext(function($ctx1) {
  393. _st(self)._interpret_("foo 1 + 2");
  394. _st(self)._deny_(_st(_st(self)._interpreter())._atEnd());
  395. _st(_st(self)._interpreter())._step();
  396. _st(self)._deny_(_st(_st(self)._interpreter())._atEnd());
  397. _st(_st(self)._interpreter())._step();
  398. _st(self)._deny_(_st(_st(self)._interpreter())._atEnd());
  399. _st(_st(self)._interpreter())._step();
  400. _st(self)._deny_(_st(_st(self)._interpreter())._atEnd());
  401. _st(_st(self)._interpreter())._step();
  402. _st(self)._assert_(_st(_st(self)._interpreter())._atEnd());
  403. return self}, function($ctx1) {$ctx1.fill(self,"testAtEnd",{},smalltalk.ASTSteppingInterpreterTest)})},
  404. args: [],
  405. source: "testAtEnd\x0a\x09self interpret: 'foo 1 + 2'.\x0a\x09self deny: self interpreter atEnd.\x0a\x0a\x09self interpreter step.\x0a\x09self deny: self interpreter atEnd.\x0a\x09\x0a\x09self interpreter step.\x0a\x09self deny: self interpreter atEnd.\x0a\x09\x0a\x09self interpreter step.\x0a\x09self deny: self interpreter atEnd.\x0a\x09\x0a\x09self interpreter step.\x0a\x09self assert: self interpreter atEnd",
  406. messageSends: ["interpret:", "deny:", "atEnd", "interpreter", "step", "assert:"],
  407. referencedClasses: []
  408. }),
  409. smalltalk.ASTSteppingInterpreterTest);
  410. smalltalk.addMethod(
  411. smalltalk.method({
  412. selector: "testMessageSend",
  413. category: 'tests',
  414. fn: function (){
  415. var self=this;
  416. return smalltalk.withContext(function($ctx1) {
  417. _st(self)._interpret_("foo 1 + 2");
  418. _st(_st(self)._interpreter())._step();
  419. _st(_st(self)._interpreter())._step();
  420. _st(_st(self)._interpreter())._step();
  421. _st(self)._assert_equals_(_st(_st(_st(self)._interpreter())._currentNode())._value(),(1));
  422. _st(_st(self)._interpreter())._step();
  423. _st(self)._assert_equals_(_st(_st(_st(self)._interpreter())._currentNode())._value(),(2));
  424. _st(_st(self)._interpreter())._step();
  425. _st(self)._assert_equals_(_st(_st(self)._interpreter())._result(),(3));
  426. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSend",{},smalltalk.ASTSteppingInterpreterTest)})},
  427. args: [],
  428. source: "testMessageSend\x0a\x09self interpret: 'foo 1 + 2'.\x0a\x09\x0a\x09\x22SequenceNode\x22\x0a\x09self interpreter step.\x0a\x09\x0a\x09\x22SendNode\x22\x0a\x09self interpreter step.\x0a\x09\x0a\x09\x22ValueNode\x22\x0a\x09self interpreter step.\x0a\x09self assert: self interpreter currentNode value equals: 1.\x0a\x09\x0a\x09\x22ValueNode\x22\x0a\x09self interpreter step.\x0a\x09self assert: self interpreter currentNode value equals: 2.\x0a\x09\x0a\x09\x22Result\x22\x0a\x09self interpreter step.\x0a\x09self assert: self interpreter result equals: 3",
  429. messageSends: ["interpret:", "step", "interpreter", "assert:equals:", "value", "currentNode", "result"],
  430. referencedClasses: []
  431. }),
  432. smalltalk.ASTSteppingInterpreterTest);
  433. smalltalk.addMethod(
  434. smalltalk.method({
  435. selector: "testSimpleStepping",
  436. category: 'tests',
  437. fn: function (){
  438. var self=this;
  439. return smalltalk.withContext(function($ctx1) {
  440. _st(self)._interpret_("foo 1");
  441. _st(_st(self)._interpreter())._step();
  442. _st(self)._assert_(_st(_st(_st(self)._interpreter())._result())._isNil());
  443. _st(_st(self)._interpreter())._step();
  444. _st(self)._assert_equals_(_st(_st(self)._interpreter())._result(),(1));
  445. return self}, function($ctx1) {$ctx1.fill(self,"testSimpleStepping",{},smalltalk.ASTSteppingInterpreterTest)})},
  446. args: [],
  447. source: "testSimpleStepping\x0a\x09self interpret: 'foo 1'.\x0a\x09\x0a\x09\x22SequenceNode\x22\x0a\x09self interpreter step.\x0a\x09\x0a\x09self assert: self interpreter result isNil.\x0a\x09\x0a\x09\x22ValueNode\x22\x0a\x09self interpreter step.\x0a\x09\x0a\x09self assert: self interpreter result equals: 1",
  448. messageSends: ["interpret:", "step", "interpreter", "assert:", "isNil", "result", "assert:equals:"],
  449. referencedClasses: []
  450. }),
  451. smalltalk.ASTSteppingInterpreterTest);
  452. smalltalk.addClass('CodeGeneratorTest', smalltalk.TestCase, ['receiver'], 'Compiler-Tests');
  453. smalltalk.addMethod(
  454. smalltalk.method({
  455. selector: "codeGeneratorClass",
  456. category: 'accessing',
  457. fn: function (){
  458. var self=this;
  459. function $CodeGenerator(){return smalltalk.CodeGenerator||(typeof CodeGenerator=="undefined"?nil:CodeGenerator)}
  460. return smalltalk.withContext(function($ctx1) {
  461. var $1;
  462. $1=$CodeGenerator();
  463. return $1;
  464. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{},smalltalk.CodeGeneratorTest)})},
  465. args: [],
  466. source: "codeGeneratorClass\x0a\x09^ CodeGenerator",
  467. messageSends: [],
  468. referencedClasses: ["CodeGenerator"]
  469. }),
  470. smalltalk.CodeGeneratorTest);
  471. smalltalk.addMethod(
  472. smalltalk.method({
  473. selector: "compiler",
  474. category: 'factory',
  475. fn: function (){
  476. var self=this;
  477. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  478. return smalltalk.withContext(function($ctx1) {
  479. var $2,$3,$1;
  480. $2=_st($Compiler())._new();
  481. _st($2)._codeGeneratorClass_(_st(self)._codeGeneratorClass());
  482. $3=_st($2)._yourself();
  483. $1=$3;
  484. return $1;
  485. }, function($ctx1) {$ctx1.fill(self,"compiler",{},smalltalk.CodeGeneratorTest)})},
  486. args: [],
  487. source: "compiler\x0a\x09^ Compiler new\x0a\x09\x09codeGeneratorClass: self codeGeneratorClass;\x0a\x09\x09yourself",
  488. messageSends: ["codeGeneratorClass:", "codeGeneratorClass", "new", "yourself"],
  489. referencedClasses: ["Compiler"]
  490. }),
  491. smalltalk.CodeGeneratorTest);
  492. smalltalk.addMethod(
  493. smalltalk.method({
  494. selector: "setUp",
  495. category: 'initialization',
  496. fn: function (){
  497. var self=this;
  498. return smalltalk.withContext(function($ctx1) {
  499. self["@receiver"]=_st(_st(self)._targetClass())._new();
  500. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},smalltalk.CodeGeneratorTest)})},
  501. args: [],
  502. source: "setUp\x0a\x09receiver := self targetClass new",
  503. messageSends: ["new", "targetClass"],
  504. referencedClasses: []
  505. }),
  506. smalltalk.CodeGeneratorTest);
  507. smalltalk.addMethod(
  508. smalltalk.method({
  509. selector: "should:return:",
  510. category: 'testing',
  511. fn: function (aString,anObject){
  512. var self=this;
  513. var method,result;
  514. return smalltalk.withContext(function($ctx1) {
  515. method=_st(_st(self)._compiler())._install_forClass_category_(aString,_st(self)._targetClass(),"tests");
  516. result=_st(self["@receiver"])._perform_(_st(method)._selector());
  517. _st(_st(self)._targetClass())._removeCompiledMethod_(method);
  518. _st(self)._assert_equals_(anObject,result);
  519. return self}, function($ctx1) {$ctx1.fill(self,"should:return:",{aString:aString,anObject:anObject,method:method,result:result},smalltalk.CodeGeneratorTest)})},
  520. args: ["aString", "anObject"],
  521. 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",
  522. messageSends: ["install:forClass:category:", "targetClass", "compiler", "perform:", "selector", "removeCompiledMethod:", "assert:equals:"],
  523. referencedClasses: []
  524. }),
  525. smalltalk.CodeGeneratorTest);
  526. smalltalk.addMethod(
  527. smalltalk.method({
  528. selector: "targetClass",
  529. category: 'accessing',
  530. fn: function (){
  531. var self=this;
  532. function $DoIt(){return smalltalk.DoIt||(typeof DoIt=="undefined"?nil:DoIt)}
  533. return smalltalk.withContext(function($ctx1) {
  534. var $1;
  535. $1=$DoIt();
  536. return $1;
  537. }, function($ctx1) {$ctx1.fill(self,"targetClass",{},smalltalk.CodeGeneratorTest)})},
  538. args: [],
  539. source: "targetClass\x0a\x09^ DoIt",
  540. messageSends: [],
  541. referencedClasses: ["DoIt"]
  542. }),
  543. smalltalk.CodeGeneratorTest);
  544. smalltalk.addMethod(
  545. smalltalk.method({
  546. selector: "tearDown",
  547. category: 'initialization',
  548. fn: function (){
  549. var self=this;
  550. return smalltalk.withContext(function($ctx1) {
  551. return self}, function($ctx1) {$ctx1.fill(self,"tearDown",{},smalltalk.CodeGeneratorTest)})},
  552. args: [],
  553. source: "tearDown\x0a\x09\x22receiver := nil\x22",
  554. messageSends: [],
  555. referencedClasses: []
  556. }),
  557. smalltalk.CodeGeneratorTest);
  558. smalltalk.addMethod(
  559. smalltalk.method({
  560. selector: "testAssignment",
  561. category: 'tests',
  562. fn: function (){
  563. var self=this;
  564. return smalltalk.withContext(function($ctx1) {
  565. _st(self)._should_return_("foo | a | a := true ifTrue: [ 1 ]. ^ a",(1));
  566. _st(self)._should_return_("foo | a | a := false ifTrue: [ 1 ]. ^ a",nil);
  567. _st(self)._should_return_("foo | a | ^ a := true ifTrue: [ 1 ]",(1));
  568. return self}, function($ctx1) {$ctx1.fill(self,"testAssignment",{},smalltalk.CodeGeneratorTest)})},
  569. args: [],
  570. 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",
  571. messageSends: ["should:return:"],
  572. referencedClasses: []
  573. }),
  574. smalltalk.CodeGeneratorTest);
  575. smalltalk.addMethod(
  576. smalltalk.method({
  577. selector: "testBackslashSelectors",
  578. category: 'tests',
  579. fn: function (){
  580. var self=this;
  581. return smalltalk.withContext(function($ctx1) {
  582. _st(self)._should_return_("\x5c arg ^ 4",(4));
  583. _st(self)._should_return_("\x5c\x5c arg ^ 42",(42));
  584. return self}, function($ctx1) {$ctx1.fill(self,"testBackslashSelectors",{},smalltalk.CodeGeneratorTest)})},
  585. args: [],
  586. source: "testBackslashSelectors\x0a\x09\x0a\x09self should: '\x5c arg ^ 4' return: 4.\x0a\x09self should: '\x5c\x5c arg ^ 42' return: 42",
  587. messageSends: ["should:return:"],
  588. referencedClasses: []
  589. }),
  590. smalltalk.CodeGeneratorTest);
  591. smalltalk.addMethod(
  592. smalltalk.method({
  593. selector: "testBlockReturn",
  594. category: 'tests',
  595. fn: function (){
  596. var self=this;
  597. return smalltalk.withContext(function($ctx1) {
  598. _st(self)._should_return_("foo ^ #(1 2 3) collect: [ :each | true ifTrue: [ each + 1 ] ]",[(2), (3), (4)]);
  599. _st(self)._should_return_("foo ^ #(1 2 3) collect: [ :each | false ifFalse: [ each + 1 ] ]",[(2), (3), (4)]);
  600. _st(self)._should_return_("foo ^ #(1 2 3) collect: [ :each | each odd ifTrue: [ each + 1 ] ifFalse: [ each - 1 ] ]",[(2), (1), (4)]);
  601. return self}, function($ctx1) {$ctx1.fill(self,"testBlockReturn",{},smalltalk.CodeGeneratorTest)})},
  602. args: [],
  603. 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).",
  604. messageSends: ["should:return:"],
  605. referencedClasses: []
  606. }),
  607. smalltalk.CodeGeneratorTest);
  608. smalltalk.addMethod(
  609. smalltalk.method({
  610. selector: "testCascades",
  611. category: 'tests',
  612. fn: function (){
  613. var self=this;
  614. return smalltalk.withContext(function($ctx1) {
  615. _st(self)._should_return_("foo ^ Array new add: 3; add: 4; yourself",[(3), (4)]);
  616. return self}, function($ctx1) {$ctx1.fill(self,"testCascades",{},smalltalk.CodeGeneratorTest)})},
  617. args: [],
  618. source: "testCascades\x0a\x09\x0a\x09self should: 'foo ^ Array new add: 3; add: 4; yourself' return: #(3 4)",
  619. messageSends: ["should:return:"],
  620. referencedClasses: []
  621. }),
  622. smalltalk.CodeGeneratorTest);
  623. smalltalk.addMethod(
  624. smalltalk.method({
  625. selector: "testDynamicArrayElementsOrdered",
  626. category: 'tests',
  627. fn: function (){
  628. var self=this;
  629. return smalltalk.withContext(function($ctx1) {
  630. _st(self)._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { x. true ifTrue: [ x := 2 ] }\x0a",[(1), (2)]);
  631. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicArrayElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  632. args: [],
  633. source: "testDynamicArrayElementsOrdered\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { x. true ifTrue: [ x := 2 ] }\x0a' return: #(1 2).",
  634. messageSends: ["should:return:"],
  635. referencedClasses: []
  636. }),
  637. smalltalk.CodeGeneratorTest);
  638. smalltalk.addMethod(
  639. smalltalk.method({
  640. selector: "testDynamicDictionaryElementsOrdered",
  641. category: 'tests',
  642. fn: function (){
  643. var self=this;
  644. return smalltalk.withContext(function($ctx1) {
  645. _st(self)._should_return_("foo\x0a\x09| x |\x0a\x09x := 'foo'->1.\x0a\x09^ #{ x. (true ifTrue: [ x := 'bar'->2 ]) }\x0a",smalltalk.HashedCollection._fromPairs_([_st("foo").__minus_gt((1)),_st("bar").__minus_gt((2))]));
  646. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicDictionaryElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  647. args: [],
  648. source: "testDynamicDictionaryElementsOrdered\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := ''foo''->1.\x0a\x09^ #{ x. (true ifTrue: [ x := ''bar''->2 ]) }\x0a' return: #{'foo'->1. 'bar'->2}.",
  649. messageSends: ["should:return:", "->"],
  650. referencedClasses: []
  651. }),
  652. smalltalk.CodeGeneratorTest);
  653. smalltalk.addMethod(
  654. smalltalk.method({
  655. selector: "testInnerTemporalDependentElementsOrdered",
  656. category: 'tests',
  657. fn: function (){
  658. var self=this;
  659. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  660. return smalltalk.withContext(function($ctx1) {
  661. _st(self)._should_return_("foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: 'foo'->x with: 'bar'->(true ifTrue: [ x := 2 ])\x0a",[_st("foo").__minus_gt($Array()),_st("bar").__minus_gt((2))]);
  662. _st(self)._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ Array with: 'foo'->x with: 'bar'->(true ifTrue: [ x := 2 ])\x0a",[_st("foo").__minus_gt((1)),_st("bar").__minus_gt((2))]);
  663. _st(self)._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { 'foo'->x. 'bar'->(true ifTrue: [ x := 2 ]) }\x0a",[_st("foo").__minus_gt((1)),_st("bar").__minus_gt((2))]);
  664. _st(self)._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ #{ 'foo'->x. 'bar'->(true ifTrue: [ x := 2 ]) }\x0a",smalltalk.HashedCollection._fromPairs_([_st("foo").__minus_gt((1)),_st("bar").__minus_gt((2))]));
  665. return self}, function($ctx1) {$ctx1.fill(self,"testInnerTemporalDependentElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  666. args: [],
  667. source: "testInnerTemporalDependentElementsOrdered\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: ''foo''->x with: ''bar''->(true ifTrue: [ x := 2 ])\x0a' return: {'foo'->Array. 'bar'->2}.\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ Array with: ''foo''->x with: ''bar''->(true ifTrue: [ x := 2 ])\x0a' return: {'foo'->1. 'bar'->2}.\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { ''foo''->x. ''bar''->(true ifTrue: [ x := 2 ]) }\x0a' return: {'foo'->1. 'bar'->2}.\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ #{ ''foo''->x. ''bar''->(true ifTrue: [ x := 2 ]) }\x0a' return: #{'foo'->1. 'bar'->2}.",
  668. messageSends: ["should:return:", "->"],
  669. referencedClasses: ["Array"]
  670. }),
  671. smalltalk.CodeGeneratorTest);
  672. smalltalk.addMethod(
  673. smalltalk.method({
  674. selector: "testLiterals",
  675. category: 'tests',
  676. fn: function (){
  677. var self=this;
  678. return smalltalk.withContext(function($ctx1) {
  679. _st(self)._should_return_("foo ^ 1",(1));
  680. _st(self)._should_return_("foo ^ 'hello'","hello");
  681. _st(self)._should_return_("foo ^ #(1 2 3 4)",[(1), (2), (3), (4)]);
  682. _st(self)._should_return_("foo ^ {1. [:x | x ] value: 2. 3. [4] value}",[(1), (2), (3), (4)]);
  683. _st(self)._should_return_("foo ^ true",true);
  684. _st(self)._should_return_("foo ^ false",false);
  685. _st(self)._should_return_("foo ^ #{1->2. 3->4}",smalltalk.HashedCollection._fromPairs_([_st((1)).__minus_gt((2)),_st((3)).__minus_gt((4))]));
  686. _st(self)._should_return_("foo ^ #hello","hello");
  687. _st(self)._should_return_("foo ^ -123.456",(-123.456));
  688. return self}, function($ctx1) {$ctx1.fill(self,"testLiterals",{},smalltalk.CodeGeneratorTest)})},
  689. args: [],
  690. 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",
  691. messageSends: ["should:return:", "->"],
  692. referencedClasses: []
  693. }),
  694. smalltalk.CodeGeneratorTest);
  695. smalltalk.addMethod(
  696. smalltalk.method({
  697. selector: "testLocalReturn",
  698. category: 'tests',
  699. fn: function (){
  700. var self=this;
  701. return smalltalk.withContext(function($ctx1) {
  702. _st(self)._should_return_("foo ^ 1",(1));
  703. _st(self)._should_return_("foo ^ 1 + 1",(2));
  704. _st(self)._should_return_("foo ",self["@receiver"]);
  705. _st(self)._should_return_("foo self asString",self["@receiver"]);
  706. _st(self)._should_return_("foo | a b | a := 1. b := 2. ^ a + b",(3));
  707. return self}, function($ctx1) {$ctx1.fill(self,"testLocalReturn",{},smalltalk.CodeGeneratorTest)})},
  708. args: [],
  709. 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",
  710. messageSends: ["should:return:"],
  711. referencedClasses: []
  712. }),
  713. smalltalk.CodeGeneratorTest);
  714. smalltalk.addMethod(
  715. smalltalk.method({
  716. selector: "testMessageSends",
  717. category: 'tests',
  718. fn: function (){
  719. var self=this;
  720. return smalltalk.withContext(function($ctx1) {
  721. _st(self)._should_return_("foo ^ 1 asString","1");
  722. _st(self)._should_return_("foo ^ 1 + 1",(2));
  723. _st(self)._should_return_("foo ^ 1 + 2 * 3",(9));
  724. _st(self)._should_return_("foo ^ 1 to: 3",[(1), (2), (3)]);
  725. _st(self)._should_return_("foo ^ 1 to: 5 by: 2",[(1), (3), (5)]);
  726. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSends",{},smalltalk.CodeGeneratorTest)})},
  727. args: [],
  728. 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)",
  729. messageSends: ["should:return:"],
  730. referencedClasses: []
  731. }),
  732. smalltalk.CodeGeneratorTest);
  733. smalltalk.addMethod(
  734. smalltalk.method({
  735. selector: "testMutableLiterals",
  736. category: 'tests',
  737. fn: function (){
  738. var self=this;
  739. return smalltalk.withContext(function($ctx1) {
  740. _st(self)._should_return_("foo ^ #( 1 2 ) at: 1 put: 3; yourself",[(3), (2)]);
  741. return self}, function($ctx1) {$ctx1.fill(self,"testMutableLiterals",{},smalltalk.CodeGeneratorTest)})},
  742. args: [],
  743. source: "testMutableLiterals\x0a\x09\x22Mutable literals must be aliased in cascades.\x0a\x09See https://github.com/amber-smalltalk/amber/issues/428\x22\x0a\x09\x0a\x09self \x0a\x09\x09should: 'foo ^ #( 1 2 ) at: 1 put: 3; yourself' \x0a\x09\x09return: #(3 2)",
  744. messageSends: ["should:return:"],
  745. referencedClasses: []
  746. }),
  747. smalltalk.CodeGeneratorTest);
  748. smalltalk.addMethod(
  749. smalltalk.method({
  750. selector: "testNestedIfTrue",
  751. category: 'tests',
  752. fn: function (){
  753. var self=this;
  754. return smalltalk.withContext(function($ctx1) {
  755. _st(self)._should_return_("foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]",(1));
  756. _st(self)._should_return_("foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]",nil);
  757. _st(self)._should_return_("foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]",(1));
  758. _st(self)._should_return_("foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]",self["@receiver"]);
  759. return self}, function($ctx1) {$ctx1.fill(self,"testNestedIfTrue",{},smalltalk.CodeGeneratorTest)})},
  760. args: [],
  761. 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.",
  762. messageSends: ["should:return:"],
  763. referencedClasses: []
  764. }),
  765. smalltalk.CodeGeneratorTest);
  766. smalltalk.addMethod(
  767. smalltalk.method({
  768. selector: "testNonLocalReturn",
  769. category: 'tests',
  770. fn: function (){
  771. var self=this;
  772. return smalltalk.withContext(function($ctx1) {
  773. _st(self)._should_return_("foo [ ^ 1 ] value",(1));
  774. _st(self)._should_return_("foo [ ^ 1 + 1 ] value",(2));
  775. _st(self)._should_return_("foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt",(3));
  776. _st(self)._should_return_("foo [ :x | ^ x + x ] value: 4. ^ 2",(8));
  777. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn",{},smalltalk.CodeGeneratorTest)})},
  778. args: [],
  779. 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",
  780. messageSends: ["should:return:"],
  781. referencedClasses: []
  782. }),
  783. smalltalk.CodeGeneratorTest);
  784. smalltalk.addMethod(
  785. smalltalk.method({
  786. selector: "testPascalCaseGlobal",
  787. category: 'tests',
  788. fn: function (){
  789. var self=this;
  790. return smalltalk.withContext(function($ctx1) {
  791. _st(self)._should_return_("foo ^Object",_st(smalltalk)._at_("Object"));
  792. _st(self)._should_return_("foo ^NonExistent",nil);
  793. return self}, function($ctx1) {$ctx1.fill(self,"testPascalCaseGlobal",{},smalltalk.CodeGeneratorTest)})},
  794. args: [],
  795. source: "testPascalCaseGlobal\x0a\x09self should: 'foo ^Object' return: (smalltalk at: 'Object').\x0a\x09self should: 'foo ^NonExistent' return: nil",
  796. messageSends: ["should:return:", "at:"],
  797. referencedClasses: []
  798. }),
  799. smalltalk.CodeGeneratorTest);
  800. smalltalk.addMethod(
  801. smalltalk.method({
  802. selector: "testSendReceiverAndArgumentsOrdered",
  803. category: 'tests',
  804. fn: function (){
  805. var self=this;
  806. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  807. return smalltalk.withContext(function($ctx1) {
  808. _st(self)._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ Array with: x with: (true ifTrue: [ x := 2 ])\x0a",[(1), (2)]);
  809. _st(self)._should_return_("foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: x with: (true ifTrue: [ x := 2 ])\x0a",[$Array(),(2)]);
  810. return self}, function($ctx1) {$ctx1.fill(self,"testSendReceiverAndArgumentsOrdered",{},smalltalk.CodeGeneratorTest)})},
  811. args: [],
  812. source: "testSendReceiverAndArgumentsOrdered\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ Array with: x with: (true ifTrue: [ x := 2 ])\x0a' return: #(1 2).\x0a\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: x with: (true ifTrue: [ x := 2 ])\x0a' return: {Array. 2}.",
  813. messageSends: ["should:return:"],
  814. referencedClasses: ["Array"]
  815. }),
  816. smalltalk.CodeGeneratorTest);
  817. smalltalk.addMethod(
  818. smalltalk.method({
  819. selector: "testifFalse",
  820. category: 'tests',
  821. fn: function (){
  822. var self=this;
  823. return smalltalk.withContext(function($ctx1) {
  824. _st(self)._should_return_("foo true ifFalse: [ ^ 1 ]",self["@receiver"]);
  825. _st(self)._should_return_("foo false ifFalse: [ ^ 2 ]",(2));
  826. _st(self)._should_return_("foo ^ true ifFalse: [ 1 ]",nil);
  827. _st(self)._should_return_("foo ^ false ifFalse: [ 2 ]",(2));
  828. return self}, function($ctx1) {$ctx1.fill(self,"testifFalse",{},smalltalk.CodeGeneratorTest)})},
  829. args: [],
  830. 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.",
  831. messageSends: ["should:return:"],
  832. referencedClasses: []
  833. }),
  834. smalltalk.CodeGeneratorTest);
  835. smalltalk.addMethod(
  836. smalltalk.method({
  837. selector: "testifFalseIfTrue",
  838. category: 'tests',
  839. fn: function (){
  840. var self=this;
  841. return smalltalk.withContext(function($ctx1) {
  842. _st(self)._should_return_("foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]",(2));
  843. _st(self)._should_return_("foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]",(2));
  844. _st(self)._should_return_("foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]",(2));
  845. _st(self)._should_return_("foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]",(2));
  846. return self}, function($ctx1) {$ctx1.fill(self,"testifFalseIfTrue",{},smalltalk.CodeGeneratorTest)})},
  847. args: [],
  848. 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.",
  849. messageSends: ["should:return:"],
  850. referencedClasses: []
  851. }),
  852. smalltalk.CodeGeneratorTest);
  853. smalltalk.addMethod(
  854. smalltalk.method({
  855. selector: "testifNil",
  856. category: 'tests',
  857. fn: function (){
  858. var self=this;
  859. return smalltalk.withContext(function($ctx1) {
  860. _st(self)._should_return_("foo ^ 1 ifNil: [ 2 ]",(1));
  861. _st(self)._should_return_("foo ^ nil ifNil: [ 2 ]",(2));
  862. _st(self)._should_return_("foo 1 ifNil: [ ^ 2 ]",self["@receiver"]);
  863. _st(self)._should_return_("foo nil ifNil: [ ^ 2 ]",(2));
  864. return self}, function($ctx1) {$ctx1.fill(self,"testifNil",{},smalltalk.CodeGeneratorTest)})},
  865. args: [],
  866. 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.",
  867. messageSends: ["should:return:"],
  868. referencedClasses: []
  869. }),
  870. smalltalk.CodeGeneratorTest);
  871. smalltalk.addMethod(
  872. smalltalk.method({
  873. selector: "testifNilIfNotNil",
  874. category: 'tests',
  875. fn: function (){
  876. var self=this;
  877. return smalltalk.withContext(function($ctx1) {
  878. _st(self)._should_return_("foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]",(3));
  879. _st(self)._should_return_("foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]",(2));
  880. _st(self)._should_return_("foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(3));
  881. _st(self)._should_return_("foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(2));
  882. return self}, function($ctx1) {$ctx1.fill(self,"testifNilIfNotNil",{},smalltalk.CodeGeneratorTest)})},
  883. args: [],
  884. 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.",
  885. messageSends: ["should:return:"],
  886. referencedClasses: []
  887. }),
  888. smalltalk.CodeGeneratorTest);
  889. smalltalk.addMethod(
  890. smalltalk.method({
  891. selector: "testifNotNil",
  892. category: 'tests',
  893. fn: function (){
  894. var self=this;
  895. return smalltalk.withContext(function($ctx1) {
  896. _st(self)._should_return_("foo ^ 1 ifNotNil: [ 2 ]",(2));
  897. _st(self)._should_return_("foo ^ nil ifNotNil: [ 2 ]",nil);
  898. _st(self)._should_return_("foo 1 ifNotNil: [ ^ 2 ]",(2));
  899. _st(self)._should_return_("foo nil ifNotNil: [ ^ 2 ]",self["@receiver"]);
  900. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNil",{},smalltalk.CodeGeneratorTest)})},
  901. args: [],
  902. 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.",
  903. messageSends: ["should:return:"],
  904. referencedClasses: []
  905. }),
  906. smalltalk.CodeGeneratorTest);
  907. smalltalk.addMethod(
  908. smalltalk.method({
  909. selector: "testifNotNilWithArgument",
  910. category: 'tests',
  911. fn: function (){
  912. var self=this;
  913. return smalltalk.withContext(function($ctx1) {
  914. _st(self)._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ]",(3));
  915. _st(self)._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ]",nil);
  916. _st(self)._should_return_("foo ^ 1 ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(3));
  917. _st(self)._should_return_("foo ^ nil ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(5));
  918. _st(self)._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(3));
  919. _st(self)._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(5));
  920. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNilWithArgument",{},smalltalk.CodeGeneratorTest)})},
  921. args: [],
  922. source: "testifNotNilWithArgument\x0a\x09self should: 'foo ^ 1 ifNotNil: [ :val | val + 2 ]' return: 3.\x0a\x09self should: 'foo ^ nil ifNotNil: [ :val | val + 2 ]' return: nil.\x0a\x09\x0a\x09self should: 'foo ^ 1 ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]' return: 3.\x0a\x09self should: 'foo ^ nil ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]' return: 5.\x0a\x09\x0a\x09self should: 'foo ^ 1 ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]' return: 3.\x0a\x09self should: 'foo ^ nil ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]' return: 5",
  923. messageSends: ["should:return:"],
  924. referencedClasses: []
  925. }),
  926. smalltalk.CodeGeneratorTest);
  927. smalltalk.addMethod(
  928. smalltalk.method({
  929. selector: "testifTrue",
  930. category: 'tests',
  931. fn: function (){
  932. var self=this;
  933. return smalltalk.withContext(function($ctx1) {
  934. _st(self)._should_return_("foo false ifTrue: [ ^ 1 ]",self["@receiver"]);
  935. _st(self)._should_return_("foo true ifTrue: [ ^ 2 ]",(2));
  936. _st(self)._should_return_("foo ^ false ifTrue: [ 1 ]",nil);
  937. _st(self)._should_return_("foo ^ true ifTrue: [ 2 ]",(2));
  938. return self}, function($ctx1) {$ctx1.fill(self,"testifTrue",{},smalltalk.CodeGeneratorTest)})},
  939. args: [],
  940. 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.",
  941. messageSends: ["should:return:"],
  942. referencedClasses: []
  943. }),
  944. smalltalk.CodeGeneratorTest);
  945. smalltalk.addMethod(
  946. smalltalk.method({
  947. selector: "testifTrueIfFalse",
  948. category: 'tests',
  949. fn: function (){
  950. var self=this;
  951. return smalltalk.withContext(function($ctx1) {
  952. _st(self)._should_return_("foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]",(2));
  953. _st(self)._should_return_("foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]",(1));
  954. _st(self)._should_return_("foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]",(1));
  955. _st(self)._should_return_("foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]",(2));
  956. return self}, function($ctx1) {$ctx1.fill(self,"testifTrueIfFalse",{},smalltalk.CodeGeneratorTest)})},
  957. args: [],
  958. 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.",
  959. messageSends: ["should:return:"],
  960. referencedClasses: []
  961. }),
  962. smalltalk.CodeGeneratorTest);
  963. smalltalk.addClass('InliningCodeGeneratorTest', smalltalk.CodeGeneratorTest, [], 'Compiler-Tests');
  964. smalltalk.addMethod(
  965. smalltalk.method({
  966. selector: "codeGeneratorClass",
  967. category: 'accessing',
  968. fn: function (){
  969. var self=this;
  970. function $InliningCodeGenerator(){return smalltalk.InliningCodeGenerator||(typeof InliningCodeGenerator=="undefined"?nil:InliningCodeGenerator)}
  971. return smalltalk.withContext(function($ctx1) {
  972. var $1;
  973. $1=$InliningCodeGenerator();
  974. return $1;
  975. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{},smalltalk.InliningCodeGeneratorTest)})},
  976. args: [],
  977. source: "codeGeneratorClass\x0a\x09^ InliningCodeGenerator",
  978. messageSends: [],
  979. referencedClasses: ["InliningCodeGenerator"]
  980. }),
  981. smalltalk.InliningCodeGeneratorTest);
  982. smalltalk.addClass('ScopeVarTest', smalltalk.TestCase, [], 'Compiler-Tests');
  983. smalltalk.addMethod(
  984. smalltalk.method({
  985. selector: "testClassRefVar",
  986. category: 'tests',
  987. fn: function (){
  988. var self=this;
  989. var node;
  990. function $ClassReferenceNode(){return smalltalk.ClassReferenceNode||(typeof ClassReferenceNode=="undefined"?nil:ClassReferenceNode)}
  991. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  992. return smalltalk.withContext(function($ctx1) {
  993. var $1,$2;
  994. $1=_st($ClassReferenceNode())._new();
  995. _st($1)._value_("Object");
  996. $2=_st($1)._yourself();
  997. node=$2;
  998. _st(_st($SemanticAnalyzer())._new())._visit_(node);
  999. _st(self)._assert_(_st(_st(node)._binding())._isClassRefVar());
  1000. return self}, function($ctx1) {$ctx1.fill(self,"testClassRefVar",{node:node},smalltalk.ScopeVarTest)})},
  1001. args: [],
  1002. 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",
  1003. messageSends: ["value:", "new", "yourself", "visit:", "assert:", "isClassRefVar", "binding"],
  1004. referencedClasses: ["ClassReferenceNode", "SemanticAnalyzer"]
  1005. }),
  1006. smalltalk.ScopeVarTest);
  1007. smalltalk.addMethod(
  1008. smalltalk.method({
  1009. selector: "testInstanceVar",
  1010. category: 'tests',
  1011. fn: function (){
  1012. var self=this;
  1013. var node,scope;
  1014. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1015. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1016. return smalltalk.withContext(function($ctx1) {
  1017. var $1,$2;
  1018. $1=_st($VariableNode())._new();
  1019. _st($1)._value_("bzzz");
  1020. $2=_st($1)._yourself();
  1021. node=$2;
  1022. scope=_st($MethodLexicalScope())._new();
  1023. _st(scope)._addIVar_("bzzz");
  1024. _st(self)._assert_(_st(_st(scope)._bindingFor_(node))._isInstanceVar());
  1025. return self}, function($ctx1) {$ctx1.fill(self,"testInstanceVar",{node:node,scope:scope},smalltalk.ScopeVarTest)})},
  1026. args: [],
  1027. 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",
  1028. messageSends: ["value:", "new", "yourself", "addIVar:", "assert:", "isInstanceVar", "bindingFor:"],
  1029. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1030. }),
  1031. smalltalk.ScopeVarTest);
  1032. smalltalk.addMethod(
  1033. smalltalk.method({
  1034. selector: "testPseudoVar",
  1035. category: 'tests',
  1036. fn: function (){
  1037. var self=this;
  1038. var node,pseudoVars;
  1039. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1040. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1041. return smalltalk.withContext(function($ctx1) {
  1042. var $1,$2;
  1043. pseudoVars=["self", "super", "true", "false", "nil"];
  1044. _st(pseudoVars)._do_((function(each){
  1045. return smalltalk.withContext(function($ctx2) {
  1046. $1=_st($VariableNode())._new();
  1047. _st($1)._value_(each);
  1048. $2=_st($1)._yourself();
  1049. node=$2;
  1050. node;
  1051. return _st(self)._assert_(_st(_st(_st($MethodLexicalScope())._new())._bindingFor_(node))._isPseudoVar());
  1052. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  1053. return self}, function($ctx1) {$ctx1.fill(self,"testPseudoVar",{node:node,pseudoVars:pseudoVars},smalltalk.ScopeVarTest)})},
  1054. args: [],
  1055. 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 ]",
  1056. messageSends: ["do:", "value:", "new", "yourself", "assert:", "isPseudoVar", "bindingFor:"],
  1057. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1058. }),
  1059. smalltalk.ScopeVarTest);
  1060. smalltalk.addMethod(
  1061. smalltalk.method({
  1062. selector: "testTempVar",
  1063. category: 'tests',
  1064. fn: function (){
  1065. var self=this;
  1066. var node,scope;
  1067. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1068. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1069. return smalltalk.withContext(function($ctx1) {
  1070. var $1,$2;
  1071. $1=_st($VariableNode())._new();
  1072. _st($1)._value_("bzzz");
  1073. $2=_st($1)._yourself();
  1074. node=$2;
  1075. scope=_st($MethodLexicalScope())._new();
  1076. _st(scope)._addTemp_("bzzz");
  1077. _st(self)._assert_(_st(_st(scope)._bindingFor_(node))._isTempVar());
  1078. return self}, function($ctx1) {$ctx1.fill(self,"testTempVar",{node:node,scope:scope},smalltalk.ScopeVarTest)})},
  1079. args: [],
  1080. 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",
  1081. messageSends: ["value:", "new", "yourself", "addTemp:", "assert:", "isTempVar", "bindingFor:"],
  1082. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1083. }),
  1084. smalltalk.ScopeVarTest);
  1085. smalltalk.addMethod(
  1086. smalltalk.method({
  1087. selector: "testUnknownVar",
  1088. category: 'tests',
  1089. fn: function (){
  1090. var self=this;
  1091. var node;
  1092. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1093. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1094. return smalltalk.withContext(function($ctx1) {
  1095. var $1,$2;
  1096. $1=_st($VariableNode())._new();
  1097. _st($1)._value_("bzzz");
  1098. $2=_st($1)._yourself();
  1099. node=$2;
  1100. _st(self)._assert_(_st(_st(_st($MethodLexicalScope())._new())._bindingFor_(node))._isNil());
  1101. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVar",{node:node},smalltalk.ScopeVarTest)})},
  1102. args: [],
  1103. source: "testUnknownVar\x0a\x09| node |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09self assert: (MethodLexicalScope new bindingFor: node) isNil",
  1104. messageSends: ["value:", "new", "yourself", "assert:", "isNil", "bindingFor:"],
  1105. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1106. }),
  1107. smalltalk.ScopeVarTest);
  1108. smalltalk.addClass('SemanticAnalyzerTest', smalltalk.TestCase, ['analyzer'], 'Compiler-Tests');
  1109. smalltalk.addMethod(
  1110. smalltalk.method({
  1111. selector: "setUp",
  1112. category: 'running',
  1113. fn: function (){
  1114. var self=this;
  1115. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  1116. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1117. return smalltalk.withContext(function($ctx1) {
  1118. self["@analyzer"]=_st($SemanticAnalyzer())._on_($Object());
  1119. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},smalltalk.SemanticAnalyzerTest)})},
  1120. args: [],
  1121. source: "setUp\x0a\x09analyzer := SemanticAnalyzer on: Object",
  1122. messageSends: ["on:"],
  1123. referencedClasses: ["Object", "SemanticAnalyzer"]
  1124. }),
  1125. smalltalk.SemanticAnalyzerTest);
  1126. smalltalk.addMethod(
  1127. smalltalk.method({
  1128. selector: "testAssignment",
  1129. category: 'tests',
  1130. fn: function (){
  1131. var self=this;
  1132. var src,ast;
  1133. function $InvalidAssignmentError(){return smalltalk.InvalidAssignmentError||(typeof InvalidAssignmentError=="undefined"?nil:InvalidAssignmentError)}
  1134. return smalltalk.withContext(function($ctx1) {
  1135. src="foo self := 1";
  1136. ast=_st(smalltalk)._parse_(src);
  1137. _st(self)._should_raise_((function(){
  1138. return smalltalk.withContext(function($ctx2) {
  1139. return _st(self["@analyzer"])._visit_(ast);
  1140. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$InvalidAssignmentError());
  1141. return self}, function($ctx1) {$ctx1.fill(self,"testAssignment",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1142. args: [],
  1143. 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",
  1144. messageSends: ["parse:", "should:raise:", "visit:"],
  1145. referencedClasses: ["InvalidAssignmentError"]
  1146. }),
  1147. smalltalk.SemanticAnalyzerTest);
  1148. smalltalk.addMethod(
  1149. smalltalk.method({
  1150. selector: "testNonLocalReturn",
  1151. category: 'tests',
  1152. fn: function (){
  1153. var self=this;
  1154. var src,ast;
  1155. return smalltalk.withContext(function($ctx1) {
  1156. src="foo | a | a + 1. ^ a";
  1157. ast=_st(smalltalk)._parse_(src);
  1158. _st(self["@analyzer"])._visit_(ast);
  1159. _st(self)._deny_(_st(_st(ast)._scope())._hasNonLocalReturn());
  1160. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1161. args: [],
  1162. 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",
  1163. messageSends: ["parse:", "visit:", "deny:", "hasNonLocalReturn", "scope"],
  1164. referencedClasses: []
  1165. }),
  1166. smalltalk.SemanticAnalyzerTest);
  1167. smalltalk.addMethod(
  1168. smalltalk.method({
  1169. selector: "testNonLocalReturn2",
  1170. category: 'tests',
  1171. fn: function (){
  1172. var self=this;
  1173. var src,ast;
  1174. return smalltalk.withContext(function($ctx1) {
  1175. src="foo | a | a + 1. [ [ ^ a] ]";
  1176. ast=_st(smalltalk)._parse_(src);
  1177. _st(self["@analyzer"])._visit_(ast);
  1178. _st(self)._assert_(_st(_st(ast)._scope())._hasNonLocalReturn());
  1179. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1180. args: [],
  1181. 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",
  1182. messageSends: ["parse:", "visit:", "assert:", "hasNonLocalReturn", "scope"],
  1183. referencedClasses: []
  1184. }),
  1185. smalltalk.SemanticAnalyzerTest);
  1186. smalltalk.addMethod(
  1187. smalltalk.method({
  1188. selector: "testScope",
  1189. category: 'tests',
  1190. fn: function (){
  1191. var self=this;
  1192. var src,ast;
  1193. return smalltalk.withContext(function($ctx1) {
  1194. src="foo | a | a + 1. [ | b | b := a ]";
  1195. ast=_st(smalltalk)._parse_(src);
  1196. _st(self["@analyzer"])._visit_(ast);
  1197. _st(self)._deny_(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._last())._scope()).__eq_eq(_st(ast)._scope()));
  1198. return self}, function($ctx1) {$ctx1.fill(self,"testScope",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1199. args: [],
  1200. 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.",
  1201. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "last", "nodes", "first"],
  1202. referencedClasses: []
  1203. }),
  1204. smalltalk.SemanticAnalyzerTest);
  1205. smalltalk.addMethod(
  1206. smalltalk.method({
  1207. selector: "testScope2",
  1208. category: 'tests',
  1209. fn: function (){
  1210. var self=this;
  1211. var src,ast;
  1212. return smalltalk.withContext(function($ctx1) {
  1213. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1214. ast=_st(smalltalk)._parse_(src);
  1215. _st(self["@analyzer"])._visit_(ast);
  1216. _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()));
  1217. return self}, function($ctx1) {$ctx1.fill(self,"testScope2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1218. args: [],
  1219. 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.",
  1220. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "first", "nodes", "last"],
  1221. referencedClasses: []
  1222. }),
  1223. smalltalk.SemanticAnalyzerTest);
  1224. smalltalk.addMethod(
  1225. smalltalk.method({
  1226. selector: "testScopeLevel",
  1227. category: 'tests',
  1228. fn: function (){
  1229. var self=this;
  1230. var src,ast;
  1231. return smalltalk.withContext(function($ctx1) {
  1232. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1233. ast=_st(smalltalk)._parse_(src);
  1234. _st(self["@analyzer"])._visit_(ast);
  1235. _st(self)._assert_equals_(_st(_st(ast)._scope())._scopeLevel(),(1));
  1236. _st(self)._assert_equals_(_st(_st(_st(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._last())._nodes())._first())._nodes())._first())._scope())._scopeLevel(),(3));
  1237. return self}, function($ctx1) {$ctx1.fill(self,"testScopeLevel",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1238. args: [],
  1239. 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 equals: 1.\x0a\x09self assert: ast nodes first nodes last nodes first nodes first scope scopeLevel equals: 3",
  1240. messageSends: ["parse:", "visit:", "assert:equals:", "scopeLevel", "scope", "first", "nodes", "last"],
  1241. referencedClasses: []
  1242. }),
  1243. smalltalk.SemanticAnalyzerTest);
  1244. smalltalk.addMethod(
  1245. smalltalk.method({
  1246. selector: "testUnknownVariables",
  1247. category: 'tests',
  1248. fn: function (){
  1249. var self=this;
  1250. var src,ast;
  1251. function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1252. return smalltalk.withContext(function($ctx1) {
  1253. src="foo | a | b + a";
  1254. ast=_st(smalltalk)._parse_(src);
  1255. _st(self)._should_raise_((function(){
  1256. return smalltalk.withContext(function($ctx2) {
  1257. return _st(self["@analyzer"])._visit_(ast);
  1258. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$UnknownVariableError());
  1259. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariables",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1260. args: [],
  1261. 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",
  1262. messageSends: ["parse:", "should:raise:", "visit:"],
  1263. referencedClasses: ["UnknownVariableError"]
  1264. }),
  1265. smalltalk.SemanticAnalyzerTest);
  1266. smalltalk.addMethod(
  1267. smalltalk.method({
  1268. selector: "testUnknownVariablesWithScope",
  1269. category: 'tests',
  1270. fn: function (){
  1271. var self=this;
  1272. var src,ast;
  1273. function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1274. return smalltalk.withContext(function($ctx1) {
  1275. src="foo | a b | [ c + 1. [ a + 1. d + 1 ]]";
  1276. ast=_st(smalltalk)._parse_(src);
  1277. _st(self)._should_raise_((function(){
  1278. return smalltalk.withContext(function($ctx2) {
  1279. return _st(self["@analyzer"])._visit_(ast);
  1280. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$UnknownVariableError());
  1281. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariablesWithScope",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1282. args: [],
  1283. 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",
  1284. messageSends: ["parse:", "should:raise:", "visit:"],
  1285. referencedClasses: ["UnknownVariableError"]
  1286. }),
  1287. smalltalk.SemanticAnalyzerTest);
  1288. smalltalk.addMethod(
  1289. smalltalk.method({
  1290. selector: "testVariableShadowing",
  1291. category: 'tests',
  1292. fn: function (){
  1293. var self=this;
  1294. var src,ast;
  1295. return smalltalk.withContext(function($ctx1) {
  1296. src="foo | a | a + 1";
  1297. ast=_st(smalltalk)._parse_(src);
  1298. _st(self["@analyzer"])._visit_(ast);
  1299. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1300. args: [],
  1301. source: "testVariableShadowing\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1302. messageSends: ["parse:", "visit:"],
  1303. referencedClasses: []
  1304. }),
  1305. smalltalk.SemanticAnalyzerTest);
  1306. smalltalk.addMethod(
  1307. smalltalk.method({
  1308. selector: "testVariableShadowing2",
  1309. category: 'tests',
  1310. fn: function (){
  1311. var self=this;
  1312. var src,ast;
  1313. function $ShadowingVariableError(){return smalltalk.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1314. return smalltalk.withContext(function($ctx1) {
  1315. src="foo | a | a + 1. [ | a | a := 2 ]";
  1316. ast=_st(smalltalk)._parse_(src);
  1317. _st(self)._should_raise_((function(){
  1318. return smalltalk.withContext(function($ctx2) {
  1319. return _st(self["@analyzer"])._visit_(ast);
  1320. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$ShadowingVariableError());
  1321. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1322. args: [],
  1323. 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",
  1324. messageSends: ["parse:", "should:raise:", "visit:"],
  1325. referencedClasses: ["ShadowingVariableError"]
  1326. }),
  1327. smalltalk.SemanticAnalyzerTest);
  1328. smalltalk.addMethod(
  1329. smalltalk.method({
  1330. selector: "testVariableShadowing3",
  1331. category: 'tests',
  1332. fn: function (){
  1333. var self=this;
  1334. var src,ast;
  1335. return smalltalk.withContext(function($ctx1) {
  1336. src="foo | a | a + 1. [ | b | b := 2 ]";
  1337. ast=_st(smalltalk)._parse_(src);
  1338. _st(self["@analyzer"])._visit_(ast);
  1339. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing3",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1340. args: [],
  1341. source: "testVariableShadowing3\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | b | b := 2 ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1342. messageSends: ["parse:", "visit:"],
  1343. referencedClasses: []
  1344. }),
  1345. smalltalk.SemanticAnalyzerTest);
  1346. smalltalk.addMethod(
  1347. smalltalk.method({
  1348. selector: "testVariableShadowing4",
  1349. category: 'tests',
  1350. fn: function (){
  1351. var self=this;
  1352. var src,ast;
  1353. return smalltalk.withContext(function($ctx1) {
  1354. src="foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]";
  1355. ast=_st(smalltalk)._parse_(src);
  1356. _st(self["@analyzer"])._visit_(ast);
  1357. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing4",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1358. args: [],
  1359. source: "testVariableShadowing4\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1360. messageSends: ["parse:", "visit:"],
  1361. referencedClasses: []
  1362. }),
  1363. smalltalk.SemanticAnalyzerTest);
  1364. smalltalk.addMethod(
  1365. smalltalk.method({
  1366. selector: "testVariableShadowing5",
  1367. category: 'tests',
  1368. fn: function (){
  1369. var self=this;
  1370. var src,ast;
  1371. function $ShadowingVariableError(){return smalltalk.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1372. return smalltalk.withContext(function($ctx1) {
  1373. src="foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]";
  1374. ast=_st(smalltalk)._parse_(src);
  1375. _st(self)._should_raise_((function(){
  1376. return smalltalk.withContext(function($ctx2) {
  1377. return _st(self["@analyzer"])._visit_(ast);
  1378. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$ShadowingVariableError());
  1379. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing5",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1380. args: [],
  1381. 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",
  1382. messageSends: ["parse:", "should:raise:", "visit:"],
  1383. referencedClasses: ["ShadowingVariableError"]
  1384. }),
  1385. smalltalk.SemanticAnalyzerTest);
  1386. smalltalk.addMethod(
  1387. smalltalk.method({
  1388. selector: "testVariablesLookup",
  1389. category: 'tests',
  1390. fn: function (){
  1391. var self=this;
  1392. var src,ast;
  1393. return smalltalk.withContext(function($ctx1) {
  1394. src="foo | a | a + 1. [ | b | b := a ]";
  1395. ast=_st(smalltalk)._parse_(src);
  1396. _st(self["@analyzer"])._visit_(ast);
  1397. _st(self)._assert_(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._first())._receiver())._binding())._isTempVar());
  1398. _st(self)._assert_(_st(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._first())._receiver())._binding())._scope()).__eq_eq(_st(ast)._scope()));
  1399. _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());
  1400. _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()));
  1401. return self}, function($ctx1) {$ctx1.fill(self,"testVariablesLookup",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1402. args: [],
  1403. 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.",
  1404. messageSends: ["parse:", "visit:", "assert:", "isTempVar", "binding", "receiver", "first", "nodes", "==", "scope", "left", "last"],
  1405. referencedClasses: []
  1406. }),
  1407. smalltalk.SemanticAnalyzerTest);