public Execute ( System.Machine machine, IObject self, object args ) : object | ||
machine | System.Machine | |
self | IObject | |
args | object | |
return | object |
public void CompileAndRun() { Machine machine = new Machine(); IClass cls = machine.CreateClass("TestClass"); cls.DefineInstanceVariable("x"); Method mth; mth = new Method(cls, "x:"); mth.CompileArgument("newX"); mth.CompileGet("newX"); mth.CompileSet("x"); cls.DefineInstanceMethod(mth); IObject obj = (IObject)cls.NewObject(); mth.Execute(machine, obj, new object[] { 10 }); Assert.AreEqual(10, obj[0]); }
static void Main(string[] args) { Machine machine = new Machine(); IClass cls = machine.CreateClass("Point"); cls.DefineInstanceVariable("x"); cls.DefineInstanceVariable("y"); IObject obj = (IObject) cls.NewObject(); Console.WriteLine(obj[0]); Console.WriteLine(obj[1]); obj[0]=0; obj[1]=1; Console.WriteLine(obj[0]); Console.WriteLine(obj[1]); Console.ReadLine(); Method mth = new Method(cls,"set:"); mth.CompileArgument("newValue"); mth.CompileGet("newValue"); mth.CompileSet("x"); mth.CompileGet("newValue"); mth.CompileSet("y"); mth.Execute(obj.Behavior,obj,new object[] {10}); cls.DefineInstanceMethod(mth); Console.WriteLine(obj[0]); Console.WriteLine(obj[1]); Console.ReadLine(); mth = new Method(cls,"x:y:"); mth.CompileArgument("newX"); mth.CompileArgument("newY"); mth.CompileGet("newX"); mth.CompileSet("x"); mth.CompileGet("newY"); mth.CompileSet("y"); mth.Execute(obj.Behavior,obj,new object[] {10,20}); cls.DefineInstanceMethod(mth); Console.WriteLine(obj[0]); Console.WriteLine(obj[1]); Console.ReadLine(); mth = new Method(cls,"x:"); mth.CompileArgument("newX"); mth.CompileGet("newX"); mth.CompileSet("x"); mth.Execute(obj.Behavior,obj,new object[] {10,20}); cls.DefineInstanceMethod(mth); mth = new Method(cls,"y:"); mth.CompileArgument("newY"); mth.CompileGet("newY"); mth.CompileSet("y"); mth.Execute(obj.Behavior,obj,new object[] {10,20}); cls.DefineInstanceMethod(mth); Parser compiler = new Parser("set2: newValue self x: newValue self y: newValue."); compiler.CompileInstanceMethod(cls); compiler = new Parser("x ^x."); compiler.CompileInstanceMethod(cls); compiler = new Parser("y ^y."); compiler.CompileInstanceMethod(cls); compiler = new Parser("x1 ^x+1."); compiler.CompileInstanceMethod(cls); compiler = new Parser("y1 ^y+1."); compiler.CompileInstanceMethod(cls); obj.SendMessage("set2:", new object[] { 10 }); Console.WriteLine(obj[0]); Console.WriteLine(obj[1]); Console.ReadLine(); obj.SendMessage("x:", new object[] { 30 }); Console.WriteLine(obj[0]); Console.WriteLine(obj[1]); Console.ReadLine(); obj.SendMessage("y:", new object[] { 20 }); Console.WriteLine(obj[0]); Console.WriteLine(obj[1]); Console.ReadLine(); Console.WriteLine(obj.SendMessage("x", null)); Console.WriteLine(obj.SendMessage("y", null)); Console.ReadLine(); }
public void NotRunWithMachine() { Machine machine = new Machine(); Method method; method = new Method("invalidMethod"); method.CompileArgument("newX"); method.CompileGet("newX"); method.CompileSet("GlobalX"); method.Execute(machine, new object[] { 10 }); }