當前位置: 首頁>>代碼示例>>C#>>正文


C# Machine.CreateClass方法代碼示例

本文整理匯總了C#中System.Machine.CreateClass方法的典型用法代碼示例。如果您正苦於以下問題:C# Machine.CreateClass方法的具體用法?C# Machine.CreateClass怎麽用?C# Machine.CreateClass使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Machine的用法示例。


在下文中一共展示了Machine.CreateClass方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: SendMessage

        public void SendMessage()
        {
            Machine machine = new Machine();
            IClass cls = machine.CreateClass("MyClass", null, "x", string.Empty);
            VmCompiler compiler = new VmCompiler();
            var method = compiler.CompileInstanceMethod("x: value x := value", cls);
            cls.DefineInstanceMethod(method);
            BaseObject obj = new BaseObject(cls, new object[1]);
            RemoteObject ro = new RemoteObject(obj, null);

            machine.SendMessage(ro, "x:", new object[] { 10 }, null);

            Assert.AreEqual(10, obj[0]);
        }
開發者ID:ajlopez,項目名稱:AjTalk,代碼行數:14,代碼來源:RemoteObjectTests.cs

示例2: GetAssociatedClassSameName

        public void GetAssociatedClassSameName()
        {
            Machine hostmachine = new Machine();
            IClass hostklass = hostmachine.CreateClass("Rectangle");
            hostmachine.SetGlobalObject(hostklass.Name, hostklass);

            Machine machine = new Machine();
            IClass klass = machine.CreateClass("Rectangle");
            machine.SetGlobalObject(klass.Name, klass);

            var result = hostmachine.GetAssociatedClass(klass);

            Assert.IsNotNull(result);
            Assert.AreSame(hostklass, result);
        }
開發者ID:ajlopez,項目名稱:AjTalk,代碼行數:15,代碼來源:HostMachineTests.cs

示例3: SerializeDeserializeClassWithInstanceMethod

        public void SerializeDeserializeClassWithInstanceMethod()
        {
            Machine machine = new Machine();
            IClass klass = machine.CreateClass("MyClass");
            Method method = (new VmCompiler()).CompileInstanceMethod("add: x to: y ^x + y", klass);
            klass.DefineInstanceMethod(method);

            machine = new Machine();
            Assert.IsNotNull(machine.GetGlobalObject("UndefinedObject"));
            Assert.IsNull(machine.GetGlobalObject("MyClass"));

            var result = this.Process(klass, machine);
            var undefined = machine.GetGlobalObject("UndefinedObject");

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(BaseClass));

            var bclass = (BaseClass)result;

            Assert.AreEqual("MyClass", bclass.Name);
            var bmethod = bclass.GetInstanceMethod("add:to:");
            Assert.IsNotNull(bmethod);
        }
開發者ID:ajlopez,項目名稱:AjTalk,代碼行數:23,代碼來源:ImageSerializerTests.cs

示例4: SerializeDeserializeClass

        public void SerializeDeserializeClass()
        {
            Machine machine = new Machine();
            IClass klass = machine.CreateClass("MyClass");
            klass.DefineInstanceVariable("a");
            klass.DefineInstanceVariable("b");
            klass.DefineClassVariable("c");
            klass.DefineClassVariable("d");

            var result = this.Process(klass, machine);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(BaseClass));

            var bclass = (BaseClass)result;

            Assert.AreEqual("MyClass", bclass.Name);
            Assert.IsNotNull(bclass.Behavior);
            Assert.AreEqual(0, bclass.GetInstanceVariableOffset("a"));
            Assert.AreEqual(1, bclass.GetInstanceVariableOffset("b"));
            Assert.AreEqual(0, bclass.GetClassVariableOffset("c"));
            Assert.AreEqual(1, bclass.GetClassVariableOffset("d"));
        }
開發者ID:ajlopez,項目名稱:AjTalk,代碼行數:23,代碼來源:ImageSerializerTests.cs

示例5: CompileClass

        internal static IClass CompileClass(string clsname, string[] varnames, string[] methods, string[] clsmethods)
        {
            Machine machine = new Machine();
            IClass cls = machine.CreateClass(clsname);

            if (varnames != null)
            {
                foreach (string varname in varnames)
                {
                    cls.DefineInstanceVariable(varname);
                }
            }

            if (methods != null)
            {
                foreach (string method in methods)
                {
                    ModelParser parser = new ModelParser(method);
                    MethodModel model = parser.ParseMethod();
                    Method newmethod = new Method(cls, model.Selector, method);
                    BytecodeCompiler compiler = new BytecodeCompiler(newmethod);
                    compiler.CompileMethod(model);
                    cls.DefineInstanceMethod(newmethod);
                }
            }

            if (clsmethods != null)
            {
                foreach (string method in clsmethods)
                {
                    ModelParser parser = new ModelParser(method);
                    MethodModel model = parser.ParseMethod();
                    Method newmethod = new Method(cls, model.Selector, method);
                    BytecodeCompiler compiler = new BytecodeCompiler(newmethod);
                    compiler.CompileMethod(model);
                    cls.DefineClassMethod(newmethod);
                }
            }

            return cls;
        }
開發者ID:ajlopez,項目名稱:AjTalk,代碼行數:41,代碼來源:BytecodeCompilerTests.cs

