Importer-Exporter.js 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  1. (function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Importer-Exporter');
  3. smalltalk.addClass('ChunkParser', smalltalk.Object, ['stream'], 'Importer-Exporter');
  4. smalltalk.ChunkParser.comment="I am responsible for parsing aStream contents in the chunk format.\x0a\x0a## API\x0a\x0a ChunkParser new\x0a stream: aStream;\x0a nextChunk";
  5. smalltalk.addMethod(
  6. smalltalk.method({
  7. selector: "nextChunk",
  8. category: 'reading',
  9. fn: function (){
  10. var self=this;
  11. var char,result,chunk;
  12. return smalltalk.withContext(function($ctx1) {
  13. var $1,$2,$3;
  14. var $early={};
  15. try {
  16. result=""._writeStream();
  17. _st((function(){
  18. return smalltalk.withContext(function($ctx2) {
  19. char=_st(self["@stream"])._next();
  20. char;
  21. return _st(char)._notNil();
  22. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileTrue_((function(){
  23. return smalltalk.withContext(function($ctx2) {
  24. $1=_st(char).__eq("!");
  25. if(smalltalk.assert($1)){
  26. $2=_st(_st(self["@stream"])._peek()).__eq("!");
  27. if(smalltalk.assert($2)){
  28. _st(self["@stream"])._next();
  29. } else {
  30. $3=_st(_st(result)._contents())._trimBoth();
  31. throw $early=[$3];
  32. };
  33. };
  34. return _st(result)._nextPut_(char);
  35. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  36. return nil;
  37. }
  38. catch(e) {if(e===$early)return e[0]; throw e}
  39. }, function($ctx1) {$ctx1.fill(self,"nextChunk",{char:char,result:result,chunk:chunk},smalltalk.ChunkParser)})},
  40. args: [],
  41. source: "nextChunk\x0a\x09\x22The chunk format (Smalltalk Interchange Format or Fileout format)\x0a\x09is a trivial format but can be a bit tricky to understand:\x0a\x09\x09- Uses the exclamation mark as delimiter of chunks.\x0a\x09\x09- Inside a chunk a normal exclamation mark must be doubled.\x0a\x09\x09- A non empty chunk must be a valid Smalltalk expression.\x0a\x09\x09- A chunk on top level with a preceding empty chunk is an instruction chunk:\x0a\x09\x09\x09- The object created by the expression then takes over reading chunks.\x0a\x0a\x09This metod returns next chunk as a String (trimmed), empty String (all whitespace) or nil.\x22\x0a\x0a\x09| char result chunk |\x0a\x09result := '' writeStream.\x0a\x09\x09[char := stream next.\x0a\x09\x09char notNil] whileTrue: [\x0a\x09\x09\x09\x09char = '!' ifTrue: [\x0a\x09\x09\x09\x09\x09\x09stream peek = '!'\x0a\x09\x09\x09\x09\x09\x09\x09\x09ifTrue: [stream next \x22skipping the escape double\x22]\x0a\x09\x09\x09\x09\x09\x09\x09\x09ifFalse: [^result contents trimBoth \x22chunk end marker found\x22]].\x0a\x09\x09\x09\x09result nextPut: char].\x0a\x09^nil \x22a chunk needs to end with !\x22",
  42. messageSends: ["writeStream", "whileTrue:", "ifTrue:", "ifTrue:ifFalse:", "next", "trimBoth", "contents", "=", "peek", "nextPut:", "notNil"],
  43. referencedClasses: []
  44. }),
  45. smalltalk.ChunkParser);
  46. smalltalk.addMethod(
  47. smalltalk.method({
  48. selector: "stream:",
  49. category: 'accessing',
  50. fn: function (aStream){
  51. var self=this;
  52. return smalltalk.withContext(function($ctx1) {
  53. self["@stream"]=aStream;
  54. return self}, function($ctx1) {$ctx1.fill(self,"stream:",{aStream:aStream},smalltalk.ChunkParser)})},
  55. args: ["aStream"],
  56. source: "stream: aStream\x0a\x09stream := aStream",
  57. messageSends: [],
  58. referencedClasses: []
  59. }),
  60. smalltalk.ChunkParser);
  61. smalltalk.addMethod(
  62. smalltalk.method({
  63. selector: "on:",
  64. category: 'not yet classified',
  65. fn: function (aStream){
  66. var self=this;
  67. return smalltalk.withContext(function($ctx1) {
  68. var $1;
  69. $1=_st(self._new())._stream_(aStream);
  70. return $1;
  71. }, function($ctx1) {$ctx1.fill(self,"on:",{aStream:aStream},smalltalk.ChunkParser.klass)})},
  72. args: ["aStream"],
  73. source: "on: aStream\x0a\x09^self new stream: aStream",
  74. messageSends: ["stream:", "new"],
  75. referencedClasses: []
  76. }),
  77. smalltalk.ChunkParser.klass);
  78. smalltalk.addClass('Importer', smalltalk.Object, [], 'Importer-Exporter');
  79. smalltalk.Importer.comment="I can import Amber code from a string in the chunk format.\x0a\x0a## API\x0a\x0a Importer new import: aString";
  80. smalltalk.addMethod(
  81. smalltalk.method({
  82. selector: "import:",
  83. category: 'fileIn',
  84. fn: function (aStream){
  85. var self=this;
  86. var chunk,result,parser,lastEmpty;
  87. function $ChunkParser(){return smalltalk.ChunkParser||(typeof ChunkParser=="undefined"?nil:ChunkParser)}
  88. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  89. return smalltalk.withContext(function($ctx1) {
  90. var $1,$2;
  91. parser=_st($ChunkParser())._on_(aStream);
  92. lastEmpty=false;
  93. _st((function(){
  94. return smalltalk.withContext(function($ctx2) {
  95. chunk=_st(parser)._nextChunk();
  96. chunk;
  97. return _st(chunk)._isNil();
  98. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileFalse_((function(){
  99. return smalltalk.withContext(function($ctx2) {
  100. $1=_st(chunk)._isEmpty();
  101. if(smalltalk.assert($1)){
  102. lastEmpty=true;
  103. return lastEmpty;
  104. } else {
  105. result=_st(_st($Compiler())._new())._evaluateExpression_(chunk);
  106. result;
  107. $2=lastEmpty;
  108. if(smalltalk.assert($2)){
  109. lastEmpty=false;
  110. lastEmpty;
  111. return _st(result)._scanFrom_(parser);
  112. };
  113. };
  114. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  115. return self}, function($ctx1) {$ctx1.fill(self,"import:",{aStream:aStream,chunk:chunk,result:result,parser:parser,lastEmpty:lastEmpty},smalltalk.Importer)})},
  116. args: ["aStream"],
  117. source: "import: aStream\x0a\x09| chunk result parser lastEmpty |\x0a\x09parser := ChunkParser on: aStream.\x0a\x09lastEmpty := false.\x0a\x09[chunk := parser nextChunk.\x0a\x09chunk isNil] whileFalse: [\x0a\x09\x09chunk isEmpty\x0a\x09\x09\x09ifTrue: [lastEmpty := true]\x0a\x09\x09\x09ifFalse: [\x0a\x09\x09\x09\x09result := Compiler new evaluateExpression: chunk.\x0a\x09\x09\x09\x09lastEmpty\x0a\x09\x09\x09\x09\x09\x09ifTrue: [\x0a\x09\x09\x09\x09\x09\x09\x09\x09\x09lastEmpty := false.\x0a\x09\x09\x09\x09\x09\x09\x09\x09\x09result scanFrom: parser]]]",
  118. messageSends: ["on:", "whileFalse:", "ifTrue:ifFalse:", "evaluateExpression:", "new", "ifTrue:", "scanFrom:", "isEmpty", "nextChunk", "isNil"],
  119. referencedClasses: ["ChunkParser", "Compiler"]
  120. }),
  121. smalltalk.Importer);
  122. smalltalk.addClass('PackageHandler', smalltalk.Object, [], 'Importer-Exporter');
  123. smalltalk.PackageHandler.comment="I am responsible for handling package loading and committing.\x0a\x0aI should not be used directly. Instead, use the corresponding `Package` methods.";
  124. smalltalk.addMethod(
  125. smalltalk.method({
  126. selector: "ajaxPutAt:data:",
  127. category: 'private',
  128. fn: function (aURL,aString){
  129. var self=this;
  130. return smalltalk.withContext(function($ctx1) {
  131. _st(jQuery)._ajax_options_(aURL,smalltalk.HashedCollection._from_(["type".__minus_gt("PUT"),"data".__minus_gt(aString),"contentType".__minus_gt("text/plain;charset=UTF-8"),"error".__minus_gt((function(xhr){
  132. return smalltalk.withContext(function($ctx2) {
  133. return self._error_(_st(_st(_st("Commiting ".__comma(aURL)).__comma(" failed with reason: \x22")).__comma(_st(xhr)._responseText())).__comma("\x22"));
  134. }, function($ctx2) {$ctx2.fillBlock({xhr:xhr},$ctx1)})}))]));
  135. return self}, function($ctx1) {$ctx1.fill(self,"ajaxPutAt:data:",{aURL:aURL,aString:aString},smalltalk.PackageHandler)})},
  136. args: ["aURL", "aString"],
  137. source: "ajaxPutAt: aURL data: aString\x0a\x09jQuery\x0a\x09\x09ajax: aURL \x0a\x09\x09options: #{ \x0a\x09\x09\x09'type' -> 'PUT'.\x0a\x09\x09\x09'data' -> aString.\x0a\x09\x09\x09'contentType' -> 'text/plain;charset=UTF-8'.\x0a\x09\x09\x09'error' -> [ :xhr | self error: 'Commiting ' , aURL , ' failed with reason: \x22' , (xhr responseText) , '\x22'] }",
  138. messageSends: ["ajax:options:", "->", "error:", ",", "responseText"],
  139. referencedClasses: []
  140. }),
  141. smalltalk.PackageHandler);
  142. smalltalk.addMethod(
  143. smalltalk.method({
  144. selector: "commit:",
  145. category: 'committing',
  146. fn: function (aPackage){
  147. var self=this;
  148. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  149. function $Exporter(){return smalltalk.Exporter||(typeof Exporter=="undefined"?nil:Exporter)}
  150. function $StrippedExporter(){return smalltalk.StrippedExporter||(typeof StrippedExporter=="undefined"?nil:StrippedExporter)}
  151. function $ChunkExporter(){return smalltalk.ChunkExporter||(typeof ChunkExporter=="undefined"?nil:ChunkExporter)}
  152. return smalltalk.withContext(function($ctx1) {
  153. _st([_st($Exporter()).__minus_gt(_st(_st(_st(_st(aPackage)._commitPathJs()).__comma("/")).__comma(_st(aPackage)._name())).__comma(".js")),_st($StrippedExporter()).__minus_gt(_st(_st(_st(_st(aPackage)._commitPathJs()).__comma("/")).__comma(_st(aPackage)._name())).__comma(".deploy.js")),_st($ChunkExporter()).__minus_gt(_st(_st(_st(_st(aPackage)._commitPathSt()).__comma("/")).__comma(_st(aPackage)._name())).__comma(".st"))])._do_displayingProgress_((function(commitStrategy){
  154. var fileContents;
  155. return smalltalk.withContext(function($ctx2) {
  156. fileContents=_st($String())._streamContents_((function(stream){
  157. return smalltalk.withContext(function($ctx3) {
  158. return _st(_st(_st(commitStrategy)._key())._new())._exportPackage_on_(aPackage,stream);
  159. }, function($ctx3) {$ctx3.fillBlock({stream:stream},$ctx2)})}));
  160. fileContents;
  161. return self._ajaxPutAt_data_(_st(commitStrategy)._value(),fileContents);
  162. }, function($ctx2) {$ctx2.fillBlock({commitStrategy:commitStrategy,fileContents:fileContents},$ctx1)})}),"Committing package ".__comma(_st(aPackage)._name()));
  163. return self}, function($ctx1) {$ctx1.fill(self,"commit:",{aPackage:aPackage},smalltalk.PackageHandler)})},
  164. args: ["aPackage"],
  165. source: "commit: aPackage\x0a\x09{ \x0a\x09\x09Exporter -> (aPackage commitPathJs, '/', aPackage name, '.js').\x0a\x09\x09StrippedExporter -> (aPackage commitPathJs, '/', aPackage name, '.deploy.js').\x0a\x09\x09ChunkExporter -> (aPackage commitPathSt, '/', aPackage name, '.st')\x0a\x09} \x0a\x09\x09do: [ :commitStrategy|| fileContents |\x0a\x09\x09\x09fileContents := String streamContents: [ :stream |\x0a\x09\x09\x09\x09commitStrategy key new exportPackage: aPackage on: stream ].\x0a\x09\x09\x09self ajaxPutAt: commitStrategy value data: fileContents ]\x0a\x09\x09displayingProgress: 'Committing package ', aPackage name",
  166. messageSends: ["do:displayingProgress:", "streamContents:", "exportPackage:on:", "new", "key", "ajaxPutAt:data:", "value", ",", "name", "->", "commitPathJs", "commitPathSt"],
  167. referencedClasses: ["String", "Exporter", "StrippedExporter", "ChunkExporter"]
  168. }),
  169. smalltalk.PackageHandler);
  170. smalltalk.addMethod(
  171. smalltalk.method({
  172. selector: "loadPackage:prefix:",
  173. category: 'loading',
  174. fn: function (packageName,aString){
  175. var self=this;
  176. var url;
  177. return smalltalk.withContext(function($ctx1) {
  178. var $1;
  179. url=_st(_st(_st("/".__comma(aString)).__comma("/js/")).__comma(packageName)).__comma(".js");
  180. _st(jQuery)._ajax_options_(url,smalltalk.HashedCollection._from_(["type".__minus_gt("GET"),"dataType".__minus_gt("script"),"complete".__minus_gt((function(jqXHR,textStatus){
  181. return smalltalk.withContext(function($ctx2) {
  182. $1=_st(_st(jqXHR)._readyState()).__eq((4));
  183. if(smalltalk.assert($1)){
  184. return self._setupPackageNamed_prefix_(packageName,aString);
  185. };
  186. }, function($ctx2) {$ctx2.fillBlock({jqXHR:jqXHR,textStatus:textStatus},$ctx1)})})),"error".__minus_gt((function(){
  187. return smalltalk.withContext(function($ctx2) {
  188. return _st(window)._alert_("Could not load package at: ".__comma(url));
  189. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))]));
  190. return self}, function($ctx1) {$ctx1.fill(self,"loadPackage:prefix:",{packageName:packageName,aString:aString,url:url},smalltalk.PackageHandler)})},
  191. args: ["packageName", "aString"],
  192. source: "loadPackage: packageName prefix: aString\x0a\x09| url |\x0a\x09url := '/', aString, '/js/', packageName, '.js'.\x0a\x09jQuery\x0a\x09\x09ajax: url\x0a\x09\x09options: #{\x0a\x09\x09\x09'type' -> 'GET'.\x0a\x09\x09\x09'dataType' -> 'script'.\x0a\x09\x09\x09'complete' -> [ :jqXHR :textStatus |\x0a\x09\x09\x09\x09jqXHR readyState = 4\x0a\x09\x09\x09\x09\x09ifTrue: [ self setupPackageNamed: packageName prefix: aString ] ].\x0a\x09\x09\x09'error' -> [ window alert: 'Could not load package at: ', url ]\x0a\x09\x09}",
  193. messageSends: [",", "ajax:options:", "->", "ifTrue:", "setupPackageNamed:prefix:", "=", "readyState", "alert:"],
  194. referencedClasses: []
  195. }),
  196. smalltalk.PackageHandler);
  197. smalltalk.addMethod(
  198. smalltalk.method({
  199. selector: "loadPackages:prefix:",
  200. category: 'loading',
  201. fn: function (aCollection,aString){
  202. var self=this;
  203. return smalltalk.withContext(function($ctx1) {
  204. _st(aCollection)._do_((function(each){
  205. return smalltalk.withContext(function($ctx2) {
  206. return self._loadPackage_prefix_(each,aString);
  207. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  208. return self}, function($ctx1) {$ctx1.fill(self,"loadPackages:prefix:",{aCollection:aCollection,aString:aString},smalltalk.PackageHandler)})},
  209. args: ["aCollection", "aString"],
  210. source: "loadPackages: aCollection prefix: aString\x0a\x09aCollection do: [ :each |\x0a\x09\x09self loadPackage: each prefix: aString ]",
  211. messageSends: ["do:", "loadPackage:prefix:"],
  212. referencedClasses: []
  213. }),
  214. smalltalk.PackageHandler);
  215. smalltalk.addMethod(
  216. smalltalk.method({
  217. selector: "setupPackageNamed:prefix:",
  218. category: 'private',
  219. fn: function (packageName,aString){
  220. var self=this;
  221. function $Package(){return smalltalk.Package||(typeof Package=="undefined"?nil:Package)}
  222. return smalltalk.withContext(function($ctx1) {
  223. var $1,$2;
  224. $1=_st($Package())._named_(packageName);
  225. _st($1)._setupClasses();
  226. _st($1)._commitPathJs_(_st("/".__comma(aString)).__comma("/js"));
  227. $2=_st($1)._commitPathSt_(_st("/".__comma(aString)).__comma("/st"));
  228. return self}, function($ctx1) {$ctx1.fill(self,"setupPackageNamed:prefix:",{packageName:packageName,aString:aString},smalltalk.PackageHandler)})},
  229. args: ["packageName", "aString"],
  230. source: "setupPackageNamed: packageName prefix: aString\x0a\x0a\x09(Package named: packageName)\x0a\x09\x09setupClasses;\x0a\x09\x09commitPathJs: '/', aString, '/js';\x0a\x09\x09commitPathSt: '/', aString, '/st'",
  231. messageSends: ["setupClasses", "named:", "commitPathJs:", ",", "commitPathSt:"],
  232. referencedClasses: ["Package"]
  233. }),
  234. smalltalk.PackageHandler);
  235. smalltalk.addMethod(
  236. smalltalk.method({
  237. selector: "loadPackages:prefix:",
  238. category: 'loading',
  239. fn: function (aCollection,aString){
  240. var self=this;
  241. return smalltalk.withContext(function($ctx1) {
  242. var $1;
  243. $1=_st(self._new())._loadPackages_prefix_(aCollection,aString);
  244. return $1;
  245. }, function($ctx1) {$ctx1.fill(self,"loadPackages:prefix:",{aCollection:aCollection,aString:aString},smalltalk.PackageHandler.klass)})},
  246. args: ["aCollection", "aString"],
  247. source: "loadPackages: aCollection prefix: aString\x0a\x09^ self new loadPackages: aCollection prefix: aString",
  248. messageSends: ["loadPackages:prefix:", "new"],
  249. referencedClasses: []
  250. }),
  251. smalltalk.PackageHandler.klass);
  252. smalltalk.addClass('PluggableExporter', smalltalk.Object, [], 'Importer-Exporter');
  253. smalltalk.addMethod(
  254. smalltalk.method({
  255. selector: "export:usingRecipe:on:",
  256. category: 'fileOut',
  257. fn: function (anObject,anArray,aStream){
  258. var self=this;
  259. var args;
  260. return smalltalk.withContext(function($ctx1) {
  261. var $1;
  262. args=[anObject,aStream];
  263. _st(anArray)._do_((function(each){
  264. var val;
  265. return smalltalk.withContext(function($ctx2) {
  266. val=_st(each)._value();
  267. val;
  268. $1=_st(val).__eq_eq(each);
  269. if(smalltalk.assert($1)){
  270. var selection;
  271. selection=_st(_st(_st(each)._first())._key())._perform_withArguments_(_st(_st(each)._first())._value(),[anObject]);
  272. selection;
  273. return _st(selection)._do_((function(eachPart){
  274. return smalltalk.withContext(function($ctx3) {
  275. return self._export_usingRecipe_on_(eachPart,_st(each)._allButFirst(),aStream);
  276. }, function($ctx3) {$ctx3.fillBlock({eachPart:eachPart},$ctx2)})}));
  277. } else {
  278. return _st(_st(each)._key())._perform_withArguments_(val,args);
  279. };
  280. }, function($ctx2) {$ctx2.fillBlock({each:each,val:val},$ctx1)})}));
  281. return self}, function($ctx1) {$ctx1.fill(self,"export:usingRecipe:on:",{anObject:anObject,anArray:anArray,aStream:aStream,args:args},smalltalk.PluggableExporter)})},
  282. args: ["anObject", "anArray", "aStream"],
  283. source: "export: anObject usingRecipe: anArray on: aStream\x0a\x09| args |\x0a\x09args := { anObject. aStream }.\x0a\x09anArray do: [ :each | | val |\x0a\x09\x09val := each value.\x0a\x09\x09val == each\x0a\x09\x09\x09ifFalse: [ \x22association\x22\x0a\x09\x09\x09\x09each key perform: val withArguments: args ]\x0a\x09\x09\x09ifTrue: [ \x22sub-array\x22\x0a\x09\x09\x09\x09| selection |\x0a\x09\x09\x09\x09selection := each first key perform: each first value withArguments: { anObject }.\x0a\x09\x09\x09\x09selection do: [ :eachPart |\x09self export: eachPart usingRecipe: each allButFirst on: aStream ]]]",
  284. messageSends: ["do:", "value", "ifFalse:ifTrue:", "perform:withArguments:", "key", "first", "export:usingRecipe:on:", "allButFirst", "=="],
  285. referencedClasses: []
  286. }),
  287. smalltalk.PluggableExporter);
  288. smalltalk.addMethod(
  289. smalltalk.method({
  290. selector: "exportAll",
  291. category: 'fileOut',
  292. fn: function (){
  293. var self=this;
  294. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  295. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  296. return smalltalk.withContext(function($ctx1) {
  297. var $1;
  298. $1=_st($String())._streamContents_((function(stream){
  299. return smalltalk.withContext(function($ctx2) {
  300. return _st(_st(_st($Smalltalk())._current())._packages())._do_((function(pkg){
  301. return smalltalk.withContext(function($ctx3) {
  302. return self._exportPackage_on_(pkg,stream);
  303. }, function($ctx3) {$ctx3.fillBlock({pkg:pkg},$ctx2)})}));
  304. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1)})}));
  305. return $1;
  306. }, function($ctx1) {$ctx1.fill(self,"exportAll",{},smalltalk.PluggableExporter)})},
  307. args: [],
  308. source: "exportAll\x0a\x09\x22Export all packages in the system.\x22\x0a\x0a\x09^String streamContents: [:stream |\x0a\x09\x09Smalltalk current packages do: [:pkg |\x0a\x09\x09self exportPackage: pkg on: stream]]",
  309. messageSends: ["streamContents:", "do:", "exportPackage:on:", "packages", "current"],
  310. referencedClasses: ["Smalltalk", "String"]
  311. }),
  312. smalltalk.PluggableExporter);
  313. smalltalk.addMethod(
  314. smalltalk.method({
  315. selector: "exportPackage:on:",
  316. category: 'fileOut',
  317. fn: function (aPackage,aStream){
  318. var self=this;
  319. return smalltalk.withContext(function($ctx1) {
  320. self._export_usingRecipe_on_(aPackage,self._recipe(),aStream);
  321. return self}, function($ctx1) {$ctx1.fill(self,"exportPackage:on:",{aPackage:aPackage,aStream:aStream},smalltalk.PluggableExporter)})},
  322. args: ["aPackage", "aStream"],
  323. source: "exportPackage: aPackage on: aStream\x0a\x09self export: aPackage usingRecipe: self recipe on: aStream",
  324. messageSends: ["export:usingRecipe:on:", "recipe"],
  325. referencedClasses: []
  326. }),
  327. smalltalk.PluggableExporter);
  328. smalltalk.addClass('Exporter', smalltalk.PluggableExporter, [], 'Importer-Exporter');
  329. smalltalk.Exporter.comment="I am responsible for outputting Amber code into a JavaScript string.\x0a\x0aThe generated output is enough to reconstruct the exported data, including Smalltalk source code and other metadata.\x0a\x0a## Use case\x0a\x0aI am typically used to save code outside of the Amber runtime (committing to disk, etc.).\x0a\x0a## API\x0a\x0aUse `#exportAll`, `#exportClass:` or `#exportPackage:` methods.";
  330. smalltalk.addMethod(
  331. smalltalk.method({
  332. selector: "classNameFor:",
  333. category: 'private',
  334. fn: function (aClass){
  335. var self=this;
  336. return smalltalk.withContext(function($ctx1) {
  337. var $2,$3,$1;
  338. $2=_st(aClass)._isMetaclass();
  339. if(smalltalk.assert($2)){
  340. $1=_st(_st(_st(aClass)._instanceClass())._name()).__comma(".klass");
  341. } else {
  342. $3=_st(aClass)._isNil();
  343. if(smalltalk.assert($3)){
  344. $1="nil";
  345. } else {
  346. $1=_st(aClass)._name();
  347. };
  348. };
  349. return $1;
  350. }, function($ctx1) {$ctx1.fill(self,"classNameFor:",{aClass:aClass},smalltalk.Exporter)})},
  351. args: ["aClass"],
  352. source: "classNameFor: aClass\x0a\x09^aClass isMetaclass\x0a\x09\x09ifTrue: [aClass instanceClass name, '.klass']\x0a\x09\x09ifFalse: [\x0a\x09\x09aClass isNil\x0a\x09\x09\x09ifTrue: ['nil']\x0a\x09\x09\x09ifFalse: [aClass name]]",
  353. messageSends: ["ifTrue:ifFalse:", ",", "name", "instanceClass", "isNil", "isMetaclass"],
  354. referencedClasses: []
  355. }),
  356. smalltalk.Exporter);
  357. smalltalk.addMethod(
  358. smalltalk.method({
  359. selector: "exportDefinitionOf:on:",
  360. category: 'private',
  361. fn: function (aClass,aStream){
  362. var self=this;
  363. return smalltalk.withContext(function($ctx1) {
  364. var $1,$2,$3,$4,$5,$6,$7;
  365. $1=aStream;
  366. _st($1)._lf();
  367. _st($1)._nextPutAll_("smalltalk.addClass(");
  368. _st($1)._nextPutAll_(_st("'".__comma(self._classNameFor_(aClass))).__comma("', "));
  369. _st($1)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aClass)._superclass())));
  370. $2=_st($1)._nextPutAll_(", [");
  371. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  372. return smalltalk.withContext(function($ctx2) {
  373. return _st(aStream)._nextPutAll_(_st("'".__comma(each)).__comma("'"));
  374. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  375. return smalltalk.withContext(function($ctx2) {
  376. return _st(aStream)._nextPutAll_(", ");
  377. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  378. $3=aStream;
  379. _st($3)._nextPutAll_("], '");
  380. _st($3)._nextPutAll_(_st(_st(aClass)._category()).__comma("'"));
  381. $4=_st($3)._nextPutAll_(");");
  382. $5=_st(_st(aClass)._comment())._notEmpty();
  383. if(smalltalk.assert($5)){
  384. $6=aStream;
  385. _st($6)._lf();
  386. _st($6)._nextPutAll_("smalltalk.");
  387. _st($6)._nextPutAll_(self._classNameFor_(aClass));
  388. _st($6)._nextPutAll_(".comment=");
  389. _st($6)._nextPutAll_(_st(_st(aClass)._comment())._asJavascript());
  390. $7=_st($6)._nextPutAll_(";");
  391. $7;
  392. };
  393. _st(aStream)._lf();
  394. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.Exporter)})},
  395. args: ["aClass", "aStream"],
  396. source: "exportDefinitionOf: aClass on: aStream\x0a\x09aStream\x0a\x09\x09lf;\x0a\x09\x09nextPutAll: 'smalltalk.addClass(';\x0a\x09\x09nextPutAll: '''', (self classNameFor: aClass), ''', ';\x0a\x09\x09nextPutAll: 'smalltalk.', (self classNameFor: aClass superclass);\x0a\x09\x09nextPutAll: ', ['.\x0a\x09aClass instanceVariableNames\x0a\x09\x09do: [:each | aStream nextPutAll: '''', each, '''']\x0a\x09\x09separatedBy: [aStream nextPutAll: ', '].\x0a\x09aStream\x0a\x09\x09nextPutAll: '], ''';\x0a\x09\x09nextPutAll: aClass category, '''';\x0a\x09\x09nextPutAll: ');'.\x0a\x09aClass comment notEmpty ifTrue: [\x0a\x09\x09aStream\x0a\x09\x09\x09lf;\x0a\x09\x09nextPutAll: 'smalltalk.';\x0a\x09\x09nextPutAll: (self classNameFor: aClass);\x0a\x09\x09nextPutAll: '.comment=';\x0a\x09\x09nextPutAll: aClass comment asJavascript;\x0a\x09\x09nextPutAll: ';'].\x0a\x09aStream lf",
  397. messageSends: ["lf", "nextPutAll:", ",", "classNameFor:", "superclass", "do:separatedBy:", "instanceVariableNames", "category", "ifTrue:", "asJavascript", "comment", "notEmpty"],
  398. referencedClasses: []
  399. }),
  400. smalltalk.Exporter);
  401. smalltalk.addMethod(
  402. smalltalk.method({
  403. selector: "exportMetaDefinitionOf:on:",
  404. category: 'private',
  405. fn: function (aClass,aStream){
  406. var self=this;
  407. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  408. return smalltalk.withContext(function($ctx1) {
  409. var $1,$2,$3;
  410. _st(aStream)._lf();
  411. $1=_st(_st(_st(aClass)._class())._instanceVariableNames())._isEmpty();
  412. if(! smalltalk.assert($1)){
  413. $2=aStream;
  414. _st($2)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aClass)._class())));
  415. $3=_st($2)._nextPutAll_(".iVarNames = [");
  416. $3;
  417. _st(_st(_st(aClass)._class())._instanceVariableNames())._do_separatedBy_((function(each){
  418. return smalltalk.withContext(function($ctx2) {
  419. return _st(aStream)._nextPutAll_(_st("'".__comma(each)).__comma("'"));
  420. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  421. return smalltalk.withContext(function($ctx2) {
  422. return _st(aStream)._nextPutAll_(",");
  423. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  424. _st(aStream)._nextPutAll_("];".__comma(_st($String())._lf()));
  425. };
  426. return self}, function($ctx1) {$ctx1.fill(self,"exportMetaDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.Exporter)})},
  427. args: ["aClass", "aStream"],
  428. source: "exportMetaDefinitionOf: aClass on: aStream\x0a\x09aStream lf.\x0a\x09aClass class instanceVariableNames isEmpty ifFalse: [\x0a\x09\x09aStream\x0a\x09\x09nextPutAll: 'smalltalk.', (self classNameFor: aClass class);\x0a\x09\x09nextPutAll: '.iVarNames = ['.\x0a\x09\x09aClass class instanceVariableNames\x0a\x09\x09do: [:each | aStream nextPutAll: '''', each, '''']\x0a\x09\x09separatedBy: [aStream nextPutAll: ','].\x0a\x09\x09aStream nextPutAll: '];', String lf]",
  429. messageSends: ["lf", "ifFalse:", "nextPutAll:", ",", "classNameFor:", "class", "do:separatedBy:", "instanceVariableNames", "isEmpty"],
  430. referencedClasses: ["String"]
  431. }),
  432. smalltalk.Exporter);
  433. smalltalk.addMethod(
  434. smalltalk.method({
  435. selector: "exportMethod:on:",
  436. category: 'private',
  437. fn: function (aMethod,aStream){
  438. var self=this;
  439. return smalltalk.withContext(function($ctx1) {
  440. var $1,$2,$3,$4;
  441. $1=aStream;
  442. _st($1)._nextPutAll_("smalltalk.addMethod(");
  443. _st($1)._lf();
  444. _st($1)._nextPutAll_("smalltalk.method({");
  445. _st($1)._lf();
  446. _st($1)._nextPutAll_(_st("selector: ".__comma(_st(_st(aMethod)._selector())._asJavascript())).__comma(","));
  447. _st($1)._lf();
  448. _st($1)._nextPutAll_(_st("category: '".__comma(_st(aMethod)._category())).__comma("',"));
  449. _st($1)._lf();
  450. _st($1)._nextPutAll_(_st("fn: ".__comma(_st(_st(aMethod)._fn())._compiledSource())).__comma(","));
  451. _st($1)._lf();
  452. _st($1)._nextPutAll_(_st("args: ".__comma(_st(_st(aMethod)._arguments())._asJavascript())).__comma(","));
  453. _st($1)._lf();
  454. _st($1)._nextPutAll_(_st("source: ".__comma(_st(_st(aMethod)._source())._asJavascript())).__comma(","));
  455. _st($1)._lf();
  456. _st($1)._nextPutAll_(_st("messageSends: ".__comma(_st(_st(aMethod)._messageSends())._asJavascript())).__comma(","));
  457. _st($1)._lf();
  458. $2=_st($1)._nextPutAll_("referencedClasses: ".__comma(_st(_st(aMethod)._referencedClasses())._asJavascript()));
  459. $3=aStream;
  460. _st($3)._lf();
  461. _st($3)._nextPutAll_("}),");
  462. _st($3)._lf();
  463. _st($3)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aMethod)._methodClass())));
  464. _st($3)._nextPutAll_(");");
  465. _st($3)._lf();
  466. $4=_st($3)._lf();
  467. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:on:",{aMethod:aMethod,aStream:aStream},smalltalk.Exporter)})},
  468. args: ["aMethod", "aStream"],
  469. source: "exportMethod: aMethod on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: 'smalltalk.addMethod(';lf;\x0a\x09\x09\x22nextPutAll: aMethod selector asSelector asJavascript, ',';lf;\x22\x0a\x09\x09nextPutAll: 'smalltalk.method({';lf;\x0a\x09\x09nextPutAll: 'selector: ', aMethod selector asJavascript, ',';lf;\x0a\x09\x09nextPutAll: 'category: ''', aMethod category, ''',';lf;\x0a\x09\x09nextPutAll: 'fn: ', aMethod fn compiledSource, ',';lf;\x0a\x09\x09nextPutAll: 'args: ', aMethod arguments asJavascript, ','; lf;\x0a\x09\x09nextPutAll: 'source: ', aMethod source asJavascript, ',';lf;\x0a\x09\x09nextPutAll: 'messageSends: ', aMethod messageSends asJavascript, ',';lf;\x0a\x09\x09nextPutAll: 'referencedClasses: ', aMethod referencedClasses asJavascript.\x0a\x09aStream\x0a\x09\x09lf;\x0a\x09\x09nextPutAll: '}),';lf;\x0a\x09\x09nextPutAll: 'smalltalk.', (self classNameFor: aMethod methodClass);\x0a\x09\x09nextPutAll: ');';lf;lf",
  470. messageSends: ["nextPutAll:", "lf", ",", "asJavascript", "selector", "category", "compiledSource", "fn", "arguments", "source", "messageSends", "referencedClasses", "classNameFor:", "methodClass"],
  471. referencedClasses: []
  472. }),
  473. smalltalk.Exporter);
  474. smalltalk.addMethod(
  475. smalltalk.method({
  476. selector: "exportPackageDefinitionOf:on:",
  477. category: 'private',
  478. fn: function (package_,aStream){
  479. var self=this;
  480. return smalltalk.withContext(function($ctx1) {
  481. var $1,$2;
  482. $1=aStream;
  483. _st($1)._nextPutAll_("smalltalk.addPackage(");
  484. _st($1)._nextPutAll_(_st("'".__comma(_st(package_)._name())).__comma("');"));
  485. $2=_st($1)._lf();
  486. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageDefinitionOf:on:",{package_:package_,aStream:aStream},smalltalk.Exporter)})},
  487. args: ["package", "aStream"],
  488. source: "exportPackageDefinitionOf: package on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: 'smalltalk.addPackage(';\x0a\x09\x09nextPutAll: '''', package name, ''');';\x0a\x09\x09lf",
  489. messageSends: ["nextPutAll:", ",", "name", "lf"],
  490. referencedClasses: []
  491. }),
  492. smalltalk.Exporter);
  493. smalltalk.addMethod(
  494. smalltalk.method({
  495. selector: "exportPackageEpilogueOf:on:",
  496. category: 'private',
  497. fn: function (aPackage,aStream){
  498. var self=this;
  499. return smalltalk.withContext(function($ctx1) {
  500. var $1,$2;
  501. $1=aStream;
  502. _st($1)._nextPutAll_("})(global_smalltalk,global_nil,global__st);");
  503. $2=_st($1)._lf();
  504. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageEpilogueOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.Exporter)})},
  505. args: ["aPackage", "aStream"],
  506. source: "exportPackageEpilogueOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '})(global_smalltalk,global_nil,global__st);';\x0a\x09\x09lf",
  507. messageSends: ["nextPutAll:", "lf"],
  508. referencedClasses: []
  509. }),
  510. smalltalk.Exporter);
  511. smalltalk.addMethod(
  512. smalltalk.method({
  513. selector: "exportPackagePrologueOf:on:",
  514. category: 'private',
  515. fn: function (aPackage,aStream){
  516. var self=this;
  517. return smalltalk.withContext(function($ctx1) {
  518. var $1,$2;
  519. $1=aStream;
  520. _st($1)._nextPutAll_("(function(smalltalk,nil,_st){");
  521. $2=_st($1)._lf();
  522. return self}, function($ctx1) {$ctx1.fill(self,"exportPackagePrologueOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.Exporter)})},
  523. args: ["aPackage", "aStream"],
  524. source: "exportPackagePrologueOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '(function(smalltalk,nil,_st){';\x0a\x09\x09lf",
  525. messageSends: ["nextPutAll:", "lf"],
  526. referencedClasses: []
  527. }),
  528. smalltalk.Exporter);
  529. smalltalk.addMethod(
  530. smalltalk.method({
  531. selector: "extensionMethodsOfPackage:",
  532. category: 'private',
  533. fn: function (package_){
  534. var self=this;
  535. var name,result;
  536. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  537. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  538. function $Package(){return smalltalk.Package||(typeof Package=="undefined"?nil:Package)}
  539. return smalltalk.withContext(function($ctx1) {
  540. var $1;
  541. name=_st(package_)._name();
  542. result=_st($OrderedCollection())._new();
  543. _st(_st($Package())._sortedClasses_(_st(_st($Smalltalk())._current())._classes()))._do_((function(each){
  544. return smalltalk.withContext(function($ctx2) {
  545. return _st([each,_st(each)._class()])._do_((function(aClass){
  546. return smalltalk.withContext(function($ctx3) {
  547. return _st(result)._addAll_(_st(_st(_st(_st(aClass)._methodDictionary())._values())._sorted_((function(a,b){
  548. return smalltalk.withContext(function($ctx4) {
  549. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  550. }, function($ctx4) {$ctx4.fillBlock({a:a,b:b},$ctx3)})})))._select_((function(method){
  551. return smalltalk.withContext(function($ctx4) {
  552. return _st(_st(method)._category())._match_("^\x5c*".__comma(name));
  553. }, function($ctx4) {$ctx4.fillBlock({method:method},$ctx3)})})));
  554. }, function($ctx3) {$ctx3.fillBlock({aClass:aClass},$ctx2)})}));
  555. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  556. $1=result;
  557. return $1;
  558. }, function($ctx1) {$ctx1.fill(self,"extensionMethodsOfPackage:",{package_:package_,name:name,result:result},smalltalk.Exporter)})},
  559. args: ["package"],
  560. source: "extensionMethodsOfPackage: package\x0a\x09\x22Issue #143: sort classes and methods alphabetically\x22\x0a\x0a\x09| name result |\x0a\x09name := package name.\x0a\x09result := OrderedCollection new.\x0a\x09(Package sortedClasses: Smalltalk current classes) do: [:each |\x0a\x09\x09{each. each class} do: [:aClass |\x0a\x09\x09\x09result addAll: (((aClass methodDictionary values)\x0a\x09\x09\x09\x09sorted: [:a :b | a selector <= b selector])\x0a\x09\x09\x09\x09select: [:method | method category match: '^\x5c*', name]) ]].\x0a\x09^result",
  561. messageSends: ["name", "new", "do:", "addAll:", "select:", "match:", ",", "category", "sorted:", "<=", "selector", "values", "methodDictionary", "class", "sortedClasses:", "classes", "current"],
  562. referencedClasses: ["OrderedCollection", "Smalltalk", "Package"]
  563. }),
  564. smalltalk.Exporter);
  565. smalltalk.addMethod(
  566. smalltalk.method({
  567. selector: "ownClassesOfPackage:",
  568. category: 'private',
  569. fn: function (package_){
  570. var self=this;
  571. return smalltalk.withContext(function($ctx1) {
  572. var $1;
  573. $1=_st(_st(package_)._sortedClasses())._asSet();
  574. return $1;
  575. }, function($ctx1) {$ctx1.fill(self,"ownClassesOfPackage:",{package_:package_},smalltalk.Exporter)})},
  576. args: ["package"],
  577. source: "ownClassesOfPackage: package\x0a\x09\x22Export classes in dependency order.\x0a\x09Update (issue #171): Remove duplicates for export\x22\x0a\x09^package sortedClasses asSet",
  578. messageSends: ["asSet", "sortedClasses"],
  579. referencedClasses: []
  580. }),
  581. smalltalk.Exporter);
  582. smalltalk.addMethod(
  583. smalltalk.method({
  584. selector: "ownMethodsOfClass:",
  585. category: 'private',
  586. fn: function (aClass){
  587. var self=this;
  588. return smalltalk.withContext(function($ctx1) {
  589. var $1;
  590. $1=_st(_st(_st(_st(aClass)._methodDictionary())._values())._sorted_((function(a,b){
  591. return smalltalk.withContext(function($ctx2) {
  592. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  593. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})})))._reject_((function(each){
  594. return smalltalk.withContext(function($ctx2) {
  595. return _st(_st(each)._category())._match_("^\x5c*");
  596. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  597. return $1;
  598. }, function($ctx1) {$ctx1.fill(self,"ownMethodsOfClass:",{aClass:aClass},smalltalk.Exporter)})},
  599. args: ["aClass"],
  600. source: "ownMethodsOfClass: aClass\x0a\x09\x22Issue #143: sort methods alphabetically\x22\x0a\x0a\x09^((aClass methodDictionary values) sorted: [:a :b | a selector <= b selector])\x0a\x09\x09reject: [:each | (each category match: '^\x5c*')]",
  601. messageSends: ["reject:", "match:", "category", "sorted:", "<=", "selector", "values", "methodDictionary"],
  602. referencedClasses: []
  603. }),
  604. smalltalk.Exporter);
  605. smalltalk.addMethod(
  606. smalltalk.method({
  607. selector: "ownMethodsOfMetaClass:",
  608. category: 'private',
  609. fn: function (aClass){
  610. var self=this;
  611. return smalltalk.withContext(function($ctx1) {
  612. var $1;
  613. $1=self._ownMethodsOfClass_(_st(aClass)._class());
  614. return $1;
  615. }, function($ctx1) {$ctx1.fill(self,"ownMethodsOfMetaClass:",{aClass:aClass},smalltalk.Exporter)})},
  616. args: ["aClass"],
  617. source: "ownMethodsOfMetaClass: aClass\x0a\x09\x22Issue #143: sort methods alphabetically\x22\x0a\x0a\x09^self ownMethodsOfClass: aClass class",
  618. messageSends: ["ownMethodsOfClass:", "class"],
  619. referencedClasses: []
  620. }),
  621. smalltalk.Exporter);
  622. smalltalk.addMethod(
  623. smalltalk.method({
  624. selector: "recipe",
  625. category: 'fileOut',
  626. fn: function (){
  627. var self=this;
  628. return smalltalk.withContext(function($ctx1) {
  629. var $1;
  630. $1=[self.__minus_gt("exportPackagePrologueOf:on:"),self.__minus_gt("exportPackageDefinitionOf:on:"),[self.__minus_gt("ownClassesOfPackage:"),self.__minus_gt("exportDefinitionOf:on:"),[self.__minus_gt("ownMethodsOfClass:"),self.__minus_gt("exportMethod:on:")],self.__minus_gt("exportMetaDefinitionOf:on:"),[self.__minus_gt("ownMethodsOfMetaClass:"),self.__minus_gt("exportMethod:on:")]],[self.__minus_gt("extensionMethodsOfPackage:"),self.__minus_gt("exportMethod:on:")],self.__minus_gt("exportPackageEpilogueOf:on:")];
  631. return $1;
  632. }, function($ctx1) {$ctx1.fill(self,"recipe",{},smalltalk.Exporter)})},
  633. args: [],
  634. source: "recipe\x0a\x09\x22Export a given package.\x22\x0a\x0a\x09^{\x0a\x09\x09self -> #exportPackagePrologueOf:on:.\x0a\x09\x09self -> #exportPackageDefinitionOf:on:.\x0a\x09\x09{\x0a\x09\x09\x09self -> #ownClassesOfPackage:.\x0a\x09\x09\x09self -> #exportDefinitionOf:on:.\x0a\x09\x09\x09{\x0a\x09\x09\x09\x09self -> #ownMethodsOfClass:.\x0a\x09\x09\x09\x09self -> #exportMethod:on: }.\x0a\x09\x09\x09self -> #exportMetaDefinitionOf:on:.\x0a\x09\x09\x09{\x0a\x09\x09\x09\x09self -> #ownMethodsOfMetaClass:.\x0a\x09\x09\x09\x09self -> #exportMethod:on: } }.\x0a\x09\x09{\x0a\x09\x09\x09self -> #extensionMethodsOfPackage:.\x0a\x09\x09\x09self -> #exportMethod:on: }.\x0a\x09\x09self -> #exportPackageEpilogueOf:on:\x0a\x09}",
  635. messageSends: ["->"],
  636. referencedClasses: []
  637. }),
  638. smalltalk.Exporter);
  639. smalltalk.addClass('ChunkExporter', smalltalk.Exporter, [], 'Importer-Exporter');
  640. smalltalk.ChunkExporter.comment="I am an exporter dedicated to outputting Amber source code in the classic Smalltalk chunk format.\x0a\x0aI do not output any compiled code.";
  641. smalltalk.addMethod(
  642. smalltalk.method({
  643. selector: "chunkEscape:",
  644. category: 'private',
  645. fn: function (aString){
  646. var self=this;
  647. return smalltalk.withContext(function($ctx1) {
  648. var $1;
  649. $1=_st(_st(aString)._replace_with_("!","!!"))._trimBoth();
  650. return $1;
  651. }, function($ctx1) {$ctx1.fill(self,"chunkEscape:",{aString:aString},smalltalk.ChunkExporter)})},
  652. args: ["aString"],
  653. source: "chunkEscape: aString\x0a\x09\x22Replace all occurrences of ! with !! and trim at both ends.\x22\x0a\x0a\x09^(aString replace: '!' with: '!!') trimBoth",
  654. messageSends: ["trimBoth", "replace:with:"],
  655. referencedClasses: []
  656. }),
  657. smalltalk.ChunkExporter);
  658. smalltalk.addMethod(
  659. smalltalk.method({
  660. selector: "classNameFor:",
  661. category: 'private',
  662. fn: function (aClass){
  663. var self=this;
  664. return smalltalk.withContext(function($ctx1) {
  665. var $2,$3,$1;
  666. $2=_st(aClass)._isMetaclass();
  667. if(smalltalk.assert($2)){
  668. $1=_st(_st(_st(aClass)._instanceClass())._name()).__comma(" class");
  669. } else {
  670. $3=_st(aClass)._isNil();
  671. if(smalltalk.assert($3)){
  672. $1="nil";
  673. } else {
  674. $1=_st(aClass)._name();
  675. };
  676. };
  677. return $1;
  678. }, function($ctx1) {$ctx1.fill(self,"classNameFor:",{aClass:aClass},smalltalk.ChunkExporter)})},
  679. args: ["aClass"],
  680. source: "classNameFor: aClass\x0a\x09^aClass isMetaclass\x0a\x09\x09ifTrue: [aClass instanceClass name, ' class']\x0a\x09\x09ifFalse: [\x0a\x09\x09aClass isNil\x0a\x09\x09\x09ifTrue: ['nil']\x0a\x09\x09\x09ifFalse: [aClass name]]",
  681. messageSends: ["ifTrue:ifFalse:", ",", "name", "instanceClass", "isNil", "isMetaclass"],
  682. referencedClasses: []
  683. }),
  684. smalltalk.ChunkExporter);
  685. smalltalk.addMethod(
  686. smalltalk.method({
  687. selector: "exportCategoryEpilogueOf:on:",
  688. category: 'private',
  689. fn: function (category,aStream){
  690. var self=this;
  691. return smalltalk.withContext(function($ctx1) {
  692. var $1,$2;
  693. $1=aStream;
  694. _st($1)._nextPutAll_(" !");
  695. _st($1)._lf();
  696. $2=_st($1)._lf();
  697. return self}, function($ctx1) {$ctx1.fill(self,"exportCategoryEpilogueOf:on:",{category:category,aStream:aStream},smalltalk.ChunkExporter)})},
  698. args: ["category", "aStream"],
  699. source: "exportCategoryEpilogueOf: category on: aStream\x0a\x09aStream nextPutAll: ' !'; lf; lf",
  700. messageSends: ["nextPutAll:", "lf"],
  701. referencedClasses: []
  702. }),
  703. smalltalk.ChunkExporter);
  704. smalltalk.addMethod(
  705. smalltalk.method({
  706. selector: "exportCategoryPrologueOf:on:",
  707. category: 'private',
  708. fn: function (category,aStream){
  709. var self=this;
  710. return smalltalk.withContext(function($ctx1) {
  711. var $1,$2;
  712. $1=aStream;
  713. _st($1)._nextPutAll_("!".__comma(self._classNameFor_(_st(category)._at_("class"))));
  714. $2=_st($1)._nextPutAll_(_st(" methodsFor: '".__comma(_st(category)._at_("name"))).__comma("'!"));
  715. return self}, function($ctx1) {$ctx1.fill(self,"exportCategoryPrologueOf:on:",{category:category,aStream:aStream},smalltalk.ChunkExporter)})},
  716. args: ["category", "aStream"],
  717. source: "exportCategoryPrologueOf: category on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '!', (self classNameFor: (category at: #class));\x0a\x09\x09nextPutAll: ' methodsFor: ''', (category at: #name), '''!'",
  718. messageSends: ["nextPutAll:", ",", "classNameFor:", "at:"],
  719. referencedClasses: []
  720. }),
  721. smalltalk.ChunkExporter);
  722. smalltalk.addMethod(
  723. smalltalk.method({
  724. selector: "exportDefinitionOf:on:",
  725. category: 'private',
  726. fn: function (aClass,aStream){
  727. var self=this;
  728. return smalltalk.withContext(function($ctx1) {
  729. var $1,$2,$3,$4,$5,$6,$7;
  730. $1=aStream;
  731. _st($1)._nextPutAll_(self._classNameFor_(_st(aClass)._superclass()));
  732. _st($1)._nextPutAll_(" subclass: #".__comma(self._classNameFor_(aClass)));
  733. _st($1)._lf();
  734. _st($1)._tab();
  735. $2=_st($1)._nextPutAll_("instanceVariableNames: '");
  736. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  737. return smalltalk.withContext(function($ctx2) {
  738. return _st(aStream)._nextPutAll_(each);
  739. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  740. return smalltalk.withContext(function($ctx2) {
  741. return _st(aStream)._nextPutAll_(" ");
  742. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  743. $3=aStream;
  744. _st($3)._nextPutAll_("'");
  745. _st($3)._lf();
  746. _st($3)._tab();
  747. _st($3)._nextPutAll_(_st("package: '".__comma(_st(aClass)._category())).__comma("'!"));
  748. $4=_st($3)._lf();
  749. $5=_st(_st(aClass)._comment())._notEmpty();
  750. if(smalltalk.assert($5)){
  751. $6=aStream;
  752. _st($6)._nextPutAll_(_st("!".__comma(self._classNameFor_(aClass))).__comma(" commentStamp!"));
  753. _st($6)._lf();
  754. _st($6)._nextPutAll_(_st(self._chunkEscape_(_st(aClass)._comment())).__comma("!"));
  755. $7=_st($6)._lf();
  756. $7;
  757. };
  758. _st(aStream)._lf();
  759. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.ChunkExporter)})},
  760. args: ["aClass", "aStream"],
  761. source: "exportDefinitionOf: aClass on: aStream\x0a\x09\x22Chunk format.\x22\x0a\x0a\x09aStream\x0a\x09\x09nextPutAll: (self classNameFor: aClass superclass);\x0a\x09\x09nextPutAll: ' subclass: #', (self classNameFor: aClass); lf;\x0a\x09\x09tab; nextPutAll: 'instanceVariableNames: '''.\x0a\x09aClass instanceVariableNames\x0a\x09\x09do: [:each | aStream nextPutAll: each]\x0a\x09\x09separatedBy: [aStream nextPutAll: ' '].\x0a\x09aStream\x0a\x09\x09nextPutAll: ''''; lf;\x0a\x09\x09tab; nextPutAll: 'package: ''', aClass category, '''!'; lf.\x0a\x09aClass comment notEmpty ifTrue: [\x0a\x09\x09aStream\x0a\x09\x09nextPutAll: '!', (self classNameFor: aClass), ' commentStamp!';lf;\x0a\x09\x09nextPutAll: (self chunkEscape: aClass comment), '!';lf].\x0a\x09aStream lf",
  762. messageSends: ["nextPutAll:", "classNameFor:", "superclass", ",", "lf", "tab", "do:separatedBy:", "instanceVariableNames", "category", "ifTrue:", "chunkEscape:", "comment", "notEmpty"],
  763. referencedClasses: []
  764. }),
  765. smalltalk.ChunkExporter);
  766. smalltalk.addMethod(
  767. smalltalk.method({
  768. selector: "exportMetaDefinitionOf:on:",
  769. category: 'private',
  770. fn: function (aClass,aStream){
  771. var self=this;
  772. return smalltalk.withContext(function($ctx1) {
  773. var $1,$2,$3,$4,$5;
  774. $1=_st(_st(_st(aClass)._class())._instanceVariableNames())._isEmpty();
  775. if(! smalltalk.assert($1)){
  776. $2=aStream;
  777. _st($2)._nextPutAll_(self._classNameFor_(_st(aClass)._class()));
  778. $3=_st($2)._nextPutAll_(" instanceVariableNames: '");
  779. $3;
  780. _st(_st(_st(aClass)._class())._instanceVariableNames())._do_separatedBy_((function(each){
  781. return smalltalk.withContext(function($ctx2) {
  782. return _st(aStream)._nextPutAll_(each);
  783. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  784. return smalltalk.withContext(function($ctx2) {
  785. return _st(aStream)._nextPutAll_(" ");
  786. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  787. $4=aStream;
  788. _st($4)._nextPutAll_("'!");
  789. _st($4)._lf();
  790. $5=_st($4)._lf();
  791. $5;
  792. };
  793. return self}, function($ctx1) {$ctx1.fill(self,"exportMetaDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.ChunkExporter)})},
  794. args: ["aClass", "aStream"],
  795. source: "exportMetaDefinitionOf: aClass on: aStream\x0a\x0a\x09aClass class instanceVariableNames isEmpty ifFalse: [\x0a\x09\x09aStream\x0a\x09\x09\x09nextPutAll: (self classNameFor: aClass class);\x0a\x09\x09\x09nextPutAll: ' instanceVariableNames: '''.\x0a\x09\x09aClass class instanceVariableNames\x0a\x09\x09\x09do: [:each | aStream nextPutAll: each]\x0a\x09\x09\x09separatedBy: [aStream nextPutAll: ' '].\x0a\x09\x09aStream\x0a\x09\x09\x09nextPutAll: '''!'; lf; lf]",
  796. messageSends: ["ifFalse:", "nextPutAll:", "classNameFor:", "class", "do:separatedBy:", "instanceVariableNames", "lf", "isEmpty"],
  797. referencedClasses: []
  798. }),
  799. smalltalk.ChunkExporter);
  800. smalltalk.addMethod(
  801. smalltalk.method({
  802. selector: "exportMethod:on:",
  803. category: 'private',
  804. fn: function (aMethod,aStream){
  805. var self=this;
  806. return smalltalk.withContext(function($ctx1) {
  807. var $1,$2;
  808. $1=aStream;
  809. _st($1)._lf();
  810. _st($1)._lf();
  811. _st($1)._nextPutAll_(self._chunkEscape_(_st(aMethod)._source()));
  812. _st($1)._lf();
  813. $2=_st($1)._nextPutAll_("!");
  814. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:on:",{aMethod:aMethod,aStream:aStream},smalltalk.ChunkExporter)})},
  815. args: ["aMethod", "aStream"],
  816. source: "exportMethod: aMethod on: aStream\x0a\x09aStream\x0a\x09\x09lf; lf; nextPutAll: (self chunkEscape: aMethod source); lf;\x0a\x09\x09nextPutAll: '!'",
  817. messageSends: ["lf", "nextPutAll:", "chunkEscape:", "source"],
  818. referencedClasses: []
  819. }),
  820. smalltalk.ChunkExporter);
  821. smalltalk.addMethod(
  822. smalltalk.method({
  823. selector: "exportPackageDefinitionOf:on:",
  824. category: 'private',
  825. fn: function (package_,aStream){
  826. var self=this;
  827. return smalltalk.withContext(function($ctx1) {
  828. var $1,$2;
  829. $1=aStream;
  830. _st($1)._nextPutAll_(_st("Smalltalk current createPackage: '".__comma(_st(package_)._name())).__comma("'!"));
  831. $2=_st($1)._lf();
  832. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageDefinitionOf:on:",{package_:package_,aStream:aStream},smalltalk.ChunkExporter)})},
  833. args: ["package", "aStream"],
  834. source: "exportPackageDefinitionOf: package on: aStream\x0a\x09\x22Chunk format.\x22\x0a\x0a\x09aStream\x0a\x09\x09nextPutAll: 'Smalltalk current createPackage: ''', package name, '''!';\x0a\x09\x09lf",
  835. messageSends: ["nextPutAll:", ",", "name", "lf"],
  836. referencedClasses: []
  837. }),
  838. smalltalk.ChunkExporter);
  839. smalltalk.addMethod(
  840. smalltalk.method({
  841. selector: "extensionCategoriesOfPackage:",
  842. category: 'private',
  843. fn: function (package_){
  844. var self=this;
  845. var name,map,result;
  846. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  847. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  848. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  849. function $Package(){return smalltalk.Package||(typeof Package=="undefined"?nil:Package)}
  850. return smalltalk.withContext(function($ctx1) {
  851. var $1,$2;
  852. name=_st(package_)._name();
  853. result=_st($OrderedCollection())._new();
  854. _st(_st($Package())._sortedClasses_(_st(_st($Smalltalk())._current())._classes()))._do_((function(each){
  855. return smalltalk.withContext(function($ctx2) {
  856. return _st([each,_st(each)._class()])._do_((function(aClass){
  857. return smalltalk.withContext(function($ctx3) {
  858. map=_st($Dictionary())._new();
  859. map;
  860. _st(aClass)._protocolsDo_((function(category,methods){
  861. return smalltalk.withContext(function($ctx4) {
  862. $1=_st(category)._match_("^\x5c*".__comma(name));
  863. if(smalltalk.assert($1)){
  864. return _st(map)._at_put_(category,methods);
  865. };
  866. }, function($ctx4) {$ctx4.fillBlock({category:category,methods:methods},$ctx3)})}));
  867. return _st(result)._addAll_(_st(_st(_st(map)._keys())._sorted_((function(a,b){
  868. return smalltalk.withContext(function($ctx4) {
  869. return _st(a).__lt_eq(b);
  870. }, function($ctx4) {$ctx4.fillBlock({a:a,b:b},$ctx3)})})))._collect_((function(category){
  871. return smalltalk.withContext(function($ctx4) {
  872. return smalltalk.HashedCollection._from_(["methods".__minus_gt(_st(map)._at_(category)),"name".__minus_gt(category),"class".__minus_gt(aClass)]);
  873. }, function($ctx4) {$ctx4.fillBlock({category:category},$ctx3)})})));
  874. }, function($ctx3) {$ctx3.fillBlock({aClass:aClass},$ctx2)})}));
  875. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  876. $2=result;
  877. return $2;
  878. }, function($ctx1) {$ctx1.fill(self,"extensionCategoriesOfPackage:",{package_:package_,name:name,map:map,result:result},smalltalk.ChunkExporter)})},
  879. args: ["package"],
  880. source: "extensionCategoriesOfPackage: package\x0a\x09\x22Issue #143: sort protocol alphabetically\x22\x0a\x0a\x09| name map result |\x0a\x09name := package name.\x0a\x09result := OrderedCollection new.\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\x09result addAll: ((map keys sorted: [:a :b | a <= b ]) collect: [:category |\x0a\x09\x09\x09\x09#{ 'methods'->(map at: category). 'name'->category. 'class'->aClass}]) ]].\x0a\x09^result",
  881. messageSends: ["name", "new", "do:", "protocolsDo:", "ifTrue:", "at:put:", "match:", ",", "addAll:", "collect:", "->", "at:", "sorted:", "<=", "keys", "class", "sortedClasses:", "classes", "current"],
  882. referencedClasses: ["OrderedCollection", "Dictionary", "Smalltalk", "Package"]
  883. }),
  884. smalltalk.ChunkExporter);
  885. smalltalk.addMethod(
  886. smalltalk.method({
  887. selector: "methodsOfCategory:",
  888. category: 'private',
  889. fn: function (category){
  890. var self=this;
  891. return smalltalk.withContext(function($ctx1) {
  892. var $1;
  893. $1=_st(_st(category)._at_("methods"))._sorted_((function(a,b){
  894. return smalltalk.withContext(function($ctx2) {
  895. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  896. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})}));
  897. return $1;
  898. }, function($ctx1) {$ctx1.fill(self,"methodsOfCategory:",{category:category},smalltalk.ChunkExporter)})},
  899. args: ["category"],
  900. source: "methodsOfCategory: category\x0a\x09\x22Issue #143: sort methods alphabetically\x22\x0a\x0a\x09^(category at: #methods) sorted: [:a :b | a selector <= b selector]",
  901. messageSends: ["sorted:", "<=", "selector", "at:"],
  902. referencedClasses: []
  903. }),
  904. smalltalk.ChunkExporter);
  905. smalltalk.addMethod(
  906. smalltalk.method({
  907. selector: "ownCategoriesOfClass:",
  908. category: 'private',
  909. fn: function (aClass){
  910. var self=this;
  911. var map;
  912. function $Dictionary(){return smalltalk.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  913. return smalltalk.withContext(function($ctx1) {
  914. var $1,$2;
  915. map=_st($Dictionary())._new();
  916. _st(aClass)._protocolsDo_((function(category,methods){
  917. return smalltalk.withContext(function($ctx2) {
  918. $1=_st(category)._match_("^\x5c*");
  919. if(! smalltalk.assert($1)){
  920. return _st(map)._at_put_(category,methods);
  921. };
  922. }, function($ctx2) {$ctx2.fillBlock({category:category,methods:methods},$ctx1)})}));
  923. $2=_st(_st(_st(map)._keys())._sorted_((function(a,b){
  924. return smalltalk.withContext(function($ctx2) {
  925. return _st(a).__lt_eq(b);
  926. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})})))._collect_((function(category){
  927. return smalltalk.withContext(function($ctx2) {
  928. return smalltalk.HashedCollection._from_(["methods".__minus_gt(_st(map)._at_(category)),"name".__minus_gt(category),"class".__minus_gt(aClass)]);
  929. }, function($ctx2) {$ctx2.fillBlock({category:category},$ctx1)})}));
  930. return $2;
  931. }, function($ctx1) {$ctx1.fill(self,"ownCategoriesOfClass:",{aClass:aClass,map:map},smalltalk.ChunkExporter)})},
  932. args: ["aClass"],
  933. source: "ownCategoriesOfClass: aClass\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 ]) collect: [:category |\x0a\x09\x09#{\x0a\x09\x09\x09'methods'->(map at: category).\x0a\x09\x09\x09'name'->category.\x0a\x09\x09\x09'class'->aClass }]",
  934. messageSends: ["new", "protocolsDo:", "ifFalse:", "at:put:", "match:", "collect:", "->", "at:", "sorted:", "<=", "keys"],
  935. referencedClasses: ["Dictionary"]
  936. }),
  937. smalltalk.ChunkExporter);
  938. smalltalk.addMethod(
  939. smalltalk.method({
  940. selector: "ownCategoriesOfMetaClass:",
  941. category: 'private',
  942. fn: function (aClass){
  943. var self=this;
  944. return smalltalk.withContext(function($ctx1) {
  945. var $1;
  946. $1=self._ownCategoriesOfClass_(_st(aClass)._class());
  947. return $1;
  948. }, function($ctx1) {$ctx1.fill(self,"ownCategoriesOfMetaClass:",{aClass:aClass},smalltalk.ChunkExporter)})},
  949. args: ["aClass"],
  950. source: "ownCategoriesOfMetaClass: aClass\x0a\x09\x22Issue #143: sort protocol alphabetically\x22\x0a\x0a\x09^self ownCategoriesOfClass: aClass class",
  951. messageSends: ["ownCategoriesOfClass:", "class"],
  952. referencedClasses: []
  953. }),
  954. smalltalk.ChunkExporter);
  955. smalltalk.addMethod(
  956. smalltalk.method({
  957. selector: "recipe",
  958. category: 'fileOut',
  959. fn: function (){
  960. var self=this;
  961. var exportCategoryRecipe;
  962. return smalltalk.withContext(function($ctx1) {
  963. var $1;
  964. exportCategoryRecipe=[self.__minus_gt("exportCategoryPrologueOf:on:"),[self.__minus_gt("methodsOfCategory:"),self.__minus_gt("exportMethod:on:")],self.__minus_gt("exportCategoryEpilogueOf:on:")];
  965. $1=[self.__minus_gt("exportPackageDefinitionOf:on:"),[self.__minus_gt("ownClassesOfPackage:"),self.__minus_gt("exportDefinitionOf:on:"),_st([self.__minus_gt("ownCategoriesOfClass:")]).__comma(exportCategoryRecipe),self.__minus_gt("exportMetaDefinitionOf:on:"),_st([self.__minus_gt("ownCategoriesOfMetaClass:")]).__comma(exportCategoryRecipe)],_st([self.__minus_gt("extensionCategoriesOfPackage:")]).__comma(exportCategoryRecipe)];
  966. return $1;
  967. }, function($ctx1) {$ctx1.fill(self,"recipe",{exportCategoryRecipe:exportCategoryRecipe},smalltalk.ChunkExporter)})},
  968. args: [],
  969. source: "recipe\x0a\x09\x22Export a given package.\x22\x0a\x0a\x09| exportCategoryRecipe |\x0a\x09exportCategoryRecipe := {\x0a\x09\x09self -> #exportCategoryPrologueOf:on:.\x0a\x09\x09{\x0a\x09\x09\x09self -> #methodsOfCategory:.\x0a\x09\x09\x09self -> #exportMethod:on: }.\x0a\x09\x09self -> #exportCategoryEpilogueOf:on: }.\x0a\x0a\x09^{\x0a\x09\x09self -> #exportPackageDefinitionOf:on:.\x0a\x09\x09{\x0a\x09\x09\x09self -> #ownClassesOfPackage:.\x0a\x09\x09\x09self -> #exportDefinitionOf:on:.\x0a\x09\x09\x09{ self -> #ownCategoriesOfClass: }, exportCategoryRecipe.\x0a\x09\x09\x09self -> #exportMetaDefinitionOf:on:.\x0a\x09\x09\x09{ self -> #ownCategoriesOfMetaClass: }, exportCategoryRecipe }.\x0a\x09\x09{ self -> #extensionCategoriesOfPackage: }, exportCategoryRecipe\x0a\x09}",
  970. messageSends: ["->", ","],
  971. referencedClasses: []
  972. }),
  973. smalltalk.ChunkExporter);
  974. smalltalk.addClass('StrippedExporter', smalltalk.Exporter, [], 'Importer-Exporter');
  975. smalltalk.StrippedExporter.comment="I export Amber code into a JavaScript string, but without any optional associated data like the Amber source code.";
  976. smalltalk.addMethod(
  977. smalltalk.method({
  978. selector: "exportDefinitionOf:on:",
  979. category: 'private',
  980. fn: function (aClass,aStream){
  981. var self=this;
  982. return smalltalk.withContext(function($ctx1) {
  983. var $1,$2,$3,$4;
  984. $1=aStream;
  985. _st($1)._lf();
  986. _st($1)._nextPutAll_("smalltalk.addClass(");
  987. _st($1)._nextPutAll_(_st("'".__comma(self._classNameFor_(aClass))).__comma("', "));
  988. _st($1)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aClass)._superclass())));
  989. $2=_st($1)._nextPutAll_(", [");
  990. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  991. return smalltalk.withContext(function($ctx2) {
  992. return _st(aStream)._nextPutAll_(_st("'".__comma(each)).__comma("'"));
  993. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  994. return smalltalk.withContext(function($ctx2) {
  995. return _st(aStream)._nextPutAll_(", ");
  996. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  997. $3=aStream;
  998. _st($3)._nextPutAll_("], '");
  999. _st($3)._nextPutAll_(_st(_st(aClass)._category()).__comma("'"));
  1000. $4=_st($3)._nextPutAll_(");");
  1001. _st(aStream)._lf();
  1002. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.StrippedExporter)})},
  1003. args: ["aClass", "aStream"],
  1004. source: "exportDefinitionOf: aClass on: aStream\x0a\x09aStream\x0a\x09\x09lf;\x0a\x09\x09nextPutAll: 'smalltalk.addClass(';\x0a\x09\x09nextPutAll: '''', (self classNameFor: aClass), ''', ';\x0a\x09\x09nextPutAll: 'smalltalk.', (self classNameFor: aClass superclass);\x0a\x09\x09nextPutAll: ', ['.\x0a\x09aClass instanceVariableNames\x0a\x09\x09do: [:each | aStream nextPutAll: '''', each, '''']\x0a\x09\x09separatedBy: [aStream nextPutAll: ', '].\x0a\x09aStream\x0a\x09\x09nextPutAll: '], ''';\x0a\x09\x09nextPutAll: aClass category, '''';\x0a\x09\x09nextPutAll: ');'.\x0a\x09aStream lf",
  1005. messageSends: ["lf", "nextPutAll:", ",", "classNameFor:", "superclass", "do:separatedBy:", "instanceVariableNames", "category"],
  1006. referencedClasses: []
  1007. }),
  1008. smalltalk.StrippedExporter);
  1009. smalltalk.addMethod(
  1010. smalltalk.method({
  1011. selector: "exportMethod:on:",
  1012. category: 'private',
  1013. fn: function (aMethod,aStream){
  1014. var self=this;
  1015. return smalltalk.withContext(function($ctx1) {
  1016. var $1,$2;
  1017. $1=aStream;
  1018. _st($1)._nextPutAll_("smalltalk.addMethod(");
  1019. _st($1)._lf();
  1020. _st($1)._nextPutAll_("smalltalk.method({");
  1021. _st($1)._lf();
  1022. _st($1)._nextPutAll_(_st("selector: ".__comma(_st(_st(aMethod)._selector())._asJavascript())).__comma(","));
  1023. _st($1)._lf();
  1024. _st($1)._nextPutAll_(_st("fn: ".__comma(_st(_st(aMethod)._fn())._compiledSource())).__comma(","));
  1025. _st($1)._lf();
  1026. _st($1)._nextPutAll_("messageSends: ".__comma(_st(_st(aMethod)._messageSends())._asJavascript()));
  1027. _st($1)._nextPutAll_("}),");
  1028. _st($1)._lf();
  1029. _st($1)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aMethod)._methodClass())));
  1030. _st($1)._nextPutAll_(");");
  1031. _st($1)._lf();
  1032. $2=_st($1)._lf();
  1033. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:on:",{aMethod:aMethod,aStream:aStream},smalltalk.StrippedExporter)})},
  1034. args: ["aMethod", "aStream"],
  1035. source: "exportMethod: aMethod on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: 'smalltalk.addMethod(';lf;\x0a\x09\x09\x22nextPutAll: aMethod selector asSelector asJavascript, ',';lf;\x22\x0a\x09\x09nextPutAll: 'smalltalk.method({';lf;\x0a\x09\x09nextPutAll: 'selector: ', aMethod selector asJavascript, ',';lf;\x0a\x09\x09nextPutAll: 'fn: ', aMethod fn compiledSource, ',';lf;\x0a\x09\x09nextPutAll: 'messageSends: ', aMethod messageSends asJavascript;\x0a\x09\x09nextPutAll: '}),';lf;\x0a\x09\x09nextPutAll: 'smalltalk.', (self classNameFor: aMethod methodClass);\x0a\x09\x09nextPutAll: ');';lf;lf",
  1036. messageSends: ["nextPutAll:", "lf", ",", "asJavascript", "selector", "compiledSource", "fn", "messageSends", "classNameFor:", "methodClass"],
  1037. referencedClasses: []
  1038. }),
  1039. smalltalk.StrippedExporter);
  1040. smalltalk.addMethod(
  1041. smalltalk.method({
  1042. selector: "commit",
  1043. category: '*Importer-Exporter',
  1044. fn: function (){
  1045. var self=this;
  1046. function $PackageHandler(){return smalltalk.PackageHandler||(typeof PackageHandler=="undefined"?nil:PackageHandler)}
  1047. return smalltalk.withContext(function($ctx1) {
  1048. var $1;
  1049. $1=_st(_st($PackageHandler())._new())._commit_(self);
  1050. return $1;
  1051. }, function($ctx1) {$ctx1.fill(self,"commit",{},smalltalk.Package)})},
  1052. args: [],
  1053. source: "commit\x0a\x09^ PackageHandler new commit: self",
  1054. messageSends: ["commit:", "new"],
  1055. referencedClasses: ["PackageHandler"]
  1056. }),
  1057. smalltalk.Package);
  1058. })(global_smalltalk,global_nil,global__st);