GetGlobalObject() public method

public GetGlobalObject ( string objname ) : object
objname string
return object
示例#1
0
 public void CompileAndExecuteTwoSimpleCommand()
 {
     Block block = this.compiler.CompileBlock("a := 1. b := 2");
     Machine machine = new Machine();
     block.Execute(machine, null);
     Assert.AreEqual(1, machine.GetGlobalObject("a"));
     Assert.AreEqual(2, machine.GetGlobalObject("b"));
 }
示例#2
0
        public void ExecuteBlockWithTwoCommands()
        {
            Loader loader = new Loader(new StringReader("One := 1.\nTwo := 2\n!\n"), new VmCompiler());
            Machine machine = new Machine();

            loader.LoadAndExecute(machine);

            Assert.AreEqual(1, machine.GetGlobalObject("One"));
            Assert.AreEqual(2, machine.GetGlobalObject("Two"));
        }
示例#3
0
        public void ExecuteBlock()
        {
            Loader loader = new Loader(new StringReader("One := 1\n!\n"), new SimpleCompiler());
            Machine machine = new Machine();

            loader.LoadAndExecute(machine);

            Assert.AreEqual(1, machine.GetGlobalObject("One"));
        }
示例#4
0
        public void DefineClassAndGetItsOutputString()
        {
            Loader loader = new Loader(@"DefineRectangleWithNewAndInitialize.st", new VmCompiler());
            Machine machine = new Machine();
            loader.LoadAndExecute(machine);

            BaseClass rectangle = (BaseClass)machine.GetGlobalObject("Rectangle");

            string output = rectangle.ToOutputString();

            Assert.IsNotNull(output);
            Assert.IsTrue(output.Contains("nil subclass:"));
            Assert.IsTrue(output.Contains("category: ''!"));
            Assert.IsTrue(output.Contains("!Rectangle class methods!"));
            Assert.IsTrue(output.Contains("!Rectangle methods!"));
            Assert.IsTrue(output.Contains("! !"));
            Assert.IsTrue(output.Contains("^x"));
            Assert.IsTrue(output.Contains("^y"));
            Assert.IsTrue(output.Contains("x := 10"));
            Assert.IsTrue(output.Contains("y := 20"));
        }
示例#5
0
        public void ExecuteSetObjectsFile()
        {
            Loader loader = new Loader(@"SetObjects.st", new VmCompiler());
            Machine machine = new Machine();

            loader.LoadAndExecute(machine);

            Assert.AreEqual(1, machine.GetGlobalObject("One"));
            Assert.AreEqual(2, machine.GetGlobalObject("Two"));
        }
示例#6
0
        public void ExecuteSetDotNetObjectFile()
        {
            Loader loader = new Loader(@"SetDotNetObject.st", new VmCompiler());
            Machine machine = new Machine();

            loader.LoadAndExecute(machine);

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

            Assert.IsNotNull(obj);
            Assert.IsInstanceOfType(obj, typeof(System.IO.FileInfo));
        }
示例#7
0
        public void ExecuteTrueIfTrueIfFalse()
        {
            Machine machine = new Machine();

            Block block = this.compiler.CompileBlock("true ifTrue: [GlobalName := 'bar'] ifFalse: [GlobalName := 'foo']");

            Assert.IsNotNull(block);

            block.Execute(machine, null);

            Assert.AreEqual("bar", machine.GetGlobalObject("GlobalName"));
        }
示例#8
0
        public void ExecuteBlock()
        {
            Machine machine = new Machine();

            object nil = machine.UndefinedObjectClass;

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

            Block block = this.compiler.CompileBlock("nil ifNil: [GlobalName := 'foo']");

            Assert.IsNotNull(block);

            block.Execute(machine, null);

            Assert.IsNotNull(machine.GetGlobalObject("GlobalName"));
        }
示例#9
0
        public void ExecuteTrueIfFalse()
        {
            Machine machine = new Machine();

            Parser compiler = new Parser("true ifFalse: [GlobalName := 'foo']");
            Block block = compiler.CompileBlock();

            Assert.IsNotNull(block);

            block.Execute(machine, null);

            Assert.IsNull(machine.GetGlobalObject("GlobalName"));
        }
