Compiler-Tests.js 69 KB

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