Kaynağa Gözat

- New Symbol class
- New String and Symbol superclass CharacterArray
- Fixed the parser to correctly parse symbols
- More unit tests
- New OrderedCollection class (not usable yet)

Nicolas Petton 12 yıl önce
ebeveyn
işleme
5b7814fa56

+ 1 - 1
js/Kernel-Classes.deploy.js

@@ -412,7 +412,7 @@ smalltalk.method({
 selector: 'subclass:instanceVariableNames:package:',
 fn: function (aString, aString2, aString3){
 var self=this;
-return smalltalk.send(smalltalk.send((smalltalk.ClassBuilder || ClassBuilder), "_new", []), "_superclass_subclass_instanceVariableNames_package_", [self, aString, aString2, aString3]);
+return smalltalk.send(smalltalk.send((smalltalk.ClassBuilder || ClassBuilder), "_new", []), "_superclass_subclass_instanceVariableNames_package_", [self, smalltalk.send(aString, "_asString", []), aString2, aString3]);
 return self;}
 }),
 smalltalk.Class);

+ 3 - 3
js/Kernel-Classes.js

@@ -583,11 +583,11 @@ selector: unescape('subclass%3AinstanceVariableNames%3Apackage%3A'),
 category: 'class creation',
 fn: function (aString, aString2, aString3){
 var self=this;
-return smalltalk.send(smalltalk.send((smalltalk.ClassBuilder || ClassBuilder), "_new", []), "_superclass_subclass_instanceVariableNames_package_", [self, aString, aString2, aString3]);
+return smalltalk.send(smalltalk.send((smalltalk.ClassBuilder || ClassBuilder), "_new", []), "_superclass_subclass_instanceVariableNames_package_", [self, smalltalk.send(aString, "_asString", []), aString2, aString3]);
 return self;},
 args: ["aString", "aString2", "aString3"],
-source: unescape('subclass%3A%20aString%20instanceVariableNames%3A%20aString2%20package%3A%20aString3%0A%09%5EClassBuilder%20new%0A%09%20%20%20%20superclass%3A%20self%20subclass%3A%20aString%20instanceVariableNames%3A%20aString2%20package%3A%20aString3'),
-messageSends: ["superclass:subclass:instanceVariableNames:package:", "new"],
+source: unescape('subclass%3A%20aString%20instanceVariableNames%3A%20aString2%20package%3A%20aString3%0A%09%5EClassBuilder%20new%0A%09%20%20%20%20superclass%3A%20self%20subclass%3A%20aString%20asString%20instanceVariableNames%3A%20aString2%20package%3A%20aString3'),
+messageSends: ["superclass:subclass:instanceVariableNames:package:", "new", "asString"],
 referencedClasses: ["ClassBuilder"]
 }),
 smalltalk.Class);

+ 697 - 130
js/Kernel-Collections.deploy.js

@@ -117,12 +117,7 @@ smalltalk.method({
 selector: 'asArray',
 fn: function (){
 var self=this;
-var array=nil;
-var index=nil;
-array=smalltalk.send((smalltalk.Array || Array), "_new", []);
-index=(0);
-smalltalk.send(self, "_do_", [(function(each){index=((($receiver = index).klass === smalltalk.Number) ? $receiver +(1) : smalltalk.send($receiver, "__plus", [(1)]));return smalltalk.send(array, "_at_put_", [index, each]);})]);
-return array;
+return smalltalk.send((smalltalk.Array || Array), "_withAll_", [self]);
 return self;}
 }),
 smalltalk.Collection);
@@ -358,6 +353,17 @@ return self;}
 }),
 smalltalk.Collection);
 
+smalltalk.addMethod(
+'_asOrderedCollection',
+smalltalk.method({
+selector: 'asOrderedCollection',
+fn: function (){
+var self=this;
+return smalltalk.send((smalltalk.OrderedCollection || OrderedCollection), "_withAll_", [self]);
+return self;}
+}),
+smalltalk.Collection);
+
 
 smalltalk.addMethod(
 '_streamClass',
@@ -414,6 +420,17 @@ return self;}
 }),
 smalltalk.Collection.klass);
 
+smalltalk.addMethod(
+'_new_',
+smalltalk.method({
+selector: 'new:',
+fn: function (anInteger){
+var self=this;
+return smalltalk.send(self, "_new", []);
+return self;}
+}),
+smalltalk.Collection.klass);
+
 
 smalltalk.addClass('SequenceableCollection', smalltalk.Collection, [], 'Kernel-Collections');
 smalltalk.addMethod(
@@ -455,7 +472,12 @@ smalltalk.method({
 selector: 'copyFrom:to:',
 fn: function (anIndex, anotherIndex){
 var self=this;
-smalltalk.send(self, "_subclassResponsibility", []);
+var range=nil;
+var newCollection=nil;
+range=smalltalk.send(anIndex, "_to_", [anotherIndex]);
+newCollection=smalltalk.send(smalltalk.send(self, "_class", []), "_new_", [smalltalk.send(range, "_size", [])]);
+smalltalk.send(range, "_do_", [(function(each){return smalltalk.send(newCollection, "_at_put_", [each, smalltalk.send(self, "_at_", [each])]);})]);
+return newCollection;
 return self;}
 }),
 smalltalk.SequenceableCollection);
@@ -646,33 +668,67 @@ return self;}
 }),
 smalltalk.SequenceableCollection);
 
-
-
-smalltalk.addClass('String', smalltalk.SequenceableCollection, [], 'Kernel-Collections');
 smalltalk.addMethod(
 '__eq',
 smalltalk.method({
 selector: '=',
-fn: function (aString){
+fn: function (aCollection){
 var self=this;
-try{((($receiver = smalltalk.send(smalltalk.send(aString, "_class", []), "__eq", [smalltalk.send(self, "_class", [])])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})]));
-return String(self) == aString;
+try{((($receiver = smalltalk.send(smalltalk.send(smalltalk.send(self, "_class", []), "__eq", [smalltalk.send(aCollection, "_class", [])]), "_and_", [(function(){return smalltalk.send(smalltalk.send(self, "_size", []), "__eq", [smalltalk.send(aCollection, "_size", [])]);})])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})]));
+smalltalk.send(self, "_withIndexDo_", [(function(each, i){return ((($receiver = smalltalk.send(smalltalk.send(aCollection, "_at_", [i]), "__eq", [each])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})]));})]);
+(function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return true}})})();
 return self;
 } catch(e) {if(e.name === 'stReturn' && e.selector === '__eq'){return e.fn()} throw(e)}}
 }),
-smalltalk.String);
+smalltalk.SequenceableCollection);
 
 smalltalk.addMethod(
-'_size',
+'_shallowCopy',
 smalltalk.method({
-selector: 'size',
+selector: 'shallowCopy',
 fn: function (){
 var self=this;
-return self.length;
+var newCollection=nil;
+newCollection=smalltalk.send(smalltalk.send(self, "_class", []), "_new_", [smalltalk.send(self, "_size", [])]);
+smalltalk.send(self, "_withIndexDo_", [(function(each, index){return smalltalk.send(newCollection, "_at_put_", [index, each]);})]);
+return newCollection;
 return self;}
 }),
-smalltalk.String);
+smalltalk.SequenceableCollection);
+
+smalltalk.addMethod(
+'_deepCopy',
+smalltalk.method({
+selector: 'deepCopy',
+fn: function (){
+var self=this;
+var newCollection=nil;
+newCollection=smalltalk.send(smalltalk.send(self, "_class", []), "_new_", [smalltalk.send(self, "_size", [])]);
+smalltalk.send(self, "_withIndexDo_", [(function(each, index){return smalltalk.send(newCollection, "_at_put_", [index, smalltalk.send(each, "_deepCopy", [])]);})]);
+return newCollection;
+return self;}
+}),
+smalltalk.SequenceableCollection);
 
+smalltalk.addMethod(
+'_printString',
+smalltalk.method({
+selector: 'printString',
+fn: function (){
+var self=this;
+var str=nil;
+str=smalltalk.send("", "_writeStream", []);
+smalltalk.send(str, "_nextPutAll_", [smalltalk.send(smalltalk.send(self, "_printString", [], smalltalk.Collection), "__comma", [unescape("%20%28")])]);
+smalltalk.send(self, "_do_separatedBy_", [(function(each){return smalltalk.send(str, "_nextPutAll_", [smalltalk.send(each, "_printString", [])]);}), (function(){return smalltalk.send(str, "_nextPutAll_", [" "]);})]);
+smalltalk.send(str, "_nextPutAll_", [unescape("%29")]);
+return smalltalk.send(str, "_contents", []);
+return self;}
+}),
+smalltalk.SequenceableCollection);
+
+
+
+smalltalk.addClass('CharacterArray', smalltalk.SequenceableCollection, [], 'Kernel-Collections');
 smalltalk.addMethod(
 '_at_put_',
 smalltalk.method({
@@ -682,6 +738,154 @@ var self=this;
 smalltalk.send(self, "_errorReadOnly", []);
 return self;}
 }),
