Inheritance: ICompiler
Esempio n. 1
0
 public void LoadEnvironmentTests()
 {
     VmCompiler compiler = new VmCompiler();
     var block = compiler.CompileBlock(File.ReadAllText("AssertTests\\EnvironmentTests.st"));
     Assert.IsNotNull(block);
     Assert.IsTrue(block.NoConstants > 0);
 }
Esempio n. 2
0
        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]);
        }
Esempio n. 3
0
        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");
        }
Esempio n. 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 }));
        }
Esempio n. 5
0
 public void Setup()
 {
     this.compiler = new VmCompiler();
 }
Esempio n. 6
0
 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]);
 }