Example #1
0
        public IInvokeResult Invoke(InvokeData invokeInfo)
        {
            var parseInfo = invokeInfo.ParseInfo;

            // Create the overload chooser for the invoke function.
            var overloadChooser = new OverloadChooser(
                new MethodOverload[] { new MethodOverload(_lambdaType.InvokeFunction) },
                parseInfo,
                invokeInfo.Scope,
                invokeInfo.Getter,
                invokeInfo.TargetRange,
                invokeInfo.CallRange,
                invokeInfo.FullRange,
                new OverloadError("lambda '" + _lambdaType.GetName() + "'")
                );

            // Apply the parameters.
            overloadChooser.Apply(invokeInfo.Context.Parameters, false, null);

            var invoke = (LambdaInvoke)overloadChooser.Overload;

            invoke?.CheckRecursionAndRestricted(parseInfo, invokeInfo.TargetRange, invokeInfo.Target);

            if (invokeInfo.UsedAsExpression && !invoke.LambdaType.ReturnsValue)
            {
                parseInfo.Script.Diagnostics.Error("The lambda '" + invoke.LambdaType.GetName() + "' does not return a value", invokeInfo.TargetRange);
            }

            return(new LambdaInvokeResult(parseInfo.TranslateInfo, invoke, overloadChooser.ParameterResults, invokeInfo.Target));
        }
        public IInvokeResult Invoke(InvokeData invokeInfo)
        {
            var parseInfo = invokeInfo.ParseInfo;

            // Create the overload chooser for the invoke function.
            var overloadChooser = new OverloadChooser(
                new IParameterCallable[] { _lambdaType.InvokeFunction },
                parseInfo,
                invokeInfo.Scope,
                invokeInfo.Getter,
                invokeInfo.TargetRange,
                invokeInfo.CallRange,
                new OverloadError("lambda '" + _lambdaType.GetName() + "'")
                );

            // Apply the parameters.
            overloadChooser.Apply(invokeInfo.Context.Parameters);

            var invoke = (LambdaInvoke)overloadChooser.Overload;

            invoke?.Call(parseInfo, invokeInfo.TargetRange);

            return(new LambdaInvokeResult(invoke, overloadChooser.Values, invokeInfo.Target));
            // return new FunctionInvokeResult(parseInfo, invokeInfo.TargetRange, invokeInfo.UsedAsExpression, invoke, overloadChooser.Values, overloadChooser.AdditionalParameterData, overloadChooser.Match);
        }
        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.Implements(expecting.Parameters[i]))
                        {
                            continue;
                        }
                    }

                    _chosenFunction = func;
                    found           = true;
                    break;
                }
            }

            // If a compatible function was found, get the handler.
            if (found)
            {
                _functionHandler = GetLambdaHandler(_chosenFunction);
                _identifier      = _parseInfo.TranslateInfo.GetComponent <LambdaGroup>().Add(_functionHandler);

                // Get the variable's invoke info from the parameters.
                InvokedState = new IBridgeInvocable[_functionHandler.ParameterCount()];
                for (int i = 0; i < _functionHandler.ParameterCount(); i++)
                {
                    if (_functionHandler.GetParameterVar(i) is Var var)
                    {
                        InvokedState[i] = var.BridgeInvocable;
                    }
                }
            }
            else
            {
                _parseInfo.Script.Diagnostics.Error("No overload for '" + Group.Name + "' implements " + expecting.GetName(), _range);
            }
        }
Example #4
0
        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);
            }
        }