Kernel-Methods.js 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109
  1. smalltalk.addPackage('Kernel-Methods', {});
  2. smalltalk.addClass('BlockClosure', smalltalk.Object, [], 'Kernel-Methods');
  3. smalltalk.BlockClosure.comment="A BlockClosure is a lexical closure.\x0aThe JavaScript representation is a function.\x0a\x0aA BlockClosure is evaluated with the `#value*` methods in the 'evaluating' protocol."
  4. smalltalk.addMethod(
  5. "_applyTo_arguments_",
  6. smalltalk.method({
  7. selector: "applyTo:arguments:",
  8. category: 'evaluating',
  9. fn: function (anObject, aCollection) {
  10. var self = this;
  11. return self.apply(anObject, aCollection);
  12. return self;
  13. },
  14. args: ["anObject", "aCollection"],
  15. source: "applyTo: anObject arguments: aCollection\x0a\x09<return self.apply(anObject, aCollection)>",
  16. messageSends: [],
  17. referencedClasses: []
  18. }),
  19. smalltalk.BlockClosure);
  20. smalltalk.addMethod(
  21. "_compiledSource",
  22. smalltalk.method({
  23. selector: "compiledSource",
  24. category: 'accessing',
  25. fn: function () {
  26. var self = this;
  27. return self.toString();
  28. return self;
  29. },
  30. args: [],
  31. source: "compiledSource\x0a\x09<return self.toString()>",
  32. messageSends: [],
  33. referencedClasses: []
  34. }),
  35. smalltalk.BlockClosure);
  36. smalltalk.addMethod(
  37. "_ensure_",
  38. smalltalk.method({
  39. selector: "ensure:",
  40. category: 'evaluating',
  41. fn: function (aBlock){
  42. var self=this;
  43. try{return self()}finally{aBlock._value()};
  44. ;
  45. return self},
  46. args: ["aBlock"],
  47. source: "ensure: aBlock\x0a\x09<try{return self()}finally{aBlock._value()}>",
  48. messageSends: [],
  49. referencedClasses: []
  50. }),
  51. smalltalk.BlockClosure);
  52. smalltalk.addMethod(
  53. "_fork",
  54. smalltalk.method({
  55. selector: "fork",
  56. category: 'timeout/interval',
  57. fn: function (){
  58. var self=this;
  59. smalltalk.send(smalltalk.send((smalltalk.ForkPool || ForkPool),"_default",[]),"_fork_",[self]);
  60. return self},
  61. args: [],
  62. source: "fork\x0a\x09ForkPool default fork: self",
  63. messageSends: ["fork:", "default"],
  64. referencedClasses: ["ForkPool"]
  65. }),
  66. smalltalk.BlockClosure);
  67. smalltalk.addMethod(
  68. "_new",
  69. smalltalk.method({
  70. selector: "new",
  71. category: 'evaluating',
  72. fn: function () {
  73. var self = this;
  74. return new self;
  75. return self;
  76. },
  77. args: [],
  78. source: "new\x0a\x09\x22Use the receiver as a JS constructor. \x0a\x09*Do not* use this method to instanciate Smalltalk objects!\x22\x0a\x09<return new self()>",
  79. messageSends: [],
  80. referencedClasses: []
  81. }),
  82. smalltalk.BlockClosure);
  83. smalltalk.addMethod(
  84. "_newValue_",
  85. smalltalk.method({
  86. selector: "newValue:",
  87. category: 'evaluating',
  88. fn: function (anObject) {
  89. var self = this;
  90. return new self(anObject);
  91. return self;
  92. },
  93. args: ["anObject"],
  94. source: "newValue: anObject\x0a\x09\x22Use the receiver as a JS constructor. \x0a\x09*Do not* use this method to instanciate Smalltalk objects!\x22\x0a\x09<return new self(anObject)>",
  95. messageSends: [],
  96. referencedClasses: []
  97. }),
  98. smalltalk.BlockClosure);
  99. smalltalk.addMethod(
  100. "_newValue_value_",
  101. smalltalk.method({
  102. selector: "newValue:value:",
  103. category: 'evaluating',
  104. fn: function (anObject, anObject2) {
  105. var self = this;
  106. return new self(anObject, anObject2);
  107. return self;
  108. },
  109. args: ["anObject", "anObject2"],
  110. source: "newValue: anObject value: anObject2\x0a\x09\x22Use the receiver as a JS constructor. \x0a\x09*Do not* use this method to instanciate Smalltalk objects!\x22\x0a\x09<return new self(anObject, anObject2)>",
  111. messageSends: [],
  112. referencedClasses: []
  113. }),
  114. smalltalk.BlockClosure);
  115. smalltalk.addMethod(
  116. "_newValue_value_value_",
  117. smalltalk.method({
  118. selector: "newValue:value:value:",
  119. category: 'evaluating',
  120. fn: function (anObject, anObject2, anObject3) {
  121. var self = this;
  122. return new self(anObject, anObject2);
  123. return self;
  124. },
  125. args: ["anObject", "anObject2", "anObject3"],
  126. source: "newValue: anObject value: anObject2 value: anObject3\x0a\x09\x22Use the receiver as a JS constructor. \x0a\x09*Do not* use this method to instanciate Smalltalk objects!\x22\x0a\x09<return new self(anObject, anObject2)>",
  127. messageSends: [],
  128. referencedClasses: []
  129. }),
  130. smalltalk.BlockClosure);
  131. smalltalk.addMethod(
  132. "_numArgs",
  133. smalltalk.method({
  134. selector: "numArgs",
  135. category: 'accessing',
  136. fn: function () {
  137. var self = this;
  138. return self.length;
  139. return self;
  140. },
  141. args: [],
  142. source: "numArgs\x0a\x09<return self.length>",
  143. messageSends: [],
  144. referencedClasses: []
  145. }),
  146. smalltalk.BlockClosure);
  147. smalltalk.addMethod(
  148. "_on_do_",
  149. smalltalk.method({
  150. selector: "on:do:",
  151. category: 'error handling',
  152. fn: function (anErrorClass, aBlock) {
  153. var self = this;
  154. var $2, $1;
  155. $1 = smalltalk.send(self, "_try_catch_", [self, function (error) {$2 = smalltalk.send(error, "_isKindOf_", [anErrorClass]);if (smalltalk.assert($2)) {return smalltalk.send(aBlock, "_value_", [error]);} else {return smalltalk.send(error, "_signal", []);}}]);
  156. return $1;
  157. },
  158. args: ["anErrorClass", "aBlock"],
  159. source: "on: anErrorClass do: aBlock\x0a\x09^self try: self catch: [:error |\x0a\x09 (error isKindOf: anErrorClass) \x0a\x09 ifTrue: [aBlock value: error]\x0a\x09 ifFalse: [error signal]]",
  160. messageSends: ["try:catch:", "ifTrue:ifFalse:", "value:", "signal", "isKindOf:"],
  161. referencedClasses: []
  162. }),
  163. smalltalk.BlockClosure);
  164. smalltalk.addMethod(
  165. "_timeToRun",
  166. smalltalk.method({
  167. selector: "timeToRun",
  168. category: 'evaluating',
  169. fn: function () {
  170. var self = this;
  171. var $1;
  172. $1 = smalltalk.send(smalltalk.Date || Date, "_millisecondsToRun_", [self]);
  173. return $1;
  174. },
  175. args: [],
  176. source: "timeToRun\x0a\x09\x22Answer the number of milliseconds taken to execute this block.\x22\x0a\x0a\x09^ Date millisecondsToRun: self",
  177. messageSends: ["millisecondsToRun:"],
  178. referencedClasses: ["Date"]
  179. }),
  180. smalltalk.BlockClosure);
  181. smalltalk.addMethod(
  182. "_value",
  183. smalltalk.method({
  184. selector: "value",
  185. category: 'evaluating',
  186. fn: function () {
  187. var self = this;
  188. return self();
  189. return self;
  190. },
  191. args: [],
  192. source: "value\x0a\x09\x22inlined in the Compiler\x22\x0a\x09<return self();>",
  193. messageSends: [],
  194. referencedClasses: []
  195. }),
  196. smalltalk.BlockClosure);
  197. smalltalk.addMethod(
  198. "_value_",
  199. smalltalk.method({
  200. selector: "value:",
  201. category: 'evaluating',
  202. fn: function (anArg) {
  203. var self = this;
  204. return self(anArg);
  205. return self;
  206. },
  207. args: ["anArg"],
  208. source: "value: anArg\x0a\x09\x22inlined in the Compiler\x22\x0a\x09<return self(anArg);>",
  209. messageSends: [],
  210. referencedClasses: []
  211. }),
  212. smalltalk.BlockClosure);
  213. smalltalk.addMethod(
  214. "_value_value_",
  215. smalltalk.method({
  216. selector: "value:value:",
  217. category: 'evaluating',
  218. fn: function (firstArg, secondArg) {
  219. var self = this;
  220. return self(firstArg, secondArg);
  221. return self;
  222. },
  223. args: ["firstArg", "secondArg"],
  224. source: "value: firstArg value: secondArg\x0a\x09\x22inlined in the Compiler\x22\x0a\x09<return self(firstArg, secondArg);>",
  225. messageSends: [],
  226. referencedClasses: []
  227. }),
  228. smalltalk.BlockClosure);
  229. smalltalk.addMethod(
  230. "_value_value_value_",
  231. smalltalk.method({
  232. selector: "value:value:value:",
  233. category: 'evaluating',
  234. fn: function (firstArg, secondArg, thirdArg) {
  235. var self = this;
  236. return self(firstArg, secondArg, thirdArg);
  237. return self;
  238. },
  239. args: ["firstArg", "secondArg", "thirdArg"],
  240. source: "value: firstArg value: secondArg value: thirdArg\x0a\x09\x22inlined in the Compiler\x22\x0a\x09<return self(firstArg, secondArg, thirdArg);>",
  241. messageSends: [],
  242. referencedClasses: []
  243. }),
  244. smalltalk.BlockClosure);
  245. smalltalk.addMethod(
  246. "_valueWithInterval_",
  247. smalltalk.method({
  248. selector: "valueWithInterval:",
  249. category: 'timeout/interval',
  250. fn: function (aNumber){
  251. var self=this;
  252. var interval = setInterval(self, aNumber);
  253. return smalltalk.Timeout._on_(interval);
  254. ;
  255. ;
  256. return self},
  257. args: ["aNumber"],
  258. source: "valueWithInterval: aNumber\x0a\x09<\x0a \x09var interval = setInterval(self, aNumber);\x0a \x09return smalltalk.Timeout._on_(interval);\x0a >",
  259. messageSends: [],
  260. referencedClasses: []
  261. }),
  262. smalltalk.BlockClosure);
  263. smalltalk.addMethod(
  264. "_valueWithPossibleArguments_",
  265. smalltalk.method({
  266. selector: "valueWithPossibleArguments:",
  267. category: 'evaluating',
  268. fn: function (aCollection) {
  269. var self = this;
  270. return self.apply(null, aCollection);
  271. return self;
  272. },
  273. args: ["aCollection"],
  274. source: "valueWithPossibleArguments: aCollection\x0a\x09<return self.apply(null, aCollection);>",
  275. messageSends: [],
  276. referencedClasses: []
  277. }),
  278. smalltalk.BlockClosure);
  279. smalltalk.addMethod(
  280. "_valueWithTimeout_",
  281. smalltalk.method({
  282. selector: "valueWithTimeout:",
  283. category: 'timeout/interval',
  284. fn: function (aNumber){
  285. var self=this;
  286. var timeout = setTimeout(self, aNumber);
  287. return smalltalk.Timeout._on_(timeout);
  288. ;
  289. ;
  290. return self},
  291. args: ["aNumber"],
  292. source: "valueWithTimeout: aNumber\x0a\x09<\x0a \x09var timeout = setTimeout(self, aNumber);\x0a \x09return smalltalk.Timeout._on_(timeout);\x0a >",
  293. messageSends: [],
  294. referencedClasses: []
  295. }),
  296. smalltalk.BlockClosure);
  297. smalltalk.addMethod(
  298. "_whileFalse",
  299. smalltalk.method({
  300. selector: "whileFalse",
  301. category: 'controlling',
  302. fn: function () {
  303. var self = this;
  304. smalltalk.send(self, "_whileFalse_", [function () {}]);
  305. return self;
  306. },
  307. args: [],
  308. source: "whileFalse\x0a\x09\x22inlined in the Compiler\x22\x0a\x09self whileFalse: []",
  309. messageSends: ["whileFalse:"],
  310. referencedClasses: []
  311. }),
  312. smalltalk.BlockClosure);
  313. smalltalk.addMethod(
  314. "_whileFalse_",
  315. smalltalk.method({
  316. selector: "whileFalse:",
  317. category: 'controlling',
  318. fn: function (aBlock) {
  319. var self = this;
  320. while (!self()) {
  321. aBlock();
  322. }
  323. return self;
  324. },
  325. args: ["aBlock"],
  326. source: "whileFalse: aBlock\x0a\x09\x22inlined in the Compiler\x22\x0a\x09<while(!self()) {aBlock()}>",
  327. messageSends: [],
  328. referencedClasses: []
  329. }),
  330. smalltalk.BlockClosure);
  331. smalltalk.addMethod(
  332. "_whileTrue",
  333. smalltalk.method({
  334. selector: "whileTrue",
  335. category: 'controlling',
  336. fn: function () {
  337. var self = this;
  338. smalltalk.send(self, "_whileTrue_", [function () {}]);
  339. return self;
  340. },
  341. args: [],
  342. source: "whileTrue\x0a\x09\x22inlined in the Compiler\x22\x0a\x09self whileTrue: []",
  343. messageSends: ["whileTrue:"],
  344. referencedClasses: []
  345. }),
  346. smalltalk.BlockClosure);
  347. smalltalk.addMethod(
  348. "_whileTrue_",
  349. smalltalk.method({
  350. selector: "whileTrue:",
  351. category: 'controlling',
  352. fn: function (aBlock) {
  353. var self = this;
  354. while (self()) {
  355. aBlock();
  356. }
  357. return self;
  358. },
  359. args: ["aBlock"],
  360. source: "whileTrue: aBlock\x0a\x09\x22inlined in the Compiler\x22\x0a\x09<while(self()) {aBlock()}>",
  361. messageSends: [],
  362. referencedClasses: []
  363. }),
  364. smalltalk.BlockClosure);
  365. smalltalk.addClass('CompiledMethod', smalltalk.Object, [], 'Kernel-Methods');
  366. smalltalk.CompiledMethod.comment="CompiledMethod hold the source and compiled code of a class method.\x0a\x0aYou can get a CompiledMethod using `Behavior>>methodAt:`\x0a\x0a\x09String methodAt: 'lines'\x0a\x0aand read the source code\x0a\x0a\x09(String methodAt: 'lines') source\x0a\x0aSee referenced classes:\x0a\x0a\x09(String methodAt: 'lines') referencedClasses\x0a\x0aor messages sent from this method:\x0a\x09\x0a\x09(String methodAt: 'lines') messageSends"
  367. smalltalk.addMethod(
  368. "_arguments",
  369. smalltalk.method({
  370. selector: "arguments",
  371. category: 'accessing',
  372. fn: function () {
  373. var self = this;
  374. return self.args || [];
  375. return self;
  376. },
  377. args: [],
  378. source: "arguments\x0a\x09<return self.args || []>",
  379. messageSends: [],
  380. referencedClasses: []
  381. }),
  382. smalltalk.CompiledMethod);
  383. smalltalk.addMethod(
  384. "_category",
  385. smalltalk.method({
  386. selector: "category",
  387. category: 'accessing',
  388. fn: function () {
  389. var self = this;
  390. var $2, $1;
  391. $2 = smalltalk.send(self, "_basicAt_", ["category"]);
  392. if (($receiver = $2) == nil || $receiver == undefined) {
  393. $1 = "";
  394. } else {
  395. $1 = $2;
  396. }
  397. return $1;
  398. },
  399. args: [],
  400. source: "category\x0a\x09^(self basicAt: 'category') ifNil: ['']",
  401. messageSends: ["ifNil:", "basicAt:"],
  402. referencedClasses: []
  403. }),
  404. smalltalk.CompiledMethod);
  405. smalltalk.addMethod(
  406. "_category_",
  407. smalltalk.method({
  408. selector: "category:",
  409. category: 'accessing',
  410. fn: function (aString){
  411. var self=this;
  412. var $1;
  413. var oldCategory;
  414. oldCategory=smalltalk.send(self,"_category",[]);
  415. smalltalk.send(self,"_basicAt_put_",["category",aString]);
  416. $1=smalltalk.send(self,"_methodClass",[]);
  417. if(($receiver = $1) == nil || $receiver == undefined){
  418. $1;
  419. } else {
  420. smalltalk.send(smalltalk.send(smalltalk.send(self,"_methodClass",[]),"_organization",[]),"_addElement_",[aString]);
  421. smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(self,"_methodClass",[]),"_methods",[]),"_select_",[(function(each){
  422. return smalltalk.send(smalltalk.send(each,"_category",[]),"__eq",[oldCategory]);
  423. })]),"_ifEmpty_",[(function(){
  424. return smalltalk.send(smalltalk.send(smalltalk.send(self,"_methodClass",[]),"_organization",[]),"_removeElement_",[oldCategory]);
  425. })]);
  426. };
  427. return self},
  428. args: ["aString"],
  429. source: "category: aString\x0a\x09| oldCategory |\x0a oldCategory := self category.\x0a\x09self basicAt: 'category' put: aString.\x0a \x0a self methodClass ifNotNil: [\x0a \x09self methodClass organization addElement: aString.\x0a \x0a\x09\x09(self methodClass methods \x0a \x09\x09select: [ :each | each category = oldCategory ])\x0a \x09ifEmpty: [ self methodClass organization removeElement: oldCategory ] ]",
  430. messageSends: ["category", "basicAt:put:", "ifNotNil:", "addElement:", "organization", "methodClass", "ifEmpty:", "removeElement:", "select:", "=", "methods"],
  431. referencedClasses: []
  432. }),
  433. smalltalk.CompiledMethod);
  434. smalltalk.addMethod(
  435. "_fn",
  436. smalltalk.method({
  437. selector: "fn",
  438. category: 'accessing',
  439. fn: function () {
  440. var self = this;
  441. var $1;
  442. $1 = smalltalk.send(self, "_basicAt_", ["fn"]);
  443. return $1;
  444. },
  445. args: [],
  446. source: "fn\x0a\x09^self basicAt: 'fn'",
  447. messageSends: ["basicAt:"],
  448. referencedClasses: []
  449. }),
  450. smalltalk.CompiledMethod);
  451. smalltalk.addMethod(
  452. "_fn_",
  453. smalltalk.method({
  454. selector: "fn:",
  455. category: 'accessing',
  456. fn: function (aBlock) {
  457. var self = this;
  458. smalltalk.send(self, "_basicAt_put_", ["fn", aBlock]);
  459. return self;
  460. },
  461. args: ["aBlock"],
  462. source: "fn: aBlock\x0a\x09self basicAt: 'fn' put: aBlock",
  463. messageSends: ["basicAt:put:"],
  464. referencedClasses: []
  465. }),
  466. smalltalk.CompiledMethod);
  467. smalltalk.addMethod(
  468. "_messageSends",
  469. smalltalk.method({
  470. selector: "messageSends",
  471. category: 'accessing',
  472. fn: function () {
  473. var self = this;
  474. var $1;
  475. $1 = smalltalk.send(self, "_basicAt_", ["messageSends"]);
  476. return $1;
  477. },
  478. args: [],
  479. source: "messageSends\x0a\x09^self basicAt: 'messageSends'",
  480. messageSends: ["basicAt:"],
  481. referencedClasses: []
  482. }),
  483. smalltalk.CompiledMethod);
  484. smalltalk.addMethod(
  485. "_methodClass",
  486. smalltalk.method({
  487. selector: "methodClass",
  488. category: 'accessing',
  489. fn: function () {
  490. var self = this;
  491. var $1;
  492. $1 = smalltalk.send(self, "_basicAt_", ["methodClass"]);
  493. return $1;
  494. },
  495. args: [],
  496. source: "methodClass\x0a\x09^self basicAt: 'methodClass'",
  497. messageSends: ["basicAt:"],
  498. referencedClasses: []
  499. }),
  500. smalltalk.CompiledMethod);
  501. smalltalk.addMethod(
  502. "_protocol",
  503. smalltalk.method({
  504. selector: "protocol",
  505. category: 'accessing',
  506. fn: function () {
  507. var self = this;
  508. var $1;
  509. $1 = smalltalk.send(self, "_category", []);
  510. return $1;
  511. },
  512. args: [],
  513. source: "protocol\x0a\x09^ self category",
  514. messageSends: ["category"],
  515. referencedClasses: []
  516. }),
  517. smalltalk.CompiledMethod);
  518. smalltalk.addMethod(
  519. "_referencedClasses",
  520. smalltalk.method({
  521. selector: "referencedClasses",
  522. category: 'accessing',
  523. fn: function () {
  524. var self = this;
  525. var $1;
  526. $1 = smalltalk.send(self, "_basicAt_", ["referencedClasses"]);
  527. return $1;
  528. },
  529. args: [],
  530. source: "referencedClasses\x0a\x09^self basicAt: 'referencedClasses'",
  531. messageSends: ["basicAt:"],
  532. referencedClasses: []
  533. }),
  534. smalltalk.CompiledMethod);
  535. smalltalk.addMethod(
  536. "_selector",
  537. smalltalk.method({
  538. selector: "selector",
  539. category: 'accessing',
  540. fn: function () {
  541. var self = this;
  542. var $1;
  543. $1 = smalltalk.send(self, "_basicAt_", ["selector"]);
  544. return $1;
  545. },
  546. args: [],
  547. source: "selector\x0a\x09^self basicAt: 'selector'",
  548. messageSends: ["basicAt:"],
  549. referencedClasses: []
  550. }),
  551. smalltalk.CompiledMethod);
  552. smalltalk.addMethod(
  553. "_selector_",
  554. smalltalk.method({
  555. selector: "selector:",
  556. category: 'accessing',
  557. fn: function (aString) {
  558. var self = this;
  559. smalltalk.send(self, "_basicAt_put_", ["selector", aString]);
  560. return self;
  561. },
  562. args: ["aString"],
  563. source: "selector: aString\x0a\x09self basicAt: 'selector' put: aString",
  564. messageSends: ["basicAt:put:"],
  565. referencedClasses: []
  566. }),
  567. smalltalk.CompiledMethod);
  568. smalltalk.addMethod(
  569. "_source",
  570. smalltalk.method({
  571. selector: "source",
  572. category: 'accessing',
  573. fn: function () {
  574. var self = this;
  575. var $2, $1;
  576. $2 = smalltalk.send(self, "_basicAt_", ["source"]);
  577. if (($receiver = $2) == nil || $receiver == undefined) {
  578. $1 = "";
  579. } else {
  580. $1 = $2;
  581. }
  582. return $1;
  583. },
  584. args: [],
  585. source: "source\x0a\x09^(self basicAt: 'source') ifNil: ['']",
  586. messageSends: ["ifNil:", "basicAt:"],
  587. referencedClasses: []
  588. }),
  589. smalltalk.CompiledMethod);
  590. smalltalk.addMethod(
  591. "_source_",
  592. smalltalk.method({
  593. selector: "source:",
  594. category: 'accessing',
  595. fn: function (aString) {
  596. var self = this;
  597. smalltalk.send(self, "_basicAt_put_", ["source", aString]);
  598. return self;
  599. },
  600. args: ["aString"],
  601. source: "source: aString\x0a\x09self basicAt: 'source' put: aString",
  602. messageSends: ["basicAt:put:"],
  603. referencedClasses: []
  604. }),
  605. smalltalk.CompiledMethod);
  606. smalltalk.addClass('ForkPool', smalltalk.Object, ['poolSize', 'maxPoolSize', 'queue', 'worker'], 'Kernel-Methods');
  607. smalltalk.ForkPool.comment="A ForkPool is responsible for handling forked blocks.\x0aThe pool size sets the maximum concurrent forked blocks.\x0a\x0aThe default instance is accessed with `ForkPool default`"
  608. smalltalk.addMethod(
  609. "_addWorker",
  610. smalltalk.method({
  611. selector: "addWorker",
  612. category: 'action',
  613. fn: function (){
  614. var self=this;
  615. smalltalk.send(self["@worker"],"_valueWithTimeout_",[(0)]);
  616. self["@poolSize"]=smalltalk.send(self["@poolSize"],"__plus",[(1)]);
  617. return self},
  618. args: [],
  619. source: "addWorker\x0a\x09worker valueWithTimeout: 0.\x0a poolSize := poolSize + 1",
  620. messageSends: ["valueWithTimeout:", "+"],
  621. referencedClasses: []
  622. }),
  623. smalltalk.ForkPool);
  624. smalltalk.addMethod(
  625. "_defaultMaxPoolSize",
  626. smalltalk.method({
  627. selector: "defaultMaxPoolSize",
  628. category: 'defaults',
  629. fn: function (){
  630. var self=this;
  631. var $1;
  632. $1=smalltalk.send(smalltalk.send(self,"_class",[]),"_defaultMaxPoolSize",[]);
  633. return $1;
  634. },
  635. args: [],
  636. source: "defaultMaxPoolSize\x0a\x09^ self class defaultMaxPoolSize",
  637. messageSends: ["defaultMaxPoolSize", "class"],
  638. referencedClasses: []
  639. }),
  640. smalltalk.ForkPool);
  641. smalltalk.addMethod(
  642. "_fork_",
  643. smalltalk.method({
  644. selector: "fork:",
  645. category: 'action',
  646. fn: function (aBlock){
  647. var self=this;
  648. var $1;
  649. $1=smalltalk.send(self["@poolSize"],"__lt",[smalltalk.send(self,"_maxPoolSize",[])]);
  650. if(smalltalk.assert($1)){
  651. smalltalk.send(self,"_addWorker",[]);
  652. };
  653. smalltalk.send(self["@queue"],"_back_",[aBlock]);
  654. return self},
  655. args: ["aBlock"],
  656. source: "fork: aBlock\x0a\x09poolSize < self maxPoolSize ifTrue: [ self addWorker ].\x0a\x09queue back: aBlock",
  657. messageSends: ["ifTrue:", "addWorker", "<", "maxPoolSize", "back:"],
  658. referencedClasses: []
  659. }),
  660. smalltalk.ForkPool);
  661. smalltalk.addMethod(
  662. "_initialize",
  663. smalltalk.method({
  664. selector: "initialize",
  665. category: 'initialization',
  666. fn: function (){
  667. var self=this;
  668. smalltalk.send(self,"_initialize",[],smalltalk.Object);
  669. self["@poolSize"]=(0);
  670. self["@queue"]=smalltalk.send((smalltalk.Queue || Queue),"_new",[]);
  671. self["@worker"]=smalltalk.send(self,"_makeWorker",[]);
  672. return self},
  673. args: [],
  674. source: "initialize\x0a super initialize.\x0a \x0a\x09poolSize := 0.\x0a queue := Queue new.\x0a worker := self makeWorker",
  675. messageSends: ["initialize", "new", "makeWorker"],
  676. referencedClasses: ["Queue"]
  677. }),
  678. smalltalk.ForkPool);
  679. smalltalk.addMethod(
  680. "_makeWorker",
  681. smalltalk.method({
  682. selector: "makeWorker",
  683. category: 'initialization',
  684. fn: function (){
  685. var self=this;
  686. var $2,$1;
  687. var sentinel;
  688. sentinel=smalltalk.send((smalltalk.Object || Object),"_new",[]);
  689. $1=(function(){
  690. var block;
  691. self["@poolSize"]=smalltalk.send(self["@poolSize"],"__minus",[(1)]);
  692. self["@poolSize"];
  693. block=smalltalk.send(self["@queue"],"_frontIfAbsent_",[(function(){
  694. return sentinel;
  695. })]);
  696. block;
  697. $2=smalltalk.send(block,"__eq_eq",[sentinel]);
  698. if(! smalltalk.assert($2)){
  699. return smalltalk.send((function(){
  700. return smalltalk.send(block,"_value",[]);
  701. }),"_ensure_",[(function(){
  702. return smalltalk.send(self,"_addWorker",[]);
  703. })]);
  704. };
  705. });
  706. return $1;
  707. },
  708. args: [],
  709. source: "makeWorker\x0a\x09| sentinel |\x0a sentinel := Object new.\x0a ^[ | block |\x0a poolSize := poolSize - 1.\x0a\x09\x09block := queue frontIfAbsent: [ sentinel ].\x0a block == sentinel ifFalse: [\x0a \x09[ block value ] ensure: [ self addWorker ]]]",
  710. messageSends: ["new", "-", "frontIfAbsent:", "ifFalse:", "ensure:", "addWorker", "value", "=="],
  711. referencedClasses: ["Object"]
  712. }),
  713. smalltalk.ForkPool);
  714. smalltalk.addMethod(
  715. "_maxPoolSize",
  716. smalltalk.method({
  717. selector: "maxPoolSize",
  718. category: 'accessing',
  719. fn: function (){
  720. var self=this;
  721. var $2,$1;
  722. $2=self["@maxPoolSize"];
  723. if(($receiver = $2) == nil || $receiver == undefined){
  724. $1=smalltalk.send(self,"_defaultMaxPoolSize",[]);
  725. } else {
  726. $1=$2;
  727. };
  728. return $1;
  729. },
  730. args: [],
  731. source: "maxPoolSize\x0a\x09^ maxPoolSize ifNil: [ self defaultMaxPoolSize ]",
  732. messageSends: ["ifNil:", "defaultMaxPoolSize"],
  733. referencedClasses: []
  734. }),
  735. smalltalk.ForkPool);
  736. smalltalk.addMethod(
  737. "_maxPoolSize_",
  738. smalltalk.method({
  739. selector: "maxPoolSize:",
  740. category: 'accessing',
  741. fn: function (anInteger){
  742. var self=this;
  743. self["@maxPoolSize"]=anInteger;
  744. return self},
  745. args: ["anInteger"],
  746. source: "maxPoolSize: anInteger\x0a\x09maxPoolSize := anInteger",
  747. messageSends: [],
  748. referencedClasses: []
  749. }),
  750. smalltalk.ForkPool);
  751. smalltalk.ForkPool.klass.iVarNames = ['default'];
  752. smalltalk.addMethod(
  753. "_default",
  754. smalltalk.method({
  755. selector: "default",
  756. category: 'accessing',
  757. fn: function (){
  758. var self=this;
  759. var $1;
  760. if(($receiver = self["@default"]) == nil || $receiver == undefined){
  761. self["@default"]=smalltalk.send(self,"_new",[]);
  762. $1=self["@default"];
  763. } else {
  764. $1=self["@default"];
  765. };
  766. return $1;
  767. },
  768. args: [],
  769. source: "default\x0a\x09^default ifNil: [ default := self new ]",
  770. messageSends: ["ifNil:", "new"],
  771. referencedClasses: []
  772. }),
  773. smalltalk.ForkPool.klass);
  774. smalltalk.addMethod(
  775. "_defaultMaxPoolSize",
  776. smalltalk.method({
  777. selector: "defaultMaxPoolSize",
  778. category: 'accessing',
  779. fn: function (){
  780. var self=this;
  781. return (100);
  782. },
  783. args: [],
  784. source: "defaultMaxPoolSize\x0a\x09^100",
  785. messageSends: [],
  786. referencedClasses: []
  787. }),
  788. smalltalk.ForkPool.klass);
  789. smalltalk.addMethod(
  790. "_resetDefault",
  791. smalltalk.method({
  792. selector: "resetDefault",
  793. category: 'accessing',
  794. fn: function (){
  795. var self=this;
  796. self["@default"]=nil;
  797. return self},
  798. args: [],
  799. source: "resetDefault\x0a\x09default := nil",
  800. messageSends: [],
  801. referencedClasses: []
  802. }),
  803. smalltalk.ForkPool.klass);
  804. smalltalk.addClass('Message', smalltalk.Object, ['selector', 'arguments'], 'Kernel-Methods');
  805. smalltalk.Message.comment="Generally, the system does not use instances of Message for efficiency reasons.\x0aHowever, when a message is not understood by its receiver, the interpreter will make up an instance of it in order to capture the information involved in an actual message transmission. \x0aThis instance is sent it as an argument with the message `doesNotUnderstand:` to the receiver.\x0a\x0aSee boot.js, `messageNotUnderstood` and its counterpart `Object>>doesNotUnderstand:`"
  806. smalltalk.addMethod(
  807. "_arguments",
  808. smalltalk.method({
  809. selector: "arguments",
  810. category: 'accessing',
  811. fn: function () {
  812. var self = this;
  813. return self['@arguments'];
  814. },
  815. args: [],
  816. source: "arguments\x0a\x09^arguments",
  817. messageSends: [],
  818. referencedClasses: []
  819. }),
  820. smalltalk.Message);
  821. smalltalk.addMethod(
  822. "_arguments_",
  823. smalltalk.method({
  824. selector: "arguments:",
  825. category: 'accessing',
  826. fn: function (anArray) {
  827. var self = this;
  828. self['@arguments'] = anArray;
  829. return self;
  830. },
  831. args: ["anArray"],
  832. source: "arguments: anArray\x0a\x09arguments := anArray",
  833. messageSends: [],
  834. referencedClasses: []
  835. }),
  836. smalltalk.Message);
  837. smalltalk.addMethod(
  838. "_printString",
  839. smalltalk.method({
  840. selector: "printString",
  841. category: 'printing',
  842. fn: function () {
  843. var self = this;
  844. var $2, $1;
  845. $1 = smalltalk.send(smalltalk.String || String, "_streamContents_", [function (aStream) {smalltalk.send(aStream, "_nextPutAll_", [smalltalk.send(self, "_printString", [], smalltalk.Object)]);smalltalk.send(aStream, "_nextPutAll_", ["("]);smalltalk.send(aStream, "_nextPutAll_", [self['@selector']]);$2 = smalltalk.send(aStream, "_nextPutAll_", [")"]);return $2;}]);
  846. return $1;
  847. },
  848. args: [],
  849. source: "printString\x0a\x09^ String streamContents: [:aStream| \x0a \x09\x09\x09\x09aStream \x0a \x09\x09\x09\x09\x09nextPutAll: super printString;\x0a \x09\x09\x09\x09\x09nextPutAll: '(';\x0a \x09\x09\x09\x09\x09nextPutAll: selector;\x0a \x09\x09\x09\x09\x09nextPutAll: ')' \x09\x09\x09\x09]",
  850. messageSends: ["streamContents:", "nextPutAll:", "printString"],
  851. referencedClasses: ["String"]
  852. }),
  853. smalltalk.Message);
  854. smalltalk.addMethod(
  855. "_selector",
  856. smalltalk.method({
  857. selector: "selector",
  858. category: 'accessing',
  859. fn: function () {
  860. var self = this;
  861. return self['@selector'];
  862. },
  863. args: [],
  864. source: "selector\x0a\x09^selector",
  865. messageSends: [],
  866. referencedClasses: []
  867. }),
  868. smalltalk.Message);
  869. smalltalk.addMethod(
  870. "_selector_",
  871. smalltalk.method({
  872. selector: "selector:",
  873. category: 'accessing',
  874. fn: function (aString) {
  875. var self = this;
  876. self['@selector'] = aString;
  877. return self;
  878. },
  879. args: ["aString"],
  880. source: "selector: aString\x0a\x09selector := aString",
  881. messageSends: [],
  882. referencedClasses: []
  883. }),
  884. smalltalk.Message);
  885. smalltalk.addMethod(
  886. "_sendTo_",
  887. smalltalk.method({
  888. selector: "sendTo:",
  889. category: 'printing',
  890. fn: function (anObject) {
  891. var self = this;
  892. var $1;
  893. $1 = smalltalk.send(smalltalk.send(smalltalk.Smalltalk || Smalltalk, "_current", []), "_send_to_arguments_", [smalltalk.send(self, "_selector", []), anObject, smalltalk.send(self, "_arguments", [])]);
  894. return $1;
  895. },
  896. args: ["anObject"],
  897. source: "sendTo: anObject\x0a\x09^ Smalltalk current send: self selector to: anObject arguments: self arguments",
  898. messageSends: ["send:to:arguments:", "selector", "arguments", "current"],
  899. referencedClasses: ["Smalltalk"]
  900. }),
  901. smalltalk.Message);
  902. smalltalk.addMethod(
  903. "_selector_arguments_",
  904. smalltalk.method({
  905. selector: "selector:arguments:",
  906. category: 'instance creation',
  907. fn: function (aString, anArray) {
  908. var self = this;
  909. var $2, $3, $1;
  910. $2 = smalltalk.send(self, "_new", []);
  911. smalltalk.send($2, "_selector_", [aString]);
  912. smalltalk.send($2, "_arguments_", [anArray]);
  913. $3 = smalltalk.send($2, "_yourself", []);
  914. $1 = $3;
  915. return $1;
  916. },
  917. args: ["aString", "anArray"],
  918. source: "selector: aString arguments: anArray\x0a\x09^self new\x0a\x09\x09selector: aString;\x0a\x09\x09arguments: anArray;\x0a\x09\x09yourself",
  919. messageSends: ["selector:", "new", "arguments:", "yourself"],
  920. referencedClasses: []
  921. }),
  922. smalltalk.Message.klass);
  923. smalltalk.addClass('MethodContext', smalltalk.Object, [], 'Kernel-Methods');
  924. smalltalk.MethodContext.comment="MethodContext holds all the dynamic state associated with the execution of either a method activation resulting from a message send. That is used to build the call stack while debugging.\x0a \x0aMethodContext instances are JavaScript `SmalltalkMethodContext` objects defined in boot.js \x0a\x0aCurrent limitation: MethodContext instances are not created on Block evaluation. That means it's actually impossible to debug inside a Block."
  925. smalltalk.addMethod(
  926. "_asString",
  927. smalltalk.method({
  928. selector: "asString",
  929. category: 'accessing',
  930. fn: function () {
  931. var self = this;
  932. var $1;
  933. $1 = smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(self, "_receiver", []), "_class", []), "_printString", []), "__comma", [" >> "]), "__comma", [smalltalk.send(self, "_selector", [])]);
  934. return $1;
  935. },
  936. args: [],
  937. source: "asString\x0a\x09^self receiver class printString, ' >> ', self selector",
  938. messageSends: [",", "selector", "printString", "class", "receiver"],
  939. referencedClasses: []
  940. }),
  941. smalltalk.MethodContext);
  942. smalltalk.addMethod(
  943. "_home",
  944. smalltalk.method({
  945. selector: "home",
  946. category: 'accessing',
  947. fn: function () {
  948. var self = this;
  949. return self.homeContext;
  950. return self;
  951. },
  952. args: [],
  953. source: "home\x0a\x09<return self.homeContext>",
  954. messageSends: [],
  955. referencedClasses: []
  956. }),
  957. smalltalk.MethodContext);
  958. smalltalk.addMethod(
  959. "_pc",
  960. smalltalk.method({
  961. selector: "pc",
  962. category: 'accessing',
  963. fn: function () {
  964. var self = this;
  965. return self.pc;
  966. return self;
  967. },
  968. args: [],
  969. source: "pc\x0a\x09<return self.pc>",
  970. messageSends: [],
  971. referencedClasses: []
  972. }),
  973. smalltalk.MethodContext);
  974. smalltalk.addMethod(
  975. "_printString",
  976. smalltalk.method({
  977. selector: "printString",
  978. category: 'accessing',
  979. fn: function () {
  980. var self = this;
  981. var $1;
  982. $1 = smalltalk.send(smalltalk.send(smalltalk.send(smalltalk.send(self, "_printString", [], smalltalk.Object), "__comma", ["("]), "__comma", [smalltalk.send(self, "_asString", [])]), "__comma", [")"]);
  983. return $1;
  984. },
  985. args: [],
  986. source: "printString\x0a\x09^super printString, '(', self asString, ')'",
  987. messageSends: [",", "asString", "printString"],
  988. referencedClasses: []
  989. }),
  990. smalltalk.MethodContext);
  991. smalltalk.addMethod(
  992. "_receiver",
  993. smalltalk.method({
  994. selector: "receiver",
  995. category: 'accessing',
  996. fn: function () {
  997. var self = this;
  998. return self.receiver;
  999. return self;
  1000. },
  1001. args: [],
  1002. source: "receiver\x0a\x09<return self.receiver>",
  1003. messageSends: [],
  1004. referencedClasses: []
  1005. }),
  1006. smalltalk.MethodContext);
  1007. smalltalk.addMethod(
  1008. "_selector",
  1009. smalltalk.method({
  1010. selector: "selector",
  1011. category: 'accessing',
  1012. fn: function () {
  1013. var self = this;
  1014. return smalltalk.convertSelector(self.selector);
  1015. return self;
  1016. },
  1017. args: [],
  1018. source: "selector\x0a\x09<return smalltalk.convertSelector(self.selector)>",
  1019. messageSends: [],
  1020. referencedClasses: []
  1021. }),
  1022. smalltalk.MethodContext);
  1023. smalltalk.addMethod(
  1024. "_temps",
  1025. smalltalk.method({
  1026. selector: "temps",
  1027. category: 'accessing',
  1028. fn: function () {
  1029. var self = this;
  1030. return self.temps;
  1031. return self;
  1032. },
  1033. args: [],
  1034. source: "temps\x0a\x09<return self.temps>",
  1035. messageSends: [],
  1036. referencedClasses: []
  1037. }),
  1038. smalltalk.MethodContext);