示例#10
0
        public void DuplicateClassInOtherMachine()
        {
            Loader loader = new Loader(@"DefineRectangleWithNewAndInitialize.st", new SimpleCompiler());
            Machine machine = new Machine();
            loader.LoadAndExecute(machine);

            BaseClass rectangle = (BaseClass)machine.GetGlobalObject("Rectangle");

            string output = rectangle.ToOutputString();

            Loader loader2 = new Loader(new StringReader(output), new VmCompiler());
            Machine machine2 = new Machine();
            loader2.LoadAndExecute(machine2);

            BaseClass rectangle2 = (BaseClass)machine2.GetGlobalObject("Rectangle");

            Assert.IsNotNull(rectangle2);
            Assert.IsNotNull(rectangle2.GetClassMethod("new"));
            Assert.IsNotNull(rectangle2.GetInstanceMethod("x"));
            Assert.IsNotNull(rectangle2.GetInstanceMethod("y"));
            Assert.IsNotNull(rectangle2.GetInstanceMethod("x:"));
            Assert.IsNotNull(rectangle2.GetInstanceMethod("y:"));
            Assert.IsNotNull(rectangle2.GetInstanceMethod("initialize"));

            Parser parser = new Parser("Rectangle new");
            Block block = parser.CompileBlock();
            object result = block.Execute(machine2, null);

            Assert.IsNotNull(result);

            Assert.IsInstanceOfType(result, typeof(IObject));

            IObject iobj = (IObject)result;

            Assert.AreEqual(10, iobj[0]);
            Assert.AreEqual(20, iobj[1]);
        }
示例#11
0
        public void CompileAndRun()
        {
            Machine machine = new Machine();

            Block block;

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

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

            Assert.AreEqual(10, machine.GetGlobalObject("GlobalX"));
        }
示例#12
0
        public void CompileAndRunWithGlobal()
        {
            Block block;

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

            Machine machine = new Machine();

            block.Execute(machine, null);

            Assert.AreEqual(10, machine.GetGlobalObject("Global"));
        }
示例#13
0
        public void SetGlobalVariable()
        {
            Machine machine = new Machine();

            machine.SetGlobalObject("One", 1);

            Assert.AreEqual(1, machine.GetGlobalObject("One"));
        }
示例#14
0
        public void LoadLibrary2UsingLoadFile()
        {
            Machine machine = new Machine();

            machine.LoadFile("Library2.st");

            Assert.IsNotNull(machine.GetGlobalObject("Object"));
            Assert.IsNotNull(machine.GetGlobalObject("Behavior"));
            Assert.IsNotNull(machine.GetGlobalObject("ClassDescription"));
            Assert.IsNotNull(machine.GetGlobalObject("Class"));
            Assert.IsNotNull(machine.GetGlobalObject("Metaclass"));
            Assert.IsNotNull(machine.GetGlobalObject("UndefinedObject"));
        }
示例#15
0
        public void InitializeMachine()
        {
            Machine machine = new Machine();

            Assert.IsNotNull(machine.UndefinedObjectClass);
            Assert.IsNull(machine.ClassClass);

            Assert.IsNotNull(machine.Environment);

            var result = machine.GetGlobalObject("UndefinedObject");
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(IBehavior));
            Assert.IsInstanceOfType(result, typeof(BaseClass));

            var klass = (BaseClass)result;
            Assert.AreEqual("UndefinedObject", klass.Name);
            Assert.AreSame(klass, machine.UndefinedObjectClass);

            result = machine.GetGlobalObject("Machine");
            Assert.IsNotNull(result);
            Assert.AreSame(machine, result);

            result = machine.GetGlobalObject("Smalltalk");
            Assert.IsNotNull(result);
            Assert.AreSame(machine.Environment, result);

            Assert.AreSame(machine.Environment, machine.CurrentEnvironment);
        }
示例#16
0
        public void GetNullIfGlobalVariableDoesNotExists()
        {
            Machine machine = new Machine();

            Assert.IsNull(machine.GetGlobalObject("InexistenteGlobal"));
        }