Browse Source

Updated amber

Nicolas Petton 12 years ago
parent
commit
ee2e3c6f12
6 changed files with 274 additions and 905 deletions
  1. 1 1
      amber/LICENSE
  2. 97 462
      amber/js/Kernel.deploy.js
  3. 101 179
      amber/js/Kernel.js
  4. 0 2
      amber/repl/REPL.js
  5. 7 3
      amber/repl/REPL.st
  6. 68 258
      amber/st/Kernel.st

+ 1 - 1
amber/LICENSE

@@ -1,4 +1,4 @@
-Copyright (C) 2011 by Nicolas Petton <petton.nicolas@gmail.com>
+Copyright (C) 2011 Nicolas Petton <petton.nicolas@gmail.com>
 Copyright (C) 2011 Amber contributors https://github.com/NicolasPetton/amber/contributors
 
 Parts of Amber take ideas from Clamato (http://clamato.net), written by Avi Bryant.

+ 97 - 462
amber/js/Kernel.deploy.js

@@ -462,7 +462,7 @@ smalltalk.method({
 selector: 'basicDelete:',
 fn: function (aString){
 var self=this;
-delete self[aString];
+delete self[aString]; return aString;
 return self;}
 }),
 smalltalk.Object);
@@ -484,21 +484,7 @@ smalltalk.method({
 selector: 'asJSON',
 fn: function (){
 var self=this;
-return JSON.stringify(self._asJSONObject());
-return self;}
-}),
-smalltalk.Object);
-
-smalltalk.addMethod(
-'_asJSONObject',
-smalltalk.method({
-selector: 'asJSONObject',
-fn: function (){
-var self=this;
-var object=nil;
-object=smalltalk.send((smalltalk.Object || Object), "_new", []);
-smalltalk.send(smalltalk.send(smalltalk.send(self, "_class", []), "_instanceVariableNames", []), "_do_", [(function(each){return smalltalk.send(object, "_basicAt_put_", [each, smalltalk.send(smalltalk.send(self, "_instVarAt_", [each]), "_asJSONObject", [])]);})]);
-return object;
+return JSON.stringify(self);
 return self;}
 }),
 smalltalk.Object);
@@ -1883,17 +1869,6 @@ return self;}
 }),
 smalltalk.Number);
 
-smalltalk.addMethod(
-'_asJSONObject',
-smalltalk.method({
-selector: 'asJSONObject',
-fn: function (){
-var self=this;
-return self;
-return self;}
-}),
-smalltalk.Number);
-
 smalltalk.addMethod(
 '_clearTimeout',
 smalltalk.method({
@@ -2262,6 +2237,19 @@ return self;}
 }),
 smalltalk.BlockClosure);
 
+smalltalk.addMethod(
+'_ensure_',
+smalltalk.method({
+selector: 'ensure:',
+fn: function (aBlock){
+var self=this;
+var success=nil;
+success=false;
+smalltalk.send((function(){smalltalk.send(self, "_value", []);success=true;return smalltalk.send(aBlock, "_value", []);}), "_on_do_", [(smalltalk.Error || Error), (function(ex){((($receiver = success).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return smalltalk.send(aBlock, "_value", []);})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return smalltalk.send(aBlock, "_value", []);})]));return smalltalk.send(ex, "_signal", []);})]);
+return self;}
+}),
+smalltalk.BlockClosure);
+
 
 
 smalltalk.addClass('Boolean', smalltalk.Object, [], 'Kernel');
@@ -2394,17 +2382,6 @@ return self;}
 }),
 smalltalk.Boolean);
 
-smalltalk.addMethod(
-'_asJSONObject',
-smalltalk.method({
-selector: 'asJSONObject',
-fn: function (){
-var self=this;
-return self;
-return self;}
-}),
-smalltalk.Boolean);
-
 smalltalk.addMethod(
 '_&',
 smalltalk.method({
@@ -2818,17 +2795,6 @@ return self;}
 }),
 smalltalk.Date);
 
-smalltalk.addMethod(
-'_asJSONObject',
-smalltalk.method({
-selector: 'asJSONObject',
-fn: function (){
-var self=this;
-return self;
-return self;}
-}),
-smalltalk.Date);
-
 
 smalltalk.addMethod(
 '_new_',
@@ -3345,7 +3311,7 @@ smalltalk.method({
 selector: 'remove:',
 fn: function (anObject){
 var self=this;
-smalltalk.send(self, "_subclassResponsibility", []);
+return smalltalk.send(self, "_remove_ifAbsent_", [anObject, (function(){return smalltalk.send(self, "_errorNotFound", []);})]);
 return self;}
 }),
 smalltalk.Collection);
@@ -3394,6 +3360,17 @@ return self;}
 }),
 smalltalk.Collection);
 
