Esempio n. 1
0
 internal object RunWithExpectedTypes(RedwoodType[] knownArgTypes, object[] args)
 {
     RedwoodType[] types = RuntimeUtil.GetTypesFromArgs(args);
     for (int i = 0; i < knownArgTypes.Length; i++)
     {
         if (knownArgTypes[i] != null)
         {
             types[i] = knownArgTypes[i];
         }
     }
     return(RuntimeUtil.SelectSingleOverload(types, this).Run(args));
 }
Esempio n. 2
0
        public int Execute(Frame frame)
        {
            RedwoodType leftType  = leftKnownType ?? RuntimeUtil.GetTypeOf(frame.stack[leftIndex]);
            RedwoodType rightType = rightKnownType ?? RuntimeUtil.GetTypeOf(frame.stack[rightIndex]);

            string lambdaName = RuntimeUtil.NameForOperator(op);
            Lambda leftLambda;
            Lambda rightLambda;

            leftLambda  = ResolveLambda(leftType, lambdaName);
            rightLambda = ResolveLambda(rightType, lambdaName);

            Lambda lambda = RuntimeUtil.CanonicalizeLambdas(leftLambda, rightLambda);

            lambda = RuntimeUtil.SelectSingleOverload(
                new RedwoodType[] { leftType, rightType },
                lambda
                );

            frame.result = lambda;
            return(1);

            Lambda ResolveLambda(RedwoodType type, string lambdaName)
            {
                Lambda lambda;

                if (type.CSharpType == null)
                {
                    int slot = type.staticSlotMap.GetValueOrDefault(lambdaName, -1);

                    if (slot == -1)
                    {
                        lambda = null;
                    }
                    else
                    {
                        lambda = type.staticLambdas[slot];
                    }
                }
                else
                {
                    MemberResolver.TryResolveLambda(null, type, lambdaName, out lambda);
                }

                return(lambda);
            }
        }
        private static RedwoodType ResolveBinaryOperator(
            BinaryOperator op,
            RedwoodType left,
            RedwoodType right,
            RedwoodType searchType,
            out Lambda lambda,
            out int?staticSlot,
            out int?index)
        {
            if (searchType.CSharpType == null)
            {
                staticSlot = searchType.staticSlotMap[RuntimeUtil.NameForOperator(op)];
                lambda     = null;

                RedwoodType overloadType = searchType.staticSlotTypes[staticSlot ?? -1];
                if (overloadType.CSharpType == typeof(LambdaGroup))
                {
                    if (!RuntimeUtil.TrySelectOverload(
                            new RedwoodType[] { left, right },
                            overloadType.GenericArguments
                            .Select(lambdaType => lambdaType
                                    .GenericArguments
                                    .SkipLast(1)
                                    .ToArray()
                                    )
                            .ToArray(),
                            out int resIndex
                            ))
                    {
                        index      = null;
                        staticSlot = null;
                        return(null);
                    }

                    index = resIndex;
                    return(overloadType.GenericArguments[resIndex]);
                }

                index = null;
                return(overloadType);
            }
            else
            {
                index      = null;
                staticSlot = null;
                if (!MemberResolver.TryResolveLambda(
                        searchType,
                        null,
                        RuntimeUtil.NameForOperator(op),
                        out Lambda lambdaOverloads))
                {
                    lambda = null;
                    return(null);
                }

                lambda = RuntimeUtil.SelectSingleOverload(
                    new RedwoodType[] { left, right },
                    lambdaOverloads
                    );

                return(RedwoodType.GetForLambdaArgsTypes(
                           typeof(ExternalLambda),
                           lambda.ReturnType,
                           lambda.ExpectedArgs.ToArray()
                           ));
            }
        }
Esempio n. 4
0
 public object Run(params object[] args)
 {
     RedwoodType[] types = RuntimeUtil.GetTypesFromArgs(args);
     return(RuntimeUtil.SelectSingleOverload(types, this).Run(args));
 }