コード例 #1
0
        public void ShouldExecuteInstSizeInRectangle()
        {
            PepsiMachine machine = new PepsiMachine();

            string[] methods =
            {
                "x [^x]",
                "x: newX [x := newX]",
                "y [^y]",
                "y: newY [y := newY]"
            };

            IClass cls = CompileClass(
                "Rectangle",
                new string[] { "x", "y" },
                methods);

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

            Compiler compiler = new Compiler("^aRectangle instSize");
            Block    block    = compiler.CompileBlock();

            Assert.IsNotNull(block);

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

            Assert.AreEqual(2, result);
        }
コード例 #2
0
        public void ShouldCreateWithTokenizer()
        {
            PepsiMachine machine   = new PepsiMachine();
            Evaluator    evaluator = new Evaluator(machine, new Tokenizer("NewClass : Object()"));

            Assert.IsNotNull(evaluator);
        }
コード例 #3
0
        public void ShouldCreateObjectInstance()
        {
            Block block = new Block();

            block.CompileGet("Object");
            block.CompileSend("class");
            block.CompileSend("basicNew");
            block.CompileReturnPop();

            PepsiMachine machine = new PepsiMachine();

            object obj = block.Execute(machine, null);

            Assert.IsNotNull(obj);
            Assert.IsInstanceOfType(obj, typeof(IObject));

            IObject obj2 = (IObject)obj;

            Assert.IsNotNull(obj2.Behavior);

            IObject obj3 = (IObject)machine.GetGlobalObject("Object");

            Assert.AreEqual(obj2.Behavior, obj3.Behavior);
            Assert.AreEqual(0, obj2.Size);
        }
コード例 #4
0
        public void ShouldExecuteInstAtPut()
        {
            PepsiMachine machine = new PepsiMachine();

            string[] methods =
            {
                "x [^x]",
                "x: newX [x := newX]",
                "y [^y]",
                "y: newY [y := newY]"
            };

            IClass cls = CompileClass(
                "Rectangle",
                new string[] { "x", "y" },
                methods);

            IObject iobj = cls.CreateInstance();

            machine.SetGlobalObject("aRectangle", iobj);

            Compiler compiler = new Compiler("aRectangle instAt: 0 put: 200");
            Block    block    = compiler.CompileBlock();

            Assert.IsNotNull(block);

            block.Execute(machine, null);

            Assert.AreEqual(200, iobj.GetValueAt(0));
            Assert.IsNull(iobj.GetValueAt(1));
        }
コード例 #5
0
        public void ShouldCreateWithString()
        {
            PepsiMachine machine   = new PepsiMachine();
            Evaluator    evaluator = new Evaluator(machine, "NewClass : Object()");

            Assert.IsNotNull(evaluator);
        }
コード例 #6
0
        public void ShouldSetGlobalVariable()
        {
            PepsiMachine machine = new PepsiMachine();

            machine.SetGlobalObject("One", 1);

            Assert.AreEqual(1, machine.GetGlobalObject("One"));
        }
コード例 #7
0
        public void ShouldGetObjectBehavior()
        {
            PepsiMachine machine = new PepsiMachine();

            IObject obj = (IObject)machine.GetGlobalObject("Object");

            Assert.AreEqual(obj.Behavior, obj.Send("vtable"));
        }
コード例 #8
0
        private PepsiMachine LoadFile(string fileName)
        {
            PepsiMachine machine   = new PepsiMachine();
            Evaluator    evaluator = new Evaluator(machine, File.ReadAllText(fileName));

            evaluator.Evaluate();

            return(machine);
        }
コード例 #9
0
        public void ShouldCreateAnObject()
        {
            PepsiMachine machine = new PepsiMachine();

            object obj = DotNetObject.NewObject(Type.GetType("System.IO.FileInfo"), new object[] { "AnyFile.txt" });

            Assert.IsNotNull(obj);
            Assert.IsInstanceOfType(obj, typeof(System.IO.FileInfo));
        }
コード例 #10
0
        public void ShouldDelegateObject()
        {
            PepsiMachine machine = new PepsiMachine();

            IObject obj       = (IObject)machine.GetGlobalObject("Object");
            IObject delegated = (IObject)obj.Send("delegated");

            Assert.AreEqual(obj.Behavior, ((IBehavior)delegated.Behavior).Parent);
            Assert.AreEqual(obj.Behavior.Behavior, delegated.Behavior.Behavior);
        }
コード例 #11
0
        public void ShouldInvokeMethod()
        {
            PepsiMachine machine = new PepsiMachine();

            object obj = DotNetObject.SendMessage(new System.IO.FileInfo("NonexistentFile.txt"), "exists", null);

            Assert.IsNotNull(obj);
            Assert.IsInstanceOfType(obj, typeof(bool));
            Assert.IsFalse((bool)obj);
        }
コード例 #12
0
        public void ShouldEvaluateDefine()
        {
            PepsiMachine machine   = new PepsiMachine();
            Evaluator    evaluator = new Evaluator(machine, "Object new [^self class basicNew]");

            evaluator.Evaluate();

            IObject obj = (IObject)machine.GetGlobalObject("Object");

            Assert.IsNotNull(obj.Behavior.Send("lookup:", "new"));
        }