+smalltalk.addMethod(
+'_remove_ifAbsent_',
+smalltalk.method({
+selector: 'remove:ifAbsent:',
+fn: function (anObject, aBlock){
+var self=this;
+smalltalk.send(self, "_subclassResponsibility", []);
+return self;}
+}),
+smalltalk.Collection);
+
 
 smalltalk.addMethod(
 '_streamClass',
@@ -4023,17 +4000,6 @@ return self;}
 }),
 smalltalk.String);
 
-smalltalk.addMethod(
-'_asJSONObject',
-smalltalk.method({
-selector: 'asJSONObject',
-fn: function (){
-var self=this;
-return self;
-return self;}
-}),
-smalltalk.String);
-
 smalltalk.addMethod(
 '_trimLeft_',
 smalltalk.method({
@@ -4540,17 +4506,6 @@ return self;}
 }),
 smalltalk.Array);
 
-smalltalk.addMethod(
-'_asJSONObject',
-smalltalk.method({
-selector: 'asJSONObject',
-fn: function (){
-var self=this;
-return smalltalk.send(self, "_collect_", [(function(each){return smalltalk.send(each, "_asJSONObject", []);})]);
-return self;}
-}),
-smalltalk.Array);
-
 smalltalk.addMethod(
 '_removeFrom_to_',
 smalltalk.method({
@@ -4708,6 +4663,28 @@ return self;}
 }),
 smalltalk.Error);
 
+smalltalk.addMethod(
+'_jsStack',
+smalltalk.method({
+selector: 'jsStack',
+fn: function (){
+var self=this;
+return self.stack;
+return self;}
+}),
+smalltalk.Error);
+
+smalltalk.addMethod(
+'_isSmalltalkError',
+smalltalk.method({
+selector: 'isSmalltalkError',
+fn: function (){
+var self=this;
+return self.smalltalkError === true;
+return self;}
+}),
+smalltalk.Error);
+
 
 smalltalk.addMethod(
 '_signal_',
@@ -4872,7 +4849,7 @@ return self;}
 smalltalk.Association.klass);
 
 
-smalltalk.addClass('Dictionary', smalltalk.Collection, ['keys'], 'Kernel');
+smalltalk.addClass('Dictionary', smalltalk.Collection, [], 'Kernel');
 smalltalk.addMethod(
 '__eq',
 smalltalk.method({
@@ -4901,25 +4878,13 @@ return self;}
 }),
 smalltalk.Dictionary);
 
-smalltalk.addMethod(
-'_initialize',
-smalltalk.method({
-selector: 'initialize',
-fn: function (){
-var self=this;
-smalltalk.send(self, "_initialize", [], smalltalk.Collection);
-self['@keys']=[];
-return self;}
-}),
-smalltalk.Dictionary);
-
 smalltalk.addMethod(
 '_size',
 smalltalk.method({
 selector: 'size',
 fn: function (){
 var self=this;
-return smalltalk.send(self['@keys'], "_size", []);
+return smalltalk.send(smalltalk.send(self, "_keys", []), "_size", []);
 return self;}
 }),
 smalltalk.Dictionary);
@@ -4932,7 +4897,7 @@ fn: function (){
 var self=this;
 var associations=nil;
 associations=[];
-smalltalk.send(self['@keys'], "_do_", [(function(each){return smalltalk.send(associations, "_add_", [smalltalk.send((smalltalk.Association || Association), "_key_value_", [each, smalltalk.send(self, "_at_", [each])])]);})]);
+smalltalk.send(smalltalk.send(self, "_keys", []), "_do_", [(function(each){return smalltalk.send(associations, "_add_", [smalltalk.send((smalltalk.Association || Association), "_key_value_", [each, smalltalk.send(self, "_at_", [each])])]);})]);
 return associations;
 return self;}
 }),
@@ -4944,7 +4909,15 @@ smalltalk.method({
 selector: 'keys',
 fn: function (){
 var self=this;
-return smalltalk.send(self['@keys'], "_copy", []);
+
+		var keys = [];
+		for(var i in self) {
+			if(self.hasOwnProperty(i)) {
+				keys.push(i);
+			}
+		};
+		return keys;
+	;
 return self;}
 }),
 smalltalk.Dictionary);
@@ -4955,7 +4928,7 @@ smalltalk.method({
 selector: 'values',
 fn: function (){
 var self=this;
-return smalltalk.send(self['@keys'], "_collect_", [(function(each){return smalltalk.send(self, "_at_", [each]);})]);
+return smalltalk.send(smalltalk.send(self, "_keys", []), "_collect_", [(function(each){return smalltalk.send(self, "_at_", [each]);})]);
 return self;}
 }),
 smalltalk.Dictionary);
