当前位置: 首页>>代码示例>>C#>>正文


C# Machine.SetGlobalObject方法代码示例

本文整理汇总了C#中System.Machine.SetGlobalObject方法的典型用法代码示例。如果您正苦于以下问题:C# Machine.SetGlobalObject方法的具体用法?C# Machine.SetGlobalObject怎么用?C# Machine.SetGlobalObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Machine的用法示例。


在下文中一共展示了Machine.SetGlobalObject方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ResumeNewProcess

        public void ResumeNewProcess()
        {
            AutoResetEvent handle = new AutoResetEvent(false);
            Machine machine = new Machine();
            VmCompiler compiler = new VmCompiler();
            machine.SetGlobalObject("handle", handle);
            Block block = compiler.CompileBlock("handle !Set");

            Process process = new Process(block, null, machine);
            machine.SetGlobalObject("process", process);

            compiler.CompileBlock("process resume").Execute(machine, null);

            if (!handle.WaitOne(500))
                Assert.Fail("Process didn't run");
        }
开发者ID:ajlopez,项目名称:AjTalk,代码行数:16,代码来源:ProcessTests.cs

示例2: RunProcess

        public void RunProcess()
        {
            AutoResetEvent handle = new AutoResetEvent(false);
            Machine machine = new Machine();
            machine.SetGlobalObject("handle", handle);
            Block block = (new VmCompiler()).CompileBlock("handle !Set");

            Process process = new Process(block, null, machine);

            process.Start();

            if (!handle.WaitOne(500))
                Assert.Fail("Process didn't run");
        }
开发者ID:ajlopez,项目名称:AjTalk,代码行数:14,代码来源:ProcessTests.cs

示例3: GetAssociatedBehaviorUsingMetaClass

        public void GetAssociatedBehaviorUsingMetaClass()
        {
            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.GetAssociatedBehavior(klass.Behavior);

            Assert.IsNotNull(result);
            Assert.AreSame(hostklass.Behavior, result);
        }
开发者ID:ajlopez,项目名称:AjTalk,代码行数:15,代码来源:HostMachineTests.cs

示例4: ExecuteBasicInstVarAtPut

        public void ExecuteBasicInstVarAtPut()
        {
            Machine machine = new Machine();
            IClass cls = CompileClass(
                "Rectangle",
                new string[] { "x", "y" },
                new string[] { "x ^x", "x: newX x := newX", "y ^y", "y: newY y := newY" });

            IObject iobj = (IObject)cls.NewObject();

            machine.SetGlobalObject("aRectangle", iobj);

            ModelParser parser = new ModelParser("aRectangle basicInstVarAt: 1 put: 200");
            this.compiler.CompileExpression(parser.ParseExpression());

            this.block.Execute(machine, null);

            Assert.AreEqual(200, iobj[0]);
            Assert.IsNull(iobj[1]);
        }
开发者ID:ajlopez,项目名称:AjTalk,代码行数:20,代码来源:BytecodeCompilerTests.cs

示例5: ExecuteBasicInstSizeInRectangle

        public void ExecuteBasicInstSizeInRectangle()
        {
            Machine machine = new Machine();
            IClass cls = CompileClass(
                "Rectangle",
                new string[] { "x", "y" },
                new string[] { "x ^x", "x: newX x := newX", "y ^y", "y: newY y := newY" });

            machine.SetGlobalObject("aRectangle", cls.NewObject());

            ModelParser parser = new ModelParser("^aRectangle basicInstSize");
            this.compiler.CompileExpression(parser.ParseExpression());

            object result = this.block.Execute(machine, null);

            Assert.AreEqual(2, result);
        }
开发者ID:ajlopez,项目名称:AjTalk,代码行数:17,代码来源:BytecodeCompilerTests.cs

示例6: SerializeDeserializeMachineWithNativeBehavior

        public void SerializeDeserializeMachineWithNativeBehavior()
        {
            Machine machine = new Machine();
            IBehavior behavior = machine.CreateNativeBehavior(null, typeof(System.IO.File));
            machine.RegisterNativeBehavior(typeof(System.IO.File), (NativeBehavior)behavior);
            machine.SetGlobalObject("File", behavior);

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

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

            var newmachine = (Machine)result;

            Assert.IsNotNull(newmachine.GetGlobalObject("File"));
            Assert.IsNotNull(newmachine.GetNativeBehavior(typeof(System.IO.File)));
        }
开发者ID:ajlopez,项目名称:AjTalk,代码行数:17,代码来源:ImageSerializerTests.cs

示例7: SerializeDeserializeMachineWithEnvironment

        public void SerializeDeserializeMachineWithEnvironment()
        {
            Machine machine = new Machine();
            Context environment = new Context(machine.Environment);
            machine.SetGlobalObject("MyEnvironment", environment);
            environment.SetValue("One", 1);

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

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

            var newmachine = (Machine)result;

            result = newmachine.GetGlobalObject("MyEnvironment");
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(Context));

            var newcontext = (Context)result;

            Assert.AreEqual(1, newcontext.GetValue("One"));
        }
开发者ID:ajlopez,项目名称:AjTalk,代码行数:22,代码来源:ImageSerializerTests.cs

示例8: 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

示例9: SerializeDeserializeMachinePreservingBuiltinMethods

        public void SerializeDeserializeMachinePreservingBuiltinMethods()
        {
            Machine machine = new Machine();
            machine.SetGlobalObject("Block", machine.GetNativeBehavior(typeof(Block)));

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

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

            var newmachine = (Machine)result;

            var blockbehavior = newmachine.GetNativeBehavior(typeof(Block));
            Assert.IsNotNull(blockbehavior);
        }
开发者ID:ajlopez,项目名称:AjTalk,代码行数:15,代码来源:ImageSerializerTests.cs

示例10: 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

示例11: 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

示例12: 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

示例13: 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.SetGlobalObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。