コード例 #13
0
        public void ShouldCompileSetMethod()
        {
            PepsiMachine machine = new PepsiMachine();
            IClass       cls     = machine.CreateClass();

            cls.AddVariable("x");
            Compiler compiler = new Compiler("x: newX [x := newX]");

            compiler.CompileInstanceMethod(cls);

            Assert.IsNotNull(cls.Lookup("x:"));
        }
コード例 #14
0
        public void ShouldCompileMethodWithLocals()
        {
            PepsiMachine machine = new PepsiMachine();
            IClass       cls     = machine.CreateClass();

            cls.AddVariable("x");
            Compiler compiler = new Compiler("x [| temp | temp := x. ^temp]");

            compiler.CompileInstanceMethod(cls);

            Assert.IsNotNull(cls.Lookup("x"));
        }
コード例 #15
0
        public void ShouldCompileAndRunWithGlobal()
        {
            Block block;

            block = new Block();
            block.CompileGetConstant(10);
            block.CompileSet("Global");

            PepsiMachine machine = new PepsiMachine();

            block.Execute(machine);

            Assert.AreEqual(10, machine.GetGlobalObject("Global"));
        }
コード例 #16
0
        public void ShouldLoadList01()
        {
            PepsiMachine machine = this.LoadFile("List01.st");

            Assert.IsNotNull(machine.GetGlobalObject("List"));
            Assert.IsNotNull(machine.GetGlobalObject("list1"));

            IObject list  = (IObject)machine.GetGlobalObject("List");
            IObject list1 = (IObject)machine.GetGlobalObject("list1");

            Assert.AreEqual(2, list.Size);
            Assert.AreEqual(2, list1.Size);

            Assert.AreEqual(list.Behavior, list1.Behavior);
        }
コード例 #17
0
        public void ShouldEvaluateBlockWithCommands()
        {
            PepsiMachine machine   = new PepsiMachine();
            Evaluator    evaluator = new Evaluator(machine, "[newobject := Object class basicNew. otherobject := Object class basicNew]");

            evaluator.Evaluate();

            object newObject = machine.GetGlobalObject("newobject");

            Assert.IsNotNull(newObject);

            object otherObject = machine.GetGlobalObject("otherobject");

            Assert.IsNotNull(otherObject);
        }
コード例 #18
0
        public void ShouldEvaluateDefineAndInvoke()
        {
            PepsiMachine machine   = new PepsiMachine();
            Evaluator    evaluator = new Evaluator(machine, "Object new [^self class basicNew] newObject := [^Object new]");

            evaluator.Evaluate();

            IObject obj  = (IObject)machine.GetGlobalObject("newObject");
            IObject obj2 = (IObject)machine.GetGlobalObject("Object");

            Assert.IsNotNull(obj);
            Assert.IsNotNull(obj2);

            Assert.AreEqual(obj.Behavior, obj2.Behavior);
        }
コード例 #19
0
        public void ShouldEvaluateDefineAndInvokeEmptyBlock()
        {
            PepsiMachine machine   = new PepsiMachine();
            Evaluator    evaluator = new Evaluator(machine, "Object initialize [] result := [^Object initialize]");

            evaluator.Evaluate();

            IObject obj  = (IObject)machine.GetGlobalObject("result");
            IObject obj2 = (IObject)machine.GetGlobalObject("Object");

            Assert.IsNotNull(obj);
            Assert.IsNotNull(obj2);

            Assert.AreEqual(obj, obj2);
        }
コード例 #20
0
        public void ShouldCompileAndRun()
        {
            PepsiMachine machine = new PepsiMachine();

            Block block;

            block = new Block();
            block.CompileArgument("newX");
            block.CompileGet("newX");
            block.CompileSet("GlobalX");

            block.Execute(machine, 10);

            Assert.AreEqual(10, machine.GetGlobalObject("GlobalX"));
        }
コード例 #21
0
        public void ShouldLoadObject01()
        {
            PepsiMachine machine = this.LoadFile("Object01.st");

            Assert.IsNotNull(machine.GetGlobalObject("obj1"));
            Assert.IsNotNull(machine.GetGlobalObject("Object"));

            IObject obj  = (IObject)machine.GetGlobalObject("Object");
            IObject obj1 = (IObject)machine.GetGlobalObject("obj1");

            Assert.AreEqual(0, obj.Size);
            Assert.AreEqual(0, obj1.Size);

            Assert.AreEqual(obj.Behavior, obj1.Behavior);
        }
コード例 #22
0
        public void ShouldEvaluateAssignment()
        {
            PepsiMachine machine   = new PepsiMachine();
            Evaluator    evaluator = new Evaluator(machine, "newObject := [^Object class basicNew]");

            evaluator.Evaluate();

            object newObject = machine.GetGlobalObject("newObject");

            Assert.IsNotNull(newObject);
            Assert.IsInstanceOfType(newObject, typeof(AjSoda.IObject));

            IObject obj = (IObject)machine.GetGlobalObject("Object");

            Assert.AreEqual(((AjSoda.IObject)newObject).Behavior, obj.Behavior);
        }
