public virtual void PushAllReverse(GenericStack <T> inOther) { for (int n = Count - 1; n >= 0; n--) { inOther.Push(this[n]); } }
public void Execute(Interpreter inI) { try { GenericStack <T> stack = inI.GetStack <T>(); stack.Push(func()); } catch (NoReturnValueException) { } }
/* XXX This is how things could be. */ // public virtual int ExecuteInstruction(OneOf<ProgramTree, ProgramAtom> o) { // o.Switch( // tree => { // foreach(var child in tree.children.Reverse()) { // if (child.isLeaf) // _execStack.Push(child.Value); // else // _execStack.Push(child); // } // _execStack.Push(tree.Value); // }, // atom => { // atom.Switch( // i => _intStack.Push(i), // f => _floatStack.Push(f), // b => _boolStack.Push(b), // s => { // Instruction i; // if (_instructions.TryGetValue(InstructionCase(s), out i)) { // i.Execute(this); // } else { // _nameStack.Push(s); // } // return 0; // }, // instr => instr.Execute(this)); // }); // } public virtual int ExecuteInstruction(object inObject) { switch (Type.GetTypeCode(inObject.GetType())) { case TypeCode.Int16: case TypeCode.Int32: case TypeCode.Int64: _intStack.Push((int)inObject); return(0); case TypeCode.Single: case TypeCode.Double: _floatStack.Push((float)inObject); return(0); case TypeCode.Boolean: _boolStack.Push((bool)inObject); return(0); case TypeCode.String: Instruction i; // if (_instructions.TryGetValue(InstructionCase((string)inObject), out i)) { if (!quoting && _instructions.TryGetValue((string)inObject, out i)) { i.Execute(this); } else { _nameStack.Push((string)inObject); quoting = false; } return(0); case TypeCode.Object: if (inObject is Program) { Program p = (Program)inObject; p.PushAllReverse(_execStack); return(0); } else if (inObject is Instruction) { ((Instruction)inObject).Execute(this); return(0); } else { throw new Exception("No idea how to execute instruction " + inObject); } default: throw new Exception("No idea how to execute instruction " + inObject); // return -1; } }