Exemplo n.º 1
0
 public AphidPartialFunction(
     //AphidExpression expression,
     AphidFunction function,
     AphidObject[] applied)
 {
     //Expression = expression;
     Function = function;
     Applied  = applied;
 }
Exemplo n.º 2
0
        public Delegate ConvertFunctionWrapper(
            MethodInfo method,
            Type delegateType,
            AphidFunction function,
            Type[] genericArguments)
        {
            var methodParams = method.GetParameters();
            var wrapper      = new AphidFunctionWrapper(Interpreter, function);

            var call = wrapper
                       .GetType()
                       .GetMethods()
                       .SingleOrDefault(x =>
                                        x.Name == "Call" &&
                                        (method.ReturnType == typeof(void) ?
                                         x.ReturnType == typeof(void) :
                                         x.ReturnType != typeof(void)) &&
                                        methodParams.Length == x.GetParameters().Length);

            if (call == null)
            {
                throw Interpreter.CreateRuntimeException(
                          "Could not match conversion function for {0}",
                          method);
            }

            if (methodParams.Length > 0 ||
                method.ReturnType != typeof(void))
            {
                var paramTypes = methodParams
                                 .Select(x => !x.ParameterType.IsGenericParameter ?
                                         x.ParameterType :
                                         genericArguments[x.ParameterType.GenericParameterPosition]);

                call = call.MakeGenericMethod(
                    (method.ReturnType.IsGenericParameter ?
                     paramTypes.Concat(new[] { genericArguments[method.ReturnType.GenericParameterPosition] }) :
                     method.ReturnType != typeof(void) ?
                     paramTypes.Concat(new[] { method.ReturnType }) :
                     paramTypes)
                    .ToArray());
            }

            if (delegateType.ContainsGenericParameters)
            {
                var curDelegateArgs    = delegateType.GetGenericArguments();
                var delegateTypeParams = new Type[curDelegateArgs.Length];

                for (var i = 0; i < curDelegateArgs.Length; i++)
                {
                    delegateTypeParams[i] = !curDelegateArgs[i].IsGenericParameter ?
                                            curDelegateArgs[i] :
                                            genericArguments[curDelegateArgs[i].GenericParameterPosition];
                }

                delegateType = delegateType
                               .GetGenericTypeDefinition()
                               .MakeGenericType(delegateTypeParams);
            }

            return(call.CreateDelegate(delegateType, wrapper));
        }
Exemplo n.º 3
0
 public AphidFunctionWrapper(AphidInterpreter interpreter, AphidFunction function)
     : base(interpreter) => Function = function;