コード例 #23
0
        public void ShouldCreateDelegatedPrototypeWithVariables()
        {
            PepsiMachine machine   = new PepsiMachine();
            Evaluator    evaluator = new Evaluator(machine, "List : Object(head tail)");

            evaluator.Evaluate();

            IObject listObject = (IObject)machine.GetGlobalObject("List");
            IObject objObject  = (IObject)machine.GetGlobalObject("Object");

            Assert.IsNotNull(listObject);
            Assert.IsNotNull(objObject);

            Assert.AreEqual(((IBehavior)listObject.Behavior).Parent, objObject.Behavior);

            Assert.AreEqual(2, listObject.Size);
        }
コード例 #24
0
        public void ShouldLoadList02()
        {
            PepsiMachine machine = this.LoadFile("List02.st");

            Assert.IsNotNull(machine.GetGlobalObject("list1"));
            Assert.IsNotNull(machine.GetGlobalObject("list2"));

            IObject list1 = (IObject)machine.GetGlobalObject("list1");
            IObject list2 = (IObject)machine.GetGlobalObject("list2");

            Assert.AreEqual(2, list1.Size);
            Assert.AreEqual(2, list1.Size);

            Assert.AreEqual("Hello", list1.GetValueAt(0));
            Assert.AreEqual("World", list2.GetValueAt(0));
            Assert.AreEqual(list2, list1.GetValueAt(1));
        }
コード例 #25
0
        public void ShouldExecuteInstSize()
        {
            PepsiMachine machine = new PepsiMachine();

            machine.CreatePrototype("nil");
            object nil = machine.GetGlobalObject("nil");

            Assert.IsNotNull(nil);
            Assert.IsInstanceOfType(nil, typeof(IObject));

            Compiler compiler = new Compiler("^nil class basicNew instSize");
            Block    block    = compiler.CompileBlock();

            Assert.IsNotNull(block);

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

            Assert.AreEqual(0, result);
        }
コード例 #26
0
        public void ShouldExecuteClass()
        {
            PepsiMachine machine = new PepsiMachine();

            object obj = machine.GetGlobalObject("Object");

            Assert.IsNotNull(obj);
            Assert.IsInstanceOfType(obj, typeof(IObject));

            Compiler compiler = new Compiler("^Object class basicNew class");
            Block    block    = compiler.CompileBlock();

            Assert.IsNotNull(block);

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

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(IClass));
        }
コード例 #27
0
        public void ShouldCompile()
        {
            PepsiMachine machine = new PepsiMachine();
            IClass       cls     = machine.CreateClass();

            cls.AddVariable("x");

            Block block;

            block = new Block();
            block.CompileArgument("newX");
            block.CompileGet("newX");
            block.CompileSet("x");

            Assert.AreEqual(1, block.Arity);
            Assert.AreEqual(0, block.NoLocals);
            Assert.IsNotNull(block.ByteCodes);
            Assert.IsTrue(block.ByteCodes.Length > 0);
        }
コード例 #28
0
        public void ShouldAddMethod()
        {
            PepsiMachine machine = new PepsiMachine();

            object obj = machine.GetGlobalObject("Object");

            Assert.IsNotNull(obj);
            Assert.IsInstanceOfType(obj, typeof(IObject));

            Compiler compiler = new Compiler("^Object class methodAt: #newMethod put: [self instSize]");
            Block    block    = compiler.CompileBlock();

            Assert.IsNotNull(block);

            block.Execute(machine, null);

            IObject iobj = (IObject)obj;

            Assert.IsNotNull(((IClass)iobj.Behavior).Lookup("newMethod"));
        }
コード例 #29
0
        public void ShouldExecuteBasicNew()
        {
            PepsiMachine machine = new PepsiMachine();
            IClass       cls     = CompileClass(
                "Rectangle",
                new string[] { "x", "y" },
                null);

            machine.SetGlobalObject("Rectangle", cls.CreateInstance());

            Compiler compiler = new Compiler("^Rectangle class basicNew");
            Block    block    = compiler.CompileBlock();

            Assert.IsNotNull(block);

            object obj = block.Execute(machine, null);

            Assert.IsNotNull(obj);
            Assert.IsInstanceOfType(obj, typeof(IObject));
            Assert.AreEqual(cls, ((IObject)obj).Behavior);
        }
コード例 #30
0
        public void ShouldDefineSubclass()
        {
            Block block = new Block();

            block.CompileGet("Object");
            block.CompileSend("class");
            block.CompileSend("delegated");
            block.CompileSet("NewClass");

            PepsiMachine machine = new PepsiMachine();

            block.Execute(machine, null);

            object obj = machine.GetGlobalObject("NewClass");

            Assert.IsNotNull(obj);
            Assert.IsInstanceOfType(obj, typeof(IObject));

            IObject iobj = (IObject)obj;
            IClass  cls  = (IClass)iobj.Behavior;

            Assert.AreEqual(0, cls.InstanceSize);
        }