Пример #1
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);
        }