Importer-Exporter.js 60 KB

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