Compiler-Tests.js 90 KB

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