2
0

Importer-Exporter.js 45 KB

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