Browse Source

update from master

Nicolas Petton 13 years ago
parent
commit
7b101ffed0
2 changed files with 58 additions and 10 deletions
  1. 25 7
      js/Compiler.js
  2. 33 3
      js/boot.js

+ 25 - 7
js/Compiler.js

@@ -288,7 +288,7 @@ return (function($rec){smalltalk.send($rec, "_receiver_", [smalltalk.send(self,
 return self;},
 source: unescape('cascadeNodeWithMessages%3A%20aCollection%0A%09%7C%20first%20%7C%0A%09first%20%3A%3D%20SendNode%20new%0A%09%20%20%20%20selector%3A%20self%20selector%3B%0A%09%20%20%20%20arguments%3A%20self%20arguments%3B%0A%09%20%20%20%20yourself.%0A%09%5ECascadeNode%20new%0A%09%20%20%20%20receiver%3A%20self%20receiver%3B%0A%09%20%20%20%20nodes%3A%20%28Array%20with%3A%20first%29%2C%20aCollection%3B%0A%09%20%20%20%20yourself'),
 messageSends: ["selector:", "selector", "arguments:", "arguments", "yourself", "new", "receiver:", "receiver", "nodes:", unescape("%2C"), "with:"],
-referencedClasses: [smalltalk.SendNode,smalltalk.Array,smalltalk.CascadeNode]
+referencedClasses: [smalltalk.SendNode,smalltalk.Array,smalltalk.nil]
 }),
 smalltalk.SendNode);
 
@@ -525,7 +525,7 @@ return (function($rec){smalltalk.send($rec, "_nodes_", [smalltalk.send(self, "_n
 return self;},
 source: unescape('asBlockSequenceNode%0A%09%5EBlockSequenceNode%20new%0A%09%20%20%20%20nodes%3A%20self%20nodes%3B%0A%09%20%20%20%20temps%3A%20self%20temps%3B%0A%09%20%20%20%20yourself'),
 messageSends: ["nodes:", "nodes", "temps:", "temps", "yourself", "new"],
-referencedClasses: [smalltalk.BlockSequenceNode]
+referencedClasses: [smalltalk.nil]
 }),
 smalltalk.SequenceNode);
 
@@ -1005,7 +1005,7 @@ return smalltalk.send(smalltalk.send(smalltalk.DoIt, "_new", []), "_doIt", []);
 return self;},
 source: unescape('loadExpression%3A%20aString%0A%09DoIt%20addCompiledMethod%3A%20%28self%20eval%3A%20%28self%20compileExpression%3A%20aString%29%29.%0A%09%5EDoIt%20new%20doIt'),
 messageSends: ["addCompiledMethod:", "eval:", "compileExpression:", "doIt", "new"],
-referencedClasses: [smalltalk.DoIt]
+referencedClasses: [smalltalk.nil]
 }),
 smalltalk.Compiler);
 
@@ -1016,10 +1016,13 @@ selector: 'load:forClass:',
 category: 'compiling',
 fn: function (aString, aClass){
 var self=this;
-return smalltalk.send(self, "_eval_", [smalltalk.send(self, "_compile_forClass_", [aString, aClass])]);
+var compiled=nil;
+compiled=smalltalk.send(self, "_eval_", [smalltalk.send(self, "_compile_forClass_", [aString, aClass])]);
+smalltalk.send(self, "_setupClass_", [aClass]);
+return compiled;
 return self;},
-source: unescape('load%3A%20aString%20forClass%3A%20aClass%0A%09%5Eself%20eval%3A%20%28self%20compile%3A%20aString%20forClass%3A%20aClass%29'),
-messageSends: ["eval:", "compile:forClass:"],
+source: unescape('load%3A%20aString%20forClass%3A%20aClass%0A%09%7C%20compiled%20%7C%0A%09compiled%20%3A%3D%20self%20eval%3A%20%28self%20compile%3A%20aString%20forClass%3A%20aClass%29.%0A%09self%20setupClass%3A%20aClass.%0A%09%5Ecompiled'),
+messageSends: ["eval:", "compile:forClass:", "setupClass:"],
 referencedClasses: []
 }),
 smalltalk.Compiler);
