Importer-Exporter.js 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936
  1. define("amber/Importer-Exporter", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber/Kernel-Objects", "amber/Kernel-Infrastructure"], function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Importer-Exporter');
  3. smalltalk.packages["Importer-Exporter"].transport = {"type":"amd","amdNamespace":"amber"};
  4. smalltalk.addClass('AbstractExporter', smalltalk.Object, [], 'Importer-Exporter');
  5. smalltalk.AbstractExporter.comment="I am an abstract exporter for Amber source code.\x0a\x0a## API\x0a\x0aUse `#exportPackage:on:` to export a given package on a Stream.";
  6. smalltalk.addMethod(
  7. smalltalk.method({
  8. selector: "chunkEscape:",
  9. category: 'convenience',
  10. fn: function (aString){
  11. var self=this;
  12. return smalltalk.withContext(function($ctx1) {
  13. var $1;
  14. $1=_st(_st(aString)._replace_with_("!","!!"))._trimBoth();
  15. return $1;
  16. }, function($ctx1) {$ctx1.fill(self,"chunkEscape:",{aString:aString},smalltalk.AbstractExporter)})},
  17. args: ["aString"],
  18. source: "chunkEscape: aString\x0a\x09\x22Replace all occurrences of ! with !! and trim at both ends.\x22\x0a\x0a\x09^(aString replace: '!' with: '!!') trimBoth",
  19. messageSends: ["trimBoth", "replace:with:"],
  20. referencedClasses: []
  21. }),
  22. smalltalk.AbstractExporter);
  23. smalltalk.addMethod(
  24. smalltalk.method({
  25. selector: "classNameFor:",
  26. category: 'convenience',
  27. fn: function (aClass){
  28. var self=this;
  29. return smalltalk.withContext(function($ctx1) {
  30. var $2,$3,$1;
  31. $2=_st(aClass)._isMetaclass();
  32. if(smalltalk.assert($2)){
  33. $1=_st(_st(_st(aClass)._instanceClass())._name()).__comma(" class");
  34. } else {
  35. $3=_st(aClass)._isNil();
  36. if(smalltalk.assert($3)){
  37. $1="nil";
  38. } else {
  39. $1=_st(aClass)._name();
  40. };
  41. };
  42. return $1;
  43. }, function($ctx1) {$ctx1.fill(self,"classNameFor:",{aClass:aClass},smalltalk.AbstractExporter)})},
  44. args: ["aClass"],
  45. source: "classNameFor: aClass\x0a\x09^aClass isMetaclass\x0a\x09\x09ifTrue: [ aClass instanceClass name, ' class' ]\x0a\x09\x09ifFalse: [\x0a\x09\x09\x09aClass isNil\x0a\x09\x09\x09\x09ifTrue: [ 'nil' ]\x0a\x09\x09\x09\x09ifFalse: [ aClass name ] ]",
  46. messageSends: ["ifTrue:ifFalse:", ",", "name", "instanceClass", "isNil", "isMetaclass"],
  47. referencedClasses: []
  48. }),
  49. smalltalk.AbstractExporter);
  50. smalltalk.addMethod(
  51. smalltalk.method({
  52. selector: "exportPackage:on:",
  53. category: 'output',
  54. fn: function (aPackage,aStream){
  55. var self=this;
  56. return smalltalk.withContext(function($ctx1) {
  57. self._subclassResponsibility();
  58. return self}, function($ctx1) {$ctx1.fill(self,"exportPackage:on:",{aPackage:aPackage,aStream:aStream},smalltalk.AbstractExporter)})},
  59. args: ["aPackage", "aStream"],
  60. source: "exportPackage: aPackage on: aStream\x0a\x09self subclassResponsibility",
  61. messageSends: ["subclassResponsibility"],
  62. referencedClasses: []
  63. }),
  64. smalltalk.AbstractExporter);
  65. smalltalk.addMethod(
  66. smalltalk.method({
  67. selector: "extensionMethodsOfPackage:",
  68. category: 'accessing',
  69. fn: function (aPackage){
  70. var self=this;
  71. var result;
  72. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  73. return smalltalk.withContext(function($ctx1) {
  74. var $1;
  75. result=_st($OrderedCollection())._new();
  76. _st(self._extensionProtocolsOfPackage_(aPackage))._do_((function(each){
  77. return smalltalk.withContext(function($ctx2) {
  78. return _st(result)._addAll_(_st(each)._methods());
  79. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  80. $1=result;
  81. return $1;
  82. }, function($ctx1) {$ctx1.fill(self,"extensionMethodsOfPackage:",{aPackage:aPackage,result:result},smalltalk.AbstractExporter)})},
  83. args: ["aPackage"],
  84. source: "extensionMethodsOfPackage: aPackage\x0a\x09| result |\x0a\x09\x0a\x09result := OrderedCollection new.\x0a\x09\x0a\x09(self extensionProtocolsOfPackage: aPackage) do: [ :each |\x0a\x09\x09result addAll: each methods ].\x0a\x09\x09\x0a\x09^ result",
  85. messageSends: ["new", "do:", "addAll:", "methods", "extensionProtocolsOfPackage:"],
  86. referencedClasses: ["OrderedCollection"]
  87. }),
  88. smalltalk.AbstractExporter);
  89. smalltalk.addMethod(
  90. smalltalk.method({
  91. selector: "extensionProtocolsOfPackage:",
  92. category: 'accessing',
  93. fn: function (aPackage){
  94. var self=this;
  95. var extensionName,result;
  96. function $OrderedCollection(){return smalltalk.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  97. function $ExportMethodProtocol(){return smalltalk.ExportMethodProtocol||(typeof ExportMethodProtocol=="undefined"?nil:ExportMethodProtocol)}
  98. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  99. return smalltalk.withContext(function($ctx1) {
  100. var $1,$2;
  101. extensionName="*".__comma(_st(aPackage)._name());
  102. result=_st($OrderedCollection())._new();
  103. _st(_st(_st($Smalltalk())._current())._classes())._do_((function(each){
  104. return smalltalk.withContext(function($ctx2) {
  105. return _st([each,_st(each)._class()])._do_((function(behavior){
  106. return smalltalk.withContext(function($ctx3) {
  107. $1=_st(_st(behavior)._protocols())._includes_(extensionName);
  108. if(smalltalk.assert($1)){
  109. return _st(result)._add_(_st($ExportMethodProtocol())._name_theClass_(extensionName,behavior));
  110. };
  111. }, function($ctx3) {$ctx3.fillBlock({behavior:behavior},$ctx2)})}));
  112. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  113. $2=result;
  114. return $2;
  115. }, function($ctx1) {$ctx1.fill(self,"extensionProtocolsOfPackage:",{aPackage:aPackage,extensionName:extensionName,result:result},smalltalk.AbstractExporter)})},
  116. args: ["aPackage"],
  117. source: "extensionProtocolsOfPackage: aPackage\x0a\x09| extensionName result |\x0a\x09\x0a\x09extensionName := '*', aPackage name.\x0a\x09result := OrderedCollection new.\x0a\x09\x0a\x09\x22The classes must be loaded since it is extensions only.\x0a\x09Therefore sorting (dependency resolution) does not matter here.\x0a\x09Not sorting improves the speed by a number of magnitude.\x22\x0a\x09\x0a\x09Smalltalk current classes do: [ :each |\x0a\x09\x09{each. each class} do: [ :behavior |\x0a\x09\x09\x09(behavior protocols includes: extensionName) ifTrue: [\x0a\x09\x09\x09\x09result add: (ExportMethodProtocol name: extensionName theClass: behavior) ] ] ].\x0a\x0a\x09^result",
  118. messageSends: [",", "name", "new", "do:", "ifTrue:", "add:", "name:theClass:", "includes:", "protocols", "class", "classes", "current"],
  119. referencedClasses: ["OrderedCollection", "ExportMethodProtocol", "Smalltalk"]
  120. }),
  121. smalltalk.AbstractExporter);
  122. smalltalk.AbstractExporter.klass.iVarNames = ['default'];
  123. smalltalk.addMethod(
  124. smalltalk.method({
  125. selector: "default",
  126. category: 'instance creation',
  127. fn: function (){
  128. var self=this;
  129. return smalltalk.withContext(function($ctx1) {
  130. var $2,$1;
  131. $2=self["@default"];
  132. if(($receiver = $2) == nil || $receiver == undefined){
  133. self["@default"]=self._new();
  134. $1=self["@default"];
  135. } else {
  136. $1=$2;
  137. };
  138. return $1;
  139. }, function($ctx1) {$ctx1.fill(self,"default",{},smalltalk.AbstractExporter.klass)})},
  140. args: [],
  141. source: "default\x0a\x09^ default ifNil: [ default := self new ]",
  142. messageSends: ["ifNil:", "new"],
  143. referencedClasses: []
  144. }),
  145. smalltalk.AbstractExporter.klass);
  146. smalltalk.addClass('ChunkExporter', smalltalk.AbstractExporter, [], 'Importer-Exporter');
  147. 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.";
  148. smalltalk.addMethod(
  149. smalltalk.method({
  150. selector: "exportDefinitionOf:on:",
  151. category: 'output',
  152. fn: function (aClass,aStream){
  153. var self=this;
  154. return smalltalk.withContext(function($ctx1) {
  155. var $1,$2,$3,$4,$5,$6,$7;
  156. $1=aStream;
  157. _st($1)._nextPutAll_(self._classNameFor_(_st(aClass)._superclass()));
  158. _st($1)._nextPutAll_(" subclass: #".__comma(self._classNameFor_(aClass)));
  159. _st($1)._lf();
  160. _st($1)._tab();
  161. $2=_st($1)._nextPutAll_("instanceVariableNames: '");
  162. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  163. return smalltalk.withContext(function($ctx2) {
  164. return _st(aStream)._nextPutAll_(each);
  165. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  166. return smalltalk.withContext(function($ctx2) {
  167. return _st(aStream)._nextPutAll_(" ");
  168. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  169. $3=aStream;
  170. _st($3)._nextPutAll_("'");
  171. _st($3)._lf();
  172. _st($3)._tab();
  173. _st($3)._nextPutAll_(_st("package: '".__comma(_st(aClass)._category())).__comma("'!"));
  174. $4=_st($3)._lf();
  175. $5=_st(_st(aClass)._comment())._notEmpty();
  176. if(smalltalk.assert($5)){
  177. $6=aStream;
  178. _st($6)._nextPutAll_(_st("!".__comma(self._classNameFor_(aClass))).__comma(" commentStamp!"));
  179. _st($6)._lf();
  180. _st($6)._nextPutAll_(_st(self._chunkEscape_(_st(aClass)._comment())).__comma("!"));
  181. $7=_st($6)._lf();
  182. $7;
  183. };
  184. _st(aStream)._lf();
  185. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.ChunkExporter)})},
  186. args: ["aClass", "aStream"],
  187. 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",
  188. messageSends: ["nextPutAll:", "classNameFor:", "superclass", ",", "lf", "tab", "do:separatedBy:", "instanceVariableNames", "category", "ifTrue:", "chunkEscape:", "comment", "notEmpty"],
  189. referencedClasses: []
  190. }),
  191. smalltalk.ChunkExporter);
  192. smalltalk.addMethod(
  193. smalltalk.method({
  194. selector: "exportMetaDefinitionOf:on:",
  195. category: 'output',
  196. fn: function (aClass,aStream){
  197. var self=this;
  198. return smalltalk.withContext(function($ctx1) {
  199. var $1,$2,$3,$4,$5;
  200. $1=_st(_st(_st(aClass)._class())._instanceVariableNames())._isEmpty();
  201. if(! smalltalk.assert($1)){
  202. $2=aStream;
  203. _st($2)._nextPutAll_(self._classNameFor_(_st(aClass)._class()));
  204. $3=_st($2)._nextPutAll_(" instanceVariableNames: '");
  205. $3;
  206. _st(_st(_st(aClass)._class())._instanceVariableNames())._do_separatedBy_((function(each){
  207. return smalltalk.withContext(function($ctx2) {
  208. return _st(aStream)._nextPutAll_(each);
  209. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  210. return smalltalk.withContext(function($ctx2) {
  211. return _st(aStream)._nextPutAll_(" ");
  212. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  213. $4=aStream;
  214. _st($4)._nextPutAll_("'!");
  215. _st($4)._lf();
  216. $5=_st($4)._lf();
  217. $5;
  218. };
  219. return self}, function($ctx1) {$ctx1.fill(self,"exportMetaDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.ChunkExporter)})},
  220. args: ["aClass", "aStream"],
  221. 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]",
  222. messageSends: ["ifFalse:", "nextPutAll:", "classNameFor:", "class", "do:separatedBy:", "instanceVariableNames", "lf", "isEmpty"],
  223. referencedClasses: []
  224. }),
  225. smalltalk.ChunkExporter);
  226. smalltalk.addMethod(
  227. smalltalk.method({
  228. selector: "exportMethod:on:",
  229. category: 'output',
  230. fn: function (aMethod,aStream){
  231. var self=this;
  232. return smalltalk.withContext(function($ctx1) {
  233. var $1,$2;
  234. $1=aStream;
  235. _st($1)._lf();
  236. _st($1)._lf();
  237. _st($1)._nextPutAll_(self._chunkEscape_(_st(aMethod)._source()));
  238. _st($1)._lf();
  239. $2=_st($1)._nextPutAll_("!");
  240. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:on:",{aMethod:aMethod,aStream:aStream},smalltalk.ChunkExporter)})},
  241. args: ["aMethod", "aStream"],
  242. source: "exportMethod: aMethod on: aStream\x0a\x09aStream\x0a\x09\x09lf; lf; nextPutAll: (self chunkEscape: aMethod source); lf;\x0a\x09\x09nextPutAll: '!'",
  243. messageSends: ["lf", "nextPutAll:", "chunkEscape:", "source"],
  244. referencedClasses: []
  245. }),
  246. smalltalk.ChunkExporter);
  247. smalltalk.addMethod(
  248. smalltalk.method({
  249. selector: "exportPackage:on:",
  250. category: 'output',
  251. fn: function (aPackage,aStream){
  252. var self=this;
  253. return smalltalk.withContext(function($ctx1) {
  254. self._exportPackageDefinitionOf_on_(aPackage,aStream);
  255. _st(_st(aPackage)._sortedClasses())._do_((function(each){
  256. return smalltalk.withContext(function($ctx2) {
  257. self._exportDefinitionOf_on_(each,aStream);
  258. self._exportProtocols_on_(self._ownMethodProtocolsOfClass_(each),aStream);
  259. self._exportMetaDefinitionOf_on_(each,aStream);
  260. return self._exportProtocols_on_(self._ownMethodProtocolsOfClass_(_st(each)._class()),aStream);
  261. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  262. self._exportProtocols_on_(self._extensionProtocolsOfPackage_(aPackage),aStream);
  263. return self}, function($ctx1) {$ctx1.fill(self,"exportPackage:on:",{aPackage:aPackage,aStream:aStream},smalltalk.ChunkExporter)})},
  264. args: ["aPackage", "aStream"],
  265. source: "exportPackage: aPackage on: aStream\x0a\x0a\x09self exportPackageDefinitionOf: aPackage on: aStream.\x0a\x09\x0a\x09aPackage sortedClasses do: [ :each |\x0a\x09\x09self exportDefinitionOf: each on: aStream.\x0a\x09\x09\x0a\x09\x09self \x0a\x09\x09\x09exportProtocols: (self ownMethodProtocolsOfClass: each)\x0a\x09\x09\x09on: aStream.\x0a\x09\x09\x09\x0a\x09\x09self exportMetaDefinitionOf: each on: aStream.\x0a\x09\x09\x0a\x09\x09self \x0a\x09\x09\x09exportProtocols: (self ownMethodProtocolsOfClass: each class)\x0a\x09\x09\x09on: aStream ].\x0a\x09\x09\x09\x0a\x09self \x0a\x09\x09exportProtocols: (self extensionProtocolsOfPackage: aPackage)\x0a\x09\x09on: aStream",
  266. messageSends: ["exportPackageDefinitionOf:on:", "do:", "exportDefinitionOf:on:", "exportProtocols:on:", "ownMethodProtocolsOfClass:", "exportMetaDefinitionOf:on:", "class", "sortedClasses", "extensionProtocolsOfPackage:"],
  267. referencedClasses: []
  268. }),
  269. smalltalk.ChunkExporter);
  270. smalltalk.addMethod(
  271. smalltalk.method({
  272. selector: "exportPackageDefinitionOf:on:",
  273. category: 'output',
  274. fn: function (aPackage,aStream){
  275. var self=this;
  276. return smalltalk.withContext(function($ctx1) {
  277. var $1,$2;
  278. $1=aStream;
  279. _st($1)._nextPutAll_(_st("Smalltalk current createPackage: '".__comma(_st(aPackage)._name())).__comma("'!"));
  280. $2=_st($1)._lf();
  281. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageDefinitionOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.ChunkExporter)})},
  282. args: ["aPackage", "aStream"],
  283. source: "exportPackageDefinitionOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: 'Smalltalk current createPackage: ''', aPackage name, '''!';\x0a\x09\x09lf",
  284. messageSends: ["nextPutAll:", ",", "name", "lf"],
  285. referencedClasses: []
  286. }),
  287. smalltalk.ChunkExporter);
  288. smalltalk.addMethod(
  289. smalltalk.method({
  290. selector: "exportProtocol:on:",
  291. category: 'output',
  292. fn: function (aProtocol,aStream){
  293. var self=this;
  294. return smalltalk.withContext(function($ctx1) {
  295. self._exportProtocolPrologueOf_on_(aProtocol,aStream);
  296. _st(_st(aProtocol)._methods())._do_((function(method){
  297. return smalltalk.withContext(function($ctx2) {
  298. return self._exportMethod_on_(method,aStream);
  299. }, function($ctx2) {$ctx2.fillBlock({method:method},$ctx1)})}));
  300. self._exportProtocolEpilogueOf_on_(aProtocol,aStream);
  301. return self}, function($ctx1) {$ctx1.fill(self,"exportProtocol:on:",{aProtocol:aProtocol,aStream:aStream},smalltalk.ChunkExporter)})},
  302. args: ["aProtocol", "aStream"],
  303. source: "exportProtocol: aProtocol on: aStream\x0a\x09self exportProtocolPrologueOf: aProtocol on: aStream.\x0a\x09aProtocol methods do: [ :method | \x0a\x09\x09self exportMethod: method on: aStream ].\x0a\x09self exportProtocolEpilogueOf: aProtocol on: aStream",
  304. messageSends: ["exportProtocolPrologueOf:on:", "do:", "exportMethod:on:", "methods", "exportProtocolEpilogueOf:on:"],
  305. referencedClasses: []
  306. }),
  307. smalltalk.ChunkExporter);
  308. smalltalk.addMethod(
  309. smalltalk.method({
  310. selector: "exportProtocolEpilogueOf:on:",
  311. category: 'output',
  312. fn: function (aProtocol,aStream){
  313. var self=this;
  314. return smalltalk.withContext(function($ctx1) {
  315. var $1,$2;
  316. $1=aStream;
  317. _st($1)._nextPutAll_(" !");
  318. _st($1)._lf();
  319. $2=_st($1)._lf();
  320. return self}, function($ctx1) {$ctx1.fill(self,"exportProtocolEpilogueOf:on:",{aProtocol:aProtocol,aStream:aStream},smalltalk.ChunkExporter)})},
  321. args: ["aProtocol", "aStream"],
  322. source: "exportProtocolEpilogueOf: aProtocol on: aStream\x0a\x09aStream nextPutAll: ' !'; lf; lf",
  323. messageSends: ["nextPutAll:", "lf"],
  324. referencedClasses: []
  325. }),
  326. smalltalk.ChunkExporter);
  327. smalltalk.addMethod(
  328. smalltalk.method({
  329. selector: "exportProtocolPrologueOf:on:",
  330. category: 'output',
  331. fn: function (aProtocol,aStream){
  332. var self=this;
  333. return smalltalk.withContext(function($ctx1) {
  334. var $1,$2;
  335. $1=aStream;
  336. _st($1)._nextPutAll_("!".__comma(self._classNameFor_(_st(aProtocol)._theClass())));
  337. $2=_st($1)._nextPutAll_(_st(" methodsFor: '".__comma(_st(aProtocol)._name())).__comma("'!"));
  338. return self}, function($ctx1) {$ctx1.fill(self,"exportProtocolPrologueOf:on:",{aProtocol:aProtocol,aStream:aStream},smalltalk.ChunkExporter)})},
  339. args: ["aProtocol", "aStream"],
  340. source: "exportProtocolPrologueOf: aProtocol on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '!', (self classNameFor: aProtocol theClass);\x0a\x09\x09nextPutAll: ' methodsFor: ''', aProtocol name, '''!'",
  341. messageSends: ["nextPutAll:", ",", "classNameFor:", "theClass", "name"],
  342. referencedClasses: []
  343. }),
  344. smalltalk.ChunkExporter);
  345. smalltalk.addMethod(
  346. smalltalk.method({
  347. selector: "exportProtocols:on:",
  348. category: 'output',
  349. fn: function (aCollection,aStream){
  350. var self=this;
  351. return smalltalk.withContext(function($ctx1) {
  352. _st(aCollection)._do_((function(each){
  353. return smalltalk.withContext(function($ctx2) {
  354. return self._exportProtocol_on_(each,aStream);
  355. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  356. return self}, function($ctx1) {$ctx1.fill(self,"exportProtocols:on:",{aCollection:aCollection,aStream:aStream},smalltalk.ChunkExporter)})},
  357. args: ["aCollection", "aStream"],
  358. source: "exportProtocols: aCollection on: aStream\x0a\x09aCollection do: [ :each |\x0a\x09\x09self exportProtocol: each on: aStream ]",
  359. messageSends: ["do:", "exportProtocol:on:"],
  360. referencedClasses: []
  361. }),
  362. smalltalk.ChunkExporter);
  363. smalltalk.addMethod(
  364. smalltalk.method({
  365. selector: "ownMethodProtocolsOfClass:",
  366. category: 'accessing',
  367. fn: function (aClass){
  368. var self=this;
  369. function $ExportMethodProtocol(){return smalltalk.ExportMethodProtocol||(typeof ExportMethodProtocol=="undefined"?nil:ExportMethodProtocol)}
  370. return smalltalk.withContext(function($ctx1) {
  371. var $1;
  372. $1=_st(_st(aClass)._ownProtocols())._collect_((function(each){
  373. return smalltalk.withContext(function($ctx2) {
  374. return _st($ExportMethodProtocol())._name_theClass_(each,aClass);
  375. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  376. return $1;
  377. }, function($ctx1) {$ctx1.fill(self,"ownMethodProtocolsOfClass:",{aClass:aClass},smalltalk.ChunkExporter)})},
  378. args: ["aClass"],
  379. source: "ownMethodProtocolsOfClass: aClass\x0a\x09\x22Answer a collection of ExportMethodProtocol object of aClass that are not package extensions\x22\x0a\x09\x0a\x09^ aClass ownProtocols collect: [ :each |\x0a\x09\x09ExportMethodProtocol name: each theClass: aClass ]",
  380. messageSends: ["collect:", "name:theClass:", "ownProtocols"],
  381. referencedClasses: ["ExportMethodProtocol"]
  382. }),
  383. smalltalk.ChunkExporter);
  384. smalltalk.addClass('Exporter', smalltalk.AbstractExporter, [], 'Importer-Exporter');
  385. 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.).";
  386. smalltalk.addMethod(
  387. smalltalk.method({
  388. selector: "classNameFor:",
  389. category: 'convenience',
  390. fn: function (aClass){
  391. var self=this;
  392. return smalltalk.withContext(function($ctx1) {
  393. var $2,$3,$1;
  394. $2=_st(aClass)._isMetaclass();
  395. if(smalltalk.assert($2)){
  396. $1=_st(_st(_st(aClass)._instanceClass())._name()).__comma(".klass");
  397. } else {
  398. $3=_st(aClass)._isNil();
  399. if(smalltalk.assert($3)){
  400. $1="nil";
  401. } else {
  402. $1=_st(aClass)._name();
  403. };
  404. };
  405. return $1;
  406. }, function($ctx1) {$ctx1.fill(self,"classNameFor:",{aClass:aClass},smalltalk.Exporter)})},
  407. args: ["aClass"],
  408. source: "classNameFor: aClass\x0a\x09^aClass isMetaclass\x0a\x09\x09ifTrue: [ aClass instanceClass name, '.klass' ]\x0a\x09\x09ifFalse: [\x0a\x09\x09\x09aClass isNil\x0a\x09\x09\x09\x09ifTrue: [ 'nil' ]\x0a\x09\x09\x09\x09ifFalse: [ aClass name ] ]",
  409. messageSends: ["ifTrue:ifFalse:", ",", "name", "instanceClass", "isNil", "isMetaclass"],
  410. referencedClasses: []
  411. }),
  412. smalltalk.Exporter);
  413. smalltalk.addMethod(
  414. smalltalk.method({
  415. selector: "exportDefinitionOf:on:",
  416. category: 'output',
  417. fn: function (aClass,aStream){
  418. var self=this;
  419. return smalltalk.withContext(function($ctx1) {
  420. var $1,$2,$3,$4,$5,$6,$7;
  421. $1=aStream;
  422. _st($1)._lf();
  423. _st($1)._nextPutAll_("smalltalk.addClass(");
  424. _st($1)._nextPutAll_(_st("'".__comma(self._classNameFor_(aClass))).__comma("', "));
  425. _st($1)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aClass)._superclass())));
  426. $2=_st($1)._nextPutAll_(", [");
  427. _st(_st(aClass)._instanceVariableNames())._do_separatedBy_((function(each){
  428. return smalltalk.withContext(function($ctx2) {
  429. return _st(aStream)._nextPutAll_(_st("'".__comma(each)).__comma("'"));
  430. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  431. return smalltalk.withContext(function($ctx2) {
  432. return _st(aStream)._nextPutAll_(", ");
  433. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  434. $3=aStream;
  435. _st($3)._nextPutAll_("], '");
  436. _st($3)._nextPutAll_(_st(_st(aClass)._category()).__comma("'"));
  437. $4=_st($3)._nextPutAll_(");");
  438. $5=_st(_st(aClass)._comment())._notEmpty();
  439. if(smalltalk.assert($5)){
  440. $6=aStream;
  441. _st($6)._lf();
  442. _st($6)._nextPutAll_("smalltalk.");
  443. _st($6)._nextPutAll_(self._classNameFor_(aClass));
  444. _st($6)._nextPutAll_(".comment=");
  445. _st($6)._nextPutAll_(_st(_st(aClass)._comment())._asJavascript());
  446. $7=_st($6)._nextPutAll_(";");
  447. $7;
  448. };
  449. _st(aStream)._lf();
  450. return self}, function($ctx1) {$ctx1.fill(self,"exportDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.Exporter)})},
  451. args: ["aClass", "aStream"],
  452. 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",
  453. messageSends: ["lf", "nextPutAll:", ",", "classNameFor:", "superclass", "do:separatedBy:", "instanceVariableNames", "category", "ifTrue:", "asJavascript", "comment", "notEmpty"],
  454. referencedClasses: []
  455. }),
  456. smalltalk.Exporter);
  457. smalltalk.addMethod(
  458. smalltalk.method({
  459. selector: "exportMetaDefinitionOf:on:",
  460. category: 'output',
  461. fn: function (aClass,aStream){
  462. var self=this;
  463. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  464. return smalltalk.withContext(function($ctx1) {
  465. var $1,$2,$3;
  466. _st(aStream)._lf();
  467. $1=_st(_st(_st(aClass)._class())._instanceVariableNames())._isEmpty();
  468. if(! smalltalk.assert($1)){
  469. $2=aStream;
  470. _st($2)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aClass)._class())));
  471. $3=_st($2)._nextPutAll_(".iVarNames = [");
  472. $3;
  473. _st(_st(_st(aClass)._class())._instanceVariableNames())._do_separatedBy_((function(each){
  474. return smalltalk.withContext(function($ctx2) {
  475. return _st(aStream)._nextPutAll_(_st("'".__comma(each)).__comma("'"));
  476. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),(function(){
  477. return smalltalk.withContext(function($ctx2) {
  478. return _st(aStream)._nextPutAll_(",");
  479. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  480. _st(aStream)._nextPutAll_("];".__comma(_st($String())._lf()));
  481. };
  482. return self}, function($ctx1) {$ctx1.fill(self,"exportMetaDefinitionOf:on:",{aClass:aClass,aStream:aStream},smalltalk.Exporter)})},
  483. args: ["aClass", "aStream"],
  484. 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]",
  485. messageSends: ["lf", "ifFalse:", "nextPutAll:", ",", "classNameFor:", "class", "do:separatedBy:", "instanceVariableNames", "isEmpty"],
  486. referencedClasses: ["String"]
  487. }),
  488. smalltalk.Exporter);
  489. smalltalk.addMethod(
  490. smalltalk.method({
  491. selector: "exportMethod:on:",
  492. category: 'output',
  493. fn: function (aMethod,aStream){
  494. var self=this;
  495. return smalltalk.withContext(function($ctx1) {
  496. var $1,$2,$3,$4;
  497. $1=aStream;
  498. _st($1)._nextPutAll_("smalltalk.addMethod(");
  499. _st($1)._lf();
  500. _st($1)._nextPutAll_("smalltalk.method({");
  501. _st($1)._lf();
  502. _st($1)._nextPutAll_(_st("selector: ".__comma(_st(_st(aMethod)._selector())._asJavascript())).__comma(","));
  503. _st($1)._lf();
  504. _st($1)._nextPutAll_(_st("category: '".__comma(_st(aMethod)._category())).__comma("',"));
  505. _st($1)._lf();
  506. _st($1)._nextPutAll_(_st("fn: ".__comma(_st(_st(aMethod)._fn())._compiledSource())).__comma(","));
  507. _st($1)._lf();
  508. _st($1)._nextPutAll_(_st("args: ".__comma(_st(_st(aMethod)._arguments())._asJavascript())).__comma(","));
  509. _st($1)._lf();
  510. _st($1)._nextPutAll_(_st("source: ".__comma(_st(_st(aMethod)._source())._asJavascript())).__comma(","));
  511. _st($1)._lf();
  512. _st($1)._nextPutAll_(_st("messageSends: ".__comma(_st(_st(aMethod)._messageSends())._asJavascript())).__comma(","));
  513. _st($1)._lf();
  514. $2=_st($1)._nextPutAll_("referencedClasses: ".__comma(_st(_st(aMethod)._referencedClasses())._asJavascript()));
  515. $3=aStream;
  516. _st($3)._lf();
  517. _st($3)._nextPutAll_("}),");
  518. _st($3)._lf();
  519. _st($3)._nextPutAll_("smalltalk.".__comma(self._classNameFor_(_st(aMethod)._methodClass())));
  520. _st($3)._nextPutAll_(");");
  521. _st($3)._lf();
  522. $4=_st($3)._lf();
  523. return self}, function($ctx1) {$ctx1.fill(self,"exportMethod:on:",{aMethod:aMethod,aStream:aStream},smalltalk.Exporter)})},
  524. args: ["aMethod", "aStream"],
  525. 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",
  526. messageSends: ["nextPutAll:", "lf", ",", "asJavascript", "selector", "category", "compiledSource", "fn", "arguments", "source", "messageSends", "referencedClasses", "classNameFor:", "methodClass"],
  527. referencedClasses: []
  528. }),
  529. smalltalk.Exporter);
  530. smalltalk.addMethod(
  531. smalltalk.method({
  532. selector: "exportPackage:on:",
  533. category: 'output',
  534. fn: function (aPackage,aStream){
  535. var self=this;
  536. return smalltalk.withContext(function($ctx1) {
  537. var $1,$2;
  538. $1=self;
  539. _st($1)._exportPackagePrologueOf_on_(aPackage,aStream);
  540. _st($1)._exportPackageDefinitionOf_on_(aPackage,aStream);
  541. $2=_st($1)._exportPackageTransportOf_on_(aPackage,aStream);
  542. _st(_st(aPackage)._sortedClasses())._do_((function(each){
  543. return smalltalk.withContext(function($ctx2) {
  544. self._exportDefinitionOf_on_(each,aStream);
  545. _st(_st(each)._ownMethods())._do_((function(method){
  546. return smalltalk.withContext(function($ctx3) {
  547. return self._exportMethod_on_(method,aStream);
  548. }, function($ctx3) {$ctx3.fillBlock({method:method},$ctx2)})}));
  549. self._exportMetaDefinitionOf_on_(each,aStream);
  550. return _st(_st(_st(each)._class())._ownMethods())._do_((function(method){
  551. return smalltalk.withContext(function($ctx3) {
  552. return self._exportMethod_on_(method,aStream);
  553. }, function($ctx3) {$ctx3.fillBlock({method:method},$ctx2)})}));
  554. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  555. _st(self._extensionMethodsOfPackage_(aPackage))._do_((function(each){
  556. return smalltalk.withContext(function($ctx2) {
  557. return self._exportMethod_on_(each,aStream);
  558. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  559. self._exportPackageEpilogueOf_on_(aPackage,aStream);
  560. return self}, function($ctx1) {$ctx1.fill(self,"exportPackage:on:",{aPackage:aPackage,aStream:aStream},smalltalk.Exporter)})},
  561. args: ["aPackage", "aStream"],
  562. source: "exportPackage: aPackage on: aStream\x0a\x09\x0a\x09self \x0a\x09\x09exportPackagePrologueOf: aPackage on: aStream;\x0a\x09\x09exportPackageDefinitionOf: aPackage on: aStream;\x0a\x09\x09exportPackageTransportOf: aPackage on: aStream.\x0a\x09\x0a\x09aPackage sortedClasses do: [ :each |\x0a\x09\x09self exportDefinitionOf: each on: aStream.\x0a\x09\x09each ownMethods do: [ :method |\x0a\x09\x09\x09self exportMethod: method on: aStream ].\x0a\x09\x09\x09\x0a\x09\x09self exportMetaDefinitionOf: each on: aStream.\x0a\x09\x09each class ownMethods do: [ :method |\x0a\x09\x09\x09self exportMethod: method on: aStream ] ].\x0a\x09\x09\x09\x0a\x09(self extensionMethodsOfPackage: aPackage) do: [ :each |\x0a\x09\x09self exportMethod: each on: aStream ].\x0a\x09\x09\x0a\x09self exportPackageEpilogueOf: aPackage on: aStream",
  563. messageSends: ["exportPackagePrologueOf:on:", "exportPackageDefinitionOf:on:", "exportPackageTransportOf:on:", "do:", "exportDefinitionOf:on:", "exportMethod:on:", "ownMethods", "exportMetaDefinitionOf:on:", "class", "sortedClasses", "extensionMethodsOfPackage:", "exportPackageEpilogueOf:on:"],
  564. referencedClasses: []
  565. }),
  566. smalltalk.Exporter);
  567. smalltalk.addMethod(
  568. smalltalk.method({
  569. selector: "exportPackageDefinitionOf:on:",
  570. category: 'output',
  571. fn: function (aPackage,aStream){
  572. var self=this;
  573. return smalltalk.withContext(function($ctx1) {
  574. var $1,$2;
  575. $1=aStream;
  576. _st($1)._nextPutAll_("smalltalk.addPackage(");
  577. _st($1)._nextPutAll_(_st("'".__comma(_st(aPackage)._name())).__comma("');"));
  578. $2=_st($1)._lf();
  579. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageDefinitionOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.Exporter)})},
  580. args: ["aPackage", "aStream"],
  581. source: "exportPackageDefinitionOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: 'smalltalk.addPackage(';\x0a\x09\x09nextPutAll: '''', aPackage name, ''');';\x0a\x09\x09lf",
  582. messageSends: ["nextPutAll:", ",", "name", "lf"],
  583. referencedClasses: []
  584. }),
  585. smalltalk.Exporter);
  586. smalltalk.addMethod(
  587. smalltalk.method({
  588. selector: "exportPackageEpilogueOf:on:",
  589. category: 'output',
  590. fn: function (aPackage,aStream){
  591. var self=this;
  592. return smalltalk.withContext(function($ctx1) {
  593. var $1,$2;
  594. $1=aStream;
  595. _st($1)._nextPutAll_("})(global_smalltalk,global_nil,global__st);");
  596. $2=_st($1)._lf();
  597. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageEpilogueOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.Exporter)})},
  598. args: ["aPackage", "aStream"],
  599. source: "exportPackageEpilogueOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '})(global_smalltalk,global_nil,global__st);';\x0a\x09\x09lf",
  600. messageSends: ["nextPutAll:", "lf"],
  601. referencedClasses: []
  602. }),
  603. smalltalk.Exporter);
  604. smalltalk.addMethod(
  605. smalltalk.method({
  606. selector: "exportPackagePrologueOf:on:",
  607. category: 'output',
  608. fn: function (aPackage,aStream){
  609. var self=this;
  610. return smalltalk.withContext(function($ctx1) {
  611. var $1,$2;
  612. $1=aStream;
  613. _st($1)._nextPutAll_("(function(smalltalk,nil,_st){");
  614. $2=_st($1)._lf();
  615. return self}, function($ctx1) {$ctx1.fill(self,"exportPackagePrologueOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.Exporter)})},
  616. args: ["aPackage", "aStream"],
  617. source: "exportPackagePrologueOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '(function(smalltalk,nil,_st){';\x0a\x09\x09lf",
  618. messageSends: ["nextPutAll:", "lf"],
  619. referencedClasses: []
  620. }),
  621. smalltalk.Exporter);
  622. smalltalk.addMethod(
  623. smalltalk.method({
  624. selector: "exportPackageTransportOf:on:",
  625. category: 'output',
  626. fn: function (aPackage,aStream){
  627. var self=this;
  628. var json;
  629. return smalltalk.withContext(function($ctx1) {
  630. var $1,$2,$3;
  631. json=_st(aPackage)._transportJson();
  632. $1=_st(json).__eq("null");
  633. if(! smalltalk.assert($1)){
  634. $2=aStream;
  635. _st($2)._nextPutAll_("smalltalk.packages[");
  636. _st($2)._nextPutAll_(_st(_st(aPackage)._name())._asJavascript());
  637. _st($2)._nextPutAll_("].transport = ");
  638. _st($2)._nextPutAll_(json);
  639. _st($2)._nextPutAll_(";");
  640. $3=_st($2)._lf();
  641. $3;
  642. };
  643. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageTransportOf:on:",{aPackage:aPackage,aStream:aStream,json:json},smalltalk.Exporter)})},
  644. args: ["aPackage", "aStream"],
  645. source: "exportPackageTransportOf: aPackage on: aStream\x0a\x09| json |\x0a\x09json := aPackage transportJson.\x0a\x09json = 'null' ifFalse: [\x0a\x09\x09aStream\x0a\x09\x09\x09nextPutAll: 'smalltalk.packages[';\x0a\x09\x09\x09nextPutAll: aPackage name asJavascript;\x0a\x09\x09\x09nextPutAll: '].transport = ';\x0a\x09\x09\x09nextPutAll: json;\x0a\x09\x09\x09nextPutAll: ';';\x0a\x09\x09\x09lf ]",
  646. messageSends: ["transportJson", "ifFalse:", "nextPutAll:", "asJavascript", "name", "lf", "="],
  647. referencedClasses: []
  648. }),
  649. smalltalk.Exporter);
  650. smalltalk.addClass('AmdExporter', smalltalk.Exporter, [], 'Importer-Exporter');
  651. smalltalk.addMethod(
  652. smalltalk.method({
  653. selector: "amdNamesOfPackages:",
  654. category: 'private',
  655. fn: function (anArray){
  656. var self=this;
  657. return smalltalk.withContext(function($ctx1) {
  658. var $1;
  659. $1=_st(_st(anArray)._select_((function(each){
  660. return smalltalk.withContext(function($ctx2) {
  661. return _st(_st(each)._amdNamespace())._notNil();
  662. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})})))._collect_((function(each){
  663. return smalltalk.withContext(function($ctx2) {
  664. return _st(_st(_st(each)._amdNamespace()).__comma("/")).__comma(_st(each)._name());
  665. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  666. return $1;
  667. }, function($ctx1) {$ctx1.fill(self,"amdNamesOfPackages:",{anArray:anArray},smalltalk.AmdExporter)})},
  668. args: ["anArray"],
  669. source: "amdNamesOfPackages: anArray\x0a\x09^ (anArray\x0a\x09\x09select: [ :each | each amdNamespace notNil ])\x0a\x09\x09collect: [ :each | each amdNamespace, '/', each name ]",
  670. messageSends: ["collect:", ",", "name", "amdNamespace", "select:", "notNil"],
  671. referencedClasses: []
  672. }),
  673. smalltalk.AmdExporter);
  674. smalltalk.addMethod(
  675. smalltalk.method({
  676. selector: "exportPackageEpilogueOf:on:",
  677. category: 'output',
  678. fn: function (aPackage,aStream){
  679. var self=this;
  680. return smalltalk.withContext(function($ctx1) {
  681. var $1,$2;
  682. $1=aStream;
  683. _st($1)._nextPutAll_("});");
  684. $2=_st($1)._lf();
  685. return self}, function($ctx1) {$ctx1.fill(self,"exportPackageEpilogueOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.AmdExporter)})},
  686. args: ["aPackage", "aStream"],
  687. source: "exportPackageEpilogueOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: '});';\x0a\x09\x09lf",
  688. messageSends: ["nextPutAll:", "lf"],
  689. referencedClasses: []
  690. }),
  691. smalltalk.AmdExporter);
  692. smalltalk.addMethod(
  693. smalltalk.method({
  694. selector: "exportPackagePrologueOf:on:",
  695. category: 'output',
  696. fn: function (aPackage,aStream){
  697. var self=this;
  698. return smalltalk.withContext(function($ctx1) {
  699. var $1,$2,$4,$3,$5;
  700. $1=aStream;
  701. _st($1)._nextPutAll_("define(\x22");
  702. $2=$1;
  703. $4=_st(aPackage)._amdNamespace();
  704. if(($receiver = $4) == nil || $receiver == undefined){
  705. $3="amber";
  706. } else {
  707. $3=$4;
  708. };
  709. _st($2)._nextPutAll_($3);
  710. _st($1)._nextPutAll_("/");
  711. _st($1)._nextPutAll_(_st(aPackage)._name());
  712. _st($1)._nextPutAll_("\x22, ");
  713. _st($1)._nextPutAll_(_st(["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st"].__comma(self._amdNamesOfPackages_(_st(aPackage)._loadDependencies())))._asJavascript());
  714. _st($1)._nextPutAll_(", function(smalltalk,nil,_st){");
  715. $5=_st($1)._lf();
  716. return self}, function($ctx1) {$ctx1.fill(self,"exportPackagePrologueOf:on:",{aPackage:aPackage,aStream:aStream},smalltalk.AmdExporter)})},
  717. args: ["aPackage", "aStream"],
  718. source: "exportPackagePrologueOf: aPackage on: aStream\x0a\x09aStream\x0a\x09\x09nextPutAll: 'define(\x22';\x0a\x09\x09nextPutAll: (aPackage amdNamespace ifNil: [ 'amber' ]); \x22ifNil: only for LegacyPH, it should not happen with AmdPH\x22\x0a\x09\x09nextPutAll: '/';\x0a\x09\x09nextPutAll: aPackage name;\x0a\x09\x09nextPutAll: '\x22, ';\x0a\x09\x09nextPutAll: (#('amber_vm/smalltalk' 'amber_vm/nil' 'amber_vm/_st'), (self amdNamesOfPackages: aPackage loadDependencies)) asJavascript;\x0a\x09\x09nextPutAll: ', function(smalltalk,nil,_st){';\x0a\x09\x09lf",
  719. messageSends: ["nextPutAll:", "ifNil:", "amdNamespace", "name", "asJavascript", ",", "amdNamesOfPackages:", "loadDependencies", "lf"],
  720. referencedClasses: []
  721. }),
  722. smalltalk.AmdExporter);
  723. smalltalk.addClass('ChunkParser', smalltalk.Object, ['stream'], 'Importer-Exporter');
  724. 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";
  725. smalltalk.addMethod(
  726. smalltalk.method({
  727. selector: "nextChunk",
  728. category: 'reading',
  729. fn: function (){
  730. var self=this;
  731. var char,result,chunk;
  732. return smalltalk.withContext(function($ctx1) {
  733. var $1,$2,$3;
  734. var $early={};
  735. try {
  736. result=""._writeStream();
  737. _st((function(){
  738. return smalltalk.withContext(function($ctx2) {
  739. char=_st(self["@stream"])._next();
  740. char;
  741. return _st(char)._notNil();
  742. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileTrue_((function(){
  743. return smalltalk.withContext(function($ctx2) {
  744. $1=_st(char).__eq("!");
  745. if(smalltalk.assert($1)){
  746. $2=_st(_st(self["@stream"])._peek()).__eq("!");
  747. if(smalltalk.assert($2)){
  748. _st(self["@stream"])._next();
  749. } else {
  750. $3=_st(_st(result)._contents())._trimBoth();
  751. throw $early=[$3];
  752. };
  753. };
  754. return _st(result)._nextPut_(char);
  755. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  756. return nil;
  757. }
  758. catch(e) {if(e===$early)return e[0]; throw e}
  759. }, function($ctx1) {$ctx1.fill(self,"nextChunk",{char:char,result:result,chunk:chunk},smalltalk.ChunkParser)})},
  760. args: [],
  761. 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 method 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",
  762. messageSends: ["writeStream", "whileTrue:", "ifTrue:", "ifTrue:ifFalse:", "next", "trimBoth", "contents", "=", "peek", "nextPut:", "notNil"],
  763. referencedClasses: []
  764. }),
  765. smalltalk.ChunkParser);
  766. smalltalk.addMethod(
  767. smalltalk.method({
  768. selector: "stream:",
  769. category: 'accessing',
  770. fn: function (aStream){
  771. var self=this;
  772. return smalltalk.withContext(function($ctx1) {
  773. self["@stream"]=aStream;
  774. return self}, function($ctx1) {$ctx1.fill(self,"stream:",{aStream:aStream},smalltalk.ChunkParser)})},
  775. args: ["aStream"],
  776. source: "stream: aStream\x0a\x09stream := aStream",
  777. messageSends: [],
  778. referencedClasses: []
  779. }),
  780. smalltalk.ChunkParser);
  781. smalltalk.addMethod(
  782. smalltalk.method({
  783. selector: "on:",
  784. category: 'instance creation',
  785. fn: function (aStream){
  786. var self=this;
  787. return smalltalk.withContext(function($ctx1) {
  788. var $1;
  789. $1=_st(self._new())._stream_(aStream);
  790. return $1;
  791. }, function($ctx1) {$ctx1.fill(self,"on:",{aStream:aStream},smalltalk.ChunkParser.klass)})},
  792. args: ["aStream"],
  793. source: "on: aStream\x0a\x09^self new stream: aStream",
  794. messageSends: ["stream:", "new"],
  795. referencedClasses: []
  796. }),
  797. smalltalk.ChunkParser.klass);
  798. smalltalk.addClass('ExportMethodProtocol', smalltalk.Object, ['name', 'theClass'], 'Importer-Exporter');
  799. smalltalk.ExportMethodProtocol.comment="I am an abstraction for a method protocol in a class / metaclass.\x0a\x0aI know of my class, name and methods.\x0aI am used when exporting a package.";
  800. smalltalk.addMethod(
  801. smalltalk.method({
  802. selector: "methods",
  803. category: 'accessing',
  804. fn: function (){
  805. var self=this;
  806. return smalltalk.withContext(function($ctx1) {
  807. var $1;
  808. $1=_st(self._theClass())._methodsInProtocol_(self._name());
  809. return $1;
  810. }, function($ctx1) {$ctx1.fill(self,"methods",{},smalltalk.ExportMethodProtocol)})},
  811. args: [],
  812. source: "methods\x0a\x09^ self theClass methodsInProtocol: self name",
  813. messageSends: ["methodsInProtocol:", "name", "theClass"],
  814. referencedClasses: []
  815. }),
  816. smalltalk.ExportMethodProtocol);
  817. smalltalk.addMethod(
  818. smalltalk.method({
  819. selector: "name",
  820. category: 'accessing',
  821. fn: function (){
  822. var self=this;
  823. return smalltalk.withContext(function($ctx1) {
  824. var $1;
  825. $1=self["@name"];
  826. return $1;
  827. }, function($ctx1) {$ctx1.fill(self,"name",{},smalltalk.ExportMethodProtocol)})},
  828. args: [],
  829. source: "name\x0a\x09^name",
  830. messageSends: [],
  831. referencedClasses: []
  832. }),
  833. smalltalk.ExportMethodProtocol);
  834. smalltalk.addMethod(
  835. smalltalk.method({
  836. selector: "name:",
  837. category: 'accessing',
  838. fn: function (aString){
  839. var self=this;
  840. return smalltalk.withContext(function($ctx1) {
  841. self["@name"]=aString;
  842. return self}, function($ctx1) {$ctx1.fill(self,"name:",{aString:aString},smalltalk.ExportMethodProtocol)})},
  843. args: ["aString"],
  844. source: "name: aString\x0a\x09name := aString",
  845. messageSends: [],
  846. referencedClasses: []
  847. }),
  848. smalltalk.ExportMethodProtocol);
  849. smalltalk.addMethod(
  850. smalltalk.method({
  851. selector: "sortedMethods",
  852. category: 'accessing',
  853. fn: function (){
  854. var self=this;
  855. return smalltalk.withContext(function($ctx1) {
  856. var $1;
  857. $1=_st(self._methods())._sorted_((function(a,b){
  858. return smalltalk.withContext(function($ctx2) {
  859. return _st(_st(a)._selector()).__lt_eq(_st(b)._selector());
  860. }, function($ctx2) {$ctx2.fillBlock({a:a,b:b},$ctx1)})}));
  861. return $1;
  862. }, function($ctx1) {$ctx1.fill(self,"sortedMethods",{},smalltalk.ExportMethodProtocol)})},
  863. args: [],
  864. source: "sortedMethods\x0a\x09^ self methods sorted: [ :a :b | a selector <= b selector ]",
  865. messageSends: ["sorted:", "<=", "selector", "methods"],
  866. referencedClasses: []
  867. }),
  868. smalltalk.ExportMethodProtocol);
  869. smalltalk.addMethod(
  870. smalltalk.method({
  871. selector: "theClass",
  872. category: 'accessing',
  873. fn: function (){
  874. var self=this;
  875. return smalltalk.withContext(function($ctx1) {
  876. var $1;
  877. $1=self["@theClass"];
  878. return $1;
  879. }, function($ctx1) {$ctx1.fill(self,"theClass",{},smalltalk.ExportMethodProtocol)})},
  880. args: [],
  881. source: "theClass\x0a\x09^theClass",
  882. messageSends: [],
  883. referencedClasses: []
  884. }),
  885. smalltalk.ExportMethodProtocol);
  886. smalltalk.addMethod(
  887. smalltalk.method({
  888. selector: "theClass:",
  889. category: 'accessing',
  890. fn: function (aClass){
  891. var self=this;
  892. return smalltalk.withContext(function($ctx1) {
  893. self["@theClass"]=aClass;
  894. return self}, function($ctx1) {$ctx1.fill(self,"theClass:",{aClass:aClass},smalltalk.ExportMethodProtocol)})},
  895. args: ["aClass"],
  896. source: "theClass: aClass\x0a\x09theClass := aClass",
  897. messageSends: [],
  898. referencedClasses: []
  899. }),
  900. smalltalk.ExportMethodProtocol);
  901. smalltalk.addMethod(
  902. smalltalk.method({
  903. selector: "name:theClass:",
  904. category: 'instance creation',
  905. fn: function (aString,aClass){
  906. var self=this;
  907. return smalltalk.withContext(function($ctx1) {
  908. var $2,$3,$1;
  909. $2=self._new();
  910. _st($2)._name_(aString);
  911. _st($2)._theClass_(aClass);
  912. $3=_st($2)._yourself();
  913. $1=$3;
  914. return $1;
  915. }, function($ctx1) {$ctx1.fill(self,"name:theClass:",{aString:aString,aClass:aClass},smalltalk.ExportMethodProtocol.klass)})},
  916. args: ["aString", "aClass"],
  917. source: "name: aString theClass: aClass\x0a\x09^self new\x0a\x09\x09name: aString;\x0a\x09\x09theClass: aClass;\x0a\x09\x09yourself",
  918. messageSends: ["name:", "new", "theClass:", "yourself"],
  919. referencedClasses: []
  920. }),
  921. smalltalk.ExportMethodProtocol.klass);
  922. smalltalk.addClass('ExportRecipeInterpreter', smalltalk.Object, [], 'Importer-Exporter');
  923. smalltalk.ExportRecipeInterpreter.comment="I am an interpreter for export recipes.\x0a\x0a## Recipe format\x0a\x0aRecipe is an array, which can contain two kinds of elements:\x0a\x0a - an assocation where the key is the receiver and the value is a two-arguments selector\x0a In this case, `receiver perform: selector withArguments: { data. stream }` is called.\x0a\x09This essentially defines one step of export process.\x0a\x09The key (eg. receiver) is presumed to be some kind of 'repository' of the exporting methods\x0a\x09that just format appropriate aspect of data into a stream; like a class or a singleton,\x0a\x09so that the recipe itself can be decoupled from data.\x0a\x0a - a subarray, where first element is special and the rest is recursive recipe.\x0a\x0a `subarray first` must be an association similar to one above,\x0a\x09with key being the 'repository' receiver, but value is one-arg selector.\x0a\x09In this case, `receiver perform: selector withArguments: { data }` should create a collection.\x0a\x09Then, the sub-recipe (`subarray allButFirst`) is applied to every element of a collection, eg.\x0a\x09 collection do: [ :each | self export: each using: sa allButFirst on: stream ]";
  924. smalltalk.addMethod(
  925. smalltalk.method({
  926. selector: "interpret:for:on:",
  927. category: 'interpreting',
  928. fn: function (aRecipe,anObject,aStream){
  929. var self=this;
  930. var recipeStream;
  931. return smalltalk.withContext(function($ctx1) {
  932. recipeStream=_st(aRecipe)._readStream();
  933. _st((function(){
  934. return smalltalk.withContext(function($ctx2) {
  935. return _st(recipeStream)._atEnd();
  936. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileFalse_((function(){
  937. return smalltalk.withContext(function($ctx2) {
  938. return self._interpretStep_for_on_(_st(recipeStream)._next(),anObject,aStream);
  939. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  940. return self}, function($ctx1) {$ctx1.fill(self,"interpret:for:on:",{aRecipe:aRecipe,anObject:anObject,aStream:aStream,recipeStream:recipeStream},smalltalk.ExportRecipeInterpreter)})},
  941. args: ["aRecipe", "anObject", "aStream"],
  942. source: "interpret: aRecipe for: anObject on: aStream\x0a\x09| recipeStream |\x0a\x09\x0a\x09recipeStream := aRecipe readStream.\x0a\x09\x0a\x09[ recipeStream atEnd ] whileFalse: [\x0a\x09\x09self \x0a\x09\x09\x09interpretStep: recipeStream next\x0a\x09\x09\x09for: anObject\x0a\x09\x09\x09on: aStream ]",
  943. messageSends: ["readStream", "whileFalse:", "interpretStep:for:on:", "next", "atEnd"],
  944. referencedClasses: []
  945. }),
  946. smalltalk.ExportRecipeInterpreter);
  947. smalltalk.addMethod(
  948. smalltalk.method({
  949. selector: "interpretStep:for:on:",
  950. category: 'interpreting',
  951. fn: function (aRecipeStep,anObject,aStream){
  952. var self=this;
  953. return smalltalk.withContext(function($ctx1) {
  954. var $1,$2;
  955. $1=_st(_st(aRecipeStep)._value()).__eq_eq(aRecipeStep);
  956. if(smalltalk.assert($1)){
  957. $2=self._interpretSubRecipe_for_on_(aRecipeStep,anObject,aStream);
  958. return $2;
  959. };
  960. _st(_st(aRecipeStep)._key())._perform_withArguments_(_st(aRecipeStep)._value(),[anObject,aStream]);
  961. return self}, function($ctx1) {$ctx1.fill(self,"interpretStep:for:on:",{aRecipeStep:aRecipeStep,anObject:anObject,aStream:aStream},smalltalk.ExportRecipeInterpreter)})},
  962. args: ["aRecipeStep", "anObject", "aStream"],
  963. source: "interpretStep: aRecipeStep for: anObject on: aStream\x0a\x09aRecipeStep value == aRecipeStep ifTrue: [ \x0a\x09\x09^ self interpretSubRecipe: aRecipeStep for: anObject on: aStream ].\x0a\x09\x09\x09\x0a\x09aRecipeStep key perform: aRecipeStep value withArguments: { anObject. aStream }",
  964. messageSends: ["ifTrue:", "interpretSubRecipe:for:on:", "==", "value", "perform:withArguments:", "key"],
  965. referencedClasses: []
  966. }),
  967. smalltalk.ExportRecipeInterpreter);
  968. smalltalk.addMethod(
  969. smalltalk.method({
  970. selector: "interpretSubRecipe:for:on:",
  971. category: 'interpreting',
  972. fn: function (aRecipe,anObject,aStream){
  973. var self=this;
  974. var selection;
  975. return smalltalk.withContext(function($ctx1) {
  976. selection=_st(_st(_st(aRecipe)._first())._key())._perform_withArguments_(_st(_st(aRecipe)._first())._value(),[anObject]);
  977. _st(selection)._do_((function(each){
  978. return smalltalk.withContext(function($ctx2) {
  979. return self._interpret_for_on_(_st(aRecipe)._allButFirst(),each,aStream);
  980. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  981. return self}, function($ctx1) {$ctx1.fill(self,"interpretSubRecipe:for:on:",{aRecipe:aRecipe,anObject:anObject,aStream:aStream,selection:selection},smalltalk.ExportRecipeInterpreter)})},
  982. args: ["aRecipe", "anObject", "aStream"],
  983. source: "interpretSubRecipe: aRecipe for: anObject on: aStream\x0a\x09| selection |\x0a\x09selection := aRecipe first key \x0a\x09\x09perform: aRecipe first value \x0a\x09\x09withArguments: { anObject }.\x0a\x09selection do: [ :each |\x09\x0a\x09\x09self interpret: aRecipe allButFirst for: each on: aStream ]",
  984. messageSends: ["perform:withArguments:", "value", "first", "key", "do:", "interpret:for:on:", "allButFirst"],
  985. referencedClasses: []
  986. }),
  987. smalltalk.ExportRecipeInterpreter);
  988. smalltalk.addClass('Importer', smalltalk.Object, [], 'Importer-Exporter');
  989. smalltalk.Importer.comment="I can import Amber code from a string in the chunk format.\x0a\x0a## API\x0a\x0a Importer new import: aString";
  990. smalltalk.addMethod(
  991. smalltalk.method({
  992. selector: "import:",
  993. category: 'fileIn',
  994. fn: function (aStream){
  995. var self=this;
  996. var chunk,result,parser,lastEmpty;
  997. function $ChunkParser(){return smalltalk.ChunkParser||(typeof ChunkParser=="undefined"?nil:ChunkParser)}
  998. function $Compiler(){return smalltalk.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  999. return smalltalk.withContext(function($ctx1) {
  1000. var $1,$2;
  1001. parser=_st($ChunkParser())._on_(aStream);
  1002. lastEmpty=false;
  1003. _st((function(){
  1004. return smalltalk.withContext(function($ctx2) {
  1005. chunk=_st(parser)._nextChunk();
  1006. chunk;
  1007. return _st(chunk)._isNil();
  1008. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}))._whileFalse_((function(){
  1009. return smalltalk.withContext(function($ctx2) {
  1010. $1=_st(chunk)._isEmpty();
  1011. if(smalltalk.assert($1)){
  1012. lastEmpty=true;
  1013. return lastEmpty;
  1014. } else {
  1015. result=_st(_st($Compiler())._new())._evaluateExpression_(chunk);
  1016. result;
  1017. $2=lastEmpty;
  1018. if(smalltalk.assert($2)){
  1019. lastEmpty=false;
  1020. lastEmpty;
  1021. return _st(result)._scanFrom_(parser);
  1022. };
  1023. };
  1024. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  1025. return self}, function($ctx1) {$ctx1.fill(self,"import:",{aStream:aStream,chunk:chunk,result:result,parser:parser,lastEmpty:lastEmpty},smalltalk.Importer)})},
  1026. args: ["aStream"],
  1027. 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]]]",
  1028. messageSends: ["on:", "whileFalse:", "ifTrue:ifFalse:", "evaluateExpression:", "new", "ifTrue:", "scanFrom:", "isEmpty", "nextChunk", "isNil"],
  1029. referencedClasses: ["ChunkParser", "Compiler"]
  1030. }),
  1031. smalltalk.Importer);
  1032. smalltalk.addClass('PackageHandler', smalltalk.InterfacingObject, [], 'Importer-Exporter');
  1033. 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.";
  1034. smalltalk.addMethod(
  1035. smalltalk.method({
  1036. selector: "ajaxPutAt:data:",
  1037. category: 'private',
  1038. fn: function (aURL,aString){
  1039. var self=this;
  1040. return smalltalk.withContext(function($ctx1) {
  1041. self._ajax_(smalltalk.HashedCollection._from_(["url".__minus_gt(aURL),"type".__minus_gt("PUT"),"data".__minus_gt(aString),"contentType".__minus_gt("text/plain;charset=UTF-8"),"error".__minus_gt((function(xhr){
  1042. return smalltalk.withContext(function($ctx2) {
  1043. return self._error_(_st(_st(_st("Commiting ".__comma(aURL)).__comma(" failed with reason: \x22")).__comma(_st(xhr)._responseText())).__comma("\x22"));
  1044. }, function($ctx2) {$ctx2.fillBlock({xhr:xhr},$ctx1)})}))]));
  1045. return self}, function($ctx1) {$ctx1.fill(self,"ajaxPutAt:data:",{aURL:aURL,aString:aString},smalltalk.PackageHandler)})},
  1046. args: ["aURL", "aString"],
  1047. source: "ajaxPutAt: aURL data: aString\x0a\x09self\x0a\x09\x09ajax: #{\x0a\x09\x09\x09'url' -> aURL.\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'] }",
  1048. messageSends: ["ajax:", "->", "error:", ",", "responseText"],
  1049. referencedClasses: []
  1050. }),
  1051. smalltalk.PackageHandler);
  1052. smalltalk.addMethod(
  1053. smalltalk.method({
  1054. selector: "chunkContentsFor:",
  1055. category: 'accessing',
  1056. fn: function (aPackage){
  1057. var self=this;
  1058. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  1059. return smalltalk.withContext(function($ctx1) {
  1060. var $1;
  1061. $1=_st($String())._streamContents_((function(str){
  1062. return smalltalk.withContext(function($ctx2) {
  1063. return _st(self._chunkExporter())._exportPackage_on_(aPackage,str);
  1064. }, function($ctx2) {$ctx2.fillBlock({str:str},$ctx1)})}));
  1065. return $1;
  1066. }, function($ctx1) {$ctx1.fill(self,"chunkContentsFor:",{aPackage:aPackage},smalltalk.PackageHandler)})},
  1067. args: ["aPackage"],
  1068. source: "chunkContentsFor: aPackage\x0a\x09^ String streamContents: [ :str |\x0a\x09\x09self chunkExporter exportPackage: aPackage on: str ]",
  1069. messageSends: ["streamContents:", "exportPackage:on:", "chunkExporter"],
  1070. referencedClasses: ["String"]
  1071. }),
  1072. smalltalk.PackageHandler);
  1073. smalltalk.addMethod(
  1074. smalltalk.method({
  1075. selector: "chunkExporter",
  1076. category: 'factory',
  1077. fn: function (){
  1078. var self=this;
  1079. return smalltalk.withContext(function($ctx1) {
  1080. var $1;
  1081. $1=_st(self._chunkExporterClass())._default();
  1082. return $1;
  1083. }, function($ctx1) {$ctx1.fill(self,"chunkExporter",{},smalltalk.PackageHandler)})},
  1084. args: [],
  1085. source: "chunkExporter\x0a\x09^ self chunkExporterClass default",
  1086. messageSends: ["default", "chunkExporterClass"],
  1087. referencedClasses: []
  1088. }),
  1089. smalltalk.PackageHandler);
  1090. smalltalk.addMethod(
  1091. smalltalk.method({
  1092. selector: "chunkExporterClass",
  1093. category: 'accessing',
  1094. fn: function (){
  1095. var self=this;
  1096. function $ChunkExporter(){return smalltalk.ChunkExporter||(typeof ChunkExporter=="undefined"?nil:ChunkExporter)}
  1097. return smalltalk.withContext(function($ctx1) {
  1098. var $1;
  1099. $1=$ChunkExporter();
  1100. return $1;
  1101. }, function($ctx1) {$ctx1.fill(self,"chunkExporterClass",{},smalltalk.PackageHandler)})},
  1102. args: [],
  1103. source: "chunkExporterClass\x0a\x09^ ChunkExporter",
  1104. messageSends: [],
  1105. referencedClasses: ["ChunkExporter"]
  1106. }),
  1107. smalltalk.PackageHandler);
  1108. smalltalk.addMethod(
  1109. smalltalk.method({
  1110. selector: "commit:",
  1111. category: 'committing',
  1112. fn: function (aPackage){
  1113. var self=this;
  1114. return smalltalk.withContext(function($ctx1) {
  1115. _st([(function(){
  1116. return smalltalk.withContext(function($ctx2) {
  1117. return self._commitStFileFor_(aPackage);
  1118. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}),(function(){
  1119. return smalltalk.withContext(function($ctx2) {
  1120. return self._commitJsFileFor_(aPackage);
  1121. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})})])._do_displayingProgress_((function(each){
  1122. return smalltalk.withContext(function($ctx2) {
  1123. return _st(each)._value();
  1124. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}),"Committing package ".__comma(_st(aPackage)._name()));
  1125. return self}, function($ctx1) {$ctx1.fill(self,"commit:",{aPackage:aPackage},smalltalk.PackageHandler)})},
  1126. args: ["aPackage"],
  1127. source: "commit: aPackage\x0a\x09{\x0a\x09\x09[ self commitStFileFor: aPackage ].\x0a\x09\x09[ self commitJsFileFor: aPackage ]\x0a\x09}\x0a\x09\x09do: [ :each | each value ]\x0a\x09\x09displayingProgress: 'Committing package ', aPackage name",
  1128. messageSends: ["do:displayingProgress:", "value", ",", "name", "commitStFileFor:", "commitJsFileFor:"],
  1129. referencedClasses: []
  1130. }),
  1131. smalltalk.PackageHandler);
  1132. smalltalk.addMethod(
  1133. smalltalk.method({
  1134. selector: "commitJsFileFor:",
  1135. category: 'committing',
  1136. fn: function (aPackage){
  1137. var self=this;
  1138. return smalltalk.withContext(function($ctx1) {
  1139. self._ajaxPutAt_data_(_st(_st(_st(self._commitPathJsFor_(aPackage)).__comma("/")).__comma(_st(aPackage)._name())).__comma(".js"),self._contentsFor_(aPackage));
  1140. return self}, function($ctx1) {$ctx1.fill(self,"commitJsFileFor:",{aPackage:aPackage},smalltalk.PackageHandler)})},
  1141. args: ["aPackage"],
  1142. source: "commitJsFileFor: aPackage\x0a\x09self \x0a\x09\x09ajaxPutAt: (self commitPathJsFor: aPackage), '/', aPackage name, '.js'\x0a\x09\x09data: (self contentsFor: aPackage)",
  1143. messageSends: ["ajaxPutAt:data:", ",", "name", "commitPathJsFor:", "contentsFor:"],
  1144. referencedClasses: []
  1145. }),
  1146. smalltalk.PackageHandler);
  1147. smalltalk.addMethod(
  1148. smalltalk.method({
  1149. selector: "commitPathJsFor:",
  1150. category: 'accessing',
  1151. fn: function (aPackage){
  1152. var self=this;
  1153. return smalltalk.withContext(function($ctx1) {
  1154. self._subclassResponsibility();
  1155. return self}, function($ctx1) {$ctx1.fill(self,"commitPathJsFor:",{aPackage:aPackage},smalltalk.PackageHandler)})},
  1156. args: ["aPackage"],
  1157. source: "commitPathJsFor: aPackage\x0a\x09self subclassResponsibility",
  1158. messageSends: ["subclassResponsibility"],
  1159. referencedClasses: []
  1160. }),
  1161. smalltalk.PackageHandler);
  1162. smalltalk.addMethod(
  1163. smalltalk.method({
  1164. selector: "commitPathStFor:",
  1165. category: 'accessing',
  1166. fn: function (aPackage){
  1167. var self=this;
  1168. return smalltalk.withContext(function($ctx1) {
  1169. self._subclassResponsibility();
  1170. return self}, function($ctx1) {$ctx1.fill(self,"commitPathStFor:",{aPackage:aPackage},smalltalk.PackageHandler)})},
  1171. args: ["aPackage"],
  1172. source: "commitPathStFor: aPackage\x0a\x09self subclassResponsibility",
  1173. messageSends: ["subclassResponsibility"],
  1174. referencedClasses: []
  1175. }),
  1176. smalltalk.PackageHandler);
  1177. smalltalk.addMethod(
  1178. smalltalk.method({
  1179. selector: "commitStFileFor:",
  1180. category: 'committing',
  1181. fn: function (aPackage){
  1182. var self=this;
  1183. return smalltalk.withContext(function($ctx1) {
  1184. self._ajaxPutAt_data_(_st(_st(_st(self._commitPathStFor_(aPackage)).__comma("/")).__comma(_st(aPackage)._name())).__comma(".st"),self._chunkContentsFor_(aPackage));
  1185. return self}, function($ctx1) {$ctx1.fill(self,"commitStFileFor:",{aPackage:aPackage},smalltalk.PackageHandler)})},
  1186. args: ["aPackage"],
  1187. source: "commitStFileFor: aPackage\x0a\x09self \x0a\x09\x09ajaxPutAt: (self commitPathStFor: aPackage), '/', aPackage name, '.st'\x0a\x09\x09data: (self chunkContentsFor: aPackage)",
  1188. messageSends: ["ajaxPutAt:data:", ",", "name", "commitPathStFor:", "chunkContentsFor:"],
  1189. referencedClasses: []
  1190. }),
  1191. smalltalk.PackageHandler);
  1192. smalltalk.addMethod(
  1193. smalltalk.method({
  1194. selector: "contentsFor:",
  1195. category: 'accessing',
  1196. fn: function (aPackage){
  1197. var self=this;
  1198. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  1199. return smalltalk.withContext(function($ctx1) {
  1200. var $1;
  1201. $1=_st($String())._streamContents_((function(str){
  1202. return smalltalk.withContext(function($ctx2) {
  1203. return _st(self._exporter())._exportPackage_on_(aPackage,str);
  1204. }, function($ctx2) {$ctx2.fillBlock({str:str},$ctx1)})}));
  1205. return $1;
  1206. }, function($ctx1) {$ctx1.fill(self,"contentsFor:",{aPackage:aPackage},smalltalk.PackageHandler)})},
  1207. args: ["aPackage"],
  1208. source: "contentsFor: aPackage\x0a\x09^ String streamContents: [ :str |\x0a\x09\x09self exporter exportPackage: aPackage on: str ]",
  1209. messageSends: ["streamContents:", "exportPackage:on:", "exporter"],
  1210. referencedClasses: ["String"]
  1211. }),
  1212. smalltalk.PackageHandler);
  1213. smalltalk.addMethod(
  1214. smalltalk.method({
  1215. selector: "exporter",
  1216. category: 'factory',
  1217. fn: function (){
  1218. var self=this;
  1219. return smalltalk.withContext(function($ctx1) {
  1220. var $1;
  1221. $1=_st(self._exporterClass())._default();
  1222. return $1;
  1223. }, function($ctx1) {$ctx1.fill(self,"exporter",{},smalltalk.PackageHandler)})},
  1224. args: [],
  1225. source: "exporter\x0a\x09^ self exporterClass default",
  1226. messageSends: ["default", "exporterClass"],
  1227. referencedClasses: []
  1228. }),
  1229. smalltalk.PackageHandler);
  1230. smalltalk.addMethod(
  1231. smalltalk.method({
  1232. selector: "exporterClass",
  1233. category: 'accessing',
  1234. fn: function (){
  1235. var self=this;
  1236. function $Exporter(){return smalltalk.Exporter||(typeof Exporter=="undefined"?nil:Exporter)}
  1237. return smalltalk.withContext(function($ctx1) {
  1238. var $1;
  1239. $1=$Exporter();
  1240. return $1;
  1241. }, function($ctx1) {$ctx1.fill(self,"exporterClass",{},smalltalk.PackageHandler)})},
  1242. args: [],
  1243. source: "exporterClass\x0a\x09^ Exporter",
  1244. messageSends: [],
  1245. referencedClasses: ["Exporter"]
  1246. }),
  1247. smalltalk.PackageHandler);
  1248. smalltalk.PackageHandler.klass.iVarNames = ['registry'];
  1249. smalltalk.addMethod(
  1250. smalltalk.method({
  1251. selector: "classRegisteredFor:",
  1252. category: 'accessing',
  1253. fn: function (aString){
  1254. var self=this;
  1255. return smalltalk.withContext(function($ctx1) {
  1256. var $1;
  1257. $1=_st(self["@registry"])._at_(aString);
  1258. return $1;
  1259. }, function($ctx1) {$ctx1.fill(self,"classRegisteredFor:",{aString:aString},smalltalk.PackageHandler.klass)})},
  1260. args: ["aString"],
  1261. source: "classRegisteredFor: aString\x0a\x09^ registry at: aString",
  1262. messageSends: ["at:"],
  1263. referencedClasses: []
  1264. }),
  1265. smalltalk.PackageHandler.klass);
  1266. smalltalk.addMethod(
  1267. smalltalk.method({
  1268. selector: "for:",
  1269. category: 'accessing',
  1270. fn: function (aString){
  1271. var self=this;
  1272. return smalltalk.withContext(function($ctx1) {
  1273. var $1;
  1274. $1=_st(self._classRegisteredFor_(aString))._new();
  1275. return $1;
  1276. }, function($ctx1) {$ctx1.fill(self,"for:",{aString:aString},smalltalk.PackageHandler.klass)})},
  1277. args: ["aString"],
  1278. source: "for: aString\x0a\x09^ (self classRegisteredFor: aString) new",
  1279. messageSends: ["new", "classRegisteredFor:"],
  1280. referencedClasses: []
  1281. }),
  1282. smalltalk.PackageHandler.klass);
  1283. smalltalk.addMethod(
  1284. smalltalk.method({
  1285. selector: "initialize",
  1286. category: 'initialization',
  1287. fn: function (){
  1288. var self=this;
  1289. return smalltalk.withContext(function($ctx1) {
  1290. smalltalk.PackageHandler.klass.superclass.fn.prototype._initialize.apply(_st(self), []);
  1291. self["@registry"]=smalltalk.HashedCollection._from_([]);
  1292. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.PackageHandler.klass)})},
  1293. args: [],
  1294. source: "initialize\x0a\x09super initialize.\x0a\x09registry := #{}",
  1295. messageSends: ["initialize"],
  1296. referencedClasses: []
  1297. }),
  1298. smalltalk.PackageHandler.klass);
  1299. smalltalk.addMethod(
  1300. smalltalk.method({
  1301. selector: "register:for:",
  1302. category: 'registry',
  1303. fn: function (aClass,aString){
  1304. var self=this;
  1305. return smalltalk.withContext(function($ctx1) {
  1306. _st(self["@registry"])._at_put_(aString,aClass);
  1307. return self}, function($ctx1) {$ctx1.fill(self,"register:for:",{aClass:aClass,aString:aString},smalltalk.PackageHandler.klass)})},
  1308. args: ["aClass", "aString"],
  1309. source: "register: aClass for: aString\x0a\x09registry at: aString put: aClass",
  1310. messageSends: ["at:put:"],
  1311. referencedClasses: []
  1312. }),
  1313. smalltalk.PackageHandler.klass);
  1314. smalltalk.addMethod(
  1315. smalltalk.method({
  1316. selector: "registerFor:",
  1317. category: 'registry',
  1318. fn: function (aString){
  1319. var self=this;
  1320. function $PackageHandler(){return smalltalk.PackageHandler||(typeof PackageHandler=="undefined"?nil:PackageHandler)}
  1321. return smalltalk.withContext(function($ctx1) {
  1322. _st($PackageHandler())._register_for_(self,aString);
  1323. return self}, function($ctx1) {$ctx1.fill(self,"registerFor:",{aString:aString},smalltalk.PackageHandler.klass)})},
  1324. args: ["aString"],
  1325. source: "registerFor: aString\x0a\x09PackageHandler register: self for: aString",
  1326. messageSends: ["register:for:"],
  1327. referencedClasses: ["PackageHandler"]
  1328. }),
  1329. smalltalk.PackageHandler.klass);
  1330. smalltalk.addClass('AmdPackageHandler', smalltalk.PackageHandler, [], 'Importer-Exporter');
  1331. smalltalk.AmdPackageHandler.comment="I am responsible for handling package loading and committing.\x0a\x0aI should not be used directly. Instead, use the corresponding `Package` methods.";
  1332. smalltalk.addMethod(
  1333. smalltalk.method({
  1334. selector: "commitPathJsFor:",
  1335. category: 'accessing',
  1336. fn: function (aPackage){
  1337. var self=this;
  1338. return smalltalk.withContext(function($ctx1) {
  1339. var $1;
  1340. $1=self._toUrl_(self._namespaceFor_(aPackage));
  1341. return $1;
  1342. }, function($ctx1) {$ctx1.fill(self,"commitPathJsFor:",{aPackage:aPackage},smalltalk.AmdPackageHandler)})},
  1343. args: ["aPackage"],
  1344. source: "commitPathJsFor: aPackage\x0a\x09^self toUrl: (self namespaceFor: aPackage)",
  1345. messageSends: ["toUrl:", "namespaceFor:"],
  1346. referencedClasses: []
  1347. }),
  1348. smalltalk.AmdPackageHandler);
  1349. smalltalk.addMethod(
  1350. smalltalk.method({
  1351. selector: "commitPathStFor:",
  1352. category: 'accessing',
  1353. fn: function (aPackage){
  1354. var self=this;
  1355. return smalltalk.withContext(function($ctx1) {
  1356. var $1;
  1357. $1=self._toUrl_(_st(self._namespaceFor_(aPackage)).__comma("/_source"));
  1358. return $1;
  1359. }, function($ctx1) {$ctx1.fill(self,"commitPathStFor:",{aPackage:aPackage},smalltalk.AmdPackageHandler)})},
  1360. args: ["aPackage"],
  1361. source: "commitPathStFor: aPackage\x0a\x09\x22if _source is not mapped, .st commit will likely fail\x22\x0a\x09^self toUrl: (self namespaceFor: aPackage), '/_source'.",
  1362. messageSends: ["toUrl:", ",", "namespaceFor:"],
  1363. referencedClasses: []
  1364. }),
  1365. smalltalk.AmdPackageHandler);
  1366. smalltalk.addMethod(
  1367. smalltalk.method({
  1368. selector: "exporterClass",
  1369. category: 'accessing',
  1370. fn: function (){
  1371. var self=this;
  1372. function $AmdExporter(){return smalltalk.AmdExporter||(typeof AmdExporter=="undefined"?nil:AmdExporter)}
  1373. return smalltalk.withContext(function($ctx1) {
  1374. var $1;
  1375. $1=$AmdExporter();
  1376. return $1;
  1377. }, function($ctx1) {$ctx1.fill(self,"exporterClass",{},smalltalk.AmdPackageHandler)})},
  1378. args: [],
  1379. source: "exporterClass\x0a\x09^ AmdExporter",
  1380. messageSends: [],
  1381. referencedClasses: ["AmdExporter"]
  1382. }),
  1383. smalltalk.AmdPackageHandler);
  1384. smalltalk.addMethod(
  1385. smalltalk.method({
  1386. selector: "namespaceFor:",
  1387. category: 'committing',
  1388. fn: function (aPackage){
  1389. var self=this;
  1390. return smalltalk.withContext(function($ctx1) {
  1391. var $2,$3,$4,$1;
  1392. $2=_st(aPackage)._amdNamespace();
  1393. if(($receiver = $2) == nil || $receiver == undefined){
  1394. $3=aPackage;
  1395. _st($3)._amdNamespace_(_st(self._class())._defaultNamespace());
  1396. $4=_st($3)._amdNamespace();
  1397. $1=$4;
  1398. } else {
  1399. $1=$2;
  1400. };
  1401. return $1;
  1402. }, function($ctx1) {$ctx1.fill(self,"namespaceFor:",{aPackage:aPackage},smalltalk.AmdPackageHandler)})},
  1403. args: ["aPackage"],
  1404. source: "namespaceFor: aPackage\x0a\x09^ aPackage amdNamespace\x0a\x09\x09ifNil: [ aPackage amdNamespace: self class defaultNamespace; amdNamespace ]",
  1405. messageSends: ["ifNil:", "amdNamespace:", "defaultNamespace", "class", "amdNamespace"],
  1406. referencedClasses: []
  1407. }),
  1408. smalltalk.AmdPackageHandler);
  1409. smalltalk.addMethod(
  1410. smalltalk.method({
  1411. selector: "toUrl:",
  1412. category: 'private',
  1413. fn: function (aString){
  1414. var self=this;
  1415. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1416. return smalltalk.withContext(function($ctx1) {
  1417. var $2,$1;
  1418. $2=_st(_st($Smalltalk())._current())._amdRequire();
  1419. if(($receiver = $2) == nil || $receiver == undefined){
  1420. $1=self._error_("AMD loader not present");
  1421. } else {
  1422. var require;
  1423. require=$receiver;
  1424. $1=_st(_st(require)._basicAt_("toUrl"))._value_(aString);
  1425. };
  1426. return $1;
  1427. }, function($ctx1) {$ctx1.fill(self,"toUrl:",{aString:aString},smalltalk.AmdPackageHandler)})},
  1428. args: ["aString"],
  1429. source: "toUrl: aString\x0a\x09^ Smalltalk current amdRequire\x0a\x09\x09ifNil: [ self error: 'AMD loader not present' ]\x0a\x09\x09ifNotNil: [ :require | (require basicAt: 'toUrl') value: aString ]",
  1430. messageSends: ["ifNil:ifNotNil:", "error:", "value:", "basicAt:", "amdRequire", "current"],
  1431. referencedClasses: ["Smalltalk"]
  1432. }),
  1433. smalltalk.AmdPackageHandler);
  1434. smalltalk.addMethod(
  1435. smalltalk.method({
  1436. selector: "defaultNamespace",
  1437. category: 'commit paths',
  1438. fn: function (){
  1439. var self=this;
  1440. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1441. return smalltalk.withContext(function($ctx1) {
  1442. var $1;
  1443. $1=_st(_st($Smalltalk())._current())._defaultAMDNamespace();
  1444. return $1;
  1445. }, function($ctx1) {$ctx1.fill(self,"defaultNamespace",{},smalltalk.AmdPackageHandler.klass)})},
  1446. args: [],
  1447. source: "defaultNamespace\x0a\x09^ Smalltalk current defaultAMDNamespace",
  1448. messageSends: ["defaultAMDNamespace", "current"],
  1449. referencedClasses: ["Smalltalk"]
  1450. }),
  1451. smalltalk.AmdPackageHandler.klass);
  1452. smalltalk.addMethod(
  1453. smalltalk.method({
  1454. selector: "defaultNamespace:",
  1455. category: 'commit paths',
  1456. fn: function (aString){
  1457. var self=this;
  1458. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1459. return smalltalk.withContext(function($ctx1) {
  1460. _st(_st($Smalltalk())._current())._defaultAMDNamespace_(aString);
  1461. return self}, function($ctx1) {$ctx1.fill(self,"defaultNamespace:",{aString:aString},smalltalk.AmdPackageHandler.klass)})},
  1462. args: ["aString"],
  1463. source: "defaultNamespace: aString\x0a\x09Smalltalk current defaultAMDNamespace: aString",
  1464. messageSends: ["defaultAMDNamespace:", "current"],
  1465. referencedClasses: ["Smalltalk"]
  1466. }),
  1467. smalltalk.AmdPackageHandler.klass);
  1468. smalltalk.addMethod(
  1469. smalltalk.method({
  1470. selector: "initialize",
  1471. category: 'initialization',
  1472. fn: function (){
  1473. var self=this;
  1474. return smalltalk.withContext(function($ctx1) {
  1475. smalltalk.AmdPackageHandler.klass.superclass.fn.prototype._initialize.apply(_st(self), []);
  1476. self._registerFor_("amd");
  1477. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.AmdPackageHandler.klass)})},
  1478. args: [],
  1479. source: "initialize\x0a\x09super initialize.\x0a\x09self registerFor: 'amd'",
  1480. messageSends: ["initialize", "registerFor:"],
  1481. referencedClasses: []
  1482. }),
  1483. smalltalk.AmdPackageHandler.klass);
  1484. smalltalk.addMethod(
  1485. smalltalk.method({
  1486. selector: "resetCommitPaths",
  1487. category: 'commit paths',
  1488. fn: function (){
  1489. var self=this;
  1490. return smalltalk.withContext(function($ctx1) {
  1491. self["@defaultNamespace"]=nil;
  1492. return self}, function($ctx1) {$ctx1.fill(self,"resetCommitPaths",{},smalltalk.AmdPackageHandler.klass)})},
  1493. args: [],
  1494. source: "resetCommitPaths\x0a\x09defaultNamespace := nil",
  1495. messageSends: [],
  1496. referencedClasses: []
  1497. }),
  1498. smalltalk.AmdPackageHandler.klass);
  1499. smalltalk.addClass('PluggableExporter', smalltalk.Object, ['recipe'], 'Importer-Exporter');
  1500. smalltalk.PluggableExporter.comment="I am an engine for exporting structured data on a Stream.\x0a\x0aMy instances are created using\x0a PluggableExporter forRecipe: aRecipe,\x0awhere recipe is structured description of the exporting algorithm (see `ExportRecipeInterpreter`).\x0a\x0aThe actual exporting is done by interpreting the recipe using a `RecipeInterpreter`.\x0a\x0a\x0aI am used to export amber packages, so I have a convenience method\x0a`exportPackage: aPackage on: aStream`\x0awhich exports `aPackage` using the `recipe`\x0a(it is otherwise no special, so it may be renamed to export:on:)";
  1501. smalltalk.addMethod(
  1502. smalltalk.method({
  1503. selector: "exportAllPackages",
  1504. category: 'fileOut',
  1505. fn: function (){
  1506. var self=this;
  1507. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1508. function $String(){return smalltalk.String||(typeof String=="undefined"?nil:String)}
  1509. return smalltalk.withContext(function($ctx1) {
  1510. var $1;
  1511. $1=_st($String())._streamContents_((function(stream){
  1512. return smalltalk.withContext(function($ctx2) {
  1513. return _st(_st(_st($Smalltalk())._current())._packages())._do_((function(pkg){
  1514. return smalltalk.withContext(function($ctx3) {
  1515. return self._exportPackage_on_(pkg,stream);
  1516. }, function($ctx3) {$ctx3.fillBlock({pkg:pkg},$ctx2)})}));
  1517. }, function($ctx2) {$ctx2.fillBlock({stream:stream},$ctx1)})}));
  1518. return $1;
  1519. }, function($ctx1) {$ctx1.fill(self,"exportAllPackages",{},smalltalk.PluggableExporter)})},
  1520. args: [],
  1521. source: "exportAllPackages\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]]",
  1522. messageSends: ["streamContents:", "do:", "exportPackage:on:", "packages", "current"],
  1523. referencedClasses: ["Smalltalk", "String"]
  1524. }),
  1525. smalltalk.PluggableExporter);
  1526. smalltalk.addMethod(
  1527. smalltalk.method({
  1528. selector: "exportPackage:on:",
  1529. category: 'fileOut',
  1530. fn: function (aPackage,aStream){
  1531. var self=this;
  1532. return smalltalk.withContext(function($ctx1) {
  1533. _st(self._interpreter())._interpret_for_on_(self._recipe(),aPackage,aStream);
  1534. return self}, function($ctx1) {$ctx1.fill(self,"exportPackage:on:",{aPackage:aPackage,aStream:aStream},smalltalk.PluggableExporter)})},
  1535. args: ["aPackage", "aStream"],
  1536. source: "exportPackage: aPackage on: aStream\x0a\x09self interpreter interpret: self recipe for: aPackage on: aStream",
  1537. messageSends: ["interpret:for:on:", "recipe", "interpreter"],
  1538. referencedClasses: []
  1539. }),
  1540. smalltalk.PluggableExporter);
  1541. smalltalk.addMethod(
  1542. smalltalk.method({
  1543. selector: "interpreter",
  1544. category: 'accessing',
  1545. fn: function (){
  1546. var self=this;
  1547. function $ExportRecipeInterpreter(){return smalltalk.ExportRecipeInterpreter||(typeof ExportRecipeInterpreter=="undefined"?nil:ExportRecipeInterpreter)}
  1548. return smalltalk.withContext(function($ctx1) {
  1549. var $1;
  1550. $1=_st($ExportRecipeInterpreter())._new();
  1551. return $1;
  1552. }, function($ctx1) {$ctx1.fill(self,"interpreter",{},smalltalk.PluggableExporter)})},
  1553. args: [],
  1554. source: "interpreter\x0a\x09^ ExportRecipeInterpreter new",
  1555. messageSends: ["new"],
  1556. referencedClasses: ["ExportRecipeInterpreter"]
  1557. }),
  1558. smalltalk.PluggableExporter);
  1559. smalltalk.addMethod(
  1560. smalltalk.method({
  1561. selector: "recipe",
  1562. category: 'accessing',
  1563. fn: function (){
  1564. var self=this;
  1565. return smalltalk.withContext(function($ctx1) {
  1566. var $1;
  1567. $1=self["@recipe"];
  1568. return $1;
  1569. }, function($ctx1) {$ctx1.fill(self,"recipe",{},smalltalk.PluggableExporter)})},
  1570. args: [],
  1571. source: "recipe\x0a\x09^recipe",
  1572. messageSends: [],
  1573. referencedClasses: []
  1574. }),
  1575. smalltalk.PluggableExporter);
  1576. smalltalk.addMethod(
  1577. smalltalk.method({
  1578. selector: "recipe:",
  1579. category: 'accessing',
  1580. fn: function (anArray){
  1581. var self=this;
  1582. return smalltalk.withContext(function($ctx1) {
  1583. self["@recipe"]=anArray;
  1584. return self}, function($ctx1) {$ctx1.fill(self,"recipe:",{anArray:anArray},smalltalk.PluggableExporter)})},
  1585. args: ["anArray"],
  1586. source: "recipe: anArray\x0a\x09recipe := anArray",
  1587. messageSends: [],
  1588. referencedClasses: []
  1589. }),
  1590. smalltalk.PluggableExporter);
  1591. smalltalk.addMethod(
  1592. smalltalk.method({
  1593. selector: "forRecipe:",
  1594. category: 'instance creation',
  1595. fn: function (aRecipe){
  1596. var self=this;
  1597. return smalltalk.withContext(function($ctx1) {
  1598. var $2,$3,$1;
  1599. $2=self._new();
  1600. _st($2)._recipe_(aRecipe);
  1601. $3=_st($2)._yourself();
  1602. $1=$3;
  1603. return $1;
  1604. }, function($ctx1) {$ctx1.fill(self,"forRecipe:",{aRecipe:aRecipe},smalltalk.PluggableExporter.klass)})},
  1605. args: ["aRecipe"],
  1606. source: "forRecipe: aRecipe\x0a\x09^self new recipe: aRecipe; yourself",
  1607. messageSends: ["recipe:", "new", "yourself"],
  1608. referencedClasses: []
  1609. }),
  1610. smalltalk.PluggableExporter.klass);
  1611. smalltalk.addMethod(
  1612. smalltalk.method({
  1613. selector: "ownClassesOfPackage:",
  1614. category: 'convenience',
  1615. fn: function (package_){
  1616. var self=this;
  1617. return smalltalk.withContext(function($ctx1) {
  1618. var $1;
  1619. $1=_st(_st(package_)._sortedClasses())._asSet();
  1620. return $1;
  1621. }, function($ctx1) {$ctx1.fill(self,"ownClassesOfPackage:",{package_:package_},smalltalk.PluggableExporter.klass)})},
  1622. args: ["package"],
  1623. source: "ownClassesOfPackage: package\x0a\x09\x22Export classes in dependency order.\x0a\x09Update (issue #171): Remove duplicates for export\x22\x0a\x09^package sortedClasses asSet",
  1624. messageSends: ["asSet", "sortedClasses"],
  1625. referencedClasses: []
  1626. }),
  1627. smalltalk.PluggableExporter.klass);
  1628. smalltalk.addMethod(
  1629. smalltalk.method({
  1630. selector: "amdNamespace",
  1631. category: '*Importer-Exporter',
  1632. fn: function (){
  1633. var self=this;
  1634. return smalltalk.withContext(function($ctx1) {
  1635. return (self.transport && self.transport.amdNamespace) || nil;
  1636. return self}, function($ctx1) {$ctx1.fill(self,"amdNamespace",{},smalltalk.Package)})},
  1637. args: [],
  1638. source: "amdNamespace\x0a\x09<return (self.transport && self.transport.amdNamespace) || nil>",
  1639. messageSends: [],
  1640. referencedClasses: []
  1641. }),
  1642. smalltalk.Package);
  1643. smalltalk.addMethod(
  1644. smalltalk.method({
  1645. selector: "amdNamespace:",
  1646. category: '*Importer-Exporter',
  1647. fn: function (aString){
  1648. var self=this;
  1649. return smalltalk.withContext(function($ctx1) {
  1650. if (!self.transport) { self.transport = { type: 'amd' }; }
  1651. if (self.transport.type !== 'amd') { throw new Error('Package '+self._name()+' has transport type '+self.transport.type+', not "amd".'); }
  1652. self.transport.amdNamespace = aString;
  1653. ;
  1654. return self}, function($ctx1) {$ctx1.fill(self,"amdNamespace:",{aString:aString},smalltalk.Package)})},
  1655. args: ["aString"],
  1656. source: "amdNamespace: aString\x0a\x09<\x0a\x09\x09if (!self.transport) { self.transport = { type: 'amd' }; }\x0a\x09\x09if (self.transport.type !== 'amd') { throw new Error('Package '+self._name()+' has transport type '+self.transport.type+', not \x22amd\x22.'); }\x0a\x09\x09self.transport.amdNamespace = aString;\x0a\x09>",
  1657. messageSends: [],
  1658. referencedClasses: []
  1659. }),
  1660. smalltalk.Package);
  1661. smalltalk.addMethod(
  1662. smalltalk.method({
  1663. selector: "commit",
  1664. category: '*Importer-Exporter',
  1665. fn: function (){
  1666. var self=this;
  1667. return smalltalk.withContext(function($ctx1) {
  1668. var $1;
  1669. $1=_st(self._handler())._commit_(self);
  1670. return $1;
  1671. }, function($ctx1) {$ctx1.fill(self,"commit",{},smalltalk.Package)})},
  1672. args: [],
  1673. source: "commit\x0a\x09^ self handler commit: self",
  1674. messageSends: ["commit:", "handler"],
  1675. referencedClasses: []
  1676. }),
  1677. smalltalk.Package);
  1678. smalltalk.addMethod(
  1679. smalltalk.method({
  1680. selector: "commitPathJs",
  1681. category: '*Importer-Exporter',
  1682. fn: function (){
  1683. var self=this;
  1684. return smalltalk.withContext(function($ctx1) {
  1685. var $3,$2,$1;
  1686. $3=self["@extension"];
  1687. if(($receiver = $3) == nil || $receiver == undefined){
  1688. self["@extension"]=smalltalk.HashedCollection._from_([]);
  1689. $2=self["@extension"];
  1690. } else {
  1691. $2=$3;
  1692. };
  1693. $1=_st($2)._at_ifAbsent_("commitPathJs",(function(){
  1694. return smalltalk.withContext(function($ctx2) {
  1695. return _st(self._handler())._commitPathJsFor_(self);
  1696. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  1697. return $1;
  1698. }, function($ctx1) {$ctx1.fill(self,"commitPathJs",{},smalltalk.Package)})},
  1699. args: [],
  1700. source: "commitPathJs\x0a\x09^ (extension ifNil: [ extension := #{} ]) at: #commitPathJs ifAbsent: [ self handler commitPathJsFor: self ]",
  1701. messageSends: ["at:ifAbsent:", "commitPathJsFor:", "handler", "ifNil:"],
  1702. referencedClasses: []
  1703. }),
  1704. smalltalk.Package);
  1705. smalltalk.addMethod(
  1706. smalltalk.method({
  1707. selector: "commitPathJs:",
  1708. category: '*Importer-Exporter',
  1709. fn: function (aString){
  1710. var self=this;
  1711. return smalltalk.withContext(function($ctx1) {
  1712. var $3,$2,$1;
  1713. $3=self["@extension"];
  1714. if(($receiver = $3) == nil || $receiver == undefined){
  1715. self["@extension"]=smalltalk.HashedCollection._from_([]);
  1716. $2=self["@extension"];
  1717. } else {
  1718. $2=$3;
  1719. };
  1720. $1=_st($2)._at_put_("commitPathJs",aString);
  1721. return $1;
  1722. }, function($ctx1) {$ctx1.fill(self,"commitPathJs:",{aString:aString},smalltalk.Package)})},
  1723. args: ["aString"],
  1724. source: "commitPathJs: aString\x0a\x09^ (extension ifNil: [ extension := #{} ]) at: #commitPathJs put: aString",
  1725. messageSends: ["at:put:", "ifNil:"],
  1726. referencedClasses: []
  1727. }),
  1728. smalltalk.Package);
  1729. smalltalk.addMethod(
  1730. smalltalk.method({
  1731. selector: "commitPathSt",
  1732. category: '*Importer-Exporter',
  1733. fn: function (){
  1734. var self=this;
  1735. return smalltalk.withContext(function($ctx1) {
  1736. var $3,$2,$1;
  1737. $3=self["@extension"];
  1738. if(($receiver = $3) == nil || $receiver == undefined){
  1739. self["@extension"]=smalltalk.HashedCollection._from_([]);
  1740. $2=self["@extension"];
  1741. } else {
  1742. $2=$3;
  1743. };
  1744. $1=_st($2)._at_ifAbsent_("commitPathSt",(function(){
  1745. return smalltalk.withContext(function($ctx2) {
  1746. return _st(self._handler())._commitPathStFor_(self);
  1747. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  1748. return $1;
  1749. }, function($ctx1) {$ctx1.fill(self,"commitPathSt",{},smalltalk.Package)})},
  1750. args: [],
  1751. source: "commitPathSt\x0a\x09^ (extension ifNil: [ extension := #{} ]) at: #commitPathSt ifAbsent: [ self handler commitPathStFor: self ]",
  1752. messageSends: ["at:ifAbsent:", "commitPathStFor:", "handler", "ifNil:"],
  1753. referencedClasses: []
  1754. }),
  1755. smalltalk.Package);
  1756. smalltalk.addMethod(
  1757. smalltalk.method({
  1758. selector: "commitPathSt:",
  1759. category: '*Importer-Exporter',
  1760. fn: function (aString){
  1761. var self=this;
  1762. return smalltalk.withContext(function($ctx1) {
  1763. var $3,$2,$1;
  1764. $3=self["@extension"];
  1765. if(($receiver = $3) == nil || $receiver == undefined){
  1766. self["@extension"]=smalltalk.HashedCollection._from_([]);
  1767. $2=self["@extension"];
  1768. } else {
  1769. $2=$3;
  1770. };
  1771. $1=_st($2)._at_put_("commitPathSt",aString);
  1772. return $1;
  1773. }, function($ctx1) {$ctx1.fill(self,"commitPathSt:",{aString:aString},smalltalk.Package)})},
  1774. args: ["aString"],
  1775. source: "commitPathSt: aString\x0a\x09^ (extension ifNil: [ extension := #{} ]) at: #commitPathSt put: aString",
  1776. messageSends: ["at:put:", "ifNil:"],
  1777. referencedClasses: []
  1778. }),
  1779. smalltalk.Package);
  1780. smalltalk.addMethod(
  1781. smalltalk.method({
  1782. selector: "handler",
  1783. category: '*Importer-Exporter',
  1784. fn: function (){
  1785. var self=this;
  1786. function $PackageHandler(){return smalltalk.PackageHandler||(typeof PackageHandler=="undefined"?nil:PackageHandler)}
  1787. return smalltalk.withContext(function($ctx1) {
  1788. var $1;
  1789. $1=_st($PackageHandler())._for_(self._transportType());
  1790. return $1;
  1791. }, function($ctx1) {$ctx1.fill(self,"handler",{},smalltalk.Package)})},
  1792. args: [],
  1793. source: "handler\x0a\x09^ PackageHandler for: self transportType",
  1794. messageSends: ["for:", "transportType"],
  1795. referencedClasses: ["PackageHandler"]
  1796. }),
  1797. smalltalk.Package);
  1798. smalltalk.addMethod(
  1799. smalltalk.method({
  1800. selector: "transportJson",
  1801. category: '*Importer-Exporter',
  1802. fn: function (){
  1803. var self=this;
  1804. return smalltalk.withContext(function($ctx1) {
  1805. return JSON.stringify(self.transport || null);;
  1806. return self}, function($ctx1) {$ctx1.fill(self,"transportJson",{},smalltalk.Package)})},
  1807. args: [],
  1808. source: "transportJson\x0a\x09<return JSON.stringify(self.transport || null);>",
  1809. messageSends: [],
  1810. referencedClasses: []
  1811. }),
  1812. smalltalk.Package);
  1813. smalltalk.addMethod(
  1814. smalltalk.method({
  1815. selector: "transportType",
  1816. category: '*Importer-Exporter',
  1817. fn: function (){
  1818. var self=this;
  1819. return smalltalk.withContext(function($ctx1) {
  1820. return (self.transport && self.transport.type) || 'unknown';;
  1821. return self}, function($ctx1) {$ctx1.fill(self,"transportType",{},smalltalk.Package)})},
  1822. args: [],
  1823. source: "transportType\x0a\x09<return (self.transport && self.transport.type) || 'unknown';>",
  1824. messageSends: [],
  1825. referencedClasses: []
  1826. }),
  1827. smalltalk.Package);
  1828. });