+smalltalk.CharacterArray);
+
+smalltalk.addMethod(
+'_add_',
+smalltalk.method({
+selector: 'add:',
+fn: function (anObject){
+var self=this;
+smalltalk.send(self, "_errorReadOnly", []);
+return self;}
+}),
+smalltalk.CharacterArray);
+
+smalltalk.addMethod(
+'__comma',
+smalltalk.method({
+selector: ',',
+fn: function (aString){
+var self=this;
+return smalltalk.send(smalltalk.send(self, "_asString", []), "__comma", [smalltalk.send(aString, "_asString", [])]);
+return self;}
+}),
+smalltalk.CharacterArray);
+
+smalltalk.addMethod(
+'_asString',
+smalltalk.method({
+selector: 'asString',
+fn: function (){
+var self=this;
+return smalltalk.send(self, "_subclassResponsibility", []);
+return self;}
+}),
+smalltalk.CharacterArray);
+
+smalltalk.addMethod(
+'_asNumber',
+smalltalk.method({
+selector: 'asNumber',
+fn: function (){
+var self=this;
+return smalltalk.send(smalltalk.send(self, "_asString", []), "_asNumber", []);
+return self;}
+}),
+smalltalk.CharacterArray);
+
+smalltalk.addMethod(
+'_errorReadOnly',
+smalltalk.method({
+selector: 'errorReadOnly',
+fn: function (){
+var self=this;
+smalltalk.send(self, "_error_", [unescape("Object%20is%20read-only")]);
+return self;}
+}),
+smalltalk.CharacterArray);
+
+smalltalk.addMethod(
+'_printString',
+smalltalk.method({
+selector: 'printString',
+fn: function (){
+var self=this;
+return smalltalk.send(smalltalk.send(self, "_asString", []), "_printString", []);
+return self;}
+}),
+smalltalk.CharacterArray);
+
+smalltalk.addMethod(
+'_remove_',
+smalltalk.method({
+selector: 'remove:',
+fn: function (anObject){
+var self=this;
+smalltalk.send(self, "_errorReadOnly", []);
+return self;}
+}),
+smalltalk.CharacterArray);
+
+smalltalk.addMethod(
+'_asUppercase',
+smalltalk.method({
+selector: 'asUppercase',
+fn: function (){
+var self=this;
+return smalltalk.send(smalltalk.send(self, "_class", []), "_fromString_", [smalltalk.send(smalltalk.send(self, "_asString", []), "_asUppercase", [])]);
+return self;}
+}),
+smalltalk.CharacterArray);
+
+smalltalk.addMethod(
+'_asSymbol',
+smalltalk.method({
+selector: 'asSymbol',
+fn: function (){
+var self=this;
+return smalltalk.send(self, "_subclassResponsibility", []);
+return self;}
+}),
+smalltalk.CharacterArray);
+
+smalltalk.addMethod(
+'_asLowercase',
+smalltalk.method({
+selector: 'asLowercase',
+fn: function (){
+var self=this;
+return smalltalk.send(smalltalk.send(self, "_class", []), "_fromString_", [smalltalk.send(smalltalk.send(self, "_asString", []), "_asLowercase", [])]);
+return self;}
+}),
+smalltalk.CharacterArray);
+
+
+smalltalk.addMethod(
+'_fromString_',
+smalltalk.method({
+selector: 'fromString:',
+fn: function (aString){
+var self=this;
+smalltalk.send(self, "_subclassResponsibility", []);
+return self;}
+}),
+smalltalk.CharacterArray.klass);
+
+
+smalltalk.addClass('String', smalltalk.CharacterArray, [], 'Kernel-Collections');
+smalltalk.addMethod(
+'__eq',
+smalltalk.method({
+selector: '=',
+fn: function (aString){
+var self=this;
+try{((($receiver = smalltalk.send(smalltalk.send(aString, "_class", []), "__eq", [smalltalk.send(self, "_class", [])])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})]));
+return String(self) === String(aString);
+return self;
+} catch(e) {if(e.name === 'stReturn' && e.selector === '__eq'){return e.fn()} throw(e)}}
+}),
+smalltalk.String);
+
+smalltalk.addMethod(
+'_size',
+smalltalk.method({
+selector: 'size',
+fn: function (){
+var self=this;
+return self.length;
+return self;}
+}),
 smalltalk.String);
 
 smalltalk.addMethod(
@@ -717,17 +921,6 @@ return self;}
 }),
 smalltalk.String);
 
-smalltalk.addMethod(
-'_add_',
-smalltalk.method({
-selector: 'add:',
-fn: function (anObject){
-var self=this;
-smalltalk.send(self, "_errorReadOnly", []);
-return self;}
-}),
-smalltalk.String);
-
 smalltalk.addMethod(
 '__comma',
 smalltalk.method({
@@ -877,17 +1070,6 @@ return self;}
 }),
 smalltalk.String);
 
-smalltalk.addMethod(
-'_errorReadOnly',
-smalltalk.method({
-selector: 'errorReadOnly',
-fn: function (){
-var self=this;
-smalltalk.send(self, "_error_", [unescape("Object%20is%20read-only")]);
-return self;}
-}),
-smalltalk.String);
-
 smalltalk.addMethod(
 '_printString',
 smalltalk.method({
@@ -965,17 +1147,6 @@ return self;}
 }),
 smalltalk.String);
 
-smalltalk.addMethod(
-'_remove_',
-smalltalk.method({
-selector: 'remove:',
-fn: function (anObject){
-var self=this;
-smalltalk.send(self, "_errorReadOnly", []);
-return self;}
-}),
-smalltalk.String);
-
 smalltalk.addMethod(
 '_trimLeft_',
 smalltalk.method({
@@ -1172,19 +1343,6 @@ return self;}
 }),
 smalltalk.String);
 
-smalltalk.addMethod(
-'__eq_eq',
-smalltalk.method({
-selector: '==',
-fn: function (aString){
-var self=this;
-try{((($receiver = smalltalk.send(smalltalk.send(aString, "_class", []), "__eq", [smalltalk.send(self, "_class", [])])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (function(){throw({name: 'stReturn', selector: '__eq_eq', fn: function(){return false}})})();})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (function(){throw({name: 'stReturn', selector: '__eq_eq', fn: function(){return false}})})();})]));
-return String(self) === String(aString);
-return self;
-} catch(e) {if(e.name === 'stReturn' && e.selector === '__eq_eq'){return e.fn()} throw(e)}}
-}),
-smalltalk.String);
-
 smalltalk.addMethod(
 '_asJavaScriptSelector',
 smalltalk.method({
@@ -1207,6 +1365,17 @@ return self;}
 }),
 smalltalk.String);
 
+smalltalk.addMethod(
+'_asSymbol',
+smalltalk.method({
+selector: 'asSymbol',
+fn: function (){
+var self=this;
+return smalltalk.send((smalltalk.Symbol || Symbol), "_lookup_", [self]);
+return self;}
+}),
+smalltalk.String);
+
 
 smalltalk.addMethod(
 '_streamClass',
@@ -1311,96 +1480,255 @@ return self;}
 smalltalk.String.klass);
 
 
