Пример #1
0
        /// <summary>
        /// Initializes a new instance of the Expression class.
        /// </summary>
        /// <param name="slot">The slot that this expression resides in.</param>
        /// <param name="type">The type of this expression.</param>
        /// <param name="domain">The domain of the expression. If this value is <c>null</c>, the
        /// domain is considered to be all real numbers (i.e. no domain).</param>
        protected Expression(int slot, ExpressionType type, CompiledDomain domain = null)
        {
            Slot = slot;
            Type = type;

            Color = Color.Black;
            Domain = domain ?? DomainCompiler.EmptyDomain;
        }
        static DomainCompiler()
        {
            DynamicMethod method = GetDomainDynamicMethod();
            ILGenerator il = method.GetILGenerator();

            il.Emit(OpCodes.Ldc_I4_1);
            il.Emit(OpCodes.Ret);

            EmptyDomain = new CompiledDomain(method, null, new List<Constraint>());
        }
        /// <summary>
        /// Initializes a new instance of the StandardExpression class.
        /// </summary>
        /// <param name="slot">The slot this expression resides in. Used as an identifier when
        /// graphing.</param>
        /// <param name="type">The type of expression this instance represents. Do not use
        /// <see cref="ExpressionType.Parametric"/>; use the <see cref="ParametricExpression"/>
        /// class instead.</param>
        /// <param name="expr">The expression this instance represents.</param>
        /// <remarks>
        /// This constructor assumes that <paramref name="expr"/> is formatted as an infix
        /// expression, and will be automatically compiled using the infix compiler.
        /// </remarks>
        public StandardExpression(int slot, ExpressionType type, string expr, CompiledDomain domain = null)
            : base(slot, type, domain)
        {
            if (type == ExpressionType.Parametric)
            {
                throw new ArgumentException(
                    "ExpressionType.Parametric is not valid for this class. " +
                    "Use the ParametricExpression class instead.",
                    "type");
            }

            Expression = ExpressionCompiler.CompileInfix(expr);
        }
 /// <summary>
 /// Initializes a new instance of the ParametricExpression class.
 /// </summary>
 /// <param name="slot">The slot this expression resides in. Used as an identifier when
 /// graphing.</param>
 /// <param name="x">The infix expression used in the "x = " portion of a parametric
 /// expression.</param>
 /// <param name="y">The infix expression used in the "y = " portion of a parametric
 /// expression.</param>
 /// <remarks>
 /// This constructor assumes that the <paramref name="x"/> and <paramref name="y"/>
 /// are formatted as infix expressions, and will be automatically compiled using the
 /// infix compiler.
 /// </remarks>
 public ParametricExpression(int slot, string x, string y, CompiledDomain domain = null)
     : base(slot, ExpressionType.Parametric, domain)
 {
     XExpression = ExpressionCompiler.CompileInfix(x);
     YExpression = ExpressionCompiler.CompileInfix(y);
 }
Пример #5
0
            public ExpressionInfo(UncompiledExpression expr, CompiledDomain domain = null)
            {
                if (expr is UncompiledStandardExpression)
                {
                    var stdExpr = expr as UncompiledStandardExpression;
                    Expression = new StandardExpression(expr.Slot, expr.Type, stdExpr.Expression, domain);
                }
                else if (expr is UncompiledParametricExpression)
                {
                    var paraExpr = expr as UncompiledParametricExpression;
                    Expression = new ParametricExpression(expr.Slot, paraExpr.XExpression, paraExpr.YExpression, domain);
                }
                else
                {
                    throw new ArgumentException("expr");
                }

                OriginalUncompiled = expr;
                Enabled = true;
            }