Browse Source

Merge branch 'load-dependencies' into requirejs

Herbert Vojčík 10 years ago
parent
commit
d9aad8f5c4
3 changed files with 113 additions and 39 deletions
  1. 43 14
      js/Kernel-Infrastructure.deploy.js
  2. 50 16
      js/Kernel-Infrastructure.js
  3. 20 9
      st/Kernel-Infrastructure.st

+ 43 - 14
js/Kernel-Infrastructure.deploy.js

@@ -935,21 +935,50 @@ smalltalk.method({
 selector: "loadDependencies",
 fn: function (){
 var self=this;
-var root;
-function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
+var classes,packages;
 return smalltalk.withContext(function($ctx1) { 
-var $1,$2,$3;
-root=_st($Object())._package();
-$1=self.__eq_eq(root);
-if(smalltalk.assert($1)){
-$2=[];
-return $2;
-} else {
-$3=[root];
-return $3;
-};
-return self}, function($ctx1) {$ctx1.fill(self,"loadDependencies",{root:root},smalltalk.Package)})},
-messageSends: ["package", "ifTrue:ifFalse:", "=="]}),
+var $2,$3,$1;
+classes=self._loadDependencyClasses();
+$2=_st(_st(classes)._collect_((function(each){
+return smalltalk.withContext(function($ctx2) {
+return _st(each)._package();
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})})))._asSet();
+_st($2)._remove_ifAbsent_(self,(function(){
+return smalltalk.withContext(function($ctx2) {
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
+$3=_st($2)._yourself();
+$1=$3;
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"loadDependencies",{classes:classes,packages:packages},smalltalk.Package)})},
+messageSends: ["loadDependencyClasses", "remove:ifAbsent:", "asSet", "collect:", "package", "yourself"]}),
+smalltalk.Package);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "loadDependencyClasses",
+fn: function (){
+var self=this;
+var starCategoryName;
+function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
+return smalltalk.withContext(function($ctx1) { 
+var $2,$3,$1;
+starCategoryName="*".__comma(self._name());
+$2=_st(_st(self._classes())._collect_((function(each){
+return smalltalk.withContext(function($ctx2) {
+return _st(each)._superclass();
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})})))._asSet();
+_st($2)._remove_ifAbsent_(nil,(function(){
+return smalltalk.withContext(function($ctx2) {
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
+_st($2)._addAll_(_st(_st(_st($Smalltalk())._current())._classes())._select_((function(each){
+return smalltalk.withContext(function($ctx2) {
+return _st(_st(each)._protocols())._includes_(starCategoryName);
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})})));
+$3=_st($2)._yourself();
+$1=$3;
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"loadDependencyClasses",{starCategoryName:starCategoryName},smalltalk.Package)})},
+messageSends: [",", "name", "remove:ifAbsent:", "asSet", "collect:", "superclass", "classes", "addAll:", "select:", "includes:", "protocols", "current", "yourself"]}),
 smalltalk.Package);
 
 smalltalk.addMethod(

+ 50 - 16
js/Kernel-Infrastructure.js

@@ -1249,24 +1249,58 @@ selector: "loadDependencies",
 category: 'dependencies',
 fn: function (){
 var self=this;
-var root;
-function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
+var classes,packages;
 return smalltalk.withContext(function($ctx1) { 
-var $1,$2,$3;
-root=_st($Object())._package();
-$1=self.__eq_eq(root);
-if(smalltalk.assert($1)){
-$2=[];
-return $2;
-} else {
-$3=[root];
-return $3;
-};
-return self}, function($ctx1) {$ctx1.fill(self,"loadDependencies",{root:root},smalltalk.Package)})},
+var $2,$3,$1;
+classes=self._loadDependencyClasses();
+$2=_st(_st(classes)._collect_((function(each){
+return smalltalk.withContext(function($ctx2) {
+return _st(each)._package();
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})})))._asSet();
+_st($2)._remove_ifAbsent_(self,(function(){
+return smalltalk.withContext(function($ctx2) {
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
+$3=_st($2)._yourself();
+$1=$3;
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"loadDependencies",{classes:classes,packages:packages},smalltalk.Package)})},
+args: [],
+source: "loadDependencies\x0a\x09\x22Returns list of packages that need to be loaded\x0a\x09before loading this package.\x22\x0a\x09\x0a\x09| classes packages |\x0a\x09classes := self loadDependencyClasses.\x0a\x09^(classes collect: [ :each | each package ]) asSet\x0a\x09\x09remove: self ifAbsent: [];\x0a\x09\x09yourself",
+messageSends: ["loadDependencyClasses", "remove:ifAbsent:", "asSet", "collect:", "package", "yourself"],
+referencedClasses: []
+}),
+smalltalk.Package);
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "loadDependencyClasses",
+category: 'dependencies',
+fn: function (){
+var self=this;
+var starCategoryName;
+function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
+return smalltalk.withContext(function($ctx1) { 
+var $2,$3,$1;
+starCategoryName="*".__comma(self._name());
+$2=_st(_st(self._classes())._collect_((function(each){
+return smalltalk.withContext(function($ctx2) {
+return _st(each)._superclass();
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})})))._asSet();
+_st($2)._remove_ifAbsent_(nil,(function(){
+return smalltalk.withContext(function($ctx2) {
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
+_st($2)._addAll_(_st(_st(_st($Smalltalk())._current())._classes())._select_((function(each){
+return smalltalk.withContext(function($ctx2) {
+return _st(_st(each)._protocols())._includes_(starCategoryName);
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})})));
+$3=_st($2)._yourself();
+$1=$3;
+return $1;
+}, function($ctx1) {$ctx1.fill(self,"loadDependencyClasses",{starCategoryName:starCategoryName},smalltalk.Package)})},
 args: [],
-source: "loadDependencies\x0a\x09\x22Returns list of packages that need to be present\x0a\x09before loading this package.\x0a\x09These are determined as set of packages covering\x0a\x09all classes used either for subclassing or for defining\x0a\x09extension methods on.\x22\x0a\x09\x0a\x09\x22Fake one for now. TODO\x22\x0a\x09| root |\x0a\x09root := Object package.\x0a\x09self == root ifTrue: [ ^#() ] ifFalse: [ ^{root} ]",
-messageSends: ["package", "ifTrue:ifFalse:", "=="],
-referencedClasses: ["Object"]
+source: "loadDependencyClasses\x0a\x09\x22Returns classes needed at the time of loading a package.\x0a\x09These are all that are used to subclass\x0a\x09and to define an extension method\x22\x0a\x09\x0a\x09| starCategoryName |\x0a\x09starCategoryName := '*', self name.\x0a\x09^(self classes collect: [ :each | each superclass ]) asSet\x0a\x09\x09remove: nil ifAbsent: [];\x0a\x09\x09addAll: (Smalltalk current classes select: [ :each | each protocols includes: starCategoryName ]);\x0a\x09\x09yourself",
+messageSends: [",", "name", "remove:ifAbsent:", "asSet", "collect:", "superclass", "classes", "addAll:", "select:", "includes:", "protocols", "current", "yourself"],
+referencedClasses: ["Smalltalk"]
 }),
 smalltalk.Package);
 

+ 20 - 9
st/Kernel-Infrastructure.st

@@ -507,16 +507,27 @@ sortedClasses
 !Package methodsFor: 'dependencies'!
 
 loadDependencies
-	"Returns list of packages that need to be present
-	before loading this package.
-	These are determined as set of packages covering
-	all classes used either for subclassing or for defining
-	extension methods on."
+	"Returns list of packages that need to be loaded
+	before loading this package."
 	
-	"Fake one for now. TODO"
-	| root |
-	root := Object package.
-	self == root ifTrue: [ ^#() ] ifFalse: [ ^{root} ]
+	| classes packages |
+	classes := self loadDependencyClasses.
+	^(classes collect: [ :each | each package ]) asSet
+		remove: self ifAbsent: [];
+		yourself
+!
+
+loadDependencyClasses
+	"Returns classes needed at the time of loading a package.
+	These are all that are used to subclass
+	and to define an extension method"
+	
+	| starCategoryName |
+	starCategoryName := '*', self name.
+	^(self classes collect: [ :each | each superclass ]) asSet
+		remove: nil ifAbsent: [];
+		addAll: (Smalltalk current classes select: [ :each | each protocols includes: starCategoryName ]);
+		yourself
 ! !
 
 !Package methodsFor: 'printing'!