@@ -4966,7 +4939,6 @@ smalltalk.method({
 selector: 'at:put:',
 fn: function (aKey, aValue){
 var self=this;
-((($receiver = smalltalk.send(self['@keys'], "_includes_", [aKey])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return smalltalk.send(self['@keys'], "_add_", [aKey]);})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return smalltalk.send(self['@keys'], "_add_", [aKey]);})]));
 return smalltalk.send(self, "_basicAt_put_", [aKey, aValue]);
 return self;}
 }),
@@ -4978,7 +4950,7 @@ smalltalk.method({
 selector: 'at:ifAbsent:',
 fn: function (aKey, aBlock){
 var self=this;
-return smalltalk.send(smalltalk.send(smalltalk.send(self, "_keys", []), "_includes_", [aKey]), "_ifTrue_ifFalse_", [(function(){return smalltalk.send(self, "_basicAt_", [aKey]);}), aBlock]);
+return smalltalk.send(smalltalk.send(self, "_includesKey_", [aKey]), "_ifTrue_ifFalse_", [(function(){return smalltalk.send(self, "_basicAt_", [aKey]);}), aBlock]);
 return self;}
 }),
 smalltalk.Dictionary);
@@ -5144,24 +5116,13 @@ return self;}
 }),
 smalltalk.Dictionary);
 
-smalltalk.addMethod(
-'_remove_',
-smalltalk.method({
-selector: 'remove:',
-fn: function (aKey){
-var self=this;
-smalltalk.send(self, "_removeKey_", [aKey]);
-return self;}
-}),
-smalltalk.Dictionary);
-
 smalltalk.addMethod(
 '_removeKey_',
 smalltalk.method({
 selector: 'removeKey:',
 fn: function (aKey){
 var self=this;
-smalltalk.send(self['@keys'], "_remove_", [aKey]);
+smalltalk.send(self, "_remove_", [aKey]);
 return self;}
 }),
 smalltalk.Dictionary);
@@ -5177,20 +5138,6 @@ return self;}
 }),
 smalltalk.Dictionary);
 
-smalltalk.addMethod(
-'_asJSONObject',
-smalltalk.method({
-selector: 'asJSONObject',
-fn: function (){
-var self=this;
-var object=nil;
-object=smalltalk.send((smalltalk.Object || Object), "_new", []);
-smalltalk.send(self, "_keysAndValuesDo_", [(function(key, value){return smalltalk.send(object, "_basicAt_put_", [key, smalltalk.send(value, "_asJSONObject", [])]);})]);
-return object;
-return self;}
-}),
-smalltalk.Dictionary);
-
 smalltalk.addMethod(
 '_printString',
 smalltalk.method({
@@ -5215,6 +5162,39 @@ return self;}
 }),
 smalltalk.Dictionary);
 
+smalltalk.addMethod(
+'_includesKey_',
+smalltalk.method({
+selector: 'includesKey:',
+fn: function (aKey){
+var self=this;
+return self.hasOwnProperty(aKey);
+return self;}
+}),
+smalltalk.Dictionary);
+
+smalltalk.addMethod(
+'_remove_ifAbsent_',
+smalltalk.method({
+selector: 'remove:ifAbsent:',
+fn: function (aKey, aBlock){
+var self=this;
+return smalltalk.send(self, "_removeKey_ifAbsent_", [aKey, aBlock]);
+return self;}
+}),
+smalltalk.Dictionary);
+
+smalltalk.addMethod(
+'_removeKey_ifAbsent_',
+smalltalk.method({
+selector: 'removeKey:ifAbsent:',
+fn: function (aKey, aBlock){
+var self=this;
+return ((($receiver = smalltalk.send(self, "_includesKey_", [aKey])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return smalltalk.send(aBlock, "_value", []);})() : (function(){return smalltalk.send(self, "_basicDelete_", [aKey]);})()) : smalltalk.send($receiver, "_ifFalse_ifTrue_", [(function(){return smalltalk.send(aBlock, "_value", []);}), (function(){return smalltalk.send(self, "_basicDelete_", [aKey]);})]));
+return self;}
+}),
+smalltalk.Dictionary);
+
 
 smalltalk.addMethod(
 '_fromPairs_',
@@ -6538,348 +6518,3 @@ return self;}
 smalltalk.ConsoleTranscript.klass);
 
 
