CompileSet() 공개 메소드

public CompileSet ( string name ) : void
name string
리턴 void
예제 #1
0
        public void Compile()
        {
            Machine machine = new Machine();
            IClass cls = machine.CreateClass("TestClass");
            cls.DefineInstanceVariable("x");
            cls.DefineClassVariable("count");

            Block block;

            block = new Method(cls, "x:");
            block.CompileArgument("newX");
            block.CompileGet("newX");
            block.CompileGet("count");
            block.CompileSet("x");

            Assert.AreEqual(1, block.Arity);
            Assert.AreEqual(0, block.NoLocals);
            Assert.IsNotNull(block.ByteCodes);
            Assert.IsTrue(block.ByteCodes.Length > 0);

            BlockDecompiler decompiler = new BlockDecompiler(block);
            var result = decompiler.Decompile();

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Count);

            Assert.AreEqual("GetArgument newX", result[0]);
            Assert.AreEqual("GetClassVariable count", result[1]);
            Assert.AreEqual("SetInstanceVariable x", result[2]);
        }
예제 #2
0
        public void Compile()
        {
            Machine machine = new Machine();
            IClass cls = machine.CreateClass("TestClass");
            cls.DefineClassVariable("count");
            cls.DefineInstanceVariable("x");

            Method mth;

            mth = new Method(cls, "x:");
            mth.CompileArgument("newX");
            mth.CompileGet("newX");
            mth.CompileSet("x");

            cls.DefineInstanceMethod(mth);

            Assert.AreEqual(mth, cls.GetInstanceMethod("x:"));
            Assert.AreEqual("x", mth.GetInstanceVariableName(0));
        }
예제 #3
0
        public void CompileAndRun()
        {
            Machine machine = new Machine();
            IClass cls = machine.CreateClass("TestClass");
            cls.DefineInstanceVariable("x");

            Method mth;

            mth = new Method(cls, "x:");
            mth.CompileArgument("newX");
            mth.CompileGet("newX");
            mth.CompileSet("x");

            cls.DefineInstanceMethod(mth);

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

            mth.Execute(machine, obj, new object[] { 10 });

            Assert.AreEqual(10, obj[0]);
        }
예제 #4
0
파일: Class1.cs 프로젝트: ajlopez/AjTalk
        static void Main(string[] args)
        {
            Machine machine = new Machine();
            IClass cls = machine.CreateClass("Point");
            cls.DefineInstanceVariable("x");
            cls.DefineInstanceVariable("y");
            IObject obj = (IObject) cls.NewObject();
            Console.WriteLine(obj[0]);
            Console.WriteLine(obj[1]);
            obj[0]=0;
            obj[1]=1;
            Console.WriteLine(obj[0]);
            Console.WriteLine(obj[1]);
            Console.ReadLine();
            Method mth = new Method(cls,"set:");
            mth.CompileArgument("newValue");
            mth.CompileGet("newValue");
            mth.CompileSet("x");
            mth.CompileGet("newValue");
            mth.CompileSet("y");
            mth.Execute(obj.Behavior,obj,new object[] {10});
            cls.DefineInstanceMethod(mth);
            Console.WriteLine(obj[0]);
            Console.WriteLine(obj[1]);
            Console.ReadLine();
            mth = new Method(cls,"x:y:");
            mth.CompileArgument("newX");
            mth.CompileArgument("newY");
            mth.CompileGet("newX");
            mth.CompileSet("x");
            mth.CompileGet("newY");
            mth.CompileSet("y");
            mth.Execute(obj.Behavior,obj,new object[] {10,20});
            cls.DefineInstanceMethod(mth);
            Console.WriteLine(obj[0]);
            Console.WriteLine(obj[1]);
            Console.ReadLine();

            mth = new Method(cls,"x:");
            mth.CompileArgument("newX");
            mth.CompileGet("newX");
            mth.CompileSet("x");
            mth.Execute(obj.Behavior,obj,new object[] {10,20});
            cls.DefineInstanceMethod(mth);

            mth = new Method(cls,"y:");
            mth.CompileArgument("newY");
            mth.CompileGet("newY");
            mth.CompileSet("y");
            mth.Execute(obj.Behavior,obj,new object[] {10,20});
            cls.DefineInstanceMethod(mth);

            Parser compiler = new Parser("set2: newValue self x: newValue self y: newValue.");
            compiler.CompileInstanceMethod(cls);

            compiler = new Parser("x ^x.");
            compiler.CompileInstanceMethod(cls);

            compiler = new Parser("y ^y.");
            compiler.CompileInstanceMethod(cls);

            compiler = new Parser("x1 ^x+1.");
            compiler.CompileInstanceMethod(cls);

            compiler = new Parser("y1 ^y+1.");
            compiler.CompileInstanceMethod(cls);

            obj.SendMessage("set2:", new object[] { 10 });
            Console.WriteLine(obj[0]);
            Console.WriteLine(obj[1]);
            Console.ReadLine();

            obj.SendMessage("x:", new object[] { 30 });
            Console.WriteLine(obj[0]);
            Console.WriteLine(obj[1]);
            Console.ReadLine();

            obj.SendMessage("y:", new object[] { 20 });
            Console.WriteLine(obj[0]);
            Console.WriteLine(obj[1]);
            Console.ReadLine();

            Console.WriteLine(obj.SendMessage("x", null));
            Console.WriteLine(obj.SendMessage("y", null));
            Console.ReadLine();
        }
예제 #5
0
        public void NotRunWithMachine()
        {
            Machine machine = new Machine();

            Method method;

            method = new Method("invalidMethod");
            method.CompileArgument("newX");
            method.CompileGet("newX");
            method.CompileSet("GlobalX");

            method.Execute(machine, new object[] { 10 });
        }