@@ -1052,7 +1055,7 @@ return smalltalk.send(self, "_compileNode_", [smalltalk.send(self, "_parseExpres
 return self;},
 source: unescape('compileExpression%3A%20aString%0A%09self%20currentClass%3A%20DoIt.%0A%09%5Eself%20compileNode%3A%20%28self%20parseExpression%3A%20aString%29'),
 messageSends: ["currentClass:", "compileNode:", "parseExpression:"],
-referencedClasses: [smalltalk.DoIt]
+referencedClasses: [smalltalk.nil]
 }),
 smalltalk.Compiler);
 
@@ -1513,6 +1516,21 @@ referencedClasses: []
 }),
 smalltalk.Compiler);
 
+smalltalk.addMethod(
+'_setupClass_',
+smalltalk.method({
+selector: 'setupClass:',
+category: 'compiling',
+fn: function (aClass){
+var self=this;
+smalltalk.init(aClass);
+return self;},
+source: unescape('setupClass%3A%20aClass%0A%09%3Csmalltalk.init%28aClass%29%3E'),
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.Compiler);
+
 
 smalltalk.addMethod(
 '_recompile_',

+ 33 - 3
js/boot.js

@@ -74,6 +74,7 @@ function Smalltalk(){
 	}
 	that.category = spec.category || "";
 	that.fn.prototype.methods = {};
+	that.fn.prototype.inheritedMethods = {};
 	that.fn.prototype.klass = that;
 
 	return that;
@@ -85,6 +86,7 @@ function Smalltalk(){
     st.method = function(spec) {
 	var that = new SmalltalkMethod();
 	that.selector          = spec.selector;
+	that.jsSelector        = spec.jsSelector;
 	that.category          = spec.category;
 	that.source            = spec.source;
 	that.messageSends      = spec.messageSends || [];
@@ -98,17 +100,32 @@ function Smalltalk(){
 
     st.init = function(klass) {
 	var subclasses = st.subclasses(klass);
+	var methods;
+
+	// Initializing inst vars
 	for(var i=0;i<klass.iVarNames.length;i++) {
 	    klass.fn.prototype["@"+klass.iVarNames[i]] = nil;
 	}
+
 	if(klass.superclass && klass.superclass !== nil) {
-	    klass.fn.prototype.__proto__ = klass.superclass.fn.prototype;
+	    methods = st.methods(klass.superclass);
+
+	    //Methods linking
+	    for(var i in methods) {
+		if(!klass.fn.prototype.methods[i]) {
+		    klass.fn.prototype.inheritedMethods[i] = methods[i];
+		    klass.fn.prototype[methods[i].jsSelector] = methods[i].fn;
+		}
+	    }
+
+	    //Instance variables linking
 	    for(var i=0;i<klass.superclass.iVarNames.length;i++) {
 		if(!klass["@"+klass.superclass.iVarNames[i]]) {
 		    klass.fn.prototype["@"+klass.superclass.iVarNames[i]] = nil;
 		}
 	    }
 	}
+
 	for(var i=0;i<subclasses.length;i++) {
      	    st.init(subclasses[i]);
 	}
@@ -130,8 +147,20 @@ function Smalltalk(){
 	return classes
     };
 
-    /* Answer the direct subclasses of a given class.
-       This is computed dynamically */
+    /* Answer all methods (included inherited ones) of klass. */
+
+    st.methods = function(klass) {
+	var methods = {};
+	for(var i in klass.fn.prototype.methods) {
+	    methods[i] = klass.fn.prototype.methods[i]
+	}
+	for(var i in klass.fn.prototype.inheritedMethods) {
+	    methods[i] = klass.fn.prototype.inheritedMethods[i]
+	}
+	return methods;
+    }
+
+    /* Answer the direct subclasses of klass. */
 
     st.subclasses = function(klass) {
 	var subclasses = [];
@@ -186,6 +215,7 @@ function Smalltalk(){
 	klass.fn.prototype[jsSelector] = method.fn;
 	klass.fn.prototype.methods[method.selector] = method;
 	method.methodClass = klass;
+	method.jsSelector = jsSelector;
     };
 
     /* Handles Smalltalk message send. Automatically converts undefined to the nil object.