Compiler-Tests.js 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017
  1. smalltalk.addPackage('Compiler-Tests');
  2. smalltalk.addClass('ASTVisitorTest', smalltalk.TestCase, [], 'Compiler-Tests');
  3. smalltalk.addMethod(
  4. smalltalk.method({
  5. selector: "analyze:forClass:",
  6. category: 'convenience',
  7. fn: function (aNode,aClass){
  8. var self=this;
  9. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  10. return smalltalk.withContext(function($ctx1) {
  11. var $1;
  12. _st(_st($SemanticAnalyzer())._on_(aClass))._visit_(aNode);
  13. $1=aNode;
  14. return $1;
  15. }, function($ctx1) {$ctx1.fill(self,"analyze:forClass:",{aNode:aNode,aClass:aClass},smalltalk.ASTVisitorTest)})},
  16. args: ["aNode", "aClass"],
  17. source: "analyze: aNode forClass: aClass\x0a\x09(SemanticAnalyzer on: aClass) visit: aNode.\x0a\x09^ aNode",
  18. messageSends: ["visit:", "on:"],
  19. referencedClasses: ["SemanticAnalyzer"]
  20. }),
  21. smalltalk.ASTVisitorTest);
  22. smalltalk.addMethod(
  23. smalltalk.method({
  24. selector: "parse:",
  25. category: 'parsing',
  26. fn: function (aString){
  27. var self=this;
  28. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  29. return smalltalk.withContext(function($ctx1) {
  30. var $1;
  31. $1=_st(_st($Smalltalk())._current())._parse_(aString);
  32. return $1;
  33. }, function($ctx1) {$ctx1.fill(self,"parse:",{aString:aString},smalltalk.ASTVisitorTest)})},
  34. args: ["aString"],
  35. source: "parse: aString\x0a\x09^ Smalltalk current parse: aString",
  36. messageSends: ["parse:", "current"],
  37. referencedClasses: ["Smalltalk"]
  38. }),
  39. smalltalk.ASTVisitorTest);
  40. smalltalk.addMethod(
  41. smalltalk.method({
  42. selector: "parse:forClass:",
  43. category: 'parsing',
  44. fn: function (aString,aClass){
  45. var self=this;
  46. return smalltalk.withContext(function($ctx1) {
  47. var $1;
  48. $1=self._analyze_forClass_(self._parse_(aString),aClass);
  49. return $1;
  50. }, function($ctx1) {$ctx1.fill(self,"parse:forClass:",{aString:aString,aClass:aClass},smalltalk.ASTVisitorTest)})},
  51. args: ["aString", "aClass"],
  52. source: "parse: aString forClass: aClass\x0a\x09^ self analyze: (self parse: aString) forClass: aClass",
  53. messageSends: ["analyze:forClass:", "parse:"],
  54. referencedClasses: []
  55. }),
  56. smalltalk.ASTVisitorTest);
  57. smalltalk.addClass('ASTPCNodeVisitorTest', smalltalk.ASTVisitorTest, [], 'Compiler-Tests');
  58. smalltalk.addMethod(
  59. smalltalk.method({
  60. selector: "astPCNodeVisitor",
  61. category: 'factory',
  62. fn: function (){
  63. var self=this;
  64. return smalltalk.withContext(function($ctx1) {
  65. var $1;
  66. $1=self._astPCNodeVisitorForPC_((0));
  67. return $1;
  68. }, function($ctx1) {$ctx1.fill(self,"astPCNodeVisitor",{},smalltalk.ASTPCNodeVisitorTest)})},
  69. args: [],
  70. source: "astPCNodeVisitor\x0a\x09^ self astPCNodeVisitorForPC: 0",
  71. messageSends: ["astPCNodeVisitorForPC:"],
  72. referencedClasses: []
  73. }),
  74. smalltalk.ASTPCNodeVisitorTest);
  75. smalltalk.addMethod(
  76. smalltalk.method({
  77. selector: "astPCNodeVisitorForPC:",
  78. category: 'factory',
  79. fn: function (anInteger){
  80. var self=this;
  81. function $ASTPCNodeVisitor(){return smalltalk.ASTPCNodeVisitor||(typeof ASTPCNodeVisitor=="undefined"?nil:ASTPCNodeVisitor)}
  82. function $AIContext(){return smalltalk.AIContext||(typeof AIContext=="undefined"?nil:AIContext)}
  83. return smalltalk.withContext(function($ctx1) {
  84. var $2,$3,$4,$5,$1;
  85. $2=_st($ASTPCNodeVisitor())._new();
  86. _st($2)._pc_((0));
  87. $3=_st($AIContext())._new();
  88. _st($3)._pc_(anInteger);
  89. $4=_st($3)._yourself();
  90. _st($2)._context_($4);
  91. $5=_st($2)._yourself();
  92. $1=$5;
  93. return $1;
  94. }, function($ctx1) {$ctx1.fill(self,"astPCNodeVisitorForPC:",{anInteger:anInteger},smalltalk.ASTPCNodeVisitorTest)})},
  95. args: ["anInteger"],
  96. source: "astPCNodeVisitorForPC: anInteger\x0a\x09^ ASTPCNodeVisitor new\x0a\x09\x09pc: 0;\x0a\x09\x09context: (AIContext new \x0a\x09\x09\x09pc: anInteger; \x0a\x09\x09\x09yourself);\x0a\x09\x09yourself",
  97. messageSends: ["pc:", "new", "context:", "yourself"],
  98. referencedClasses: ["ASTPCNodeVisitor", "AIContext"]
  99. }),
  100. smalltalk.ASTPCNodeVisitorTest);
  101. smalltalk.addMethod(
  102. smalltalk.method({
  103. selector: "testJSStatementNode",
  104. category: 'tests',
  105. fn: function (){
  106. var self=this;
  107. var ast,visitor;
  108. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  109. return smalltalk.withContext(function($ctx1) {
  110. var $1,$2;
  111. ast=self._parse_forClass_("foo <consolee.log(1)>",$Object());
  112. $1=self._astPCNodeVisitor();
  113. _st($1)._visit_(ast);
  114. $2=_st($1)._currentNode();
  115. self._assert_(_st($2)._isJSStatementNode());
  116. return self}, function($ctx1) {$ctx1.fill(self,"testJSStatementNode",{ast:ast,visitor:visitor},smalltalk.ASTPCNodeVisitorTest)})},
  117. args: [],
  118. source: "testJSStatementNode\x0a\x09| ast visitor |\x0a\x09\x0a\x09ast := self parse: 'foo <consolee.log(1)>' forClass: Object.\x0a\x09self assert: (self astPCNodeVisitor\x0a\x09\x09visit: ast;\x0a\x09\x09currentNode) isJSStatementNode",
  119. messageSends: ["parse:forClass:", "assert:", "isJSStatementNode", "visit:", "astPCNodeVisitor", "currentNode"],
  120. referencedClasses: ["Object"]
  121. }),
  122. smalltalk.ASTPCNodeVisitorTest);
  123. smalltalk.addMethod(
  124. smalltalk.method({
  125. selector: "testMessageSend",
  126. category: 'tests',
  127. fn: function (){
  128. var self=this;
  129. var ast;
  130. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  131. return smalltalk.withContext(function($ctx1) {
  132. var $1,$2;
  133. ast=self._parse_forClass_("foo self asString yourself. ^ self asBoolean",$Object());
  134. $1=self._astPCNodeVisitorForPC_((2));
  135. _st($1)._visit_(ast);
  136. $2=_st($1)._currentNode();
  137. self._assert_equals_(_st($2)._selector(),"yourself");
  138. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSend",{ast:ast},smalltalk.ASTPCNodeVisitorTest)})},
  139. args: [],
  140. source: "testMessageSend\x0a\x09| ast |\x0a\x09\x0a\x09ast := self parse: 'foo self asString yourself. ^ self asBoolean' forClass: Object.\x0a\x09self assert: ((self astPCNodeVisitorForPC: 2)\x0a\x09\x09visit: ast;\x0a\x09\x09currentNode) selector equals: 'yourself'",
  141. messageSends: ["parse:forClass:", "assert:equals:", "selector", "visit:", "astPCNodeVisitorForPC:", "currentNode"],
  142. referencedClasses: ["Object"]
  143. }),
  144. smalltalk.ASTPCNodeVisitorTest);
  145. smalltalk.addMethod(
  146. smalltalk.method({
  147. selector: "testMessageSendWithInlining",
  148. category: 'tests',
  149. fn: function (){
  150. var self=this;
  151. var ast;
  152. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  153. return smalltalk.withContext(function($ctx1) {
  154. var $1,$2,$3,$4;
  155. ast=self._parse_forClass_("foo true ifTrue: [ self asString yourself ]. ^ self asBoolean",$Object());
  156. $1=self._astPCNodeVisitorForPC_((2));
  157. _st($1)._visit_(ast);
  158. $2=_st($1)._currentNode();
  159. self._assert_equals_(_st($2)._selector(),"yourself");
  160. ast=self._parse_forClass_("foo true ifTrue: [ self asString yourself ]. ^ self asBoolean",$Object());
  161. $3=self._astPCNodeVisitorForPC_((3));
  162. _st($3)._visit_(ast);
  163. $4=_st($3)._currentNode();
  164. self._assert_equals_(_st($4)._selector(),"asBoolean");
  165. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSendWithInlining",{ast:ast},smalltalk.ASTPCNodeVisitorTest)})},
  166. args: [],
  167. source: "testMessageSendWithInlining\x0a\x09| ast |\x0a\x09\x0a\x09ast := self parse: 'foo true ifTrue: [ self asString yourself ]. ^ self asBoolean' forClass: Object.\x0a\x09self assert: ((self astPCNodeVisitorForPC: 2)\x0a\x09\x09visit: ast;\x0a\x09\x09currentNode) selector equals: 'yourself'.\x0a\x09\x09\x0a\x09ast := self parse: 'foo true ifTrue: [ self asString yourself ]. ^ self asBoolean' forClass: Object.\x0a\x09self assert: ((self astPCNodeVisitorForPC: 3)\x0a\x09\x09visit: ast;\x0a\x09\x09currentNode) selector equals: 'asBoolean'",
  168. messageSends: ["parse:forClass:", "assert:equals:", "selector", "visit:", "astPCNodeVisitorForPC:", "currentNode"],
  169. referencedClasses: ["Object"]
  170. }),
  171. smalltalk.ASTPCNodeVisitorTest);
  172. smalltalk.addMethod(
  173. smalltalk.method({
  174. selector: "testNoMessageSend",
  175. category: 'tests',
  176. fn: function (){
  177. var self=this;
  178. var ast;
  179. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  180. return smalltalk.withContext(function($ctx1) {
  181. var $1,$2;
  182. ast=self._parse_forClass_("foo ^ self",$Object());
  183. $1=self._astPCNodeVisitor();
  184. _st($1)._visit_(ast);
  185. $2=_st($1)._currentNode();
  186. self._assert_(_st($2)._isNil());
  187. return self}, function($ctx1) {$ctx1.fill(self,"testNoMessageSend",{ast:ast},smalltalk.ASTPCNodeVisitorTest)})},
  188. args: [],
  189. source: "testNoMessageSend\x0a\x09| ast |\x0a\x09\x0a\x09ast := self parse: 'foo ^ self' forClass: Object.\x0a\x09self assert: (self astPCNodeVisitor\x0a\x09\x09visit: ast;\x0a\x09\x09currentNode) isNil",
  190. messageSends: ["parse:forClass:", "assert:", "isNil", "visit:", "astPCNodeVisitor", "currentNode"],
  191. referencedClasses: ["Object"]
  192. }),
  193. smalltalk.ASTPCNodeVisitorTest);
  194. smalltalk.addMethod(
  195. smalltalk.method({
  196. selector: "testPC",
  197. category: 'tests',
  198. fn: function (){
  199. var self=this;
  200. var ast,visitor;
  201. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  202. return smalltalk.withContext(function($ctx1) {
  203. var $1,$2;
  204. ast=self._parse_forClass_("foo <console.log(1)>",$Object());
  205. $1=self._astPCNodeVisitor();
  206. _st($1)._visit_(ast);
  207. $2=_st($1)._currentNode();
  208. self._assert_(_st($2)._isJSStatementNode());
  209. return self}, function($ctx1) {$ctx1.fill(self,"testPC",{ast:ast,visitor:visitor},smalltalk.ASTPCNodeVisitorTest)})},
  210. args: [],
  211. source: "testPC\x0a\x09| ast visitor |\x0a\x09\x0a\x09ast := self parse: 'foo <console.log(1)>' forClass: Object.\x0a\x09self assert: (self astPCNodeVisitor\x0a\x09\x09visit: ast;\x0a\x09\x09currentNode) isJSStatementNode",
  212. messageSends: ["parse:forClass:", "assert:", "isJSStatementNode", "visit:", "astPCNodeVisitor", "currentNode"],
  213. referencedClasses: ["Object"]
  214. }),
  215. smalltalk.ASTPCNodeVisitorTest);
  216. smalltalk.addClass('AbstractASTInterpreterTest', smalltalk.ASTVisitorTest, [], 'Compiler-Tests');
  217. smalltalk.addMethod(
  218. smalltalk.method({
  219. selector: "interpret:",
  220. category: 'interpreting',
  221. fn: function (aString){
  222. var self=this;
  223. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  224. return smalltalk.withContext(function($ctx1) {
  225. var $1;
  226. $1=self._interpret_withArguments_(aString,_st($Dictionary())._new());
  227. return $1;
  228. }, function($ctx1) {$ctx1.fill(self,"interpret:",{aString:aString},smalltalk.AbstractASTInterpreterTest)})},
  229. args: ["aString"],
  230. source: "interpret: aString\x0a\x09^ self\x0a\x09\x09interpret: aString\x0a\x09\x09withArguments: Dictionary new",
  231. messageSends: ["interpret:withArguments:", "new"],
  232. referencedClasses: ["Dictionary"]
  233. }),
  234. smalltalk.AbstractASTInterpreterTest);
  235. smalltalk.addMethod(
  236. smalltalk.method({
  237. selector: "interpret:receiver:withArguments:",
  238. category: 'interpreting',
  239. fn: function (aString,anObject,aDictionary){
  240. var self=this;
  241. var ctx;
  242. function $AIContext(){return smalltalk.AIContext||(typeof AIContext=="undefined"?nil:AIContext)}
  243. return smalltalk.withContext(function($ctx1) {
  244. var $2,$3,$1;
  245. ctx=_st($AIContext())._new();
  246. _st(ctx)._receiver_(anObject);
  247. _st(aDictionary)._keysAndValuesDo_((function(key,value){
  248. return smalltalk.withContext(function($ctx2) {
  249. return _st(ctx)._localAt_put_(key,value);
  250. }, function($ctx2) {$ctx2.fillBlock({key:key,value:value},$ctx1,1)})}));
  251. $2=self._interpreter();
  252. _st($2)._context_(ctx);
  253. _st($2)._interpret_(_st(_st(self._parse_forClass_(aString,_st(anObject)._class()))._nodes())._first());
  254. $3=_st($2)._result();
  255. $1=$3;
  256. return $1;
  257. }, function($ctx1) {$ctx1.fill(self,"interpret:receiver:withArguments:",{aString:aString,anObject:anObject,aDictionary:aDictionary,ctx:ctx},smalltalk.AbstractASTInterpreterTest)})},
  258. args: ["aString", "anObject", "aDictionary"],
  259. 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",
  260. messageSends: ["new", "receiver:", "keysAndValuesDo:", "localAt:put:", "context:", "interpreter", "interpret:", "first", "nodes", "parse:forClass:", "class", "result"],
  261. referencedClasses: ["AIContext"]
  262. }),
  263. smalltalk.AbstractASTInterpreterTest);
  264. smalltalk.addMethod(
  265. smalltalk.method({
  266. selector: "interpret:withArguments:",
  267. category: 'interpreting',
  268. fn: function (aString,aDictionary){
  269. var self=this;
  270. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  271. return smalltalk.withContext(function($ctx1) {
  272. var $1;
  273. $1=self._interpret_receiver_withArguments_(aString,_st($Object())._new(),aDictionary);
  274. return $1;
  275. }, function($ctx1) {$ctx1.fill(self,"interpret:withArguments:",{aString:aString,aDictionary:aDictionary},smalltalk.AbstractASTInterpreterTest)})},
  276. args: ["aString", "aDictionary"],
  277. source: "interpret: aString withArguments: aDictionary\x0a\x09^ self\x0a\x09\x09interpret: aString\x0a\x09\x09receiver: Object new\x0a\x09\x09withArguments: aDictionary",
  278. messageSends: ["interpret:receiver:withArguments:", "new"],
  279. referencedClasses: ["Object"]
  280. }),
  281. smalltalk.AbstractASTInterpreterTest);
  282. smalltalk.addMethod(
  283. smalltalk.method({
  284. selector: "interpreter",
  285. category: 'accessing',
  286. fn: function (){
  287. var self=this;
  288. return smalltalk.withContext(function($ctx1) {
  289. var $1;
  290. $1=self._subclassResponsibility();
  291. return $1;
  292. }, function($ctx1) {$ctx1.fill(self,"interpreter",{},smalltalk.AbstractASTInterpreterTest)})},
  293. args: [],
  294. source: "interpreter\x0a\x09^ self subclassResponsibility",
  295. messageSends: ["subclassResponsibility"],
  296. referencedClasses: []
  297. }),
  298. smalltalk.AbstractASTInterpreterTest);
  299. smalltalk.addClass('ASTInterpreterTest', smalltalk.AbstractASTInterpreterTest, [], 'Compiler-Tests');
  300. smalltalk.addMethod(
  301. smalltalk.method({
  302. selector: "interpreter",
  303. category: 'accessing',
  304. fn: function (){
  305. var self=this;
  306. function $ASTInterpreter(){return smalltalk.ASTInterpreter||(typeof ASTInterpreter=="undefined"?nil:ASTInterpreter)}
  307. return smalltalk.withContext(function($ctx1) {
  308. var $1;
  309. $1=_st($ASTInterpreter())._new();
  310. return $1;
  311. }, function($ctx1) {$ctx1.fill(self,"interpreter",{},smalltalk.ASTInterpreterTest)})},
  312. args: [],
  313. source: "interpreter\x0a\x09^ ASTInterpreter new",
  314. messageSends: ["new"],
  315. referencedClasses: ["ASTInterpreter"]
  316. }),
  317. smalltalk.ASTInterpreterTest);
  318. smalltalk.addMethod(
  319. smalltalk.method({
  320. selector: "testBinarySend",
  321. category: 'tests',
  322. fn: function (){
  323. var self=this;
  324. return smalltalk.withContext(function($ctx1) {
  325. self._assert_equals_(self._interpret_("foo 2+3+4"),(9));
  326. return self}, function($ctx1) {$ctx1.fill(self,"testBinarySend",{},smalltalk.ASTInterpreterTest)})},
  327. args: [],
  328. source: "testBinarySend\x0a\x09self assert: (self interpret: 'foo 2+3+4') equals: 9",
  329. messageSends: ["assert:equals:", "interpret:"],
  330. referencedClasses: []
  331. }),
  332. smalltalk.ASTInterpreterTest);
  333. smalltalk.addMethod(
  334. smalltalk.method({
  335. selector: "testBlockLiteral",
  336. category: 'tests',
  337. fn: function (){
  338. var self=this;
  339. return smalltalk.withContext(function($ctx1) {
  340. self._assert_equals_(self._interpret_("foo ^ true ifTrue: [ 1 ] ifFalse: [ 2 ]"),(1));
  341. self._assert_equals_(self._interpret_("foo true ifTrue: [ ^ 1 ] ifFalse: [ 2 ]"),(1));
  342. self._assert_equals_(self._interpret_("foo ^ false ifTrue: [ 1 ] ifFalse: [ 2 ]"),(2));
  343. return self}, function($ctx1) {$ctx1.fill(self,"testBlockLiteral",{},smalltalk.ASTInterpreterTest)})},
  344. args: [],
  345. 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",
  346. messageSends: ["assert:equals:", "interpret:"],
  347. referencedClasses: []
  348. }),
  349. smalltalk.ASTInterpreterTest);
  350. smalltalk.addMethod(
  351. smalltalk.method({
  352. selector: "testCascade",
  353. category: 'tests',
  354. fn: function (){
  355. var self=this;
  356. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  357. return smalltalk.withContext(function($ctx1) {
  358. self._assert_equals_(self._interpret_("foo ^ OrderedCollection new add: 2; add: 3; yourself"),_st($OrderedCollection())._with_with_((2),(3)));
  359. return self}, function($ctx1) {$ctx1.fill(self,"testCascade",{},smalltalk.ASTInterpreterTest)})},
  360. args: [],
  361. source: "testCascade\x0a\x09self assert: (self interpret: 'foo ^ OrderedCollection new add: 2; add: 3; yourself') equals: (OrderedCollection with: 2 with: 3)",
  362. messageSends: ["assert:equals:", "interpret:", "with:with:"],
  363. referencedClasses: ["OrderedCollection"]
  364. }),
  365. smalltalk.ASTInterpreterTest);
  366. smalltalk.addMethod(
  367. smalltalk.method({
  368. selector: "testDynamicArray",
  369. category: 'tests',
  370. fn: function (){
  371. var self=this;
  372. return smalltalk.withContext(function($ctx1) {
  373. self._assert_equals_(self._interpret_("foo ^ {1+1. 2+2}"),[(2), (4)]);
  374. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicArray",{},smalltalk.ASTInterpreterTest)})},
  375. args: [],
  376. source: "testDynamicArray\x0a\x09self assert: (self interpret: 'foo ^ {1+1. 2+2}') equals: #(2 4)",
  377. messageSends: ["assert:equals:", "interpret:"],
  378. referencedClasses: []
  379. }),
  380. smalltalk.ASTInterpreterTest);
  381. smalltalk.addMethod(
  382. smalltalk.method({
  383. selector: "testDynamicDictionary",
  384. category: 'tests',
  385. fn: function (){
  386. var self=this;
  387. return smalltalk.withContext(function($ctx1) {
  388. self._assert_equals_(self._interpret_("foo ^ #{1->1. 2->3}"),smalltalk.HashedCollection._from_([(1).__minus_gt((1)),(2).__minus_gt((3))]));
  389. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicDictionary",{},smalltalk.ASTInterpreterTest)})},
  390. args: [],
  391. source: "testDynamicDictionary\x0a\x09self assert: (self interpret: 'foo ^ #{1->1. 2->3}') equals: #{1->1. 2->3}",
  392. messageSends: ["assert:equals:", "interpret:", "->"],
  393. referencedClasses: []
  394. }),
  395. smalltalk.ASTInterpreterTest);
  396. smalltalk.addMethod(
  397. smalltalk.method({
  398. selector: "testInlinedJSStatement",
  399. category: 'tests',
  400. fn: function (){
  401. var self=this;
  402. return smalltalk.withContext(function($ctx1) {
  403. self._assert_equals_(self._interpret_("foo <return 2+3>"),(5));
  404. self._assert_equals_(self._interpret_withArguments_("foo: anInteger <return 2 + anInteger>",smalltalk.HashedCollection._from_(["anInteger".__minus_gt((3))])),(5));
  405. return self}, function($ctx1) {$ctx1.fill(self,"testInlinedJSStatement",{},smalltalk.ASTInterpreterTest)})},
  406. args: [],
  407. 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",
  408. messageSends: ["assert:equals:", "interpret:", "interpret:withArguments:", "->"],
  409. referencedClasses: []
  410. }),
  411. smalltalk.ASTInterpreterTest);
  412. smalltalk.addMethod(
  413. smalltalk.method({
  414. selector: "testInstVarAccess",
  415. category: 'tests',
  416. fn: function (){
  417. var self=this;
  418. return smalltalk.withContext(function($ctx1) {
  419. self._assert_equals_(self._interpret_receiver_withArguments_("foo ^ x",(2).__at((3)),smalltalk.HashedCollection._from_([])),(2));
  420. return self}, function($ctx1) {$ctx1.fill(self,"testInstVarAccess",{},smalltalk.ASTInterpreterTest)})},
  421. args: [],
  422. 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",
  423. messageSends: ["assert:equals:", "interpret:receiver:withArguments:", "@"],
  424. referencedClasses: []
  425. }),
  426. smalltalk.ASTInterpreterTest);
  427. smalltalk.addMethod(
  428. smalltalk.method({
  429. selector: "testInstVarAssignment",
  430. category: 'tests',
  431. fn: function (){
  432. var self=this;
  433. function $Point(){return smalltalk.Point||(typeof Point=="undefined"?nil:Point)}
  434. return smalltalk.withContext(function($ctx1) {
  435. self._assert_equals_(self._interpret_receiver_withArguments_("foo: anInteger x := anInteger. ^ x",_st($Point())._new(),smalltalk.HashedCollection._from_(["anInteger".__minus_gt((2))])),(2));
  436. return self}, function($ctx1) {$ctx1.fill(self,"testInstVarAssignment",{},smalltalk.ASTInterpreterTest)})},
  437. args: [],
  438. 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",
  439. messageSends: ["assert:equals:", "interpret:receiver:withArguments:", "new", "->"],
  440. referencedClasses: ["Point"]
  441. }),
  442. smalltalk.ASTInterpreterTest);
  443. smalltalk.addMethod(
  444. smalltalk.method({
  445. selector: "testNonlocalReturn",
  446. category: 'tests',
  447. fn: function (){
  448. var self=this;
  449. return smalltalk.withContext(function($ctx1) {
  450. self._assert_equals_(self._interpret_("foo true ifTrue: [ ^ 1 ]. ^2"),(1));
  451. return self}, function($ctx1) {$ctx1.fill(self,"testNonlocalReturn",{},smalltalk.ASTInterpreterTest)})},
  452. args: [],
  453. source: "testNonlocalReturn\x0a\x09self assert: (self interpret: 'foo true ifTrue: [ ^ 1 ]. ^2') equals: 1",
  454. messageSends: ["assert:equals:", "interpret:"],
  455. referencedClasses: []
  456. }),
  457. smalltalk.ASTInterpreterTest);
  458. smalltalk.addMethod(
  459. smalltalk.method({
  460. selector: "testReceiver",
  461. category: 'tests',
  462. fn: function (){
  463. var self=this;
  464. return smalltalk.withContext(function($ctx1) {
  465. self._assert_equals_(self._interpret_receiver_withArguments_("foo ^ self",(2).__at((3)),smalltalk.HashedCollection._from_([])),(2).__at((3)));
  466. return self}, function($ctx1) {$ctx1.fill(self,"testReceiver",{},smalltalk.ASTInterpreterTest)})},
  467. args: [],
  468. 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",
  469. messageSends: ["assert:equals:", "interpret:receiver:withArguments:", "@"],
  470. referencedClasses: []
  471. }),
  472. smalltalk.ASTInterpreterTest);
  473. smalltalk.addMethod(
  474. smalltalk.method({
  475. selector: "testSuper",
  476. category: 'tests',
  477. fn: function (){
  478. var self=this;
  479. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  480. return smalltalk.withContext(function($ctx1) {
  481. self._assert_equals_(self._interpret_receiver_withArguments_("foo ^ super isBoolean",true,_st($Dictionary())._new()),false);
  482. return self}, function($ctx1) {$ctx1.fill(self,"testSuper",{},smalltalk.ASTInterpreterTest)})},
  483. args: [],
  484. source: "testSuper\x0a\x09self \x0a\x09\x09assert: (self \x0a\x09\x09\x09interpret: 'foo ^ super isBoolean' \x0a\x09\x09\x09receiver: true \x0a\x09\x09\x09withArguments: Dictionary new) \x0a\x09\x09equals: false",
  485. messageSends: ["assert:equals:", "interpret:receiver:withArguments:", "new"],
  486. referencedClasses: ["Dictionary"]
  487. }),
  488. smalltalk.ASTInterpreterTest);
  489. smalltalk.addMethod(
  490. smalltalk.method({
  491. selector: "testTempAssignment",
  492. category: 'tests',
  493. fn: function (){
  494. var self=this;
  495. return smalltalk.withContext(function($ctx1) {
  496. self._assert_equals_(self._interpret_("foo | a | a := 2. ^ a"),(2));
  497. return self}, function($ctx1) {$ctx1.fill(self,"testTempAssignment",{},smalltalk.ASTInterpreterTest)})},
  498. args: [],
  499. source: "testTempAssignment\x0a\x09self assert: (self interpret: 'foo | a | a := 2. ^ a') equals: 2",
  500. messageSends: ["assert:equals:", "interpret:"],
  501. referencedClasses: []
  502. }),
  503. smalltalk.ASTInterpreterTest);
  504. smalltalk.addMethod(
  505. smalltalk.method({
  506. selector: "testThisContext",
  507. category: 'tests',
  508. fn: function (){
  509. var self=this;
  510. return smalltalk.withContext(function($ctx1) {
  511. self._assert_(_st(_st(self._interpret_("foo ^ thisContext"))._outerContext())._isNil());
  512. self._assert_(_st(_st(self._interpret_("foo ^ [ thisContext ] value"))._outerContext())._notNil());
  513. self._assert_(self._interpret_("foo ^ [ thisContext ] value outerContext == thisContext"));
  514. return self}, function($ctx1) {$ctx1.fill(self,"testThisContext",{},smalltalk.ASTInterpreterTest)})},
  515. args: [],
  516. source: "testThisContext\x0a\x09self assert: (self interpret: 'foo ^ thisContext') outerContext isNil.\x0a\x09self assert: (self interpret: 'foo ^ [ thisContext ] value') outerContext notNil.\x0a\x09self assert: (self interpret: 'foo ^ [ thisContext ] value outerContext == thisContext')",
  517. messageSends: ["assert:", "isNil", "outerContext", "interpret:", "notNil"],
  518. referencedClasses: []
  519. }),
  520. smalltalk.ASTInterpreterTest);
  521. smalltalk.addClass('ASTSteppingInterpreterTest', smalltalk.AbstractASTInterpreterTest, ['interpreter'], 'Compiler-Tests');
  522. smalltalk.addMethod(
  523. smalltalk.method({
  524. selector: "interpreter",
  525. category: 'accessing',
  526. fn: function (){
  527. var self=this;
  528. function $ASTSteppingInterpreter(){return smalltalk.ASTSteppingInterpreter||(typeof ASTSteppingInterpreter=="undefined"?nil:ASTSteppingInterpreter)}
  529. return smalltalk.withContext(function($ctx1) {
  530. var $2,$1;
  531. $2=self["@interpreter"];
  532. if(($receiver = $2) == nil || $receiver == undefined){
  533. self["@interpreter"]=_st($ASTSteppingInterpreter())._new();
  534. $1=self["@interpreter"];
  535. } else {
  536. $1=$2;
  537. };
  538. return $1;
  539. }, function($ctx1) {$ctx1.fill(self,"interpreter",{},smalltalk.ASTSteppingInterpreterTest)})},
  540. args: [],
  541. source: "interpreter\x0a\x09^ interpreter ifNil: [ interpreter := ASTSteppingInterpreter new ]",
  542. messageSends: ["ifNil:", "new"],
  543. referencedClasses: ["ASTSteppingInterpreter"]
  544. }),
  545. smalltalk.ASTSteppingInterpreterTest);
  546. smalltalk.addMethod(
  547. smalltalk.method({
  548. selector: "testAtEnd",
  549. category: 'tests',
  550. fn: function (){
  551. var self=this;
  552. return smalltalk.withContext(function($ctx1) {
  553. self._interpret_("foo 1 + 2");
  554. self._deny_(_st(self._interpreter())._atEnd());
  555. _st(self._interpreter())._step();
  556. self._deny_(_st(self._interpreter())._atEnd());
  557. _st(self._interpreter())._step();
  558. self._deny_(_st(self._interpreter())._atEnd());
  559. _st(self._interpreter())._step();
  560. self._deny_(_st(self._interpreter())._atEnd());
  561. _st(self._interpreter())._step();
  562. self._assert_(_st(self._interpreter())._atEnd());
  563. return self}, function($ctx1) {$ctx1.fill(self,"testAtEnd",{},smalltalk.ASTSteppingInterpreterTest)})},
  564. args: [],
  565. 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",
  566. messageSends: ["interpret:", "deny:", "atEnd", "interpreter", "step", "assert:"],
  567. referencedClasses: []
  568. }),
  569. smalltalk.ASTSteppingInterpreterTest);
  570. smalltalk.addMethod(
  571. smalltalk.method({
  572. selector: "testMessageSend",
  573. category: 'tests',
  574. fn: function (){
  575. var self=this;
  576. return smalltalk.withContext(function($ctx1) {
  577. self._interpret_("foo 1 + 2");
  578. _st(self._interpreter())._step();
  579. _st(self._interpreter())._step();
  580. _st(self._interpreter())._step();
  581. self._assert_equals_(_st(_st(self._interpreter())._currentNode())._value(),(1));
  582. _st(self._interpreter())._step();
  583. self._assert_equals_(_st(_st(self._interpreter())._currentNode())._value(),(2));
  584. _st(self._interpreter())._step();
  585. self._assert_equals_(_st(self._interpreter())._result(),(3));
  586. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSend",{},smalltalk.ASTSteppingInterpreterTest)})},
  587. args: [],
  588. 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",
  589. messageSends: ["interpret:", "step", "interpreter", "assert:equals:", "value", "currentNode", "result"],
  590. referencedClasses: []
  591. }),
  592. smalltalk.ASTSteppingInterpreterTest);
  593. smalltalk.addMethod(
  594. smalltalk.method({
  595. selector: "testSimpleStepping",
  596. category: 'tests',
  597. fn: function (){
  598. var self=this;
  599. return smalltalk.withContext(function($ctx1) {
  600. self._interpret_("foo 1");
  601. _st(self._interpreter())._step();
  602. self._assert_(_st(_st(self._interpreter())._result())._isNil());
  603. _st(self._interpreter())._step();
  604. self._assert_equals_(_st(self._interpreter())._result(),(1));
  605. return self}, function($ctx1) {$ctx1.fill(self,"testSimpleStepping",{},smalltalk.ASTSteppingInterpreterTest)})},
  606. args: [],
  607. 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",
  608. messageSends: ["interpret:", "step", "interpreter", "assert:", "isNil", "result", "assert:equals:"],
  609. referencedClasses: []
  610. }),
  611. smalltalk.ASTSteppingInterpreterTest);
  612. smalltalk.addClass('InterpreterTest', smalltalk.AbstractASTInterpreterTest, [], 'Compiler-Tests');
  613. smalltalk.addMethod(
  614. smalltalk.method({
  615. selector: "interpret:receiver:withArguments:",
  616. category: 'interpreting',
  617. fn: function (aString,anObject,aDictionary){
  618. var self=this;
  619. var ctx;
  620. function $AIContext(){return smalltalk.AIContext||(typeof AIContext=="undefined"?nil:AIContext)}
  621. return smalltalk.withContext(function($ctx1) {
  622. var $2,$3,$1;
  623. ctx=_st($AIContext())._new();
  624. _st(ctx)._receiver_(anObject);
  625. _st(aDictionary)._keysAndValuesDo_((function(key,value){
  626. return smalltalk.withContext(function($ctx2) {
  627. return _st(ctx)._localAt_put_(key,value);
  628. }, function($ctx2) {$ctx2.fillBlock({key:key,value:value},$ctx1,1)})}));
  629. $2=self._interpreter();
  630. _st($2)._context_(ctx);
  631. _st($2)._interpret_(_st(self._parse_forClass_(aString,_st(anObject)._class()))._nextChild());
  632. _st($2)._proceed();
  633. $3=_st($2)._result();
  634. $1=$3;
  635. return $1;
  636. }, function($ctx1) {$ctx1.fill(self,"interpret:receiver:withArguments:",{aString:aString,anObject:anObject,aDictionary:aDictionary,ctx:ctx},smalltalk.InterpreterTest)})},
  637. args: ["aString", "anObject", "aDictionary"],
  638. 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) nextChild;\x0a\x09\x09proceed;\x0a\x09\x09result",
  639. messageSends: ["new", "receiver:", "keysAndValuesDo:", "localAt:put:", "context:", "interpreter", "interpret:", "nextChild", "parse:forClass:", "class", "proceed", "result"],
  640. referencedClasses: ["AIContext"]
  641. }),
  642. smalltalk.InterpreterTest);
  643. smalltalk.addMethod(
  644. smalltalk.method({
  645. selector: "interpreter",
  646. category: 'accessing',
  647. fn: function (){
  648. var self=this;
  649. function $Interpreter(){return smalltalk.Interpreter||(typeof Interpreter=="undefined"?nil:Interpreter)}
  650. return smalltalk.withContext(function($ctx1) {
  651. var $1;
  652. $1=_st($Interpreter())._new();
  653. return $1;
  654. }, function($ctx1) {$ctx1.fill(self,"interpreter",{},smalltalk.InterpreterTest)})},
  655. args: [],
  656. source: "interpreter\x0a\x09^ Interpreter new",
  657. messageSends: ["new"],
  658. referencedClasses: ["Interpreter"]
  659. }),
  660. smalltalk.InterpreterTest);
  661. smalltalk.addMethod(
  662. smalltalk.method({
  663. selector: "testBinarySend",
  664. category: 'tests',
  665. fn: function (){
  666. var self=this;
  667. return smalltalk.withContext(function($ctx1) {
  668. self._assert_equals_(self._interpret_("foo ^ 2+3+4"),(9));
  669. return self}, function($ctx1) {$ctx1.fill(self,"testBinarySend",{},smalltalk.InterpreterTest)})},
  670. args: [],
  671. source: "testBinarySend\x0a\x09self assert: (self interpret: 'foo ^ 2+3+4') equals: 9",
  672. messageSends: ["assert:equals:", "interpret:"],
  673. referencedClasses: []
  674. }),
  675. smalltalk.InterpreterTest);
  676. smalltalk.addMethod(
  677. smalltalk.method({
  678. selector: "testBlockLiteral",
  679. category: 'tests',
  680. fn: function (){
  681. var self=this;
  682. return smalltalk.withContext(function($ctx1) {
  683. self._assert_equals_(self._interpret_("foo ^ true ifTrue: [ 1 ] ifFalse: [ 2 ]"),(1));
  684. self._assert_equals_(self._interpret_("foo true ifTrue: [ ^ 1 ] ifFalse: [ 2 ]"),(1));
  685. self._assert_equals_(self._interpret_("foo ^ false ifTrue: [ 1 ] ifFalse: [ 2 ]"),(2));
  686. return self}, function($ctx1) {$ctx1.fill(self,"testBlockLiteral",{},smalltalk.InterpreterTest)})},
  687. args: [],
  688. 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",
  689. messageSends: ["assert:equals:", "interpret:"],
  690. referencedClasses: []
  691. }),
  692. smalltalk.InterpreterTest);
  693. smalltalk.addMethod(
  694. smalltalk.method({
  695. selector: "testCascade",
  696. category: 'tests',
  697. fn: function (){
  698. var self=this;
  699. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  700. return smalltalk.withContext(function($ctx1) {
  701. self._assert_equals_(self._interpret_("foo ^ OrderedCollection new add: 2; add: 3; yourself"),_st($OrderedCollection())._with_with_((2),(3)));
  702. return self}, function($ctx1) {$ctx1.fill(self,"testCascade",{},smalltalk.InterpreterTest)})},
  703. args: [],
  704. source: "testCascade\x0a\x09self assert: (self interpret: 'foo ^ OrderedCollection new add: 2; add: 3; yourself') equals: (OrderedCollection with: 2 with: 3)",
  705. messageSends: ["assert:equals:", "interpret:", "with:with:"],
  706. referencedClasses: ["OrderedCollection"]
  707. }),
  708. smalltalk.InterpreterTest);
  709. smalltalk.addMethod(
  710. smalltalk.method({
  711. selector: "testDynamicArray",
  712. category: 'tests',
  713. fn: function (){
  714. var self=this;
  715. return smalltalk.withContext(function($ctx1) {
  716. self._assert_equals_(self._interpret_("foo ^ {1+1. 2+2}"),[(2), (4)]);
  717. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicArray",{},smalltalk.InterpreterTest)})},
  718. args: [],
  719. source: "testDynamicArray\x0a\x09self assert: (self interpret: 'foo ^ {1+1. 2+2}') equals: #(2 4)",
  720. messageSends: ["assert:equals:", "interpret:"],
  721. referencedClasses: []
  722. }),
  723. smalltalk.InterpreterTest);
  724. smalltalk.addMethod(
  725. smalltalk.method({
  726. selector: "testDynamicDictionary",
  727. category: 'tests',
  728. fn: function (){
  729. var self=this;
  730. return smalltalk.withContext(function($ctx1) {
  731. self._assert_equals_(self._interpret_("foo ^ #{1->1. 2->3}"),smalltalk.HashedCollection._from_([(1).__minus_gt((1)),(2).__minus_gt((3))]));
  732. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicDictionary",{},smalltalk.InterpreterTest)})},
  733. args: [],
  734. source: "testDynamicDictionary\x0a\x09self assert: (self interpret: 'foo ^ #{1->1. 2->3}') equals: #{1->1. 2->3}",
  735. messageSends: ["assert:equals:", "interpret:", "->"],
  736. referencedClasses: []
  737. }),
  738. smalltalk.InterpreterTest);
  739. smalltalk.addMethod(
  740. smalltalk.method({
  741. selector: "testGlobalVar",
  742. category: 'tests',
  743. fn: function (){
  744. var self=this;
  745. return smalltalk.withContext(function($ctx1) {
  746. self._assert_equals_(self._interpret_("foo ^ window document title"),_st(_st(window)._document())._title());
  747. return self}, function($ctx1) {$ctx1.fill(self,"testGlobalVar",{},smalltalk.InterpreterTest)})},
  748. args: [],
  749. source: "testGlobalVar\x0a\x09self assert: (self interpret: 'foo ^ window document title') equals: window document title",
  750. messageSends: ["assert:equals:", "interpret:", "title", "document"],
  751. referencedClasses: []
  752. }),
  753. smalltalk.InterpreterTest);
  754. smalltalk.addMethod(
  755. smalltalk.method({
  756. selector: "testInlinedJSStatement",
  757. category: 'tests',
  758. fn: function (){
  759. var self=this;
  760. return smalltalk.withContext(function($ctx1) {
  761. self._assert_equals_(self._interpret_("foo <return 2+3>"),(5));
  762. self._assert_equals_(self._interpret_withArguments_("foo: anInteger <return 2 + anInteger>",smalltalk.HashedCollection._from_(["anInteger".__minus_gt((3))])),(5));
  763. return self}, function($ctx1) {$ctx1.fill(self,"testInlinedJSStatement",{},smalltalk.InterpreterTest)})},
  764. args: [],
  765. 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",
  766. messageSends: ["assert:equals:", "interpret:", "interpret:withArguments:", "->"],
  767. referencedClasses: []
  768. }),
  769. smalltalk.InterpreterTest);
  770. smalltalk.addMethod(
  771. smalltalk.method({
  772. selector: "testInstVarAccess",
  773. category: 'tests',
  774. fn: function (){
  775. var self=this;
  776. return smalltalk.withContext(function($ctx1) {
  777. self._assert_equals_(self._interpret_receiver_withArguments_("foo ^ x",(2).__at((3)),smalltalk.HashedCollection._from_([])),(2));
  778. return self}, function($ctx1) {$ctx1.fill(self,"testInstVarAccess",{},smalltalk.InterpreterTest)})},
  779. args: [],
  780. 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",
  781. messageSends: ["assert:equals:", "interpret:receiver:withArguments:", "@"],
  782. referencedClasses: []
  783. }),
  784. smalltalk.InterpreterTest);
  785. smalltalk.addMethod(
  786. smalltalk.method({
  787. selector: "testInstVarAssignment",
  788. category: 'tests',
  789. fn: function (){
  790. var self=this;
  791. function $Point(){return smalltalk.Point||(typeof Point=="undefined"?nil:Point)}
  792. return smalltalk.withContext(function($ctx1) {
  793. self._assert_equals_(self._interpret_receiver_withArguments_("foo: anInteger x := anInteger. ^ x",_st($Point())._new(),smalltalk.HashedCollection._from_(["anInteger".__minus_gt((2))])),(2));
  794. return self}, function($ctx1) {$ctx1.fill(self,"testInstVarAssignment",{},smalltalk.InterpreterTest)})},
  795. args: [],
  796. 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",
  797. messageSends: ["assert:equals:", "interpret:receiver:withArguments:", "new", "->"],
  798. referencedClasses: ["Point"]
  799. }),
  800. smalltalk.InterpreterTest);
  801. smalltalk.addMethod(
  802. smalltalk.method({
  803. selector: "testKeywordSend",
  804. category: 'tests',
  805. fn: function (){
  806. var self=this;
  807. return smalltalk.withContext(function($ctx1) {
  808. self._assert_equals_(self._interpret_("foo ^ Point x: 1 y: 2"),(1).__at((2)));
  809. return self}, function($ctx1) {$ctx1.fill(self,"testKeywordSend",{},smalltalk.InterpreterTest)})},
  810. args: [],
  811. source: "testKeywordSend\x0a\x09self assert: (self interpret: 'foo ^ Point x: 1 y: 2') equals: 1@2",
  812. messageSends: ["assert:equals:", "interpret:", "@"],
  813. referencedClasses: []
  814. }),
  815. smalltalk.InterpreterTest);
  816. smalltalk.addMethod(
  817. smalltalk.method({
  818. selector: "testMultipleSequences",
  819. category: 'tests',
  820. fn: function (){
  821. var self=this;
  822. return smalltalk.withContext(function($ctx1) {
  823. self._assert_equals_(self._interpret_("foo | a b c | a := 2. b := 3. c := a + b. ^ c * 6"),(30));
  824. return self}, function($ctx1) {$ctx1.fill(self,"testMultipleSequences",{},smalltalk.InterpreterTest)})},
  825. args: [],
  826. source: "testMultipleSequences\x0a\x09self assert: (self interpret: 'foo | a b c | a := 2. b := 3. c := a + b. ^ c * 6') equals: 30",
  827. messageSends: ["assert:equals:", "interpret:"],
  828. referencedClasses: []
  829. }),
  830. smalltalk.InterpreterTest);
  831. smalltalk.addMethod(
  832. smalltalk.method({
  833. selector: "testNestedSends",
  834. category: 'tests',
  835. fn: function (){
  836. var self=this;
  837. function $Point(){return smalltalk.Point||(typeof Point=="undefined"?nil:Point)}
  838. return smalltalk.withContext(function($ctx1) {
  839. self._assert_equals_(self._interpret_("foo ^ (Point x: (Point x: 2 y: 3) y: 4) asString"),_st(_st($Point())._x_y_((2).__at((3)),(4)))._asString());
  840. return self}, function($ctx1) {$ctx1.fill(self,"testNestedSends",{},smalltalk.InterpreterTest)})},
  841. args: [],
  842. source: "testNestedSends\x0a\x09self assert: (self interpret: 'foo ^ (Point x: (Point x: 2 y: 3) y: 4) asString') equals: (Point x: (2@3) y: 4) asString",
  843. messageSends: ["assert:equals:", "interpret:", "asString", "x:y:", "@"],
  844. referencedClasses: ["Point"]
  845. }),
  846. smalltalk.InterpreterTest);
  847. smalltalk.addMethod(
  848. smalltalk.method({
  849. selector: "testNonlocalReturn",
  850. category: 'tests',
  851. fn: function (){
  852. var self=this;
  853. return smalltalk.withContext(function($ctx1) {
  854. self._assert_equals_(self._interpret_("foo true ifTrue: [ ^ 1 ]. ^2"),(1));
  855. return self}, function($ctx1) {$ctx1.fill(self,"testNonlocalReturn",{},smalltalk.InterpreterTest)})},
  856. args: [],
  857. source: "testNonlocalReturn\x0a\x09self assert: (self interpret: 'foo true ifTrue: [ ^ 1 ]. ^2') equals: 1",
  858. messageSends: ["assert:equals:", "interpret:"],
  859. referencedClasses: []
  860. }),
  861. smalltalk.InterpreterTest);
  862. smalltalk.addMethod(
  863. smalltalk.method({
  864. selector: "testReceiver",
  865. category: 'tests',
  866. fn: function (){
  867. var self=this;
  868. return smalltalk.withContext(function($ctx1) {
  869. self._assert_equals_(self._interpret_receiver_withArguments_("foo ^ self",(2).__at((3)),smalltalk.HashedCollection._from_([])),(2).__at((3)));
  870. return self}, function($ctx1) {$ctx1.fill(self,"testReceiver",{},smalltalk.InterpreterTest)})},
  871. args: [],
  872. 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",
  873. messageSends: ["assert:equals:", "interpret:receiver:withArguments:", "@"],
  874. referencedClasses: []
  875. }),
  876. smalltalk.InterpreterTest);
  877. smalltalk.addMethod(
  878. smalltalk.method({
  879. selector: "testSuper",
  880. category: 'tests',
  881. fn: function (){
  882. var self=this;
  883. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  884. return smalltalk.withContext(function($ctx1) {
  885. self._assert_equals_(self._interpret_receiver_withArguments_("foo ^ super isBoolean",true,_st($Dictionary())._new()),false);
  886. return self}, function($ctx1) {$ctx1.fill(self,"testSuper",{},smalltalk.InterpreterTest)})},
  887. args: [],
  888. source: "testSuper\x0a\x09self \x0a\x09\x09assert: (self \x0a\x09\x09\x09interpret: 'foo ^ super isBoolean' \x0a\x09\x09\x09receiver: true \x0a\x09\x09\x09withArguments: Dictionary new) \x0a\x09\x09equals: false",
  889. messageSends: ["assert:equals:", "interpret:receiver:withArguments:", "new"],
  890. referencedClasses: ["Dictionary"]
  891. }),
  892. smalltalk.InterpreterTest);
  893. smalltalk.addMethod(
  894. smalltalk.method({
  895. selector: "testTempAssignment",
  896. category: 'tests',
  897. fn: function (){
  898. var self=this;
  899. return smalltalk.withContext(function($ctx1) {
  900. self._assert_equals_(self._interpret_("foo | a | a := 2. ^ a"),(2));
  901. return self}, function($ctx1) {$ctx1.fill(self,"testTempAssignment",{},smalltalk.InterpreterTest)})},
  902. args: [],
  903. source: "testTempAssignment\x0a\x09self assert: (self interpret: 'foo | a | a := 2. ^ a') equals: 2",
  904. messageSends: ["assert:equals:", "interpret:"],
  905. referencedClasses: []
  906. }),
  907. smalltalk.InterpreterTest);
  908. smalltalk.addMethod(
  909. smalltalk.method({
  910. selector: "testThisContext",
  911. category: 'tests',
  912. fn: function (){
  913. var self=this;
  914. return smalltalk.withContext(function($ctx1) {
  915. self._assert_(_st(_st(self._interpret_("foo ^ thisContext"))._outerContext())._isNil());
  916. self._assert_(_st(_st(self._interpret_("foo ^ [ thisContext ] value"))._outerContext())._notNil());
  917. self._assert_(self._interpret_("foo ^ [ thisContext ] value outerContext == thisContext"));
  918. return self}, function($ctx1) {$ctx1.fill(self,"testThisContext",{},smalltalk.InterpreterTest)})},
  919. args: [],
  920. source: "testThisContext\x0a\x09self assert: (self interpret: 'foo ^ thisContext') outerContext isNil.\x0a\x09self assert: (self interpret: 'foo ^ [ thisContext ] value') outerContext notNil.\x0a\x09self assert: (self interpret: 'foo ^ [ thisContext ] value outerContext == thisContext')",
  921. messageSends: ["assert:", "isNil", "outerContext", "interpret:", "notNil"],
  922. referencedClasses: []
  923. }),
  924. smalltalk.InterpreterTest);
  925. smalltalk.addMethod(
  926. smalltalk.method({
  927. selector: "testUnarySend",
  928. category: 'tests',
  929. fn: function (){
  930. var self=this;
  931. return smalltalk.withContext(function($ctx1) {
  932. self._assert_equals_(self._interpret_("foo ^ 1 asString"),"1");
  933. return self}, function($ctx1) {$ctx1.fill(self,"testUnarySend",{},smalltalk.InterpreterTest)})},
  934. args: [],
  935. source: "testUnarySend\x0a\x09self assert: (self interpret: 'foo ^ 1 asString') equals: '1'",
  936. messageSends: ["assert:equals:", "interpret:"],
  937. referencedClasses: []
  938. }),
  939. smalltalk.InterpreterTest);
  940. smalltalk.addClass('CodeGeneratorTest', smalltalk.TestCase, ['receiver'], 'Compiler-Tests');
  941. smalltalk.addMethod(
  942. smalltalk.method({
  943. selector: "codeGeneratorClass",
  944. category: 'accessing',
  945. fn: function (){
  946. var self=this;
  947. function $CodeGenerator(){return smalltalk.CodeGenerator||(typeof CodeGenerator=="undefined"?nil:CodeGenerator)}
  948. return smalltalk.withContext(function($ctx1) {
  949. var $1;
  950. $1=$CodeGenerator();
  951. return $1;
  952. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{},smalltalk.CodeGeneratorTest)})},
  953. args: [],
  954. source: "codeGeneratorClass\x0a\x09^ CodeGenerator",
  955. messageSends: [],
  956. referencedClasses: ["CodeGenerator"]
  957. }),
  958. smalltalk.CodeGeneratorTest);
  959. smalltalk.addMethod(
  960. smalltalk.method({
  961. selector: "compiler",
  962. category: 'factory',
  963. fn: function (){
  964. var self=this;
  965. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  966. return smalltalk.withContext(function($ctx1) {
  967. var $2,$3,$1;
  968. $2=_st($Compiler())._new();
  969. _st($2)._codeGeneratorClass_(self._codeGeneratorClass());
  970. $3=_st($2)._yourself();
  971. $1=$3;
  972. return $1;
  973. }, function($ctx1) {$ctx1.fill(self,"compiler",{},smalltalk.CodeGeneratorTest)})},
  974. args: [],
  975. source: "compiler\x0a\x09^ Compiler new\x0a\x09\x09codeGeneratorClass: self codeGeneratorClass;\x0a\x09\x09yourself",
  976. messageSends: ["codeGeneratorClass:", "new", "codeGeneratorClass", "yourself"],
  977. referencedClasses: ["Compiler"]
  978. }),
  979. smalltalk.CodeGeneratorTest);
  980. smalltalk.addMethod(
  981. smalltalk.method({
  982. selector: "setUp",
  983. category: 'initialization',
  984. fn: function (){
  985. var self=this;
  986. return smalltalk.withContext(function($ctx1) {
  987. self["@receiver"]=_st(self._targetClass())._new();
  988. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},smalltalk.CodeGeneratorTest)})},
  989. args: [],
  990. source: "setUp\x0a\x09receiver := self targetClass new",
  991. messageSends: ["new", "targetClass"],
  992. referencedClasses: []
  993. }),
  994. smalltalk.CodeGeneratorTest);
  995. smalltalk.addMethod(
  996. smalltalk.method({
  997. selector: "should:return:",
  998. category: 'testing',
  999. fn: function (aString,anObject){
  1000. var self=this;
  1001. var method,result;
  1002. return smalltalk.withContext(function($ctx1) {
  1003. method=_st(self._compiler())._install_forClass_category_(aString,self._targetClass(),"tests");
  1004. result=_st(self["@receiver"])._perform_(_st(method)._selector());
  1005. _st(self._targetClass())._removeCompiledMethod_(method);
  1006. self._assert_equals_(anObject,result);
  1007. return self}, function($ctx1) {$ctx1.fill(self,"should:return:",{aString:aString,anObject:anObject,method:method,result:result},smalltalk.CodeGeneratorTest)})},
  1008. args: ["aString", "anObject"],
  1009. 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",
  1010. messageSends: ["install:forClass:category:", "compiler", "targetClass", "perform:", "selector", "removeCompiledMethod:", "assert:equals:"],
  1011. referencedClasses: []
  1012. }),
  1013. smalltalk.CodeGeneratorTest);
  1014. smalltalk.addMethod(
  1015. smalltalk.method({
  1016. selector: "targetClass",
  1017. category: 'accessing',
  1018. fn: function (){
  1019. var self=this;
  1020. function $DoIt(){return smalltalk.DoIt||(typeof DoIt=="undefined"?nil:DoIt)}
  1021. return smalltalk.withContext(function($ctx1) {
  1022. var $1;
  1023. $1=$DoIt();
  1024. return $1;
  1025. }, function($ctx1) {$ctx1.fill(self,"targetClass",{},smalltalk.CodeGeneratorTest)})},
  1026. args: [],
  1027. source: "targetClass\x0a\x09^ DoIt",
  1028. messageSends: [],
  1029. referencedClasses: ["DoIt"]
  1030. }),
  1031. smalltalk.CodeGeneratorTest);
  1032. smalltalk.addMethod(
  1033. smalltalk.method({
  1034. selector: "tearDown",
  1035. category: 'initialization',
  1036. fn: function (){
  1037. var self=this;
  1038. return smalltalk.withContext(function($ctx1) {
  1039. return self}, function($ctx1) {$ctx1.fill(self,"tearDown",{},smalltalk.CodeGeneratorTest)})},
  1040. args: [],
  1041. source: "tearDown\x0a\x09\x22receiver := nil\x22",
  1042. messageSends: [],
  1043. referencedClasses: []
  1044. }),
  1045. smalltalk.CodeGeneratorTest);
  1046. smalltalk.addMethod(
  1047. smalltalk.method({
  1048. selector: "testAssignment",
  1049. category: 'tests',
  1050. fn: function (){
  1051. var self=this;
  1052. return smalltalk.withContext(function($ctx1) {
  1053. self._should_return_("foo | a | a := true ifTrue: [ 1 ]. ^ a",(1));
  1054. self._should_return_("foo | a | a := false ifTrue: [ 1 ]. ^ a",nil);
  1055. self._should_return_("foo | a | ^ a := true ifTrue: [ 1 ]",(1));
  1056. return self}, function($ctx1) {$ctx1.fill(self,"testAssignment",{},smalltalk.CodeGeneratorTest)})},
  1057. args: [],
  1058. 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",
  1059. messageSends: ["should:return:"],
  1060. referencedClasses: []
  1061. }),
  1062. smalltalk.CodeGeneratorTest);
  1063. smalltalk.addMethod(
  1064. smalltalk.method({
  1065. selector: "testBackslashSelectors",
  1066. category: 'tests',
  1067. fn: function (){
  1068. var self=this;
  1069. return smalltalk.withContext(function($ctx1) {
  1070. self._should_return_("\x5c arg ^ 4",(4));
  1071. self._should_return_("\x5c\x5c arg ^ 42",(42));
  1072. return self}, function($ctx1) {$ctx1.fill(self,"testBackslashSelectors",{},smalltalk.CodeGeneratorTest)})},
  1073. args: [],
  1074. source: "testBackslashSelectors\x0a\x09\x0a\x09self should: '\x5c arg ^ 4' return: 4.\x0a\x09self should: '\x5c\x5c arg ^ 42' return: 42",
  1075. messageSends: ["should:return:"],
  1076. referencedClasses: []
  1077. }),
  1078. smalltalk.CodeGeneratorTest);
  1079. smalltalk.addMethod(
  1080. smalltalk.method({
  1081. selector: "testBlockReturn",
  1082. category: 'tests',
  1083. fn: function (){
  1084. var self=this;
  1085. return smalltalk.withContext(function($ctx1) {
  1086. self._should_return_("foo ^ #(1 2 3) collect: [ :each | true ifTrue: [ each + 1 ] ]",[(2), (3), (4)]);
  1087. self._should_return_("foo ^ #(1 2 3) collect: [ :each | false ifFalse: [ each + 1 ] ]",[(2), (3), (4)]);
  1088. self._should_return_("foo ^ #(1 2 3) collect: [ :each | each odd ifTrue: [ each + 1 ] ifFalse: [ each - 1 ] ]",[(2), (1), (4)]);
  1089. return self}, function($ctx1) {$ctx1.fill(self,"testBlockReturn",{},smalltalk.CodeGeneratorTest)})},
  1090. args: [],
  1091. 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).",
  1092. messageSends: ["should:return:"],
  1093. referencedClasses: []
  1094. }),
  1095. smalltalk.CodeGeneratorTest);
  1096. smalltalk.addMethod(
  1097. smalltalk.method({
  1098. selector: "testCascades",
  1099. category: 'tests',
  1100. fn: function (){
  1101. var self=this;
  1102. return smalltalk.withContext(function($ctx1) {
  1103. self._should_return_("foo ^ Array new add: 3; add: 4; yourself",[(3), (4)]);
  1104. return self}, function($ctx1) {$ctx1.fill(self,"testCascades",{},smalltalk.CodeGeneratorTest)})},
  1105. args: [],
  1106. source: "testCascades\x0a\x09\x0a\x09self should: 'foo ^ Array new add: 3; add: 4; yourself' return: #(3 4)",
  1107. messageSends: ["should:return:"],
  1108. referencedClasses: []
  1109. }),
  1110. smalltalk.CodeGeneratorTest);
  1111. smalltalk.addMethod(
  1112. smalltalk.method({
  1113. selector: "testDynamicArrayElementsOrdered",
  1114. category: 'tests',
  1115. fn: function (){
  1116. var self=this;
  1117. return smalltalk.withContext(function($ctx1) {
  1118. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { x. true ifTrue: [ x := 2 ] }\x0a",[(1), (2)]);
  1119. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicArrayElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  1120. args: [],
  1121. source: "testDynamicArrayElementsOrdered\x0a\x09self should: 'foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { x. true ifTrue: [ x := 2 ] }\x0a' return: #(1 2).",
  1122. messageSends: ["should:return:"],
  1123. referencedClasses: []
  1124. }),
  1125. smalltalk.CodeGeneratorTest);
  1126. smalltalk.addMethod(
  1127. smalltalk.method({
  1128. selector: "testDynamicDictionaryElementsOrdered",
  1129. category: 'tests',
  1130. fn: function (){
  1131. var self=this;
  1132. return smalltalk.withContext(function($ctx1) {
  1133. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 'foo'->1.\x0a\x09^ #{ x. (true ifTrue: [ x := 'bar'->2 ]) }\x0a",smalltalk.HashedCollection._from_(["foo".__minus_gt((1)),"bar".__minus_gt((2))]));
  1134. return self}, function($ctx1) {$ctx1.fill(self,"testDynamicDictionaryElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  1135. args: [],
  1136. 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}.",
  1137. messageSends: ["should:return:", "->"],
  1138. referencedClasses: []
  1139. }),
  1140. smalltalk.CodeGeneratorTest);
  1141. smalltalk.addMethod(
  1142. smalltalk.method({
  1143. selector: "testInnerTemporalDependentElementsOrdered",
  1144. category: 'tests',
  1145. fn: function (){
  1146. var self=this;
  1147. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  1148. return smalltalk.withContext(function($ctx1) {
  1149. self._should_return_("foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: 'foo'->x with: 'bar'->(true ifTrue: [ x := 2 ])\x0a",["foo".__minus_gt($Array()),"bar".__minus_gt((2))]);
  1150. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ Array with: 'foo'->x with: 'bar'->(true ifTrue: [ x := 2 ])\x0a",["foo".__minus_gt((1)),"bar".__minus_gt((2))]);
  1151. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ { 'foo'->x. 'bar'->(true ifTrue: [ x := 2 ]) }\x0a",["foo".__minus_gt((1)),"bar".__minus_gt((2))]);
  1152. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ #{ 'foo'->x. 'bar'->(true ifTrue: [ x := 2 ]) }\x0a",smalltalk.HashedCollection._from_(["foo".__minus_gt((1)),"bar".__minus_gt((2))]));
  1153. return self}, function($ctx1) {$ctx1.fill(self,"testInnerTemporalDependentElementsOrdered",{},smalltalk.CodeGeneratorTest)})},
  1154. args: [],
  1155. 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}.",
  1156. messageSends: ["should:return:", "->"],
  1157. referencedClasses: ["Array"]
  1158. }),
  1159. smalltalk.CodeGeneratorTest);
  1160. smalltalk.addMethod(
  1161. smalltalk.method({
  1162. selector: "testLiterals",
  1163. category: 'tests',
  1164. fn: function (){
  1165. var self=this;
  1166. return smalltalk.withContext(function($ctx1) {
  1167. self._should_return_("foo ^ 1",(1));
  1168. self._should_return_("foo ^ 'hello'","hello");
  1169. self._should_return_("foo ^ #(1 2 3 4)",[(1), (2), (3), (4)]);
  1170. self._should_return_("foo ^ {1. [:x | x ] value: 2. 3. [4] value}",[(1), (2), (3), (4)]);
  1171. self._should_return_("foo ^ true",true);
  1172. self._should_return_("foo ^ false",false);
  1173. self._should_return_("foo ^ #{1->2. 3->4}",smalltalk.HashedCollection._from_([(1).__minus_gt((2)),(3).__minus_gt((4))]));
  1174. self._should_return_("foo ^ #hello","hello");
  1175. self._should_return_("foo ^ -123.456",(-123.456));
  1176. return self}, function($ctx1) {$ctx1.fill(self,"testLiterals",{},smalltalk.CodeGeneratorTest)})},
  1177. args: [],
  1178. 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",
  1179. messageSends: ["should:return:", "->"],
  1180. referencedClasses: []
  1181. }),
  1182. smalltalk.CodeGeneratorTest);
  1183. smalltalk.addMethod(
  1184. smalltalk.method({
  1185. selector: "testLocalReturn",
  1186. category: 'tests',
  1187. fn: function (){
  1188. var self=this;
  1189. return smalltalk.withContext(function($ctx1) {
  1190. self._should_return_("foo ^ 1",(1));
  1191. self._should_return_("foo ^ 1 + 1",(2));
  1192. self._should_return_("foo ",self["@receiver"]);
  1193. self._should_return_("foo self asString",self["@receiver"]);
  1194. self._should_return_("foo | a b | a := 1. b := 2. ^ a + b",(3));
  1195. return self}, function($ctx1) {$ctx1.fill(self,"testLocalReturn",{},smalltalk.CodeGeneratorTest)})},
  1196. args: [],
  1197. 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",
  1198. messageSends: ["should:return:"],
  1199. referencedClasses: []
  1200. }),
  1201. smalltalk.CodeGeneratorTest);
  1202. smalltalk.addMethod(
  1203. smalltalk.method({
  1204. selector: "testMessageSends",
  1205. category: 'tests',
  1206. fn: function (){
  1207. var self=this;
  1208. return smalltalk.withContext(function($ctx1) {
  1209. self._should_return_("foo ^ 1 asString","1");
  1210. self._should_return_("foo ^ 1 + 1",(2));
  1211. self._should_return_("foo ^ 1 + 2 * 3",(9));
  1212. self._should_return_("foo ^ 1 to: 3",[(1), (2), (3)]);
  1213. self._should_return_("foo ^ 1 to: 5 by: 2",[(1), (3), (5)]);
  1214. return self}, function($ctx1) {$ctx1.fill(self,"testMessageSends",{},smalltalk.CodeGeneratorTest)})},
  1215. args: [],
  1216. 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)",
  1217. messageSends: ["should:return:"],
  1218. referencedClasses: []
  1219. }),
  1220. smalltalk.CodeGeneratorTest);
  1221. smalltalk.addMethod(
  1222. smalltalk.method({
  1223. selector: "testMutableLiterals",
  1224. category: 'tests',
  1225. fn: function (){
  1226. var self=this;
  1227. return smalltalk.withContext(function($ctx1) {
  1228. self._should_return_("foo ^ #( 1 2 ) at: 1 put: 3; yourself",[(3), (2)]);
  1229. return self}, function($ctx1) {$ctx1.fill(self,"testMutableLiterals",{},smalltalk.CodeGeneratorTest)})},
  1230. args: [],
  1231. 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)",
  1232. messageSends: ["should:return:"],
  1233. referencedClasses: []
  1234. }),
  1235. smalltalk.CodeGeneratorTest);
  1236. smalltalk.addMethod(
  1237. smalltalk.method({
  1238. selector: "testNestedIfTrue",
  1239. category: 'tests',
  1240. fn: function (){
  1241. var self=this;
  1242. return smalltalk.withContext(function($ctx1) {
  1243. self._should_return_("foo ^ true ifTrue: [ false ifFalse: [ 1 ] ]",(1));
  1244. self._should_return_("foo ^ true ifTrue: [ false ifTrue: [ 1 ] ]",nil);
  1245. self._should_return_("foo true ifTrue: [ false ifFalse: [ ^ 1 ] ]",(1));
  1246. self._should_return_("foo true ifTrue: [ false ifTrue: [ ^ 1 ] ]",self["@receiver"]);
  1247. return self}, function($ctx1) {$ctx1.fill(self,"testNestedIfTrue",{},smalltalk.CodeGeneratorTest)})},
  1248. args: [],
  1249. 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.",
  1250. messageSends: ["should:return:"],
  1251. referencedClasses: []
  1252. }),
  1253. smalltalk.CodeGeneratorTest);
  1254. smalltalk.addMethod(
  1255. smalltalk.method({
  1256. selector: "testNonLocalReturn",
  1257. category: 'tests',
  1258. fn: function (){
  1259. var self=this;
  1260. return smalltalk.withContext(function($ctx1) {
  1261. self._should_return_("foo [ ^ 1 ] value",(1));
  1262. self._should_return_("foo [ ^ 1 + 1 ] value",(2));
  1263. self._should_return_("foo | a b | a := 1. b := 2. [ ^ a + b ] value. self halt",(3));
  1264. self._should_return_("foo [ :x | ^ x + x ] value: 4. ^ 2",(8));
  1265. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn",{},smalltalk.CodeGeneratorTest)})},
  1266. args: [],
  1267. 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",
  1268. messageSends: ["should:return:"],
  1269. referencedClasses: []
  1270. }),
  1271. smalltalk.CodeGeneratorTest);
  1272. smalltalk.addMethod(
  1273. smalltalk.method({
  1274. selector: "testPascalCaseGlobal",
  1275. category: 'tests',
  1276. fn: function (){
  1277. var self=this;
  1278. return smalltalk.withContext(function($ctx1) {
  1279. self._should_return_("foo ^Object",_st(smalltalk)._at_("Object"));
  1280. self._should_return_("foo ^NonExistent",nil);
  1281. return self}, function($ctx1) {$ctx1.fill(self,"testPascalCaseGlobal",{},smalltalk.CodeGeneratorTest)})},
  1282. args: [],
  1283. source: "testPascalCaseGlobal\x0a\x09self should: 'foo ^Object' return: (smalltalk at: 'Object').\x0a\x09self should: 'foo ^NonExistent' return: nil",
  1284. messageSends: ["should:return:", "at:"],
  1285. referencedClasses: []
  1286. }),
  1287. smalltalk.CodeGeneratorTest);
  1288. smalltalk.addMethod(
  1289. smalltalk.method({
  1290. selector: "testSendReceiverAndArgumentsOrdered",
  1291. category: 'tests',
  1292. fn: function (){
  1293. var self=this;
  1294. function $Array(){return smalltalk.Array||(typeof Array=="undefined"?nil:Array)}
  1295. return smalltalk.withContext(function($ctx1) {
  1296. self._should_return_("foo\x0a\x09| x |\x0a\x09x := 1.\x0a\x09^ Array with: x with: (true ifTrue: [ x := 2 ])\x0a",[(1), (2)]);
  1297. self._should_return_("foo\x0a\x09| x |\x0a\x09x := Array.\x0a\x09^ x with: x with: (true ifTrue: [ x := 2 ])\x0a",[$Array(),(2)]);
  1298. return self}, function($ctx1) {$ctx1.fill(self,"testSendReceiverAndArgumentsOrdered",{},smalltalk.CodeGeneratorTest)})},
  1299. args: [],
  1300. 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}.",
  1301. messageSends: ["should:return:"],
  1302. referencedClasses: ["Array"]
  1303. }),
  1304. smalltalk.CodeGeneratorTest);
  1305. smalltalk.addMethod(
  1306. smalltalk.method({
  1307. selector: "testifFalse",
  1308. category: 'tests',
  1309. fn: function (){
  1310. var self=this;
  1311. return smalltalk.withContext(function($ctx1) {
  1312. self._should_return_("foo true ifFalse: [ ^ 1 ]",self["@receiver"]);
  1313. self._should_return_("foo false ifFalse: [ ^ 2 ]",(2));
  1314. self._should_return_("foo ^ true ifFalse: [ 1 ]",nil);
  1315. self._should_return_("foo ^ false ifFalse: [ 2 ]",(2));
  1316. return self}, function($ctx1) {$ctx1.fill(self,"testifFalse",{},smalltalk.CodeGeneratorTest)})},
  1317. args: [],
  1318. 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.",
  1319. messageSends: ["should:return:"],
  1320. referencedClasses: []
  1321. }),
  1322. smalltalk.CodeGeneratorTest);
  1323. smalltalk.addMethod(
  1324. smalltalk.method({
  1325. selector: "testifFalseIfTrue",
  1326. category: 'tests',
  1327. fn: function (){
  1328. var self=this;
  1329. return smalltalk.withContext(function($ctx1) {
  1330. self._should_return_("foo true ifFalse: [ ^ 1 ] ifTrue: [ ^ 2 ]",(2));
  1331. self._should_return_("foo false ifFalse: [ ^ 2 ] ifTrue: [ ^1 ]",(2));
  1332. self._should_return_("foo ^ true ifFalse: [ 1 ] ifTrue: [ 2 ]",(2));
  1333. self._should_return_("foo ^ false ifFalse: [ 2 ] ifTrue: [ 1 ]",(2));
  1334. return self}, function($ctx1) {$ctx1.fill(self,"testifFalseIfTrue",{},smalltalk.CodeGeneratorTest)})},
  1335. args: [],
  1336. 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.",
  1337. messageSends: ["should:return:"],
  1338. referencedClasses: []
  1339. }),
  1340. smalltalk.CodeGeneratorTest);
  1341. smalltalk.addMethod(
  1342. smalltalk.method({
  1343. selector: "testifNil",
  1344. category: 'tests',
  1345. fn: function (){
  1346. var self=this;
  1347. return smalltalk.withContext(function($ctx1) {
  1348. self._should_return_("foo ^ 1 ifNil: [ 2 ]",(1));
  1349. self._should_return_("foo ^ nil ifNil: [ 2 ]",(2));
  1350. self._should_return_("foo 1 ifNil: [ ^ 2 ]",self["@receiver"]);
  1351. self._should_return_("foo nil ifNil: [ ^ 2 ]",(2));
  1352. return self}, function($ctx1) {$ctx1.fill(self,"testifNil",{},smalltalk.CodeGeneratorTest)})},
  1353. args: [],
  1354. 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.",
  1355. messageSends: ["should:return:"],
  1356. referencedClasses: []
  1357. }),
  1358. smalltalk.CodeGeneratorTest);
  1359. smalltalk.addMethod(
  1360. smalltalk.method({
  1361. selector: "testifNilIfNotNil",
  1362. category: 'tests',
  1363. fn: function (){
  1364. var self=this;
  1365. return smalltalk.withContext(function($ctx1) {
  1366. self._should_return_("foo ^ 1 ifNil: [ 2 ] ifNotNil: [ 3 ]",(3));
  1367. self._should_return_("foo ^ nil ifNil: [ 2 ] ifNotNil: [ 3 ]",(2));
  1368. self._should_return_("foo 1 ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(3));
  1369. self._should_return_("foo nil ifNil: [ ^ 2 ] ifNotNil: [ ^3 ]",(2));
  1370. return self}, function($ctx1) {$ctx1.fill(self,"testifNilIfNotNil",{},smalltalk.CodeGeneratorTest)})},
  1371. args: [],
  1372. 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.",
  1373. messageSends: ["should:return:"],
  1374. referencedClasses: []
  1375. }),
  1376. smalltalk.CodeGeneratorTest);
  1377. smalltalk.addMethod(
  1378. smalltalk.method({
  1379. selector: "testifNotNil",
  1380. category: 'tests',
  1381. fn: function (){
  1382. var self=this;
  1383. return smalltalk.withContext(function($ctx1) {
  1384. self._should_return_("foo ^ 1 ifNotNil: [ 2 ]",(2));
  1385. self._should_return_("foo ^ nil ifNotNil: [ 2 ]",nil);
  1386. self._should_return_("foo 1 ifNotNil: [ ^ 2 ]",(2));
  1387. self._should_return_("foo nil ifNotNil: [ ^ 2 ]",self["@receiver"]);
  1388. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNil",{},smalltalk.CodeGeneratorTest)})},
  1389. args: [],
  1390. 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.",
  1391. messageSends: ["should:return:"],
  1392. referencedClasses: []
  1393. }),
  1394. smalltalk.CodeGeneratorTest);
  1395. smalltalk.addMethod(
  1396. smalltalk.method({
  1397. selector: "testifNotNilWithArgument",
  1398. category: 'tests',
  1399. fn: function (){
  1400. var self=this;
  1401. return smalltalk.withContext(function($ctx1) {
  1402. self._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ]",(3));
  1403. self._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ]",nil);
  1404. self._should_return_("foo ^ 1 ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(3));
  1405. self._should_return_("foo ^ nil ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]",(5));
  1406. self._should_return_("foo ^ 1 ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(3));
  1407. self._should_return_("foo ^ nil ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]",(5));
  1408. return self}, function($ctx1) {$ctx1.fill(self,"testifNotNilWithArgument",{},smalltalk.CodeGeneratorTest)})},
  1409. args: [],
  1410. source: "testifNotNilWithArgument\x0a\x09self should: 'foo ^ 1 ifNotNil: [ :val | val + 2 ]' return: 3.\x0a\x09self should: 'foo ^ nil ifNotNil: [ :val | val + 2 ]' return: nil.\x0a\x09\x0a\x09self should: 'foo ^ 1 ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]' return: 3.\x0a\x09self should: 'foo ^ nil ifNil: [ 5 ] ifNotNil: [ :val | val + 2 ]' return: 5.\x0a\x09\x0a\x09self should: 'foo ^ 1 ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]' return: 3.\x0a\x09self should: 'foo ^ nil ifNotNil: [ :val | val + 2 ] ifNil: [ 5 ]' return: 5",
  1411. messageSends: ["should:return:"],
  1412. referencedClasses: []
  1413. }),
  1414. smalltalk.CodeGeneratorTest);
  1415. smalltalk.addMethod(
  1416. smalltalk.method({
  1417. selector: "testifTrue",
  1418. category: 'tests',
  1419. fn: function (){
  1420. var self=this;
  1421. return smalltalk.withContext(function($ctx1) {
  1422. self._should_return_("foo false ifTrue: [ ^ 1 ]",self["@receiver"]);
  1423. self._should_return_("foo true ifTrue: [ ^ 2 ]",(2));
  1424. self._should_return_("foo ^ false ifTrue: [ 1 ]",nil);
  1425. self._should_return_("foo ^ true ifTrue: [ 2 ]",(2));
  1426. return self}, function($ctx1) {$ctx1.fill(self,"testifTrue",{},smalltalk.CodeGeneratorTest)})},
  1427. args: [],
  1428. 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.",
  1429. messageSends: ["should:return:"],
  1430. referencedClasses: []
  1431. }),
  1432. smalltalk.CodeGeneratorTest);
  1433. smalltalk.addMethod(
  1434. smalltalk.method({
  1435. selector: "testifTrueIfFalse",
  1436. category: 'tests',
  1437. fn: function (){
  1438. var self=this;
  1439. return smalltalk.withContext(function($ctx1) {
  1440. self._should_return_("foo false ifTrue: [ ^ 1 ] ifFalse: [ ^2 ]",(2));
  1441. self._should_return_("foo true ifTrue: [ ^ 1 ] ifFalse: [ ^ 2 ]",(1));
  1442. self._should_return_("foo ^ false ifTrue: [ 2 ] ifFalse: [ 1 ]",(1));
  1443. self._should_return_("foo ^ true ifTrue: [ 2 ] ifFalse: [ 1 ]",(2));
  1444. return self}, function($ctx1) {$ctx1.fill(self,"testifTrueIfFalse",{},smalltalk.CodeGeneratorTest)})},
  1445. args: [],
  1446. 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.",
  1447. messageSends: ["should:return:"],
  1448. referencedClasses: []
  1449. }),
  1450. smalltalk.CodeGeneratorTest);
  1451. smalltalk.addClass('InliningCodeGeneratorTest', smalltalk.CodeGeneratorTest, [], 'Compiler-Tests');
  1452. smalltalk.addMethod(
  1453. smalltalk.method({
  1454. selector: "codeGeneratorClass",
  1455. category: 'accessing',
  1456. fn: function (){
  1457. var self=this;
  1458. function $InliningCodeGenerator(){return smalltalk.InliningCodeGenerator||(typeof InliningCodeGenerator=="undefined"?nil:InliningCodeGenerator)}
  1459. return smalltalk.withContext(function($ctx1) {
  1460. var $1;
  1461. $1=$InliningCodeGenerator();
  1462. return $1;
  1463. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{},smalltalk.InliningCodeGeneratorTest)})},
  1464. args: [],
  1465. source: "codeGeneratorClass\x0a\x09^ InliningCodeGenerator",
  1466. messageSends: [],
  1467. referencedClasses: ["InliningCodeGenerator"]
  1468. }),
  1469. smalltalk.InliningCodeGeneratorTest);
  1470. smalltalk.addClass('ScopeVarTest', smalltalk.TestCase, [], 'Compiler-Tests');
  1471. smalltalk.addMethod(
  1472. smalltalk.method({
  1473. selector: "testClassRefVar",
  1474. category: 'tests',
  1475. fn: function (){
  1476. var self=this;
  1477. var node;
  1478. function $ClassReferenceNode(){return smalltalk.ClassReferenceNode||(typeof ClassReferenceNode=="undefined"?nil:ClassReferenceNode)}
  1479. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1480. return smalltalk.withContext(function($ctx1) {
  1481. var $1,$2;
  1482. $1=_st($ClassReferenceNode())._new();
  1483. _st($1)._value_("Object");
  1484. $2=_st($1)._yourself();
  1485. node=$2;
  1486. _st(_st($SemanticAnalyzer())._new())._visit_(node);
  1487. self._assert_(_st(_st(node)._binding())._isClassRefVar());
  1488. return self}, function($ctx1) {$ctx1.fill(self,"testClassRefVar",{node:node},smalltalk.ScopeVarTest)})},
  1489. args: [],
  1490. 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",
  1491. messageSends: ["value:", "new", "yourself", "visit:", "assert:", "isClassRefVar", "binding"],
  1492. referencedClasses: ["ClassReferenceNode", "SemanticAnalyzer"]
  1493. }),
  1494. smalltalk.ScopeVarTest);
  1495. smalltalk.addMethod(
  1496. smalltalk.method({
  1497. selector: "testInstanceVar",
  1498. category: 'tests',
  1499. fn: function (){
  1500. var self=this;
  1501. var node,scope;
  1502. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1503. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1504. return smalltalk.withContext(function($ctx1) {
  1505. var $1,$2;
  1506. $1=_st($VariableNode())._new();
  1507. _st($1)._value_("bzzz");
  1508. $2=_st($1)._yourself();
  1509. node=$2;
  1510. scope=_st($MethodLexicalScope())._new();
  1511. _st(scope)._addIVar_("bzzz");
  1512. self._assert_(_st(_st(scope)._bindingFor_(node))._isInstanceVar());
  1513. return self}, function($ctx1) {$ctx1.fill(self,"testInstanceVar",{node:node,scope:scope},smalltalk.ScopeVarTest)})},
  1514. args: [],
  1515. 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",
  1516. messageSends: ["value:", "new", "yourself", "addIVar:", "assert:", "isInstanceVar", "bindingFor:"],
  1517. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1518. }),
  1519. smalltalk.ScopeVarTest);
  1520. smalltalk.addMethod(
  1521. smalltalk.method({
  1522. selector: "testPseudoVar",
  1523. category: 'tests',
  1524. fn: function (){
  1525. var self=this;
  1526. var node,pseudoVars;
  1527. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1528. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1529. return smalltalk.withContext(function($ctx1) {
  1530. var $1,$2;
  1531. pseudoVars=["self", "super", "true", "false", "nil"];
  1532. _st(pseudoVars)._do_((function(each){
  1533. return smalltalk.withContext(function($ctx2) {
  1534. $1=_st($VariableNode())._new();
  1535. _st($1)._value_(each);
  1536. $2=_st($1)._yourself();
  1537. node=$2;
  1538. node;
  1539. return self._assert_(_st(_st(_st($MethodLexicalScope())._new())._bindingFor_(node))._isPseudoVar());
  1540. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1541. return self}, function($ctx1) {$ctx1.fill(self,"testPseudoVar",{node:node,pseudoVars:pseudoVars},smalltalk.ScopeVarTest)})},
  1542. args: [],
  1543. 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 ]",
  1544. messageSends: ["do:", "value:", "new", "yourself", "assert:", "isPseudoVar", "bindingFor:"],
  1545. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1546. }),
  1547. smalltalk.ScopeVarTest);
  1548. smalltalk.addMethod(
  1549. smalltalk.method({
  1550. selector: "testTempVar",
  1551. category: 'tests',
  1552. fn: function (){
  1553. var self=this;
  1554. var node,scope;
  1555. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1556. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1557. return smalltalk.withContext(function($ctx1) {
  1558. var $1,$2;
  1559. $1=_st($VariableNode())._new();
  1560. _st($1)._value_("bzzz");
  1561. $2=_st($1)._yourself();
  1562. node=$2;
  1563. scope=_st($MethodLexicalScope())._new();
  1564. _st(scope)._addTemp_("bzzz");
  1565. self._assert_(_st(_st(scope)._bindingFor_(node))._isTempVar());
  1566. return self}, function($ctx1) {$ctx1.fill(self,"testTempVar",{node:node,scope:scope},smalltalk.ScopeVarTest)})},
  1567. args: [],
  1568. 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",
  1569. messageSends: ["value:", "new", "yourself", "addTemp:", "assert:", "isTempVar", "bindingFor:"],
  1570. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1571. }),
  1572. smalltalk.ScopeVarTest);
  1573. smalltalk.addMethod(
  1574. smalltalk.method({
  1575. selector: "testUnknownVar",
  1576. category: 'tests',
  1577. fn: function (){
  1578. var self=this;
  1579. var node;
  1580. function $VariableNode(){return smalltalk.VariableNode||(typeof VariableNode=="undefined"?nil:VariableNode)}
  1581. function $MethodLexicalScope(){return smalltalk.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1582. return smalltalk.withContext(function($ctx1) {
  1583. var $1,$2;
  1584. $1=_st($VariableNode())._new();
  1585. _st($1)._value_("bzzz");
  1586. $2=_st($1)._yourself();
  1587. node=$2;
  1588. self._assert_(_st(_st(_st($MethodLexicalScope())._new())._bindingFor_(node))._isNil());
  1589. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVar",{node:node},smalltalk.ScopeVarTest)})},
  1590. args: [],
  1591. source: "testUnknownVar\x0a\x09| node |\x0a\x09node := VariableNode new\x0a\x09\x09value: 'bzzz';\x0a\x09\x09yourself.\x0a\x09self assert: (MethodLexicalScope new bindingFor: node) isNil",
  1592. messageSends: ["value:", "new", "yourself", "assert:", "isNil", "bindingFor:"],
  1593. referencedClasses: ["VariableNode", "MethodLexicalScope"]
  1594. }),
  1595. smalltalk.ScopeVarTest);
  1596. smalltalk.addClass('SemanticAnalyzerTest', smalltalk.TestCase, ['analyzer'], 'Compiler-Tests');
  1597. smalltalk.addMethod(
  1598. smalltalk.method({
  1599. selector: "setUp",
  1600. category: 'running',
  1601. fn: function (){
  1602. var self=this;
  1603. function $SemanticAnalyzer(){return smalltalk.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  1604. function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
  1605. return smalltalk.withContext(function($ctx1) {
  1606. self["@analyzer"]=_st($SemanticAnalyzer())._on_($Object());
  1607. return self}, function($ctx1) {$ctx1.fill(self,"setUp",{},smalltalk.SemanticAnalyzerTest)})},
  1608. args: [],
  1609. source: "setUp\x0a\x09analyzer := SemanticAnalyzer on: Object",
  1610. messageSends: ["on:"],
  1611. referencedClasses: ["SemanticAnalyzer", "Object"]
  1612. }),
  1613. smalltalk.SemanticAnalyzerTest);
  1614. smalltalk.addMethod(
  1615. smalltalk.method({
  1616. selector: "testAssignment",
  1617. category: 'tests',
  1618. fn: function (){
  1619. var self=this;
  1620. var src,ast;
  1621. function $InvalidAssignmentError(){return smalltalk.InvalidAssignmentError||(typeof InvalidAssignmentError=="undefined"?nil:InvalidAssignmentError)}
  1622. return smalltalk.withContext(function($ctx1) {
  1623. src="foo self := 1";
  1624. ast=_st(smalltalk)._parse_(src);
  1625. self._should_raise_((function(){
  1626. return smalltalk.withContext(function($ctx2) {
  1627. return _st(self["@analyzer"])._visit_(ast);
  1628. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$InvalidAssignmentError());
  1629. return self}, function($ctx1) {$ctx1.fill(self,"testAssignment",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1630. args: [],
  1631. 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",
  1632. messageSends: ["parse:", "should:raise:", "visit:"],
  1633. referencedClasses: ["InvalidAssignmentError"]
  1634. }),
  1635. smalltalk.SemanticAnalyzerTest);
  1636. smalltalk.addMethod(
  1637. smalltalk.method({
  1638. selector: "testNonLocalReturn",
  1639. category: 'tests',
  1640. fn: function (){
  1641. var self=this;
  1642. var src,ast;
  1643. return smalltalk.withContext(function($ctx1) {
  1644. src="foo | a | a + 1. ^ a";
  1645. ast=_st(smalltalk)._parse_(src);
  1646. _st(self["@analyzer"])._visit_(ast);
  1647. self._deny_(_st(_st(ast)._scope())._hasNonLocalReturn());
  1648. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1649. args: [],
  1650. 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",
  1651. messageSends: ["parse:", "visit:", "deny:", "hasNonLocalReturn", "scope"],
  1652. referencedClasses: []
  1653. }),
  1654. smalltalk.SemanticAnalyzerTest);
  1655. smalltalk.addMethod(
  1656. smalltalk.method({
  1657. selector: "testNonLocalReturn2",
  1658. category: 'tests',
  1659. fn: function (){
  1660. var self=this;
  1661. var src,ast;
  1662. return smalltalk.withContext(function($ctx1) {
  1663. src="foo | a | a + 1. [ [ ^ a] ]";
  1664. ast=_st(smalltalk)._parse_(src);
  1665. _st(self["@analyzer"])._visit_(ast);
  1666. self._assert_(_st(_st(ast)._scope())._hasNonLocalReturn());
  1667. return self}, function($ctx1) {$ctx1.fill(self,"testNonLocalReturn2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1668. args: [],
  1669. 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",
  1670. messageSends: ["parse:", "visit:", "assert:", "hasNonLocalReturn", "scope"],
  1671. referencedClasses: []
  1672. }),
  1673. smalltalk.SemanticAnalyzerTest);
  1674. smalltalk.addMethod(
  1675. smalltalk.method({
  1676. selector: "testScope",
  1677. category: 'tests',
  1678. fn: function (){
  1679. var self=this;
  1680. var src,ast;
  1681. return smalltalk.withContext(function($ctx1) {
  1682. src="foo | a | a + 1. [ | b | b := a ]";
  1683. ast=_st(smalltalk)._parse_(src);
  1684. _st(self["@analyzer"])._visit_(ast);
  1685. self._deny_(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._last())._scope()).__eq_eq(_st(ast)._scope()));
  1686. return self}, function($ctx1) {$ctx1.fill(self,"testScope",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1687. args: [],
  1688. 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.",
  1689. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "last", "nodes", "first"],
  1690. referencedClasses: []
  1691. }),
  1692. smalltalk.SemanticAnalyzerTest);
  1693. smalltalk.addMethod(
  1694. smalltalk.method({
  1695. selector: "testScope2",
  1696. category: 'tests',
  1697. fn: function (){
  1698. var self=this;
  1699. var src,ast;
  1700. return smalltalk.withContext(function($ctx1) {
  1701. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1702. ast=_st(smalltalk)._parse_(src);
  1703. _st(self["@analyzer"])._visit_(ast);
  1704. 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()));
  1705. return self}, function($ctx1) {$ctx1.fill(self,"testScope2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1706. args: [],
  1707. 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.",
  1708. messageSends: ["parse:", "visit:", "deny:", "==", "scope", "first", "nodes", "last"],
  1709. referencedClasses: []
  1710. }),
  1711. smalltalk.SemanticAnalyzerTest);
  1712. smalltalk.addMethod(
  1713. smalltalk.method({
  1714. selector: "testScopeLevel",
  1715. category: 'tests',
  1716. fn: function (){
  1717. var self=this;
  1718. var src,ast;
  1719. return smalltalk.withContext(function($ctx1) {
  1720. src="foo | a | a + 1. [ [ | b | b := a ] ]";
  1721. ast=_st(smalltalk)._parse_(src);
  1722. _st(self["@analyzer"])._visit_(ast);
  1723. self._assert_equals_(_st(_st(ast)._scope())._scopeLevel(),(1));
  1724. 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));
  1725. return self}, function($ctx1) {$ctx1.fill(self,"testScopeLevel",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1726. args: [],
  1727. 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",
  1728. messageSends: ["parse:", "visit:", "assert:equals:", "scopeLevel", "scope", "first", "nodes", "last"],
  1729. referencedClasses: []
  1730. }),
  1731. smalltalk.SemanticAnalyzerTest);
  1732. smalltalk.addMethod(
  1733. smalltalk.method({
  1734. selector: "testUnknownVariables",
  1735. category: 'tests',
  1736. fn: function (){
  1737. var self=this;
  1738. var src,ast;
  1739. function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1740. return smalltalk.withContext(function($ctx1) {
  1741. src="foo | a | b + a";
  1742. ast=_st(smalltalk)._parse_(src);
  1743. self._should_raise_((function(){
  1744. return smalltalk.withContext(function($ctx2) {
  1745. return _st(self["@analyzer"])._visit_(ast);
  1746. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$UnknownVariableError());
  1747. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariables",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1748. args: [],
  1749. 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",
  1750. messageSends: ["parse:", "should:raise:", "visit:"],
  1751. referencedClasses: ["UnknownVariableError"]
  1752. }),
  1753. smalltalk.SemanticAnalyzerTest);
  1754. smalltalk.addMethod(
  1755. smalltalk.method({
  1756. selector: "testUnknownVariablesWithScope",
  1757. category: 'tests',
  1758. fn: function (){
  1759. var self=this;
  1760. var src,ast;
  1761. function $UnknownVariableError(){return smalltalk.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1762. return smalltalk.withContext(function($ctx1) {
  1763. src="foo | a b | [ c + 1. [ a + 1. d + 1 ]]";
  1764. ast=_st(smalltalk)._parse_(src);
  1765. self._should_raise_((function(){
  1766. return smalltalk.withContext(function($ctx2) {
  1767. return _st(self["@analyzer"])._visit_(ast);
  1768. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$UnknownVariableError());
  1769. return self}, function($ctx1) {$ctx1.fill(self,"testUnknownVariablesWithScope",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1770. args: [],
  1771. 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",
  1772. messageSends: ["parse:", "should:raise:", "visit:"],
  1773. referencedClasses: ["UnknownVariableError"]
  1774. }),
  1775. smalltalk.SemanticAnalyzerTest);
  1776. smalltalk.addMethod(
  1777. smalltalk.method({
  1778. selector: "testVariableShadowing",
  1779. category: 'tests',
  1780. fn: function (){
  1781. var self=this;
  1782. var src,ast;
  1783. return smalltalk.withContext(function($ctx1) {
  1784. src="foo | a | a + 1";
  1785. ast=_st(smalltalk)._parse_(src);
  1786. _st(self["@analyzer"])._visit_(ast);
  1787. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1788. args: [],
  1789. source: "testVariableShadowing\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1790. messageSends: ["parse:", "visit:"],
  1791. referencedClasses: []
  1792. }),
  1793. smalltalk.SemanticAnalyzerTest);
  1794. smalltalk.addMethod(
  1795. smalltalk.method({
  1796. selector: "testVariableShadowing2",
  1797. category: 'tests',
  1798. fn: function (){
  1799. var self=this;
  1800. var src,ast;
  1801. function $ShadowingVariableError(){return smalltalk.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1802. return smalltalk.withContext(function($ctx1) {
  1803. src="foo | a | a + 1. [ | a | a := 2 ]";
  1804. ast=_st(smalltalk)._parse_(src);
  1805. self._should_raise_((function(){
  1806. return smalltalk.withContext(function($ctx2) {
  1807. return _st(self["@analyzer"])._visit_(ast);
  1808. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$ShadowingVariableError());
  1809. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing2",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1810. args: [],
  1811. 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",
  1812. messageSends: ["parse:", "should:raise:", "visit:"],
  1813. referencedClasses: ["ShadowingVariableError"]
  1814. }),
  1815. smalltalk.SemanticAnalyzerTest);
  1816. smalltalk.addMethod(
  1817. smalltalk.method({
  1818. selector: "testVariableShadowing3",
  1819. category: 'tests',
  1820. fn: function (){
  1821. var self=this;
  1822. var src,ast;
  1823. return smalltalk.withContext(function($ctx1) {
  1824. src="foo | a | a + 1. [ | b | b := 2 ]";
  1825. ast=_st(smalltalk)._parse_(src);
  1826. _st(self["@analyzer"])._visit_(ast);
  1827. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing3",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1828. args: [],
  1829. source: "testVariableShadowing3\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ | b | b := 2 ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1830. messageSends: ["parse:", "visit:"],
  1831. referencedClasses: []
  1832. }),
  1833. smalltalk.SemanticAnalyzerTest);
  1834. smalltalk.addMethod(
  1835. smalltalk.method({
  1836. selector: "testVariableShadowing4",
  1837. category: 'tests',
  1838. fn: function (){
  1839. var self=this;
  1840. var src,ast;
  1841. return smalltalk.withContext(function($ctx1) {
  1842. src="foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]";
  1843. ast=_st(smalltalk)._parse_(src);
  1844. _st(self["@analyzer"])._visit_(ast);
  1845. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing4",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1846. args: [],
  1847. source: "testVariableShadowing4\x0a\x09| src ast |\x0a\x09src := 'foo | a | a + 1. [ [ [ | b | b := 2 ] ] ]'.\x0a\x09ast := smalltalk parse: src.\x0a\x09analyzer visit: ast",
  1848. messageSends: ["parse:", "visit:"],
  1849. referencedClasses: []
  1850. }),
  1851. smalltalk.SemanticAnalyzerTest);
  1852. smalltalk.addMethod(
  1853. smalltalk.method({
  1854. selector: "testVariableShadowing5",
  1855. category: 'tests',
  1856. fn: function (){
  1857. var self=this;
  1858. var src,ast;
  1859. function $ShadowingVariableError(){return smalltalk.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1860. return smalltalk.withContext(function($ctx1) {
  1861. src="foo | a | a + 1. [ [ [ | a | a := 2 ] ] ]";
  1862. ast=_st(smalltalk)._parse_(src);
  1863. self._should_raise_((function(){
  1864. return smalltalk.withContext(function($ctx2) {
  1865. return _st(self["@analyzer"])._visit_(ast);
  1866. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}),$ShadowingVariableError());
  1867. return self}, function($ctx1) {$ctx1.fill(self,"testVariableShadowing5",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1868. args: [],
  1869. 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",
  1870. messageSends: ["parse:", "should:raise:", "visit:"],
  1871. referencedClasses: ["ShadowingVariableError"]
  1872. }),
  1873. smalltalk.SemanticAnalyzerTest);
  1874. smalltalk.addMethod(
  1875. smalltalk.method({
  1876. selector: "testVariablesLookup",
  1877. category: 'tests',
  1878. fn: function (){
  1879. var self=this;
  1880. var src,ast;
  1881. return smalltalk.withContext(function($ctx1) {
  1882. src="foo | a | a + 1. [ | b | b := a ]";
  1883. ast=_st(smalltalk)._parse_(src);
  1884. _st(self["@analyzer"])._visit_(ast);
  1885. self._assert_(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._first())._receiver())._binding())._isTempVar());
  1886. self._assert_(_st(_st(_st(_st(_st(_st(_st(_st(ast)._nodes())._first())._nodes())._first())._receiver())._binding())._scope()).__eq_eq(_st(ast)._scope()));
  1887. 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());
  1888. 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()));
  1889. return self}, function($ctx1) {$ctx1.fill(self,"testVariablesLookup",{src:src,ast:ast},smalltalk.SemanticAnalyzerTest)})},
  1890. args: [],
  1891. 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.",
  1892. messageSends: ["parse:", "visit:", "assert:", "isTempVar", "binding", "receiver", "first", "nodes", "==", "scope", "left", "last"],
  1893. referencedClasses: []
  1894. }),
  1895. smalltalk.SemanticAnalyzerTest);