Compiler-Tests.js 57 KB

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