2
0

Importer-Exporter.js 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851
  1. (function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Importer-Exporter');
  3. smalltalk.addClass('AbstractExporter', smalltalk.Object, [], 'Importer-Exporter');
  4. smalltalk.AbstractExporter.comment="I am an abstract exporter for Amber source code.";
  5. smalltalk.addMethod(
  6. smalltalk.method({
  7. selector: "chunkEscape:",
  8. category: 'convenience',
  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.AbstractExporter)})},
  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.AbstractExporter);
  22. smalltalk.addMethod(
  23. smalltalk.method({
  24. selector: "classNameFor:",
  25. category: 'convenience',
  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.AbstractExporter)})},
  43. args: ["aClass"],
  44. source: "classNameFor: aClass\x0a\x09^aClass isMetaclass\x0a\x09\x09ifTrue: [ aClass instanceClass name, ' class' ]\x0a\x09\x09ifFalse: [\x0a\x09\x09\x09aClass isNil\x0a\x09\x09\x09\x09ifTrue: [ 'nil' ]\x0a\x09\x09\x09\x09ifFalse: [ aClass name ] ]",
  45. messageSends: ["ifTrue:ifFalse:", ",", "name", "instanceClass", "isNil", "isMetaclass"],
  46. referencedClasses: []
  47. }),
  48. smalltalk.AbstractExporter);
  49. smalltalk.addMethod(
  50. smalltalk.method({
  51. selector: "recipe",
  52. category: 'fileOut',
  53. fn: function (){
  54. var self=this;
  55. return smalltalk.withContext(function($ctx1) {
  56. self._subclassResponsibility();
  57. return self}, function($ctx1) {$ctx1.fill(self,"recipe",{},smalltalk.AbstractExporter)})},
  58. args: [],
  59. source: "recipe\x0a\x09\x22Recipe to export a given package.\x22\x0a\x0a\x09self subclassResponsibility",
  60. messageSends: ["subclassResponsibility"],
  61. referencedClasses: []
  62. }),
  63. smalltalk.AbstractExporter);
  64. smalltalk.AbstractExporter.klass.iVarNames = ['default'];
  65. smalltalk.addMethod(
  66. smalltalk.method({
  67. selector: "default",
  68. category: 'instance creation',
  69. fn: function (){
  70. var self=this;
  71. return smalltalk.withContext(function($ctx1) {
  72. var $2,$1;
  73. $2=self["@default"];
  74. if(($receiver = $2) == nil || $receiver == undefined){
  75. self["@default"]=self._new();
  76. $1=self["@default"];
  77. } else {
  78. $1=$2;
  79. };
  80. return $1;
  81. }, function($ctx1) {$ctx1.fill(self,"default",{},smalltalk.AbstractExporter.klass)})},
  82. args: [],
  83. source: "default\x0a\x09^ default ifNil: [ default := self new ]",
  84. messageSends: ["ifNil:", "new"],
  85. referencedClasses: []
  86. }),
  87. smalltalk.AbstractExporter.klass);
  88. smalltalk.addClass('ChunkExporter', smalltalk.AbstractExporter, [], 'Importer-Exporter');
  89. 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.";
  90. smalltalk.addMethod(
  91. smalltalk.method({
  92. selector: "exportCategoryEpilogueOf:on:",
  93. category: 'output',
  94. fn: function (aCategory,aStream){
  95. var self=this;
  96. return smalltalk.withContext(function($ctx1) {
  97. var $1,$2;
  98. $1=aStream;
  99. _st($1)._nextPutAll_(" !");
  100. _st($1)._lf();
  101. $2=_st($1)._lf();
  102. return self}, function($ctx1) {$ctx1.fill(self,"exportCategoryEpilogueOf:on:",{aCategory:aCategory,aStream:aStream},smalltalk.ChunkExporter)})},
  103. args: ["aCategory", "aStream"],
  104. source: "exportCategoryEpilogueOf: aCategory on: aStream\x0a\x09aStream nextPutAll: ' !'; lf; lf",
  105. messageSends: ["nextPutAll:", "lf"],
  106. referencedClasses: []
  107. }),
  108. smalltalk.ChunkExporter);
  109. smalltalk.addMethod(
  110. smalltalk.method({
  111. selector: "exportCategoryPrologueOf:on:",
  112. category: 'output',
  113. fn: function (aCategory,aStream){
  114. var self=this;
  115. return smalltalk.withContext(function($ctx1) {
  116. var $1,$2;
  117. $1=aStream;
  118. _st($1)._nextPutAll_("!".__comma(self._classNameFor_(_st(aCategory)._theClass())));
  119. $2=_st($1)._nextPutAll_(_st(" methodsFor: '".__comma(_st(aCategory)._name())).__comma("'!"));
  120. return self}, function($ctx1) {$ctx1.fill(self,"exportCategoryPrologueOf:on:",{aCategory:aCategory,aStream:aStream},smalltalk.ChunkExporter)})},
  121. args: ["aCategory", "aStream"],
  122. source: "exportCategoryPrologueOf: aCategory on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '!', (self classNameFor: aCategory theClass);\x0a\x09\x09nextPutAll: ' methodsFor: ''', aCategory name, '''!'",
  123. messageSends: ["nextPutAll:", ",", "classNameFor:", "theClass", "name"],
  124. referencedClasses: []
  125. }),
  126. smalltalk.ChunkExporter);
  127. smalltalk.addMethod(
  128. smalltalk.method({
  129. selector: "exportDefinitionOf:on:",
  130. category: 'output',
  131. fn: function (aClass,aStream){
  132. var self=this;
  133. return smalltalk.withContext(function($ctx1) {
  134. var $1,$2,$3,$4,$5,$6,$7;
  135. $1=aStream;
  136. _st($1)._nextPutAll_(self._classNameFor_(_st(aClass)._superclass()));
  137. _st($1)._nextPutAll_(" subclass: #".__comma(self._classNameFor_(aClass)));
  138. _st($1)._lf();
  139. _st($1)._tab();
  140. $2=_st($1)._nextPutAll_("instanceVariableNames: '");
  141. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  142. return smalltalk.withContext(function($ctx2) {
  143. return _st(aStream)._nextPutAll_(each);
  144. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  145. return smalltalk.withContext(function($ctx2) {
  146. return _st(aStream)._nextPutAll_(" ");
  147. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  148. $3=aStream;
  149. _st($3)._nextPutAll_("'");
  150. _st($3)._lf();
  151. _st($3)._tab();
  152. _st($3)._nextPutAll_(_st("package: '".__comma(_st(aClass)._category())).__comma("'!"));
  153. $4=_st($3)._lf();
  154. $5=_st(_st(aClass)._comment())._notEmpty();
  155. if(smalltalk.assert($5)){
  156. $6=aStream;
  157. _st($6)._nextPutAll_(_st("!".__comma(self._classNameFor_(aClass))).__comma(" commentStamp!"));
  158. _st($6)._lf();
  159. _st($6)._nextPutAll_(_st(self._chunkEscape_(_st(aClass)._comment())).__comma("!"));
  160. $7=_st($6)._lf();
  161. $7;
  162. };
  163. _st(aStream)._lf();
  164. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.ChunkExporter)})},
  165. args: ["aClass", "aStream"],
  166. 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",
  167. messageSends: ["nextPutAll:", "classNameFor:", "superclass", ",", "lf", "tab", "do:separatedBy:", "instanceVariableNames", "category", "ifTrue:", "chunkEscape:", "comment", "notEmpty"],
  168. referencedClasses: []
  169. }),
  170. smalltalk.ChunkExporter);
  171. smalltalk.addMethod(
  172. smalltalk.method({
  173. selector: "exportMetaDefinitionOf:on:",
  174. category: 'output',
  175. fn: function (aClass,aStream){
  176. var self=this;
  177. return smalltalk.withContext(function($ctx1) {
  178. var $1,$2,$3,$4,$5;
  179. $1=_st(_st(_st(aClass)._class())._instanceVariableNames())._isEmpty();
  180. if(! smalltalk.assert($1)){
  181. $2=aStream;
  182. _st($2)._nextPutAll_(self._classNameFor_(_st(aClass)._class()));
  183. $3=_st($2)._nextPutAll_(" instanceVariableNames: '");
  184. $3;
  185. _st(_st(_st(aClass)._class())._instanceVariableNames())._do_separatedBy_((function(each){
  186. return smalltalk.withContext(function($ctx2) {
  187. return _st(aStream)._nextPutAll_(each);
  188. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  189. return smalltalk.withContext(function($ctx2) {
  190. return _st(aStream)._nextPutAll_(" ");
  191. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  192. $4=aStream;
  193. _st($4)._nextPutAll_("'!");
  194. _st($4)._lf();
  195. $5=_st($4)._lf();
  196. $5;
  197. };
  198. return self}, function($ctx1) {$ctx1.fill(self,"exportMetaDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.ChunkExporter)})},
  199. args: ["aClass", "aStream"],
  200. 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]",
  201. messageSends: ["ifFalse:", "nextPutAll:", "classNameFor:", "class", "do:separatedBy:", "instanceVariableNames", "lf", "isEmpty"],
  202. referencedClasses: []
  203. }),
  204. smalltalk.ChunkExporter);
  205. smalltalk.addMethod(
  206. smalltalk.method({
  207. selector: "exportMethod:on:",
  208. category: 'output',
  209. fn: function (aMethod,aStream){
  210. var self=this;
  211. return smalltalk.withContext(function($ctx1) {
  212. var $1,$2;
  213. $1=aStream;
  214. _st($1)._lf();
  215. _st($1)._lf();
  216. _st($1)._nextPutAll_(self._chunkEscape_(_st(aMethod)._source()));
  217. _st($1)._lf();
  218. $2=_st($1)._nextPutAll_("!");
  219. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:on:",{aMethod:aMethod,aStream:aStream},smalltalk.ChunkExporter)})},
  220. args: ["aMethod", "aStream"],
  221. source: "exportMethod: aMethod on: aStream\x0a\x09aStream\x0a\x09\x09lf; lf; nextPutAll: (self chunkEscape: aMethod source); lf;\x0a\x09\x09nextPutAll: '!'",
  222. messageSends: ["lf", "nextPutAll:", "chunkEscape:", "source"],
  223. referencedClasses: []
  224. }),
  225. smalltalk.ChunkExporter);
  226. smalltalk.addMethod(
  227. smalltalk.method({
  228. selector: "exportPackageDefinitionOf:on:",
  229. category: 'output',
  230. fn: function (aPackage,aStream){
  231. var self=this;
  232. return smalltalk.withContext(function($ctx1) {
  233. var $1,$2;
  234. $1=aStream;
  235. _st($1)._nextPutAll_(_st("Smalltalk current createPackage: '".__comma(_st(aPackage)._name())).__comma("'!"));
  236. $2=_st($1)._lf();
  237. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageDefinitionOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.ChunkExporter)})},
  238. args: ["aPackage", "aStream"],
  239. source: "exportPackageDefinitionOf: aPackage on: aStream\x0a\x09\x22Chunk format.\x22\x0a\x0a\x09aStream\x0a\x09\x09nextPutAll: 'Smalltalk current createPackage: ''', aPackage name, '''!';\x0a\x09\x09lf",
  240. messageSends: ["nextPutAll:", ",", "name", "lf"],
  241. referencedClasses: []
  242. }),
  243. smalltalk.ChunkExporter);
  244. smalltalk.addMethod(
  245. smalltalk.method({
  246. selector: "extensionCategoriesOfPackage:",
  247. category: 'accessing',
  248. fn: function (aPackage){
  249. var self=this;
  250. var name,map,result;
  251. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  252. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  253. function $MethodCategory(){return smalltalk.MethodCategory||(typeof MethodCategory=="undefined"?nil:MethodCategory)}
  254. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  255. function $Package(){return smalltalk.Package||(typeof Package=="undefined"?nil:Package)}
  256. return smalltalk.withContext(function($ctx1) {
  257. var $1,$2;
  258. name=_st(aPackage)._name();
  259. result=_st($OrderedCollection())._new();
  260. _st(_st($Package())._sortedClasses_(_st(_st($Smalltalk())._current())._classes()))._do_((function(each){
  261. return smalltalk.withContext(function($ctx2) {
  262. return _st([each,_st(each)._class()])._do_((function(aClass){
  263. return smalltalk.withContext(function($ctx3) {
  264. map=_st($Dictionary())._new();
  265. map;
  266. _st(aClass)._protocolsDo_((function(category,methods){
  267. return smalltalk.withContext(function($ctx4) {
  268. $1=_st(category).__eq("*".__comma(name));
  269. if(smalltalk.assert($1)){
  270. return _st(map)._at_put_(category,methods);
  271. };
  272. }, function($ctx4) {$ctx4.fillBlock({category:category,methods:methods},$ctx3)})}));
  273. return _st(result)._addAll_(_st(_st(_st(map)._keys())._sorted_((function(a,b){
  274. return smalltalk.withContext(function($ctx4) {
  275. return _st(a).__lt_eq(b);
  276. }, function($ctx4) {$ctx4.fillBlock({a:a,b:b},$ctx3)})})))._collect_((function(category){
  277. return smalltalk.withContext(function($ctx4) {
  278. return _st($MethodCategory())._name_theClass_methods_(category,aClass,_st(map)._at_(category));
  279. }, function($ctx4) {$ctx4.fillBlock({category:category},$ctx3)})})));
  280. }, function($ctx3) {$ctx3.fillBlock({aClass:aClass},$ctx2)})}));
  281. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  282. $2=result;
  283. return $2;
  284. }, function($ctx1) {$ctx1.fill(self,"extensionCategoriesOfPackage:",{aPackage:aPackage,name:name,map:map,result:result},smalltalk.ChunkExporter)})},
  285. args: ["aPackage"],
  286. source: "extensionCategoriesOfPackage: aPackage\x0a\x09\x22Issue #143: sort protocol alphabetically\x22\x0a\x0a\x09| name map result |\x0a\x09name := aPackage 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\x09category = ('*', 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\x09MethodCategory name: category theClass: aClass methods: (map at: category)]) ]].\x0a\x09^result",
  287. messageSends: ["name", "new", "do:", "protocolsDo:", "ifTrue:", "at:put:", "=", ",", "addAll:", "collect:", "name:theClass:methods:", "at:", "sorted:", "<=", "keys", "class", "sortedClasses:", "classes", "current"],
  288. referencedClasses: ["OrderedCollection", "Dictionary", "MethodCategory", "Smalltalk", "Package"]
  289. }),
  290. smalltalk.ChunkExporter);
  291. smalltalk.addMethod(
  292. smalltalk.method({
  293. selector: "methodsOfCategory:",
  294. category: 'accessing',
  295. fn: function (aCategory){
  296. var self=this;
  297. return smalltalk.withContext(function($ctx1) {
  298. var $1;
  299. $1=_st(_st(aCategory)._methods())._sorted_((function(a,b){
  300. return smalltalk.withContext(function($ctx2) {
  301. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  302. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})}));
  303. return $1;
  304. }, function($ctx1) {$ctx1.fill(self,"methodsOfCategory:",{aCategory:aCategory},smalltalk.ChunkExporter)})},
  305. args: ["aCategory"],
  306. source: "methodsOfCategory: aCategory\x0a\x09\x22Issue #143: sort methods alphabetically\x22\x0a\x0a\x09^(aCategory methods) sorted: [:a :b | a selector <= b selector]",
  307. messageSends: ["sorted:", "<=", "selector", "methods"],
  308. referencedClasses: []
  309. }),
  310. smalltalk.ChunkExporter);
  311. smalltalk.addMethod(
  312. smalltalk.method({
  313. selector: "ownCategoriesOfClass:",
  314. category: 'accessing',
  315. fn: function (aClass){
  316. var self=this;
  317. var map;
  318. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  319. function $MethodCategory(){return smalltalk.MethodCategory||(typeof MethodCategory=="undefined"?nil:MethodCategory)}
  320. return smalltalk.withContext(function($ctx1) {
  321. var $1,$2;
  322. map=_st($Dictionary())._new();
  323. _st(aClass)._protocolsDo_((function(category,methods){
  324. return smalltalk.withContext(function($ctx2) {
  325. $1=_st(category)._match_("^\x5c*");
  326. if(! smalltalk.assert($1)){
  327. return _st(map)._at_put_(category,methods);
  328. };
  329. }, function($ctx2) {$ctx2.fillBlock({category:category,methods:methods},$ctx1)})}));
  330. $2=_st(_st(_st(map)._keys())._sorted_((function(a,b){
  331. return smalltalk.withContext(function($ctx2) {
  332. return _st(a).__lt_eq(b);
  333. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})})))._collect_((function(category){
  334. return smalltalk.withContext(function($ctx2) {
  335. return _st($MethodCategory())._name_theClass_methods_(category,aClass,_st(map)._at_(category));
  336. }, function($ctx2) {$ctx2.fillBlock({category:category},$ctx1)})}));
  337. return $2;
  338. }, function($ctx1) {$ctx1.fill(self,"ownCategoriesOfClass:",{aClass:aClass,map:map},smalltalk.ChunkExporter)})},
  339. args: ["aClass"],
  340. source: "ownCategoriesOfClass: aClass\x0a\x09\x22Answer the protocols of aClassthat are not package extensions\x22\x0a\x09\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\x09MethodCategory name: category theClass: aClass methods: (map at: category) ]",
  341. messageSends: ["new", "protocolsDo:", "ifFalse:", "at:put:", "match:", "collect:", "name:theClass:methods:", "at:", "sorted:", "<=", "keys"],
  342. referencedClasses: ["Dictionary", "MethodCategory"]
  343. }),
  344. smalltalk.ChunkExporter);
  345. smalltalk.addMethod(
  346. smalltalk.method({
  347. selector: "ownCategoriesOfMetaClass:",
  348. category: 'accessing',
  349. fn: function (aClass){
  350. var self=this;
  351. return smalltalk.withContext(function($ctx1) {
  352. var $1;
  353. $1=self._ownCategoriesOfClass_(_st(aClass)._class());
  354. return $1;
  355. }, function($ctx1) {$ctx1.fill(self,"ownCategoriesOfMetaClass:",{aClass:aClass},smalltalk.ChunkExporter)})},
  356. args: ["aClass"],
  357. source: "ownCategoriesOfMetaClass: aClass\x0a\x09\x22Issue #143: sort protocol alphabetically\x22\x0a\x0a\x09^self ownCategoriesOfClass: aClass class",
  358. messageSends: ["ownCategoriesOfClass:", "class"],
  359. referencedClasses: []
  360. }),
  361. smalltalk.ChunkExporter);
  362. smalltalk.addMethod(
  363. smalltalk.method({
  364. selector: "recipe",
  365. category: 'fileOut',
  366. fn: function (){
  367. var self=this;
  368. var exportCategoryRecipe;
  369. function $PluggableExporter(){return smalltalk.PluggableExporter||(typeof PluggableExporter=="undefined"?nil:PluggableExporter)}
  370. return smalltalk.withContext(function($ctx1) {
  371. var $1;
  372. exportCategoryRecipe=[self.__minus_gt("exportCategoryPrologueOf:on:"),[self.__minus_gt("methodsOfCategory:"),self.__minus_gt("exportMethod:on:")],self.__minus_gt("exportCategoryEpilogueOf:on:")];
  373. $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)];
  374. return $1;
  375. }, function($ctx1) {$ctx1.fill(self,"recipe",{exportCategoryRecipe:exportCategoryRecipe},smalltalk.ChunkExporter)})},
  376. args: [],
  377. 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}",
  378. messageSends: ["->", ","],
  379. referencedClasses: ["PluggableExporter"]
  380. }),
  381. smalltalk.ChunkExporter);
  382. smalltalk.addClass('Exporter', smalltalk.AbstractExporter, [], 'Importer-Exporter');
  383. 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.";
  384. smalltalk.addMethod(
  385. smalltalk.method({
  386. selector: "classNameFor:",
  387. category: 'convenience',
  388. fn: function (aClass){
  389. var self=this;
  390. return smalltalk.withContext(function($ctx1) {
  391. var $2,$3,$1;
  392. $2=_st(aClass)._isMetaclass();
  393. if(smalltalk.assert($2)){
  394. $1=_st(_st(_st(aClass)._instanceClass())._name()).__comma(".klass");
  395. } else {
  396. $3=_st(aClass)._isNil();
  397. if(smalltalk.assert($3)){
  398. $1="nil";
  399. } else {
  400. $1=_st(aClass)._name();
  401. };
  402. };
  403. return $1;
  404. }, function($ctx1) {$ctx1.fill(self,"classNameFor:",{aClass:aClass},smalltalk.Exporter)})},
  405. args: ["aClass"],
  406. source: "classNameFor: aClass\x0a\x09^aClass isMetaclass\x0a\x09\x09ifTrue: [ aClass instanceClass name, '.klass' ]\x0a\x09\x09ifFalse: [\x0a\x09\x09\x09aClass isNil\x0a\x09\x09\x09\x09ifTrue: [ 'nil' ]\x0a\x09\x09\x09\x09ifFalse: [ aClass name ] ]",
  407. messageSends: ["ifTrue:ifFalse:", ",", "name", "instanceClass", "isNil", "isMetaclass"],
  408. referencedClasses: []
  409. }),
  410. smalltalk.Exporter);
  411. smalltalk.addMethod(
  412. smalltalk.method({
  413. selector: "exportDefinitionOf:on:",
  414. category: 'output',
  415. fn: function (aClass,aStream){
  416. var self=this;
  417. return smalltalk.withContext(function($ctx1) {
  418. var $1,$2,$3,$4,$5,$6,$7;
  419. $1=aStream;
  420. _st($1)._lf();
  421. _st($1)._nextPutAll_("smalltalk.addClass(");
  422. _st($1)._nextPutAll_(_st("'".__comma(self._classNameFor_(aClass))).__comma("', "));
  423. _st($1)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aClass)._superclass())));
  424. $2=_st($1)._nextPutAll_(", [");
  425. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  426. return smalltalk.withContext(function($ctx2) {
  427. return _st(aStream)._nextPutAll_(_st("'".__comma(each)).__comma("'"));
  428. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  429. return smalltalk.withContext(function($ctx2) {
  430. return _st(aStream)._nextPutAll_(", ");
  431. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  432. $3=aStream;
  433. _st($3)._nextPutAll_("], '");
  434. _st($3)._nextPutAll_(_st(_st(aClass)._category()).__comma("'"));
  435. $4=_st($3)._nextPutAll_(");");
  436. $5=_st(_st(aClass)._comment())._notEmpty();
  437. if(smalltalk.assert($5)){
  438. $6=aStream;
  439. _st($6)._lf();
  440. _st($6)._nextPutAll_("smalltalk.");
  441. _st($6)._nextPutAll_(self._classNameFor_(aClass));
  442. _st($6)._nextPutAll_(".comment=");
  443. _st($6)._nextPutAll_(_st(_st(aClass)._comment())._asJavascript());
  444. $7=_st($6)._nextPutAll_(";");
  445. $7;
  446. };
  447. _st(aStream)._lf();
  448. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.Exporter)})},
  449. args: ["aClass", "aStream"],
  450. 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",
  451. messageSends: ["lf", "nextPutAll:", ",", "classNameFor:", "superclass", "do:separatedBy:", "instanceVariableNames", "category", "ifTrue:", "asJavascript", "comment", "notEmpty"],
  452. referencedClasses: []
  453. }),
  454. smalltalk.Exporter);
  455. smalltalk.addMethod(
  456. smalltalk.method({
  457. selector: "exportMetaDefinitionOf:on:",
  458. category: 'output',
  459. fn: function (aClass,aStream){
  460. var self=this;
  461. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  462. return smalltalk.withContext(function($ctx1) {
  463. var $1,$2,$3;
  464. _st(aStream)._lf();
  465. $1=_st(_st(_st(aClass)._class())._instanceVariableNames())._isEmpty();
  466. if(! smalltalk.assert($1)){
  467. $2=aStream;
  468. _st($2)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aClass)._class())));
  469. $3=_st($2)._nextPutAll_(".iVarNames = [");
  470. $3;
  471. _st(_st(_st(aClass)._class())._instanceVariableNames())._do_separatedBy_((function(each){
  472. return smalltalk.withContext(function($ctx2) {
  473. return _st(aStream)._nextPutAll_(_st("'".__comma(each)).__comma("'"));
  474. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  475. return smalltalk.withContext(function($ctx2) {
  476. return _st(aStream)._nextPutAll_(",");
  477. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  478. _st(aStream)._nextPutAll_("];".__comma(_st($String())._lf()));
  479. };
  480. return self}, function($ctx1) {$ctx1.fill(self,"exportMetaDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.Exporter)})},
  481. args: ["aClass", "aStream"],
  482. 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]",
  483. messageSends: ["lf", "ifFalse:", "nextPutAll:", ",", "classNameFor:", "class", "do:separatedBy:", "instanceVariableNames", "isEmpty"],
  484. referencedClasses: ["String"]
  485. }),
  486. smalltalk.Exporter);
  487. smalltalk.addMethod(
  488. smalltalk.method({
  489. selector: "exportMethod:on:",
  490. category: 'output',
  491. fn: function (aMethod,aStream){
  492. var self=this;
  493. return smalltalk.withContext(function($ctx1) {
  494. var $1,$2,$3,$4;
  495. $1=aStream;
  496. _st($1)._nextPutAll_("smalltalk.addMethod(");
  497. _st($1)._lf();
  498. _st($1)._nextPutAll_("smalltalk.method({");
  499. _st($1)._lf();
  500. _st($1)._nextPutAll_(_st("selector: ".__comma(_st(_st(aMethod)._selector())._asJavascript())).__comma(","));
  501. _st($1)._lf();
  502. _st($1)._nextPutAll_(_st("category: '".__comma(_st(aMethod)._category())).__comma("',"));
  503. _st($1)._lf();
  504. _st($1)._nextPutAll_(_st("fn: ".__comma(_st(_st(aMethod)._fn())._compiledSource())).__comma(","));
  505. _st($1)._lf();
  506. _st($1)._nextPutAll_(_st("args: ".__comma(_st(_st(aMethod)._arguments())._asJavascript())).__comma(","));
  507. _st($1)._lf();
  508. _st($1)._nextPutAll_(_st("source: ".__comma(_st(_st(aMethod)._source())._asJavascript())).__comma(","));
  509. _st($1)._lf();
  510. _st($1)._nextPutAll_(_st("messageSends: ".__comma(_st(_st(aMethod)._messageSends())._asJavascript())).__comma(","));
  511. _st($1)._lf();
  512. $2=_st($1)._nextPutAll_("referencedClasses: ".__comma(_st(_st(aMethod)._referencedClasses())._asJavascript()));
  513. $3=aStream;
  514. _st($3)._lf();
  515. _st($3)._nextPutAll_("}),");
  516. _st($3)._lf();
  517. _st($3)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aMethod)._methodClass())));
  518. _st($3)._nextPutAll_(");");
  519. _st($3)._lf();
  520. $4=_st($3)._lf();
  521. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:on:",{aMethod:aMethod,aStream:aStream},smalltalk.Exporter)})},
  522. args: ["aMethod", "aStream"],
  523. 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",
  524. messageSends: ["nextPutAll:", "lf", ",", "asJavascript", "selector", "category", "compiledSource", "fn", "arguments", "source", "messageSends", "referencedClasses", "classNameFor:", "methodClass"],
  525. referencedClasses: []
  526. }),
  527. smalltalk.Exporter);
  528. smalltalk.addMethod(
  529. smalltalk.method({
  530. selector: "exportPackageDefinitionOf:on:",
  531. category: 'output',
  532. fn: function (aPackage,aStream){
  533. var self=this;
  534. return smalltalk.withContext(function($ctx1) {
  535. var $1,$2;
  536. $1=aStream;
  537. _st($1)._nextPutAll_("smalltalk.addPackage(");
  538. _st($1)._nextPutAll_(_st("'".__comma(_st(aPackage)._name())).__comma("');"));
  539. $2=_st($1)._lf();
  540. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageDefinitionOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.Exporter)})},
  541. args: ["aPackage", "aStream"],
  542. source: "exportPackageDefinitionOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: 'smalltalk.addPackage(';\x0a\x09\x09nextPutAll: '''', aPackage name, ''');';\x0a\x09\x09lf",
  543. messageSends: ["nextPutAll:", ",", "name", "lf"],
  544. referencedClasses: []
  545. }),
  546. smalltalk.Exporter);
  547. smalltalk.addMethod(
  548. smalltalk.method({
  549. selector: "exportPackageEpilogueOf:on:",
  550. category: 'output',
  551. fn: function (aPackage,aStream){
  552. var self=this;
  553. return smalltalk.withContext(function($ctx1) {
  554. var $1,$2;
  555. $1=aStream;
  556. _st($1)._nextPutAll_("})(global_smalltalk,global_nil,global__st);");
  557. $2=_st($1)._lf();
  558. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageEpilogueOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.Exporter)})},
  559. args: ["aPackage", "aStream"],
  560. source: "exportPackageEpilogueOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '})(global_smalltalk,global_nil,global__st);';\x0a\x09\x09lf",
  561. messageSends: ["nextPutAll:", "lf"],
  562. referencedClasses: []
  563. }),
  564. smalltalk.Exporter);
  565. smalltalk.addMethod(
  566. smalltalk.method({
  567. selector: "exportPackagePrologueOf:on:",
  568. category: 'output',
  569. fn: function (aPackage,aStream){
  570. var self=this;
  571. return smalltalk.withContext(function($ctx1) {
  572. var $1,$2;
  573. $1=aStream;
  574. _st($1)._nextPutAll_("(function(smalltalk,nil,_st){");
  575. $2=_st($1)._lf();
  576. return self}, function($ctx1) {$ctx1.fill(self,"exportPackagePrologueOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.Exporter)})},
  577. args: ["aPackage", "aStream"],
  578. source: "exportPackagePrologueOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '(function(smalltalk,nil,_st){';\x0a\x09\x09lf",
  579. messageSends: ["nextPutAll:", "lf"],
  580. referencedClasses: []
  581. }),
  582. smalltalk.Exporter);
  583. smalltalk.addMethod(
  584. smalltalk.method({
  585. selector: "extensionMethodsOfPackage:",
  586. category: 'accessing',
  587. fn: function (aPackage){
  588. var self=this;
  589. var name,result;
  590. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  591. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  592. function $Package(){return smalltalk.Package||(typeof Package=="undefined"?nil:Package)}
  593. return smalltalk.withContext(function($ctx1) {
  594. var $1;
  595. name=_st(aPackage)._name();
  596. result=_st($OrderedCollection())._new();
  597. _st(_st($Package())._sortedClasses_(_st(_st($Smalltalk())._current())._classes()))._do_((function(each){
  598. return smalltalk.withContext(function($ctx2) {
  599. return _st([each,_st(each)._class()])._do_((function(aClass){
  600. return smalltalk.withContext(function($ctx3) {
  601. return _st(result)._addAll_(_st(_st(_st(_st(aClass)._methodDictionary())._values())._sorted_((function(a,b){
  602. return smalltalk.withContext(function($ctx4) {
  603. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  604. }, function($ctx4) {$ctx4.fillBlock({a:a,b:b},$ctx3)})})))._select_((function(method){
  605. return smalltalk.withContext(function($ctx4) {
  606. return _st(_st(method)._category()).__eq("*".__comma(name));
  607. }, function($ctx4) {$ctx4.fillBlock({method:method},$ctx3)})})));
  608. }, function($ctx3) {$ctx3.fillBlock({aClass:aClass},$ctx2)})}));
  609. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  610. $1=result;
  611. return $1;
  612. }, function($ctx1) {$ctx1.fill(self,"extensionMethodsOfPackage:",{aPackage:aPackage,name:name,result:result},smalltalk.Exporter)})},
  613. args: ["aPackage"],
  614. source: "extensionMethodsOfPackage: aPackage\x0a\x09\x22Issue #143: sort classes and methods alphabetically\x22\x0a\x0a\x09| name result |\x0a\x09name := aPackage 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 = ('*', name)]) ]].\x0a\x09^result",
  615. messageSends: ["name", "new", "do:", "addAll:", "select:", "=", ",", "category", "sorted:", "<=", "selector", "values", "methodDictionary", "class", "sortedClasses:", "classes", "current"],
  616. referencedClasses: ["OrderedCollection", "Smalltalk", "Package"]
  617. }),
  618. smalltalk.Exporter);
  619. smalltalk.addMethod(
  620. smalltalk.method({
  621. selector: "ownMethodsOfClass:",
  622. category: 'accessing',
  623. fn: function (aClass){
  624. var self=this;
  625. return smalltalk.withContext(function($ctx1) {
  626. var $1;
  627. $1=_st(_st(_st(_st(aClass)._methodDictionary())._values())._sorted_((function(a,b){
  628. return smalltalk.withContext(function($ctx2) {
  629. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  630. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})})))._reject_((function(each){
  631. return smalltalk.withContext(function($ctx2) {
  632. return _st(_st(each)._category())._match_("^\x5c*");
  633. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  634. return $1;
  635. }, function($ctx1) {$ctx1.fill(self,"ownMethodsOfClass:",{aClass:aClass},smalltalk.Exporter)})},
  636. args: ["aClass"],
  637. 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*')]",
  638. messageSends: ["reject:", "match:", "category", "sorted:", "<=", "selector", "values", "methodDictionary"],
  639. referencedClasses: []
  640. }),
  641. smalltalk.Exporter);
  642. smalltalk.addMethod(
  643. smalltalk.method({
  644. selector: "ownMethodsOfMetaClass:",
  645. category: 'accessing',
  646. fn: function (aClass){
  647. var self=this;
  648. return smalltalk.withContext(function($ctx1) {
  649. var $1;
  650. $1=self._ownMethodsOfClass_(_st(aClass)._class());
  651. return $1;
  652. }, function($ctx1) {$ctx1.fill(self,"ownMethodsOfMetaClass:",{aClass:aClass},smalltalk.Exporter)})},
  653. args: ["aClass"],
  654. source: "ownMethodsOfMetaClass: aClass\x0a\x09\x22Issue #143: sort methods alphabetically\x22\x0a\x0a\x09^self ownMethodsOfClass: aClass class",
  655. messageSends: ["ownMethodsOfClass:", "class"],
  656. referencedClasses: []
  657. }),
  658. smalltalk.Exporter);
  659. smalltalk.addMethod(
  660. smalltalk.method({
  661. selector: "recipe",
  662. category: 'fileOut',
  663. fn: function (){
  664. var self=this;
  665. function $PluggableExporter(){return smalltalk.PluggableExporter||(typeof PluggableExporter=="undefined"?nil:PluggableExporter)}
  666. return smalltalk.withContext(function($ctx1) {
  667. var $1;
  668. $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:")];
  669. return $1;
  670. }, function($ctx1) {$ctx1.fill(self,"recipe",{},smalltalk.Exporter)})},
  671. args: [],
  672. 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}",
  673. messageSends: ["->"],
  674. referencedClasses: ["PluggableExporter"]
  675. }),
  676. smalltalk.Exporter);
  677. smalltalk.addClass('StrippedExporter', smalltalk.Exporter, [], 'Importer-Exporter');
  678. smalltalk.StrippedExporter.comment="I export Amber code into a JavaScript string, but without any optional associated data like the Amber source code.";
  679. smalltalk.addMethod(
  680. smalltalk.method({
  681. selector: "exportDefinitionOf:on:",
  682. category: 'output',
  683. fn: function (aClass,aStream){
  684. var self=this;
  685. return smalltalk.withContext(function($ctx1) {
  686. var $1,$2,$3,$4;
  687. $1=aStream;
  688. _st($1)._lf();
  689. _st($1)._nextPutAll_("smalltalk.addClass(");
  690. _st($1)._nextPutAll_(_st("'".__comma(self._classNameFor_(aClass))).__comma("', "));
  691. _st($1)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aClass)._superclass())));
  692. $2=_st($1)._nextPutAll_(", [");
  693. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  694. return smalltalk.withContext(function($ctx2) {
  695. return _st(aStream)._nextPutAll_(_st("'".__comma(each)).__comma("'"));
  696. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  697. return smalltalk.withContext(function($ctx2) {
  698. return _st(aStream)._nextPutAll_(", ");
  699. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  700. $3=aStream;
  701. _st($3)._nextPutAll_("], '");
  702. _st($3)._nextPutAll_(_st(_st(aClass)._category()).__comma("'"));
  703. $4=_st($3)._nextPutAll_(");");
  704. _st(aStream)._lf();
  705. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.StrippedExporter)})},
  706. args: ["aClass", "aStream"],
  707. 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",
  708. messageSends: ["lf", "nextPutAll:", ",", "classNameFor:", "superclass", "do:separatedBy:", "instanceVariableNames", "category"],
  709. referencedClasses: []
  710. }),
  711. smalltalk.StrippedExporter);
  712. smalltalk.addMethod(
  713. smalltalk.method({
  714. selector: "exportMethod:on:",
  715. category: 'output',
  716. fn: function (aMethod,aStream){
  717. var self=this;
  718. return smalltalk.withContext(function($ctx1) {
  719. var $1,$2;
  720. $1=aStream;
  721. _st($1)._nextPutAll_("smalltalk.addMethod(");
  722. _st($1)._lf();
  723. _st($1)._nextPutAll_("smalltalk.method({");
  724. _st($1)._lf();
  725. _st($1)._nextPutAll_(_st("selector: ".__comma(_st(_st(aMethod)._selector())._asJavascript())).__comma(","));
  726. _st($1)._lf();
  727. _st($1)._nextPutAll_(_st("fn: ".__comma(_st(_st(aMethod)._fn())._compiledSource())).__comma(","));
  728. _st($1)._lf();
  729. _st($1)._nextPutAll_("messageSends: ".__comma(_st(_st(aMethod)._messageSends())._asJavascript()));
  730. _st($1)._nextPutAll_("}),");
  731. _st($1)._lf();
  732. _st($1)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aMethod)._methodClass())));
  733. _st($1)._nextPutAll_(");");
  734. _st($1)._lf();
  735. $2=_st($1)._lf();
  736. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:on:",{aMethod:aMethod,aStream:aStream},smalltalk.StrippedExporter)})},
  737. args: ["aMethod", "aStream"],
  738. 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",
  739. messageSends: ["nextPutAll:", "lf", ",", "asJavascript", "selector", "compiledSource", "fn", "messageSends", "classNameFor:", "methodClass"],
  740. referencedClasses: []
  741. }),
  742. smalltalk.StrippedExporter);
  743. smalltalk.addClass('ChunkParser', smalltalk.Object, ['stream'], 'Importer-Exporter');
  744. 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";
  745. smalltalk.addMethod(
  746. smalltalk.method({
  747. selector: "nextChunk",
  748. category: 'reading',
  749. fn: function (){
  750. var self=this;
  751. var char,result,chunk;
  752. return smalltalk.withContext(function($ctx1) {
  753. var $1,$2,$3;
  754. var $early={};
  755. try {
  756. result=""._writeStream();
  757. _st((function(){
  758. return smalltalk.withContext(function($ctx2) {
  759. char=_st(self["@stream"])._next();
  760. char;
  761. return _st(char)._notNil();
  762. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileTrue_((function(){
  763. return smalltalk.withContext(function($ctx2) {
  764. $1=_st(char).__eq("!");
  765. if(smalltalk.assert($1)){
  766. $2=_st(_st(self["@stream"])._peek()).__eq("!");
  767. if(smalltalk.assert($2)){
  768. _st(self["@stream"])._next();
  769. } else {
  770. $3=_st(_st(result)._contents())._trimBoth();
  771. throw $early=[$3];
  772. };
  773. };
  774. return _st(result)._nextPut_(char);
  775. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  776. return nil;
  777. }
  778. catch(e) {if(e===$early)return e[0]; throw e}
  779. }, function($ctx1) {$ctx1.fill(self,"nextChunk",{char:char,result:result,chunk:chunk},smalltalk.ChunkParser)})},
  780. args: [],
  781. 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",
  782. messageSends: ["writeStream", "whileTrue:", "ifTrue:", "ifTrue:ifFalse:", "next", "trimBoth", "contents", "=", "peek", "nextPut:", "notNil"],
  783. referencedClasses: []
  784. }),
  785. smalltalk.ChunkParser);
  786. smalltalk.addMethod(
  787. smalltalk.method({
  788. selector: "stream:",
  789. category: 'accessing',
  790. fn: function (aStream){
  791. var self=this;
  792. return smalltalk.withContext(function($ctx1) {
  793. self["@stream"]=aStream;
  794. return self}, function($ctx1) {$ctx1.fill(self,"stream:",{aStream:aStream},smalltalk.ChunkParser)})},
  795. args: ["aStream"],
  796. source: "stream: aStream\x0a\x09stream := aStream",
  797. messageSends: [],
  798. referencedClasses: []
  799. }),
  800. smalltalk.ChunkParser);
  801. smalltalk.addMethod(
  802. smalltalk.method({
  803. selector: "on:",
  804. category: 'instance creation',
  805. fn: function (aStream){
  806. var self=this;
  807. return smalltalk.withContext(function($ctx1) {
  808. var $1;
  809. $1=_st(self._new())._stream_(aStream);
  810. return $1;
  811. }, function($ctx1) {$ctx1.fill(self,"on:",{aStream:aStream},smalltalk.ChunkParser.klass)})},
  812. args: ["aStream"],
  813. source: "on: aStream\x0a\x09^self new stream: aStream",
  814. messageSends: ["stream:", "new"],
  815. referencedClasses: []
  816. }),
  817. smalltalk.ChunkParser.klass);
  818. smalltalk.addClass('ExportRecipeInterpreter', smalltalk.Object, [], 'Importer-Exporter');
  819. smalltalk.ExportRecipeInterpreter.comment="I am an interpreter for export recipes.\x0a\x0a## Recipe format\x0a\x0aRecipe is an array, which can contain two kinds of elements:\x0a\x0a - an assocation where the key is the receiver and the value is a two-arguments selector\x0a In this case, `receiver perform: selector withArguments: { data. stream }` is called.\x0a\x09This essentially defines one step of export process.\x0a\x09The key (eg. receiver) is presumed to be some kind of 'repository' of the exporting methods\x0a\x09that just format appropriate aspect of data into a stream; like a class or a singleton,\x0a\x09so that the recipe itself can be decoupled from data.\x0a\x0a - a subarray, where first element is special and the rest is recursive recipe.\x0a\x0a `subarray first` must be an association similar to one above,\x0a\x09with key being the 'repository' receiver, but value is one-arg selector.\x0a\x09In this case, `receiver perform: selector withArguments: { data }` should create a collection.\x0a\x09Then, the sub-recipe (`subarray allButFirst`) is applied to every element of a collection, eg.\x0a\x09 collection do: [ :each | self export: each using: sa allButFirst on: stream ]";
  820. smalltalk.addMethod(
  821. smalltalk.method({
  822. selector: "interpret:for:on:",
  823. category: 'interpreting',
  824. fn: function (aRecipe,anObject,aStream){
  825. var self=this;
  826. var recipeStream;
  827. return smalltalk.withContext(function($ctx1) {
  828. recipeStream=_st(aRecipe)._readStream();
  829. _st((function(){
  830. return smalltalk.withContext(function($ctx2) {
  831. return _st(recipeStream)._atEnd();
  832. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileFalse_((function(){
  833. return smalltalk.withContext(function($ctx2) {
  834. return self._interpretStep_for_on_(_st(recipeStream)._next(),anObject,aStream);
  835. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  836. return self}, function($ctx1) {$ctx1.fill(self,"interpret:for:on:",{aRecipe:aRecipe,anObject:anObject,aStream:aStream,recipeStream:recipeStream},smalltalk.ExportRecipeInterpreter)})},
  837. args: ["aRecipe", "anObject", "aStream"],
  838. source: "interpret: aRecipe for: anObject on: aStream\x0a\x09| recipeStream |\x0a\x09\x0a\x09recipeStream := aRecipe readStream.\x0a\x09\x0a\x09[ recipeStream atEnd ] whileFalse: [\x0a\x09\x09self \x0a\x09\x09\x09interpretStep: recipeStream next\x0a\x09\x09\x09for: anObject\x0a\x09\x09\x09on: aStream ]",
  839. messageSends: ["readStream", "whileFalse:", "interpretStep:for:on:", "next", "atEnd"],
  840. referencedClasses: []
  841. }),
  842. smalltalk.ExportRecipeInterpreter);
  843. smalltalk.addMethod(
  844. smalltalk.method({
  845. selector: "interpretStep:for:on:",
  846. category: 'interpreting',
  847. fn: function (aRecipeStep,anObject,aStream){
  848. var self=this;
  849. return smalltalk.withContext(function($ctx1) {
  850. var $1,$2;
  851. $1=_st(_st(aRecipeStep)._value()).__eq_eq(aRecipeStep);
  852. if(smalltalk.assert($1)){
  853. $2=self._interpretSubRecipe_for_on_(aRecipeStep,anObject,aStream);
  854. return $2;
  855. };
  856. _st(_st(aRecipeStep)._key())._perform_withArguments_(_st(aRecipeStep)._value(),[anObject,aStream]);
  857. return self}, function($ctx1) {$ctx1.fill(self,"interpretStep:for:on:",{aRecipeStep:aRecipeStep,anObject:anObject,aStream:aStream},smalltalk.ExportRecipeInterpreter)})},
  858. args: ["aRecipeStep", "anObject", "aStream"],
  859. source: "interpretStep: aRecipeStep for: anObject on: aStream\x0a\x09aRecipeStep value == aRecipeStep ifTrue: [ \x0a\x09\x09^ self interpretSubRecipe: aRecipeStep for: anObject on: aStream ].\x0a\x09\x09\x09\x0a\x09aRecipeStep key perform: aRecipeStep value withArguments: { anObject. aStream }",
  860. messageSends: ["ifTrue:", "interpretSubRecipe:for:on:", "==", "value", "perform:withArguments:", "key"],
  861. referencedClasses: []
  862. }),
  863. smalltalk.ExportRecipeInterpreter);
  864. smalltalk.addMethod(
  865. smalltalk.method({
  866. selector: "interpretSubRecipe:for:on:",
  867. category: 'interpreting',
  868. fn: function (aRecipe,anObject,aStream){
  869. var self=this;
  870. var selection;
  871. return smalltalk.withContext(function($ctx1) {
  872. selection=_st(_st(_st(aRecipe)._first())._key())._perform_withArguments_(_st(_st(aRecipe)._first())._value(),[anObject]);
  873. _st(selection)._do_((function(each){
  874. return smalltalk.withContext(function($ctx2) {
  875. return self._interpret_for_on_(_st(aRecipe)._allButFirst(),each,aStream);
  876. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  877. return self}, function($ctx1) {$ctx1.fill(self,"interpretSubRecipe:for:on:",{aRecipe:aRecipe,anObject:anObject,aStream:aStream,selection:selection},smalltalk.ExportRecipeInterpreter)})},
  878. args: ["aRecipe", "anObject", "aStream"],
  879. source: "interpretSubRecipe: aRecipe for: anObject on: aStream\x0a\x09| selection |\x0a\x09selection := aRecipe first key \x0a\x09\x09perform: aRecipe first value \x0a\x09\x09withArguments: { anObject }.\x0a\x09selection do: [ :each |\x09\x0a\x09\x09self interpret: aRecipe allButFirst for: each on: aStream ]",
  880. messageSends: ["perform:withArguments:", "value", "first", "key", "do:", "interpret:for:on:", "allButFirst"],
  881. referencedClasses: []
  882. }),
  883. smalltalk.ExportRecipeInterpreter);
  884. smalltalk.addClass('Importer', smalltalk.Object, [], 'Importer-Exporter');
  885. smalltalk.Importer.comment="I can import Amber code from a string in the chunk format.\x0a\x0a## API\x0a\x0a Importer new import: aString";
  886. smalltalk.addMethod(
  887. smalltalk.method({
  888. selector: "import:",
  889. category: 'fileIn',
  890. fn: function (aStream){
  891. var self=this;
  892. var chunk,result,parser,lastEmpty;
  893. function $ChunkParser(){return smalltalk.ChunkParser||(typeof ChunkParser=="undefined"?nil:ChunkParser)}
  894. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  895. return smalltalk.withContext(function($ctx1) {
  896. var $1,$2;
  897. parser=_st($ChunkParser())._on_(aStream);
  898. lastEmpty=false;
  899. _st((function(){
  900. return smalltalk.withContext(function($ctx2) {
  901. chunk=_st(parser)._nextChunk();
  902. chunk;
  903. return _st(chunk)._isNil();
  904. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileFalse_((function(){
  905. return smalltalk.withContext(function($ctx2) {
  906. $1=_st(chunk)._isEmpty();
  907. if(smalltalk.assert($1)){
  908. lastEmpty=true;
  909. return lastEmpty;
  910. } else {
  911. result=_st(_st($Compiler())._new())._evaluateExpression_(chunk);
  912. result;
  913. $2=lastEmpty;
  914. if(smalltalk.assert($2)){
  915. lastEmpty=false;
  916. lastEmpty;
  917. return _st(result)._scanFrom_(parser);
  918. };
  919. };
  920. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  921. return self}, function($ctx1) {$ctx1.fill(self,"import:",{aStream:aStream,chunk:chunk,result:result,parser:parser,lastEmpty:lastEmpty},smalltalk.Importer)})},
  922. args: ["aStream"],
  923. 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]]]",
  924. messageSends: ["on:", "whileFalse:", "ifTrue:ifFalse:", "evaluateExpression:", "new", "ifTrue:", "scanFrom:", "isEmpty", "nextChunk", "isNil"],
  925. referencedClasses: ["ChunkParser", "Compiler"]
  926. }),
  927. smalltalk.Importer);
  928. smalltalk.addClass('MethodCategory', smalltalk.Object, ['methods', 'name', 'theClass'], 'Importer-Exporter');
  929. smalltalk.MethodCategory.comment="I am an abstraction for a method category in a class / metaclass.\x0a\x0aI know of my class, name and methods.\x0aI am used when exporting a package.";
  930. smalltalk.addMethod(
  931. smalltalk.method({
  932. selector: "methods",
  933. category: 'accessing',
  934. fn: function (){
  935. var self=this;
  936. return smalltalk.withContext(function($ctx1) {
  937. var $1;
  938. $1=self["@methods"];
  939. return $1;
  940. }, function($ctx1) {$ctx1.fill(self,"methods",{},smalltalk.MethodCategory)})},
  941. args: [],
  942. source: "methods\x0a\x09^methods",
  943. messageSends: [],
  944. referencedClasses: []
  945. }),
  946. smalltalk.MethodCategory);
  947. smalltalk.addMethod(
  948. smalltalk.method({
  949. selector: "methods:",
  950. category: 'accessing',
  951. fn: function (aCollection){
  952. var self=this;
  953. return smalltalk.withContext(function($ctx1) {
  954. self["@methods"]=aCollection;
  955. return self}, function($ctx1) {$ctx1.fill(self,"methods:",{aCollection:aCollection},smalltalk.MethodCategory)})},
  956. args: ["aCollection"],
  957. source: "methods: aCollection\x0a\x09methods := aCollection",
  958. messageSends: [],
  959. referencedClasses: []
  960. }),
  961. smalltalk.MethodCategory);
  962. smalltalk.addMethod(
  963. smalltalk.method({
  964. selector: "name",
  965. category: 'accessing',
  966. fn: function (){
  967. var self=this;
  968. return smalltalk.withContext(function($ctx1) {
  969. var $1;
  970. $1=self["@name"];
  971. return $1;
  972. }, function($ctx1) {$ctx1.fill(self,"name",{},smalltalk.MethodCategory)})},
  973. args: [],
  974. source: "name\x0a\x09^name",
  975. messageSends: [],
  976. referencedClasses: []
  977. }),
  978. smalltalk.MethodCategory);
  979. smalltalk.addMethod(
  980. smalltalk.method({
  981. selector: "name:",
  982. category: 'accessing',
  983. fn: function (aString){
  984. var self=this;
  985. return smalltalk.withContext(function($ctx1) {
  986. self["@name"]=aString;
  987. return self}, function($ctx1) {$ctx1.fill(self,"name:",{aString:aString},smalltalk.MethodCategory)})},
  988. args: ["aString"],
  989. source: "name: aString\x0a\x09name := aString",
  990. messageSends: [],
  991. referencedClasses: []
  992. }),
  993. smalltalk.MethodCategory);
  994. smalltalk.addMethod(
  995. smalltalk.method({
  996. selector: "theClass",
  997. category: 'accessing',
  998. fn: function (){
  999. var self=this;
  1000. return smalltalk.withContext(function($ctx1) {
  1001. var $1;
  1002. $1=self["@theClass"];
  1003. return $1;
  1004. }, function($ctx1) {$ctx1.fill(self,"theClass",{},smalltalk.MethodCategory)})},
  1005. args: [],
  1006. source: "theClass\x0a\x09^theClass",
  1007. messageSends: [],
  1008. referencedClasses: []
  1009. }),
  1010. smalltalk.MethodCategory);
  1011. smalltalk.addMethod(
  1012. smalltalk.method({
  1013. selector: "theClass:",
  1014. category: 'accessing',
  1015. fn: function (aClass){
  1016. var self=this;
  1017. return smalltalk.withContext(function($ctx1) {
  1018. self["@theClass"]=aClass;
  1019. return self}, function($ctx1) {$ctx1.fill(self,"theClass:",{aClass:aClass},smalltalk.MethodCategory)})},
  1020. args: ["aClass"],
  1021. source: "theClass: aClass\x0a\x09theClass := aClass",
  1022. messageSends: [],
  1023. referencedClasses: []
  1024. }),
  1025. smalltalk.MethodCategory);
  1026. smalltalk.addMethod(
  1027. smalltalk.method({
  1028. selector: "name:theClass:methods:",
  1029. category: 'not yet classified',
  1030. fn: function (aString,aClass,anArray){
  1031. var self=this;
  1032. return smalltalk.withContext(function($ctx1) {
  1033. var $2,$3,$1;
  1034. $2=self._new();
  1035. _st($2)._name_(aString);
  1036. _st($2)._theClass_(aClass);
  1037. _st($2)._methods_(anArray);
  1038. $3=_st($2)._yourself();
  1039. $1=$3;
  1040. return $1;
  1041. }, function($ctx1) {$ctx1.fill(self,"name:theClass:methods:",{aString:aString,aClass:aClass,anArray:anArray},smalltalk.MethodCategory.klass)})},
  1042. args: ["aString", "aClass", "anArray"],
  1043. source: "name: aString theClass: aClass methods: anArray\x0a\x09^self new\x0a\x09\x09name: aString;\x0a\x09\x09theClass: aClass;\x0a\x09\x09methods: anArray;\x0a\x09\x09yourself",
  1044. messageSends: ["name:", "new", "theClass:", "methods:", "yourself"],
  1045. referencedClasses: []
  1046. }),
  1047. smalltalk.MethodCategory.klass);
  1048. smalltalk.addClass('PackageHandler', smalltalk.InterfacingObject, [], 'Importer-Exporter');
  1049. 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.";
  1050. smalltalk.addMethod(
  1051. smalltalk.method({
  1052. selector: "ajaxPutAt:data:",
  1053. category: 'private',
  1054. fn: function (aURL,aString){
  1055. var self=this;
  1056. return smalltalk.withContext(function($ctx1) {
  1057. self._ajax_(smalltalk.HashedCollection._from_(["url".__minus_gt(aURL),"type".__minus_gt("PUT"),"data".__minus_gt(aString),"contentType".__minus_gt("text/plain;charset=UTF-8"),"error".__minus_gt((function(xhr){
  1058. return smalltalk.withContext(function($ctx2) {
  1059. return self._error_(_st(_st(_st("Commiting ".__comma(aURL)).__comma(" failed with reason: \x22")).__comma(_st(xhr)._responseText())).__comma("\x22"));
  1060. }, function($ctx2) {$ctx2.fillBlock({xhr:xhr},$ctx1)})}))]));
  1061. return self}, function($ctx1) {$ctx1.fill(self,"ajaxPutAt:data:",{aURL:aURL,aString:aString},smalltalk.PackageHandler)})},
  1062. args: ["aURL", "aString"],
  1063. source: "ajaxPutAt: aURL data: aString\x0a\x09self\x0a\x09\x09ajax: #{\x0a\x09\x09\x09'url' -> aURL.\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'] }",
  1064. messageSends: ["ajax:", "->", "error:", ",", "responseText"],
  1065. referencedClasses: []
  1066. }),
  1067. smalltalk.PackageHandler);
  1068. smalltalk.addMethod(
  1069. smalltalk.method({
  1070. selector: "commit:",
  1071. category: 'committing',
  1072. fn: function (aPackage){
  1073. var self=this;
  1074. function $PluggableExporter(){return smalltalk.PluggableExporter||(typeof PluggableExporter=="undefined"?nil:PluggableExporter)}
  1075. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  1076. return smalltalk.withContext(function($ctx1) {
  1077. _st(self._commitChannels())._do_displayingProgress_((function(commitStrategyFactory){
  1078. var fileContents,commitStrategy;
  1079. return smalltalk.withContext(function($ctx2) {
  1080. commitStrategy=_st(commitStrategyFactory)._value_(aPackage);
  1081. commitStrategy;
  1082. fileContents=_st($String())._streamContents_((function(stream){
  1083. return smalltalk.withContext(function($ctx3) {
  1084. return _st(_st($PluggableExporter())._forRecipe_(_st(commitStrategy)._key()))._exportPackage_on_(aPackage,stream);
  1085. }, function($ctx3) {$ctx3.fillBlock({stream:stream},$ctx2)})}));
  1086. fileContents;
  1087. return self._ajaxPutAt_data_(_st(commitStrategy)._value(),fileContents);
  1088. }, function($ctx2) {$ctx2.fillBlock({commitStrategyFactory:commitStrategyFactory,fileContents:fileContents,commitStrategy:commitStrategy},$ctx1)})}),"Committing package ".__comma(_st(aPackage)._name()));
  1089. return self}, function($ctx1) {$ctx1.fill(self,"commit:",{aPackage:aPackage},smalltalk.PackageHandler)})},
  1090. args: ["aPackage"],
  1091. source: "commit: aPackage\x0a\x09self commitChannels\x0a\x09\x09do: [ :commitStrategyFactory || fileContents commitStrategy |\x0a\x09\x09\x09commitStrategy := commitStrategyFactory value: aPackage.\x0a\x09\x09\x09fileContents := String streamContents: [ :stream |\x0a\x09\x09\x09\x09(PluggableExporter forRecipe: commitStrategy key) exportPackage: aPackage on: stream ].\x0a\x09\x09\x09self ajaxPutAt: commitStrategy value data: fileContents ]\x0a\x09\x09displayingProgress: 'Committing package ', aPackage name",
  1092. messageSends: ["do:displayingProgress:", "value:", "streamContents:", "exportPackage:on:", "forRecipe:", "key", "ajaxPutAt:data:", "value", ",", "name", "commitChannels"],
  1093. referencedClasses: ["PluggableExporter", "String"]
  1094. }),
  1095. smalltalk.PackageHandler);
  1096. smalltalk.addMethod(
  1097. smalltalk.method({
  1098. selector: "commitChannels",
  1099. category: 'committing',
  1100. fn: function (){
  1101. var self=this;
  1102. return smalltalk.withContext(function($ctx1) {
  1103. self._subclassResponsibility();
  1104. return self}, function($ctx1) {$ctx1.fill(self,"commitChannels",{},smalltalk.PackageHandler)})},
  1105. args: [],
  1106. source: "commitChannels\x0a\x09self subclassResponsibility",
  1107. messageSends: ["subclassResponsibility"],
  1108. referencedClasses: []
  1109. }),
  1110. smalltalk.PackageHandler);
  1111. smalltalk.PackageHandler.klass.iVarNames = ['registry'];
  1112. smalltalk.addMethod(
  1113. smalltalk.method({
  1114. selector: "classRegisteredFor:",
  1115. category: 'accessing',
  1116. fn: function (aString){
  1117. var self=this;
  1118. return smalltalk.withContext(function($ctx1) {
  1119. var $1;
  1120. $1=_st(self["@registry"])._at_(aString);
  1121. return $1;
  1122. }, function($ctx1) {$ctx1.fill(self,"classRegisteredFor:",{aString:aString},smalltalk.PackageHandler.klass)})},
  1123. args: ["aString"],
  1124. source: "classRegisteredFor: aString\x0a\x09^registry at: aString",
  1125. messageSends: ["at:"],
  1126. referencedClasses: []
  1127. }),
  1128. smalltalk.PackageHandler.klass);
  1129. smalltalk.addMethod(
  1130. smalltalk.method({
  1131. selector: "for:",
  1132. category: 'accessing',
  1133. fn: function (aString){
  1134. var self=this;
  1135. return smalltalk.withContext(function($ctx1) {
  1136. var $1;
  1137. $1=_st(self._classRegisteredFor_(aString))._new();
  1138. return $1;
  1139. }, function($ctx1) {$ctx1.fill(self,"for:",{aString:aString},smalltalk.PackageHandler.klass)})},
  1140. args: ["aString"],
  1141. source: "for: aString\x0a\x09^(self classRegisteredFor: aString) new",
  1142. messageSends: ["new", "classRegisteredFor:"],
  1143. referencedClasses: []
  1144. }),
  1145. smalltalk.PackageHandler.klass);
  1146. smalltalk.addMethod(
  1147. smalltalk.method({
  1148. selector: "initialize",
  1149. category: 'initialization',
  1150. fn: function (){
  1151. var self=this;
  1152. return smalltalk.withContext(function($ctx1) {
  1153. smalltalk.PackageHandler.klass.superclass.fn.prototype._initialize.apply(_st(self), []);
  1154. self["@registry"]=smalltalk.HashedCollection._from_([]);
  1155. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.PackageHandler.klass)})},
  1156. args: [],
  1157. source: "initialize\x0a\x09super initialize.\x0a\x09registry := #{}",
  1158. messageSends: ["initialize"],
  1159. referencedClasses: []
  1160. }),
  1161. smalltalk.PackageHandler.klass);
  1162. smalltalk.addMethod(
  1163. smalltalk.method({
  1164. selector: "register:for:",
  1165. category: 'registry',
  1166. fn: function (aClass,aString){
  1167. var self=this;
  1168. return smalltalk.withContext(function($ctx1) {
  1169. _st(self["@registry"])._at_put_(aString,aClass);
  1170. return self}, function($ctx1) {$ctx1.fill(self,"register:for:",{aClass:aClass,aString:aString},smalltalk.PackageHandler.klass)})},
  1171. args: ["aClass", "aString"],
  1172. source: "register: aClass for: aString\x0a\x09registry at: aString put: aClass",
  1173. messageSends: ["at:put:"],
  1174. referencedClasses: []
  1175. }),
  1176. smalltalk.PackageHandler.klass);
  1177. smalltalk.addMethod(
  1178. smalltalk.method({
  1179. selector: "registerFor:",
  1180. category: 'registry',
  1181. fn: function (aString){
  1182. var self=this;
  1183. function $PackageHandler(){return smalltalk.PackageHandler||(typeof PackageHandler=="undefined"?nil:PackageHandler)}
  1184. return smalltalk.withContext(function($ctx1) {
  1185. _st($PackageHandler())._register_for_(self,aString);
  1186. return self}, function($ctx1) {$ctx1.fill(self,"registerFor:",{aString:aString},smalltalk.PackageHandler.klass)})},
  1187. args: ["aString"],
  1188. source: "registerFor: aString\x0a\x09PackageHandler register: self for: aString",
  1189. messageSends: ["register:for:"],
  1190. referencedClasses: ["PackageHandler"]
  1191. }),
  1192. smalltalk.PackageHandler.klass);
  1193. smalltalk.addClass('LegacyPackageHandler', smalltalk.PackageHandler, [], 'Importer-Exporter');
  1194. smalltalk.LegacyPackageHandler.comment="I am responsible for handling package loading and committing.\x0d\x0a\x0d\x0aI should not be used directly. Instead, use the corresponding `Package` methods.";
  1195. smalltalk.addMethod(
  1196. smalltalk.method({
  1197. selector: "commitChannels",
  1198. category: 'committing',
  1199. fn: function (){
  1200. var self=this;
  1201. function $Exporter(){return smalltalk.Exporter||(typeof Exporter=="undefined"?nil:Exporter)}
  1202. function $StrippedExporter(){return smalltalk.StrippedExporter||(typeof StrippedExporter=="undefined"?nil:StrippedExporter)}
  1203. function $ChunkExporter(){return smalltalk.ChunkExporter||(typeof ChunkExporter=="undefined"?nil:ChunkExporter)}
  1204. return smalltalk.withContext(function($ctx1) {
  1205. var $1;
  1206. $1=[(function(pkg){
  1207. return smalltalk.withContext(function($ctx2) {
  1208. return _st(_st(_st($Exporter())._default())._recipe()).__minus_gt(_st(_st(_st(_st(pkg)._commitPathJs()).__comma("/")).__comma(_st(pkg)._name())).__comma(".js"));
  1209. }, function($ctx2) {$ctx2.fillBlock({pkg:pkg},$ctx1)})}),(function(pkg){
  1210. return smalltalk.withContext(function($ctx2) {
  1211. return _st(_st(_st($StrippedExporter())._default())._recipe()).__minus_gt(_st(_st(_st(_st(pkg)._commitPathJs()).__comma("/")).__comma(_st(pkg)._name())).__comma(".deploy.js"));
  1212. }, function($ctx2) {$ctx2.fillBlock({pkg:pkg},$ctx1)})}),(function(pkg){
  1213. return smalltalk.withContext(function($ctx2) {
  1214. return _st(_st(_st($ChunkExporter())._default())._recipe()).__minus_gt(_st(_st(_st(_st(pkg)._commitPathSt()).__comma("/")).__comma(_st(pkg)._name())).__comma(".st"));
  1215. }, function($ctx2) {$ctx2.fillBlock({pkg:pkg},$ctx1)})})];
  1216. return $1;
  1217. }, function($ctx1) {$ctx1.fill(self,"commitChannels",{},smalltalk.LegacyPackageHandler)})},
  1218. args: [],
  1219. source: "commitChannels\x0a\x09^{ \x0a\x09\x09[ :pkg | Exporter default recipe -> (pkg commitPathJs, '/', pkg name, '.js') ].\x0a\x09\x09[ :pkg | StrippedExporter default recipe -> (pkg commitPathJs, '/', pkg name, '.deploy.js') ].\x0a\x09\x09[ :pkg | ChunkExporter default recipe -> (pkg commitPathSt, '/', pkg name, '.st') ]\x0a\x09}",
  1220. messageSends: ["->", ",", "name", "commitPathJs", "recipe", "default", "commitPathSt"],
  1221. referencedClasses: ["Exporter", "StrippedExporter", "ChunkExporter"]
  1222. }),
  1223. smalltalk.LegacyPackageHandler);
  1224. smalltalk.addMethod(
  1225. smalltalk.method({
  1226. selector: "commitPathJsFor:",
  1227. category: 'committing',
  1228. fn: function (aPackage){
  1229. var self=this;
  1230. return smalltalk.withContext(function($ctx1) {
  1231. var $1;
  1232. $1=_st(self._class())._defaultCommitPathJs();
  1233. return $1;
  1234. }, function($ctx1) {$ctx1.fill(self,"commitPathJsFor:",{aPackage:aPackage},smalltalk.LegacyPackageHandler)})},
  1235. args: ["aPackage"],
  1236. source: "commitPathJsFor: aPackage\x0a\x09^self class defaultCommitPathJs",
  1237. messageSends: ["defaultCommitPathJs", "class"],
  1238. referencedClasses: []
  1239. }),
  1240. smalltalk.LegacyPackageHandler);
  1241. smalltalk.addMethod(
  1242. smalltalk.method({
  1243. selector: "commitPathStFor:",
  1244. category: 'committing',
  1245. fn: function (aPackage){
  1246. var self=this;
  1247. return smalltalk.withContext(function($ctx1) {
  1248. var $1;
  1249. $1=_st(self._class())._defaultCommitPathSt();
  1250. return $1;
  1251. }, function($ctx1) {$ctx1.fill(self,"commitPathStFor:",{aPackage:aPackage},smalltalk.LegacyPackageHandler)})},
  1252. args: ["aPackage"],
  1253. source: "commitPathStFor: aPackage\x0a\x09^self class defaultCommitPathSt",
  1254. messageSends: ["defaultCommitPathSt", "class"],
  1255. referencedClasses: []
  1256. }),
  1257. smalltalk.LegacyPackageHandler);
  1258. smalltalk.addMethod(
  1259. smalltalk.method({
  1260. selector: "loadPackage:prefix:",
  1261. category: 'loading',
  1262. fn: function (packageName,aString){
  1263. var self=this;
  1264. var url;
  1265. return smalltalk.withContext(function($ctx1) {
  1266. var $1;
  1267. url=_st(_st(_st("/".__comma(aString)).__comma("/js/")).__comma(packageName)).__comma(".js");
  1268. self._ajax_(smalltalk.HashedCollection._from_(["url".__minus_gt(url),"type".__minus_gt("GET"),"dataType".__minus_gt("script"),"complete".__minus_gt((function(jqXHR,textStatus){
  1269. return smalltalk.withContext(function($ctx2) {
  1270. $1=_st(_st(jqXHR)._readyState()).__eq((4));
  1271. if(smalltalk.assert($1)){
  1272. return self._setupPackageNamed_prefix_(packageName,aString);
  1273. };
  1274. }, function($ctx2) {$ctx2.fillBlock({jqXHR:jqXHR,textStatus:textStatus},$ctx1)})})),"error".__minus_gt((function(){
  1275. return smalltalk.withContext(function($ctx2) {
  1276. return self._alert_("Could not load package at: ".__comma(url));
  1277. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))]));
  1278. return self}, function($ctx1) {$ctx1.fill(self,"loadPackage:prefix:",{packageName:packageName,aString:aString,url:url},smalltalk.LegacyPackageHandler)})},
  1279. args: ["packageName", "aString"],
  1280. source: "loadPackage: packageName prefix: aString\x0a\x09| url |\x0a\x09url := '/', aString, '/js/', packageName, '.js'.\x0a\x09self\x0a\x09\x09ajax: #{\x0a\x09\x09\x09'url' -> url.\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' -> [ self alert: 'Could not load package at: ', url ]\x0a\x09\x09}",
  1281. messageSends: [",", "ajax:", "->", "ifTrue:", "setupPackageNamed:prefix:", "=", "readyState", "alert:"],
  1282. referencedClasses: []
  1283. }),
  1284. smalltalk.LegacyPackageHandler);
  1285. smalltalk.addMethod(
  1286. smalltalk.method({
  1287. selector: "loadPackages:prefix:",
  1288. category: 'loading',
  1289. fn: function (aCollection,aString){
  1290. var self=this;
  1291. return smalltalk.withContext(function($ctx1) {
  1292. _st(aCollection)._do_((function(each){
  1293. return smalltalk.withContext(function($ctx2) {
  1294. return self._loadPackage_prefix_(each,aString);
  1295. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  1296. return self}, function($ctx1) {$ctx1.fill(self,"loadPackages:prefix:",{aCollection:aCollection,aString:aString},smalltalk.LegacyPackageHandler)})},
  1297. args: ["aCollection", "aString"],
  1298. source: "loadPackages: aCollection prefix: aString\x0a\x09aCollection do: [ :each |\x0a\x09\x09self loadPackage: each prefix: aString ]",
  1299. messageSends: ["do:", "loadPackage:prefix:"],
  1300. referencedClasses: []
  1301. }),
  1302. smalltalk.LegacyPackageHandler);
  1303. smalltalk.addMethod(
  1304. smalltalk.method({
  1305. selector: "setupPackageNamed:prefix:",
  1306. category: 'private',
  1307. fn: function (packageName,aString){
  1308. var self=this;
  1309. function $Package(){return smalltalk.Package||(typeof Package=="undefined"?nil:Package)}
  1310. return smalltalk.withContext(function($ctx1) {
  1311. var $1,$2;
  1312. $1=_st($Package())._named_(packageName);
  1313. _st($1)._setupClasses();
  1314. _st($1)._commitPathJs_(_st("/".__comma(aString)).__comma("/js"));
  1315. $2=_st($1)._commitPathSt_(_st("/".__comma(aString)).__comma("/st"));
  1316. return self}, function($ctx1) {$ctx1.fill(self,"setupPackageNamed:prefix:",{packageName:packageName,aString:aString},smalltalk.LegacyPackageHandler)})},
  1317. args: ["packageName", "aString"],
  1318. source: "setupPackageNamed: packageName prefix: aString\x0a\x0a\x09(Package named: packageName)\x0a\x09\x09setupClasses;\x0a\x09\x09commitPathJs: '/', aString, '/js';\x0a\x09\x09commitPathSt: '/', aString, '/st'",
  1319. messageSends: ["setupClasses", "named:", "commitPathJs:", ",", "commitPathSt:"],
  1320. referencedClasses: ["Package"]
  1321. }),
  1322. smalltalk.LegacyPackageHandler);
  1323. smalltalk.LegacyPackageHandler.klass.iVarNames = ['defaultCommitPathJs','defaultCommitPathSt'];
  1324. smalltalk.addMethod(
  1325. smalltalk.method({
  1326. selector: "commitPathsFromLoader",
  1327. category: 'commit paths',
  1328. fn: function (){
  1329. var self=this;
  1330. return smalltalk.withContext(function($ctx1) {
  1331. var commitPath = typeof amber !== 'undefined' && amber.commitPath;
  1332. if (!commitPath) return;
  1333. if (commitPath.js) self._defaultCommitPathJs_(commitPath.js);
  1334. if (commitPath.st) self._defaultCommitPathSt_(commitPath.st);
  1335. ;
  1336. return self}, function($ctx1) {$ctx1.fill(self,"commitPathsFromLoader",{},smalltalk.LegacyPackageHandler.klass)})},
  1337. args: [],
  1338. source: "commitPathsFromLoader\x0a\x09<\x0a\x09\x09var commitPath = typeof amber !== 'undefined' && amber.commitPath;\x0a\x09\x09if (!commitPath) return;\x0a\x09\x09if (commitPath.js) self._defaultCommitPathJs_(commitPath.js);\x0a\x09\x09if (commitPath.st) self._defaultCommitPathSt_(commitPath.st);\x0a\x09>",
  1339. messageSends: [],
  1340. referencedClasses: []
  1341. }),
  1342. smalltalk.LegacyPackageHandler.klass);
  1343. smalltalk.addMethod(
  1344. smalltalk.method({
  1345. selector: "defaultCommitPathJs",
  1346. category: 'commit paths',
  1347. fn: function (){
  1348. var self=this;
  1349. return smalltalk.withContext(function($ctx1) {
  1350. var $2,$1;
  1351. $2=self["@defaultCommitPathJs"];
  1352. if(($receiver = $2) == nil || $receiver == undefined){
  1353. self["@defaultCommitPathJs"]="js";
  1354. $1=self["@defaultCommitPathJs"];
  1355. } else {
  1356. $1=$2;
  1357. };
  1358. return $1;
  1359. }, function($ctx1) {$ctx1.fill(self,"defaultCommitPathJs",{},smalltalk.LegacyPackageHandler.klass)})},
  1360. args: [],
  1361. source: "defaultCommitPathJs\x0a\x09^ defaultCommitPathJs ifNil: [ defaultCommitPathJs := 'js']",
  1362. messageSends: ["ifNil:"],
  1363. referencedClasses: []
  1364. }),
  1365. smalltalk.LegacyPackageHandler.klass);
  1366. smalltalk.addMethod(
  1367. smalltalk.method({
  1368. selector: "defaultCommitPathJs:",
  1369. category: 'commit paths',
  1370. fn: function (aString){
  1371. var self=this;
  1372. return smalltalk.withContext(function($ctx1) {
  1373. self["@defaultCommitPathJs"]=aString;
  1374. return self}, function($ctx1) {$ctx1.fill(self,"defaultCommitPathJs:",{aString:aString},smalltalk.LegacyPackageHandler.klass)})},
  1375. args: ["aString"],
  1376. source: "defaultCommitPathJs: aString\x0a\x09defaultCommitPathJs := aString",
  1377. messageSends: [],
  1378. referencedClasses: []
  1379. }),
  1380. smalltalk.LegacyPackageHandler.klass);
  1381. smalltalk.addMethod(
  1382. smalltalk.method({
  1383. selector: "defaultCommitPathSt",
  1384. category: 'commit paths',
  1385. fn: function (){
  1386. var self=this;
  1387. return smalltalk.withContext(function($ctx1) {
  1388. var $2,$1;
  1389. $2=self["@defaultCommitPathSt"];
  1390. if(($receiver = $2) == nil || $receiver == undefined){
  1391. self["@defaultCommitPathSt"]="st";
  1392. $1=self["@defaultCommitPathSt"];
  1393. } else {
  1394. $1=$2;
  1395. };
  1396. return $1;
  1397. }, function($ctx1) {$ctx1.fill(self,"defaultCommitPathSt",{},smalltalk.LegacyPackageHandler.klass)})},
  1398. args: [],
  1399. source: "defaultCommitPathSt\x0a\x09^ defaultCommitPathSt ifNil: [ defaultCommitPathSt := 'st']",
  1400. messageSends: ["ifNil:"],
  1401. referencedClasses: []
  1402. }),
  1403. smalltalk.LegacyPackageHandler.klass);
  1404. smalltalk.addMethod(
  1405. smalltalk.method({
  1406. selector: "defaultCommitPathSt:",
  1407. category: 'commit paths',
  1408. fn: function (aString){
  1409. var self=this;
  1410. return smalltalk.withContext(function($ctx1) {
  1411. self["@defaultCommitPathSt"]=aString;
  1412. return self}, function($ctx1) {$ctx1.fill(self,"defaultCommitPathSt:",{aString:aString},smalltalk.LegacyPackageHandler.klass)})},
  1413. args: ["aString"],
  1414. source: "defaultCommitPathSt: aString\x0a\x09defaultCommitPathSt := aString",
  1415. messageSends: [],
  1416. referencedClasses: []
  1417. }),
  1418. smalltalk.LegacyPackageHandler.klass);
  1419. smalltalk.addMethod(
  1420. smalltalk.method({
  1421. selector: "initialize",
  1422. category: 'initialization',
  1423. fn: function (){
  1424. var self=this;
  1425. return smalltalk.withContext(function($ctx1) {
  1426. smalltalk.LegacyPackageHandler.klass.superclass.fn.prototype._initialize.apply(_st(self), []);
  1427. self._registerFor_("unknown");
  1428. self._commitPathsFromLoader();
  1429. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.LegacyPackageHandler.klass)})},
  1430. args: [],
  1431. source: "initialize\x0a\x09super initialize.\x0a\x09self registerFor: 'unknown'.\x0a\x09self commitPathsFromLoader",
  1432. messageSends: ["initialize", "registerFor:", "commitPathsFromLoader"],
  1433. referencedClasses: []
  1434. }),
  1435. smalltalk.LegacyPackageHandler.klass);
  1436. smalltalk.addMethod(
  1437. smalltalk.method({
  1438. selector: "loadPackages:prefix:",
  1439. category: 'loading',
  1440. fn: function (aCollection,aString){
  1441. var self=this;
  1442. return smalltalk.withContext(function($ctx1) {
  1443. var $1;
  1444. $1=_st(self._new())._loadPackages_prefix_(aCollection,aString);
  1445. return $1;
  1446. }, function($ctx1) {$ctx1.fill(self,"loadPackages:prefix:",{aCollection:aCollection,aString:aString},smalltalk.LegacyPackageHandler.klass)})},
  1447. args: ["aCollection", "aString"],
  1448. source: "loadPackages: aCollection prefix: aString\x0a\x09^ self new loadPackages: aCollection prefix: aString",
  1449. messageSends: ["loadPackages:prefix:", "new"],
  1450. referencedClasses: []
  1451. }),
  1452. smalltalk.LegacyPackageHandler.klass);
  1453. smalltalk.addMethod(
  1454. smalltalk.method({
  1455. selector: "resetCommitPaths",
  1456. category: 'commit paths',
  1457. fn: function (){
  1458. var self=this;
  1459. return smalltalk.withContext(function($ctx1) {
  1460. self["@defaultCommitPathJs"]=nil;
  1461. self["@defaultCommitPathSt"]=nil;
  1462. return self}, function($ctx1) {$ctx1.fill(self,"resetCommitPaths",{},smalltalk.LegacyPackageHandler.klass)})},
  1463. args: [],
  1464. source: "resetCommitPaths\x0a\x09defaultCommitPathJs := nil.\x0a\x09defaultCommitPathSt := nil",
  1465. messageSends: [],
  1466. referencedClasses: []
  1467. }),
  1468. smalltalk.LegacyPackageHandler.klass);
  1469. smalltalk.addClass('PluggableExporter', smalltalk.Object, ['recipe'], 'Importer-Exporter');
  1470. smalltalk.PluggableExporter.comment="I am an engine for exporting structured data on a Stream.\x0a\x0aMy instances are created using\x0a PluggableExporter forRecipe: aRecipe,\x0awhere recipe is structured description of the exporting algorithm (see `ExportRecipeInterpreter`).\x0a\x0aThe actual exporting is done by interpreting the recipe using a `RecipeInterpreter`.\x0a\x0a\x0aI am used to export amber packages, so I have a convenience method\x0a`exportPackage: aPackage on: aStream`\x0awhich exports `aPackage` using the `recipe`\x0a(it is otherwise no special, so it may be renamed to export:on:)";
  1471. smalltalk.addMethod(
  1472. smalltalk.method({
  1473. selector: "exportAllPackages",
  1474. category: 'fileOut',
  1475. fn: function (){
  1476. var self=this;
  1477. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1478. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  1479. return smalltalk.withContext(function($ctx1) {
  1480. var $1;
  1481. $1=_st($String())._streamContents_((function(stream){
  1482. return smalltalk.withContext(function($ctx2) {
  1483. return _st(_st(_st($Smalltalk())._current())._packages())._do_((function(pkg){
  1484. return smalltalk.withContext(function($ctx3) {
  1485. return self._exportPackage_on_(pkg,stream);
  1486. }, function($ctx3) {$ctx3.fillBlock({pkg:pkg},$ctx2)})}));
  1487. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1)})}));
  1488. return $1;
  1489. }, function($ctx1) {$ctx1.fill(self,"exportAllPackages",{},smalltalk.PluggableExporter)})},
  1490. args: [],
  1491. source: "exportAllPackages\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]]",
  1492. messageSends: ["streamContents:", "do:", "exportPackage:on:", "packages", "current"],
  1493. referencedClasses: ["Smalltalk", "String"]
  1494. }),
  1495. smalltalk.PluggableExporter);
  1496. smalltalk.addMethod(
  1497. smalltalk.method({
  1498. selector: "exportPackage:on:",
  1499. category: 'fileOut',
  1500. fn: function (aPackage,aStream){
  1501. var self=this;
  1502. return smalltalk.withContext(function($ctx1) {
  1503. _st(self._interpreter())._interpret_for_on_(self._recipe(),aPackage,aStream);
  1504. return self}, function($ctx1) {$ctx1.fill(self,"exportPackage:on:",{aPackage:aPackage,aStream:aStream},smalltalk.PluggableExporter)})},
  1505. args: ["aPackage", "aStream"],
  1506. source: "exportPackage: aPackage on: aStream\x0a\x09self interpreter interpret: self recipe for: aPackage on: aStream",
  1507. messageSends: ["interpret:for:on:", "recipe", "interpreter"],
  1508. referencedClasses: []
  1509. }),
  1510. smalltalk.PluggableExporter);
  1511. smalltalk.addMethod(
  1512. smalltalk.method({
  1513. selector: "interpreter",
  1514. category: 'accessing',
  1515. fn: function (){
  1516. var self=this;
  1517. function $ExportRecipeInterpreter(){return smalltalk.ExportRecipeInterpreter||(typeof ExportRecipeInterpreter=="undefined"?nil:ExportRecipeInterpreter)}
  1518. return smalltalk.withContext(function($ctx1) {
  1519. var $1;
  1520. $1=_st($ExportRecipeInterpreter())._new();
  1521. return $1;
  1522. }, function($ctx1) {$ctx1.fill(self,"interpreter",{},smalltalk.PluggableExporter)})},
  1523. args: [],
  1524. source: "interpreter\x0a\x09^ ExportRecipeInterpreter new",
  1525. messageSends: ["new"],
  1526. referencedClasses: ["ExportRecipeInterpreter"]
  1527. }),
  1528. smalltalk.PluggableExporter);
  1529. smalltalk.addMethod(
  1530. smalltalk.method({
  1531. selector: "recipe",
  1532. category: 'accessing',
  1533. fn: function (){
  1534. var self=this;
  1535. return smalltalk.withContext(function($ctx1) {
  1536. var $1;
  1537. $1=self["@recipe"];
  1538. return $1;
  1539. }, function($ctx1) {$ctx1.fill(self,"recipe",{},smalltalk.PluggableExporter)})},
  1540. args: [],
  1541. source: "recipe\x0a\x09^recipe",
  1542. messageSends: [],
  1543. referencedClasses: []
  1544. }),
  1545. smalltalk.PluggableExporter);
  1546. smalltalk.addMethod(
  1547. smalltalk.method({
  1548. selector: "recipe:",
  1549. category: 'accessing',
  1550. fn: function (anArray){
  1551. var self=this;
  1552. return smalltalk.withContext(function($ctx1) {
  1553. self["@recipe"]=anArray;
  1554. return self}, function($ctx1) {$ctx1.fill(self,"recipe:",{anArray:anArray},smalltalk.PluggableExporter)})},
  1555. args: ["anArray"],
  1556. source: "recipe: anArray\x0a\x09recipe := anArray",
  1557. messageSends: [],
  1558. referencedClasses: []
  1559. }),
  1560. smalltalk.PluggableExporter);
  1561. smalltalk.addMethod(
  1562. smalltalk.method({
  1563. selector: "forRecipe:",
  1564. category: 'instance creation',
  1565. fn: function (aRecipe){
  1566. var self=this;
  1567. return smalltalk.withContext(function($ctx1) {
  1568. var $2,$3,$1;
  1569. $2=self._new();
  1570. _st($2)._recipe_(aRecipe);
  1571. $3=_st($2)._yourself();
  1572. $1=$3;
  1573. return $1;
  1574. }, function($ctx1) {$ctx1.fill(self,"forRecipe:",{aRecipe:aRecipe},smalltalk.PluggableExporter.klass)})},
  1575. args: ["aRecipe"],
  1576. source: "forRecipe: aRecipe\x0a\x09^self new recipe: aRecipe; yourself",
  1577. messageSends: ["recipe:", "new", "yourself"],
  1578. referencedClasses: []
  1579. }),
  1580. smalltalk.PluggableExporter.klass);
  1581. smalltalk.addMethod(
  1582. smalltalk.method({
  1583. selector: "ownClassesOfPackage:",
  1584. category: 'convenience',
  1585. fn: function (package_){
  1586. var self=this;
  1587. return smalltalk.withContext(function($ctx1) {
  1588. var $1;
  1589. $1=_st(_st(package_)._sortedClasses())._asSet();
  1590. return $1;
  1591. }, function($ctx1) {$ctx1.fill(self,"ownClassesOfPackage:",{package_:package_},smalltalk.PluggableExporter.klass)})},
  1592. args: ["package"],
  1593. source: "ownClassesOfPackage: package\x0a\x09\x22Export classes in dependency order.\x0a\x09Update (issue #171): Remove duplicates for export\x22\x0a\x09^package sortedClasses asSet",
  1594. messageSends: ["asSet", "sortedClasses"],
  1595. referencedClasses: []
  1596. }),
  1597. smalltalk.PluggableExporter.klass);
  1598. smalltalk.addMethod(
  1599. smalltalk.method({
  1600. selector: "commit",
  1601. category: '*Importer-Exporter',
  1602. fn: function (){
  1603. var self=this;
  1604. return smalltalk.withContext(function($ctx1) {
  1605. var $1;
  1606. $1=_st(self._transport())._commit_(self);
  1607. return $1;
  1608. }, function($ctx1) {$ctx1.fill(self,"commit",{},smalltalk.Package)})},
  1609. args: [],
  1610. source: "commit\x0a\x09^ self transport commit: self",
  1611. messageSends: ["commit:", "transport"],
  1612. referencedClasses: []
  1613. }),
  1614. smalltalk.Package);
  1615. smalltalk.addMethod(
  1616. smalltalk.method({
  1617. selector: "commitPathJs",
  1618. category: '*Importer-Exporter',
  1619. fn: function (){
  1620. var self=this;
  1621. return smalltalk.withContext(function($ctx1) {
  1622. var $3,$2,$1;
  1623. $3=self["@extension"];
  1624. if(($receiver = $3) == nil || $receiver == undefined){
  1625. self["@extension"]=smalltalk.HashedCollection._from_([]);
  1626. $2=self["@extension"];
  1627. } else {
  1628. $2=$3;
  1629. };
  1630. $1=_st($2)._at_ifAbsentPut_("commitPathJs",(function(){
  1631. return smalltalk.withContext(function($ctx2) {
  1632. return _st(self._transport())._commitPathJsFor_(self);
  1633. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  1634. return $1;
  1635. }, function($ctx1) {$ctx1.fill(self,"commitPathJs",{},smalltalk.Package)})},
  1636. args: [],
  1637. source: "commitPathJs\x0a\x09^ (extension ifNil: [ extension := #{} ]) at: #commitPathJs ifAbsentPut: [self transport commitPathJsFor: self]",
  1638. messageSends: ["at:ifAbsentPut:", "commitPathJsFor:", "transport", "ifNil:"],
  1639. referencedClasses: []
  1640. }),
  1641. smalltalk.Package);
  1642. smalltalk.addMethod(
  1643. smalltalk.method({
  1644. selector: "commitPathJs:",
  1645. category: '*Importer-Exporter',
  1646. fn: function (aString){
  1647. var self=this;
  1648. return smalltalk.withContext(function($ctx1) {
  1649. var $3,$2,$1;
  1650. $3=self["@extension"];
  1651. if(($receiver = $3) == nil || $receiver == undefined){
  1652. self["@extension"]=smalltalk.HashedCollection._from_([]);
  1653. $2=self["@extension"];
  1654. } else {
  1655. $2=$3;
  1656. };
  1657. $1=_st($2)._at_put_("commitPathJs",aString);
  1658. return $1;
  1659. }, function($ctx1) {$ctx1.fill(self,"commitPathJs:",{aString:aString},smalltalk.Package)})},
  1660. args: ["aString"],
  1661. source: "commitPathJs: aString\x0a\x09^ (extension ifNil: [ extension := #{} ]) at: #commitPathJs put: aString",
  1662. messageSends: ["at:put:", "ifNil:"],
  1663. referencedClasses: []
  1664. }),
  1665. smalltalk.Package);
  1666. smalltalk.addMethod(
  1667. smalltalk.method({
  1668. selector: "commitPathSt",
  1669. category: '*Importer-Exporter',
  1670. fn: function (){
  1671. var self=this;
  1672. return smalltalk.withContext(function($ctx1) {
  1673. var $3,$2,$1;
  1674. $3=self["@extension"];
  1675. if(($receiver = $3) == nil || $receiver == undefined){
  1676. self["@extension"]=smalltalk.HashedCollection._from_([]);
  1677. $2=self["@extension"];
  1678. } else {
  1679. $2=$3;
  1680. };
  1681. $1=_st($2)._at_ifAbsentPut_("commitPathSt",(function(){
  1682. return smalltalk.withContext(function($ctx2) {
  1683. return _st(self._transport())._commitPathStFor_(self);
  1684. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  1685. return $1;
  1686. }, function($ctx1) {$ctx1.fill(self,"commitPathSt",{},smalltalk.Package)})},
  1687. args: [],
  1688. source: "commitPathSt\x0a\x09^ (extension ifNil: [ extension := #{} ]) at: #commitPathSt ifAbsentPut: [self transport commitPathStFor: self]",
  1689. messageSends: ["at:ifAbsentPut:", "commitPathStFor:", "transport", "ifNil:"],
  1690. referencedClasses: []
  1691. }),
  1692. smalltalk.Package);
  1693. smalltalk.addMethod(
  1694. smalltalk.method({
  1695. selector: "commitPathSt:",
  1696. category: '*Importer-Exporter',
  1697. fn: function (aString){
  1698. var self=this;
  1699. return smalltalk.withContext(function($ctx1) {
  1700. var $3,$2,$1;
  1701. $3=self["@extension"];
  1702. if(($receiver = $3) == nil || $receiver == undefined){
  1703. self["@extension"]=smalltalk.HashedCollection._from_([]);
  1704. $2=self["@extension"];
  1705. } else {
  1706. $2=$3;
  1707. };
  1708. $1=_st($2)._at_put_("commitPathSt",aString);
  1709. return $1;
  1710. }, function($ctx1) {$ctx1.fill(self,"commitPathSt:",{aString:aString},smalltalk.Package)})},
  1711. args: ["aString"],
  1712. source: "commitPathSt: aString\x0a\x09^ (extension ifNil: [ extension := #{} ]) at: #commitPathSt put: aString",
  1713. messageSends: ["at:put:", "ifNil:"],
  1714. referencedClasses: []
  1715. }),
  1716. smalltalk.Package);
  1717. smalltalk.addMethod(
  1718. smalltalk.method({
  1719. selector: "transport",
  1720. category: '*Importer-Exporter',
  1721. fn: function (){
  1722. var self=this;
  1723. function $PackageHandler(){return smalltalk.PackageHandler||(typeof PackageHandler=="undefined"?nil:PackageHandler)}
  1724. return smalltalk.withContext(function($ctx1) {
  1725. var $1;
  1726. $1=_st($PackageHandler())._for_(self._transportType());
  1727. return $1;
  1728. }, function($ctx1) {$ctx1.fill(self,"transport",{},smalltalk.Package)})},
  1729. args: [],
  1730. source: "transport\x0a\x09^ PackageHandler for: self transportType",
  1731. messageSends: ["for:", "transportType"],
  1732. referencedClasses: ["PackageHandler"]
  1733. }),
  1734. smalltalk.Package);
  1735. smalltalk.addMethod(
  1736. smalltalk.method({
  1737. selector: "transportType",
  1738. category: '*Importer-Exporter',
  1739. fn: function (){
  1740. var self=this;
  1741. return smalltalk.withContext(function($ctx1) {
  1742. return (self.transport && self.transport.type) || 'unknown';;
  1743. return self}, function($ctx1) {$ctx1.fill(self,"transportType",{},smalltalk.Package)})},
  1744. args: [],
  1745. source: "transportType\x0a\x09<return (self.transport && self.transport.type) || 'unknown';>",
  1746. messageSends: [],
  1747. referencedClasses: []
  1748. }),
  1749. smalltalk.Package);
  1750. })(global_smalltalk,global_nil,global__st);