Kernel-Dag.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. define(["amber/boot", "amber_core/Kernel-Objects"], function($boot){"use strict";
  2. if(!$boot.nilAsReceiver)$boot.nilAsReceiver=$boot.nil;
  3. var $core=$boot.api,nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
  4. if(!$boot.nilAsClass)$boot.nilAsClass=$boot.dnu;
  5. $core.addPackage('Kernel-Dag');
  6. $core.packages["Kernel-Dag"].innerEval = function (expr) { return eval(expr); };
  7. $core.packages["Kernel-Dag"].transport = {"type":"amd","amdNamespace":"amber_core"};
  8. $core.addClass('DagNode', $globals.Object, [], 'Kernel-Dag');
  9. //>>excludeStart("ide", pragmas.excludeIdeData);
  10. $globals.DagNode.comment="I am the abstract root class of any directed acyclic graph.\x0a\x0aConcrete classes should implement `dagChildren` and `dagChildren:`\x0ato get / set direct successor nodes (aka child nodes / subnodes).";
  11. //>>excludeEnd("ide");
  12. $core.addMethod(
  13. $core.method({
  14. selector: "allDagChildren",
  15. protocol: 'accessing',
  16. fn: function (){
  17. var self=this;
  18. var allNodes;
  19. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  20. return $core.withContext(function($ctx1) {
  21. //>>excludeEnd("ctx");
  22. var $1;
  23. $1=self._dagChildren();
  24. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  25. $ctx1.sendIdx["dagChildren"]=1;
  26. //>>excludeEnd("ctx");
  27. allNodes=$recv($1)._asSet();
  28. $recv(self._dagChildren())._do_((function(each){
  29. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  30. return $core.withContext(function($ctx2) {
  31. //>>excludeEnd("ctx");
  32. return $recv(allNodes)._addAll_($recv(each)._allDagChildren());
  33. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  34. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  35. //>>excludeEnd("ctx");
  36. }));
  37. return allNodes;
  38. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  39. }, function($ctx1) {$ctx1.fill(self,"allDagChildren",{allNodes:allNodes},$globals.DagNode)});
  40. //>>excludeEnd("ctx");
  41. },
  42. //>>excludeStart("ide", pragmas.excludeIdeData);
  43. args: [],
  44. source: "allDagChildren\x0a\x09| allNodes |\x0a\x09\x0a\x09allNodes := self dagChildren asSet.\x0a\x09self dagChildren do: [ :each | \x0a\x09\x09allNodes addAll: each allDagChildren ].\x0a\x09\x0a\x09^ allNodes",
  45. referencedClasses: [],
  46. //>>excludeEnd("ide");
  47. messageSends: ["asSet", "dagChildren", "do:", "addAll:", "allDagChildren"]
  48. }),
  49. $globals.DagNode);
  50. $core.addMethod(
  51. $core.method({
  52. selector: "dagChildren",
  53. protocol: 'accessing',
  54. fn: function (){
  55. var self=this;
  56. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  57. return $core.withContext(function($ctx1) {
  58. //>>excludeEnd("ctx");
  59. self._subclassResponsibility();
  60. return self;
  61. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  62. }, function($ctx1) {$ctx1.fill(self,"dagChildren",{},$globals.DagNode)});
  63. //>>excludeEnd("ctx");
  64. },
  65. //>>excludeStart("ide", pragmas.excludeIdeData);
  66. args: [],
  67. source: "dagChildren\x0a\x09self subclassResponsibility",
  68. referencedClasses: [],
  69. //>>excludeEnd("ide");
  70. messageSends: ["subclassResponsibility"]
  71. }),
  72. $globals.DagNode);
  73. $core.addMethod(
  74. $core.method({
  75. selector: "dagChildren:",
  76. protocol: 'accessing',
  77. fn: function (aCollection){
  78. var self=this;
  79. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  80. return $core.withContext(function($ctx1) {
  81. //>>excludeEnd("ctx");
  82. self._subclassResponsibility();
  83. return self;
  84. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  85. }, function($ctx1) {$ctx1.fill(self,"dagChildren:",{aCollection:aCollection},$globals.DagNode)});
  86. //>>excludeEnd("ctx");
  87. },
  88. //>>excludeStart("ide", pragmas.excludeIdeData);
  89. args: ["aCollection"],
  90. source: "dagChildren: aCollection\x0a\x09self subclassResponsibility",
  91. referencedClasses: [],
  92. //>>excludeEnd("ide");
  93. messageSends: ["subclassResponsibility"]
  94. }),
  95. $globals.DagNode);
  96. $core.addMethod(
  97. $core.method({
  98. selector: "isDagNode",
  99. protocol: 'testing',
  100. fn: function (){
  101. var self=this;
  102. return true;
  103. },
  104. //>>excludeStart("ide", pragmas.excludeIdeData);
  105. args: [],
  106. source: "isDagNode\x0a\x09^ true",
  107. referencedClasses: [],
  108. //>>excludeEnd("ide");
  109. messageSends: []
  110. }),
  111. $globals.DagNode);
  112. $core.addClass('DagParentNode', $globals.DagNode, ['nodes'], 'Kernel-Dag');
  113. //>>excludeStart("ide", pragmas.excludeIdeData);
  114. $globals.DagParentNode.comment="I am `DagNode` that stores a collection of its children,\x0alazy initialized to empty array.\x0a\x0aI can `addDagChild:` to add a child.";
  115. //>>excludeEnd("ide");
  116. $core.addMethod(
  117. $core.method({
  118. selector: "addDagChild:",
  119. protocol: 'accessing',
  120. fn: function (aDagNode){
  121. var self=this;
  122. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  123. return $core.withContext(function($ctx1) {
  124. //>>excludeEnd("ctx");
  125. $recv(self._dagChildren())._add_(aDagNode);
  126. return self;
  127. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  128. }, function($ctx1) {$ctx1.fill(self,"addDagChild:",{aDagNode:aDagNode},$globals.DagParentNode)});
  129. //>>excludeEnd("ctx");
  130. },
  131. //>>excludeStart("ide", pragmas.excludeIdeData);
  132. args: ["aDagNode"],
  133. source: "addDagChild: aDagNode\x0a\x09self dagChildren add: aDagNode",
  134. referencedClasses: [],
  135. //>>excludeEnd("ide");
  136. messageSends: ["add:", "dagChildren"]
  137. }),
  138. $globals.DagParentNode);
  139. $core.addMethod(
  140. $core.method({
  141. selector: "dagChildren",
  142. protocol: 'accessing',
  143. fn: function (){
  144. var self=this;
  145. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  146. return $core.withContext(function($ctx1) {
  147. //>>excludeEnd("ctx");
  148. var $1,$receiver;
  149. $1=self["@nodes"];
  150. if(($receiver = $1) == null || $receiver.isNil){
  151. self["@nodes"]=$recv($globals.Array)._new();
  152. return self["@nodes"];
  153. } else {
  154. return $1;
  155. };
  156. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  157. }, function($ctx1) {$ctx1.fill(self,"dagChildren",{},$globals.DagParentNode)});
  158. //>>excludeEnd("ctx");
  159. },
  160. //>>excludeStart("ide", pragmas.excludeIdeData);
  161. args: [],
  162. source: "dagChildren\x0a\x09^ nodes ifNil: [ nodes := Array new ]",
  163. referencedClasses: ["Array"],
  164. //>>excludeEnd("ide");
  165. messageSends: ["ifNil:", "new"]
  166. }),
  167. $globals.DagParentNode);
  168. $core.addMethod(
  169. $core.method({
  170. selector: "dagChildren:",
  171. protocol: 'accessing',
  172. fn: function (aCollection){
  173. var self=this;
  174. self["@nodes"]=aCollection;
  175. return self;
  176. },
  177. //>>excludeStart("ide", pragmas.excludeIdeData);
  178. args: ["aCollection"],
  179. source: "dagChildren: aCollection\x0a\x09nodes := aCollection",
  180. referencedClasses: [],
  181. //>>excludeEnd("ide");
  182. messageSends: []
  183. }),
  184. $globals.DagParentNode);
  185. $core.addClass('DagSink', $globals.DagNode, ['nodes'], 'Kernel-Dag');
  186. //>>excludeStart("ide", pragmas.excludeIdeData);
  187. $globals.DagSink.comment="I am `DagNode` with no direct successors.\x0a\x0aSending `dagChildren:` with empty collection is legal.";
  188. //>>excludeEnd("ide");
  189. $core.addMethod(
  190. $core.method({
  191. selector: "dagChildren",
  192. protocol: 'accessing',
  193. fn: function (){
  194. var self=this;
  195. return [];
  196. },
  197. //>>excludeStart("ide", pragmas.excludeIdeData);
  198. args: [],
  199. source: "dagChildren\x0a\x09^ #()",
  200. referencedClasses: [],
  201. //>>excludeEnd("ide");
  202. messageSends: []
  203. }),
  204. $globals.DagSink);
  205. $core.addMethod(
  206. $core.method({
  207. selector: "dagChildren:",
  208. protocol: 'accessing',
  209. fn: function (aCollection){
  210. var self=this;
  211. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  212. return $core.withContext(function($ctx1) {
  213. //>>excludeEnd("ctx");
  214. $recv(aCollection)._ifNotEmpty_((function(){
  215. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  216. return $core.withContext(function($ctx2) {
  217. //>>excludeEnd("ctx");
  218. return self._error_("A DagSink cannot have children.");
  219. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  220. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  221. //>>excludeEnd("ctx");
  222. }));
  223. return self;
  224. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  225. }, function($ctx1) {$ctx1.fill(self,"dagChildren:",{aCollection:aCollection},$globals.DagSink)});
  226. //>>excludeEnd("ctx");
  227. },
  228. //>>excludeStart("ide", pragmas.excludeIdeData);
  229. args: ["aCollection"],
  230. source: "dagChildren: aCollection\x0a\x09aCollection ifNotEmpty: [ self error: 'A DagSink cannot have children.' ]",
  231. referencedClasses: [],
  232. //>>excludeEnd("ide");
  233. messageSends: ["ifNotEmpty:", "error:"]
  234. }),
  235. $globals.DagSink);
  236. $core.addMethod(
  237. $core.method({
  238. selector: "isDagNode",
  239. protocol: '*Kernel-Dag',
  240. fn: function (){
  241. var self=this;
  242. return false;
  243. },
  244. //>>excludeStart("ide", pragmas.excludeIdeData);
  245. args: [],
  246. source: "isDagNode\x0a\x09^ false",
  247. referencedClasses: [],
  248. //>>excludeEnd("ide");
  249. messageSends: []
  250. }),
  251. $globals.Object);
  252. });