1
0

Importer-Exporter.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  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 [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",
  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 ifTrue: [aClass instanceClass name, '.klass']\x0a\x09 ifFalse: [\x0a\x09\x09aClass isNil\x0a\x09\x09 ifTrue: ['nil']\x0a\x09\x09 ifFalse: [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 \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)]]",
  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 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",
  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 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]",
  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 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]",
  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. $2=_st($1)._nextPutAll_(_st(_st(_st(_st("'").__comma(_st(package_)._name())).__comma("', ")).__comma(_st(package_)._propertiesAsJSON())).__comma(");"));
  317. _st(aStream)._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 nextPutAll: 'smalltalk.addPackage(';\x0a\x09 nextPutAll: '''', package name, ''', ', package propertiesAsJSON , ');'.\x0a\x09aStream lf",
  321. messageSends: ["nextPutAll:", ",", "propertiesAsJSON", "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 ifTrue: [aClass instanceClass name, ' class']\x0a\x09 ifFalse: [\x0a\x09\x09aClass isNil\x0a\x09\x09 ifTrue: ['nil']\x0a\x09\x09 ifFalse: [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. $2=_st($1)._nextPutAll_("\x09instanceVariableNames: '");
  412. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  413. return smalltalk.withContext(function($ctx2) { return _st(aStream)._nextPutAll_(each);
  414. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  415. return smalltalk.withContext(function($ctx2) { return _st(aStream)._nextPutAll_(" ");
  416. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  417. $3=aStream;
  418. _st($3)._nextPutAll_("'");
  419. _st($3)._lf();
  420. _st($3)._nextPutAll_(_st(_st("\x09package: '").__comma(_st(aClass)._category())).__comma("'!"));
  421. $4=_st($3)._lf();
  422. $5=_st(_st(aClass)._comment())._notEmpty();
  423. if(smalltalk.assert($5)){
  424. $6=aStream;
  425. _st($6)._nextPutAll_(_st(_st("!").__comma(_st(self)._classNameFor_(aClass))).__comma(" commentStamp!"));
  426. _st($6)._lf();
  427. _st($6)._nextPutAll_(_st(_st(self)._chunkEscape_(_st(aClass)._comment())).__comma("!"));
  428. $7=_st($6)._lf();
  429. $7;
  430. };
  431. _st(aStream)._lf();
  432. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream}, smalltalk.ChunkExporter)})},
  433. args: ["aClass", "aStream"],
  434. 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",
  435. messageSends: ["nextPutAll:", "classNameFor:", "superclass", ",", "lf", "do:separatedBy:", "instanceVariableNames", "category", "ifTrue:", "chunkEscape:", "comment", "notEmpty"],
  436. referencedClasses: []
  437. }),
  438. smalltalk.ChunkExporter);
  439. smalltalk.addMethod(
  440. "_exportMetaDefinitionOf_on_",
  441. smalltalk.method({
  442. selector: "exportMetaDefinitionOf:on:",
  443. category: 'not yet classified',
  444. fn: function (aClass,aStream){
  445. var self=this;
  446. return smalltalk.withContext(function($ctx1) { var $1,$2,$3,$4,$5;
  447. $1=_st(_st(_st(aClass)._class())._instanceVariableNames())._isEmpty();
  448. if(! smalltalk.assert($1)){
  449. $2=aStream;
  450. _st($2)._nextPutAll_(_st(self)._classNameFor_(_st(aClass)._class()));
  451. $3=_st($2)._nextPutAll_(" instanceVariableNames: '");
  452. $3;
  453. _st(_st(_st(aClass)._class())._instanceVariableNames())._do_separatedBy_((function(each){
  454. return smalltalk.withContext(function($ctx2) { return _st(aStream)._nextPutAll_(each);
  455. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  456. return smalltalk.withContext(function($ctx2) { return _st(aStream)._nextPutAll_(" ");
  457. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  458. $4=aStream;
  459. _st($4)._nextPutAll_("'!");
  460. _st($4)._lf();
  461. $5=_st($4)._lf();
  462. $5;
  463. };
  464. return self}, function($ctx1) {$ctx1.fill(self,"exportMetaDefinitionOf:on:",{aClass:aClass,aStream:aStream}, smalltalk.ChunkExporter)})},
  465. args: ["aClass", "aStream"],
  466. 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]",
  467. messageSends: ["ifFalse:", "nextPutAll:", "classNameFor:", "class", "do:separatedBy:", "instanceVariableNames", "lf", "isEmpty"],
  468. referencedClasses: []
  469. }),
  470. smalltalk.ChunkExporter);
  471. smalltalk.addMethod(
  472. "_exportMethod_of_on_",
  473. smalltalk.method({
  474. selector: "exportMethod:of:on:",
  475. category: 'not yet classified',
  476. fn: function (aMethod,aClass,aStream){
  477. var self=this;
  478. return smalltalk.withContext(function($ctx1) { var $1,$2;
  479. $1=aStream;
  480. _st($1)._lf();
  481. _st($1)._lf();
  482. _st($1)._nextPutAll_(_st(self)._chunkEscape_(_st(aMethod)._source()));
  483. _st($1)._lf();
  484. $2=_st($1)._nextPutAll_("!");
  485. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:of:on:",{aMethod:aMethod,aClass:aClass,aStream:aStream}, smalltalk.ChunkExporter)})},
  486. args: ["aMethod", "aClass", "aStream"],
  487. source: "exportMethod: aMethod of: aClass on: aStream\x0a\x09aStream \x0a\x09\x09lf; lf; nextPutAll: (self chunkEscape: aMethod source); lf;\x0a\x09\x09nextPutAll: '!'",
  488. messageSends: ["lf", "nextPutAll:", "chunkEscape:", "source"],
  489. referencedClasses: []
  490. }),
  491. smalltalk.ChunkExporter);
  492. smalltalk.addMethod(
  493. "_exportMethods_category_of_on_",
  494. smalltalk.method({
  495. selector: "exportMethods:category:of:on:",
  496. category: 'not yet classified',
  497. fn: function (methods,category,aClass,aStream){
  498. var self=this;
  499. return smalltalk.withContext(function($ctx1) { var $1,$2,$3,$4;
  500. $1=aStream;
  501. _st($1)._nextPutAll_(_st("!").__comma(_st(self)._classNameFor_(aClass)));
  502. $2=_st($1)._nextPutAll_(_st(_st(" methodsFor: '").__comma(category)).__comma("'!"));
  503. _st(_st(methods)._sorted_((function(a,b){
  504. return smalltalk.withContext(function($ctx2) { return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  505. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})})))._do_((function(each){
  506. return smalltalk.withContext(function($ctx2) { return _st(self)._exportMethod_of_on_(each,aClass,aStream);
  507. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  508. $3=aStream;
  509. _st($3)._nextPutAll_(" !");
  510. _st($3)._lf();
  511. $4=_st($3)._lf();
  512. return self}, function($ctx1) {$ctx1.fill(self,"exportMethods:category:of:on:",{methods:methods,category:category,aClass:aClass,aStream:aStream}, smalltalk.ChunkExporter)})},
  513. args: ["methods", "category", "aClass", "aStream"],
  514. 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",
  515. messageSends: ["nextPutAll:", ",", "classNameFor:", "do:", "exportMethod:of:on:", "sorted:", "<=", "selector", "lf"],
  516. referencedClasses: []
  517. }),
  518. smalltalk.ChunkExporter);
  519. smalltalk.addMethod(
  520. "_exportMethodsOf_on_",
  521. smalltalk.method({
  522. selector: "exportMethodsOf:on:",
  523. category: 'not yet classified',
  524. fn: function (aClass,aStream){
  525. var self=this;
  526. var map;
  527. return smalltalk.withContext(function($ctx1) { var $1;
  528. map=_st((smalltalk.Dictionary || Dictionary))._new();
  529. _st(aClass)._protocolsDo_((function(category,methods){
  530. return smalltalk.withContext(function($ctx2) { $1=_st(category)._match_("^\x5c*");
  531. if(! smalltalk.assert($1)){
  532. return _st(map)._at_put_(category,methods);
  533. };
  534. }, function($ctx2) {$ctx2.fillBlock({category:category,methods:methods},$ctx1)})}));
  535. _st(_st(_st(map)._keys())._sorted_((function(a,b){
  536. return smalltalk.withContext(function($ctx2) { return _st(a).__lt_eq(b);
  537. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})})))._do_((function(category){
  538. var methods;
  539. return smalltalk.withContext(function($ctx2) { methods=_st(map)._at_(category);
  540. methods;
  541. return _st(self)._exportMethods_category_of_on_(methods,category,aClass,aStream);
  542. }, function($ctx2) {$ctx2.fillBlock({category:category,methods:methods},$ctx1)})}));
  543. return self}, function($ctx1) {$ctx1.fill(self,"exportMethodsOf:on:",{aClass:aClass,aStream:aStream,map:map}, smalltalk.ChunkExporter)})},
  544. args: ["aClass", "aStream"],
  545. 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 ]",
  546. messageSends: ["new", "protocolsDo:", "ifFalse:", "at:put:", "match:", "do:", "at:", "exportMethods:category:of:on:", "sorted:", "<=", "keys"],
  547. referencedClasses: ["Dictionary"]
  548. }),
  549. smalltalk.ChunkExporter);
  550. smalltalk.addMethod(
  551. "_exportPackageDefinitionOf_on_",
  552. smalltalk.method({
  553. selector: "exportPackageDefinitionOf:on:",
  554. category: 'not yet classified',
  555. fn: function (package_,aStream){
  556. var self=this;
  557. return smalltalk.withContext(function($ctx1) { var $1,$2;
  558. $1=aStream;
  559. _st($1)._nextPutAll_(_st(_st(_st(_st("Smalltalk current createPackage: '").__comma(_st(package_)._name())).__comma("' properties: ")).__comma(_st(_st(package_)._properties())._storeString())).__comma("!"));
  560. $2=_st($1)._lf();
  561. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageDefinitionOf:on:",{package_:package_,aStream:aStream}, smalltalk.ChunkExporter)})},
  562. args: ["package", "aStream"],
  563. source: "exportPackageDefinitionOf: package on: aStream\x0a\x09\x22Chunk format.\x22\x0a\x0a\x09aStream \x0a\x09 nextPutAll: 'Smalltalk current createPackage: ''', package name,\x0a\x09\x09''' properties: ', package properties storeString, '!'; lf.",
  564. messageSends: ["nextPutAll:", ",", "storeString", "properties", "name", "lf"],
  565. referencedClasses: []
  566. }),
  567. smalltalk.ChunkExporter);
  568. smalltalk.addMethod(
  569. "_exportPackageExtensionsOf_on_",
  570. smalltalk.method({
  571. selector: "exportPackageExtensionsOf:on:",
  572. category: 'not yet classified',
  573. fn: function (package_,aStream){
  574. var self=this;
  575. var name,map;
  576. return smalltalk.withContext(function($ctx1) { var $1;
  577. name=_st(package_)._name();
  578. _st(_st((smalltalk.Package || Package))._sortedClasses_(_st(_st((smalltalk.Smalltalk || Smalltalk))._current())._classes()))._do_((function(each){
  579. return smalltalk.withContext(function($ctx2) { return _st([each,_st(each)._class()])._do_((function(aClass){
  580. return smalltalk.withContext(function($ctx3) { map=_st((smalltalk.Dictionary || Dictionary))._new();
  581. map;
  582. _st(aClass)._protocolsDo_((function(category,methods){
  583. return smalltalk.withContext(function($ctx4) { $1=_st(category)._match_(_st("^\x5c*").__comma(name));
  584. if(smalltalk.assert($1)){
  585. return _st(map)._at_put_(category,methods);
  586. };
  587. }, function($ctx4) {$ctx4.fillBlock({category:category,methods:methods},$ctx1)})}));
  588. return _st(_st(_st(map)._keys())._sorted_((function(a,b){
  589. return smalltalk.withContext(function($ctx4) { return _st(a).__lt_eq(b);
  590. }, function($ctx4) {$ctx4.fillBlock({a:a,b:b},$ctx1)})})))._do_((function(category){
  591. var methods;
  592. return smalltalk.withContext(function($ctx4) { methods=_st(map)._at_(category);
  593. methods;
  594. return _st(self)._exportMethods_category_of_on_(methods,category,aClass,aStream);
  595. }, function($ctx4) {$ctx4.fillBlock({category:category,methods:methods},$ctx1)})}));
  596. }, function($ctx3) {$ctx3.fillBlock({aClass:aClass},$ctx1)})}));
  597. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  598. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageExtensionsOf:on:",{package_:package_,aStream:aStream,name:name,map:map}, smalltalk.ChunkExporter)})},
  599. args: ["package", "aStream"],
  600. 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 ]]]",
  601. messageSends: ["name", "do:", "new", "protocolsDo:", "ifTrue:", "at:put:", "match:", ",", "at:", "exportMethods:category:of:on:", "sorted:", "<=", "keys", "class", "sortedClasses:", "classes", "current"],
  602. referencedClasses: ["Dictionary", "Smalltalk", "Package"]
  603. }),
  604. smalltalk.ChunkExporter);
  605. smalltalk.addClass('StrippedExporter', smalltalk.Exporter, [], 'Importer-Exporter');
  606. smalltalk.addMethod(
  607. "_exportDefinitionOf_on_",
  608. smalltalk.method({
  609. selector: "exportDefinitionOf:on:",
  610. category: 'private',
  611. fn: function (aClass,aStream){
  612. var self=this;
  613. return smalltalk.withContext(function($ctx1) { var $1,$2,$3,$4;
  614. $1=aStream;
  615. _st($1)._nextPutAll_("smalltalk.addClass(");
  616. _st($1)._nextPutAll_(_st(_st("'").__comma(_st(self)._classNameFor_(aClass))).__comma("', "));
  617. _st($1)._nextPutAll_(_st("smalltalk.").__comma(_st(self)._classNameFor_(_st(aClass)._superclass())));
  618. $2=_st($1)._nextPutAll_(", [");
  619. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  620. return smalltalk.withContext(function($ctx2) { return _st(aStream)._nextPutAll_(_st(_st("'").__comma(each)).__comma("'"));
  621. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  622. return smalltalk.withContext(function($ctx2) { return _st(aStream)._nextPutAll_(", ");
  623. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  624. $3=aStream;
  625. _st($3)._nextPutAll_("], '");
  626. _st($3)._nextPutAll_(_st(_st(aClass)._category()).__comma("'"));
  627. $4=_st($3)._nextPutAll_(");");
  628. _st(aStream)._lf();
  629. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream}, smalltalk.StrippedExporter)})},
  630. args: ["aClass", "aStream"],
  631. 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",
  632. messageSends: ["nextPutAll:", ",", "classNameFor:", "superclass", "do:separatedBy:", "instanceVariableNames", "category", "lf"],
  633. referencedClasses: []
  634. }),
  635. smalltalk.StrippedExporter);
  636. smalltalk.addMethod(
  637. "_exportMethod_of_on_",
  638. smalltalk.method({
  639. selector: "exportMethod:of:on:",
  640. category: 'private',
  641. fn: function (aMethod,aClass,aStream){
  642. var self=this;
  643. return smalltalk.withContext(function($ctx1) { var $1,$2;
  644. $1=aStream;
  645. _st($1)._nextPutAll_("smalltalk.addMethod(");
  646. _st($1)._lf();
  647. _st($1)._nextPutAll_(_st(_st(_st(_st(aMethod)._selector())._asSelector())._asJavascript()).__comma(","));
  648. _st($1)._lf();
  649. _st($1)._nextPutAll_("smalltalk.method({");
  650. _st($1)._lf();
  651. _st($1)._nextPutAll_(_st(_st("selector: ").__comma(_st(_st(aMethod)._selector())._asJavascript())).__comma(","));
  652. _st($1)._lf();
  653. _st($1)._nextPutAll_(_st(_st("fn: ").__comma(_st(_st(aMethod)._fn())._compiledSource())).__comma(","));
  654. _st($1)._lf();
  655. _st($1)._nextPutAll_(_st("messageSends: ").__comma(_st(_st(aMethod)._messageSends())._asJavascript()));
  656. _st($1)._nextPutAll_("}),");
  657. _st($1)._lf();
  658. _st($1)._nextPutAll_(_st("smalltalk.").__comma(_st(self)._classNameFor_(aClass)));
  659. _st($1)._nextPutAll_(");");
  660. _st($1)._lf();
  661. $2=_st($1)._lf();
  662. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:of:on:",{aMethod:aMethod,aClass:aClass,aStream:aStream}, smalltalk.StrippedExporter)})},
  663. args: ["aMethod", "aClass", "aStream"],
  664. 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",
  665. messageSends: ["nextPutAll:", "lf", ",", "asJavascript", "asSelector", "selector", "compiledSource", "fn", "messageSends", "classNameFor:"],
  666. referencedClasses: []
  667. }),
  668. smalltalk.StrippedExporter);
  669. smalltalk.addClass('Importer', smalltalk.Object, [], 'Importer-Exporter');
  670. smalltalk.addMethod(
  671. "_import_",
  672. smalltalk.method({
  673. selector: "import:",
  674. category: 'fileIn',
  675. fn: function (aStream){
  676. var self=this;
  677. var chunk,result,parser,lastEmpty;
  678. return smalltalk.withContext(function($ctx1) { var $1,$2;
  679. parser=_st((smalltalk.ChunkParser || ChunkParser))._on_(aStream);
  680. lastEmpty=false;
  681. _st((function(){
  682. return smalltalk.withContext(function($ctx2) { chunk=_st(parser)._nextChunk();
  683. chunk;
  684. return _st(chunk)._isNil();
  685. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileFalse_((function(){
  686. return smalltalk.withContext(function($ctx2) { $1=_st(chunk)._isEmpty();
  687. if(smalltalk.assert($1)){
  688. lastEmpty=true;
  689. return lastEmpty;
  690. } else {
  691. result=_st(_st((smalltalk.Compiler || Compiler))._new())._evaluateExpression_(chunk);
  692. result;
  693. $2=lastEmpty;
  694. if(smalltalk.assert($2)){
  695. lastEmpty=false;
  696. lastEmpty;
  697. return _st(result)._scanFrom_(parser);
  698. };
  699. };
  700. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  701. return self}, function($ctx1) {$ctx1.fill(self,"import:",{aStream:aStream,chunk:chunk,result:result,parser:parser,lastEmpty:lastEmpty}, smalltalk.Importer)})},
  702. args: ["aStream"],
  703. 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]]]",
  704. messageSends: ["on:", "whileFalse:", "ifTrue:ifFalse:", "evaluateExpression:", "new", "ifTrue:", "scanFrom:", "isEmpty", "nextChunk", "isNil"],
  705. referencedClasses: ["ChunkParser", "Compiler"]
  706. }),
  707. smalltalk.Importer);
  708. smalltalk.addClass('PackageLoader', smalltalk.Object, [], 'Importer-Exporter');
  709. smalltalk.addMethod(
  710. "_initializePackageNamed_prefix_",
  711. smalltalk.method({
  712. selector: "initializePackageNamed:prefix:",
  713. category: 'laoding',
  714. fn: function (packageName,aString){
  715. var self=this;
  716. return smalltalk.withContext(function($ctx1) { var $1,$2;
  717. $1=_st((smalltalk.Package || Package))._named_(packageName);
  718. _st($1)._setupClasses();
  719. _st($1)._commitPathJs_(_st(_st("/").__comma(aString)).__comma("/js"));
  720. $2=_st($1)._commitPathSt_(_st(_st("/").__comma(aString)).__comma("/st"));
  721. return self}, function($ctx1) {$ctx1.fill(self,"initializePackageNamed:prefix:",{packageName:packageName,aString:aString}, smalltalk.PackageLoader)})},
  722. args: ["packageName", "aString"],
  723. source: "initializePackageNamed: packageName prefix: aString\x0a\x0a\x09(Package named: packageName) \x0a \x09setupClasses;\x0a commitPathJs: '/', aString, '/js';\x0a commitPathSt: '/', aString, '/st'",
  724. messageSends: ["setupClasses", "named:", "commitPathJs:", ",", "commitPathSt:"],
  725. referencedClasses: ["Package"]
  726. }),
  727. smalltalk.PackageLoader);
  728. smalltalk.addMethod(
  729. "_loadPackage_prefix_",
  730. smalltalk.method({
  731. selector: "loadPackage:prefix:",
  732. category: 'laoding',
  733. fn: function (packageName,aString){
  734. var self=this;
  735. var url;
  736. return smalltalk.withContext(function($ctx1) { var $1;
  737. url=_st(_st(_st(_st("/").__comma(aString)).__comma("/js/")).__comma(packageName)).__comma(".js");
  738. _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){
  739. return smalltalk.withContext(function($ctx2) { $1=_st(_st(jqXHR)._readyState()).__eq((4));
  740. if(smalltalk.assert($1)){
  741. return _st(self)._initializePackageNamed_prefix_(packageName,aString);
  742. };
  743. }, function($ctx2) {$ctx2.fillBlock({jqXHR:jqXHR,textStatus:textStatus},$ctx1)})})),_st("error").__minus_gt((function(){
  744. return smalltalk.withContext(function($ctx2) { return _st(window)._alert_(_st("Could not load package at: ").__comma(url));
  745. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))]));
  746. return self}, function($ctx1) {$ctx1.fill(self,"loadPackage:prefix:",{packageName:packageName,aString:aString,url:url}, smalltalk.PackageLoader)})},
  747. args: ["packageName", "aString"],
  748. 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}",
  749. messageSends: [",", "ajax:options:", "->", "ifTrue:", "initializePackageNamed:prefix:", "=", "readyState", "alert:"],
  750. referencedClasses: []
  751. }),
  752. smalltalk.PackageLoader);
  753. smalltalk.addMethod(
  754. "_loadPackages_prefix_",
  755. smalltalk.method({
  756. selector: "loadPackages:prefix:",
  757. category: 'laoding',
  758. fn: function (aCollection,aString){
  759. var self=this;
  760. return smalltalk.withContext(function($ctx1) { _st(aCollection)._do_((function(each){
  761. return smalltalk.withContext(function($ctx2) { return _st(self)._loadPackage_prefix_(each,aString);
  762. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  763. return self}, function($ctx1) {$ctx1.fill(self,"loadPackages:prefix:",{aCollection:aCollection,aString:aString}, smalltalk.PackageLoader)})},
  764. args: ["aCollection", "aString"],
  765. source: "loadPackages: aCollection prefix: aString\x0a\x09aCollection do: [ :each |\x0a \x09self loadPackage: each prefix: aString ]",
  766. messageSends: ["do:", "loadPackage:prefix:"],
  767. referencedClasses: []
  768. }),
  769. smalltalk.PackageLoader);
  770. smalltalk.addMethod(
  771. "_loadPackages_prefix_",
  772. smalltalk.method({
  773. selector: "loadPackages:prefix:",
  774. category: 'not yet classified',
  775. fn: function (aCollection,aString){
  776. var self=this;
  777. return smalltalk.withContext(function($ctx1) { var $1;
  778. $1=_st(_st(self)._new())._loadPackages_prefix_(aCollection,aString);
  779. return $1;
  780. }, function($ctx1) {$ctx1.fill(self,"loadPackages:prefix:",{aCollection:aCollection,aString:aString}, smalltalk.PackageLoader.klass)})},
  781. args: ["aCollection", "aString"],
  782. source: "loadPackages: aCollection prefix: aString\x0a\x09^ self new loadPackages: aCollection prefix: aString",
  783. messageSends: ["loadPackages:prefix:", "new"],
  784. referencedClasses: []
  785. }),
  786. smalltalk.PackageLoader.klass);