コード例 #1
0
        private static DLR.Expression BuildMonadicCase(
            Token functionToken,
            DLR.LabelTarget methodReturnTarget,
            DLR.ParameterExpression methodEnvArg,
            DLR.ParameterExpression methodRightArg)
        {
            DLR.Expression          result;
            AbstractMonadicFunction monadic = MethodChooser.GetMonadicMethod(functionToken);

            if (monadic != null)
            {
                result = DLR.Expression.Goto(
                    methodReturnTarget,
                    DLR.Expression.Call(
                        DLR.Expression.Constant(monadic),
                        monadic.GetType().GetMethod("Execute"),
                        methodRightArg,
                        methodEnvArg
                        )
                    );
            }
            else
            {
                result = DLR.Expression.Throw(
                    DLR.Expression.New(
                        typeof(Error.Valence).GetConstructor(new Type[] { typeof(string) }),
                        DLR.Expression.Constant(functionToken.Text)
                        )
                    );
            }

            return(result);
        }
コード例 #2
0
        private DLR.Expression GenerateMonadic(AplusScope scope, DLR.Expression argument)
        {
            DLR.Expression result;
            // Handle the result monadic function a little differently:
            if (this.token.Type == Tokens.RESULT)
            {
                result = scope.ReturnTarget != null
                         // If inside of a function create a return expression Tree
                    ? DLR.Expression.Return(scope.ReturnTarget, argument, typeof(AType))
                         // Otherwise just return the value
                    : argument
                ;
            }
            else
            {
                AbstractMonadicFunction method = MethodChooser.GetMonadicMethod(this.token);

                if (method == null)
                {
                    throw new ParseException(String.Format("Not supported Monadic function[{0}]", this.token));
                }

                result = DLR.Expression.Call(
                    DLR.Expression.Constant(method),
                    method.GetType().GetMethod("Execute"),
                    argument,
                    scope.GetRuntimeExpression()
                    );
            }

            return(result);
        }