Наследование: BaseClassDescription, IMetaClass
Пример #1
0
 public void CreateMetaClassWithVariablesAndSpaces()
 {
     IMetaClass metaclass = new BaseMetaClass(null, null, this.machine, " x   y ");
     Assert.AreEqual(0, metaclass.GetInstanceVariableOffset("x"));
     Assert.AreEqual(1, metaclass.GetInstanceVariableOffset("y"));
     Assert.AreEqual("x y", metaclass.GetInstanceVariableNamesAsString());
 }
Пример #2
0
        public Machine(bool iscurrent)
        {
            if (iscurrent)
                this.SetCurrent();

            IMetaClass meta = new BaseMetaClass(null, null, this, string.Empty);
            this.nilclass = (BaseClass)meta.CreateClass("UndefinedObject", string.Empty);

            // TODO review, nil object never receives a message, see Send in Execution block
            this.nilclass.DefineInstanceMethod(new BehaviorDoesNotUnderstandMethod(this, this.nilclass));
            this.nilclass.DefineClassMethod(new BehaviorDoesNotUnderstandMethod(this, this.nilclass));
            this.nilclass.DefineInstanceMethod(new FunctionalMethod("ifNil:", this.nilclass, this.IfNil));
            this.nilclass.DefineInstanceMethod(new FunctionalMethod("ifNotNil:", this.nilclass, this.IfNotNil));
            this.nilclass.DefineInstanceMethod(new FunctionalMethod("isNil", this.nilclass, this.IsNil));
            this.nilclass.DefineInstanceMethod(new FunctionalMethod("isNotNil", this.nilclass, this.IsNotNil));

            // Native Behaviors
            var nativeObjectBehavior = new NativeObjectBehavior(meta, null, this);
            var enumerableBehavior = new EnumerableBehavior(meta, nativeObjectBehavior, this);
            var booleanBehavior = new BooleanBehavior(meta, nativeObjectBehavior, this);
            var listBehavior = new ListBehavior(meta, enumerableBehavior, this);
            var stringBehavior = new StringBehavior(meta, nativeObjectBehavior, this);

            this.RegisterNativeBehavior(typeof(IEnumerable), enumerableBehavior);
            this.RegisterNativeBehavior(typeof(bool), booleanBehavior);
            this.RegisterNativeBehavior(typeof(IList), listBehavior);
            this.RegisterNativeBehavior(typeof(Block), new BlockBehavior(meta, this.nilclass, this));
            this.RegisterNativeBehavior(typeof(string), stringBehavior);

            // Global Objects
            this.SetGlobalObject("UndefinedObject", this.nilclass);
            this.SetGlobalObject("Machine", this);
            this.SetGlobalObject("Smalltalk", this.environment);
        }
Пример #3
0
 public void CreateClass()
 {
     IMetaClass metaclass = new BaseMetaClass(null, null, this.machine, "x y");
     IClass cls = metaclass.CreateClass("MyClass", "a b");
     Assert.AreEqual(cls.Behavior, metaclass);
     Assert.AreEqual("MyClass", cls.Name);
     Assert.AreEqual(cls.MetaClass, metaclass);
     Assert.AreEqual("a b", cls.GetInstanceVariableNamesAsString());
 }
Пример #4
0
 public void CreateMetaClass()
 {
     IMetaClass metaclass = new BaseMetaClass(null, null, this.machine, string.Empty);
     Assert.IsNull(metaclass.Behavior);
     Assert.AreSame(this.machine.CurrentEnvironment, metaclass.Scope);
 }
Пример #5
0
        public IBehavior CreateNativeBehavior(IBehavior superclass, Type type)
        {
            IMetaClass supermeta = null;

            if (superclass != null)
                supermeta = superclass.MetaClass;

            IMetaClass meta = new BaseMetaClass(this.metaclassclass, supermeta, this, string.Empty);
            NativeBehavior behavior = new NativeBehavior(meta, superclass, this, type);
            return behavior;
        }
Пример #6
0
        public IClass CreateClass(string clsname, IClass superclass, string instancevarnames, string classvarnames)
        {
            var oldcls = this.CurrentEnvironment.GetValue(clsname) as IClass;

            if (oldcls != null)
            {
                oldcls.RedefineClassVariables(classvarnames);
                oldcls.RedefineInstanceVariables(instancevarnames);
                return oldcls;
            }

            IMetaClass supermeta = null;

            if (superclass == null)
                if (this.classclass != null)
                    superclass = this.classclass;
                else
                    superclass = this.nilclass;

            if (superclass != null)
                supermeta = superclass.MetaClass;

            // TODO review using a provisional metaclassclass, for test that doesn't define Metaclass yet
            IMetaClass meta = new BaseMetaClass(this.metaclassclass ?? this.nilclass.Behavior, supermeta, this, null);
            IClass cls = meta.CreateClass(clsname, instancevarnames);
            cls.RedefineClassVariables(classvarnames);

            return cls;
        }