예제 #1
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);
            }
        }