Compiler-Tests.js 57 KB

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