protected object EvaluateNativeFunction(Environment env, NativeFunction function) { if (function == null) { throw new ArgumentNullException(nameof(function), "null function"); } int pcount = function.ParametersCount; if (Count != pcount) { throw new LepException("bad number of arguments", this); } object[] arguments = new object[pcount]; int count = 0; foreach (IAstNode node in this) { arguments[count++] = node.Evaluate(env); } return(function.Invoke(arguments, this)); }
public object Evaluate(Environment env, object target) { UserFunction user = target as UserFunction; if (user != null) { return(EvaluateFunction(env, user)); } NativeFunction native = target as NativeFunction; if (native != null) { return(EvaluateNativeFunction(env, native)); } throw new LepException("bad function", this); }
protected object EvaluateNativeFunction(Environment env, NativeFunction function) { if (function == null) { throw new ArgumentNullException(nameof(function), "null function"); } int pcount = function.ParametersCount; Tuple arguments = Evaluate(env) as Tuple; if (arguments == null) { throw new LepException("bad expression argument", this); } if (arguments.Count != pcount) { throw new LepException("bad number of argument", this); } return(function.Invoke(arguments.GetArray(), this)); }