Importer-Exporter.js 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. (function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Importer-Exporter');
  3. smalltalk.addClass('ChunkExporter', smalltalk.Object, [], 'Importer-Exporter');
  4. smalltalk.ChunkExporter.comment="I am an exporter dedicated to outputting Amber source code in the classic Smalltalk chunk format.\x0a\x0aI do not output any compiled code.";
  5. smalltalk.addMethod(
  6. smalltalk.method({
  7. selector: "chunkEscape:",
  8. category: 'private',
  9. fn: function (aString){
  10. var self=this;
  11. return smalltalk.withContext(function($ctx1) {
  12. var $1;
  13. $1=_st(_st(aString)._replace_with_("!","!!"))._trimBoth();
  14. return $1;
  15. }, function($ctx1) {$ctx1.fill(self,"chunkEscape:",{aString:aString},smalltalk.ChunkExporter.klass)})},
  16. args: ["aString"],
  17. source: "chunkEscape: aString\x0a\x09\x22Replace all occurrences of ! with !! and trim at both ends.\x22\x0a\x0a\x09^(aString replace: '!' with: '!!') trimBoth",
  18. messageSends: ["trimBoth", "replace:with:"],
  19. referencedClasses: []
  20. }),
  21. smalltalk.ChunkExporter.klass);
  22. smalltalk.addMethod(
  23. smalltalk.method({
  24. selector: "classNameFor:",
  25. category: 'private',
  26. fn: function (aClass){
  27. var self=this;
  28. return smalltalk.withContext(function($ctx1) {
  29. var $2,$3,$1;
  30. $2=_st(aClass)._isMetaclass();
  31. if(smalltalk.assert($2)){
  32. $1=_st(_st(_st(aClass)._instanceClass())._name()).__comma(" class");
  33. } else {
  34. $3=_st(aClass)._isNil();
  35. if(smalltalk.assert($3)){
  36. $1="nil";
  37. } else {
  38. $1=_st(aClass)._name();
  39. };
  40. };
  41. return $1;
  42. }, function($ctx1) {$ctx1.fill(self,"classNameFor:",{aClass:aClass},smalltalk.ChunkExporter.klass)})},
  43. args: ["aClass"],
  44. source: "classNameFor: aClass\x0a\x09^aClass isMetaclass\x0a\x09\x09ifTrue: [aClass instanceClass name, ' class']\x0a\x09\x09ifFalse: [\x0a\x09\x09aClass isNil\x0a\x09\x09\x09ifTrue: ['nil']\x0a\x09\x09\x09ifFalse: [aClass name]]",
  45. messageSends: ["ifTrue:ifFalse:", ",", "name", "instanceClass", "isNil", "isMetaclass"],
  46. referencedClasses: []
  47. }),
  48. smalltalk.ChunkExporter.klass);
  49. smalltalk.addMethod(
  50. smalltalk.method({
  51. selector: "exportCategoryEpilogueOf:on:",
  52. category: 'exporting-output',
  53. fn: function (category,aStream){
  54. var self=this;
  55. return smalltalk.withContext(function($ctx1) {
  56. var $1,$2;
  57. $1=aStream;
  58. _st($1)._nextPutAll_(" !");
  59. _st($1)._lf();
  60. $2=_st($1)._lf();
  61. return self}, function($ctx1) {$ctx1.fill(self,"exportCategoryEpilogueOf:on:",{category:category,aStream:aStream},smalltalk.ChunkExporter.klass)})},
  62. args: ["category", "aStream"],
  63. source: "exportCategoryEpilogueOf: category on: aStream\x0a\x09aStream nextPutAll: ' !'; lf; lf",
  64. messageSends: ["nextPutAll:", "lf"],
  65. referencedClasses: []
  66. }),
  67. smalltalk.ChunkExporter.klass);
  68. smalltalk.addMethod(
  69. smalltalk.method({
  70. selector: "exportCategoryPrologueOf:on:",
  71. category: 'exporting-output',
  72. fn: function (category,aStream){
  73. var self=this;
  74. return smalltalk.withContext(function($ctx1) {
  75. var $1,$2;
  76. $1=aStream;
  77. _st($1)._nextPutAll_("!".__comma(self._classNameFor_(_st(category)._at_("class"))));
  78. $2=_st($1)._nextPutAll_(_st(" methodsFor: '".__comma(_st(category)._at_("name"))).__comma("'!"));
  79. return self}, function($ctx1) {$ctx1.fill(self,"exportCategoryPrologueOf:on:",{category:category,aStream:aStream},smalltalk.ChunkExporter.klass)})},
  80. args: ["category", "aStream"],
  81. source: "exportCategoryPrologueOf: category on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '!', (self classNameFor: (category at: #class));\x0a\x09\x09nextPutAll: ' methodsFor: ''', (category at: #name), '''!'",
  82. messageSends: ["nextPutAll:", ",", "classNameFor:", "at:"],
  83. referencedClasses: []
  84. }),
  85. smalltalk.ChunkExporter.klass);
  86. smalltalk.addMethod(
  87. smalltalk.method({
  88. selector: "exportDefinitionOf:on:",
  89. category: 'exporting-output',
  90. fn: function (aClass,aStream){
  91. var self=this;
  92. return smalltalk.withContext(function($ctx1) {
  93. var $1,$2,$3,$4,$5,$6,$7;
  94. $1=aStream;
  95. _st($1)._nextPutAll_(self._classNameFor_(_st(aClass)._superclass()));
  96. _st($1)._nextPutAll_(" subclass: #".__comma(self._classNameFor_(aClass)));
  97. _st($1)._lf();
  98. _st($1)._tab();
  99. $2=_st($1)._nextPutAll_("instanceVariableNames: '");
  100. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  101. return smalltalk.withContext(function($ctx2) {
  102. return _st(aStream)._nextPutAll_(each);
  103. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  104. return smalltalk.withContext(function($ctx2) {
  105. return _st(aStream)._nextPutAll_(" ");
  106. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  107. $3=aStream;
  108. _st($3)._nextPutAll_("'");
  109. _st($3)._lf();
  110. _st($3)._tab();
  111. _st($3)._nextPutAll_(_st("package: '".__comma(_st(aClass)._category())).__comma("'!"));
  112. $4=_st($3)._lf();
  113. $5=_st(_st(aClass)._comment())._notEmpty();
  114. if(smalltalk.assert($5)){
  115. $6=aStream;
  116. _st($6)._nextPutAll_(_st("!".__comma(self._classNameFor_(aClass))).__comma(" commentStamp!"));
  117. _st($6)._lf();
  118. _st($6)._nextPutAll_(_st(self._chunkEscape_(_st(aClass)._comment())).__comma("!"));
  119. $7=_st($6)._lf();
  120. $7;
  121. };
  122. _st(aStream)._lf();
  123. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.ChunkExporter.klass)})},
  124. args: ["aClass", "aStream"],
  125. source: "exportDefinitionOf: aClass on: aStream\x0a\x09\x22Chunk format.\x22\x0a\x0a\x09aStream\x0a\x09\x09nextPutAll: (self classNameFor: aClass superclass);\x0a\x09\x09nextPutAll: ' subclass: #', (self classNameFor: aClass); lf;\x0a\x09\x09tab; nextPutAll: 'instanceVariableNames: '''.\x0a\x09aClass instanceVariableNames\x0a\x09\x09do: [:each | aStream nextPutAll: each]\x0a\x09\x09separatedBy: [aStream nextPutAll: ' '].\x0a\x09aStream\x0a\x09\x09nextPutAll: ''''; lf;\x0a\x09\x09tab; nextPutAll: 'package: ''', aClass category, '''!'; lf.\x0a\x09aClass comment notEmpty ifTrue: [\x0a\x09\x09aStream\x0a\x09\x09nextPutAll: '!', (self classNameFor: aClass), ' commentStamp!';lf;\x0a\x09\x09nextPutAll: (self chunkEscape: aClass comment), '!';lf].\x0a\x09aStream lf",
  126. messageSends: ["nextPutAll:", "classNameFor:", "superclass", ",", "lf", "tab", "do:separatedBy:", "instanceVariableNames", "category", "ifTrue:", "chunkEscape:", "comment", "notEmpty"],
  127. referencedClasses: []
  128. }),
  129. smalltalk.ChunkExporter.klass);
  130. smalltalk.addMethod(
  131. smalltalk.method({
  132. selector: "exportMetaDefinitionOf:on:",
  133. category: 'exporting-output',
  134. fn: function (aClass,aStream){
  135. var self=this;
  136. return smalltalk.withContext(function($ctx1) {
  137. var $1,$2,$3,$4,$5;
  138. $1=_st(_st(_st(aClass)._class())._instanceVariableNames())._isEmpty();
  139. if(! smalltalk.assert($1)){
  140. $2=aStream;
  141. _st($2)._nextPutAll_(self._classNameFor_(_st(aClass)._class()));
  142. $3=_st($2)._nextPutAll_(" instanceVariableNames: '");
  143. $3;
  144. _st(_st(_st(aClass)._class())._instanceVariableNames())._do_separatedBy_((function(each){
  145. return smalltalk.withContext(function($ctx2) {
  146. return _st(aStream)._nextPutAll_(each);
  147. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  148. return smalltalk.withContext(function($ctx2) {
  149. return _st(aStream)._nextPutAll_(" ");
  150. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  151. $4=aStream;
  152. _st($4)._nextPutAll_("'!");
  153. _st($4)._lf();
  154. $5=_st($4)._lf();
  155. $5;
  156. };
  157. return self}, function($ctx1) {$ctx1.fill(self,"exportMetaDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.ChunkExporter.klass)})},
  158. args: ["aClass", "aStream"],
  159. source: "exportMetaDefinitionOf: aClass on: aStream\x0a\x0a\x09aClass class instanceVariableNames isEmpty ifFalse: [\x0a\x09\x09aStream\x0a\x09\x09\x09nextPutAll: (self classNameFor: aClass class);\x0a\x09\x09\x09nextPutAll: ' instanceVariableNames: '''.\x0a\x09\x09aClass class instanceVariableNames\x0a\x09\x09\x09do: [:each | aStream nextPutAll: each]\x0a\x09\x09\x09separatedBy: [aStream nextPutAll: ' '].\x0a\x09\x09aStream\x0a\x09\x09\x09nextPutAll: '''!'; lf; lf]",
  160. messageSends: ["ifFalse:", "nextPutAll:", "classNameFor:", "class", "do:separatedBy:", "instanceVariableNames", "lf", "isEmpty"],
  161. referencedClasses: []
  162. }),
  163. smalltalk.ChunkExporter.klass);
  164. smalltalk.addMethod(
  165. smalltalk.method({
  166. selector: "exportMethod:on:",
  167. category: 'exporting-output',
  168. fn: function (aMethod,aStream){
  169. var self=this;
  170. return smalltalk.withContext(function($ctx1) {
  171. var $1,$2;
  172. $1=aStream;
  173. _st($1)._lf();
  174. _st($1)._lf();
  175. _st($1)._nextPutAll_(self._chunkEscape_(_st(aMethod)._source()));
  176. _st($1)._lf();
  177. $2=_st($1)._nextPutAll_("!");
  178. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:on:",{aMethod:aMethod,aStream:aStream},smalltalk.ChunkExporter.klass)})},
  179. args: ["aMethod", "aStream"],
  180. source: "exportMethod: aMethod on: aStream\x0a\x09aStream\x0a\x09\x09lf; lf; nextPutAll: (self chunkEscape: aMethod source); lf;\x0a\x09\x09nextPutAll: '!'",
  181. messageSends: ["lf", "nextPutAll:", "chunkEscape:", "source"],
  182. referencedClasses: []
  183. }),
  184. smalltalk.ChunkExporter.klass);
  185. smalltalk.addMethod(
  186. smalltalk.method({
  187. selector: "exportPackageDefinitionOf:on:",
  188. category: 'exporting-output',
  189. fn: function (package_,aStream){
  190. var self=this;
  191. return smalltalk.withContext(function($ctx1) {
  192. var $1,$2;
  193. $1=aStream;
  194. _st($1)._nextPutAll_(_st("Smalltalk current createPackage: '".__comma(_st(package_)._name())).__comma("'!"));
  195. $2=_st($1)._lf();
  196. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageDefinitionOf:on:",{package_:package_,aStream:aStream},smalltalk.ChunkExporter.klass)})},
  197. args: ["package", "aStream"],
  198. source: "exportPackageDefinitionOf: package on: aStream\x0a\x09\x22Chunk format.\x22\x0a\x0a\x09aStream\x0a\x09\x09nextPutAll: 'Smalltalk current createPackage: ''', package name, '''!';\x0a\x09\x09lf",
  199. messageSends: ["nextPutAll:", ",", "name", "lf"],
  200. referencedClasses: []
  201. }),
  202. smalltalk.ChunkExporter.klass);
  203. smalltalk.addMethod(
  204. smalltalk.method({
  205. selector: "extensionCategoriesOfPackage:",
  206. category: 'exporting-accessing',
  207. fn: function (package_){
  208. var self=this;
  209. var name,map,result;
  210. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  211. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  212. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  213. function $Package(){return smalltalk.Package||(typeof Package=="undefined"?nil:Package)}
  214. return smalltalk.withContext(function($ctx1) {
  215. var $1,$2;
  216. name=_st(package_)._name();
  217. result=_st($OrderedCollection())._new();
  218. _st(_st($Package())._sortedClasses_(_st(_st($Smalltalk())._current())._classes()))._do_((function(each){
  219. return smalltalk.withContext(function($ctx2) {
  220. return _st([each,_st(each)._class()])._do_((function(aClass){
  221. return smalltalk.withContext(function($ctx3) {
  222. map=_st($Dictionary())._new();
  223. map;
  224. _st(aClass)._protocolsDo_((function(category,methods){
  225. return smalltalk.withContext(function($ctx4) {
  226. $1=_st(category)._match_("^\x5c*".__comma(name));
  227. if(smalltalk.assert($1)){
  228. return _st(map)._at_put_(category,methods);
  229. };
  230. }, function($ctx4) {$ctx4.fillBlock({category:category,methods:methods},$ctx3)})}));
  231. return _st(result)._addAll_(_st(_st(_st(map)._keys())._sorted_((function(a,b){
  232. return smalltalk.withContext(function($ctx4) {
  233. return _st(a).__lt_eq(b);
  234. }, function($ctx4) {$ctx4.fillBlock({a:a,b:b},$ctx3)})})))._collect_((function(category){
  235. return smalltalk.withContext(function($ctx4) {
  236. return smalltalk.HashedCollection._from_(["methods".__minus_gt(_st(map)._at_(category)),"name".__minus_gt(category),"class".__minus_gt(aClass)]);
  237. }, function($ctx4) {$ctx4.fillBlock({category:category},$ctx3)})})));
  238. }, function($ctx3) {$ctx3.fillBlock({aClass:aClass},$ctx2)})}));
  239. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  240. $2=result;
  241. return $2;
  242. }, function($ctx1) {$ctx1.fill(self,"extensionCategoriesOfPackage:",{package_:package_,name:name,map:map,result:result},smalltalk.ChunkExporter.klass)})},
  243. args: ["package"],
  244. source: "extensionCategoriesOfPackage: package\x0a\x09\x22Issue #143: sort protocol alphabetically\x22\x0a\x0a\x09| name map result |\x0a\x09name := package name.\x0a\x09result := OrderedCollection new.\x0a\x09(Package sortedClasses: Smalltalk current classes) do: [:each |\x0a\x09\x09{each. each class} do: [:aClass |\x0a\x09\x09\x09map := Dictionary new.\x0a\x09\x09\x09aClass protocolsDo: [:category :methods |\x0a\x09\x09\x09\x09(category match: '^\x5c*', name) ifTrue: [ map at: category put: methods ]].\x0a\x09\x09\x09result addAll: ((map keys sorted: [:a :b | a <= b ]) collect: [:category |\x0a\x09\x09\x09\x09#{ 'methods'->(map at: category). 'name'->category. 'class'->aClass}]) ]].\x0a\x09^result",
  245. messageSends: ["name", "new", "do:", "protocolsDo:", "ifTrue:", "at:put:", "match:", ",", "addAll:", "collect:", "->", "at:", "sorted:", "<=", "keys", "class", "sortedClasses:", "classes", "current"],
  246. referencedClasses: ["OrderedCollection", "Dictionary", "Smalltalk", "Package"]
  247. }),
  248. smalltalk.ChunkExporter.klass);
  249. smalltalk.addMethod(
  250. smalltalk.method({
  251. selector: "methodsOfCategory:",
  252. category: 'exporting-accessing',
  253. fn: function (category){
  254. var self=this;
  255. return smalltalk.withContext(function($ctx1) {
  256. var $1;
  257. $1=_st(_st(category)._at_("methods"))._sorted_((function(a,b){
  258. return smalltalk.withContext(function($ctx2) {
  259. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  260. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})}));
  261. return $1;
  262. }, function($ctx1) {$ctx1.fill(self,"methodsOfCategory:",{category:category},smalltalk.ChunkExporter.klass)})},
  263. args: ["category"],
  264. source: "methodsOfCategory: category\x0a\x09\x22Issue #143: sort methods alphabetically\x22\x0a\x0a\x09^(category at: #methods) sorted: [:a :b | a selector <= b selector]",
  265. messageSends: ["sorted:", "<=", "selector", "at:"],
  266. referencedClasses: []
  267. }),
  268. smalltalk.ChunkExporter.klass);
  269. smalltalk.addMethod(
  270. smalltalk.method({
  271. selector: "ownCategoriesOfClass:",
  272. category: 'exporting-accessing',
  273. fn: function (aClass){
  274. var self=this;
  275. var map;
  276. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  277. return smalltalk.withContext(function($ctx1) {
  278. var $1,$2;
  279. map=_st($Dictionary())._new();
  280. _st(aClass)._protocolsDo_((function(category,methods){
  281. return smalltalk.withContext(function($ctx2) {
  282. $1=_st(category)._match_("^\x5c*");
  283. if(! smalltalk.assert($1)){
  284. return _st(map)._at_put_(category,methods);
  285. };
  286. }, function($ctx2) {$ctx2.fillBlock({category:category,methods:methods},$ctx1)})}));
  287. $2=_st(_st(_st(map)._keys())._sorted_((function(a,b){
  288. return smalltalk.withContext(function($ctx2) {
  289. return _st(a).__lt_eq(b);
  290. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})})))._collect_((function(category){
  291. return smalltalk.withContext(function($ctx2) {
  292. return smalltalk.HashedCollection._from_(["methods".__minus_gt(_st(map)._at_(category)),"name".__minus_gt(category),"class".__minus_gt(aClass)]);
  293. }, function($ctx2) {$ctx2.fillBlock({category:category},$ctx1)})}));
  294. return $2;
  295. }, function($ctx1) {$ctx1.fill(self,"ownCategoriesOfClass:",{aClass:aClass,map:map},smalltalk.ChunkExporter.klass)})},
  296. args: ["aClass"],
  297. source: "ownCategoriesOfClass: aClass\x0a\x09\x22Issue #143: sort protocol alphabetically\x22\x0a\x0a\x09| map |\x0a\x09map := Dictionary new.\x0a\x09aClass protocolsDo: [:category :methods |\x0a\x09\x09(category match: '^\x5c*') ifFalse: [ map at: category put: methods ]].\x0a\x09^(map keys sorted: [:a :b | a <= b ]) collect: [:category |\x0a\x09\x09#{\x0a\x09\x09\x09'methods'->(map at: category).\x0a\x09\x09\x09'name'->category.\x0a\x09\x09\x09'class'->aClass }]",
  298. messageSends: ["new", "protocolsDo:", "ifFalse:", "at:put:", "match:", "collect:", "->", "at:", "sorted:", "<=", "keys"],
  299. referencedClasses: ["Dictionary"]
  300. }),
  301. smalltalk.ChunkExporter.klass);
  302. smalltalk.addMethod(
  303. smalltalk.method({
  304. selector: "ownCategoriesOfMetaClass:",
  305. category: 'exporting-accessing',
  306. fn: function (aClass){
  307. var self=this;
  308. return smalltalk.withContext(function($ctx1) {
  309. var $1;
  310. $1=self._ownCategoriesOfClass_(_st(aClass)._class());
  311. return $1;
  312. }, function($ctx1) {$ctx1.fill(self,"ownCategoriesOfMetaClass:",{aClass:aClass},smalltalk.ChunkExporter.klass)})},
  313. args: ["aClass"],
  314. source: "ownCategoriesOfMetaClass: aClass\x0a\x09\x22Issue #143: sort protocol alphabetically\x22\x0a\x0a\x09^self ownCategoriesOfClass: aClass class",
  315. messageSends: ["ownCategoriesOfClass:", "class"],
  316. referencedClasses: []
  317. }),
  318. smalltalk.ChunkExporter.klass);
  319. smalltalk.addMethod(
  320. smalltalk.method({
  321. selector: "recipe",
  322. category: 'fileOut',
  323. fn: function (){
  324. var self=this;
  325. var exportCategoryRecipe;
  326. function $PluggableExporter(){return smalltalk.PluggableExporter||(typeof PluggableExporter=="undefined"?nil:PluggableExporter)}
  327. return smalltalk.withContext(function($ctx1) {
  328. var $1;
  329. exportCategoryRecipe=[self.__minus_gt("exportCategoryPrologueOf:on:"),[self.__minus_gt("methodsOfCategory:"),self.__minus_gt("exportMethod:on:")],self.__minus_gt("exportCategoryEpilogueOf:on:")];
  330. $1=[self.__minus_gt("exportPackageDefinitionOf:on:"),[_st($PluggableExporter()).__minus_gt("ownClassesOfPackage:"),self.__minus_gt("exportDefinitionOf:on:"),_st([self.__minus_gt("ownCategoriesOfClass:")]).__comma(exportCategoryRecipe),self.__minus_gt("exportMetaDefinitionOf:on:"),_st([self.__minus_gt("ownCategoriesOfMetaClass:")]).__comma(exportCategoryRecipe)],_st([self.__minus_gt("extensionCategoriesOfPackage:")]).__comma(exportCategoryRecipe)];
  331. return $1;
  332. }, function($ctx1) {$ctx1.fill(self,"recipe",{exportCategoryRecipe:exportCategoryRecipe},smalltalk.ChunkExporter.klass)})},
  333. args: [],
  334. source: "recipe\x0a\x09\x22Export a given package.\x22\x0a\x0a\x09| exportCategoryRecipe |\x0a\x09exportCategoryRecipe := {\x0a\x09\x09self -> #exportCategoryPrologueOf:on:.\x0a\x09\x09{\x0a\x09\x09\x09self -> #methodsOfCategory:.\x0a\x09\x09\x09self -> #exportMethod:on: }.\x0a\x09\x09self -> #exportCategoryEpilogueOf:on: }.\x0a\x0a\x09^{\x0a\x09\x09self -> #exportPackageDefinitionOf:on:.\x0a\x09\x09{\x0a\x09\x09\x09PluggableExporter -> #ownClassesOfPackage:.\x0a\x09\x09\x09self -> #exportDefinitionOf:on:.\x0a\x09\x09\x09{ self -> #ownCategoriesOfClass: }, exportCategoryRecipe.\x0a\x09\x09\x09self -> #exportMetaDefinitionOf:on:.\x0a\x09\x09\x09{ self -> #ownCategoriesOfMetaClass: }, exportCategoryRecipe }.\x0a\x09\x09{ self -> #extensionCategoriesOfPackage: }, exportCategoryRecipe\x0a\x09}",
  335. messageSends: ["->", ","],
  336. referencedClasses: ["PluggableExporter"]
  337. }),
  338. smalltalk.ChunkExporter.klass);
  339. smalltalk.addClass('ChunkParser', smalltalk.Object, ['stream'], 'Importer-Exporter');
  340. smalltalk.ChunkParser.comment="I am responsible for parsing aStream contents in the chunk format.\x0a\x0a## API\x0a\x0a ChunkParser new\x0a stream: aStream;\x0a nextChunk";
  341. smalltalk.addMethod(
  342. smalltalk.method({
  343. selector: "nextChunk",
  344. category: 'reading',
  345. fn: function (){
  346. var self=this;
  347. var char,result,chunk;
  348. return smalltalk.withContext(function($ctx1) {
  349. var $1,$2,$3;
  350. var $early={};
  351. try {
  352. result=""._writeStream();
  353. _st((function(){
  354. return smalltalk.withContext(function($ctx2) {
  355. char=_st(self["@stream"])._next();
  356. char;
  357. return _st(char)._notNil();
  358. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileTrue_((function(){
  359. return smalltalk.withContext(function($ctx2) {
  360. $1=_st(char).__eq("!");
  361. if(smalltalk.assert($1)){
  362. $2=_st(_st(self["@stream"])._peek()).__eq("!");
  363. if(smalltalk.assert($2)){
  364. _st(self["@stream"])._next();
  365. } else {
  366. $3=_st(_st(result)._contents())._trimBoth();
  367. throw $early=[$3];
  368. };
  369. };
  370. return _st(result)._nextPut_(char);
  371. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  372. return nil;
  373. }
  374. catch(e) {if(e===$early)return e[0]; throw e}
  375. }, function($ctx1) {$ctx1.fill(self,"nextChunk",{char:char,result:result,chunk:chunk},smalltalk.ChunkParser)})},
  376. args: [],
  377. source: "nextChunk\x0a\x09\x22The chunk format (Smalltalk Interchange Format or Fileout format)\x0a\x09is a trivial format but can be a bit tricky to understand:\x0a\x09\x09- Uses the exclamation mark as delimiter of chunks.\x0a\x09\x09- Inside a chunk a normal exclamation mark must be doubled.\x0a\x09\x09- A non empty chunk must be a valid Smalltalk expression.\x0a\x09\x09- A chunk on top level with a preceding empty chunk is an instruction chunk:\x0a\x09\x09\x09- The object created by the expression then takes over reading chunks.\x0a\x0a\x09This metod returns next chunk as a String (trimmed), empty String (all whitespace) or nil.\x22\x0a\x0a\x09| char result chunk |\x0a\x09result := '' writeStream.\x0a\x09\x09[char := stream next.\x0a\x09\x09char notNil] whileTrue: [\x0a\x09\x09\x09\x09char = '!' ifTrue: [\x0a\x09\x09\x09\x09\x09\x09stream peek = '!'\x0a\x09\x09\x09\x09\x09\x09\x09\x09ifTrue: [stream next \x22skipping the escape double\x22]\x0a\x09\x09\x09\x09\x09\x09\x09\x09ifFalse: [^result contents trimBoth \x22chunk end marker found\x22]].\x0a\x09\x09\x09\x09result nextPut: char].\x0a\x09^nil \x22a chunk needs to end with !\x22",
  378. messageSends: ["writeStream", "whileTrue:", "ifTrue:", "ifTrue:ifFalse:", "next", "trimBoth", "contents", "=", "peek", "nextPut:", "notNil"],
  379. referencedClasses: []
  380. }),
  381. smalltalk.ChunkParser);
  382. smalltalk.addMethod(
  383. smalltalk.method({
  384. selector: "stream:",
  385. category: 'accessing',
  386. fn: function (aStream){
  387. var self=this;
  388. return smalltalk.withContext(function($ctx1) {
  389. self["@stream"]=aStream;
  390. return self}, function($ctx1) {$ctx1.fill(self,"stream:",{aStream:aStream},smalltalk.ChunkParser)})},
  391. args: ["aStream"],
  392. source: "stream: aStream\x0a\x09stream := aStream",
  393. messageSends: [],
  394. referencedClasses: []
  395. }),
  396. smalltalk.ChunkParser);
  397. smalltalk.addMethod(
  398. smalltalk.method({
  399. selector: "on:",
  400. category: 'not yet classified',
  401. fn: function (aStream){
  402. var self=this;
  403. return smalltalk.withContext(function($ctx1) {
  404. var $1;
  405. $1=_st(self._new())._stream_(aStream);
  406. return $1;
  407. }, function($ctx1) {$ctx1.fill(self,"on:",{aStream:aStream},smalltalk.ChunkParser.klass)})},
  408. args: ["aStream"],
  409. source: "on: aStream\x0a\x09^self new stream: aStream",
  410. messageSends: ["stream:", "new"],
  411. referencedClasses: []
  412. }),
  413. smalltalk.ChunkParser.klass);
  414. smalltalk.addClass('Exporter', smalltalk.Object, [], 'Importer-Exporter');
  415. smalltalk.Exporter.comment="I am responsible for outputting Amber code into a JavaScript string.\x0a\x0aThe generated output is enough to reconstruct the exported data, including Smalltalk source code and other metadata.\x0a\x0a## Use case\x0a\x0aI am typically used to save code outside of the Amber runtime (committing to disk, etc.).\x0a\x0a## API\x0a\x0aUse `#exportAll`, `#exportClass:` or `#exportPackage:` methods.";
  416. smalltalk.addMethod(
  417. smalltalk.method({
  418. selector: "classNameFor:",
  419. category: 'private',
  420. fn: function (aClass){
  421. var self=this;
  422. return smalltalk.withContext(function($ctx1) {
  423. var $2,$3,$1;
  424. $2=_st(aClass)._isMetaclass();
  425. if(smalltalk.assert($2)){
  426. $1=_st(_st(_st(aClass)._instanceClass())._name()).__comma(".klass");
  427. } else {
  428. $3=_st(aClass)._isNil();
  429. if(smalltalk.assert($3)){
  430. $1="nil";
  431. } else {
  432. $1=_st(aClass)._name();
  433. };
  434. };
  435. return $1;
  436. }, function($ctx1) {$ctx1.fill(self,"classNameFor:",{aClass:aClass},smalltalk.Exporter.klass)})},
  437. args: ["aClass"],
  438. source: "classNameFor: aClass\x0a\x09^aClass isMetaclass\x0a\x09\x09ifTrue: [aClass instanceClass name, '.klass']\x0a\x09\x09ifFalse: [\x0a\x09\x09aClass isNil\x0a\x09\x09\x09ifTrue: ['nil']\x0a\x09\x09\x09ifFalse: [aClass name]]",
  439. messageSends: ["ifTrue:ifFalse:", ",", "name", "instanceClass", "isNil", "isMetaclass"],
  440. referencedClasses: []
  441. }),
  442. smalltalk.Exporter.klass);
  443. smalltalk.addMethod(
  444. smalltalk.method({
  445. selector: "exportDefinitionOf:on:",
  446. category: 'exporting-output',
  447. fn: function (aClass,aStream){
  448. var self=this;
  449. return smalltalk.withContext(function($ctx1) {
  450. var $1,$2,$3,$4,$5,$6,$7;
  451. $1=aStream;
  452. _st($1)._lf();
  453. _st($1)._nextPutAll_("smalltalk.addClass(");
  454. _st($1)._nextPutAll_(_st("'".__comma(self._classNameFor_(aClass))).__comma("', "));
  455. _st($1)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aClass)._superclass())));
  456. $2=_st($1)._nextPutAll_(", [");
  457. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  458. return smalltalk.withContext(function($ctx2) {
  459. return _st(aStream)._nextPutAll_(_st("'".__comma(each)).__comma("'"));
  460. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  461. return smalltalk.withContext(function($ctx2) {
  462. return _st(aStream)._nextPutAll_(", ");
  463. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  464. $3=aStream;
  465. _st($3)._nextPutAll_("], '");
  466. _st($3)._nextPutAll_(_st(_st(aClass)._category()).__comma("'"));
  467. $4=_st($3)._nextPutAll_(");");
  468. $5=_st(_st(aClass)._comment())._notEmpty();
  469. if(smalltalk.assert($5)){
  470. $6=aStream;
  471. _st($6)._lf();
  472. _st($6)._nextPutAll_("smalltalk.");
  473. _st($6)._nextPutAll_(self._classNameFor_(aClass));
  474. _st($6)._nextPutAll_(".comment=");
  475. _st($6)._nextPutAll_(_st(_st(aClass)._comment())._asJavascript());
  476. $7=_st($6)._nextPutAll_(";");
  477. $7;
  478. };
  479. _st(aStream)._lf();
  480. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.Exporter.klass)})},
  481. args: ["aClass", "aStream"],
  482. source: "exportDefinitionOf: aClass on: aStream\x0a\x09aStream\x0a\x09\x09lf;\x0a\x09\x09nextPutAll: 'smalltalk.addClass(';\x0a\x09\x09nextPutAll: '''', (self classNameFor: aClass), ''', ';\x0a\x09\x09nextPutAll: 'smalltalk.', (self classNameFor: aClass superclass);\x0a\x09\x09nextPutAll: ', ['.\x0a\x09aClass instanceVariableNames\x0a\x09\x09do: [:each | aStream nextPutAll: '''', each, '''']\x0a\x09\x09separatedBy: [aStream nextPutAll: ', '].\x0a\x09aStream\x0a\x09\x09nextPutAll: '], ''';\x0a\x09\x09nextPutAll: aClass category, '''';\x0a\x09\x09nextPutAll: ');'.\x0a\x09aClass comment notEmpty ifTrue: [\x0a\x09\x09aStream\x0a\x09\x09\x09lf;\x0a\x09\x09nextPutAll: 'smalltalk.';\x0a\x09\x09nextPutAll: (self classNameFor: aClass);\x0a\x09\x09nextPutAll: '.comment=';\x0a\x09\x09nextPutAll: aClass comment asJavascript;\x0a\x09\x09nextPutAll: ';'].\x0a\x09aStream lf",
  483. messageSends: ["lf", "nextPutAll:", ",", "classNameFor:", "superclass", "do:separatedBy:", "instanceVariableNames", "category", "ifTrue:", "asJavascript", "comment", "notEmpty"],
  484. referencedClasses: []
  485. }),
  486. smalltalk.Exporter.klass);
  487. smalltalk.addMethod(
  488. smalltalk.method({
  489. selector: "exportMetaDefinitionOf:on:",
  490. category: 'exporting-output',
  491. fn: function (aClass,aStream){
  492. var self=this;
  493. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  494. return smalltalk.withContext(function($ctx1) {
  495. var $1,$2,$3;
  496. _st(aStream)._lf();
  497. $1=_st(_st(_st(aClass)._class())._instanceVariableNames())._isEmpty();
  498. if(! smalltalk.assert($1)){
  499. $2=aStream;
  500. _st($2)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aClass)._class())));
  501. $3=_st($2)._nextPutAll_(".iVarNames = [");
  502. $3;
  503. _st(_st(_st(aClass)._class())._instanceVariableNames())._do_separatedBy_((function(each){
  504. return smalltalk.withContext(function($ctx2) {
  505. return _st(aStream)._nextPutAll_(_st("'".__comma(each)).__comma("'"));
  506. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  507. return smalltalk.withContext(function($ctx2) {
  508. return _st(aStream)._nextPutAll_(",");
  509. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  510. _st(aStream)._nextPutAll_("];".__comma(_st($String())._lf()));
  511. };
  512. return self}, function($ctx1) {$ctx1.fill(self,"exportMetaDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.Exporter.klass)})},
  513. args: ["aClass", "aStream"],
  514. source: "exportMetaDefinitionOf: aClass on: aStream\x0a\x09aStream lf.\x0a\x09aClass class instanceVariableNames isEmpty ifFalse: [\x0a\x09\x09aStream\x0a\x09\x09nextPutAll: 'smalltalk.', (self classNameFor: aClass class);\x0a\x09\x09nextPutAll: '.iVarNames = ['.\x0a\x09\x09aClass class instanceVariableNames\x0a\x09\x09do: [:each | aStream nextPutAll: '''', each, '''']\x0a\x09\x09separatedBy: [aStream nextPutAll: ','].\x0a\x09\x09aStream nextPutAll: '];', String lf]",
  515. messageSends: ["lf", "ifFalse:", "nextPutAll:", ",", "classNameFor:", "class", "do:separatedBy:", "instanceVariableNames", "isEmpty"],
  516. referencedClasses: ["String"]
  517. }),
  518. smalltalk.Exporter.klass);
  519. smalltalk.addMethod(
  520. smalltalk.method({
  521. selector: "exportMethod:on:",
  522. category: 'exporting-output',
  523. fn: function (aMethod,aStream){
  524. var self=this;
  525. return smalltalk.withContext(function($ctx1) {
  526. var $1,$2,$3,$4;
  527. $1=aStream;
  528. _st($1)._nextPutAll_("smalltalk.addMethod(");
  529. _st($1)._lf();
  530. _st($1)._nextPutAll_("smalltalk.method({");
  531. _st($1)._lf();
  532. _st($1)._nextPutAll_(_st("selector: ".__comma(_st(_st(aMethod)._selector())._asJavascript())).__comma(","));
  533. _st($1)._lf();
  534. _st($1)._nextPutAll_(_st("category: '".__comma(_st(aMethod)._category())).__comma("',"));
  535. _st($1)._lf();
  536. _st($1)._nextPutAll_(_st("fn: ".__comma(_st(_st(aMethod)._fn())._compiledSource())).__comma(","));
  537. _st($1)._lf();
  538. _st($1)._nextPutAll_(_st("args: ".__comma(_st(_st(aMethod)._arguments())._asJavascript())).__comma(","));
  539. _st($1)._lf();
  540. _st($1)._nextPutAll_(_st("source: ".__comma(_st(_st(aMethod)._source())._asJavascript())).__comma(","));
  541. _st($1)._lf();
  542. _st($1)._nextPutAll_(_st("messageSends: ".__comma(_st(_st(aMethod)._messageSends())._asJavascript())).__comma(","));
  543. _st($1)._lf();
  544. $2=_st($1)._nextPutAll_("referencedClasses: ".__comma(_st(_st(aMethod)._referencedClasses())._asJavascript()));
  545. $3=aStream;
  546. _st($3)._lf();
  547. _st($3)._nextPutAll_("}),");
  548. _st($3)._lf();
  549. _st($3)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aMethod)._methodClass())));
  550. _st($3)._nextPutAll_(");");
  551. _st($3)._lf();
  552. $4=_st($3)._lf();
  553. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:on:",{aMethod:aMethod,aStream:aStream},smalltalk.Exporter.klass)})},
  554. args: ["aMethod", "aStream"],
  555. source: "exportMethod: aMethod on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: 'smalltalk.addMethod(';lf;\x0a\x09\x09\x22nextPutAll: aMethod selector asSelector asJavascript, ',';lf;\x22\x0a\x09\x09nextPutAll: 'smalltalk.method({';lf;\x0a\x09\x09nextPutAll: 'selector: ', aMethod selector asJavascript, ',';lf;\x0a\x09\x09nextPutAll: 'category: ''', aMethod category, ''',';lf;\x0a\x09\x09nextPutAll: 'fn: ', aMethod fn compiledSource, ',';lf;\x0a\x09\x09nextPutAll: 'args: ', aMethod arguments asJavascript, ','; lf;\x0a\x09\x09nextPutAll: 'source: ', aMethod source asJavascript, ',';lf;\x0a\x09\x09nextPutAll: 'messageSends: ', aMethod messageSends asJavascript, ',';lf;\x0a\x09\x09nextPutAll: 'referencedClasses: ', aMethod referencedClasses asJavascript.\x0a\x09aStream\x0a\x09\x09lf;\x0a\x09\x09nextPutAll: '}),';lf;\x0a\x09\x09nextPutAll: 'smalltalk.', (self classNameFor: aMethod methodClass);\x0a\x09\x09nextPutAll: ');';lf;lf",
  556. messageSends: ["nextPutAll:", "lf", ",", "asJavascript", "selector", "category", "compiledSource", "fn", "arguments", "source", "messageSends", "referencedClasses", "classNameFor:", "methodClass"],
  557. referencedClasses: []
  558. }),
  559. smalltalk.Exporter.klass);
  560. smalltalk.addMethod(
  561. smalltalk.method({
  562. selector: "exportPackageDefinitionOf:on:",
  563. category: 'exporting-output',
  564. fn: function (package_,aStream){
  565. var self=this;
  566. return smalltalk.withContext(function($ctx1) {
  567. var $1,$2;
  568. $1=aStream;
  569. _st($1)._nextPutAll_("smalltalk.addPackage(");
  570. _st($1)._nextPutAll_(_st("'".__comma(_st(package_)._name())).__comma("');"));
  571. $2=_st($1)._lf();
  572. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageDefinitionOf:on:",{package_:package_,aStream:aStream},smalltalk.Exporter.klass)})},
  573. args: ["package", "aStream"],
  574. source: "exportPackageDefinitionOf: package on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: 'smalltalk.addPackage(';\x0a\x09\x09nextPutAll: '''', package name, ''');';\x0a\x09\x09lf",
  575. messageSends: ["nextPutAll:", ",", "name", "lf"],
  576. referencedClasses: []
  577. }),
  578. smalltalk.Exporter.klass);
  579. smalltalk.addMethod(
  580. smalltalk.method({
  581. selector: "exportPackageEpilogueOf:on:",
  582. category: 'exporting-output',
  583. fn: function (aPackage,aStream){
  584. var self=this;
  585. return smalltalk.withContext(function($ctx1) {
  586. var $1,$2;
  587. $1=aStream;
  588. _st($1)._nextPutAll_("})(global_smalltalk,global_nil,global__st);");
  589. $2=_st($1)._lf();
  590. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageEpilogueOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.Exporter.klass)})},
  591. args: ["aPackage", "aStream"],
  592. source: "exportPackageEpilogueOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '})(global_smalltalk,global_nil,global__st);';\x0a\x09\x09lf",
  593. messageSends: ["nextPutAll:", "lf"],
  594. referencedClasses: []
  595. }),
  596. smalltalk.Exporter.klass);
  597. smalltalk.addMethod(
  598. smalltalk.method({
  599. selector: "exportPackagePrologueOf:on:",
  600. category: 'exporting-output',
  601. fn: function (aPackage,aStream){
  602. var self=this;
  603. return smalltalk.withContext(function($ctx1) {
  604. var $1,$2;
  605. $1=aStream;
  606. _st($1)._nextPutAll_("(function(smalltalk,nil,_st){");
  607. $2=_st($1)._lf();
  608. return self}, function($ctx1) {$ctx1.fill(self,"exportPackagePrologueOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.Exporter.klass)})},
  609. args: ["aPackage", "aStream"],
  610. source: "exportPackagePrologueOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '(function(smalltalk,nil,_st){';\x0a\x09\x09lf",
  611. messageSends: ["nextPutAll:", "lf"],
  612. referencedClasses: []
  613. }),
  614. smalltalk.Exporter.klass);
  615. smalltalk.addMethod(
  616. smalltalk.method({
  617. selector: "extensionMethodsOfPackage:",
  618. category: 'exporting-accessing',
  619. fn: function (package_){
  620. var self=this;
  621. var name,result;
  622. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  623. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  624. function $Package(){return smalltalk.Package||(typeof Package=="undefined"?nil:Package)}
  625. return smalltalk.withContext(function($ctx1) {
  626. var $1;
  627. name=_st(package_)._name();
  628. result=_st($OrderedCollection())._new();
  629. _st(_st($Package())._sortedClasses_(_st(_st($Smalltalk())._current())._classes()))._do_((function(each){
  630. return smalltalk.withContext(function($ctx2) {
  631. return _st([each,_st(each)._class()])._do_((function(aClass){
  632. return smalltalk.withContext(function($ctx3) {
  633. return _st(result)._addAll_(_st(_st(_st(_st(aClass)._methodDictionary())._values())._sorted_((function(a,b){
  634. return smalltalk.withContext(function($ctx4) {
  635. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  636. }, function($ctx4) {$ctx4.fillBlock({a:a,b:b},$ctx3)})})))._select_((function(method){
  637. return smalltalk.withContext(function($ctx4) {
  638. return _st(_st(method)._category())._match_("^\x5c*".__comma(name));
  639. }, function($ctx4) {$ctx4.fillBlock({method:method},$ctx3)})})));
  640. }, function($ctx3) {$ctx3.fillBlock({aClass:aClass},$ctx2)})}));
  641. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  642. $1=result;
  643. return $1;
  644. }, function($ctx1) {$ctx1.fill(self,"extensionMethodsOfPackage:",{package_:package_,name:name,result:result},smalltalk.Exporter.klass)})},
  645. args: ["package"],
  646. source: "extensionMethodsOfPackage: package\x0a\x09\x22Issue #143: sort classes and methods alphabetically\x22\x0a\x0a\x09| name result |\x0a\x09name := package name.\x0a\x09result := OrderedCollection new.\x0a\x09(Package sortedClasses: Smalltalk current classes) do: [:each |\x0a\x09\x09{each. each class} do: [:aClass |\x0a\x09\x09\x09result addAll: (((aClass methodDictionary values)\x0a\x09\x09\x09\x09sorted: [:a :b | a selector <= b selector])\x0a\x09\x09\x09\x09select: [:method | method category match: '^\x5c*', name]) ]].\x0a\x09^result",
  647. messageSends: ["name", "new", "do:", "addAll:", "select:", "match:", ",", "category", "sorted:", "<=", "selector", "values", "methodDictionary", "class", "sortedClasses:", "classes", "current"],
  648. referencedClasses: ["OrderedCollection", "Smalltalk", "Package"]
  649. }),
  650. smalltalk.Exporter.klass);
  651. smalltalk.addMethod(
  652. smalltalk.method({
  653. selector: "ownMethodsOfClass:",
  654. category: 'exporting-accessing',
  655. fn: function (aClass){
  656. var self=this;
  657. return smalltalk.withContext(function($ctx1) {
  658. var $1;
  659. $1=_st(_st(_st(_st(aClass)._methodDictionary())._values())._sorted_((function(a,b){
  660. return smalltalk.withContext(function($ctx2) {
  661. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  662. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})})))._reject_((function(each){
  663. return smalltalk.withContext(function($ctx2) {
  664. return _st(_st(each)._category())._match_("^\x5c*");
  665. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  666. return $1;
  667. }, function($ctx1) {$ctx1.fill(self,"ownMethodsOfClass:",{aClass:aClass},smalltalk.Exporter.klass)})},
  668. args: ["aClass"],
  669. source: "ownMethodsOfClass: aClass\x0a\x09\x22Issue #143: sort methods alphabetically\x22\x0a\x0a\x09^((aClass methodDictionary values) sorted: [:a :b | a selector <= b selector])\x0a\x09\x09reject: [:each | (each category match: '^\x5c*')]",
  670. messageSends: ["reject:", "match:", "category", "sorted:", "<=", "selector", "values", "methodDictionary"],
  671. referencedClasses: []
  672. }),
  673. smalltalk.Exporter.klass);
  674. smalltalk.addMethod(
  675. smalltalk.method({
  676. selector: "ownMethodsOfMetaClass:",
  677. category: 'exporting-accessing',
  678. fn: function (aClass){
  679. var self=this;
  680. return smalltalk.withContext(function($ctx1) {
  681. var $1;
  682. $1=self._ownMethodsOfClass_(_st(aClass)._class());
  683. return $1;
  684. }, function($ctx1) {$ctx1.fill(self,"ownMethodsOfMetaClass:",{aClass:aClass},smalltalk.Exporter.klass)})},
  685. args: ["aClass"],
  686. source: "ownMethodsOfMetaClass: aClass\x0a\x09\x22Issue #143: sort methods alphabetically\x22\x0a\x0a\x09^self ownMethodsOfClass: aClass class",
  687. messageSends: ["ownMethodsOfClass:", "class"],
  688. referencedClasses: []
  689. }),
  690. smalltalk.Exporter.klass);
  691. smalltalk.addMethod(
  692. smalltalk.method({
  693. selector: "recipe",
  694. category: 'fileOut',
  695. fn: function (){
  696. var self=this;
  697. function $PluggableExporter(){return smalltalk.PluggableExporter||(typeof PluggableExporter=="undefined"?nil:PluggableExporter)}
  698. return smalltalk.withContext(function($ctx1) {
  699. var $1;
  700. $1=[self.__minus_gt("exportPackagePrologueOf:on:"),self.__minus_gt("exportPackageDefinitionOf:on:"),[_st($PluggableExporter()).__minus_gt("ownClassesOfPackage:"),self.__minus_gt("exportDefinitionOf:on:"),[self.__minus_gt("ownMethodsOfClass:"),self.__minus_gt("exportMethod:on:")],self.__minus_gt("exportMetaDefinitionOf:on:"),[self.__minus_gt("ownMethodsOfMetaClass:"),self.__minus_gt("exportMethod:on:")]],[self.__minus_gt("extensionMethodsOfPackage:"),self.__minus_gt("exportMethod:on:")],self.__minus_gt("exportPackageEpilogueOf:on:")];
  701. return $1;
  702. }, function($ctx1) {$ctx1.fill(self,"recipe",{},smalltalk.Exporter.klass)})},
  703. args: [],
  704. source: "recipe\x0a\x09\x22Export a given package.\x22\x0a\x0a\x09^{\x0a\x09\x09self -> #exportPackagePrologueOf:on:.\x0a\x09\x09self -> #exportPackageDefinitionOf:on:.\x0a\x09\x09{\x0a\x09\x09\x09PluggableExporter -> #ownClassesOfPackage:.\x0a\x09\x09\x09self -> #exportDefinitionOf:on:.\x0a\x09\x09\x09{\x0a\x09\x09\x09\x09self -> #ownMethodsOfClass:.\x0a\x09\x09\x09\x09self -> #exportMethod:on: }.\x0a\x09\x09\x09self -> #exportMetaDefinitionOf:on:.\x0a\x09\x09\x09{\x0a\x09\x09\x09\x09self -> #ownMethodsOfMetaClass:.\x0a\x09\x09\x09\x09self -> #exportMethod:on: } }.\x0a\x09\x09{\x0a\x09\x09\x09self -> #extensionMethodsOfPackage:.\x0a\x09\x09\x09self -> #exportMethod:on: }.\x0a\x09\x09self -> #exportPackageEpilogueOf:on:\x0a\x09}",
  705. messageSends: ["->"],
  706. referencedClasses: ["PluggableExporter"]
  707. }),
  708. smalltalk.Exporter.klass);
  709. smalltalk.addClass('StrippedExporter', smalltalk.Exporter, [], 'Importer-Exporter');
  710. smalltalk.StrippedExporter.comment="I export Amber code into a JavaScript string, but without any optional associated data like the Amber source code.";
  711. smalltalk.addMethod(
  712. smalltalk.method({
  713. selector: "exportDefinitionOf:on:",
  714. category: 'exporting-output',
  715. fn: function (aClass,aStream){
  716. var self=this;
  717. return smalltalk.withContext(function($ctx1) {
  718. var $1,$2,$3,$4;
  719. $1=aStream;
  720. _st($1)._lf();
  721. _st($1)._nextPutAll_("smalltalk.addClass(");
  722. _st($1)._nextPutAll_(_st("'".__comma(self._classNameFor_(aClass))).__comma("', "));
  723. _st($1)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aClass)._superclass())));
  724. $2=_st($1)._nextPutAll_(", [");
  725. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  726. return smalltalk.withContext(function($ctx2) {
  727. return _st(aStream)._nextPutAll_(_st("'".__comma(each)).__comma("'"));
  728. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  729. return smalltalk.withContext(function($ctx2) {
  730. return _st(aStream)._nextPutAll_(", ");
  731. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  732. $3=aStream;
  733. _st($3)._nextPutAll_("], '");
  734. _st($3)._nextPutAll_(_st(_st(aClass)._category()).__comma("'"));
  735. $4=_st($3)._nextPutAll_(");");
  736. _st(aStream)._lf();
  737. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.StrippedExporter.klass)})},
  738. args: ["aClass", "aStream"],
  739. source: "exportDefinitionOf: aClass on: aStream\x0a\x09aStream\x0a\x09\x09lf;\x0a\x09\x09nextPutAll: 'smalltalk.addClass(';\x0a\x09\x09nextPutAll: '''', (self classNameFor: aClass), ''', ';\x0a\x09\x09nextPutAll: 'smalltalk.', (self classNameFor: aClass superclass);\x0a\x09\x09nextPutAll: ', ['.\x0a\x09aClass instanceVariableNames\x0a\x09\x09do: [:each | aStream nextPutAll: '''', each, '''']\x0a\x09\x09separatedBy: [aStream nextPutAll: ', '].\x0a\x09aStream\x0a\x09\x09nextPutAll: '], ''';\x0a\x09\x09nextPutAll: aClass category, '''';\x0a\x09\x09nextPutAll: ');'.\x0a\x09aStream lf",
  740. messageSends: ["lf", "nextPutAll:", ",", "classNameFor:", "superclass", "do:separatedBy:", "instanceVariableNames", "category"],
  741. referencedClasses: []
  742. }),
  743. smalltalk.StrippedExporter.klass);
  744. smalltalk.addMethod(
  745. smalltalk.method({
  746. selector: "exportMethod:on:",
  747. category: 'exporting-output',
  748. fn: function (aMethod,aStream){
  749. var self=this;
  750. return smalltalk.withContext(function($ctx1) {
  751. var $1,$2;
  752. $1=aStream;
  753. _st($1)._nextPutAll_("smalltalk.addMethod(");
  754. _st($1)._lf();
  755. _st($1)._nextPutAll_("smalltalk.method({");
  756. _st($1)._lf();
  757. _st($1)._nextPutAll_(_st("selector: ".__comma(_st(_st(aMethod)._selector())._asJavascript())).__comma(","));
  758. _st($1)._lf();
  759. _st($1)._nextPutAll_(_st("fn: ".__comma(_st(_st(aMethod)._fn())._compiledSource())).__comma(","));
  760. _st($1)._lf();
  761. _st($1)._nextPutAll_("messageSends: ".__comma(_st(_st(aMethod)._messageSends())._asJavascript()));
  762. _st($1)._nextPutAll_("}),");
  763. _st($1)._lf();
  764. _st($1)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aMethod)._methodClass())));
  765. _st($1)._nextPutAll_(");");
  766. _st($1)._lf();
  767. $2=_st($1)._lf();
  768. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:on:",{aMethod:aMethod,aStream:aStream},smalltalk.StrippedExporter.klass)})},
  769. args: ["aMethod", "aStream"],
  770. source: "exportMethod: aMethod on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: 'smalltalk.addMethod(';lf;\x0a\x09\x09\x22nextPutAll: aMethod selector asSelector asJavascript, ',';lf;\x22\x0a\x09\x09nextPutAll: 'smalltalk.method({';lf;\x0a\x09\x09nextPutAll: 'selector: ', aMethod selector asJavascript, ',';lf;\x0a\x09\x09nextPutAll: 'fn: ', aMethod fn compiledSource, ',';lf;\x0a\x09\x09nextPutAll: 'messageSends: ', aMethod messageSends asJavascript;\x0a\x09\x09nextPutAll: '}),';lf;\x0a\x09\x09nextPutAll: 'smalltalk.', (self classNameFor: aMethod methodClass);\x0a\x09\x09nextPutAll: ');';lf;lf",
  771. messageSends: ["nextPutAll:", "lf", ",", "asJavascript", "selector", "compiledSource", "fn", "messageSends", "classNameFor:", "methodClass"],
  772. referencedClasses: []
  773. }),
  774. smalltalk.StrippedExporter.klass);
  775. smalltalk.addClass('Importer', smalltalk.Object, [], 'Importer-Exporter');
  776. smalltalk.Importer.comment="I can import Amber code from a string in the chunk format.\x0a\x0a## API\x0a\x0a Importer new import: aString";
  777. smalltalk.addMethod(
  778. smalltalk.method({
  779. selector: "import:",
  780. category: 'fileIn',
  781. fn: function (aStream){
  782. var self=this;
  783. var chunk,result,parser,lastEmpty;
  784. function $ChunkParser(){return smalltalk.ChunkParser||(typeof ChunkParser=="undefined"?nil:ChunkParser)}
  785. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  786. return smalltalk.withContext(function($ctx1) {
  787. var $1,$2;
  788. parser=_st($ChunkParser())._on_(aStream);
  789. lastEmpty=false;
  790. _st((function(){
  791. return smalltalk.withContext(function($ctx2) {
  792. chunk=_st(parser)._nextChunk();
  793. chunk;
  794. return _st(chunk)._isNil();
  795. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileFalse_((function(){
  796. return smalltalk.withContext(function($ctx2) {
  797. $1=_st(chunk)._isEmpty();
  798. if(smalltalk.assert($1)){
  799. lastEmpty=true;
  800. return lastEmpty;
  801. } else {
  802. result=_st(_st($Compiler())._new())._evaluateExpression_(chunk);
  803. result;
  804. $2=lastEmpty;
  805. if(smalltalk.assert($2)){
  806. lastEmpty=false;
  807. lastEmpty;
  808. return _st(result)._scanFrom_(parser);
  809. };
  810. };
  811. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  812. return self}, function($ctx1) {$ctx1.fill(self,"import:",{aStream:aStream,chunk:chunk,result:result,parser:parser,lastEmpty:lastEmpty},smalltalk.Importer)})},
  813. args: ["aStream"],
  814. source: "import: aStream\x0a\x09| chunk result parser lastEmpty |\x0a\x09parser := ChunkParser on: aStream.\x0a\x09lastEmpty := false.\x0a\x09[chunk := parser nextChunk.\x0a\x09chunk isNil] whileFalse: [\x0a\x09\x09chunk isEmpty\x0a\x09\x09\x09ifTrue: [lastEmpty := true]\x0a\x09\x09\x09ifFalse: [\x0a\x09\x09\x09\x09result := Compiler new evaluateExpression: chunk.\x0a\x09\x09\x09\x09lastEmpty\x0a\x09\x09\x09\x09\x09\x09ifTrue: [\x0a\x09\x09\x09\x09\x09\x09\x09\x09\x09lastEmpty := false.\x0a\x09\x09\x09\x09\x09\x09\x09\x09\x09result scanFrom: parser]]]",
  815. messageSends: ["on:", "whileFalse:", "ifTrue:ifFalse:", "evaluateExpression:", "new", "ifTrue:", "scanFrom:", "isEmpty", "nextChunk", "isNil"],
  816. referencedClasses: ["ChunkParser", "Compiler"]
  817. }),
  818. smalltalk.Importer);
  819. smalltalk.addClass('PackageHandler', smalltalk.Object, [], 'Importer-Exporter');
  820. smalltalk.PackageHandler.comment="I am responsible for handling package loading and committing.\x0a\x0aI should not be used directly. Instead, use the corresponding `Package` methods.";
  821. smalltalk.addMethod(
  822. smalltalk.method({
  823. selector: "ajaxPutAt:data:",
  824. category: 'private',
  825. fn: function (aURL,aString){
  826. var self=this;
  827. return smalltalk.withContext(function($ctx1) {
  828. _st(jQuery)._ajax_options_(aURL,smalltalk.HashedCollection._from_(["type".__minus_gt("PUT"),"data".__minus_gt(aString),"contentType".__minus_gt("text/plain;charset=UTF-8"),"error".__minus_gt((function(xhr){
  829. return smalltalk.withContext(function($ctx2) {
  830. return self._error_(_st(_st(_st("Commiting ".__comma(aURL)).__comma(" failed with reason: \x22")).__comma(_st(xhr)._responseText())).__comma("\x22"));
  831. }, function($ctx2) {$ctx2.fillBlock({xhr:xhr},$ctx1)})}))]));
  832. return self}, function($ctx1) {$ctx1.fill(self,"ajaxPutAt:data:",{aURL:aURL,aString:aString},smalltalk.PackageHandler)})},
  833. args: ["aURL", "aString"],
  834. source: "ajaxPutAt: aURL data: aString\x0a\x09jQuery\x0a\x09\x09ajax: aURL \x0a\x09\x09options: #{ \x0a\x09\x09\x09'type' -> 'PUT'.\x0a\x09\x09\x09'data' -> aString.\x0a\x09\x09\x09'contentType' -> 'text/plain;charset=UTF-8'.\x0a\x09\x09\x09'error' -> [ :xhr | self error: 'Commiting ' , aURL , ' failed with reason: \x22' , (xhr responseText) , '\x22'] }",
  835. messageSends: ["ajax:options:", "->", "error:", ",", "responseText"],
  836. referencedClasses: []
  837. }),
  838. smalltalk.PackageHandler);
  839. smalltalk.addMethod(
  840. smalltalk.method({
  841. selector: "commit:",
  842. category: 'committing',
  843. fn: function (aPackage){
  844. var self=this;
  845. function $PluggableExporter(){return smalltalk.PluggableExporter||(typeof PluggableExporter=="undefined"?nil:PluggableExporter)}
  846. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  847. function $Exporter(){return smalltalk.Exporter||(typeof Exporter=="undefined"?nil:Exporter)}
  848. function $StrippedExporter(){return smalltalk.StrippedExporter||(typeof StrippedExporter=="undefined"?nil:StrippedExporter)}
  849. function $ChunkExporter(){return smalltalk.ChunkExporter||(typeof ChunkExporter=="undefined"?nil:ChunkExporter)}
  850. return smalltalk.withContext(function($ctx1) {
  851. _st([_st($Exporter()).__minus_gt(_st(_st(_st(_st(aPackage)._commitPathJs()).__comma("/")).__comma(_st(aPackage)._name())).__comma(".js")),_st($StrippedExporter()).__minus_gt(_st(_st(_st(_st(aPackage)._commitPathJs()).__comma("/")).__comma(_st(aPackage)._name())).__comma(".deploy.js")),_st($ChunkExporter()).__minus_gt(_st(_st(_st(_st(aPackage)._commitPathSt()).__comma("/")).__comma(_st(aPackage)._name())).__comma(".st"))])._do_displayingProgress_((function(commitStrategy){
  852. var fileContents;
  853. return smalltalk.withContext(function($ctx2) {
  854. fileContents=_st($String())._streamContents_((function(stream){
  855. return smalltalk.withContext(function($ctx3) {
  856. return _st(_st($PluggableExporter())._newUsing_(_st(_st(commitStrategy)._key())._recipe()))._exportPackage_on_(aPackage,stream);
  857. }, function($ctx3) {$ctx3.fillBlock({stream:stream},$ctx2)})}));
  858. fileContents;
  859. return self._ajaxPutAt_data_(_st(commitStrategy)._value(),fileContents);
  860. }, function($ctx2) {$ctx2.fillBlock({commitStrategy:commitStrategy,fileContents:fileContents},$ctx1)})}),"Committing package ".__comma(_st(aPackage)._name()));
  861. return self}, function($ctx1) {$ctx1.fill(self,"commit:",{aPackage:aPackage},smalltalk.PackageHandler)})},
  862. args: ["aPackage"],
  863. source: "commit: aPackage\x0a\x09{ \x0a\x09\x09Exporter -> (aPackage commitPathJs, '/', aPackage name, '.js').\x0a\x09\x09StrippedExporter -> (aPackage commitPathJs, '/', aPackage name, '.deploy.js').\x0a\x09\x09ChunkExporter -> (aPackage commitPathSt, '/', aPackage name, '.st')\x0a\x09} \x0a\x09\x09do: [ :commitStrategy|| fileContents |\x0a\x09\x09\x09fileContents := String streamContents: [ :stream |\x0a\x09\x09\x09\x09(PluggableExporter newUsing: commitStrategy key recipe) exportPackage: aPackage on: stream ].\x0a\x09\x09\x09self ajaxPutAt: commitStrategy value data: fileContents ]\x0a\x09\x09displayingProgress: 'Committing package ', aPackage name",
  864. messageSends: ["do:displayingProgress:", "streamContents:", "exportPackage:on:", "newUsing:", "recipe", "key", "ajaxPutAt:data:", "value", ",", "name", "->", "commitPathJs", "commitPathSt"],
  865. referencedClasses: ["PluggableExporter", "String", "Exporter", "StrippedExporter", "ChunkExporter"]
  866. }),
  867. smalltalk.PackageHandler);
  868. smalltalk.addMethod(
  869. smalltalk.method({
  870. selector: "loadPackage:prefix:",
  871. category: 'loading',
  872. fn: function (packageName,aString){
  873. var self=this;
  874. var url;
  875. return smalltalk.withContext(function($ctx1) {
  876. var $1;
  877. url=_st(_st(_st("/".__comma(aString)).__comma("/js/")).__comma(packageName)).__comma(".js");
  878. _st(jQuery)._ajax_options_(url,smalltalk.HashedCollection._from_(["type".__minus_gt("GET"),"dataType".__minus_gt("script"),"complete".__minus_gt((function(jqXHR,textStatus){
  879. return smalltalk.withContext(function($ctx2) {
  880. $1=_st(_st(jqXHR)._readyState()).__eq((4));
  881. if(smalltalk.assert($1)){
  882. return self._setupPackageNamed_prefix_(packageName,aString);
  883. };
  884. }, function($ctx2) {$ctx2.fillBlock({jqXHR:jqXHR,textStatus:textStatus},$ctx1)})})),"error".__minus_gt((function(){
  885. return smalltalk.withContext(function($ctx2) {
  886. return _st(window)._alert_("Could not load package at: ".__comma(url));
  887. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))]));
  888. return self}, function($ctx1) {$ctx1.fill(self,"loadPackage:prefix:",{packageName:packageName,aString:aString,url:url},smalltalk.PackageHandler)})},
  889. args: ["packageName", "aString"],
  890. source: "loadPackage: packageName prefix: aString\x0a\x09| url |\x0a\x09url := '/', aString, '/js/', packageName, '.js'.\x0a\x09jQuery\x0a\x09\x09ajax: url\x0a\x09\x09options: #{\x0a\x09\x09\x09'type' -> 'GET'.\x0a\x09\x09\x09'dataType' -> 'script'.\x0a\x09\x09\x09'complete' -> [ :jqXHR :textStatus |\x0a\x09\x09\x09\x09jqXHR readyState = 4\x0a\x09\x09\x09\x09\x09ifTrue: [ self setupPackageNamed: packageName prefix: aString ] ].\x0a\x09\x09\x09'error' -> [ window alert: 'Could not load package at: ', url ]\x0a\x09\x09}",
  891. messageSends: [",", "ajax:options:", "->", "ifTrue:", "setupPackageNamed:prefix:", "=", "readyState", "alert:"],
  892. referencedClasses: []
  893. }),
  894. smalltalk.PackageHandler);
  895. smalltalk.addMethod(
  896. smalltalk.method({
  897. selector: "loadPackages:prefix:",
  898. category: 'loading',
  899. fn: function (aCollection,aString){
  900. var self=this;
  901. return smalltalk.withContext(function($ctx1) {
  902. _st(aCollection)._do_((function(each){
  903. return smalltalk.withContext(function($ctx2) {
  904. return self._loadPackage_prefix_(each,aString);
  905. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  906. return self}, function($ctx1) {$ctx1.fill(self,"loadPackages:prefix:",{aCollection:aCollection,aString:aString},smalltalk.PackageHandler)})},
  907. args: ["aCollection", "aString"],
  908. source: "loadPackages: aCollection prefix: aString\x0a\x09aCollection do: [ :each |\x0a\x09\x09self loadPackage: each prefix: aString ]",
  909. messageSends: ["do:", "loadPackage:prefix:"],
  910. referencedClasses: []
  911. }),
  912. smalltalk.PackageHandler);
  913. smalltalk.addMethod(
  914. smalltalk.method({
  915. selector: "setupPackageNamed:prefix:",
  916. category: 'private',
  917. fn: function (packageName,aString){
  918. var self=this;
  919. function $Package(){return smalltalk.Package||(typeof Package=="undefined"?nil:Package)}
  920. return smalltalk.withContext(function($ctx1) {
  921. var $1,$2;
  922. $1=_st($Package())._named_(packageName);
  923. _st($1)._setupClasses();
  924. _st($1)._commitPathJs_(_st("/".__comma(aString)).__comma("/js"));
  925. $2=_st($1)._commitPathSt_(_st("/".__comma(aString)).__comma("/st"));
  926. return self}, function($ctx1) {$ctx1.fill(self,"setupPackageNamed:prefix:",{packageName:packageName,aString:aString},smalltalk.PackageHandler)})},
  927. args: ["packageName", "aString"],
  928. source: "setupPackageNamed: packageName prefix: aString\x0a\x0a\x09(Package named: packageName)\x0a\x09\x09setupClasses;\x0a\x09\x09commitPathJs: '/', aString, '/js';\x0a\x09\x09commitPathSt: '/', aString, '/st'",
  929. messageSends: ["setupClasses", "named:", "commitPathJs:", ",", "commitPathSt:"],
  930. referencedClasses: ["Package"]
  931. }),
  932. smalltalk.PackageHandler);
  933. smalltalk.addMethod(
  934. smalltalk.method({
  935. selector: "loadPackages:prefix:",
  936. category: 'loading',
  937. fn: function (aCollection,aString){
  938. var self=this;
  939. return smalltalk.withContext(function($ctx1) {
  940. var $1;
  941. $1=_st(self._new())._loadPackages_prefix_(aCollection,aString);
  942. return $1;
  943. }, function($ctx1) {$ctx1.fill(self,"loadPackages:prefix:",{aCollection:aCollection,aString:aString},smalltalk.PackageHandler.klass)})},
  944. args: ["aCollection", "aString"],
  945. source: "loadPackages: aCollection prefix: aString\x0a\x09^ self new loadPackages: aCollection prefix: aString",
  946. messageSends: ["loadPackages:prefix:", "new"],
  947. referencedClasses: []
  948. }),
  949. smalltalk.PackageHandler.klass);
  950. smalltalk.addClass('PluggableExporter', smalltalk.Object, ['recipe'], 'Importer-Exporter');
  951. smalltalk.addMethod(
  952. smalltalk.method({
  953. selector: "export:usingRecipe:on:",
  954. category: 'fileOut',
  955. fn: function (anObject,anArray,aStream){
  956. var self=this;
  957. var args;
  958. return smalltalk.withContext(function($ctx1) {
  959. var $1;
  960. args=[anObject,aStream];
  961. _st(anArray)._do_((function(each){
  962. var val;
  963. return smalltalk.withContext(function($ctx2) {
  964. val=_st(each)._value();
  965. val;
  966. $1=_st(val).__eq_eq(each);
  967. if(smalltalk.assert($1)){
  968. var selection;
  969. selection=_st(_st(_st(each)._first())._key())._perform_withArguments_(_st(_st(each)._first())._value(),[anObject]);
  970. selection;
  971. return _st(selection)._do_((function(eachPart){
  972. return smalltalk.withContext(function($ctx3) {
  973. return self._export_usingRecipe_on_(eachPart,_st(each)._allButFirst(),aStream);
  974. }, function($ctx3) {$ctx3.fillBlock({eachPart:eachPart},$ctx2)})}));
  975. } else {
  976. return _st(_st(each)._key())._perform_withArguments_(val,args);
  977. };
  978. }, function($ctx2) {$ctx2.fillBlock({each:each,val:val},$ctx1)})}));
  979. return self}, function($ctx1) {$ctx1.fill(self,"export:usingRecipe:on:",{anObject:anObject,anArray:anArray,aStream:aStream,args:args},smalltalk.PluggableExporter)})},
  980. args: ["anObject", "anArray", "aStream"],
  981. source: "export: anObject usingRecipe: anArray on: aStream\x0a\x09| args |\x0a\x09args := { anObject. aStream }.\x0a\x09anArray do: [ :each | | val |\x0a\x09\x09val := each value.\x0a\x09\x09val == each\x0a\x09\x09\x09ifFalse: [ \x22association\x22\x0a\x09\x09\x09\x09each key perform: val withArguments: args ]\x0a\x09\x09\x09ifTrue: [ \x22sub-array\x22\x0a\x09\x09\x09\x09| selection |\x0a\x09\x09\x09\x09selection := each first key perform: each first value withArguments: { anObject }.\x0a\x09\x09\x09\x09selection do: [ :eachPart |\x09self export: eachPart usingRecipe: each allButFirst on: aStream ]]]",
  982. messageSends: ["do:", "value", "ifFalse:ifTrue:", "perform:withArguments:", "key", "first", "export:usingRecipe:on:", "allButFirst", "=="],
  983. referencedClasses: []
  984. }),
  985. smalltalk.PluggableExporter);
  986. smalltalk.addMethod(
  987. smalltalk.method({
  988. selector: "exportAll",
  989. category: 'fileOut',
  990. fn: function (){
  991. var self=this;
  992. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  993. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  994. return smalltalk.withContext(function($ctx1) {
  995. var $1;
  996. $1=_st($String())._streamContents_((function(stream){
  997. return smalltalk.withContext(function($ctx2) {
  998. return _st(_st(_st($Smalltalk())._current())._packages())._do_((function(pkg){
  999. return smalltalk.withContext(function($ctx3) {
  1000. return self._exportPackage_on_(pkg,stream);
  1001. }, function($ctx3) {$ctx3.fillBlock({pkg:pkg},$ctx2)})}));
  1002. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1)})}));
  1003. return $1;
  1004. }, function($ctx1) {$ctx1.fill(self,"exportAll",{},smalltalk.PluggableExporter)})},
  1005. args: [],
  1006. source: "exportAll\x0a\x09\x22Export all packages in the system.\x22\x0a\x0a\x09^String streamContents: [:stream |\x0a\x09\x09Smalltalk current packages do: [:pkg |\x0a\x09\x09self exportPackage: pkg on: stream]]",
  1007. messageSends: ["streamContents:", "do:", "exportPackage:on:", "packages", "current"],
  1008. referencedClasses: ["Smalltalk", "String"]
  1009. }),
  1010. smalltalk.PluggableExporter);
  1011. smalltalk.addMethod(
  1012. smalltalk.method({
  1013. selector: "exportPackage:on:",
  1014. category: 'fileOut',
  1015. fn: function (aPackage,aStream){
  1016. var self=this;
  1017. return smalltalk.withContext(function($ctx1) {
  1018. self._export_usingRecipe_on_(aPackage,self._recipe(),aStream);
  1019. return self}, function($ctx1) {$ctx1.fill(self,"exportPackage:on:",{aPackage:aPackage,aStream:aStream},smalltalk.PluggableExporter)})},
  1020. args: ["aPackage", "aStream"],
  1021. source: "exportPackage: aPackage on: aStream\x0a\x09self export: aPackage usingRecipe: self recipe on: aStream",
  1022. messageSends: ["export:usingRecipe:on:", "recipe"],
  1023. referencedClasses: []
  1024. }),
  1025. smalltalk.PluggableExporter);
  1026. smalltalk.addMethod(
  1027. smalltalk.method({
  1028. selector: "recipe",
  1029. category: 'accessing',
  1030. fn: function (){
  1031. var self=this;
  1032. return smalltalk.withContext(function($ctx1) {
  1033. var $1;
  1034. $1=self["@recipe"];
  1035. return $1;
  1036. }, function($ctx1) {$ctx1.fill(self,"recipe",{},smalltalk.PluggableExporter)})},
  1037. args: [],
  1038. source: "recipe\x0a\x09^recipe",
  1039. messageSends: [],
  1040. referencedClasses: []
  1041. }),
  1042. smalltalk.PluggableExporter);
  1043. smalltalk.addMethod(
  1044. smalltalk.method({
  1045. selector: "recipe:",
  1046. category: 'accessing',
  1047. fn: function (anArray){
  1048. var self=this;
  1049. return smalltalk.withContext(function($ctx1) {
  1050. self["@recipe"]=anArray;
  1051. return self}, function($ctx1) {$ctx1.fill(self,"recipe:",{anArray:anArray},smalltalk.PluggableExporter)})},
  1052. args: ["anArray"],
  1053. source: "recipe: anArray\x0a\x09recipe := anArray",
  1054. messageSends: [],
  1055. referencedClasses: []
  1056. }),
  1057. smalltalk.PluggableExporter);
  1058. smalltalk.addMethod(
  1059. smalltalk.method({
  1060. selector: "newUsing:",
  1061. category: 'exporting-accessing',
  1062. fn: function (recipe){
  1063. var self=this;
  1064. return smalltalk.withContext(function($ctx1) {
  1065. var $2,$3,$1;
  1066. $2=self._new();
  1067. _st($2)._recipe_(recipe);
  1068. $3=_st($2)._yourself();
  1069. $1=$3;
  1070. return $1;
  1071. }, function($ctx1) {$ctx1.fill(self,"newUsing:",{recipe:recipe},smalltalk.PluggableExporter.klass)})},
  1072. args: ["recipe"],
  1073. source: "newUsing: recipe\x0a\x09^self new recipe: recipe; yourself",
  1074. messageSends: ["recipe:", "new", "yourself"],
  1075. referencedClasses: []
  1076. }),
  1077. smalltalk.PluggableExporter.klass);
  1078. smalltalk.addMethod(
  1079. smalltalk.method({
  1080. selector: "ownClassesOfPackage:",
  1081. category: 'exporting-accessing',
  1082. fn: function (package_){
  1083. var self=this;
  1084. return smalltalk.withContext(function($ctx1) {
  1085. var $1;
  1086. $1=_st(_st(package_)._sortedClasses())._asSet();
  1087. return $1;
  1088. }, function($ctx1) {$ctx1.fill(self,"ownClassesOfPackage:",{package_:package_},smalltalk.PluggableExporter.klass)})},
  1089. args: ["package"],
  1090. source: "ownClassesOfPackage: package\x0a\x09\x22Export classes in dependency order.\x0a\x09Update (issue #171): Remove duplicates for export\x22\x0a\x09^package sortedClasses asSet",
  1091. messageSends: ["asSet", "sortedClasses"],
  1092. referencedClasses: []
  1093. }),
  1094. smalltalk.PluggableExporter.klass);
  1095. smalltalk.addMethod(
  1096. smalltalk.method({
  1097. selector: "commit",
  1098. category: '*Importer-Exporter',
  1099. fn: function (){
  1100. var self=this;
  1101. function $PackageHandler(){return smalltalk.PackageHandler||(typeof PackageHandler=="undefined"?nil:PackageHandler)}
  1102. return smalltalk.withContext(function($ctx1) {
  1103. var $1;
  1104. $1=_st(_st($PackageHandler())._new())._commit_(self);
  1105. return $1;
  1106. }, function($ctx1) {$ctx1.fill(self,"commit",{},smalltalk.Package)})},
  1107. args: [],
  1108. source: "commit\x0a\x09^ PackageHandler new commit: self",
  1109. messageSends: ["commit:", "new"],
  1110. referencedClasses: ["PackageHandler"]
  1111. }),
  1112. smalltalk.Package);
  1113. })(global_smalltalk,global_nil,global__st);