public ErlangValue Evaluate(ErlangProcess process, string functionName, ErlangValue[] parameters) { ErlangValue error = null; if (functionName == "module_info") { if (parameters.Length == 0) { return(ModuleInfo); } else if (parameters.Length == 1) { if (parameters[0].Kind == ErlangValueKind.Atom) { var text = ((ErlangAtom)parameters[0]).Name; if (text == "functions") { return(AllFunctions); } else { // find matching tuple var list = ModuleInfo; while (list != null && list.Value != null) { Debug.Assert(list.Value is ErlangTuple); var tuple = (ErlangTuple)list.Value; Debug.Assert(tuple.Airity == 2); Debug.Assert(tuple.Values[0].Kind == ErlangValueKind.Atom); if (((ErlangAtom)tuple.Values[0]).Name == text) { Debug.Assert(tuple.Values[1].Kind == ErlangValueKind.List); return(tuple.Values[1]); } list = list.Tail as ErlangList; } return(new ErlangError("no matching tuple item")); } } else { error = new ErlangError("no matching function"); } } else { error = new ErlangError("no matching function"); } } error = error ?? parameters.FirstOrDefault(p => p.Kind == ErlangValueKind.Error); return(error ?? EvaluateLocal(process, functionName, parameters)); }
internal ErlangValue EvaluateInternal(ErlangProcess process, string functionName, ErlangValue[] parameters) { ErlangValue result; var function = GetFunction(functionName, parameters.Length); process.CallStack.Push(new ErlangStackFrame(Name, functionName, parameters.Length)); var overload = function.GetFunctionOverload(process, parameters); if (overload != null) { result = overload.Evaluate(process); } else { result = new ErlangError("no matching function found"); } process.CallStack.Pop(); return(result); }