-smalltalk.addClass('Dictionary2', smalltalk.Dictionary, ['keys'], 'Kernel');
-smalltalk.addMethod(
-'__eq',
-smalltalk.method({
-selector: '=',
-fn: function (aDictionary){
-var self=this;
-try{((($receiver = smalltalk.send(smalltalk.send(self, "_class", []), "__eq", [smalltalk.send(aDictionary, "_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}})})();})]));
-((($receiver = smalltalk.send(smalltalk.send(self, "_size", []), "__eq", [smalltalk.send(aDictionary, "_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}})})();})]));
-(function(){throw({name: 'stReturn', selector: '__eq', fn: function(){return smalltalk.send(smalltalk.send(self, "_associations", []), "__eq", [smalltalk.send(aDictionary, "_associations", [])])}})})();
-return self;
-} catch(e) {if(e.name === 'stReturn' && e.selector === '__eq'){return e.fn()} throw(e)}}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_shallowCopy',
-smalltalk.method({
-selector: 'shallowCopy',
-fn: function (){
-var self=this;
-var copy=nil;
-copy=smalltalk.send(smalltalk.send(self, "_class", []), "_new", []);
-smalltalk.send(self, "_associationsDo_", [(function(each){return smalltalk.send(copy, "_at_put_", [smalltalk.send(each, "_key", []), smalltalk.send(each, "_value", [])]);})]);
-return copy;
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_initialize',
-smalltalk.method({
-selector: 'initialize',
-fn: function (){
-var self=this;
-smalltalk.send(self, "_initialize", [], smalltalk.Dictionary);
-self['@keys']=[];
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_size',
-smalltalk.method({
-selector: 'size',
-fn: function (){
-var self=this;
-return smalltalk.send(self['@keys'], "_size", []);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_associations',
-smalltalk.method({
-selector: 'associations',
-fn: function (){
-var self=this;
-var associations=nil;
-associations=[];
-smalltalk.send(self['@keys'], "_do_", [(function(each){return smalltalk.send(associations, "_add_", [smalltalk.send((smalltalk.Association || Association), "_key_value_", [each, smalltalk.send(self, "_at_", [each])])]);})]);
-return associations;
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_keys',
-smalltalk.method({
-selector: 'keys',
-fn: function (){
-var self=this;
-return smalltalk.send(self['@keys'], "_copy", []);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_values',
-smalltalk.method({
-selector: 'values',
-fn: function (){
-var self=this;
-return smalltalk.send(self['@keys'], "_collect_", [(function(each){return smalltalk.send(self, "_at_", [each]);})]);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_at_put_',
-smalltalk.method({
-selector: 'at:put:',
-fn: function (aKey, aValue){
-var self=this;
-((($receiver = smalltalk.send(self['@keys'], "_includes_", [aKey])).klass === smalltalk.Boolean) ? (! $receiver ? (function(){return smalltalk.send(self['@keys'], "_add_", [aKey]);})() : nil) : smalltalk.send($receiver, "_ifFalse_", [(function(){return smalltalk.send(self['@keys'], "_add_", [aKey]);})]));
-return smalltalk.send(self, "_basicAt_put_", [aKey, aValue]);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_at_ifAbsent_',
-smalltalk.method({
-selector: 'at:ifAbsent:',
-fn: function (aKey, aBlock){
-var self=this;
-return smalltalk.send(smalltalk.send(smalltalk.send(self, "_keys", []), "_includes_", [aKey]), "_ifTrue_ifFalse_", [(function(){return smalltalk.send(self, "_basicAt_", [aKey]);}), aBlock]);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_at_ifAbsentPut_',
-smalltalk.method({
-selector: 'at:ifAbsentPut:',
-fn: function (aKey, aBlock){
-var self=this;
-return smalltalk.send(self, "_at_ifAbsent_", [aKey, (function(){return smalltalk.send(self, "_at_put_", [aKey, smalltalk.send(aBlock, "_value", [])]);})]);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_at_ifPresent_',
-smalltalk.method({
-selector: 'at:ifPresent:',
-fn: function (aKey, aBlock){
-var self=this;
-return (($receiver = smalltalk.send(self, "_basicAt_", [aKey])) != nil && $receiver != undefined) ? (function(){return smalltalk.send(aBlock, "_value_", [smalltalk.send(self, "_at_", [aKey])]);})() : nil;
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_at_ifPresent_ifAbsent_',
-smalltalk.method({
-selector: 'at:ifPresent:ifAbsent:',
-fn: function (aKey, aBlock, anotherBlock){
-var self=this;
-return smalltalk.send(smalltalk.send(self, "_basicAt_", [aKey]), "_ifNil_ifNotNil_", [anotherBlock, (function(){return smalltalk.send(aBlock, "_value_", [smalltalk.send(self, "_at_", [aKey])]);})]);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_add_',
-smalltalk.method({
-selector: 'add:',
-fn: function (anAssociation){
-var self=this;
-smalltalk.send(self, "_at_put_", [smalltalk.send(anAssociation, "_key", []), smalltalk.send(anAssociation, "_value", [])]);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_addAll_',
-smalltalk.method({
-selector: 'addAll:',
-fn: function (aDictionary){
-var self=this;
-smalltalk.send(self, "_addAll_", [smalltalk.send(aDictionary, "_associations", [])], smalltalk.Dictionary);
-return aDictionary;
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'__comma',
-smalltalk.method({
-selector: ',',
-fn: function (aCollection){
-var self=this;
-smalltalk.send(self, "_shouldNotImplement", []);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_copyFrom_to_',
-smalltalk.method({
-selector: 'copyFrom:to:',
-fn: function (anIndex, anotherIndex){
-var self=this;
-smalltalk.send(self, "_shouldNotImplement", []);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_associationsDo_',
-smalltalk.method({
-selector: 'associationsDo:',
-fn: function (aBlock){
-var self=this;
-smalltalk.send(smalltalk.send(self, "_associations", []), "_do_", [aBlock]);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_keysAndValuesDo_',
-smalltalk.method({
-selector: 'keysAndValuesDo:',
-fn: function (aBlock){
-var self=this;
-smalltalk.send(self, "_associationsDo_", [(function(each){return smalltalk.send(aBlock, "_value_value_", [smalltalk.send(each, "_key", []), smalltalk.send(each, "_value", [])]);})]);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_do_',
-smalltalk.method({
-selector: 'do:',
-fn: function (aBlock){
-var self=this;
-smalltalk.send(smalltalk.send(self, "_values", []), "_do_", [aBlock]);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_select_',
-smalltalk.method({
-selector: 'select:',
-fn: function (aBlock){
-var self=this;
-var newDict=nil;
-newDict=smalltalk.send(smalltalk.send(self, "_class", []), "_new", []);
-smalltalk.send(self, "_keysAndValuesDo_", [(function(key, value){return ((($receiver = smalltalk.send(aBlock, "_value_", [value])).klass === smalltalk.Boolean) ? ($receiver ? (function(){return smalltalk.send(newDict, "_at_put_", [key, value]);})() : nil) : smalltalk.send($receiver, "_ifTrue_", [(function(){return smalltalk.send(newDict, "_at_put_", [key, value]);})]));})]);
-return newDict;
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_collect_',
-smalltalk.method({
-selector: 'collect:',
-fn: function (aBlock){
-var self=this;
-var newDict=nil;
-newDict=smalltalk.send(smalltalk.send(self, "_class", []), "_new", []);
-smalltalk.send(self, "_keysAndValuesDo_", [(function(key, value){return smalltalk.send(newDict, "_at_put_", [key, smalltalk.send(aBlock, "_value_", [value])]);})]);
-return newDict;
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_detect_ifNone_',
-smalltalk.method({
-selector: 'detect:ifNone:',
-fn: function (aBlock, anotherBlock){
-var self=this;
-return smalltalk.send(smalltalk.send(self, "_values", []), "_detect_ifNone_", [aBlock, anotherBlock]);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_includes_',
-smalltalk.method({
-selector: 'includes:',
-fn: function (anObject){
-var self=this;
-return smalltalk.send(smalltalk.send(self, "_values", []), "_includes_", [anObject]);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_remove_',
-smalltalk.method({
-selector: 'remove:',
-fn: function (aKey){
-var self=this;
-smalltalk.send(self, "_removeKey_", [aKey]);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_removeKey_',
-smalltalk.method({
-selector: 'removeKey:',
-fn: function (aKey){
-var self=this;
-smalltalk.send(self['@keys'], "_remove_", [aKey]);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_at_',
-smalltalk.method({
-selector: 'at:',
-fn: function (aKey){
-var self=this;
-return smalltalk.send(self, "_at_ifAbsent_", [aKey, (function(){return smalltalk.send(self, "_errorNotFound", []);})]);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_asJSONObject',
-smalltalk.method({
-selector: 'asJSONObject',
-fn: function (){
-var self=this;
-var object=nil;
-object=smalltalk.send((smalltalk.Object || Object), "_new", []);
-smalltalk.send(self, "_keysAndValuesDo_", [(function(key, value){return smalltalk.send(object, "_basicAt_put_", [key, smalltalk.send(value, "_asJSONObject", [])]);})]);
-return object;
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_printString',
-smalltalk.method({
-selector: 'printString',
-fn: function (){
-var self=this;
-return smalltalk.send((smalltalk.String || String), "_streamContents_", [(function(aStream){(function($rec){smalltalk.send($rec, "_nextPutAll_", [smalltalk.send(self, "_printString", [], smalltalk.Dictionary)]);return smalltalk.send($rec, "_nextPutAll_", [unescape("%28")]);})(aStream);smalltalk.send(smalltalk.send(self, "_associations", []), "_do_separatedBy_", [(function(anAssociation){return (function($rec){smalltalk.send($rec, "_nextPutAll_", [smalltalk.send(smalltalk.send(anAssociation, "_key", []), "_printString", [])]);smalltalk.send($rec, "_nextPutAll_", [unescape("%20-%3E%20")]);return smalltalk.send($rec, "_nextPutAll_", [smalltalk.send(smalltalk.send(anAssociation, "_value", []), "_printString", [])]);})(aStream);}), (function(){return smalltalk.send(aStream, "_nextPutAll_", [unescape("%20%2C%20")]);})]);return smalltalk.send(aStream, "_nextPutAll_", [unescape("%29")]);})]);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-smalltalk.addMethod(
-'_storeOn_',
-smalltalk.method({
-selector: 'storeOn:',
-fn: function (aStream){
-var self=this;
-smalltalk.send(aStream, "_nextPutAll_", [unescape("%23%7B")]);
-smalltalk.send(smalltalk.send(self, "_associations", []), "_do_separatedBy_", [(function(each){return smalltalk.send(each, "_storeOn_", [aStream]);}), (function(){return smalltalk.send(aStream, "_nextPutAll_", [". "]);})]);
-smalltalk.send(aStream, "_nextPutAll_", [unescape("%7D")]);
-return self;}
-}),
-smalltalk.Dictionary2);
-
-
-

File diff suppressed because it is too large
+ 101 - 179
amber/js/Kernel.js


File diff suppressed because it is too large
+ 0 - 2
amber/repl/REPL.js


+ 7 - 3
amber/repl/REPL.st

@@ -30,9 +30,13 @@ close
 eval: buffer
 	| result |
 	buffer isEmpty ifFalse: [
-		result := Compiler new loadExpression: buffer.
-		Transcript show: result].
-	self setPrompt.
+		self try: [
+			result := Compiler new loadExpression: buffer.
+			Transcript show: result]
+		catch: [:e |
+			e isSmalltalkError
+			    ifTrue: [ErrorHandler new handleError: e]
+			    ifFalse: [process stdout write: e jsStack]]].
 	interface prompt
 ! !
 

+ 68 - 258
amber/st/Kernel.st

@@ -34,7 +34,7 @@ basicAt: aString put: anObject
 !
 
 basicDelete: aString
-    <delete self[aString]>
+    <delete self[aString]; return aString>
 ! !
 
 !Object methodsFor: 'comparing'!
@@ -70,15 +70,7 @@ asJavascript
 !
 
 asJSON
-	<return JSON.stringify(self._asJSONObject())>
-!
-
-asJSONObject
-	| object |
-	object := Object new.
-	self class instanceVariableNames do: [:each |
-		object basicAt: each put: (self instVarAt: each) asJSONObject].
-	^object
+	<return JSON.stringify(self)>
 ! !
 
 !Object methodsFor: 'copying'!
@@ -931,10 +923,6 @@ asPoint
 	^Point x: self y: self
 !
 
-asJSONObject
-	^self
-!
-
 to: stop by: step
 	| array value pos |
 	value := self.
@@ -1122,6 +1110,16 @@ timeToRun
 	"Answer the number of milliseconds taken to execute this block."
 
 	^ Date millisecondsToRun: self
+!
+
+ensure: aBlock
+	| success |
+	success := false.
+	[self value. success := true. aBlock value]
+		on: Error
+		do: [:ex |
+			success ifFalse: [aBlock value].
+			ex signal]
 ! !
 
 !BlockClosure methodsFor: 'timeout/interval'!
@@ -1214,12 +1212,6 @@ not
 	>
 ! !
 
-!Boolean methodsFor: 'converting'!
-
-asJSONObject
-	^self
-! !
-
 !Boolean methodsFor: 'copying'!
 
 shallowCopy
@@ -1376,10 +1368,6 @@ asLocaleString
 
 asNumber
 	^self asMilliseconds
-!
-
-asJSONObject
-	^self
 ! !
 
 !Date methodsFor: 'printing'!
@@ -1533,6 +1521,10 @@ addAll: aCollection
 !
 
 remove: anObject
+    ^self remove: anObject ifAbsent: [self errorNotFound]
+!
+
+remove: anObject ifAbsent: aBlock
     self subclassResponsibility
 ! !
 
@@ -1923,10 +1915,6 @@ asNumber
 	<return Number(self)>
 !
 
-asJSONObject
-	^self
-!
-
 asLowercase
 	<return self.toLowerCase()>
 !
@@ -2205,10 +2193,6 @@ asJavascript
 	^'[', ((self collect: [:each | each asJavascript]) join: ', '),  ']'
 !
 
-asJSONObject
-	^self collect: [:each | each asJSONObject]
-!
-
 reversed
 	<return self._copy().reverse()>
 ! !
@@ -2318,6 +2302,10 @@ messageText: aString
 
 context
 	<return self.context>
+!
+
+jsStack
+	<return self.stack>
 ! !
 
 !Error methodsFor: 'signaling'!
@@ -2326,6 +2314,12 @@ signal
 	<self.context = smalltalk.getThisContext(); self.smalltalkError = true; throw(self)>
 ! !
 
+!Error methodsFor: 'testing'!
+
+isSmalltalkError
+	<return self.smalltalkError === true>
+! !
+
 !Error class methodsFor: 'instance creation'!
 
 signal: aString
@@ -2414,38 +2408,45 @@ key: aKey value: aValue
 ! !
 
 Collection subclass: #Dictionary
-	instanceVariableNames: 'keys'
+	instanceVariableNames: ''
 	category: 'Kernel'!
 
 !Dictionary methodsFor: 'accessing'!
 
 size
-	^keys size
+	^self keys size
 !
 
 associations
 	| associations |
 	associations := #().
-	keys do: [:each |
+	self keys do: [:each |
 	    associations add: (Association key: each value: (self at: each))].
 	^associations
 !
 
 keys
-	^keys copy
+	<
+		var keys = [];
+		for(var i in self) {
+			if(self.hasOwnProperty(i)) {
+				keys.push(i);
+			}
+		};
+		return keys;
+	>
 !
 
 values
-    	^keys collect: [:each | self at: each]
+    	^self keys collect: [:each | self at: each]
 !
 
 at: aKey put: aValue
-	(keys includes: aKey) ifFalse: [keys add: aKey].
 	^self basicAt: aKey put: aValue
 !
 
 at: aKey ifAbsent: aBlock
-	^(self keys includes: aKey)
+	^(self includesKey: aKey)
 		ifTrue: [self basicAt: aKey]
 		ifFalse: aBlock
 !
@@ -2480,12 +2481,18 @@ addAll: aDictionary
     	^aDictionary
 !
 
-remove: aKey
-    self removeKey: aKey
+removeKey: aKey
+    self remove: aKey
 !
 
-removeKey: aKey
-    keys remove: aKey
+remove: aKey ifAbsent: aBlock
+    ^self removeKey: aKey ifAbsent: aBlock
+!
+
+removeKey: aKey ifAbsent: aBlock
+	^(self includesKey: aKey) 
+		ifFalse: [aBlock value]
+		ifTrue: [self basicDelete: aKey]
 ! !
 
 !Dictionary methodsFor: 'comparing'!
@@ -2496,16 +2503,6 @@ removeKey: aKey
 	^self associations = aDictionary associations
 ! !
 
-!Dictionary methodsFor: 'converting'!
-
-asJSONObject
-	| object |
-	object := Object new.
-	self keysAndValuesDo: [:key :value |
-		object basicAt: key put: value asJSONObject].
-	^object
-! !
-
 !Dictionary methodsFor: 'copying'!
 
 shallowCopy
@@ -2563,30 +2560,21 @@ includes: anObject
 	^self values includes: anObject
 ! !
 
-!Dictionary methodsFor: 'initialization'!
-
-initialize
-    	super initialize.
-    	keys := #()
-! !
-
 !Dictionary methodsFor: 'printing'!
 
 printString
-	^ String streamContents: [:aStream|  
-                                  		aStream 
-                                  			nextPutAll: super printString;
-                                  			nextPutAll: '('.
-                                  		self associations 
-                                  			do: [:anAssociation|  
-                                                                      	aStream 
-                                                                      		nextPutAll: anAssociation key printString;
-                                                                      		nextPutAll: ' -> ';
-                                                                      		nextPutAll: anAssociation value printString]
-                                  
-                                 			separatedBy: [aStream nextPutAll: ' , '].
-                                  		aStream nextPutAll: ')'.
-                                 ]
+	^String streamContents: [:aStream|  
+		aStream 
+			nextPutAll: super printString;
+			nextPutAll: '('.
+				self associations 
+					do: [:anAssociation|  
+						aStream 
+							nextPutAll: anAssociation key printString;
+								nextPutAll: ' -> ';
+								nextPutAll: anAssociation value printString]
+							separatedBy: [aStream nextPutAll: ' , '].
+						aStream nextPutAll: ')']
 !
 
 storeOn: aStream
@@ -2597,6 +2585,12 @@ storeOn: aStream
 	aStream nextPutAll: '}'
 ! !
 
+!Dictionary methodsFor: 'testing'!
+
+includesKey: aKey
+	<return self.hasOwnProperty(aKey)>
+! !
+
 !Dictionary class methodsFor: 'instance creation'!
 
 fromPairs: aCollection
@@ -3306,187 +3300,3 @@ initialize
 	Transcript register: self new
 ! !
 
-Dictionary subclass: #Dictionary2
-	instanceVariableNames: 'keys'
-	category: 'Kernel'!
-
-!Dictionary2 methodsFor: 'accessing'!
-
-size
-	^keys size
-!
-
-associations
-	| associations |
-	associations := #().
-	keys do: [:each |
-	    associations add: (Association key: each value: (self at: each))].
-	^associations
-!
-
-keys
-	^keys copy
-!
-
-values
-    	^keys collect: [:each | self at: each]
-!
-
-at: aKey put: aValue
-	(keys includes: aKey) ifFalse: [keys add: aKey].
-	^self basicAt: aKey put: aValue
-!
-
-at: aKey ifAbsent: aBlock
-	^(self keys includes: aKey)
-		ifTrue: [self basicAt: aKey]
-		ifFalse: aBlock
-!
-
-at: aKey ifAbsentPut: aBlock
-    	^self at: aKey ifAbsent: [
-    	    self at: aKey put: aBlock value]
-!
-
-at: aKey ifPresent: aBlock
-	^(self basicAt: aKey) ifNotNil: [aBlock value: (self at: aKey)]
-!
-
-at: aKey ifPresent: aBlock ifAbsent: anotherBlock
-	^(self basicAt: aKey)
-	    ifNil: anotherBlock
-	    ifNotNil: [aBlock value: (self at: aKey)]
-!
-
-at: aKey
-	^self at: aKey ifAbsent: [self errorNotFound]
-! !
-
-!Dictionary2 methodsFor: 'adding/removing'!
-
-add: anAssociation
-    	self at: anAssociation key put: anAssociation value
-!
-
-addAll: aDictionary
-    	super addAll: aDictionary associations.
-    	^aDictionary
-!
-
-remove: aKey
-    self removeKey: aKey
-!
-
-removeKey: aKey
-    keys remove: aKey
-! !
-
-!Dictionary2 methodsFor: 'comparing'!
-
-= aDictionary
-	self class = aDictionary class ifFalse: [^false].
-	self size = aDictionary size ifFalse: [^false].
-	^self associations = aDictionary associations
-! !
-
-!Dictionary2 methodsFor: 'converting'!
-
-asJSONObject
-	| object |
-	object := Object new.
-	self keysAndValuesDo: [:key :value |
-		object basicAt: key put: value asJSONObject].
-	^object
-! !
-
-!Dictionary2 methodsFor: 'copying'!
-
-shallowCopy
-	| copy |
-	copy := self class new.
-	self associationsDo: [:each |
-	    copy at: each key  put: each value].
-	^copy
-!
-
-, aCollection
-	self shouldNotImplement
-!
-
-copyFrom: anIndex to: anotherIndex
-	self shouldNotImplement
-! !
-
-!Dictionary2 methodsFor: 'enumerating'!
-
-associationsDo: aBlock
-    	self associations do: aBlock
-!
-
-keysAndValuesDo: aBlock
-    	self associationsDo: [:each |
-    	    aBlock value: each key value: each value]
-!
-
-do: aBlock
-    	self values do: aBlock
-!
-
-select: aBlock
-    	| newDict |
-    	newDict := self class new.
-    	self keysAndValuesDo: [:key :value |
-    	    (aBlock value: value) ifTrue: [newDict at: key put: value]].
-    	^newDict
-!
-
-collect: aBlock
-    	| newDict |
-    	newDict := self class new.
-    	self keysAndValuesDo: [:key :value |
-    	    newDict at: key put: (aBlock value: value)].
-    	^newDict
-!
-
-detect: aBlock ifNone: anotherBlock
-	^self values detect: aBlock ifNone: anotherBlock
-!
-
-includes: anObject
-	^self values includes: anObject
-! !
-
-!Dictionary2 methodsFor: 'initialization'!
-
-initialize
-    	super initialize.
-    	keys := #()
-! !
-
-!Dictionary2 methodsFor: 'printing'!
-
-printString
-	^ String streamContents: [:aStream|  
-                                  		aStream 
-                                  			nextPutAll: super printString;
-                                  			nextPutAll: '('.
-                                  		self associations 
-                                  			do: [:anAssociation|  
-                                                                      	aStream 
-                                                                      		nextPutAll: anAssociation key printString;
-                                                                      		nextPutAll: ' -> ';
-                                                                      		nextPutAll: anAssociation value printString]
-                                  
-                                 			separatedBy: [aStream nextPutAll: ' , '].
-                                  		aStream nextPutAll: ')'.
-                                 ]
-!
-
-storeOn: aStream
-	aStream nextPutAll: '#{'.
-	self associations
-		do: [:each | each storeOn: aStream]
-		separatedBy: [ aStream nextPutAll: '. '].
-	aStream nextPutAll: '}'
-! !
-

Some files were not shown because too many files changed in this diff