示例6: SerializeDeserializeMachineWithClassObjectAndValues

        public void SerializeDeserializeMachineWithClassObjectAndValues()
        {
            Machine machine = new Machine();
            IClass klass = machine.CreateClass("Rectangle", machine.UndefinedObjectClass, "x y", null);
            machine.SetGlobalObject(klass.Name, klass);
            machine.SetGlobalObject("One", 1);
            machine.SetGlobalObject("Name", "Adam");
            IObject rect = (IObject)klass.NewObject();
            machine.SetGlobalObject("MyRectangle", rect);
            rect[0] = 10;
            rect[1] = 20;
            var compiler = new VmCompiler();
            Method xmethod = compiler.CompileInstanceMethod("x ^x", klass);
            klass.DefineInstanceMethod(xmethod);
            Method ymethod = compiler.CompileInstanceMethod("y ^y", klass);
            klass.DefineInstanceMethod(ymethod);
            Method addmethod = compiler.CompileClassMethod("add: x to: y ^x + y", klass);
            klass.DefineClassMethod(addmethod);

            var result = this.Process(machine, machine);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(Machine));

            var newmachine = (Machine)result;

            CompareMachines(machine, newmachine);

            Assert.AreEqual(1, newmachine.GetGlobalObject("One"));
            Assert.AreEqual("Adam", newmachine.GetGlobalObject("Name"));

            var newvalue = newmachine.GetGlobalObject("MyRectangle");
            Assert.IsNotNull(newvalue);
            Assert.IsInstanceOfType(newvalue, typeof(IObject));

            var newrect = (IObject)newvalue;

            newvalue = newmachine.GetGlobalObject("Rectangle");
            Assert.IsNotNull(newvalue);
            Assert.IsInstanceOfType(newvalue, typeof(IBehavior));

            var newklass = (IBehavior)newvalue;

            Assert.IsNotNull(newrect.Behavior);
            Assert.AreEqual(newrect.Behavior, newklass);

            Assert.AreEqual(10, newrect[0]);
            Assert.AreEqual(20, newrect[1]);

            Assert.AreEqual(10, newrect.SendMessage(newmachine, "x", null));
            Assert.AreEqual(20, newrect.SendMessage(newmachine, "y", null));
            Assert.AreEqual(3, newklass.SendMessage(newmachine, "add:to:", new object[] { 1, 2 }));
        }
開發者ID:ajlopez,項目名稱:AjTalk,代碼行數:53,代碼來源:ImageSerializerTests.cs

示例7: DecompileGetSetInstanceVariable

        public void DecompileGetSetInstanceVariable()
        {
            Machine machine = new Machine();
            IClass cls = machine.CreateClass("TestClass");
            cls.DefineInstanceVariable("x");
            cls.DefineInstanceVariable("y");
            Block block = new Method(cls,"process");
            block.CompileByteCode(ByteCode.GetInstanceVariable, 0);
            block.CompileByteCode(ByteCode.SetInstanceVariable, 1);
            BlockDecompiler decompiler = new BlockDecompiler(block);

            var result = decompiler.Decompile();

            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Count);
            Assert.AreEqual("GetInstanceVariable x", result[0]);
            Assert.AreEqual("SetInstanceVariable y", result[1]);
        }
開發者ID:ajlopez,項目名稱:AjTalk,代碼行數:18,代碼來源:BlockDecompilerTests.cs

示例8: NotAssociatedSuperClass

        public void NotAssociatedSuperClass()
        {
            Machine hostmachine = new Machine();

            Machine machine = new Machine();
            IClass superclass = machine.CreateClass("Figure");
            machine.SetGlobalObject(superclass.Name, superclass);
            IClass klass = machine.CreateClass("Rectangle", superclass);
            machine.SetGlobalObject(klass.Name, klass);

            var result = hostmachine.GetAssociatedClass(klass);

            Assert.IsNotNull(result);
            Assert.AreSame(hostmachine.UndefinedObjectClass, result);
        }
開發者ID:ajlopez,項目名稱:AjTalk,代碼行數:15,代碼來源:HostMachineTests.cs

示例9: GetMetaClassByClassName

        public void GetMetaClassByClassName()
        {
            Machine machine = new Machine();
            IClass klass = machine.CreateClass("Rectangle");
            machine.SetGlobalObject(klass.Name, klass);

            var result = machine.GetMetaClass(klass.Name);

            Assert.IsNotNull(result);
            Assert.AreSame(klass.Behavior, result);
        }
開發者ID:ajlopez,項目名稱:AjTalk,代碼行數:11,代碼來源:HostMachineTests.cs

示例10: GetGlobalObjectFromHostMachine

        public void GetGlobalObjectFromHostMachine()
        {
            Machine hostmachine = new Machine();
            IClass hostklass = hostmachine.CreateClass("Rectangle");
            hostmachine.SetGlobalObject(hostklass.Name, hostklass);

            Machine machine = new Machine();
            machine.HostMachine = hostmachine;

            var result = machine.GetGlobalObject("Rectangle");

            Assert.IsNotNull(result);
            Assert.AreSame(hostklass, result);
        }
開發者ID:ajlopez,項目名稱:AjTalk,代碼行數:14,代碼來源:HostMachineTests.cs

示例11: GetAssociatedSuperMetaClass

        public void GetAssociatedSuperMetaClass()
        {
            Machine hostmachine = new Machine();
            IClass hostsuperclass = hostmachine.CreateClass("Figure");
            hostmachine.SetGlobalObject(hostsuperclass.Name, hostsuperclass);

            Machine machine = new Machine();
            IClass superclass = machine.CreateClass("Figure");
            machine.SetGlobalObject(superclass.Name, superclass);
            IClass klass = machine.CreateClass("Rectangle", superclass);
            machine.SetGlobalObject(klass.Name, klass);

            var result = hostmachine.GetAssociatedMetaClass((IMetaClass)klass.Behavior);

            Assert.IsNotNull(result);
            Assert.AreSame(hostsuperclass.Behavior, result);
        }
開發者ID:ajlopez,項目名稱:AjTalk,代碼行數:17,代碼來源:HostMachineTests.cs


注:本文中的System.Machine.CreateClass方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。