-smalltalk.addClass('Array', smalltalk.SequenceableCollection, [], 'Kernel-Collections');
+smalltalk.addClass('Symbol', smalltalk.CharacterArray, [], 'Kernel-Collections');
+smalltalk.addMethod(
+'_at_ifAbsent_',
+smalltalk.method({
+selector: 'at:ifAbsent:',
+fn: function (anIndex, aBlock){
+var self=this;
+return smalltalk.send(smalltalk.send(self, "_asString", []), "_at_ifAbsent_", [anIndex, aBlock]);
+return self;}
+}),
+smalltalk.Symbol);
+
+smalltalk.addMethod(
+'_asString',
+smalltalk.method({
+selector: 'asString',
+fn: function (){
+var self=this;
+return self.value;
+return self;}
+}),
+smalltalk.Symbol);
+
+smalltalk.addMethod(
+'_printString',
+smalltalk.method({
+selector: 'printString',
+fn: function (){
+var self=this;
+return smalltalk.send(unescape("%23"), "__comma", [smalltalk.send(self, "_asString", [])]);
+return self;}
+}),
+smalltalk.Symbol);
+
 smalltalk.addMethod(
 '_size',
 smalltalk.method({
 selector: 'size',
 fn: function (){
 var self=this;
-return self.length;
+return smalltalk.send(smalltalk.send(self, "_asString", []), "_size", []);
 return self;}
 }),
-smalltalk.Array);
+smalltalk.Symbol);
 
 smalltalk.addMethod(
-'_at_put_',
+'_asSymbol',
 smalltalk.method({
-selector: 'at:put:',
-fn: function (anIndex, anObject){
+selector: 'asSymbol',
+fn: function (){
 var self=this;
-return self[anIndex - 1] = anObject;
+return self;
 return self;}
 }),
-smalltalk.Array);
+smalltalk.Symbol);
 
 smalltalk.addMethod(
-'_at_ifAbsent_',
+'_copyFrom_to_',
 smalltalk.method({
-selector: 'at:ifAbsent:',
-fn: function (anIndex, aBlock){
+selector: 'copyFrom:to:',
+fn: function (anIndex, anotherIndex){
 var self=this;
+return smalltalk.send(smalltalk.send(self, "_class", []), "_fromString_", [smalltalk.send(smalltalk.send(self, "_asString", []), "_copyFrom_to_", [anIndex, anotherIndex])]);
+return self;}
+}),
+smalltalk.Symbol);
 
-	    var value = self[anIndex - 1];
-	    if(value === undefined) {
-		return aBlock();
-	    } else {
-		return value;
-	    }
-	;
+smalltalk.addMethod(
+'_deepCopy',
+smalltalk.method({
+selector: 'deepCopy',
+fn: function (){
+var self=this;
+return self;
 return self;}
 }),
-smalltalk.Array);
+smalltalk.Symbol);
 
 smalltalk.addMethod(
-'_add_',
+'_shadowCopy',
 smalltalk.method({
-selector: 'add:',
-fn: function (anObject){
+selector: 'shadowCopy',
+fn: function (){
 var self=this;
-self.push(anObject); return anObject;;
+return self;
 return self;}
 }),
-smalltalk.Array);
+smalltalk.Symbol);
 
 smalltalk.addMethod(
-'_shallowCopy',
+'__lt',
 smalltalk.method({
-selector: 'shallowCopy',
+selector: '<',
+fn: function (aSymbol){
+var self=this;
+return ((($receiver = smalltalk.send(self, "_asString", [])).klass === smalltalk.Number) ? $receiver <smalltalk.send(aSymbol, "_asString", []) : smalltalk.send($receiver, "__lt", [smalltalk.send(aSymbol, "_asString", [])]));
+return self;}
+}),
+smalltalk.Symbol);
+
+smalltalk.addMethod(
+'__lt_eq',
+smalltalk.method({
+selector: '<=',
+fn: function (aSymbol){
+var self=this;
+return ((($receiver = smalltalk.send(self, "_asString", [])).klass === smalltalk.Number) ? $receiver <=smalltalk.send(aSymbol, "_asString", []) : smalltalk.send($receiver, "__lt_eq", [smalltalk.send(aSymbol, "_asString", [])]));
+return self;}
+}),
+smalltalk.Symbol);
+
+smalltalk.addMethod(
+'__gt_eq',
+smalltalk.method({
+selector: '>=',
+fn: function (aSymbol){
+var self=this;
+return ((($receiver = smalltalk.send(self, "_asString", [])).klass === smalltalk.Number) ? $receiver >=smalltalk.send(aSymbol, "_asString", []) : smalltalk.send($receiver, "__gt_eq", [smalltalk.send(aSymbol, "_asString", [])]));
+return self;}
+}),
+smalltalk.Symbol);
+
+smalltalk.addMethod(
+'__eq',
+smalltalk.method({
+selector: '=',
+fn: function (aSymbol){
+var self=this;
+return smalltalk.send(smalltalk.send(self, "_asString", []), "__eq", [smalltalk.send(aSymbol, "_asString", [])]);
+return self;}
+}),
+smalltalk.Symbol);
+
+smalltalk.addMethod(
+'_isSymbol',
+smalltalk.method({
+selector: 'isSymbol',
 fn: function (){
 var self=this;
-var newCollection=nil;
-newCollection=smalltalk.send(smalltalk.send(self, "_class", []), "_new", []);
-smalltalk.send(self, "_do_", [(function(each){return smalltalk.send(newCollection, "_add_", [each]);})]);
-return newCollection;
+return true;
+return self;}
+}),
+smalltalk.Symbol);
+
+smalltalk.addMethod(
+'_asJavascript',
+smalltalk.method({
+selector: 'asJavascript',
+fn: function (){
+var self=this;
+return smalltalk.send(smalltalk.send(unescape("smalltalk.symbolFor%28%22"), "__comma", [smalltalk.send(self, "_asString", [])]), "__comma", [unescape("%22%29")]);
+return self;}
+}),
+smalltalk.Symbol);
+
+smalltalk.addMethod(
+'__gt',
+smalltalk.method({
+selector: '>',
+fn: function (aSymbol){
+var self=this;
+return ((($receiver = smalltalk.send(self, "_asString", [])).klass === smalltalk.Number) ? $receiver >smalltalk.send(aSymbol, "_asString", []) : smalltalk.send($receiver, "__gt", [smalltalk.send(aSymbol, "_asString", [])]));
+return self;}
+}),
+smalltalk.Symbol);
+
+
+smalltalk.addMethod(
+'_lookup_',
+smalltalk.method({
+selector: 'lookup:',
+fn: function (aString){
+var self=this;
+return smalltalk.symbolFor(aString);;
+return self;}
+}),
+smalltalk.Symbol.klass);
+
+smalltalk.addMethod(
+'_basicNew',
+smalltalk.method({
+selector: 'basicNew',
+fn: function (){
+var self=this;
+smalltalk.send(self, "_shouldNotImplement", []);
+return self;}
+}),
+smalltalk.Symbol.klass);
+
+smalltalk.addMethod(
+'_fromString_',
+smalltalk.method({
+selector: 'fromString:',
+fn: function (aString){
+var self=this;
+return smalltalk.send(self, "_lookup_", [aString]);
+return self;}
+}),
+smalltalk.Symbol.klass);
+
+
+smalltalk.addClass('Array', smalltalk.SequenceableCollection, [], 'Kernel-Collections');
+smalltalk.addMethod(
+'_size',
+smalltalk.method({
+selector: 'size',
+fn: function (){
+var self=this;
+return self.length;
+return self;}
+}),
+smalltalk.Array);
+
+smalltalk.addMethod(
+'_at_put_',
+smalltalk.method({
+selector: 'at:put:',
+fn: function (anIndex, anObject){
+var self=this;
+return self[anIndex - 1] = anObject;
 return self;}
 }),
 smalltalk.Array);
 
 smalltalk.addMethod(
-'_deepCopy',
+'_at_ifAbsent_',
 smalltalk.method({
-selector: 'deepCopy',
-fn: function (){
+selector: 'at:ifAbsent:',
+fn: function (anIndex, aBlock){
 var self=this;
-var newCollection=nil;
-newCollection=smalltalk.send(smalltalk.send(self, "_class", []), "_new", []);
-smalltalk.send(self, "_do_", [(function(each){return smalltalk.send(newCollection, "_add_", [smalltalk.send(each, "_deepCopy", [])]);})]);
-return newCollection;
+
+	    var value = self[anIndex - 1];
+	    if(value === undefined) {
+		return aBlock();
+	    } else {
+		return value;
+	    }
+	;
 return self;}
 }),
 smalltalk.Array);
 
 smalltalk.addMethod(
-'_copyFrom_to_',
+'_add_',
 smalltalk.method({
-selector: 'copyFrom:to:',
-fn: function (anIndex, anotherIndex){
+selector: 'add:',
+fn: function (anObject){
 var self=this;
-var array=nil;
-array=smalltalk.send(smalltalk.send(self, "_class", []), "_new", []);
-smalltalk.send(anIndex, "_to_do_", [anotherIndex, (function(each){return smalltalk.send(array, "_add_", [smalltalk.send(self, "_at_", [each])]);})]);
-return array;
+self.push(anObject); return anObject;;
 return self;}
 }),
 smalltalk.Array);
@@ -1505,46 +1833,74 @@ return self;}
 smalltalk.Array);
 
 smalltalk.addMethod(
-'_printString',
+'_reversed',
 smalltalk.method({
-selector: 'printString',
+selector: 'reversed',
 fn: function (){
 var self=this;
-var str=nil;
-str=smalltalk.send("", "_writeStream", []);
-smalltalk.send(str, "_nextPutAll_", [smalltalk.send(smalltalk.send(self, "_printString", [], smalltalk.SequenceableCollection), "__comma", [unescape("%20%28")])]);
-smalltalk.send(self, "_do_separatedBy_", [(function(each){return smalltalk.send(str, "_nextPutAll_", [smalltalk.send(each, "_printString", [])]);}), (function(){return smalltalk.send(str, "_nextPutAll_", [" "]);})]);
-smalltalk.send(str, "_nextPutAll_", [unescape("%29")]);
-return smalltalk.send(str, "_contents", []);
+return self._copy().reverse();
 return self;}
 }),
 smalltalk.Array);
 
