Beispiel #1
0
        public override void Generate(Generator generator)
        {
            base.Generate(generator);
            parent.Generate(generator);

            TypeReference parentType = parent.TypeReference;

            generator.Symbols.Source(generator.Assembler.Region.CurrentLocation, this);

            generator.Assembler.PushValue();

            FunctionTypeReference callType = (FunctionTypeReference)parentType;

            List <TypeReference> callParameters = callType.FunctionParameters;

            int idx = 0;

            foreach (Expression parameter in parameters)
            {
                parameter.Generate(generator);
                callParameters[idx].GenerateConversion(parameter, generator, parameter.TypeReference);
                idx++;
                generator.Assembler.PushValue();
            }

            generator.Symbols.Source(generator.Assembler.Region.CurrentLocation, this);
            Placeholder retSite = generator.Assembler.CallFromStack(parameters.Count);

            if (generator.Resolver.CurrentDefinition != null)
            {
                generator.AddCallTraceEntry(retSite, this, generator.Resolver.CurrentDefinition.Name.DataModifierLess, generator.Resolver.CurrentFieldName);
            }
        }
Beispiel #2
0
        public override bool Equals(object obj)
        {
            FunctionTypeReference tr = obj as FunctionTypeReference;

            if (tr == null)
            {
                return(false);
            }
            if (!returnType.Equals(tr.returnType))
            {
                return(false);
            }
            if (parameters.Count != tr.parameters.Count)
            {
                return(false);
            }
            for (int i = 0; i < parameters.Count; ++i)
            {
                if (!parameters[i].Equals(tr.parameters[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #3
0
        public override bool SupportsImplicit(TypeReference value)
        {
            if (value == null)
            {
                return(true);
            }
            if (value is NullableTypeReference)
            {
                return(false);
            }
            FunctionTypeReference tr = value as FunctionTypeReference;

            if (tr == null)
            {
                return(false);
            }
            if (!returnType.SupportsImplicit(tr.returnType))
            {
                return(false);
            }
            if (parameters.Count != tr.parameters.Count)
            {
                return(false);
            }
            for (int i = 0; i < parameters.Count; ++i)
            {
                if (!parameters[i].SupportsImplicit(tr.parameters[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #4
0
        public override void Prepare(Generator generator, TypeReference inferredType)
        {
            base.Prepare(generator, inferredType);
            FunctionTypeReference ftr = null;

            if (inferredType is FunctionTypeReference)
            {
                ftr = (FunctionTypeReference)inferredType;
            }

            if (ftr != null)
            {
                returnType = ftr.ReturnType;
                for (int i = 0; (i < ftr.FunctionParameters.Count) && (i < parameters.Count); ++i)
                {
                    if (parameterTypes[i] == null)
                    {
                        parameterTypes[i] = ftr.FunctionParameters[i];
                    }
                }
            }
            for (int i = 0; i < parameterTypes.Count; ++i)
            {
                if (parameterTypes[i] == null)
                {
                    throw new CompilerException(this, Resource.TypeOfExpressionUnclear);
                }
            }
            if (returnType == null)
            {
                throw new CompilerException(this, Resource.TypeOfExpressionUnclear);
            }
        }
Beispiel #5
0
        public override void Prepare(Generator generator, TypeReference inferredType)
        {
            base.Prepare(generator, inferredType);
            if (NeedsInference(generator, inferredType))
            {
                for (int i = 0; i < parameters.Count; ++i)
                {
                    if (parameterTypes[i] == null)
                    {
                        parameters[i].Prepare(generator, null);
                        parameterTypes[i] = parameters[i].TypeReference;
                    }
                }
            }

            TypeReference inferred = new FunctionTypeReference(this, inferredType, parameterTypes, true);

            parent.Prepare(generator, inferred);

            TypeReference parentType = parent.TypeReference;

            if (!parentType.IsFunction)
            {
                throw new CompilerException(this, string.Format(Resource.Culture,
                                                                Resource.CannotUseExpressionOfTypeAsFunction, parent.TypeReference.TypeName.Data));
            }

            FunctionTypeReference callType       = (FunctionTypeReference)parentType;
            List <TypeReference>  callParameters = callType.FunctionParameters;

            if (parameters.Count != callParameters.Count)
            {
                throw new CompilerException(this, string.Format(Resource.Culture,
                                                                Resource.FunctionCallParameterCountMismatch, ParameterListString(callParameters), parameters.Count));
            }

            for (int i = 0; i < parameters.Count; ++i)
            {
                if (parameterTypes[i] == null)
                {
                    parameters[i].Prepare(generator, callParameters[i]);
                    parameterTypes[i] = parameters[i].TypeReference;
                }
            }

            type = callType.ReturnType;
        }
Beispiel #6
0
        protected override bool InnerNeedsInference(Generator generator, TypeReference inferredHint)
        {
            foreach (Expression parameter in parameters)
            {
                if (!parameter.NeedsInference(generator, null))
                {
                    parameter.Prepare(generator, null);
                    parameterTypes.Add(parameter.TypeReference);
                }
                else
                {
                    parameterTypes.Add(null);
                }
            }

            TypeReference inferred = new FunctionTypeReference(this, inferredHint, parameterTypes, true);

            return(parent.NeedsInference(generator, inferred));
        }