public override object Eval(StackFrame stackFrame) { throw stackFrame.CreateException("CommaNodes should not be evaluated"); }
public override object Eval(StackFrame stackFrame) { if (Args.Count == 0) return null; object res = null; object first = Args[0]; var func = Utils.Eval(stackFrame, first) as LispFunc; if (func != null) { string name = ""; if (first is SymbolNode) { name = ((SymbolNode) first).Name; } var newStackFrame = new StackFrame(stackFrame, this); newStackFrame.Function = func; newStackFrame.FunctionName = name; Stack.Engine.OnBeginNotifyCall(newStackFrame, this, func, name); //function var invocation = new FunctionInvocation(func, Args, newStackFrame); try { res = func(invocation); } catch (Exception x) { throw newStackFrame.CreateException(x.Message); } Stack.Engine.OnEndNotifyCall(newStackFrame, this, func, name, res); //int recursions = 0; //while (res is TailRecursionValue) //{ // TailRecursionValue tail = res as TailRecursionValue; // if (!tail.ReadyForEval) // { // tail.ReadyForEval = true; // break; // } // else // { // recursions++; // ConsNode tailCons = tail.Expression as ConsNode; // newStackFrame = new StackFrame(stackFrame, this); // newStackFrame.Function = func; // newStackFrame.FunctionName = name; // Stack.Engine.OnBeginNotifyCall(newStackFrame, this, func, name); // invocation.Args = tailCons.Args; // try // { // res = func(invocation); // } // catch (Exception x) // { // throw newStackFrame.CreateException(x.Message); // } // Stack.Engine.OnEndNotifyCall(newStackFrame, this, func, name, res); // } //} return res; } throw stackFrame.CreateException(string.Format("Invalid function : {0}", this)); }