+
 smalltalk.addMethod(
-'_reversed',
+'_new_',
 smalltalk.method({
-selector: 'reversed',
-fn: function (){
+selector: 'new:',
+fn: function (anInteger){
 var self=this;
-return self._copy().reverse();
+return new Array(anInteger);
 return self;}
 }),
-smalltalk.Array);
+smalltalk.Array.klass);
 
 smalltalk.addMethod(
-'__eq',
+'_with_',
 smalltalk.method({
-selector: '=',
-fn: function (aCollection){
+selector: 'with:',
+fn: function (anObject){
 var self=this;
-try{((($receiver = smalltalk.send(smalltalk.send(smalltalk.send(self, "_class", []), "__eq", [smalltalk.send(aCollection, "_class", [])]), "_and_", [(function(){return smalltalk.send(smalltalk.send(self, "_size", []), "__eq", [smalltalk.send(aCollection, "_size", [])]);})])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})]));
-smalltalk.send(self, "_withIndexDo_", [(function(each, i){return ((($receiver = smalltalk.send(smalltalk.send(aCollection, "_at_", [i]), "__eq", [each])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})]));})]);
-(function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return true}})})();
-return self;
-} catch(e) {if(e.name === 'stReturn' && e.selector === '__eq'){return e.fn()} throw(e)}}
+return (function($rec){smalltalk.send($rec, "_at_put_", [(1), anObject]);return smalltalk.send($rec, "_yourself", []);})(smalltalk.send(self, "_new_", [(1)]));
+return self;}
 }),
-smalltalk.Array);
+smalltalk.Array.klass);
+
+smalltalk.addMethod(
+'_with_with_',
+smalltalk.method({
+selector: 'with:with:',
+fn: function (anObject, anObject2){
+var self=this;
+return (function($rec){smalltalk.send($rec, "_at_put_", [(1), anObject]);smalltalk.send($rec, "_at_put_", [(2), anObject2]);return smalltalk.send($rec, "_yourself", []);})(smalltalk.send(self, "_new_", [(2)]));
+return self;}
+}),
+smalltalk.Array.klass);
+
+smalltalk.addMethod(
+'_with_with_with_',
+smalltalk.method({
+selector: 'with:with:with:',
+fn: function (anObject, anObject2, anObject3){
+var self=this;
+return (function($rec){smalltalk.send($rec, "_at_put_", [(1), anObject]);smalltalk.send($rec, "_at_put_", [(2), anObject2]);smalltalk.send($rec, "_at_put_", [(3), anObject3]);return smalltalk.send($rec, "_yourself", []);})(smalltalk.send(self, "_new_", [(3)]));
+return self;}
+}),
+smalltalk.Array.klass);
 
+smalltalk.addMethod(
+'_withAll_',
+smalltalk.method({
+selector: 'withAll:',
+fn: function (aCollection){
+var self=this;
+var instance=nil;
+instance=smalltalk.send(self, "_new_", [smalltalk.send(aCollection, "_size", [])]);
+smalltalk.send(aCollection, "_withIndexDo_", [(function(index, each){return smalltalk.send(instance, "_at_put_", [index, each]);})]);
+return instance;
+return self;}
+}),
+smalltalk.Array.klass);
 
 
 smalltalk.addClass('RegularExpression', smalltalk.Object, [], 'Kernel-Collections');
@@ -2678,3 +3034,214 @@ smalltalk.Dictionary);
 
 
 
+smalltalk.addClass('OrderedCollection', smalltalk.SequenceableCollection, ['elements'], 'Kernel-Collections');
+smalltalk.addMethod(
+'_size',
+smalltalk.method({
+selector: 'size',
+fn: function (){
+var self=this;
+return smalltalk.send(self['@elements'], "_size", []);
+return self;}
+}),
+smalltalk.OrderedCollection);
+
+smalltalk.addMethod(
+'_at_put_',
+smalltalk.method({
+selector: 'at:put:',
+fn: function (anIndex, anObject){
+var self=this;
+return self['@elements'][anIndex - 1] = anObject;
+return self;}
+}),
+smalltalk.OrderedCollection);
+
+smalltalk.addMethod(
+'_at_ifAbsent_',
+smalltalk.method({
+selector: 'at:ifAbsent:',
+fn: function (anIndex, aBlock){
+var self=this;
+return smalltalk.send(self['@elements'], "_at_ifAbsent_", [anIndex, aBlock]);
+return self;}
+}),
+smalltalk.OrderedCollection);
+
+smalltalk.addMethod(
+'_add_',
+smalltalk.method({
+selector: 'add:',
+fn: function (anObject){
+var self=this;
+self['@elements'].push(anObject); return anObject;;
+return self;}
+}),
+smalltalk.OrderedCollection);
+
+smalltalk.addMethod(
+'_join_',
+smalltalk.method({
+selector: 'join:',
+fn: function (aString){
+var self=this;
+return smalltalk.send(self['@elements'], "_join_", [aString]);
+return self;}
+}),
+smalltalk.OrderedCollection);
+
+smalltalk.addMethod(
+'_sort',
+smalltalk.method({
+selector: 'sort',
+fn: function (){
+var self=this;
+smalltalk.send(self['@elements'], "_sort", []);
+return self;
+return self;}
+}),
+smalltalk.OrderedCollection);
+
+smalltalk.addMethod(
+'_sort_',
+smalltalk.method({
+selector: 'sort:',
+fn: function (aBlock){
+var self=this;
+smalltalk.send(self['@elements'], "_sort_", [aBlock]);
+return self;
+return self;}
+}),
+smalltalk.OrderedCollection);
+
+smalltalk.addMethod(
+'_remove_',
+smalltalk.method({
+selector: 'remove:',
+fn: function (anObject){
+var self=this;
+
+		for(var i=0;i<self['@elements'].length;i++) {
+			if(self['@elements'][i] == anObject) {
+				self['@elements'].splice(i,1);
+				break;
+			}
+		}
+	;
+return self;}
+}),
+smalltalk.OrderedCollection);
+
+smalltalk.addMethod(
+'_sorted',
+smalltalk.method({
+selector: 'sorted',
+fn: function (){
+var self=this;
+return smalltalk.send(smalltalk.send(self, "_copy", []), "_sort", []);
+return self;}
+}),
+smalltalk.OrderedCollection);
+
+smalltalk.addMethod(
+'_sorted_',
+smalltalk.method({
+selector: 'sorted:',
+fn: function (aBlock){
+var self=this;
+return smalltalk.send(smalltalk.send(self, "_copy", []), "_sort_", [aBlock]);
+return self;}
+}),
+smalltalk.OrderedCollection);
+
+smalltalk.addMethod(
+'_removeFrom_to_',
+smalltalk.method({
+selector: 'removeFrom:to:',
+fn: function (aNumber, anotherNumber){
+var self=this;
+self['@elements'].splice(aNumber - 1,anotherNumber - 1);
+return self;}
+}),
+smalltalk.OrderedCollection);
+
+smalltalk.addMethod(
+'_reversed',
+smalltalk.method({
+selector: 'reversed',
+fn: function (){
+var self=this;
+return smalltalk.send(smalltalk.send(smalltalk.send(self, "_asArray", []), "_reversed", []), "_asOrderedCollection", []);
+return self;}
+}),
+smalltalk.OrderedCollection);
+
+smalltalk.addMethod(
+'_initialize',
+smalltalk.method({
+selector: 'initialize',
+fn: function (){
+var self=this;
+smalltalk.send(self, "_initialize", [], smalltalk.SequenceableCollection);
+self['@elements']=[];
+return self;}
+}),
+smalltalk.OrderedCollection);
+
+smalltalk.addMethod(
+'_withIndexDo_',
+smalltalk.method({
+selector: 'withIndexDo:',
+fn: function (aBlock){
+var self=this;
+smalltalk.send(self['@elements'], "_withIndexDo_", [aBlock]);
+return self;}
+}),
+smalltalk.OrderedCollection);
+
+smalltalk.addMethod(
+'_detect_ifNone_',
+smalltalk.method({
+selector: 'detect:ifNone:',
+fn: function (aBlock, anotherBlock){
+var self=this;
+return smalltalk.send(self['@elements'], "_detect_ifNone_", [aBlock, anotherBlock]);
+return self;}
+}),
+smalltalk.OrderedCollection);
+
+smalltalk.addMethod(
+'_do_',
+smalltalk.method({
+selector: 'do:',
+fn: function (aBlock){
+var self=this;
+smalltalk.send(self['@elements'], "_do_", [aBlock]);
+return self;}
+}),
+smalltalk.OrderedCollection);
+
+smalltalk.addMethod(
+'_asOrderedCollection',
+smalltalk.method({
+selector: 'asOrderedCollection',
+fn: function (){
+var self=this;
+return self;
+return self;}
+}),
+smalltalk.OrderedCollection);
+
+smalltalk.addMethod(
+'_asArray',
+smalltalk.method({
+selector: 'asArray',
+fn: function (){
+var self=this;
+return smalltalk.send(self['@elements'], "_copy", []);
+return self;}
+}),
+smalltalk.OrderedCollection);
+
+
+

