2
0

Importer-Exporter.js 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. smalltalk.addPackage('Importer-Exporter');
  2. smalltalk.addClass('ChunkParser', smalltalk.Object, ['stream'], 'Importer-Exporter');
  3. smalltalk.addMethod(
  4. smalltalk.method({
  5. selector: "nextChunk",
  6. category: 'reading',
  7. fn: function (){
  8. var self=this;
  9. var char,result,chunk;
  10. return smalltalk.withContext(function($ctx1) {
  11. var $1,$2,$3;
  12. var $early={};
  13. try {
  14. result=_st("")._writeStream();
  15. _st((function(){
  16. return smalltalk.withContext(function($ctx2) {
  17. char=_st(self["@stream"])._next();
  18. char;
  19. return _st(char)._notNil();
  20. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileTrue_((function(){
  21. return smalltalk.withContext(function($ctx2) {
  22. $1=_st(char).__eq("!");
  23. if(smalltalk.assert($1)){
  24. $2=_st(_st(self["@stream"])._peek()).__eq("!");
  25. if(smalltalk.assert($2)){
  26. _st(self["@stream"])._next();
  27. } else {
  28. $3=_st(_st(result)._contents())._trimBoth();
  29. throw $early=[$3];
  30. };
  31. };
  32. return _st(result)._nextPut_(char);
  33. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  34. return nil;
  35. }
  36. catch(e) {if(e===$early)return e[0]; throw e}
  37. }, function($ctx1) {$ctx1.fill(self,"nextChunk",{char:char,result:result,chunk:chunk},smalltalk.ChunkParser)})},
  38. args: [],
  39. 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",
  40. messageSends: ["writeStream", "whileTrue:", "ifTrue:", "ifTrue:ifFalse:", "next", "trimBoth", "contents", "=", "peek", "nextPut:", "notNil"],
  41. referencedClasses: []
  42. }),
  43. smalltalk.ChunkParser);
  44. smalltalk.addMethod(
  45. smalltalk.method({
  46. selector: "stream:",
  47. category: 'accessing',
  48. fn: function (aStream){
  49. var self=this;
  50. return smalltalk.withContext(function($ctx1) {
  51. self["@stream"]=aStream;
  52. return self}, function($ctx1) {$ctx1.fill(self,"stream:",{aStream:aStream},smalltalk.ChunkParser)})},
  53. args: ["aStream"],
  54. source: "stream: aStream\x0a\x09stream := aStream",
  55. messageSends: [],
  56. referencedClasses: []
  57. }),
  58. smalltalk.ChunkParser);
  59. smalltalk.addMethod(
  60. smalltalk.method({
  61. selector: "on:",
  62. category: 'not yet classified',
  63. fn: function (aStream){
  64. var self=this;
  65. return smalltalk.withContext(function($ctx1) {
  66. var $1;
  67. $1=_st(_st(self)._new())._stream_(aStream);
  68. return $1;
  69. }, function($ctx1) {$ctx1.fill(self,"on:",{aStream:aStream},smalltalk.ChunkParser.klass)})},
  70. args: ["aStream"],
  71. source: "on: aStream\x0a\x09^self new stream: aStream",
  72. messageSends: ["stream:", "new"],
  73. referencedClasses: []
  74. }),
  75. smalltalk.ChunkParser.klass);
  76. smalltalk.addClass('Exporter', smalltalk.Object, [], 'Importer-Exporter');
  77. smalltalk.addMethod(
  78. smalltalk.method({
  79. selector: "classNameFor:",
  80. category: 'private',
  81. fn: function (aClass){
  82. var self=this;
  83. return smalltalk.withContext(function($ctx1) {
  84. var $2,$3,$1;
  85. $2=_st(aClass)._isMetaclass();
  86. if(smalltalk.assert($2)){
  87. $1=_st(_st(_st(aClass)._instanceClass())._name()).__comma(".klass");
  88. } else {
  89. $3=_st(aClass)._isNil();
  90. if(smalltalk.assert($3)){
  91. $1="nil";
  92. } else {
  93. $1=_st(aClass)._name();
  94. };
  95. };
  96. return $1;
  97. }, function($ctx1) {$ctx1.fill(self,"classNameFor:",{aClass:aClass},smalltalk.Exporter)})},
  98. args: ["aClass"],
  99. source: "classNameFor: aClass\x0a\x09^aClass isMetaclass\x0a\x09\x09ifTrue: [aClass instanceClass name, '.klass']\x0a\x09\x09ifFalse: [\x0a\x09\x09aClass isNil\x0a\x09\x09\x09ifTrue: ['nil']\x0a\x09\x09\x09ifFalse: [aClass name]]",
  100. messageSends: ["ifTrue:ifFalse:", ",", "name", "instanceClass", "isNil", "isMetaclass"],
  101. referencedClasses: []
  102. }),
  103. smalltalk.Exporter);
  104. smalltalk.addMethod(
  105. smalltalk.method({
  106. selector: "exportAll",
  107. category: 'fileOut',
  108. fn: function (){
  109. var self=this;
  110. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  111. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  112. return smalltalk.withContext(function($ctx1) {
  113. var $1;
  114. $1=_st($String())._streamContents_((function(stream){
  115. return smalltalk.withContext(function($ctx2) {
  116. return _st(_st(_st($Smalltalk())._current())._packages())._do_((function(pkg){
  117. return smalltalk.withContext(function($ctx3) {
  118. return _st(stream)._nextPutAll_(_st(self)._exportPackage_(_st(pkg)._name()));
  119. }, function($ctx3) {$ctx3.fillBlock({pkg:pkg},$ctx1)})}));
  120. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1)})}));
  121. return $1;
  122. }, function($ctx1) {$ctx1.fill(self,"exportAll",{},smalltalk.Exporter)})},
  123. args: [],
  124. source: "exportAll\x0a\x09\x22Export all packages in the system.\x22\x0a\x0a\x09^String streamContents: [:stream |\x0a\x09\x09Smalltalk current packages do: [:pkg |\x0a\x09\x09stream nextPutAll: (self exportPackage: pkg name)]]",
  125. messageSends: ["streamContents:", "do:", "nextPutAll:", "exportPackage:", "name", "packages", "current"],
  126. referencedClasses: ["Smalltalk", "String"]
  127. }),
  128. smalltalk.Exporter);
  129. smalltalk.addMethod(
  130. smalltalk.method({
  131. selector: "exportClass:",
  132. category: 'fileOut',
  133. fn: function (aClass){
  134. var self=this;
  135. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  136. return smalltalk.withContext(function($ctx1) {
  137. var $1;
  138. $1=_st($String())._streamContents_((function(stream){
  139. return smalltalk.withContext(function($ctx2) {
  140. _st(self)._exportDefinitionOf_on_(aClass,stream);
  141. _st(self)._exportMethodsOf_on_(aClass,stream);
  142. _st(self)._exportMetaDefinitionOf_on_(aClass,stream);
  143. return _st(self)._exportMethodsOf_on_(_st(aClass)._class(),stream);
  144. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1)})}));
  145. return $1;
  146. }, function($ctx1) {$ctx1.fill(self,"exportClass:",{aClass:aClass},smalltalk.Exporter)})},
  147. args: ["aClass"],
  148. source: "exportClass: aClass\x0a\x09\x22Export a single class. Subclasses override these methods.\x22\x0a\x0a\x09^String streamContents: [:stream |\x0a\x09\x09self exportDefinitionOf: aClass on: stream.\x0a\x09\x09self exportMethodsOf: aClass on: stream.\x0a\x09\x09self exportMetaDefinitionOf: aClass on: stream.\x0a\x09\x09self exportMethodsOf: aClass class on: stream]",
  149. messageSends: ["streamContents:", "exportDefinitionOf:on:", "exportMethodsOf:on:", "exportMetaDefinitionOf:on:", "class"],
  150. referencedClasses: ["String"]
  151. }),
  152. smalltalk.Exporter);
  153. smalltalk.addMethod(
  154. smalltalk.method({
  155. selector: "exportDefinitionOf:on:",
  156. category: 'private',
  157. fn: function (aClass,aStream){
  158. var self=this;
  159. return smalltalk.withContext(function($ctx1) {
  160. var $1,$2,$3,$4,$5,$6,$7;
  161. $1=aStream;
  162. _st($1)._nextPutAll_("smalltalk.addClass(");
  163. _st($1)._nextPutAll_(_st(_st("'").__comma(_st(self)._classNameFor_(aClass))).__comma("', "));
  164. _st($1)._nextPutAll_(_st("smalltalk.").__comma(_st(self)._classNameFor_(_st(aClass)._superclass())));
  165. $2=_st($1)._nextPutAll_(", [");
  166. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  167. return smalltalk.withContext(function($ctx2) {
  168. return _st(aStream)._nextPutAll_(_st(_st("'").__comma(each)).__comma("'"));
  169. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  170. return smalltalk.withContext(function($ctx2) {
  171. return _st(aStream)._nextPutAll_(", ");
  172. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  173. $3=aStream;
  174. _st($3)._nextPutAll_("], '");
  175. _st($3)._nextPutAll_(_st(_st(aClass)._category()).__comma("'"));
  176. $4=_st($3)._nextPutAll_(");");
  177. $5=_st(_st(aClass)._comment())._notEmpty();
  178. if(smalltalk.assert($5)){
  179. $6=aStream;
  180. _st($6)._lf();
  181. _st($6)._nextPutAll_("smalltalk.");
  182. _st($6)._nextPutAll_(_st(self)._classNameFor_(aClass));
  183. _st($6)._nextPutAll_(".comment=");
  184. $7=_st($6)._nextPutAll_(_st(_st(aClass)._comment())._asJavascript());
  185. $7;
  186. };
  187. _st(aStream)._lf();
  188. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.Exporter)})},
  189. args: ["aClass", "aStream"],
  190. source: "exportDefinitionOf: aClass on: aStream\x0a\x09aStream\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\x09aStream lf",
  191. messageSends: ["nextPutAll:", ",", "classNameFor:", "superclass", "do:separatedBy:", "instanceVariableNames", "category", "ifTrue:", "lf", "asJavascript", "comment", "notEmpty"],
  192. referencedClasses: []
  193. }),
  194. smalltalk.Exporter);
  195. smalltalk.addMethod(
  196. smalltalk.method({
  197. selector: "exportMetaDefinitionOf:on:",
  198. category: 'private',
  199. fn: function (aClass,aStream){
  200. var self=this;
  201. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  202. return smalltalk.withContext(function($ctx1) {
  203. var $1,$2,$3;
  204. $1=_st(_st(_st(aClass)._class())._instanceVariableNames())._isEmpty();
  205. if(! smalltalk.assert($1)){
  206. $2=aStream;
  207. _st($2)._nextPutAll_(_st("smalltalk.").__comma(_st(self)._classNameFor_(_st(aClass)._class())));
  208. $3=_st($2)._nextPutAll_(".iVarNames = [");
  209. $3;
  210. _st(_st(_st(aClass)._class())._instanceVariableNames())._do_separatedBy_((function(each){
  211. return smalltalk.withContext(function($ctx2) {
  212. return _st(aStream)._nextPutAll_(_st(_st("'").__comma(each)).__comma("'"));
  213. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  214. return smalltalk.withContext(function($ctx2) {
  215. return _st(aStream)._nextPutAll_(",");
  216. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  217. _st(aStream)._nextPutAll_(_st("];").__comma(_st($String())._lf()));
  218. };
  219. return self}, function($ctx1) {$ctx1.fill(self,"exportMetaDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.Exporter)})},
  220. args: ["aClass", "aStream"],
  221. source: "exportMetaDefinitionOf: aClass on: aStream\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]",
  222. messageSends: ["ifFalse:", "nextPutAll:", ",", "classNameFor:", "class", "do:separatedBy:", "instanceVariableNames", "lf", "isEmpty"],
  223. referencedClasses: ["String"]
  224. }),
  225. smalltalk.Exporter);
  226. smalltalk.addMethod(
  227. smalltalk.method({
  228. selector: "exportMethod:of:on:",
  229. category: 'private',
  230. fn: function (aMethod,aClass,aStream){
  231. var self=this;
  232. return smalltalk.withContext(function($ctx1) {
  233. var $1,$2,$3,$4;
  234. $1=aStream;
  235. _st($1)._nextPutAll_("smalltalk.addMethod(");
  236. _st($1)._lf();
  237. _st($1)._nextPutAll_("smalltalk.method({");
  238. _st($1)._lf();
  239. _st($1)._nextPutAll_(_st(_st("selector: ").__comma(_st(_st(aMethod)._selector())._asJavascript())).__comma(","));
  240. _st($1)._lf();
  241. _st($1)._nextPutAll_(_st(_st("category: '").__comma(_st(aMethod)._category())).__comma("',"));
  242. _st($1)._lf();
  243. _st($1)._nextPutAll_(_st(_st("fn: ").__comma(_st(_st(aMethod)._fn())._compiledSource())).__comma(","));
  244. _st($1)._lf();
  245. _st($1)._nextPutAll_(_st(_st("args: ").__comma(_st(_st(aMethod)._arguments())._asJavascript())).__comma(","));
  246. _st($1)._lf();
  247. _st($1)._nextPutAll_(_st(_st("source: ").__comma(_st(_st(aMethod)._source())._asJavascript())).__comma(","));
  248. _st($1)._lf();
  249. _st($1)._nextPutAll_(_st(_st("messageSends: ").__comma(_st(_st(aMethod)._messageSends())._asJavascript())).__comma(","));
  250. _st($1)._lf();
  251. $2=_st($1)._nextPutAll_(_st("referencedClasses: ").__comma(_st(_st(aMethod)._referencedClasses())._asJavascript()));
  252. $3=aStream;
  253. _st($3)._lf();
  254. _st($3)._nextPutAll_("}),");
  255. _st($3)._lf();
  256. _st($3)._nextPutAll_(_st("smalltalk.").__comma(_st(self)._classNameFor_(aClass)));
  257. _st($3)._nextPutAll_(");");
  258. _st($3)._lf();
  259. $4=_st($3)._lf();
  260. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:of:on:",{aMethod:aMethod,aClass:aClass,aStream:aStream},smalltalk.Exporter)})},
  261. args: ["aMethod", "aClass", "aStream"],
  262. source: "exportMethod: aMethod of: aClass 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: aClass);\x0a\x09\x09nextPutAll: ');';lf;lf",
  263. messageSends: ["nextPutAll:", "lf", ",", "asJavascript", "selector", "category", "compiledSource", "fn", "arguments", "source", "messageSends", "referencedClasses", "classNameFor:"],
  264. referencedClasses: []
  265. }),
  266. smalltalk.Exporter);
  267. smalltalk.addMethod(
  268. smalltalk.method({
  269. selector: "exportMethodsOf:on:",
  270. category: 'private',
  271. fn: function (aClass,aStream){
  272. var self=this;
  273. return smalltalk.withContext(function($ctx1) {
  274. var $1;
  275. _st(_st(_st(_st(aClass)._methodDictionary())._values())._sorted_((function(a,b){
  276. return smalltalk.withContext(function($ctx2) {
  277. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  278. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})})))._do_((function(each){
  279. return smalltalk.withContext(function($ctx2) {
  280. $1=_st(_st(each)._category())._match_("^\x5c*");
  281. if(! smalltalk.assert($1)){
  282. return _st(self)._exportMethod_of_on_(each,aClass,aStream);
  283. };
  284. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  285. _st(aStream)._lf();
  286. return self}, function($ctx1) {$ctx1.fill(self,"exportMethodsOf:on:",{aClass:aClass,aStream:aStream},smalltalk.Exporter)})},
  287. args: ["aClass", "aStream"],
  288. source: "exportMethodsOf: aClass on: aStream\x0a\x09\x22Issue #143: sort methods alphabetically\x22\x0a\x0a\x09((aClass methodDictionary values) sorted: [:a :b | a selector <= b selector]) do: [:each |\x0a\x09\x09(each category match: '^\x5c*') ifFalse: [\x0a\x09\x09\x09self exportMethod: each of: aClass on: aStream]].\x0a\x09aStream lf",
  289. messageSends: ["do:", "ifFalse:", "exportMethod:of:on:", "match:", "category", "sorted:", "<=", "selector", "values", "methodDictionary", "lf"],
  290. referencedClasses: []
  291. }),
  292. smalltalk.Exporter);
  293. smalltalk.addMethod(
  294. smalltalk.method({
  295. selector: "exportPackage:",
  296. category: 'fileOut',
  297. fn: function (packageName){
  298. var self=this;
  299. var package_;
  300. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  301. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  302. return smalltalk.withContext(function($ctx1) {
  303. var $1;
  304. $1=_st($String())._streamContents_((function(stream){
  305. return smalltalk.withContext(function($ctx2) {
  306. package_=_st(_st($Smalltalk())._current())._packageAt_(packageName);
  307. package_;
  308. _st(self)._exportPackageDefinitionOf_on_(package_,stream);
  309. _st(_st(_st(package_)._sortedClasses())._asSet())._do_((function(each){
  310. return smalltalk.withContext(function($ctx3) {
  311. return _st(stream)._nextPutAll_(_st(self)._exportClass_(each));
  312. }, function($ctx3) {$ctx3.fillBlock({each:each},$ctx1)})}));
  313. return _st(self)._exportPackageExtensionsOf_on_(package_,stream);
  314. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1)})}));
  315. return $1;
  316. }, function($ctx1) {$ctx1.fill(self,"exportPackage:",{packageName:packageName,package_:package_},smalltalk.Exporter)})},
  317. args: ["packageName"],
  318. source: "exportPackage: packageName\x0a\x09\x22Export a given package by name.\x22\x0a\x0a\x09| package |\x0a\x09^String streamContents: [:stream |\x0a\x09\x09\x09\x09package := Smalltalk current packageAt: packageName.\x0a\x09\x09\x09\x09self exportPackageDefinitionOf: package on: stream.\x0a\x0a\x09\x09\x22Export classes in dependency order.\x0a\x09\x09Update (issue #171): Remove duplicates for export\x22\x0a\x09\x09\x09package sortedClasses asSet do: [:each |\x0a\x09\x09\x09\x09\x09\x09stream nextPutAll: (self exportClass: each)].\x0a\x09\x09self exportPackageExtensionsOf: package on: stream]",
  319. messageSends: ["streamContents:", "packageAt:", "current", "exportPackageDefinitionOf:on:", "do:", "nextPutAll:", "exportClass:", "asSet", "sortedClasses", "exportPackageExtensionsOf:on:"],
  320. referencedClasses: ["Smalltalk", "String"]
  321. }),
  322. smalltalk.Exporter);
  323. smalltalk.addMethod(
  324. smalltalk.method({
  325. selector: "exportPackageDefinitionOf:on:",
  326. category: 'private',
  327. fn: function (package_,aStream){
  328. var self=this;
  329. return smalltalk.withContext(function($ctx1) {
  330. var $1,$2;
  331. $1=aStream;
  332. _st($1)._nextPutAll_("smalltalk.addPackage(");
  333. _st($1)._nextPutAll_(_st(_st("'").__comma(_st(package_)._name())).__comma("');"));
  334. $2=_st($1)._lf();
  335. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageDefinitionOf:on:",{package_:package_,aStream:aStream},smalltalk.Exporter)})},
  336. args: ["package", "aStream"],
  337. source: "exportPackageDefinitionOf: package on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: 'smalltalk.addPackage(';\x0a\x09\x09nextPutAll: '''', package name, ''');';\x0a\x09\x09lf",
  338. messageSends: ["nextPutAll:", ",", "name", "lf"],
  339. referencedClasses: []
  340. }),
  341. smalltalk.Exporter);
  342. smalltalk.addMethod(
  343. smalltalk.method({
  344. selector: "exportPackageExtensionsOf:on:",
  345. category: 'private',
  346. fn: function (package_,aStream){
  347. var self=this;
  348. var name;
  349. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  350. function $Package(){return smalltalk.Package||(typeof Package=="undefined"?nil:Package)}
  351. return smalltalk.withContext(function($ctx1) {
  352. var $1;
  353. name=_st(package_)._name();
  354. _st(_st($Package())._sortedClasses_(_st(_st($Smalltalk())._current())._classes()))._do_((function(each){
  355. return smalltalk.withContext(function($ctx2) {
  356. return _st([each,_st(each)._class()])._do_((function(aClass){
  357. return smalltalk.withContext(function($ctx3) {
  358. return _st(_st(_st(_st(aClass)._methodDictionary())._values())._sorted_((function(a,b){
  359. return smalltalk.withContext(function($ctx4) {
  360. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  361. }, function($ctx4) {$ctx4.fillBlock({a:a,b:b},$ctx1)})})))._do_((function(method){
  362. return smalltalk.withContext(function($ctx4) {
  363. $1=_st(_st(method)._category())._match_(_st("^\x5c*").__comma(name));
  364. if(smalltalk.assert($1)){
  365. return _st(self)._exportMethod_of_on_(method,aClass,aStream);
  366. };
  367. }, function($ctx4) {$ctx4.fillBlock({method:method},$ctx1)})}));
  368. }, function($ctx3) {$ctx3.fillBlock({aClass:aClass},$ctx1)})}));
  369. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  370. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageExtensionsOf:on:",{package_:package_,aStream:aStream,name:name},smalltalk.Exporter)})},
  371. args: ["package", "aStream"],
  372. source: "exportPackageExtensionsOf: package on: aStream\x0a\x09\x22Issue #143: sort classes and methods alphabetically\x22\x0a\x0a\x09| name |\x0a\x09name := package name.\x0a\x09(Package sortedClasses: Smalltalk current classes) do: [:each |\x0a\x09\x09{each. each class} do: [:aClass |\x0a\x09\x09\x09((aClass methodDictionary values) sorted: [:a :b | a selector <= b selector]) do: [:method |\x0a\x09\x09\x09\x09(method category match: '^\x5c*', name) ifTrue: [\x0a\x09\x09\x09\x09\x09self exportMethod: method of: aClass on: aStream ]]]]",
  373. messageSends: ["name", "do:", "ifTrue:", "exportMethod:of:on:", "match:", ",", "category", "sorted:", "<=", "selector", "values", "methodDictionary", "class", "sortedClasses:", "classes", "current"],
  374. referencedClasses: ["Smalltalk", "Package"]
  375. }),
  376. smalltalk.Exporter);
  377. smalltalk.addClass('ChunkExporter', smalltalk.Exporter, [], 'Importer-Exporter');
  378. smalltalk.addMethod(
  379. smalltalk.method({
  380. selector: "chunkEscape:",
  381. category: 'not yet classified',
  382. fn: function (aString){
  383. var self=this;
  384. return smalltalk.withContext(function($ctx1) {
  385. var $1;
  386. $1=_st(_st(aString)._replace_with_("!","!!"))._trimBoth();
  387. return $1;
  388. }, function($ctx1) {$ctx1.fill(self,"chunkEscape:",{aString:aString},smalltalk.ChunkExporter)})},
  389. args: ["aString"],
  390. source: "chunkEscape: aString\x0a\x09\x22Replace all occurrences of ! with !! and trim at both ends.\x22\x0a\x0a\x09^(aString replace: '!' with: '!!') trimBoth",
  391. messageSends: ["trimBoth", "replace:with:"],
  392. referencedClasses: []
  393. }),
  394. smalltalk.ChunkExporter);
  395. smalltalk.addMethod(
  396. smalltalk.method({
  397. selector: "classNameFor:",
  398. category: 'not yet classified',
  399. fn: function (aClass){
  400. var self=this;
  401. return smalltalk.withContext(function($ctx1) {
  402. var $2,$3,$1;
  403. $2=_st(aClass)._isMetaclass();
  404. if(smalltalk.assert($2)){
  405. $1=_st(_st(_st(aClass)._instanceClass())._name()).__comma(" class");
  406. } else {
  407. $3=_st(aClass)._isNil();
  408. if(smalltalk.assert($3)){
  409. $1="nil";
  410. } else {
  411. $1=_st(aClass)._name();
  412. };
  413. };
  414. return $1;
  415. }, function($ctx1) {$ctx1.fill(self,"classNameFor:",{aClass:aClass},smalltalk.ChunkExporter)})},
  416. args: ["aClass"],
  417. source: "classNameFor: aClass\x0a\x09^aClass isMetaclass\x0a\x09\x09ifTrue: [aClass instanceClass name, ' class']\x0a\x09\x09ifFalse: [\x0a\x09\x09aClass isNil\x0a\x09\x09\x09ifTrue: ['nil']\x0a\x09\x09\x09ifFalse: [aClass name]]",
  418. messageSends: ["ifTrue:ifFalse:", ",", "name", "instanceClass", "isNil", "isMetaclass"],
  419. referencedClasses: []
  420. }),
  421. smalltalk.ChunkExporter);
  422. smalltalk.addMethod(
  423. smalltalk.method({
  424. selector: "exportDefinitionOf:on:",
  425. category: 'not yet classified',
  426. fn: function (aClass,aStream){
  427. var self=this;
  428. return smalltalk.withContext(function($ctx1) {
  429. var $1,$2,$3,$4,$5,$6,$7;
  430. $1=aStream;
  431. _st($1)._nextPutAll_(_st(self)._classNameFor_(_st(aClass)._superclass()));
  432. _st($1)._nextPutAll_(_st(" subclass: #").__comma(_st(self)._classNameFor_(aClass)));
  433. _st($1)._lf();
  434. _st($1)._tab();
  435. $2=_st($1)._nextPutAll_("instanceVariableNames: '");
  436. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  437. return smalltalk.withContext(function($ctx2) {
  438. return _st(aStream)._nextPutAll_(each);
  439. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  440. return smalltalk.withContext(function($ctx2) {
  441. return _st(aStream)._nextPutAll_(" ");
  442. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  443. $3=aStream;
  444. _st($3)._nextPutAll_("'");
  445. _st($3)._lf();
  446. _st($3)._tab();
  447. _st($3)._nextPutAll_(_st(_st("package: '").__comma(_st(aClass)._category())).__comma("'!"));
  448. $4=_st($3)._lf();
  449. $5=_st(_st(aClass)._comment())._notEmpty();
  450. if(smalltalk.assert($5)){
  451. $6=aStream;
  452. _st($6)._nextPutAll_(_st(_st("!").__comma(_st(self)._classNameFor_(aClass))).__comma(" commentStamp!"));
  453. _st($6)._lf();
  454. _st($6)._nextPutAll_(_st(_st(self)._chunkEscape_(_st(aClass)._comment())).__comma("!"));
  455. $7=_st($6)._lf();
  456. $7;
  457. };
  458. _st(aStream)._lf();
  459. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.ChunkExporter)})},
  460. args: ["aClass", "aStream"],
  461. 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",
  462. messageSends: ["nextPutAll:", "classNameFor:", "superclass", ",", "lf", "tab", "do:separatedBy:", "instanceVariableNames", "category", "ifTrue:", "chunkEscape:", "comment", "notEmpty"],
  463. referencedClasses: []
  464. }),
  465. smalltalk.ChunkExporter);
  466. smalltalk.addMethod(
  467. smalltalk.method({
  468. selector: "exportMetaDefinitionOf:on:",
  469. category: 'not yet classified',
  470. fn: function (aClass,aStream){
  471. var self=this;
  472. return smalltalk.withContext(function($ctx1) {
  473. var $1,$2,$3,$4,$5;
  474. $1=_st(_st(_st(aClass)._class())._instanceVariableNames())._isEmpty();
  475. if(! smalltalk.assert($1)){
  476. $2=aStream;
  477. _st($2)._nextPutAll_(_st(self)._classNameFor_(_st(aClass)._class()));
  478. $3=_st($2)._nextPutAll_(" instanceVariableNames: '");
  479. $3;
  480. _st(_st(_st(aClass)._class())._instanceVariableNames())._do_separatedBy_((function(each){
  481. return smalltalk.withContext(function($ctx2) {
  482. return _st(aStream)._nextPutAll_(each);
  483. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  484. return smalltalk.withContext(function($ctx2) {
  485. return _st(aStream)._nextPutAll_(" ");
  486. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  487. $4=aStream;
  488. _st($4)._nextPutAll_("'!");
  489. _st($4)._lf();
  490. $5=_st($4)._lf();
  491. $5;
  492. };
  493. return self}, function($ctx1) {$ctx1.fill(self,"exportMetaDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.ChunkExporter)})},
  494. args: ["aClass", "aStream"],
  495. 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]",
  496. messageSends: ["ifFalse:", "nextPutAll:", "classNameFor:", "class", "do:separatedBy:", "instanceVariableNames", "lf", "isEmpty"],
  497. referencedClasses: []
  498. }),
  499. smalltalk.ChunkExporter);
  500. smalltalk.addMethod(
  501. smalltalk.method({
  502. selector: "exportMethod:of:on:",
  503. category: 'not yet classified',
  504. fn: function (aMethod,aClass,aStream){
  505. var self=this;
  506. return smalltalk.withContext(function($ctx1) {
  507. var $1,$2;
  508. $1=aStream;
  509. _st($1)._lf();
  510. _st($1)._lf();
  511. _st($1)._nextPutAll_(_st(self)._chunkEscape_(_st(aMethod)._source()));
  512. _st($1)._lf();
  513. $2=_st($1)._nextPutAll_("!");
  514. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:of:on:",{aMethod:aMethod,aClass:aClass,aStream:aStream},smalltalk.ChunkExporter)})},
  515. args: ["aMethod", "aClass", "aStream"],
  516. source: "exportMethod: aMethod of: aClass on: aStream\x0a\x09aStream\x0a\x09\x09lf; lf; nextPutAll: (self chunkEscape: aMethod source); lf;\x0a\x09\x09nextPutAll: '!'",
  517. messageSends: ["lf", "nextPutAll:", "chunkEscape:", "source"],
  518. referencedClasses: []
  519. }),
  520. smalltalk.ChunkExporter);
  521. smalltalk.addMethod(
  522. smalltalk.method({
  523. selector: "exportMethods:category:of:on:",
  524. category: 'not yet classified',
  525. fn: function (methods,category,aClass,aStream){
  526. var self=this;
  527. return smalltalk.withContext(function($ctx1) {
  528. var $1,$2,$3,$4;
  529. $1=aStream;
  530. _st($1)._nextPutAll_(_st("!").__comma(_st(self)._classNameFor_(aClass)));
  531. $2=_st($1)._nextPutAll_(_st(_st(" methodsFor: '").__comma(category)).__comma("'!"));
  532. _st(_st(methods)._sorted_((function(a,b){
  533. return smalltalk.withContext(function($ctx2) {
  534. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  535. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})})))._do_((function(each){
  536. return smalltalk.withContext(function($ctx2) {
  537. return _st(self)._exportMethod_of_on_(each,aClass,aStream);
  538. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  539. $3=aStream;
  540. _st($3)._nextPutAll_(" !");
  541. _st($3)._lf();
  542. $4=_st($3)._lf();
  543. return self}, function($ctx1) {$ctx1.fill(self,"exportMethods:category:of:on:",{methods:methods,category:category,aClass:aClass,aStream:aStream},smalltalk.ChunkExporter)})},
  544. args: ["methods", "category", "aClass", "aStream"],
  545. source: "exportMethods: methods category: category of: aClass on: aStream\x0a\x09\x22Issue #143: sort methods alphabetically\x22\x0a\x0a\x09aStream\x0a\x09\x09nextPutAll: '!', (self classNameFor: aClass);\x0a\x09\x09nextPutAll: ' methodsFor: ''', category, '''!'.\x0a\x09\x09(methods sorted: [:a :b | a selector <= b selector]) do: [:each |\x0a\x09\x09\x09\x09self exportMethod: each of: aClass on: aStream].\x0a\x09aStream nextPutAll: ' !'; lf; lf",
  546. messageSends: ["nextPutAll:", ",", "classNameFor:", "do:", "exportMethod:of:on:", "sorted:", "<=", "selector", "lf"],
  547. referencedClasses: []
  548. }),
  549. smalltalk.ChunkExporter);
  550. smalltalk.addMethod(
  551. smalltalk.method({
  552. selector: "exportMethodsOf:on:",
  553. category: 'not yet classified',
  554. fn: function (aClass,aStream){
  555. var self=this;
  556. var map;
  557. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  558. return smalltalk.withContext(function($ctx1) {
  559. var $1;
  560. map=_st($Dictionary())._new();
  561. _st(aClass)._protocolsDo_((function(category,methods){
  562. return smalltalk.withContext(function($ctx2) {
  563. $1=_st(category)._match_("^\x5c*");
  564. if(! smalltalk.assert($1)){
  565. return _st(map)._at_put_(category,methods);
  566. };
  567. }, function($ctx2) {$ctx2.fillBlock({category:category,methods:methods},$ctx1)})}));
  568. _st(_st(_st(map)._keys())._sorted_((function(a,b){
  569. return smalltalk.withContext(function($ctx2) {
  570. return _st(a).__lt_eq(b);
  571. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})})))._do_((function(category){
  572. var methods;
  573. return smalltalk.withContext(function($ctx2) {
  574. methods=_st(map)._at_(category);
  575. methods;
  576. return _st(self)._exportMethods_category_of_on_(methods,category,aClass,aStream);
  577. }, function($ctx2) {$ctx2.fillBlock({category:category,methods:methods},$ctx1)})}));
  578. return self}, function($ctx1) {$ctx1.fill(self,"exportMethodsOf:on:",{aClass:aClass,aStream:aStream,map:map},smalltalk.ChunkExporter)})},
  579. args: ["aClass", "aStream"],
  580. source: "exportMethodsOf: aClass on: aStream\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 ]) do: [:category | | methods |\x0a\x09\x09methods := map at: category.\x0a\x09\x09self\x0a\x09\x09\x09exportMethods: methods\x0a\x09\x09\x09category: category\x0a\x09\x09\x09of: aClass\x0a\x09\x09\x09on: aStream ]",
  581. messageSends: ["new", "protocolsDo:", "ifFalse:", "at:put:", "match:", "do:", "at:", "exportMethods:category:of:on:", "sorted:", "<=", "keys"],
  582. referencedClasses: ["Dictionary"]
  583. }),
  584. smalltalk.ChunkExporter);
  585. smalltalk.addMethod(
  586. smalltalk.method({
  587. selector: "exportPackageDefinitionOf:on:",
  588. category: 'not yet classified',
  589. fn: function (package_,aStream){
  590. var self=this;
  591. return smalltalk.withContext(function($ctx1) {
  592. var $1,$2;
  593. $1=aStream;
  594. _st($1)._nextPutAll_(_st(_st("Smalltalk current createPackage: '").__comma(_st(package_)._name())).__comma("'!"));
  595. $2=_st($1)._lf();
  596. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageDefinitionOf:on:",{package_:package_,aStream:aStream},smalltalk.ChunkExporter)})},
  597. args: ["package", "aStream"],
  598. source: "exportPackageDefinitionOf: package on: aStream\x0a\x09\x22Chunk format.\x22\x0a\x0a\x09aStream\x0a\x09\x09nextPutAll: 'Smalltalk current createPackage: ''', package name, '''!';\x0a\x09\x09lf",
  599. messageSends: ["nextPutAll:", ",", "name", "lf"],
  600. referencedClasses: []
  601. }),
  602. smalltalk.ChunkExporter);
  603. smalltalk.addMethod(
  604. smalltalk.method({
  605. selector: "exportPackageExtensionsOf:on:",
  606. category: 'not yet classified',
  607. fn: function (package_,aStream){
  608. var self=this;
  609. var name,map;
  610. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  611. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  612. function $Package(){return smalltalk.Package||(typeof Package=="undefined"?nil:Package)}
  613. return smalltalk.withContext(function($ctx1) {
  614. var $1;
  615. name=_st(package_)._name();
  616. _st(_st($Package())._sortedClasses_(_st(_st($Smalltalk())._current())._classes()))._do_((function(each){
  617. return smalltalk.withContext(function($ctx2) {
  618. return _st([each,_st(each)._class()])._do_((function(aClass){
  619. return smalltalk.withContext(function($ctx3) {
  620. map=_st($Dictionary())._new();
  621. map;
  622. _st(aClass)._protocolsDo_((function(category,methods){
  623. return smalltalk.withContext(function($ctx4) {
  624. $1=_st(category)._match_(_st("^\x5c*").__comma(name));
  625. if(smalltalk.assert($1)){
  626. return _st(map)._at_put_(category,methods);
  627. };
  628. }, function($ctx4) {$ctx4.fillBlock({category:category,methods:methods},$ctx1)})}));
  629. return _st(_st(_st(map)._keys())._sorted_((function(a,b){
  630. return smalltalk.withContext(function($ctx4) {
  631. return _st(a).__lt_eq(b);
  632. }, function($ctx4) {$ctx4.fillBlock({a:a,b:b},$ctx1)})})))._do_((function(category){
  633. var methods;
  634. return smalltalk.withContext(function($ctx4) {
  635. methods=_st(map)._at_(category);
  636. methods;
  637. return _st(self)._exportMethods_category_of_on_(methods,category,aClass,aStream);
  638. }, function($ctx4) {$ctx4.fillBlock({category:category,methods:methods},$ctx1)})}));
  639. }, function($ctx3) {$ctx3.fillBlock({aClass:aClass},$ctx1)})}));
  640. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  641. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageExtensionsOf:on:",{package_:package_,aStream:aStream,name:name,map:map},smalltalk.ChunkExporter)})},
  642. args: ["package", "aStream"],
  643. source: "exportPackageExtensionsOf: package on: aStream\x0a\x09\x22We need to override this one too since we need to group\x0a\x09all methods in a given protocol under a leading methodsFor: chunk\x0a\x09for that class.\x22\x0a\x0a\x09\x22Issue #143: sort protocol alphabetically\x22\x0a\x0a\x09| name map |\x0a\x09name := package name.\x0a\x09(Package sortedClasses: Smalltalk current classes) do: [:each |\x0a\x09\x09{each. each class} do: [:aClass |\x0a\x09\x09\x09map := Dictionary new.\x0a\x09\x09\x09aClass protocolsDo: [:category :methods |\x0a\x09\x09\x09\x09(category match: '^\x5c*', name) ifTrue: [ map at: category put: methods ]].\x0a\x09\x09\x09(map keys sorted: [:a :b | a <= b ]) do: [:category | | methods |\x0a\x09\x09\x09\x09methods := map at: category.\x0a\x09\x09\x09\x09self exportMethods: methods category: category of: aClass on: aStream ]]]",
  644. messageSends: ["name", "do:", "new", "protocolsDo:", "ifTrue:", "at:put:", "match:", ",", "at:", "exportMethods:category:of:on:", "sorted:", "<=", "keys", "class", "sortedClasses:", "classes", "current"],
  645. referencedClasses: ["Dictionary", "Smalltalk", "Package"]
  646. }),
  647. smalltalk.ChunkExporter);
  648. smalltalk.addClass('StrippedExporter', smalltalk.Exporter, [], 'Importer-Exporter');
  649. smalltalk.addMethod(
  650. smalltalk.method({
  651. selector: "exportDefinitionOf:on:",
  652. category: 'private',
  653. fn: function (aClass,aStream){
  654. var self=this;
  655. return smalltalk.withContext(function($ctx1) {
  656. var $1,$2,$3,$4;
  657. $1=aStream;
  658. _st($1)._nextPutAll_("smalltalk.addClass(");
  659. _st($1)._nextPutAll_(_st(_st("'").__comma(_st(self)._classNameFor_(aClass))).__comma("', "));
  660. _st($1)._nextPutAll_(_st("smalltalk.").__comma(_st(self)._classNameFor_(_st(aClass)._superclass())));
  661. $2=_st($1)._nextPutAll_(", [");
  662. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  663. return smalltalk.withContext(function($ctx2) {
  664. return _st(aStream)._nextPutAll_(_st(_st("'").__comma(each)).__comma("'"));
  665. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  666. return smalltalk.withContext(function($ctx2) {
  667. return _st(aStream)._nextPutAll_(", ");
  668. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  669. $3=aStream;
  670. _st($3)._nextPutAll_("], '");
  671. _st($3)._nextPutAll_(_st(_st(aClass)._category()).__comma("'"));
  672. $4=_st($3)._nextPutAll_(");");
  673. _st(aStream)._lf();
  674. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.StrippedExporter)})},
  675. args: ["aClass", "aStream"],
  676. source: "exportDefinitionOf: aClass on: aStream\x0a\x09aStream\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",
  677. messageSends: ["nextPutAll:", ",", "classNameFor:", "superclass", "do:separatedBy:", "instanceVariableNames", "category", "lf"],
  678. referencedClasses: []
  679. }),
  680. smalltalk.StrippedExporter);
  681. smalltalk.addMethod(
  682. smalltalk.method({
  683. selector: "exportMethod:of:on:",
  684. category: 'private',
  685. fn: function (aMethod,aClass,aStream){
  686. var self=this;
  687. return smalltalk.withContext(function($ctx1) {
  688. var $1,$2;
  689. $1=aStream;
  690. _st($1)._nextPutAll_("smalltalk.addMethod(");
  691. _st($1)._lf();
  692. _st($1)._nextPutAll_("smalltalk.method({");
  693. _st($1)._lf();
  694. _st($1)._nextPutAll_(_st(_st("selector: ").__comma(_st(_st(aMethod)._selector())._asJavascript())).__comma(","));
  695. _st($1)._lf();
  696. _st($1)._nextPutAll_(_st(_st("fn: ").__comma(_st(_st(aMethod)._fn())._compiledSource())).__comma(","));
  697. _st($1)._lf();
  698. _st($1)._nextPutAll_(_st("messageSends: ").__comma(_st(_st(aMethod)._messageSends())._asJavascript()));
  699. _st($1)._nextPutAll_("}),");
  700. _st($1)._lf();
  701. _st($1)._nextPutAll_(_st("smalltalk.").__comma(_st(self)._classNameFor_(aClass)));
  702. _st($1)._nextPutAll_(");");
  703. _st($1)._lf();
  704. $2=_st($1)._lf();
  705. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:of:on:",{aMethod:aMethod,aClass:aClass,aStream:aStream},smalltalk.StrippedExporter)})},
  706. args: ["aMethod", "aClass", "aStream"],
  707. source: "exportMethod: aMethod of: aClass 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: aClass);\x0a\x09\x09nextPutAll: ');';lf;lf",
  708. messageSends: ["nextPutAll:", "lf", ",", "asJavascript", "selector", "compiledSource", "fn", "messageSends", "classNameFor:"],
  709. referencedClasses: []
  710. }),
  711. smalltalk.StrippedExporter);
  712. smalltalk.addClass('Importer', smalltalk.Object, [], 'Importer-Exporter');
  713. smalltalk.addMethod(
  714. smalltalk.method({
  715. selector: "import:",
  716. category: 'fileIn',
  717. fn: function (aStream){
  718. var self=this;
  719. var chunk,result,parser,lastEmpty;
  720. function $ChunkParser(){return smalltalk.ChunkParser||(typeof ChunkParser=="undefined"?nil:ChunkParser)}
  721. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  722. return smalltalk.withContext(function($ctx1) {
  723. var $1,$2;
  724. parser=_st($ChunkParser())._on_(aStream);
  725. lastEmpty=false;
  726. _st((function(){
  727. return smalltalk.withContext(function($ctx2) {
  728. chunk=_st(parser)._nextChunk();
  729. chunk;
  730. return _st(chunk)._isNil();
  731. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileFalse_((function(){
  732. return smalltalk.withContext(function($ctx2) {
  733. $1=_st(chunk)._isEmpty();
  734. if(smalltalk.assert($1)){
  735. lastEmpty=true;
  736. return lastEmpty;
  737. } else {
  738. result=_st(_st($Compiler())._new())._evaluateExpression_(chunk);
  739. result;
  740. $2=lastEmpty;
  741. if(smalltalk.assert($2)){
  742. lastEmpty=false;
  743. lastEmpty;
  744. return _st(result)._scanFrom_(parser);
  745. };
  746. };
  747. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  748. return self}, function($ctx1) {$ctx1.fill(self,"import:",{aStream:aStream,chunk:chunk,result:result,parser:parser,lastEmpty:lastEmpty},smalltalk.Importer)})},
  749. args: ["aStream"],
  750. 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]]]",
  751. messageSends: ["on:", "whileFalse:", "ifTrue:ifFalse:", "evaluateExpression:", "new", "ifTrue:", "scanFrom:", "isEmpty", "nextChunk", "isNil"],
  752. referencedClasses: ["ChunkParser", "Compiler"]
  753. }),
  754. smalltalk.Importer);
  755. smalltalk.addClass('PackageHandler', smalltalk.Object, [], 'Importer-Exporter');
  756. smalltalk.addMethod(
  757. smalltalk.method({
  758. selector: "ajaxPutAt:data:",
  759. category: 'private',
  760. fn: function (aURL,aString){
  761. var self=this;
  762. return smalltalk.withContext(function($ctx1) {
  763. _st(jQuery)._ajax_options_(aURL,smalltalk.HashedCollection._fromPairs_([_st("type").__minus_gt("PUT"),_st("data").__minus_gt(aString),_st("contentType").__minus_gt("text/plain;charset=UTF-8"),_st("error").__minus_gt((function(xhr){
  764. return smalltalk.withContext(function($ctx2) {
  765. return _st(self)._error_(_st(_st(_st(_st("Commiting ").__comma(aURL)).__comma(" failed with reason: \x22")).__comma(_st(xhr)._responseText())).__comma("\x22"));
  766. }, function($ctx2) {$ctx2.fillBlock({xhr:xhr},$ctx1)})}))]));
  767. return self}, function($ctx1) {$ctx1.fill(self,"ajaxPutAt:data:",{aURL:aURL,aString:aString},smalltalk.PackageHandler)})},
  768. args: ["aURL", "aString"],
  769. source: "ajaxPutAt: aURL data: aString\x0a\x09jQuery\x0a\x09\x09ajax: aURL \x0a\x09\x09options: #{ \x0a\x09\x09\x09'type' -> 'PUT'.\x0a\x09\x09\x09'data' -> aString.\x0a\x09\x09\x09'contentType' -> 'text/plain;charset=UTF-8'.\x0a\x09\x09\x09'error' -> [ :xhr | self error: 'Commiting ' , aURL , ' failed with reason: \x22' , (xhr responseText) , '\x22'] }",
  770. messageSends: ["ajax:options:", "->", "error:", ",", "responseText"],
  771. referencedClasses: []
  772. }),
  773. smalltalk.PackageHandler);
  774. smalltalk.addMethod(
  775. smalltalk.method({
  776. selector: "commit:",
  777. category: 'committing',
  778. fn: function (aPackage){
  779. var self=this;
  780. function $Exporter(){return smalltalk.Exporter||(typeof Exporter=="undefined"?nil:Exporter)}
  781. function $StrippedExporter(){return smalltalk.StrippedExporter||(typeof StrippedExporter=="undefined"?nil:StrippedExporter)}
  782. function $ChunkExporter(){return smalltalk.ChunkExporter||(typeof ChunkExporter=="undefined"?nil:ChunkExporter)}
  783. return smalltalk.withContext(function($ctx1) {
  784. _st([_st($Exporter()).__minus_gt(_st(_st(_st(_st(aPackage)._commitPathJs()).__comma("/")).__comma(_st(aPackage)._name())).__comma(".js")),_st($StrippedExporter()).__minus_gt(_st(_st(_st(_st(aPackage)._commitPathJs()).__comma("/")).__comma(_st(aPackage)._name())).__comma(".deploy.js")),_st($ChunkExporter()).__minus_gt(_st(_st(_st(_st(aPackage)._commitPathSt()).__comma("/")).__comma(_st(aPackage)._name())).__comma(".st"))])._do_((function(commitStrategy){
  785. var fileContents;
  786. return smalltalk.withContext(function($ctx2) {
  787. fileContents=_st(_st(_st(commitStrategy)._key())._new())._exportPackage_(_st(aPackage)._name());
  788. fileContents;
  789. return _st(self)._ajaxPutAt_data_(_st(commitStrategy)._value(),fileContents);
  790. }, function($ctx2) {$ctx2.fillBlock({commitStrategy:commitStrategy,fileContents:fileContents},$ctx1)})}));
  791. return self}, function($ctx1) {$ctx1.fill(self,"commit:",{aPackage:aPackage},smalltalk.PackageHandler)})},
  792. args: ["aPackage"],
  793. source: "commit: aPackage\x0a\x09{ \x0a\x09\x09Exporter -> (aPackage commitPathJs, '/', aPackage name, '.js').\x0a\x09\x09StrippedExporter -> (aPackage commitPathJs, '/', aPackage name, '.deploy.js').\x0a\x09\x09ChunkExporter -> (aPackage commitPathSt, '/', aPackage name, '.st')\x0a\x09} \x0a\x09\x09do: [ :commitStrategy|| fileContents |\x0a\x09\x09\x09fileContents := (commitStrategy key new exportPackage: aPackage name).\x0a\x09\x09\x09self ajaxPutAt: commitStrategy value data: fileContents ]",
  794. messageSends: ["do:", "exportPackage:", "name", "new", "key", "ajaxPutAt:data:", "value", "->", ",", "commitPathJs", "commitPathSt"],
  795. referencedClasses: ["Exporter", "StrippedExporter", "ChunkExporter"]
  796. }),
  797. smalltalk.PackageHandler);
  798. smalltalk.addMethod(
  799. smalltalk.method({
  800. selector: "loadPackage:prefix:",
  801. category: 'loading',
  802. fn: function (packageName,aString){
  803. var self=this;
  804. var url;
  805. return smalltalk.withContext(function($ctx1) {
  806. var $1;
  807. url=_st(_st(_st(_st("/").__comma(aString)).__comma("/js/")).__comma(packageName)).__comma(".js");
  808. _st(jQuery)._ajax_options_(url,smalltalk.HashedCollection._fromPairs_([_st("type").__minus_gt("GET"),_st("dataType").__minus_gt("script"),_st("complete").__minus_gt((function(jqXHR,textStatus){
  809. return smalltalk.withContext(function($ctx2) {
  810. $1=_st(_st(jqXHR)._readyState()).__eq((4));
  811. if(smalltalk.assert($1)){
  812. return _st(self)._setupPackageNamed_prefix_(packageName,aString);
  813. };
  814. }, function($ctx2) {$ctx2.fillBlock({jqXHR:jqXHR,textStatus:textStatus},$ctx1)})})),_st("error").__minus_gt((function(){
  815. return smalltalk.withContext(function($ctx2) {
  816. return _st(window)._alert_(_st("Could not load package at: ").__comma(url));
  817. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))]));
  818. return self}, function($ctx1) {$ctx1.fill(self,"loadPackage:prefix:",{packageName:packageName,aString:aString,url:url},smalltalk.PackageHandler)})},
  819. args: ["packageName", "aString"],
  820. source: "loadPackage: packageName prefix: aString\x0a\x09| url |\x0a\x09url := '/', aString, '/js/', packageName, '.js'.\x0a\x09jQuery\x0a\x09\x09ajax: url\x0a\x09\x09options: #{\x0a\x09\x09\x09'type' -> 'GET'.\x0a\x09\x09\x09'dataType' -> 'script'.\x0a\x09\x09\x09'complete' -> [ :jqXHR :textStatus |\x0a\x09\x09\x09\x09jqXHR readyState = 4\x0a\x09\x09\x09\x09\x09ifTrue: [ self setupPackageNamed: packageName prefix: aString ] ].\x0a\x09\x09\x09'error' -> [ window alert: 'Could not load package at: ', url ]\x0a\x09\x09}",
  821. messageSends: [",", "ajax:options:", "->", "ifTrue:", "setupPackageNamed:prefix:", "=", "readyState", "alert:"],
  822. referencedClasses: []
  823. }),
  824. smalltalk.PackageHandler);
  825. smalltalk.addMethod(
  826. smalltalk.method({
  827. selector: "loadPackages:prefix:",
  828. category: 'loading',
  829. fn: function (aCollection,aString){
  830. var self=this;
  831. return smalltalk.withContext(function($ctx1) {
  832. _st(aCollection)._do_((function(each){
  833. return smalltalk.withContext(function($ctx2) {
  834. return _st(self)._loadPackage_prefix_(each,aString);
  835. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  836. return self}, function($ctx1) {$ctx1.fill(self,"loadPackages:prefix:",{aCollection:aCollection,aString:aString},smalltalk.PackageHandler)})},
  837. args: ["aCollection", "aString"],
  838. source: "loadPackages: aCollection prefix: aString\x0a\x09aCollection do: [ :each |\x0a\x09\x09self loadPackage: each prefix: aString ]",
  839. messageSends: ["do:", "loadPackage:prefix:"],
  840. referencedClasses: []
  841. }),
  842. smalltalk.PackageHandler);
  843. smalltalk.addMethod(
  844. smalltalk.method({
  845. selector: "setupPackageNamed:prefix:",
  846. category: 'private',
  847. fn: function (packageName,aString){
  848. var self=this;
  849. function $Package(){return smalltalk.Package||(typeof Package=="undefined"?nil:Package)}
  850. return smalltalk.withContext(function($ctx1) {
  851. var $1,$2;
  852. $1=_st($Package())._named_(packageName);
  853. _st($1)._setupClasses();
  854. _st($1)._commitPathJs_(_st(_st("/").__comma(aString)).__comma("/js"));
  855. $2=_st($1)._commitPathSt_(_st(_st("/").__comma(aString)).__comma("/st"));
  856. return self}, function($ctx1) {$ctx1.fill(self,"setupPackageNamed:prefix:",{packageName:packageName,aString:aString},smalltalk.PackageHandler)})},
  857. args: ["packageName", "aString"],
  858. source: "setupPackageNamed: packageName prefix: aString\x0a\x0a\x09(Package named: packageName)\x0a\x09\x09setupClasses;\x0a\x09\x09commitPathJs: '/', aString, '/js';\x0a\x09\x09commitPathSt: '/', aString, '/st'",
  859. messageSends: ["setupClasses", "named:", "commitPathJs:", ",", "commitPathSt:"],
  860. referencedClasses: ["Package"]
  861. }),
  862. smalltalk.PackageHandler);
  863. smalltalk.addMethod(
  864. smalltalk.method({
  865. selector: "loadPackages:prefix:",
  866. category: 'not yet classified',
  867. fn: function (aCollection,aString){
  868. var self=this;
  869. return smalltalk.withContext(function($ctx1) {
  870. var $1;
  871. $1=_st(_st(self)._new())._loadPackages_prefix_(aCollection,aString);
  872. return $1;
  873. }, function($ctx1) {$ctx1.fill(self,"loadPackages:prefix:",{aCollection:aCollection,aString:aString},smalltalk.PackageHandler.klass)})},
  874. args: ["aCollection", "aString"],
  875. source: "loadPackages: aCollection prefix: aString\x0a\x09^ self new loadPackages: aCollection prefix: aString",
  876. messageSends: ["loadPackages:prefix:", "new"],
  877. referencedClasses: []
  878. }),
  879. smalltalk.PackageHandler.klass);
  880. smalltalk.addMethod(
  881. smalltalk.method({
  882. selector: "commit",
  883. category: '*Importer-Exporter',
  884. fn: function (){
  885. var self=this;
  886. function $PackageHandler(){return smalltalk.PackageHandler||(typeof PackageHandler=="undefined"?nil:PackageHandler)}
  887. return smalltalk.withContext(function($ctx1) {
  888. var $1;
  889. $1=_st(_st($PackageHandler())._new())._commit_(self);
  890. return $1;
  891. }, function($ctx1) {$ctx1.fill(self,"commit",{},smalltalk.Package)})},
  892. args: [],
  893. source: "commit\x0a\x09^ PackageHandler new commit: self",
  894. messageSends: ["commit:", "new"],
  895. referencedClasses: ["PackageHandler"]
  896. }),
  897. smalltalk.Package);