Exemple #1
0
        protected override Type ResolveInternal(Context ctx, bool mustReturn)
        {
            var argTypes = new List <Type>();

            foreach (var curr in Arguments)
            {
                if (curr.IsVariadic)
                {
                    Error(CompilerMessages.VariadicArgumentLambda);
                }

                var type = curr.GetArgumentType(ctx);
                argTypes.Add(type);

                if (type == typeof(UnspecifiedType))
                {
                    MustInferArgTypes = true;
                }
            }

            if (MustInferArgTypes)
            {
                return(FunctionalHelper.CreateLambdaType(argTypes.ToArray()));
            }

            Body.Scope.RegisterArguments(ctx, false, Arguments);

            var retType = Body.Resolve(ctx);

            return(FunctionalHelper.CreateDelegateType(retType, argTypes.ToArray()));
        }
Exemple #2
0
        protected override void EmitInternal(Context ctx, bool mustReturn)
        {
            var gen = ctx.CurrentMethod.Generator;

            // find constructor
            var type = FunctionalHelper.CreateDelegateType(Body.Resolve(ctx), _method.ArgumentTypes);
            var ctor = ctx.ResolveConstructor(type, new[] { typeof(object), typeof(IntPtr) });

            var closureInstance = ctx.Scope.ActiveClosure.ClosureVariable;

            gen.EmitLoadLocal(closureInstance);
            gen.EmitLoadFunctionPointer(_method.MethodBuilder);
            gen.EmitCreateObject(ctor.ConstructorInfo);
        }
Exemple #3
0
        /// <summary>
        /// Resolves the expression type in case of partial application.
        /// </summary>
        protected static Type resolvePartial(CallableWrapperBase wrapper, Type returnType, Type[] argTypes)
        {
            if (!wrapper.IsPartiallyApplied)
            {
                return(returnType);
            }

            var lambdaArgTypes = new List <Type>();

            for (var idx = 0; idx < argTypes.Length; idx++)
            {
                if (argTypes[idx] == typeof(UnspecifiedType))
                {
                    lambdaArgTypes.Add(wrapper.ArgumentTypes[idx]);
                }
            }

            return(FunctionalHelper.CreateDelegateType(returnType, lambdaArgTypes.ToArray()));
        }
Exemple #4
0
        protected override Type resolve(Context ctx, bool mustReturn)
        {
            var argTypes = new List <Type>();

            foreach (var curr in Arguments)
            {
                if (curr.IsVariadic)
                {
                    error(CompilerMessages.VariadicArgumentLambda);
                }

                var type = curr.GetArgumentType(ctx);
                argTypes.Add(type);

                if (type == typeof(UnspecifiedType))
                {
                    MustInferArgTypes = true;
                }
            }

            if (MustInferArgTypes)
            {
                return(FunctionalHelper.CreateLambdaType(argTypes.ToArray()));
            }

            Body.Scope.RegisterArguments(ctx, false, Arguments);

            var retType = Body.Resolve(ctx);

            if (_InferredDelegateType != null)
            {
                if (!_InferredReturnType.IsExtendablyAssignableFrom(retType))
                {
                    error(CompilerMessages.LambdaReturnTypeMismatch, _InferredDelegateType.Name, retType.Name, _InferredReturnType.Name);
                }

                return(_InferredDelegateType);
            }

            return(FunctionalHelper.CreateDelegateType(retType, argTypes.ToArray()));
        }