1
0

Importer-Exporter.js 38 KB

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