Dosya farkı çok büyük olduğundan ihmal edildi
+ 519 - 278
js/Kernel-Collections.js


+ 35 - 28
js/Kernel-Objects.deploy.js

@@ -520,7 +520,7 @@ smalltalk.method({
 selector: '==',
 fn: function (anObject){
 var self=this;
-return self === anObject;
+return smalltalk.send(smalltalk.send(self, "_identityHash", []), "__eq", [smalltalk.send(anObject, "_identityHash", [])]);
 return self;}
 }),
 smalltalk.Object);
@@ -580,6 +580,28 @@ return self;}
 }),
 smalltalk.Object);
 
+smalltalk.addMethod(
+'_identityHash',
+smalltalk.method({
+selector: 'identityHash',
+fn: function (){
+var self=this;
+return self.identityHash || (self.identityHash = smalltalk.nextId());;
+return self;}
+}),
+smalltalk.Object);
+
+smalltalk.addMethod(
+'_isSymbol',
+smalltalk.method({
+selector: 'isSymbol',
+fn: function (){
+var self=this;
+return false;
+return self;}
+}),
+smalltalk.Object);
+
 
 smalltalk.addMethod(
 '_initialize',
@@ -1104,7 +1126,7 @@ smalltalk.method({
 selector: '=',
 fn: function (aNumber){
 var self=this;
-try{((($receiver = smalltalk.send(smalltalk.send(aNumber, "_class", []), "__eq", [smalltalk.send(self, "_class", [])])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})]));
+try{((($receiver = smalltalk.send(aNumber, "_isNumber", [])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})]));
 return Number(self) == aNumber;
 return self;
 } catch(e) {if(e.name === 'stReturn' && e.selector === '__eq'){return e.fn()} throw(e)}}
@@ -1425,19 +1447,6 @@ return self;}
 }),
 smalltalk.Number);
 
-smalltalk.addMethod(
-'__eq_eq',
-smalltalk.method({
-selector: '==',
-fn: function (aNumber){
-var self=this;
-try{((($receiver = smalltalk.send(smalltalk.send(aNumber, "_class", []), "__eq", [smalltalk.send(self, "_class", [])])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (function(){throw({name: 'stReturn', selector: '__eq_eq', fn: function(){return false}})})();})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (function(){throw({name: 'stReturn', selector: '__eq_eq', fn: function(){return false}})})();})]));
-return Number(self) === Number(aNumber);
-return self;
-} catch(e) {if(e.name === 'stReturn' && e.selector === '__eq_eq'){return e.fn()} throw(e)}}
-}),
-smalltalk.Number);
-
 smalltalk.addMethod(
 '_printShowingDecimalPlaces_',
 smalltalk.method({
@@ -1548,6 +1557,17 @@ return self;}
 }),
 smalltalk.Number);
 
+smalltalk.addMethod(
+'_identityHash',
+smalltalk.method({
+selector: 'identityHash',
+fn: function (){
+var self=this;
+return smalltalk.send(smalltalk.send(self, "_asString", []), "__comma", ["n"]);
+return self;}
+}),
+smalltalk.Number);
+
 
 smalltalk.addMethod(
 '_pi',
@@ -1725,19 +1745,6 @@ return self;}
 }),
 smalltalk.Boolean);
 
-smalltalk.addMethod(
-'__eq_eq',
-smalltalk.method({
-selector: '==',
-fn: function (aBoolean){
-var self=this;
-try{((($receiver = smalltalk.send(smalltalk.send(aBoolean, "_class", []), "__eq", [smalltalk.send(self, "_class", [])])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (function(){throw({name: 'stReturn', selector: '__eq_eq', fn: function(){return false}})})();})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (function(){throw({name: 'stReturn', selector: '__eq_eq', fn: function(){return false}})})();})]));
-return Boolean(self == true) === Boolean(aBoolean == true);
-return self;
-} catch(e) {if(e.name === 'stReturn' && e.selector === '__eq_eq'){return e.fn()} throw(e)}}
-}),
-smalltalk.Boolean);
-
 
 
 smalltalk.addClass('Date', smalltalk.Object, [], 'Kernel-Objects');

+ 54 - 42
js/Kernel-Objects.js

@@ -746,11 +746,11 @@ selector: unescape('%3D%3D'),
 category: 'comparing',
 fn: function (anObject){
 var self=this;
-return self === anObject;
+return smalltalk.send(smalltalk.send(self, "_identityHash", []), "__eq", [smalltalk.send(anObject, "_identityHash", [])]);
 return self;},
 args: ["anObject"],
-source: unescape('%3D%3D%20anObject%0A%09%3Creturn%20self%20%3D%3D%3D%20anObject%3E'),
-messageSends: [],
+source: unescape('%3D%3D%20anObject%0A%09%5Eself%20identityHash%20%3D%20anObject%20identityHash'),
+messageSends: [unescape("%3D"), "identityHash"],
 referencedClasses: []
 }),
 smalltalk.Object);
@@ -835,6 +835,38 @@ referencedClasses: ["JSON"]
 }),
 smalltalk.Object);
 
+smalltalk.addMethod(
+unescape('_identityHash'),
+smalltalk.method({
+selector: unescape('identityHash'),
+category: 'accessing',
+fn: function (){
+var self=this;
+return self.identityHash || (self.identityHash = smalltalk.nextId());;
+return self;},
+args: [],
+source: unescape('identityHash%0A%09%3Creturn%20self.identityHash%20%7C%7C%20%28self.identityHash%20%3D%20smalltalk.nextId%28%29%29%3B%3E'),
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.Object);
+
+smalltalk.addMethod(
+unescape('_isSymbol'),
+smalltalk.method({
+selector: unescape('isSymbol'),
+category: 'testing',
+fn: function (){
+var self=this;
+return false;
+return self;},
+args: [],
+source: unescape('isSymbol%0A%09%5Efalse'),
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.Object);
+
 
 smalltalk.addMethod(
 unescape('_initialize'),
@@ -1576,13 +1608,13 @@ selector: unescape('%3D'),
 category: 'comparing',
 fn: function (aNumber){
 var self=this;
-try{((($receiver = smalltalk.send(smalltalk.send(aNumber, "_class", []), "__eq", [smalltalk.send(self, "_class", [])])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})]));
+try{((($receiver = smalltalk.send(aNumber, "_isNumber", [])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return false}})})();})]));
 return Number(self) == aNumber;
 return self;
 } catch(e) {if(e.name === 'stReturn' && e.selector === '__eq'){return e.fn()} throw(e)}},
 args: ["aNumber"],
-source: unescape('%3D%20aNumber%0A%09aNumber%20class%20%3D%20self%20class%20ifFalse%3A%20%5B%5Efalse%5D.%20%0A%09%3Creturn%20Number%28self%29%20%3D%3D%20aNumber%3E'),
-messageSends: ["ifFalse:", unescape("%3D"), "class"],
+source: unescape('%3D%20aNumber%0A%09aNumber%20isNumber%20ifFalse%3A%20%5B%5Efalse%5D.%20%0A%09%3Creturn%20Number%28self%29%20%3D%3D%20aNumber%3E'),
+messageSends: ["ifFalse:", "isNumber"],
 referencedClasses: []
 }),
 smalltalk.Number);
@@ -2036,24 +2068,6 @@ referencedClasses: []
 }),
 smalltalk.Number);
 
