public void CompileAndExecuteTwoSimpleCommand() { ModelParser parser = new ModelParser("a := 1. b := 2"); this.compiler.CompileExpressions(parser.ParseExpressions()); Machine machine = new Machine(); this.block.Execute(machine, null); Assert.AreEqual(1, machine.GetGlobalObject("a")); Assert.AreEqual(2, machine.GetGlobalObject("b")); }
public void CreateRemotingAndClientServerAndExecuteCommand() { Machine machine = new Machine(); RemotingHostServer server = new RemotingHostServer(machine, 10003, "Server3"); Machine machine2 = new Machine(); RemotingHostClient client = new RemotingHostClient("localhost", 10003, "Server3"); client.Execute("aNumber := 3"); Assert.AreEqual(3, machine.GetGlobalObject("aNumber")); Assert.IsNull(machine2.GetGlobalObject("aNumber")); server.Stop(); }
public void SerializeDeserializeClassWithInstanceMethod() { Machine machine = new Machine(); IClass klass = machine.CreateClass("MyClass"); Method method = (new VmCompiler()).CompileInstanceMethod("add: x to: y ^x + y", klass); klass.DefineInstanceMethod(method); machine = new Machine(); Assert.IsNotNull(machine.GetGlobalObject("UndefinedObject")); Assert.IsNull(machine.GetGlobalObject("MyClass")); var result = this.Process(klass, machine); var undefined = machine.GetGlobalObject("UndefinedObject"); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(BaseClass)); var bclass = (BaseClass)result; Assert.AreEqual("MyClass", bclass.Name); var bmethod = bclass.GetInstanceMethod("add:to:"); Assert.IsNotNull(bmethod); }
public void CreateRemotingAndClientServerAndExportClass() { Loader loader = new Loader(@"DefineRectangleWithNewAndInitialize.st", new SimpleCompiler()); Machine machine = new Machine(true); RemotingHostServer server = new RemotingHostServer(machine, 10004, "Server4"); Machine machine2 = new Machine(true); loader.LoadAndExecute(machine2); BaseClass rect = (BaseClass)machine2.GetGlobalObject("Rectangle"); RemotingHostClient client = new RemotingHostClient("localhost", 10004, "Server4"); client.Execute(rect.ToOutputString()); object result = machine.GetGlobalObject("Rectangle"); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(BaseClass)); object newresult = client.Evaluate("Rectangle new"); Assert.IsNotNull(newresult); Assert.IsInstanceOfType(newresult, typeof(IObject)); IObject newrect = (IObject)newresult; Assert.AreSame(rect, newrect.Behavior); Assert.AreEqual(10, newrect[0]); Assert.AreEqual(20, newrect[1]); server.Stop(); }
public void ExecuteTrueIfTrueIfFalse() { Machine machine = new Machine(); ModelParser parser = new ModelParser("true ifTrue: [GlobalName := 'bar'] ifFalse: [GlobalName := 'foo']"); this.compiler.CompileExpression(parser.ParseExpression()); this.block.Execute(machine, null); Assert.AreEqual("bar", machine.GetGlobalObject("GlobalName")); }
public void ExecuteBlock() { Machine machine = new Machine(); object nil = machine.UndefinedObjectClass; Assert.IsNotNull(nil); Assert.IsInstanceOfType(nil, typeof(IClass)); ModelParser parser = new ModelParser("nil ifNil: [GlobalName := 'foo']"); this.compiler.CompileExpression(parser.ParseExpression()); this.block.Execute(machine, null); Assert.IsNotNull(machine.GetGlobalObject("GlobalName")); }
private static void CompareMachines(Machine machine, Machine newmachine) { Assert.IsNotNull(newmachine.UndefinedObjectClass); Assert.IsNotNull(newmachine.GetGlobalObject("UndefinedObject")); Assert.AreNotEqual(machine.GetGlobalObject("UndefinedObject"), newmachine.GetGlobalObject("UndefinedObject")); var names = machine.GetGlobalNames(); var newnames = machine.GetGlobalNames(); Assert.IsNotNull(newnames); Assert.AreEqual(names.Count, newnames.Count); foreach (var newname in newnames) Assert.IsTrue(names.Contains(newname)); }
public void GetGlobalObjectFromHostMachine() { Machine hostmachine = new Machine(); IClass hostklass = hostmachine.CreateClass("Rectangle"); hostmachine.SetGlobalObject(hostklass.Name, hostklass); Machine machine = new Machine(); machine.HostMachine = hostmachine; var result = machine.GetGlobalObject("Rectangle"); Assert.IsNotNull(result); Assert.AreSame(hostklass, result); }