Procházet zdrojové kódy

Merge pull request #769 from herby/empty-protoobject

Empty protoobject
Nicolas Petton před 11 roky
rodič
revize
7c088d507d

+ 1 - 1
js/Kernel-Infrastructure.js

@@ -2,7 +2,7 @@ define("amber_core/Kernel-Infrastructure", ["amber_vm/smalltalk", "amber_vm/nil"
 smalltalk.addPackage('Kernel-Infrastructure');
 smalltalk.packages["Kernel-Infrastructure"].transport = {"type":"amd","amdNamespace":"amber_core"};
 
-smalltalk.addClass('AbstractProxy', smalltalk.nil, [], 'Kernel-Infrastructure');
+smalltalk.addClass('AbstractProxy', smalltalk.ProtoObject, [], 'Kernel-Infrastructure');
 smalltalk.AbstractProxy.comment="I provide a basic set of methods for proxies handling `#doesNotUnderstand:` so that inspectors, debuggers, etc. won't fail.";
 smalltalk.addMethod(
 smalltalk.method({

+ 19 - 1
js/Kernel-Objects.js

@@ -2,7 +2,25 @@ define("amber_core/Kernel-Objects", ["amber_vm/smalltalk", "amber_vm/nil", "ambe
 smalltalk.addPackage('Kernel-Objects');
 smalltalk.packages["Kernel-Objects"].transport = {"type":"amd","amdNamespace":"amber_core"};
 
-smalltalk.addClass('Object', smalltalk.nil, [], 'Kernel-Objects');
+smalltalk.addClass('ProtoObject', smalltalk.nil, [], 'Kernel-Objects');
+
+smalltalk.addMethod(
+smalltalk.method({
+selector: "initialize",
+category: 'initialization',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+return self}, function($ctx1) {$ctx1.fill(self,"initialize",{},smalltalk.ProtoObject.klass)})},
+args: [],
+source: "initialize",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.ProtoObject.klass);
+
+
+smalltalk.addClass('Object', smalltalk.ProtoObject, [], 'Kernel-Objects');
 smalltalk.Object.comment="**I am the root of the Smalltalk class system**. All classes in the system are subclasses of me.\x0a\x0aI provide default behavior common to all normal objects, such as:\x0a\x0a- accessing\x0a- copying\x0a- comparison\x0a- error handling\x0a- message sending\x0a- reflection\x0a\x0aAlso utility messages that all objects should respond to are defined here.\x0a\x0aI have no instance variable.\x0a\x0a##Access\x0a\x0aInstance variables can be accessed with `#instVarAt:` and `#instVarAt:put:`. `#instanceVariableNames` answers a collection of all instance variable names.\x0aAccessing JavaScript properties of an object is done through `#basicAt:`, `#basicAt:put:` and `basicDelete:`.\x0a\x0a##Copying\x0a\x0aCopying an object is handled by `#copy` and `#deepCopy`. The first one performs a shallow copy of the receiver, while the second one performs a deep copy.\x0aThe hook method `#postCopy` can be overriden in subclasses to copy fields as necessary to complete the full copy. It will be sent by the copy of the receiver.\x0a\x0a##Comparison\x0a\x0aI understand equality `#=` and identity `#==` comparison.\x0a\x0a##Error handling\x0a\x0a- `#halt` is the typical message to use for inserting breakpoints during debugging.\x0a- `#error:` throws a generic error exception\x0a- `#doesNotUnderstand:` handles the fact that there was an attempt to send the given message to the receiver but the receiver does not understand this message.\x0a\x09Overriding this message can be useful to implement proxies for example.";
 smalltalk.addMethod(
 smalltalk.method({

+ 1 - 1
st/Kernel-Infrastructure.st

@@ -1,5 +1,5 @@
 Smalltalk current createPackage: 'Kernel-Infrastructure'!
-nil subclass: #AbstractProxy
+ProtoObject subclass: #AbstractProxy
 	instanceVariableNames: ''
 	package: 'Kernel-Infrastructure'!
 !AbstractProxy commentStamp!

+ 10 - 1
st/Kernel-Objects.st

@@ -1,5 +1,14 @@
 Smalltalk current createPackage: 'Kernel-Objects'!
-nil subclass: #Object
+nil subclass: #ProtoObject
+	instanceVariableNames: ''
+	package: 'Kernel-Objects'!
+
+!ProtoObject class methodsFor: 'initialization'!
+
+initialize
+! !
+
+ProtoObject subclass: #Object
 	instanceVariableNames: ''
 	package: 'Kernel-Objects'!
 !Object commentStamp!

+ 7 - 4
support/boot.js

@@ -97,8 +97,10 @@ function inherits(child, parent) {
 /* SmalltalkRoot is the hidden root of the Amber hierarchy.
  All objects including `Object` inherit from SmalltalkRoot */
 function SmalltalkRoot() {}
+function SmalltalkProtoObject() {}
+inherits(SmalltalkProtoObject, SmalltalkRoot);
 function SmalltalkObject() {}
-inherits(SmalltalkObject, SmalltalkRoot);
+inherits(SmalltalkObject, SmalltalkProtoObject);
 
 function Smalltalk() {}
 inherits(Smalltalk, SmalltalkObject);
@@ -119,7 +121,8 @@ function RootBrik(brikz, st) {
 	this.__init__ = function () {
 		st.addPackage("Kernel-Objects");
 		st.addPackage("Kernel-Infrastructure");
-		st.wrapClassName("Object", "Kernel-Objects", SmalltalkObject, undefined, false);
+		st.wrapClassName("ProtoObject", "Kernel-Objects", SmalltalkProtoObject, undefined, false);
+		st.wrapClassName("Object", "Kernel-Objects", SmalltalkObject, st.ProtoObject, false);
 		st.wrapClassName("Smalltalk", "Kernel-Infrastructure", Smalltalk, st.Object, false);
 		st.wrapClassName("UndefinedObject", "Kernel-Objects", SmalltalkNil, st.Object, false);
 	};
@@ -326,8 +329,8 @@ function ClassesBrik(brikz, st) {
 		st.wrapClassName("Class", "Kernel-Classes", SmalltalkClass, st.Behavior, false);
 
 		// Manually bootstrap the metaclass hierarchy
-		st.Object.klass.superclass = rootAsClass.klass = st.Class;
-		addSubclass(st.Object.klass);
+		st.ProtoObject.klass.superclass = rootAsClass.klass = st.Class;
+		addSubclass(st.ProtoObject.klass);
 
 		st.wrapClassName("Package", "Kernel-Infrastructure", SmalltalkPackage, st.Object, false);
 	};