-smalltalk.addMethod(
-unescape('__eq_eq'),
-smalltalk.method({
-selector: unescape('%3D%3D'),
-category: 'comparing',
-fn: function (aNumber){
-var self=this;
-try{((($receiver = smalltalk.send(smalltalk.send(aNumber, "_class", []), "__eq", [smalltalk.send(self, "_class", [])])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (function(){throw({name: 'stReturn', selector: '__eq_eq', fn: function(){return false}})})();})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (function(){throw({name: 'stReturn', selector: '__eq_eq', fn: function(){return false}})})();})]));
-return Number(self) === Number(aNumber);
-return self;
-} catch(e) {if(e.name === 'stReturn' && e.selector === '__eq_eq'){return e.fn()} throw(e)}},
-args: ["aNumber"],
-source: unescape('%3D%3D%20aNumber%0A%09aNumber%20class%20%3D%20self%20class%20ifFalse%3A%20%5B%5Efalse%5D.%20%0A%09%3Creturn%20Number%28self%29%20%3D%3D%3D%20Number%28aNumber%29%3E'),
-messageSends: ["ifFalse:", unescape("%3D"), "class"],
-referencedClasses: []
-}),
-smalltalk.Number);
-
 smalltalk.addMethod(
 unescape('_printShowingDecimalPlaces_'),
 smalltalk.method({
@@ -2209,6 +2223,22 @@ referencedClasses: []
 }),
 smalltalk.Number);
 
+smalltalk.addMethod(
+unescape('_identityHash'),
+smalltalk.method({
+selector: unescape('identityHash'),
+category: 'accessing',
+fn: function (){
+var self=this;
+return smalltalk.send(smalltalk.send(self, "_asString", []), "__comma", ["n"]);
+return self;},
+args: [],
+source: unescape('identityHash%0A%09%5Eself%20asString%2C%20%27n%27'),
+messageSends: [unescape("%2C"), "asString"],
+referencedClasses: []
+}),
+smalltalk.Number);
+
 
 smalltalk.addMethod(
 unescape('_pi'),
@@ -2456,24 +2486,6 @@ referencedClasses: []
 }),
 smalltalk.Boolean);
 
-smalltalk.addMethod(
-unescape('__eq_eq'),
-smalltalk.method({
-selector: unescape('%3D%3D'),
-category: 'comparing',
-fn: function (aBoolean){
-var self=this;
-try{((($receiver = smalltalk.send(smalltalk.send(aBoolean, "_class", []), "__eq", [smalltalk.send(self, "_class", [])])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return (function(){throw({name: 'stReturn', selector: '__eq_eq', fn: function(){return false}})})();})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return (function(){throw({name: 'stReturn', selector: '__eq_eq', fn: function(){return false}})})();})]));
-return Boolean(self == true) === Boolean(aBoolean == true);
-return self;
-} catch(e) {if(e.name === 'stReturn' && e.selector === '__eq_eq'){return e.fn()} throw(e)}},
-args: ["aBoolean"],
-source: unescape('%3D%3D%20aBoolean%0A%09aBoolean%20class%20%3D%20self%20class%20ifFalse%3A%20%5B%5Efalse%5D.%0A%09%3Creturn%20Boolean%28self%20%3D%3D%20true%29%20%3D%3D%3D%20Boolean%28aBoolean%20%3D%3D%20true%29%3E'),
-messageSends: ["ifFalse:", unescape("%3D"), "class"],
-referencedClasses: []
-}),
-smalltalk.Boolean);
-
 
 
 smalltalk.addClass('Date', smalltalk.Object, [], 'Kernel-Objects');

+ 0 - 15
js/Kernel-Tests.deploy.js

@@ -269,21 +269,6 @@ return self;}
 }),
 smalltalk.BooleanTest);
 
-smalltalk.addMethod(
-'_testIdentity',
-smalltalk.method({
-selector: 'testIdentity',
-fn: function (){
-var self=this;
-smalltalk.send(self, "_assert_", [smalltalk.send(true, "__eq_eq", [true])]);
-smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(true, "_yourself", []), "__eq_eq", [true])]);
-smalltalk.send(self, "_assert_", [smalltalk.send(true, "__eq_eq", [smalltalk.send(true, "_yourself", [])])]);
-smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(true, "_yourself", []), "__eq_eq", [smalltalk.send(true, "_yourself", [])])]);
-smalltalk.send(self, "_deny_", [smalltalk.send(true, "__eq_eq", [false])]);
-return self;}
-}),
-smalltalk.BooleanTest);
-
 
 
 smalltalk.addClass('NumberTest', smalltalk.TestCase, [], 'Kernel-Tests');

+ 0 - 20
js/Kernel-Tests.js

@@ -359,26 +359,6 @@ referencedClasses: []
 }),
 smalltalk.BooleanTest);
 
-smalltalk.addMethod(
-unescape('_testIdentity'),
-smalltalk.method({
-selector: unescape('testIdentity'),
-category: 'tests',
-fn: function (){
-var self=this;
-smalltalk.send(self, "_assert_", [smalltalk.send(true, "__eq_eq", [true])]);
-smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(true, "_yourself", []), "__eq_eq", [true])]);
-smalltalk.send(self, "_assert_", [smalltalk.send(true, "__eq_eq", [smalltalk.send(true, "_yourself", [])])]);
-smalltalk.send(self, "_assert_", [smalltalk.send(smalltalk.send(true, "_yourself", []), "__eq_eq", [smalltalk.send(true, "_yourself", [])])]);
-smalltalk.send(self, "_deny_", [smalltalk.send(true, "__eq_eq", [false])]);
-return self;},
-args: [],
-source: unescape('testIdentity%0A%09self%20assert%3A%20true%20%3D%3D%20true.%0A%09self%20assert%3A%20true%20yourself%20%3D%3D%20true.%0A%09self%20assert%3A%20true%20%3D%3D%20true%20yourself.%0A%09self%20assert%3A%20true%20yourself%20%3D%3D%20true%20yourself.%0A%0A%09self%20deny%3A%20true%20%3D%3D%20false'),
-messageSends: ["assert:", unescape("%3D%3D"), "yourself", "deny:"],
-referencedClasses: []
-}),
-smalltalk.BooleanTest);
-
 
 
 smalltalk.addClass('NumberTest', smalltalk.TestCase, [], 'Kernel-Tests');

+ 26 - 1
js/boot.js

