/// <summary>
 /// Initializes a new instance of <see cref="BuiltInOperator"/> AST node.
 /// </summary>
 /// <param name="op">The <see cref="AST.Operator"/> to wrap.</param>
 public BuiltInOperator(Operator op)
 {
     this.op = op;
 }
 /// <summary>
 /// Build a AST node which represents a standalone built-in operator.
 /// </summary>
 /// <param name="op">The <see cref="AST.Operator"/> to build the function from.</param>
 /// <returns><see cref="AST.BuiltInOperator"/> AST node.</returns>
 public static BuiltInOperator BuiltInOperator(Operator op)
 {
     return new BuiltInOperator(op);
 }
        private static DLR.Expression GenerateOpFunction(AplusScope scope, Operator op)
        {
            DLR.Expression function;
            if (op.isBuiltin)
            {
                function = AST.Node.BuiltInFunction((Token)op.Function).Generate(scope);
            }
            else
            {
                function = op.Function.Generate(scope);
            }

            return function;
        }
        private static DLR.Expression BuildMonadicCase(
            AplusScope scope,
            Operator op,
            DLR.ParameterExpression functionVariable,
            DLR.LabelTarget methodReturnTarget,
            DLR.ParameterExpression methodEnvArg,
            DLR.ParameterExpression methodRightArg)
        {
            DLR.Expression result;
            if (op is EachOperator)
            {

                result =
                    DLR.Expression.IfThenElse(
                        DLR.Expression.Property(functionVariable, "IsFunctionScalar"),
                        DLR.Expression.Goto(
                            methodReturnTarget,
                            DLR.Expression.Call(
                                DLR.Expression.Constant(MonadicOperatorInstance.Apply),
                                MonadicOperatorInstance.Apply.GetType().GetMethod("Execute"),
                                functionVariable,
                                methodRightArg,
                                methodEnvArg
                            )
                        ),
                        DLR.Expression.Goto(
                            methodReturnTarget,
                            DLR.Expression.Call(
                                DLR.Expression.Constant(MonadicOperatorInstance.Each),
                                MonadicOperatorInstance.Each.GetType().GetMethod("Execute"),
                                functionVariable,
                                methodRightArg,
                                methodEnvArg
                            )
                        )
                    );
            }
            else
            {
                result = DLR.Expression.Goto(
                    methodReturnTarget,
                    DLR.Expression.Call(
                        DLR.Expression.Constant(MonadicOperatorInstance.Rank),
                        MonadicOperatorInstance.Rank.GetType().GetMethod("Execute"),
                        functionVariable,
                        ((RankOperator)op).Condition.Generate(scope),
                        methodRightArg,
                        methodEnvArg
                    )
                );
            }

            return result;
        }
Example #5
0
        /// <summary>
        /// Updates the properties of the <see cref="Operator"/> based on the <paramref name="expressionList"/> parameter.
        /// </summary>
        /// <param name="op">The <see cref="Operator"/> to update.</param>
        /// <param name="expressionList">The list of arguments wrapped in an <see cref="ExpressionList"/>.</param>
        /// <exception cref="ParseException"></exception>
        /// <returns>Returns the updated <see cref="Operator"/>.</returns>
        public static Node BuiltinOpInvoke(Operator op, ExpressionList expressionList)
        {
            switch (expressionList.Length)
            {
                case 1:
                    op.RightArgument = expressionList[0];
                    break;
                case 2:
                    op.RightArgument = expressionList[1];
                    op.LeftArgument = expressionList[0];
                    break;
                default:
                    if (!(op is EachOperator))
                    {
                        throw new ParseException("Valence", false);
                    }

                    EachOperator eachOp = (EachOperator)op;
                    eachOp.IsGeneralApply = true;
                    eachOp.RightArgument = expressionList;
                    break;
            }

            return op;
        }