示例#1
0
        private RedwoodType(Type cSharpType)
        {
            CSharpType = cSharpType;
            Name       = CSharpType.Name;

            Type[] genericArgs = cSharpType.GenericTypeArguments;
            GenericArguments = new RedwoodType[genericArgs.Length];

            for (int i = 0; i < genericArgs.Length; i++)
            {
                GenericArguments[i] = GetForCSharpType(genericArgs[i]);
            }

            // TODO: base type's generic arguments?
            if (cSharpType != typeof(object) && cSharpType.BaseType != null)
            {
                BaseType = GetForCSharpType(cSharpType.BaseType);
            }

            // TODO: Is LINQ too slow for a runtime context?
            Constructor = RuntimeUtil.CanonicalizeLambdas(
                cSharpType
                .GetConstructors()
                .Select(constructor => new ExternalLambda(this, constructor))
                .ToArray()
                );
        }
示例#2
0
        static RedwoodType()
        {
            specialMappedTypes.Add("?", null);

            specialMappedTypes.Add("int", GetForCSharpType(typeof(int)));
            specialMappedTypes.Add("string", GetForCSharpType(typeof(string)));
            specialMappedTypes.Add("double", GetForCSharpType(typeof(double)));
            specialMappedTypes.Add("bool", GetForCSharpType(typeof(bool)));
            specialMappedTypes.Add("object", GetForCSharpType(typeof(object)));

            NullType.staticSlotMap = new Dictionary <string, int>();
            NullType.staticSlotMap[RuntimeUtil.NameForOperator(BinaryOperator.Equals)]    = 0;
            NullType.staticSlotMap[RuntimeUtil.NameForOperator(BinaryOperator.NotEquals)] = 1;
            NullType.staticSlotTypes = new RedwoodType[]
            {
                RedwoodType.GetForLambdaArgsTypes(
                    typeof(InPlaceLambda),
                    RedwoodType.GetForCSharpType(typeof(bool)),
                    new RedwoodType[] { null, null }
                    ),
                RedwoodType.GetForLambdaArgsTypes(
                    typeof(InPlaceLambda),
                    RedwoodType.GetForCSharpType(typeof(bool)),
                    new RedwoodType[] { null, null }
                    )
            };

            NullType.staticLambdas = new Lambda[] {
                new InPlaceLambda(
                    new RedwoodType[] { null, null },
                    GetForCSharpType(typeof(bool)),
                    new InPlaceLambdaExecutor((stack, locs) => {
                    return(stack[locs[0]] == null && stack[locs[1]] == null);
                })
                    ),
                new InPlaceLambda(
                    new RedwoodType[] { null, null },
                    GetForCSharpType(typeof(bool)),
                    new InPlaceLambdaExecutor((stack, locs) => {
                    return(stack[locs[0]] != null || stack[locs[1]] != null);
                })
                    )
            };
        }
示例#3
0
        internal void SelectOverloads(RedwoodType[] argumentTypes)
        {
            bool[]          candidates = new bool[infos.Length];
            RedwoodType[][] overloads  = new RedwoodType[infos.Length][];
            for (int i = 0; i < infos.Length; i++)
            {
                overloads[i] = RuntimeUtil.GetTypesFromMethodInfo(infos[i]);
            }
            RuntimeUtil.SelectBestOverloads(argumentTypes, overloads, candidates);

            List <MethodInfo> selectedInfos = new List <MethodInfo>();

            for (int i = 0; i < candidates.Length; i++)
            {
                if (candidates[i])
                {
                    selectedInfos.Add(infos[i]);
                }
            }
            infos = selectedInfos.ToArray();
        }
示例#4
0
        internal int GetSlotNumberForOverload(string functionName, RedwoodType[] argTypes)
        {
            int baseSlot = slotMap[functionName];

            RedwoodType[][] overloadArgTypes = overloadsMap[baseSlot].Item1;

            bool found = RuntimeUtil.TrySelectOverload(
                argTypes,
                overloadArgTypes,
                out int index);

            if (found)
            {
                return(overloadsMap[baseSlot].Item2[index]);
            }
            else
            {
                // Retrun a sentinel value so we can count the lambda as
                // not found.
                return(-1);
            }
        }