public CreateClass ( string name, string varnames ) : IClass | ||
name | string | |
varnames | string | |
return | IClass |
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); }
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()); }
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; }