public void GetLambdaContent(PortableLambdaType expecting) { if (SelectFunction(expecting)) { _type = TypeFromMethod(_parseInfo.TranslateInfo, ChosenFunction); } }
bool SelectFunction(PortableLambdaType expecting) { foreach (var func in Group.Functions) { if (FuncValid(func, expecting)) { ChosenFunction = func; return(true); } } return(false); }
public void GetLambdaStatement(PortableLambdaType expecting) { bool found = false; _type = expecting; foreach (var func in Group.Functions) { if (func.Parameters.Length == expecting.Parameters.Length) { // Make sure the method implements the target lambda. for (int i = 0; i < func.Parameters.Length; i++) { if (func.Parameters[i].Type != null && !func.Parameters[i].Type.Implements(expecting.Parameters[i])) { continue; } } _chosenFunction = func; found = true; break; } } // If a compatible function was found, get the handler. if (found) { _functionInvoker = GetLambdaHandler(_chosenFunction); if (!_type.IsConstant()) { _identifier = _functionInvoker.GetIdentifier(_parseInfo); } // Get the variable's invoke info from the parameters. InvokedState = new IBridgeInvocable[_functionInvoker.ParameterCount()]; for (int i = 0; i < _functionInvoker.ParameterCount(); i++) { if (_functionInvoker.GetParameterVar(i) is Var var) { InvokedState[i] = var.BridgeInvocable; } } } else { _parseInfo.Script.Diagnostics.Error("No overload for '" + Group.Name + "' implements " + expecting.GetName(), _range); } }
bool FuncValid(IMethod method, PortableLambdaType expecting) { if (method.Parameters.Length != expecting.Parameters.Length) { return(false); } // Make sure the method implements the target lambda. for (int i = 0; i < method.Parameters.Length; i++) { var parameterType = method.Parameters[i].GetCodeType(_parseInfo.TranslateInfo); if (!parameterType.Implements(expecting.Parameters[i])) { return(false); } } return(true); }
public void Add(Scope addToScope, ITypeSupplier supplier) { // value => ... var noIndex = GetFuncMethod(); noIndex.Parameters = new CodeParameter[] { new CodeParameter("conditionLambda", ParameterDocumentation, PortableLambdaType.CreateConstantType(FuncType, ArrayOfType)) }; noIndex.Action = (actionSet, methodCall) => Executor.GetResult(Function, actionSet, inv => Lambda(methodCall).Invoke(actionSet, inv)); // (value, index) => ... var withIndex = GetFuncMethod(); withIndex.Parameters = new CodeParameter[] { new CodeParameter("conditionLambda", ParameterDocumentation, PortableLambdaType.CreateConstantType(FuncType, ArrayOfType, supplier.Number())) }; withIndex.Action = (actionSet, methodCall) => Executor.GetResult(Function, actionSet, inv => Lambda(methodCall).Invoke(actionSet, inv, Element.ArrayIndex())); addToScope.AddNativeMethod(new FuncMethod(noIndex)); addToScope.AddNativeMethod(new FuncMethod(withIndex)); }
public void Finalize(PortableLambdaType expecting) { _type = expecting; // If a compatible function was found, get the handler. if (ChosenFunction != null || SelectFunction(expecting)) { _constFunctionInvoker = GetLambdaHandler(ChosenFunction); // Get the variable's invoke info from the parameters. InvokedState = new IBridgeInvocable[_constFunctionInvoker.ParameterCount()]; for (int i = 0; i < _constFunctionInvoker.ParameterCount(); i++) { if (_constFunctionInvoker.GetParameterVar(i) is Var var) { InvokedState[i] = var.BridgeInvocable; } } } else { _parseInfo.Script.Diagnostics.Error("No overload for '" + Group.Name + "' implements " + expecting.GetName(), _range); } }
public LambdaInvokeInfo(PortableLambdaType lambdaType) { _lambdaType = lambdaType; }