public void TestInterpreterChain() { var p = new MockProcess (); var i1 = new Interpreter (p, null); var i2 = new Interpreter (p, i1); i2.ops.Add (new LoadConstant (anInteger)); i2.ops.Add (new Return ()); i2.Resume (); Assert.AreEqual (i1, p.i); var peek = i1.stack.Peek (); Assert.AreEqual (typeof(NativeInteger), peek.GetType ()); Assert.AreEqual (anInteger, ((NativeInteger)peek).Value); }
public void TestInterpreterSumLambda() { var p = new MockProcess (); var i = new Interpreter (p, null); for (int x = 0; x < 1000; x++) { i.ops.Add (new LoadConstant (2)); i.ops.Add (new LoadConstant (3)); i.ops.Add (new SumLambda ()); i.Resume (); i.stack.Pop (); } var peek = i.stack.Peek (); Assert.AreEqual (typeof(NativeInteger), peek.GetType ()); Assert.AreEqual (5, ((NativeInteger)peek).Value); }
public override void Resume() { Console.Write (ToString () + "> "); var input = Console.ReadLine ().Trim (); if (input.Count () > 0) { var interpreter = new Interpreter (process, this); try { interpreter.ops.AddRange (Parse (input)); process.ChangeIntepreter (interpreter); interpreter.Resume (); if (interpreter.stack.Count () > 0) Console.WriteLine (interpreter.stack.Peek ()); } catch (InvalidOperationException) { Console.WriteLine ("Syntax Error."); } } }
public override void ChangeIntepreter(Interpreter i) { this.i = i; }
public void TestLoadStore() { var p = new MockProcess(); var i = new Interpreter(p, null); i.ops.Add(new LoadConstant(anInteger)); i.ops.Add(new StoreLocalVar("temp")); i.ops.Add(new LoadLocalVar("temp")); i.Resume(); Assert.AreEqual(typeof(NativeInteger), i.stack.Peek().GetType()); Assert.AreEqual(anInteger, ((NativeInteger) i.stack.Peek()).Value); }
public virtual void Execute(Interpreter ctx) { action (ctx); }
public Interpreter(Process p,Interpreter sender) { this.process = p; this.sender = sender; this.context = new Object (); this.stack = new Stack<Object> (); this.ops = new List<Op> (); }