@@ -58,6 +58,10 @@ function SmalltalkMetaclass(){
 function SmalltalkMethod(){};
 function SmalltalkNil(){};
 
+function SmalltalkSymbol(string){
+	this.value = string;
+};
+
 function Smalltalk(){
 
 	var st = this;
@@ -77,6 +81,25 @@ function Smalltalk(){
 		'public', 'return', 'static', 'switch', 'this', 'throw',
 		'try', 'typeof', 'var', 'void', 'while', 'with', 'yield'];
 
+	/* The symbol table ensures symbol unicity */
+
+	symbolTable = {};
+	st.symbolFor = function(string) {
+		if(symbolTable[string] === undefined) {
+			symbolTable[string] = new SmalltalkSymbol(string);
+		};
+
+		return symbolTable[string];
+	};
+
+	/* Unique ID number generator */
+
+	oid = 0;
+	st.nextId = function() {
+		oid += 1;
+		return oid;
+	};
+
 	/* We hold all Packages in a separate Object */
 
 	st.packages = {};
@@ -554,7 +577,9 @@ smalltalk.mapClassName("UndefinedObject", "Kernel", SmalltalkNil, smalltalk.Obje
 
 smalltalk.mapClassName("Collection", "Kernel", null, smalltalk.Object);
 smalltalk.mapClassName("SequenceableCollection", "Kernel", null, smalltalk.Collection);
-smalltalk.mapClassName("String", "Kernel", String, smalltalk.SequenceableCollection);
+smalltalk.mapClassName("CharacterArray", "Kernel", null, smalltalk.SequenceableCollection);
+smalltalk.mapClassName("String", "Kernel", String, smalltalk.CharacterArray);
+smalltalk.mapClassName("Symbol", "Kernel", SmalltalkSymbol, smalltalk.CharacterArray);
 smalltalk.mapClassName("Array", "Kernel", Array, smalltalk.SequenceableCollection);
 smalltalk.mapClassName("RegularExpression", "Kernel", RegExp, smalltalk.String);
 

+ 3 - 4
js/parser.js

@@ -755,7 +755,7 @@ smalltalk.parser = (function(){
         var result2 = result1 !== null
           ? (function(val) {
           		  return smalltalk.ValueNode._new()
-                         	   	._value_(val.join("").replace(/\"/ig, '"'))
+                         	   	._value_(smalltalk.symbolFor(val.join("").replace(/\"/ig, '"')))
                          	 })(result1[1])
           : null;
         if (result2 !== null) {
@@ -1341,9 +1341,8 @@ smalltalk.parser = (function(){
         }
         var result2 = result1 !== null
           ? (function(val) {
-          					return smalltalk.ValueNode._new()
-          						._value_(val)
-          				})(result1)
+          			return smalltalk.ValueNode._new()._value_(val)
+          		    })(result1)
           : null;
         if (result2 !== null) {
           var result0 = result2;

+ 7 - 7
js/parser.pegjs

@@ -13,7 +13,7 @@ string         = ['] val:(("''" {return "'"} / [^'])*) ['] {
 
 symbol         = "#"val:[a-zA-Z0-9]* {
 		  return smalltalk.ValueNode._new()
-               	   	._value_(val.join("").replace(/\"/ig, '"'))
+               	   	._value_('smalltalk.symbolFor(val.join("").replace(/\"/ig, '"')))
                	 }
 number         = n:(float / integer) {
 		  return smalltalk.ValueNode._new()
@@ -33,12 +33,12 @@ dynamicDictionary = "#{" ws expressions: expressions? ws "}" {
 	       	  return smalltalk.DynamicDictionaryNode._new()
 		        ._nodes_(expressions)
 		  }
-pseudoVariable = val:('true' {return true} 
-				/ 'false' {return false}
-				/ 'nil' {return nil} {
-					return smalltalk.ValueNode._new()
-						._value_(val)
-				}
+pseudoVariable = val:(
+	          'true' {return true} 
+	       	/ 'false' {return false}
+		/ 'nil' {return nil}) {
+			return smalltalk.ValueNode._new()._value_(val)
+		    }
 literal        = pseudoVariable / number / literalArray / dynamicDictionary / dynamicArray / string / symbol / block
 
 

+ 1 - 1
st/Kernel-Classes.st

@@ -194,7 +194,7 @@ subclass: aString instanceVariableNames: aString2 classVariableNames: classVars
 
 subclass: aString instanceVariableNames: aString2 package: aString3
 	^ClassBuilder new
-	    superclass: self subclass: aString instanceVariableNames: aString2 package: aString3
+	    superclass: self subclass: aString asString instanceVariableNames: aString2 package: aString3
 ! !
 
 !Class methodsFor: 'printing'!

+ 347 - 78
st/Kernel-Collections.st

@@ -48,13 +48,7 @@ remove: anObject ifAbsent: aBlock
 !Collection methodsFor: 'converting'!
 
 asArray
-	| array index |
-	array := Array new.
-	index := 0.
-	self do: [:each |
-	    index := index + 1.
-	    array at: index put: each].
-	^array
+	^Array withAll: self
 !
 
 asSet
@@ -63,6 +57,10 @@ asSet
 
 asJSONString
 	^JSON stringify: (self collect: [:each | each asJSONString])
+!
+
+asOrderedCollection
+	^OrderedCollection withAll: self
 ! !
 
 !Collection methodsFor: 'copying'!
@@ -213,6 +211,10 @@ withAll: aCollection
 	    ^self new
 		addAll: aCollection;
 		yourself
+!
+
+new: anInteger
+	^self new
 ! !
 
 Collection subclass: #SequenceableCollection
@@ -305,6 +307,16 @@ addLast: anObject
 	self add: anObject
 ! !
 
+!SequenceableCollection methodsFor: 'comparing'!
+
+= aCollection
+	(self class = aCollection class and: [
+		self size = aCollection size]) ifFalse: [^false].
+	self withIndexDo: [:each :i |
+                 (aCollection at: i) = each ifFalse: [^false]].
+	^true
+! !
+
 !SequenceableCollection methodsFor: 'converting'!
 
 reversed
@@ -314,7 +326,28 @@ reversed
 !SequenceableCollection methodsFor: 'copying'!
 
 copyFrom: anIndex to: anotherIndex
-	self subclassResponsibility
+	| range newCollection |
+	range := anIndex to: anotherIndex.
+	newCollection := self class new: range size.
+	range do: [:each |
+	    newCollection at: each put: (self at: each)].
+	^newCollection
+!
+
+shallowCopy
+	| newCollection |
+	newCollection := self class new: self size.
+	self withIndexDo: [ :each :index | 
+		newCollection at: index put: each].
+	^newCollection
+!
+
+deepCopy
+	| newCollection |
+	newCollection := self class new: self size.
+	self withIndexDo: [:each :index | 
+		newCollection at: index put: each deepCopy].
+	^newCollection
 ! !
 
 !SequenceableCollection methodsFor: 'enumerating'!
@@ -323,18 +356,93 @@ withIndexDo: aBlock
 	<for(var i=0;i<self.length;i++){aBlock(self[i], i+1);}>
 ! !
 
-SequenceableCollection subclass: #String
+!SequenceableCollection methodsFor: 'printing'!
+
+printString
+	| str |
+	str := '' writeStream.
+	str nextPutAll: super printString, ' ('.
+	self 
+		do: [:each | str nextPutAll: each printString]
+		separatedBy: [str nextPutAll: ' '].
+	str nextPutAll: ')'.
+	^str contents
+! !
+
+SequenceableCollection subclass: #CharacterArray
 	instanceVariableNames: ''
 	category: 'Kernel-Collections'!
 
-!String methodsFor: 'accessing'!
+!CharacterArray methodsFor: 'accessing'!
 
-size
-	<return self.length>
+at: anIndex put: anObject
+	self errorReadOnly
+! !
+
+!CharacterArray methodsFor: 'adding'!
+
+add: anObject
+	self errorReadOnly
 !
 
-at: anIndex put: anObject
+remove: anObject
 	self errorReadOnly
+! !
+
+!CharacterArray methodsFor: 'converting'!
+
+asString
+	^self subclassResponsibility
+!
+
+asNumber
+	^self asString asNumber
+!
+
+asUppercase
+	^self class fromString: self asString asUppercase
+!
+
+asSymbol
+	^self subclassResponsibility
+!
+
+asLowercase
+	^self class fromString: self asString asLowercase
+! !
+
+!CharacterArray methodsFor: 'copying'!
+
+, aString
+	^self asString, aString asString
+! !
+
+!CharacterArray methodsFor: 'error handling'!
+
+errorReadOnly
+	self error: 'Object is read-only'
+! !
+
+!CharacterArray methodsFor: 'printing'!
+
+printString
+	^self asString printString
+! !
+
+!CharacterArray class methodsFor: 'instance creation'!
+
+fromString: aString
+	self subclassResponsibility
+! !
+
+CharacterArray subclass: #String
+	instanceVariableNames: ''
+	category: 'Kernel-Collections'!
+
+!String methodsFor: 'accessing'!
+
+size
+	<return self.length>
 !
 
 at: anIndex ifAbsent: aBlock
@@ -353,21 +461,11 @@ asciiValue
 	<return self.charCodeAt(0);>
 ! !
 
-!String methodsFor: 'adding'!
-
-add: anObject
-	self errorReadOnly
-!
-
-remove: anObject
-	self errorReadOnly
-! !
-
 !String methodsFor: 'comparing'!
 
 = aString
 	aString class = self class ifFalse: [^false].
-	<return String(self) == aString>
+	<return String(self) === String(aString)>
 !
 
 > aString
@@ -384,11 +482,6 @@ remove: anObject
 
 <= aString
 	<return String(self) <= aString>
-!
-
-== aString
-	aString class = self class ifFalse: [^false].
-	<return String(self) === String(aString)>
 ! !
 
 !String methodsFor: 'converting'!
@@ -450,6 +543,10 @@ asJavaScriptSelector
 
 asJSONString
 	^self
+!
+
+asSymbol
+	^Symbol lookup: self
 ! !
 
 !String methodsFor: 'copying'!
@@ -470,12 +567,6 @@ deepCopy
 	^self shallowCopy
 ! !
 
-!String methodsFor: 'error handling'!
-
-errorReadOnly
-	self error: 'Object is read-only'
-! !
-
 !String methodsFor: 'printing'!
 
 printString
@@ -652,6 +743,94 @@ value: aUTFCharCode
 	<return String.fromCharCode(aUTFCharCode);>
 ! !
 
+CharacterArray subclass: #Symbol
+	instanceVariableNames: ''
+	category: 'Kernel-Collections'!
+
+!Symbol methodsFor: 'accessing'!
+
+at: anIndex ifAbsent: aBlock
+	^self asString at: anIndex ifAbsent: aBlock
+!
+
+size
+	^self asString size
+! !
+
+!Symbol methodsFor: 'comparing'!
+
+< aSymbol
+	^self asString < aSymbol asString
+!
+
+<= aSymbol
+	^self asString <= aSymbol asString
+!
+
+>= aSymbol
+	^self asString >= aSymbol asString
+!
+
+= aSymbol
+	^self asString = aSymbol asString
+!
+
+> aSymbol
+	^self asString > aSymbol asString
+! !
+
+!Symbol methodsFor: 'converting'!
+
+asString
+	<return self.value>
+!
+
+asSymbol
+	^self
+!
+
+asJavascript
+	^'smalltalk.symbolFor("', self asString, '")'
+! !
+
+!Symbol methodsFor: 'copying'!
+
+copyFrom: anIndex to: anotherIndex
+	^self class fromString: (self asString copyFrom: anIndex to: anotherIndex)
+!
+
+deepCopy
+	^self
+!
+
+shadowCopy
+	^self
+! !
+
+!Symbol methodsFor: 'printing'!
+
+printString
+	^'#', self asString
+!
+
+isSymbol
+	^true
+! !
+
+!Symbol class methodsFor: 'instance creation'!
+
+lookup: aString
+	<return smalltalk.symbolFor(aString);>
+!
+
+basicNew
+	self shouldNotImplement
+!
+
+fromString: aString
+	^self lookup: aString
+! !
+
 SequenceableCollection subclass: #Array
 	instanceVariableNames: ''
 	category: 'Kernel-Collections'!
@@ -698,16 +877,6 @@ removeFrom: aNumber to: anotherNumber
 	<self.splice(aNumber - 1,anotherNumber - 1)>
 ! !
 
-!Array methodsFor: 'comparing'!
-
-= aCollection
-	(self class = aCollection class and: [
-		self size = aCollection size]) ifFalse: [^false].
-	self withIndexDo: [:each :i |
-                 (aCollection at: i) = each ifFalse: [^false]].
-	^true
-! !
-
 !Array methodsFor: 'converting'!
 
 asJavascript
@@ -718,30 +887,6 @@ reversed
 	<return self._copy().reverse()>
 ! !
 
-!Array methodsFor: 'copying'!
-
-shallowCopy
-	| newCollection |
-	newCollection := self class new.
-	self do: [:each | newCollection add: each].
-	^newCollection
-!
-
-deepCopy
-	| newCollection |
-	newCollection := self class new.
-	self do: [:each | newCollection add: each deepCopy].
-	^newCollection
-!
-
-copyFrom: anIndex to: anotherIndex
-	| array |
-	array := self class new.
-	anIndex to: anotherIndex do: [:each |
-	    array add: (self at: each)].
-	^array
-! !
-
 !Array methodsFor: 'enumerating'!
 
 join: aString
@@ -766,17 +911,41 @@ sorted
 
 sorted: aBlock
 	^self copy sort: aBlock
+! !
+
+!Array class methodsFor: 'instance creation'!
+
+new: anInteger
+	<return new Array(anInteger)>
 !
 
-printString
-	| str |
-	str := '' writeStream.
-	str nextPutAll: super printString, ' ('.
-	self 
-		do: [:each | str nextPutAll: each printString]
-		separatedBy: [str nextPutAll: ' '].
-	str nextPutAll: ')'.
-	^str contents
+with: anObject
+	    ^(self new: 1)
+		at: 1 put: anObject;
+		yourself
+!
+
+with: anObject with: anObject2
+	    ^(self new: 2)
+		at: 1 put: anObject;
+		at: 2 put: anObject2;
+		yourself
+!
+
+with: anObject with: anObject2 with: anObject3
+	    ^(self new: 3)
+		at: 1 put: anObject;
+		at: 2 put: anObject2;
+		at: 3 put: anObject3;
+		yourself
+!
+
+withAll: aCollection
+	| instance |
+	instance := self new: aCollection size.
+	aCollection withIndexDo: [:index :each |
+		instance at: index put: each].
+	^instance
 ! !
 
 Object subclass: #RegularExpression
@@ -1100,6 +1269,10 @@ includes: anObject
 Collection subclass: #HashedCollection
 	instanceVariableNames: ''
 	category: 'Kernel-Collections'!
+!HashedCollection commentStamp!
+A HashedCollection is a traditional JavaScript object, or a Smalltalk Dictionary.
+
+Unlike a Dictionary, it can only have strings as keys.!
 
 !HashedCollection methodsFor: 'accessing'!
 
@@ -1385,3 +1558,99 @@ includesKey: aKey
 	^keys includes: aKey
 ! !
 
+SequenceableCollection subclass: #OrderedCollection
+	instanceVariableNames: 'elements'
+	category: 'Kernel-Collections'!
+
+!OrderedCollection methodsFor: 'accessing'!
+
+size
+	^elements size
+!
+
+at: anIndex put: anObject
+	<return self['@elements'][anIndex - 1] = anObject>
+!
+
+at: anIndex ifAbsent: aBlock
+	^elements at: anIndex ifAbsent: aBlock
+! !
+
+!OrderedCollection methodsFor: 'adding/removing'!
+
+add: anObject
+	<self['@elements'].push(anObject); return anObject;>
+!
+
+remove: anObject
+	<
+		for(var i=0;i<self['@elements'].length;i++) {
+			if(self['@elements'][i] == anObject) {
+				self['@elements'].splice(i,1);
+				break;
+			}
+		}
+	>
+!
+
+removeFrom: aNumber to: anotherNumber
+	<self['@elements'].splice(aNumber - 1,anotherNumber - 1)>
+! !
+
+!OrderedCollection methodsFor: 'converting'!
+
+reversed
+	^self asArray reversed asOrderedCollection
+!
+
+asOrderedCollection
+	^self
+!
+
+asArray
+	^elements copy
+! !
+
+!OrderedCollection methodsFor: 'enumerating'!
+
+join: aString
+	^elements join: aString
+!
+
+sort
+ 	elements sort.
+	^self
+!
+
+sort: aBlock
+	elements sort: aBlock.
+	^self
+!
+
+sorted
+	^self copy sort
+!
+
+sorted: aBlock
+	^self copy sort: aBlock
+!
+
+withIndexDo: aBlock
+	elements withIndexDo: aBlock
+!
+
+detect: aBlock ifNone: anotherBlock
+	^elements detect: aBlock ifNone: anotherBlock
+!
+
+do: aBlock
+	elements do: aBlock
+! !
+
+!OrderedCollection methodsFor: 'initialization'!
+
+initialize
+	super initialize.
+	elements := #()
+! !
+

+ 16 - 12
st/Kernel-Objects.st

@@ -35,6 +35,10 @@ basicAt: aString put: anObject
 
 basicDelete: aString
     <delete self[aString]; return aString>
+!
+
+identityHash
+	<return self.identityHash || (self.identityHash = smalltalk.nextId());>
 ! !
 
 !Object methodsFor: 'comparing'!
@@ -48,7 +52,7 @@ basicDelete: aString
 !
 
 == anObject
-	<return self === anObject>
+	^self identityHash = anObject identityHash
 !
 
 ~~ anObject
@@ -256,6 +260,10 @@ isString
 
 isParseFailure
 	^false
+!
+
+isSymbol
+	^false
 ! !
 
 !Object class methodsFor: 'initialization'!
@@ -552,6 +560,12 @@ Object subclass: #Number
 
 ! !
 
+!Number methodsFor: 'accessing'!
+
+identityHash
+	^self asString, 'n'
+! !
+
 !Number methodsFor: 'arithmetic'!
 
 + aNumber
@@ -601,7 +615,7 @@ squared
 !Number methodsFor: 'comparing'!
 
 = aNumber
-	aNumber class = self class ifFalse: [^false]. 
+	aNumber isNumber ifFalse: [^false]. 
 	<return Number(self) == aNumber>
 !
 
@@ -623,11 +637,6 @@ squared
 <= aNumber
 	"Inlined in the Compiler"
 	<return self <= aNumber>
-!
-
-== aNumber
-	aNumber class = self class ifFalse: [^false]. 
-	<return Number(self) === Number(aNumber)>
 ! !
 
 !Number methodsFor: 'converting'!
@@ -790,11 +799,6 @@ Object subclass: #Boolean
 = aBoolean
 	aBoolean class = self class ifFalse: [^false].
 	<return Boolean(self == true) == aBoolean>
-!
-
-== aBoolean
-	aBoolean class = self class ifFalse: [^false].
-	<return Boolean(self == true) === Boolean(aBoolean == true)>
 ! !
 
 !Boolean methodsFor: 'controlling'!

+ 0 - 9
st/Kernel-Tests.st

@@ -212,15 +212,6 @@ testIfTrueIfFalse
 
 	self assert: (true ifTrue: ['alternative block'] ifFalse: ['alternative block2']) = 'alternative block'.
 	self assert: (true ifFalse: ['alternative block'] ifTrue: ['alternative block2']) = 'alternative block2'.
-!
-
-testIdentity
-	self assert: true == true.
-	self assert: true yourself == true.
-	self assert: true == true yourself.
-	self assert: true yourself == true yourself.
-
-	self deny: true == false
 ! !
 
 TestCase subclass: #NumberTest

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor