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); }
public void ShouldCreateWithTokenizer() { PepsiMachine machine = new PepsiMachine(); Evaluator evaluator = new Evaluator(machine, new Tokenizer("NewClass : Object()")); Assert.IsNotNull(evaluator); }
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); }
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)); }
public void ShouldCreateWithString() { PepsiMachine machine = new PepsiMachine(); Evaluator evaluator = new Evaluator(machine, "NewClass : Object()"); Assert.IsNotNull(evaluator); }
public void ShouldSetGlobalVariable() { PepsiMachine machine = new PepsiMachine(); machine.SetGlobalObject("One", 1); Assert.AreEqual(1, machine.GetGlobalObject("One")); }
public void ShouldGetObjectBehavior() { PepsiMachine machine = new PepsiMachine(); IObject obj = (IObject)machine.GetGlobalObject("Object"); Assert.AreEqual(obj.Behavior, obj.Send("vtable")); }
private PepsiMachine LoadFile(string fileName) { PepsiMachine machine = new PepsiMachine(); Evaluator evaluator = new Evaluator(machine, File.ReadAllText(fileName)); evaluator.Evaluate(); return(machine); }
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)); }
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); }
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); }
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")); }
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:")); }
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")); }
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")); }
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); }
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); }
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); }
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); }
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")); }
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); }
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); }
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); }
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)); }
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); }
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)); }
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); }
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")); }
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); }
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); }