2
0

Compiler-Tests.js 62 KB

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