1
0

Compiler-Tests.js 63 KB

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