1
0

Compiler-Tests.js 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534
  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.addClass('ASTSteppingInterpreterTest', smalltalk.AbstractASTInterpreterTest, ['interpreter'], 'Compiler-Tests');
  348. smalltalk.addMethod(
  349. "_interpreter",
  350. smalltalk.method({
  351. selector: "interpreter",
  352. category: 'accessing',
  353. fn: function (){
  354. var self=this;
  355. function $ASTSteppingInterpreter(){return smalltalk.ASTSteppingInterpreter||(typeof ASTSteppingInterpreter=="undefined"?nil:ASTSteppingInterpreter)}
  356. return smalltalk.withContext(function($ctx1) {
  357. var $2,$1;
  358. $2=self["@interpreter"];
  359. if(($receiver = $2) == nil || $receiver == undefined){
  360. self["@interpreter"]=_st($ASTSteppingInterpreter())._new();
  361. $1=self["@interpreter"];
  362. } else {
  363. $1=$2;
  364. };
  365. return $1;
  366. }, function($ctx1) {$ctx1.fill(self,"interpreter",{},smalltalk.ASTSteppingInterpreterTest)})},
  367. args: [],
  368. source: "interpreter\x0a\x09^ interpreter ifNil: [ interpreter := ASTSteppingInterpreter new ]",
  369. messageSends: ["ifNil:", "new"],
  370. referencedClasses: ["ASTSteppingInterpreter"]
  371. }),
  372. smalltalk.ASTSteppingInterpreterTest);
  373. smalltalk.addMethod(
  374. "_testAtEnd",
  375. smalltalk.method({
  376. selector: "testAtEnd",
  377. category: 'tests',
  378. fn: function (){
  379. var self=this;
  380. return smalltalk.withContext(function($ctx1) {
  381. _st(self)._interpret_("foo 1 + 2");
  382. _st(self)._deny_(_st(_st(self)._interpreter())._atEnd());
  383. _st(_st(self)._interpreter())._step();
  384. _st(self)._deny_(_st(_st(self)._interpreter())._atEnd());
  385. _st(_st(self)._interpreter())._step();
  386. _st(self)._deny_(_st(_st(self)._interpreter())._atEnd());
  387. _st(_st(self)._interpreter())._step();
  388. _st(self)._deny_(_st(_st(self)._interpreter())._atEnd());
  389. _st(_st(self)._interpreter())._step();
  390. _st(self)._assert_(_st(_st(self)._interpreter())._atEnd());
  391. return self}, function($ctx1) {$ctx1.fill(self,"testAtEnd",{},smalltalk.ASTSteppingInterpreterTest)})},
  392. args: [],
  393. 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",
  394. messageSends: ["interpret:", "deny:", "atEnd", "interpreter", "step", "assert:"],
  395. referencedClasses: []
  396. }),
  397. smalltalk.ASTSteppingInterpreterTest);
  398. smalltalk.addMethod(
  399. "_testMessageSend",
  400. smalltalk.method({
  401. selector: "testMessageSend",
  402. category: 'tests',
  403. fn: function (){
  404. var self=this;
  405. return smalltalk.withContext(function($ctx1) {
  406. _st(self)._interpret_("foo 1 + 2");
  407. _st(_st(self)._interpreter())._step();
  408. _st(_st(self)._interpreter())._step();
  409. _st(_st(self)._interpreter())._step();
  410. _st(self)._assert_equals_(_st(_st(_st(self)._interpreter())._currentNode())._value(),(1));
  411. _st(_st(self)._interpreter())._step();
  412. _st(self)._assert_equals_(_st(_st(_st(self)._interpreter())._currentNode())._value(),(2));
  413. _st(_st(self)._interpreter())._step();
  414. _st(self)._assert_equals_(_st(_st(self)._interpreter())._result(),(3));
  415. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSend",{},smalltalk.ASTSteppingInterpreterTest)})},
  416. args: [],
  417. 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",
  418. messageSends: ["interpret:", "step", "interpreter", "assert:equals:", "value", "currentNode", "result"],
  419. referencedClasses: []
  420. }),
  421. smalltalk.ASTSteppingInterpreterTest);
  422. smalltalk.addMethod(
  423. "_testSimpleStepping",
  424. smalltalk.method({
  425. selector: "testSimpleStepping",
  426. category: 'tests',
  427. fn: function (){
  428. var self=this;
  429. return smalltalk.withContext(function($ctx1) {
  430. _st(self)._interpret_("foo 1");
  431. _st(_st(self)._interpreter())._step();
  432. _st(self)._assert_(_st(_st(_st(self)._interpreter())._result())._isNil());
  433. _st(_st(self)._interpreter())._step();
  434. _st(self)._assert_equals_(_st(_st(self)._interpreter())._result(),(1));
  435. return self}, function($ctx1) {$ctx1.fill(self,"testSimpleStepping",{},smalltalk.ASTSteppingInterpreterTest)})},
  436. args: [],
  437. 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",
  438. messageSends: ["interpret:", "step", "interpreter", "assert:", "isNil", "result", "assert:equals:"],
  439. referencedClasses: []
  440. }),
  441. smalltalk.ASTSteppingInterpreterTest);
  442. smalltalk.addClass('CodeGeneratorTest', smalltalk.TestCase, ['receiver'], 'Compiler-Tests');
  443. smalltalk.addMethod(
  444. "_codeGeneratorClass",
  445. smalltalk.method({
  446. selector: "codeGeneratorClass",
  447. category: 'accessing',
  448. fn: function (){
  449. var self=this;
  450. function $CodeGenerator(){return smalltalk.CodeGenerator||(typeof CodeGenerator=="undefined"?nil:CodeGenerator)}
  451. return smalltalk.withContext(function($ctx1) {
  452. var $1;
  453. $1=$CodeGenerator();
  454. return $1;
  455. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{},smalltalk.CodeGeneratorTest)})},
  456. args: [],
  457. source: "codeGeneratorClass\x0a\x09^ CodeGenerator",
  458. messageSends: [],
  459. referencedClasses: ["CodeGenerator"]
  460. }),
  461. smalltalk.CodeGeneratorTest);
  462. smalltalk.addMethod(
  463. "_compiler",
  464. smalltalk.method({
  465. selector: "compiler",
  466. category: 'factory',
  467. fn: function (){
  468. var self=this;
  469. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  470. return smalltalk.withContext(function($ctx1) {
  471. var $2,$3,$1;
  472. $2=_st($Compiler())._new();
  473. _st($2)._codeGeneratorClass_(_st(self)._codeGeneratorClass());
  474. $3=_st($2)._yourself();
  475. $1=$3;
  476. return $1;
  477. }, function($ctx1) {$ctx1.fill(self,"compiler",{},smalltalk.CodeGeneratorTest)})},
  478. args: [],
  479. source: "compiler\x0a\x09^ Compiler new\x0a\x09\x09codeGeneratorClass: self codeGeneratorClass;\x0a\x09\x09yourself",
  480. messageSends: ["codeGeneratorClass:", "codeGeneratorClass", "new", "yourself"],
  481. referencedClasses: ["Compiler"]
  482. }),
  483. smalltalk.CodeGeneratorTest);
  484. smalltalk.addMethod(
  485. "_setUp",
  486. smalltalk.method({
  487. selector: "setUp",
  488. category: 'initialization',
  489. fn: function (){
  490. var self=this;
  491. return smalltalk.withContext(function($ctx1) {
  492. self["@receiver"]=_st(_st(self)._targetClass())._new();
  493. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},smalltalk.CodeGeneratorTest)})},
  494. args: [],
  495. source: "setUp\x0a\x09receiver := self targetClass new",
  496. messageSends: ["new", "targetClass"],
  497. referencedClasses: []
  498. }),
  499. smalltalk.CodeGeneratorTest);
  500. smalltalk.addMethod(
  501. "_should_return_",
  502. smalltalk.method({
  503. selector: "should:return:",
  504. category: 'testing',
  505. fn: function (aString,anObject){
  506. var self=this;
  507. var method,result;
  508. return smalltalk.withContext(function($ctx1) {
  509. method=_st(_st(self)._compiler())._install_forClass_category_(aString,_st(self)._targetClass(),"tests");
  510. result=_st(self["@receiver"])._perform_(_st(method)._selector());
  511. _st(_st(self)._targetClass())._removeCompiledMethod_(method);
  512. _st(self)._assert_equals_(anObject,result);
  513. return self}, function($ctx1) {$ctx1.fill(self,"should:return:",{aString:aString,anObject:anObject,method:method,result:result},smalltalk.CodeGeneratorTest)})},
  514. args: ["aString", "anObject"],
  515. 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",
  516. messageSends: ["install:forClass:category:", "targetClass", "compiler", "perform:", "selector", "removeCompiledMethod:", "assert:equals:"],
  517. referencedClasses: []
  518. }),
  519. smalltalk.CodeGeneratorTest);
  520. smalltalk.addMethod(
  521. "_targetClass",
  522. smalltalk.method({
  523. selector: "targetClass",
  524. category: 'accessing',
  525. fn: function (){
  526. var self=this;
  527. function $DoIt(){return smalltalk.DoIt||(typeof DoIt=="undefined"?nil:DoIt)}
  528. return smalltalk.withContext(function($ctx1) {
  529. var $1;
  530. $1=$DoIt();
  531. return $1;
  532. }, function($ctx1) {$ctx1.fill(self,"targetClass",{},smalltalk.CodeGeneratorTest)})},
  533. args: [],
  534. source: "targetClass\x0a\x09^ DoIt",
  535. messageSends: [],
  536. referencedClasses: ["DoIt"]
  537. }),
  538. smalltalk.CodeGeneratorTest);
  539. smalltalk.addMethod(
  540. "_tearDown",
  541. smalltalk.method({
  542. selector: "tearDown",
  543. category: 'initialization',
  544. fn: function (){
  545. var self=this;
  546. return smalltalk.withContext(function($ctx1) {
  547. return self}, function($ctx1) {$ctx1.fill(self,"tearDown",{},smalltalk.CodeGeneratorTest)})},
  548. args: [],
  549. source: "tearDown\x0a\x09\x22receiver := nil\x22",
  550. messageSends: [],
  551. referencedClasses: []
  552. }),
  553. smalltalk.CodeGeneratorTest);
  554. smalltalk.addMethod(
  555. "_testAssignment",
  556. smalltalk.method({
  557. selector: "testAssignment",
  558. category: 'tests',
  559. fn: function (){
  560. var self=this;
  561. return smalltalk.withContext(function($ctx1) {
  562. _st(self)._should_return_("foo | a | a := true ifTrue: [ 1 ]. ^ a",(1));
  563. _st(self)._should_return_("foo | a | a := false ifTrue: [ 1 ]. ^ a",nil);
  564. _st(self)._should_return_("foo | a | ^ a := true ifTrue: [ 1 ]",(1));
  565. return self}, function($ctx1) {$ctx1.fill(self,"testAssignment",{},smalltalk.CodeGeneratorTest)})},
  566. args: [],
  567. 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",
  568. messageSends: ["should:return:"],
  569. referencedClasses: []
  570. }),
  571. smalltalk.CodeGeneratorTest);
  572. smalltalk.addMethod(
  573. "_testBackslashSelectors",
  574. smalltalk.method({
  575. selector: "testBackslashSelectors",
  576. category: 'tests',
  577. fn: function (){
  578. var self=this;
  579. return smalltalk.withContext(function($ctx1) {
  580. _st(self)._should_return_("\x5c arg ^ 4",(4));
  581. _st(self)._should_return_("\x5c\x5c arg ^ 42",(42));
  582. return self}, function($ctx1) {$ctx1.fill(self,"testBackslashSelectors",{},smalltalk.CodeGeneratorTest)})},
  583. args: [],
  584. source: "testBackslashSelectors\x0a\x09\x0a\x09self should: '\x5c arg ^ 4' return: 4.\x0a\x09self should: '\x5c\x5c arg ^ 42' return: 42",
  585. messageSends: ["should:return:"],
  586. referencedClasses: []
  587. }),
  588. smalltalk.CodeGeneratorTest);
  589. smalltalk.addMethod(
  590. "_testBlockReturn",
  591. smalltalk.method({
  592. selector: "testBlockReturn",
  593. category: 'tests',
  594. fn: function (){
  595. var self=this;
  596. return smalltalk.withContext(function($ctx1) {
  597. _st(self)._should_return_("foo ^ #(1 2 3) collect: [ :each | true ifTrue: [ each + 1 ] ]",[(2), (3), (4)]);
  598. _st(self)._should_return_("foo ^ #(1 2 3) collect: [ :each | false ifFalse: [ each + 1 ] ]",[(2), (3), (4)]);
  599. _st(self)._should_return_("foo ^ #(1 2 3) collect: [ :each | each odd ifTrue: [ each + 1 ] ifFalse: [ each - 1 ] ]",[(2), (1), (4)]);
  600. return self}, function($ctx1) {$ctx1.fill(self,"testBlockReturn",{},smalltalk.CodeGeneratorTest)})},
  601. args: [],
  602. 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).",
  603. messageSends: ["should:return:"],
  604. referencedClasses: []
  605. }),
  606. smalltalk.CodeGeneratorTest);
  607. smalltalk.addMethod(
  608. "_testCascades",
  609. smalltalk.method({
  610. selector: "testCascades",
  611. category: 'tests',
  612. fn: function (){
  613. var self=this;
  614. return smalltalk.withContext(function($ctx1) {
  615. _st(self)._should_return_("foo ^ Array new add: 3; add: 4; yourself",[(3), (4)]);
  616. return self}, function($ctx1) {$ctx1.fill(self,"testCascades",{},smalltalk.CodeGeneratorTest)})},
  617. args: [],
  618. source: "testCascades\x0a\x09\x0a\x09self should: 'foo ^ Array new add: 3; add: 4; yourself' return: #(3 4)",
  619. messageSends: ["should:return:"],
  620. referencedClasses: []
  621. }),
  622. smalltalk.CodeGeneratorTest);
  623. smalltalk.addMethod(
  624. "_testDynamicArrayElementsOrdered",
  625. smalltalk.method({
  626. selector: "testDynamicArrayElementsOrdered",
  627. category: 'tests',
  628. fn: function (){
  629. var self=this;
  630. return smalltalk.withContext(function($ctx1) {
  631. _st(self)._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { x. true ifTrue: [ x := 2 ] }\x0a",[(1), (2)]);
  632. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicArrayElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  633. args: [],
  634. source: "testDynamicArrayElementsOrdered\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { x. true ifTrue: [ x := 2 ] }\x0a' return: #(1 2).",
  635. messageSends: ["should:return:"],
  636. referencedClasses: []
  637. }),
  638. smalltalk.CodeGeneratorTest);
  639. smalltalk.addMethod(
  640. "_testDynamicDictionaryElementsOrdered",
  641. smalltalk.method({
  642. selector: "testDynamicDictionaryElementsOrdered",
  643. category: 'tests',
  644. fn: function (){
  645. var self=this;
  646. return smalltalk.withContext(function($ctx1) {
  647. _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))]));
  648. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicDictionaryElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  649. args: [],
  650. 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}.",
  651. messageSends: ["should:return:", "->"],
  652. referencedClasses: []
  653. }),
  654. smalltalk.CodeGeneratorTest);
  655. smalltalk.addMethod(
  656. "_testInnerTemporalDependentElementsOrdered",
  657. smalltalk.method({
  658. selector: "testInnerTemporalDependentElementsOrdered",
  659. category: 'tests',
  660. fn: function (){
  661. var self=this;
  662. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  663. return smalltalk.withContext(function($ctx1) {
  664. _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))]);
  665. _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))]);
  666. _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))]);
  667. _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))]));
  668. return self}, function($ctx1) {$ctx1.fill(self,"testInnerTemporalDependentElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  669. args: [],
  670. 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}.",
  671. messageSends: ["should:return:", "->"],
  672. referencedClasses: ["Array"]
  673. }),
  674. smalltalk.CodeGeneratorTest);
  675. smalltalk.addMethod(
  676. "_testLiterals",
  677. smalltalk.method({
  678. selector: "testLiterals",
  679. category: 'tests',
  680. fn: function (){
  681. var self=this;
  682. return smalltalk.withContext(function($ctx1) {
  683. _st(self)._should_return_("foo ^ 1",(1));
  684. _st(self)._should_return_("foo ^ 'hello'","hello");
  685. _st(self)._should_return_("foo ^ #(1 2 3 4)",[(1), (2), (3), (4)]);
  686. _st(self)._should_return_("foo ^ {1. [:x | x ] value: 2. 3. [4] value}",[(1), (2), (3), (4)]);
  687. _st(self)._should_return_("foo ^ true",true);
  688. _st(self)._should_return_("foo ^ false",false);
  689. _st(self)._should_return_("foo ^ #{1->2. 3->4}",smalltalk.HashedCollection._fromPairs_([_st((1)).__minus_gt((2)),_st((3)).__minus_gt((4))]));
  690. _st(self)._should_return_("foo ^ #hello","hello");
  691. _st(self)._should_return_("foo ^ -123.456",(-123.456));
  692. return self}, function($ctx1) {$ctx1.fill(self,"testLiterals",{},smalltalk.CodeGeneratorTest)})},
  693. args: [],
  694. 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",
  695. messageSends: ["should:return:", "->"],
  696. referencedClasses: []
  697. }),
  698. smalltalk.CodeGeneratorTest);
  699. smalltalk.addMethod(
  700. "_testLocalReturn",
  701. smalltalk.method({
  702. selector: "testLocalReturn",
  703. category: 'tests',
  704. fn: function (){
  705. var self=this;
  706. return smalltalk.withContext(function($ctx1) {
  707. _st(self)._should_return_("foo ^ 1",(1));
  708. _st(self)._should_return_("foo ^ 1 + 1",(2));
  709. _st(self)._should_return_("foo ",self["@receiver"]);
  710. _st(self)._should_return_("foo self asString",self["@receiver"]);
  711. _st(self)._should_return_("foo | a b | a := 1. b := 2. ^ a + b",(3));
  712. return self}, function($ctx1) {$ctx1.fill(self,"testLocalReturn",{},smalltalk.CodeGeneratorTest)})},
  713. args: [],
  714. 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",
  715. messageSends: ["should:return:"],
  716. referencedClasses: []
  717. }),
  718. smalltalk.CodeGeneratorTest);
  719. smalltalk.addMethod(
  720. "_testMessageSends",
  721. smalltalk.method({
  722. selector: "testMessageSends",
  723. category: 'tests',
  724. fn: function (){
  725. var self=this;
  726. return smalltalk.withContext(function($ctx1) {
  727. _st(self)._should_return_("foo ^ 1 asString","1");
  728. _st(self)._should_return_("foo ^ 1 + 1",(2));
  729. _st(self)._should_return_("foo ^ 1 + 2 * 3",(9));
  730. _st(self)._should_return_("foo ^ 1 to: 3",[(1), (2), (3)]);
  731. _st(self)._should_return_("foo ^ 1 to: 5 by: 2",[(1), (3), (5)]);
  732. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSends",{},smalltalk.CodeGeneratorTest)})},
  733. args: [],
  734. 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)",
  735. messageSends: ["should:return:"],
  736. referencedClasses: []
  737. }),
  738. smalltalk.CodeGeneratorTest);
  739. smalltalk.addMethod(
  740. "_testMutableLiterals",
  741. smalltalk.method({
  742. selector: "testMutableLiterals",
  743. category: 'tests',
  744. fn: function (){
  745. var self=this;
  746. return smalltalk.withContext(function($ctx1) {
  747. _st(self)._should_return_("foo ^ #( 1 2 ) at: 1 put: 3; yourself",[(3), (2)]);
  748. return self}, function($ctx1) {$ctx1.fill(self,"testMutableLiterals",{},smalltalk.CodeGeneratorTest)})},
  749. args: [],
  750. 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)",
  751. messageSends: ["should:return:"],
  752. referencedClasses: []
  753. }),
  754. smalltalk.CodeGeneratorTest);
  755. smalltalk.addMethod(
  756. "_testNestedIfTrue",
  757. smalltalk.method({
  758. selector: "testNestedIfTrue",
  759. category: 'tests',
  760. fn: function (){
  761. var self=this;
  762. return smalltalk.withContext(function($ctx1) {
  763. _st(self)._should_return_("foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]",(1));
  764. _st(self)._should_return_("foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]",nil);
  765. _st(self)._should_return_("foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]",(1));
  766. _st(self)._should_return_("foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]",self["@receiver"]);
  767. return self}, function($ctx1) {$ctx1.fill(self,"testNestedIfTrue",{},smalltalk.CodeGeneratorTest)})},
  768. args: [],
  769. 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.",
  770. messageSends: ["should:return:"],
  771. referencedClasses: []
  772. }),
  773. smalltalk.CodeGeneratorTest);
  774. smalltalk.addMethod(
  775. "_testNonLocalReturn",
  776. smalltalk.method({
  777. selector: "testNonLocalReturn",
  778. category: 'tests',
  779. fn: function (){
  780. var self=this;
  781. return smalltalk.withContext(function($ctx1) {
  782. _st(self)._should_return_("foo [ ^ 1 ] value",(1));
  783. _st(self)._should_return_("foo [ ^ 1 + 1 ] value",(2));
  784. _st(self)._should_return_("foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt",(3));
  785. _st(self)._should_return_("foo [ :x | ^ x + x ] value: 4. ^ 2",(8));
  786. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn",{},smalltalk.CodeGeneratorTest)})},
  787. args: [],
  788. 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",
  789. messageSends: ["should:return:"],
  790. referencedClasses: []
  791. }),
  792. smalltalk.CodeGeneratorTest);
  793. smalltalk.addMethod(
  794. "_testPascalCaseGlobal",
  795. smalltalk.method({
  796. selector: "testPascalCaseGlobal",
  797. category: 'tests',
  798. fn: function (){
  799. var self=this;
  800. return smalltalk.withContext(function($ctx1) {
  801. _st(self)._should_return_("foo ^Object",_st(smalltalk)._at_("Object"));
  802. _st(self)._should_return_("foo ^NonExistent",nil);
  803. return self}, function($ctx1) {$ctx1.fill(self,"testPascalCaseGlobal",{},smalltalk.CodeGeneratorTest)})},
  804. args: [],
  805. source: "testPascalCaseGlobal\x0a\x09self should: 'foo ^Object' return: (smalltalk at: 'Object').\x0a\x09self should: 'foo ^NonExistent' return: nil",
  806. messageSends: ["should:return:", "at:"],
  807. referencedClasses: []
  808. }),
  809. smalltalk.CodeGeneratorTest);
  810. smalltalk.addMethod(
  811. "_testSendReceiverAndArgumentsOrdered",
  812. smalltalk.method({
  813. selector: "testSendReceiverAndArgumentsOrdered",
  814. category: 'tests',
  815. fn: function (){
  816. var self=this;
  817. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  818. return smalltalk.withContext(function($ctx1) {
  819. _st(self)._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ Array with: x with: (true ifTrue: [ x := 2 ])\x0a",[(1), (2)]);
  820. _st(self)._should_return_("foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: x with: (true ifTrue: [ x := 2 ])\x0a",[$Array(),(2)]);
  821. return self}, function($ctx1) {$ctx1.fill(self,"testSendReceiverAndArgumentsOrdered",{},smalltalk.CodeGeneratorTest)})},
  822. args: [],
  823. 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}.",
  824. messageSends: ["should:return:"],
  825. referencedClasses: ["Array"]
  826. }),
  827. smalltalk.CodeGeneratorTest);
  828. smalltalk.addMethod(
  829. "_testifFalse",
  830. smalltalk.method({
  831. selector: "testifFalse",
  832. category: 'tests',
  833. fn: function (){
  834. var self=this;
  835. return smalltalk.withContext(function($ctx1) {
  836. _st(self)._should_return_("foo true ifFalse: [ ^ 1 ]",self["@receiver"]);
  837. _st(self)._should_return_("foo false ifFalse: [ ^ 2 ]",(2));
  838. _st(self)._should_return_("foo ^ true ifFalse: [ 1 ]",nil);
  839. _st(self)._should_return_("foo ^ false ifFalse: [ 2 ]",(2));
  840. return self}, function($ctx1) {$ctx1.fill(self,"testifFalse",{},smalltalk.CodeGeneratorTest)})},
  841. args: [],
  842. 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.",
  843. messageSends: ["should:return:"],
  844. referencedClasses: []
  845. }),
  846. smalltalk.CodeGeneratorTest);
  847. smalltalk.addMethod(
  848. "_testifFalseIfTrue",
  849. smalltalk.method({
  850. selector: "testifFalseIfTrue",
  851. category: 'tests',
  852. fn: function (){
  853. var self=this;
  854. return smalltalk.withContext(function($ctx1) {
  855. _st(self)._should_return_("foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]",(2));
  856. _st(self)._should_return_("foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]",(2));
  857. _st(self)._should_return_("foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]",(2));
  858. _st(self)._should_return_("foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]",(2));
  859. return self}, function($ctx1) {$ctx1.fill(self,"testifFalseIfTrue",{},smalltalk.CodeGeneratorTest)})},
  860. args: [],
  861. 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.",
  862. messageSends: ["should:return:"],
  863. referencedClasses: []
  864. }),
  865. smalltalk.CodeGeneratorTest);
  866. smalltalk.addMethod(
  867. "_testifNil",
  868. smalltalk.method({
  869. selector: "testifNil",
  870. category: 'tests',
  871. fn: function (){
  872. var self=this;
  873. return smalltalk.withContext(function($ctx1) {
  874. _st(self)._should_return_("foo ^ 1 ifNil: [ 2 ]",(1));
  875. _st(self)._should_return_("foo ^ nil ifNil: [ 2 ]",(2));
  876. _st(self)._should_return_("foo 1 ifNil: [ ^ 2 ]",self["@receiver"]);
  877. _st(self)._should_return_("foo nil ifNil: [ ^ 2 ]",(2));
  878. return self}, function($ctx1) {$ctx1.fill(self,"testifNil",{},smalltalk.CodeGeneratorTest)})},
  879. args: [],
  880. 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.",
  881. messageSends: ["should:return:"],
  882. referencedClasses: []
  883. }),
  884. smalltalk.CodeGeneratorTest);
  885. smalltalk.addMethod(
  886. "_testifNilIfNotNil",
  887. smalltalk.method({
  888. selector: "testifNilIfNotNil",
  889. category: 'tests',
  890. fn: function (){
  891. var self=this;
  892. return smalltalk.withContext(function($ctx1) {
  893. _st(self)._should_return_("foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]",(3));
  894. _st(self)._should_return_("foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]",(2));
  895. _st(self)._should_return_("foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(3));
  896. _st(self)._should_return_("foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(2));
  897. return self}, function($ctx1) {$ctx1.fill(self,"testifNilIfNotNil",{},smalltalk.CodeGeneratorTest)})},
  898. args: [],
  899. 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.",
  900. messageSends: ["should:return:"],
  901. referencedClasses: []
  902. }),
  903. smalltalk.CodeGeneratorTest);
  904. smalltalk.addMethod(
  905. "_testifNotNil",
  906. smalltalk.method({
  907. selector: "testifNotNil",
  908. category: 'tests',
  909. fn: function (){
  910. var self=this;
  911. return smalltalk.withContext(function($ctx1) {
  912. _st(self)._should_return_("foo ^ 1 ifNotNil: [ 2 ]",(2));
  913. _st(self)._should_return_("foo ^ nil ifNotNil: [ 2 ]",nil);
  914. _st(self)._should_return_("foo 1 ifNotNil: [ ^ 2 ]",(2));
  915. _st(self)._should_return_("foo nil ifNotNil: [ ^ 2 ]",self["@receiver"]);
  916. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNil",{},smalltalk.CodeGeneratorTest)})},
  917. args: [],
  918. 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.",
  919. messageSends: ["should:return:"],
  920. referencedClasses: []
  921. }),
  922. smalltalk.CodeGeneratorTest);
  923. smalltalk.addMethod(
  924. "_testifNotNilWithArgument",
  925. smalltalk.method({
  926. selector: "testifNotNilWithArgument",
  927. category: 'tests',
  928. fn: function (){
  929. var self=this;
  930. return smalltalk.withContext(function($ctx1) {
  931. _st(self)._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ]",(3));
  932. _st(self)._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ]",nil);
  933. _st(self)._should_return_("foo ^ 1 ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(3));
  934. _st(self)._should_return_("foo ^ nil ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(5));
  935. _st(self)._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(3));
  936. _st(self)._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(5));
  937. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNilWithArgument",{},smalltalk.CodeGeneratorTest)})},
  938. args: [],
  939. 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",
  940. messageSends: ["should:return:"],
  941. referencedClasses: []
  942. }),
  943. smalltalk.CodeGeneratorTest);
  944. smalltalk.addMethod(
  945. "_testifTrue",
  946. smalltalk.method({
  947. selector: "testifTrue",
  948. category: 'tests',
  949. fn: function (){
  950. var self=this;
  951. return smalltalk.withContext(function($ctx1) {
  952. _st(self)._should_return_("foo false ifTrue: [ ^ 1 ]",self["@receiver"]);
  953. _st(self)._should_return_("foo true ifTrue: [ ^ 2 ]",(2));
  954. _st(self)._should_return_("foo ^ false ifTrue: [ 1 ]",nil);
  955. _st(self)._should_return_("foo ^ true ifTrue: [ 2 ]",(2));
  956. return self}, function($ctx1) {$ctx1.fill(self,"testifTrue",{},smalltalk.CodeGeneratorTest)})},
  957. args: [],
  958. 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.",
  959. messageSends: ["should:return:"],
  960. referencedClasses: []
  961. }),
  962. smalltalk.CodeGeneratorTest);
  963. smalltalk.addMethod(
  964. "_testifTrueIfFalse",
  965. smalltalk.method({
  966. selector: "testifTrueIfFalse",
  967. category: 'tests',
  968. fn: function (){
  969. var self=this;
  970. return smalltalk.withContext(function($ctx1) {
  971. _st(self)._should_return_("foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]",(2));
  972. _st(self)._should_return_("foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]",(1));
  973. _st(self)._should_return_("foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]",(1));
  974. _st(self)._should_return_("foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]",(2));
  975. return self}, function($ctx1) {$ctx1.fill(self,"testifTrueIfFalse",{},smalltalk.CodeGeneratorTest)})},
  976. args: [],
  977. 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.",
  978. messageSends: ["should:return:"],
  979. referencedClasses: []
  980. }),
  981. smalltalk.CodeGeneratorTest);
  982. smalltalk.addClass('InliningCodeGeneratorTest', smalltalk.CodeGeneratorTest, [], 'Compiler-Tests');
  983. smalltalk.addMethod(
  984. "_codeGeneratorClass",
  985. smalltalk.method({
  986. selector: "codeGeneratorClass",
  987. category: 'accessing',
  988. fn: function (){
  989. var self=this;
  990. function $InliningCodeGenerator(){return smalltalk.InliningCodeGenerator||(typeof InliningCodeGenerator=="undefined"?nil:InliningCodeGenerator)}
  991. return smalltalk.withContext(function($ctx1) {
  992. var $1;
  993. $1=$InliningCodeGenerator();
  994. return $1;
  995. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{},smalltalk.InliningCodeGeneratorTest)})},
  996. args: [],
  997. source: "codeGeneratorClass\x0a\x09^ InliningCodeGenerator",
  998. messageSends: [],
  999. referencedClasses: ["InliningCodeGenerator"]
  1000. }),
  1001. smalltalk.InliningCodeGeneratorTest);
  1002. smalltalk.addClass('ScopeVarTest', smalltalk.TestCase, [], 'Compiler-Tests');
  1003. smalltalk.addMethod(
  1004. "_testClassRefVar",
  1005. smalltalk.method({
  1006. selector: "testClassRefVar",
  1007. category: 'tests',
  1008. fn: function (){
  1009. var self=this;
  1010. var node;
  1011. function $ClassReferenceNode(){return smalltalk.ClassReferenceNode||(typeof ClassReferenceNode=="undefined"?nil:ClassReferenceNode)}
  1012. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1013. return smalltalk.withContext(function($ctx1) {
  1014. var $1,$2;
  1015. $1=_st($ClassReferenceNode())._new();
  1016. _st($1)._value_("Object");
  1017. $2=_st($1)._yourself();
  1018. node=$2;
  1019. _st(_st($SemanticAnalyzer())._new())._visit_(node);
  1020. _st(self)._assert_(_st(_st(node)._binding())._isClassRefVar());
  1021. return self}, function($ctx1) {$ctx1.fill(self,"testClassRefVar",{node:node},smalltalk.ScopeVarTest)})},
  1022. args: [],
  1023. 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",
  1024. messageSends: ["value:", "new", "yourself", "visit:", "assert:", "isClassRefVar", "binding"],
  1025. referencedClasses: ["ClassReferenceNode", "SemanticAnalyzer"]
  1026. }),
  1027. smalltalk.ScopeVarTest);
  1028. smalltalk.addMethod(
  1029. "_testInstanceVar",
  1030. smalltalk.method({
  1031. selector: "testInstanceVar",
  1032. category: 'tests',
  1033. fn: function (){
  1034. var self=this;
  1035. var node,scope;
  1036. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1037. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1038. return smalltalk.withContext(function($ctx1) {
  1039. var $1,$2;
  1040. $1=_st($VariableNode())._new();
  1041. _st($1)._value_("bzzz");
  1042. $2=_st($1)._yourself();
  1043. node=$2;
  1044. scope=_st($MethodLexicalScope())._new();
  1045. _st(scope)._addIVar_("bzzz");
  1046. _st(self)._assert_(_st(_st(scope)._bindingFor_(node))._isInstanceVar());
  1047. return self}, function($ctx1) {$ctx1.fill(self,"testInstanceVar",{node:node,scope:scope},smalltalk.ScopeVarTest)})},
  1048. args: [],
  1049. 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",
  1050. messageSends: ["value:", "new", "yourself", "addIVar:", "assert:", "isInstanceVar", "bindingFor:"],
  1051. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1052. }),
  1053. smalltalk.ScopeVarTest);
  1054. smalltalk.addMethod(
  1055. "_testPseudoVar",
  1056. smalltalk.method({
  1057. selector: "testPseudoVar",
  1058. category: 'tests',
  1059. fn: function (){
  1060. var self=this;
  1061. var node,pseudoVars;
  1062. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1063. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1064. return smalltalk.withContext(function($ctx1) {
  1065. var $1,$2;
  1066. pseudoVars=["self", "super", "true", "false", "nil"];
  1067. _st(pseudoVars)._do_((function(each){
  1068. return smalltalk.withContext(function($ctx2) {
  1069. $1=_st($VariableNode())._new();
  1070. _st($1)._value_(each);
  1071. $2=_st($1)._yourself();
  1072. node=$2;
  1073. node;
  1074. return _st(self)._assert_(_st(_st(_st($MethodLexicalScope())._new())._bindingFor_(node))._isPseudoVar());
  1075. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  1076. return self}, function($ctx1) {$ctx1.fill(self,"testPseudoVar",{node:node,pseudoVars:pseudoVars},smalltalk.ScopeVarTest)})},
  1077. args: [],
  1078. 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 ]",
  1079. messageSends: ["do:", "value:", "new", "yourself", "assert:", "isPseudoVar", "bindingFor:"],
  1080. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1081. }),
  1082. smalltalk.ScopeVarTest);
  1083. smalltalk.addMethod(
  1084. "_testTempVar",
  1085. smalltalk.method({
  1086. selector: "testTempVar",
  1087. category: 'tests',
  1088. fn: function (){
  1089. var self=this;
  1090. var node,scope;
  1091. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1092. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1093. return smalltalk.withContext(function($ctx1) {
  1094. var $1,$2;
  1095. $1=_st($VariableNode())._new();
  1096. _st($1)._value_("bzzz");
  1097. $2=_st($1)._yourself();
  1098. node=$2;
  1099. scope=_st($MethodLexicalScope())._new();
  1100. _st(scope)._addTemp_("bzzz");
  1101. _st(self)._assert_(_st(_st(scope)._bindingFor_(node))._isTempVar());
  1102. return self}, function($ctx1) {$ctx1.fill(self,"testTempVar",{node:node,scope:scope},smalltalk.ScopeVarTest)})},
  1103. args: [],
  1104. 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",
  1105. messageSends: ["value:", "new", "yourself", "addTemp:", "assert:", "isTempVar", "bindingFor:"],
  1106. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1107. }),
  1108. smalltalk.ScopeVarTest);
  1109. smalltalk.addMethod(
  1110. "_testUnknownVar",
  1111. smalltalk.method({
  1112. selector: "testUnknownVar",
  1113. category: 'tests',
  1114. fn: function (){
  1115. var self=this;
  1116. var node;
  1117. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1118. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1119. return smalltalk.withContext(function($ctx1) {
  1120. var $1,$2;
  1121. $1=_st($VariableNode())._new();
  1122. _st($1)._value_("bzzz");
  1123. $2=_st($1)._yourself();
  1124. node=$2;
  1125. _st(self)._assert_(_st(_st(_st($MethodLexicalScope())._new())._bindingFor_(node))._isNil());
  1126. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVar",{node:node},smalltalk.ScopeVarTest)})},
  1127. args: [],
  1128. source: "testUnknownVar\x0a\x09| node |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09self assert: (MethodLexicalScope new bindingFor: node) isNil",
  1129. messageSends: ["value:", "new", "yourself", "assert:", "isNil", "bindingFor:"],
  1130. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1131. }),
  1132. smalltalk.ScopeVarTest);
  1133. smalltalk.addClass('SemanticAnalyzerTest', smalltalk.TestCase, ['analyzer'], 'Compiler-Tests');
  1134. smalltalk.addMethod(
  1135. "_setUp",
  1136. smalltalk.method({
  1137. selector: "setUp",
  1138. category: 'running',
  1139. fn: function (){
  1140. var self=this;
  1141. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  1142. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1143. return smalltalk.withContext(function($ctx1) {
  1144. self["@analyzer"]=_st($SemanticAnalyzer())._on_($Object());
  1145. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},smalltalk.SemanticAnalyzerTest)})},
  1146. args: [],
  1147. source: "setUp\x0a\x09analyzer := SemanticAnalyzer on: Object",
  1148. messageSends: ["on:"],
  1149. referencedClasses: ["Object", "SemanticAnalyzer"]
  1150. }),
  1151. smalltalk.SemanticAnalyzerTest);
  1152. smalltalk.addMethod(
  1153. "_testAssignment",
  1154. smalltalk.method({
  1155. selector: "testAssignment",
  1156. category: 'tests',
  1157. fn: function (){
  1158. var self=this;
  1159. var src,ast;
  1160. function $InvalidAssignmentError(){return smalltalk.InvalidAssignmentError||(typeof InvalidAssignmentError=="undefined"?nil:InvalidAssignmentError)}
  1161. return smalltalk.withContext(function($ctx1) {
  1162. src="foo self := 1";
  1163. ast=_st(smalltalk)._parse_(src);
  1164. _st(self)._should_raise_((function(){
  1165. return smalltalk.withContext(function($ctx2) {
  1166. return _st(self["@analyzer"])._visit_(ast);
  1167. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$InvalidAssignmentError());
  1168. return self}, function($ctx1) {$ctx1.fill(self,"testAssignment",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1169. args: [],
  1170. 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",
  1171. messageSends: ["parse:", "should:raise:", "visit:"],
  1172. referencedClasses: ["InvalidAssignmentError"]
  1173. }),
  1174. smalltalk.SemanticAnalyzerTest);
  1175. smalltalk.addMethod(
  1176. "_testNonLocalReturn",
  1177. smalltalk.method({
  1178. selector: "testNonLocalReturn",
  1179. category: 'tests',
  1180. fn: function (){
  1181. var self=this;
  1182. var src,ast;
  1183. return smalltalk.withContext(function($ctx1) {
  1184. src="foo | a | a + 1. ^ a";
  1185. ast=_st(smalltalk)._parse_(src);
  1186. _st(self["@analyzer"])._visit_(ast);
  1187. _st(self)._deny_(_st(_st(ast)._scope())._hasNonLocalReturn());
  1188. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1189. args: [],
  1190. 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",
  1191. messageSends: ["parse:", "visit:", "deny:", "hasNonLocalReturn", "scope"],
  1192. referencedClasses: []
  1193. }),
  1194. smalltalk.SemanticAnalyzerTest);
  1195. smalltalk.addMethod(
  1196. "_testNonLocalReturn2",
  1197. smalltalk.method({
  1198. selector: "testNonLocalReturn2",
  1199. category: 'tests',
  1200. fn: function (){
  1201. var self=this;
  1202. var src,ast;
  1203. return smalltalk.withContext(function($ctx1) {
  1204. src="foo | a | a + 1. [ [ ^ a] ]";
  1205. ast=_st(smalltalk)._parse_(src);
  1206. _st(self["@analyzer"])._visit_(ast);
  1207. _st(self)._assert_(_st(_st(ast)._scope())._hasNonLocalReturn());
  1208. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1209. args: [],
  1210. 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",
  1211. messageSends: ["parse:", "visit:", "assert:", "hasNonLocalReturn", "scope"],
  1212. referencedClasses: []
  1213. }),
  1214. smalltalk.SemanticAnalyzerTest);
  1215. smalltalk.addMethod(
  1216. "_testScope",
  1217. smalltalk.method({
  1218. selector: "testScope",
  1219. category: 'tests',
  1220. fn: function (){
  1221. var self=this;
  1222. var src,ast;
  1223. return smalltalk.withContext(function($ctx1) {
  1224. src="foo | a | a + 1. [ | b | b := a ]";
  1225. ast=_st(smalltalk)._parse_(src);
  1226. _st(self["@analyzer"])._visit_(ast);
  1227. _st(self)._deny_(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._last())._scope()).__eq_eq(_st(ast)._scope()));
  1228. return self}, function($ctx1) {$ctx1.fill(self,"testScope",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1229. args: [],
  1230. 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.",
  1231. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "last", "nodes", "first"],
  1232. referencedClasses: []
  1233. }),
  1234. smalltalk.SemanticAnalyzerTest);
  1235. smalltalk.addMethod(
  1236. "_testScope2",
  1237. smalltalk.method({
  1238. selector: "testScope2",
  1239. category: 'tests',
  1240. fn: function (){
  1241. var self=this;
  1242. var src,ast;
  1243. return smalltalk.withContext(function($ctx1) {
  1244. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1245. ast=_st(smalltalk)._parse_(src);
  1246. _st(self["@analyzer"])._visit_(ast);
  1247. _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()));
  1248. return self}, function($ctx1) {$ctx1.fill(self,"testScope2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1249. args: [],
  1250. 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.",
  1251. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "first", "nodes", "last"],
  1252. referencedClasses: []
  1253. }),
  1254. smalltalk.SemanticAnalyzerTest);
  1255. smalltalk.addMethod(
  1256. "_testScopeLevel",
  1257. smalltalk.method({
  1258. selector: "testScopeLevel",
  1259. category: 'tests',
  1260. fn: function (){
  1261. var self=this;
  1262. var src,ast;
  1263. return smalltalk.withContext(function($ctx1) {
  1264. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1265. ast=_st(smalltalk)._parse_(src);
  1266. _st(self["@analyzer"])._visit_(ast);
  1267. _st(self)._assert_equals_(_st(_st(ast)._scope())._scopeLevel(),(1));
  1268. _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));
  1269. return self}, function($ctx1) {$ctx1.fill(self,"testScopeLevel",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1270. args: [],
  1271. 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",
  1272. messageSends: ["parse:", "visit:", "assert:equals:", "scopeLevel", "scope", "first", "nodes", "last"],
  1273. referencedClasses: []
  1274. }),
  1275. smalltalk.SemanticAnalyzerTest);
  1276. smalltalk.addMethod(
  1277. "_testUnknownVariables",
  1278. smalltalk.method({
  1279. selector: "testUnknownVariables",
  1280. category: 'tests',
  1281. fn: function (){
  1282. var self=this;
  1283. var src,ast;
  1284. function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1285. return smalltalk.withContext(function($ctx1) {
  1286. src="foo | a | b + a";
  1287. ast=_st(smalltalk)._parse_(src);
  1288. _st(self)._should_raise_((function(){
  1289. return smalltalk.withContext(function($ctx2) {
  1290. return _st(self["@analyzer"])._visit_(ast);
  1291. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$UnknownVariableError());
  1292. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariables",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1293. args: [],
  1294. 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",
  1295. messageSends: ["parse:", "should:raise:", "visit:"],
  1296. referencedClasses: ["UnknownVariableError"]
  1297. }),
  1298. smalltalk.SemanticAnalyzerTest);
  1299. smalltalk.addMethod(
  1300. "_testUnknownVariablesWithScope",
  1301. smalltalk.method({
  1302. selector: "testUnknownVariablesWithScope",
  1303. category: 'tests',
  1304. fn: function (){
  1305. var self=this;
  1306. var src,ast;
  1307. function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1308. return smalltalk.withContext(function($ctx1) {
  1309. src="foo | a b | [ c + 1. [ a + 1. d + 1 ]]";
  1310. ast=_st(smalltalk)._parse_(src);
  1311. _st(self)._should_raise_((function(){
  1312. return smalltalk.withContext(function($ctx2) {
  1313. return _st(self["@analyzer"])._visit_(ast);
  1314. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$UnknownVariableError());
  1315. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariablesWithScope",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1316. args: [],
  1317. 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",
  1318. messageSends: ["parse:", "should:raise:", "visit:"],
  1319. referencedClasses: ["UnknownVariableError"]
  1320. }),
  1321. smalltalk.SemanticAnalyzerTest);
  1322. smalltalk.addMethod(
  1323. "_testVariableShadowing",
  1324. smalltalk.method({
  1325. selector: "testVariableShadowing",
  1326. category: 'tests',
  1327. fn: function (){
  1328. var self=this;
  1329. var src,ast;
  1330. return smalltalk.withContext(function($ctx1) {
  1331. src="foo | a | a + 1";
  1332. ast=_st(smalltalk)._parse_(src);
  1333. _st(self["@analyzer"])._visit_(ast);
  1334. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1335. args: [],
  1336. source: "testVariableShadowing\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1337. messageSends: ["parse:", "visit:"],
  1338. referencedClasses: []
  1339. }),
  1340. smalltalk.SemanticAnalyzerTest);
  1341. smalltalk.addMethod(
  1342. "_testVariableShadowing2",
  1343. smalltalk.method({
  1344. selector: "testVariableShadowing2",
  1345. category: 'tests',
  1346. fn: function (){
  1347. var self=this;
  1348. var src,ast;
  1349. function $ShadowingVariableError(){return smalltalk.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1350. return smalltalk.withContext(function($ctx1) {
  1351. src="foo | a | a + 1. [ | a | a := 2 ]";
  1352. ast=_st(smalltalk)._parse_(src);
  1353. _st(self)._should_raise_((function(){
  1354. return smalltalk.withContext(function($ctx2) {
  1355. return _st(self["@analyzer"])._visit_(ast);
  1356. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$ShadowingVariableError());
  1357. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1358. args: [],
  1359. 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",
  1360. messageSends: ["parse:", "should:raise:", "visit:"],
  1361. referencedClasses: ["ShadowingVariableError"]
  1362. }),
  1363. smalltalk.SemanticAnalyzerTest);
  1364. smalltalk.addMethod(
  1365. "_testVariableShadowing3",
  1366. smalltalk.method({
  1367. selector: "testVariableShadowing3",
  1368. category: 'tests',
  1369. fn: function (){
  1370. var self=this;
  1371. var src,ast;
  1372. return smalltalk.withContext(function($ctx1) {
  1373. src="foo | a | a + 1. [ | b | b := 2 ]";
  1374. ast=_st(smalltalk)._parse_(src);
  1375. _st(self["@analyzer"])._visit_(ast);
  1376. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing3",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1377. args: [],
  1378. source: "testVariableShadowing3\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | b | b := 2 ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1379. messageSends: ["parse:", "visit:"],
  1380. referencedClasses: []
  1381. }),
  1382. smalltalk.SemanticAnalyzerTest);
  1383. smalltalk.addMethod(
  1384. "_testVariableShadowing4",
  1385. smalltalk.method({
  1386. selector: "testVariableShadowing4",
  1387. category: 'tests',
  1388. fn: function (){
  1389. var self=this;
  1390. var src,ast;
  1391. return smalltalk.withContext(function($ctx1) {
  1392. src="foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]";
  1393. ast=_st(smalltalk)._parse_(src);
  1394. _st(self["@analyzer"])._visit_(ast);
  1395. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing4",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1396. args: [],
  1397. source: "testVariableShadowing4\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1398. messageSends: ["parse:", "visit:"],
  1399. referencedClasses: []
  1400. }),
  1401. smalltalk.SemanticAnalyzerTest);
  1402. smalltalk.addMethod(
  1403. "_testVariableShadowing5",
  1404. smalltalk.method({
  1405. selector: "testVariableShadowing5",
  1406. category: 'tests',
  1407. fn: function (){
  1408. var self=this;
  1409. var src,ast;
  1410. function $ShadowingVariableError(){return smalltalk.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1411. return smalltalk.withContext(function($ctx1) {
  1412. src="foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]";
  1413. ast=_st(smalltalk)._parse_(src);
  1414. _st(self)._should_raise_((function(){
  1415. return smalltalk.withContext(function($ctx2) {
  1416. return _st(self["@analyzer"])._visit_(ast);
  1417. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),$ShadowingVariableError());
  1418. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing5",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1419. args: [],
  1420. 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",
  1421. messageSends: ["parse:", "should:raise:", "visit:"],
  1422. referencedClasses: ["ShadowingVariableError"]
  1423. }),
  1424. smalltalk.SemanticAnalyzerTest);
  1425. smalltalk.addMethod(
  1426. "_testVariablesLookup",
  1427. smalltalk.method({
  1428. selector: "testVariablesLookup",
  1429. category: 'tests',
  1430. fn: function (){
  1431. var self=this;
  1432. var src,ast;
  1433. return smalltalk.withContext(function($ctx1) {
  1434. src="foo | a | a + 1. [ | b | b := a ]";
  1435. ast=_st(smalltalk)._parse_(src);
  1436. _st(self["@analyzer"])._visit_(ast);
  1437. _st(self)._assert_(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._first())._receiver())._binding())._isTempVar());
  1438. _st(self)._assert_(_st(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._first())._receiver())._binding())._scope()).__eq_eq(_st(ast)._scope()));
  1439. _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());
  1440. _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()));
  1441. return self}, function($ctx1) {$ctx1.fill(self,"testVariablesLookup",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1442. args: [],
  1443. 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.",
  1444. messageSends: ["parse:", "visit:", "assert:", "isTempVar", "binding", "receiver", "first", "nodes", "==", "scope", "left", "last"],
  1445. referencedClasses: []
  1446. }),
  1447. smalltalk.SemanticAnalyzerTest);