Inheritance: ICompiler
コード例 #1
0
ファイル: AssertTests.cs プロジェクト: ajlopez/AjTalk
 public void LoadEnvironmentTests()
 {
     VmCompiler compiler = new VmCompiler();
     var block = compiler.CompileBlock(File.ReadAllText("AssertTests\\EnvironmentTests.st"));
     Assert.IsNotNull(block);
     Assert.IsTrue(block.NoConstants > 0);
 }
コード例 #2
0
ファイル: RemoteObjectTests.cs プロジェクト: ajlopez/AjTalk
        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]);
        }
コード例 #3
0
ファイル: ProcessTests.cs プロジェクト: ajlopez/AjTalk
        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");
        }
コード例 #4
0
        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 }));
        }
コード例 #5
0
ファイル: VmCompilerTests.cs プロジェクト: ajlopez/AjTalk
 public void Setup()
 {
     this.compiler = new VmCompiler();
 }
コード例 #6
0
ファイル: EvaluateTests.cs プロジェクト: ajlopez/AjTalk
 public void EvaluateSuperNew()
 {
     IClass testclass = this.machine.CreateClass("Test1", null, "x", string.Empty);
     this.machine.SetCurrentEnvironmentObject("Test1", testclass);
     IClass testclass2 = this.machine.CreateClass("Test2", testclass, "y", string.Empty);
     this.machine.SetCurrentEnvironmentObject("Test2", testclass2);
     VmCompiler compiler = new VmCompiler();
     testclass.DefineInstanceMethod(compiler.CompileInstanceMethod("x: value x := value", testclass));
     testclass2.DefineInstanceMethod(compiler.CompileInstanceMethod("y: value y := value", testclass2));
     testclass.DefineClassMethod(compiler.CompileClassMethod("new ^self basicNew x: 10", testclass));
     testclass2.DefineClassMethod(compiler.CompileClassMethod("new ^super new y: 20", testclass2));
     var result = this.Evaluate("Test2 new");
     Assert.IsNotNull(result);
     Assert.IsInstanceOfType(result, typeof(IObject));
     var iobj = (IObject)result;
     Assert.AreEqual(10, iobj[0]);
     Assert.AreEqual(20, iobj[1]);
 }