1
0

Compiler-Tests.js 63 KB

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