Importer-Exporter.js 45 KB

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