Пример #1
0
        public override void Evaluate(IScriptContext context)
        {
            // ( Expr )
            if (typeExpr == null)
            {
                expr.Evaluate(context);
            }
            // (Type) Expr
            else
            {
                typeExpr.Evaluate(context);

                Type type = context.Result as Type;
                if (type == null)
                {
                    //NOTE: Handling special case of unary minus operator:
                    //      (3+2)-2;
                    ScriptUnaryExpr unary = expr as ScriptUnaryExpr;

                    if (unary == null || unary.OperationSymbol != "-")
                    {
                        throw new ScriptException("Wrong type expression!");
                    }

                    //NOTE: expr + (unary expr)
                    object left = context.Result;
                    unary.Evaluate(context);
                    context.Result = @operator.Evaluate(left, context.Result);
                    return;
                }

                expr.Evaluate(context);
                context.Result = RuntimeHost.Binder.ConvertTo(context.Result, type);
            }
        }
Пример #2
0
        public override void Evaluate(IScriptContext context)
        {
            if (rightExpr != null)
            {
                rightExpr.Evaluate(context);
            }

            context.Result = assignOperation(context);
        }
Пример #3
0
        public override void Evaluate(IScriptContext context)
        {
            conditionExpression.Evaluate(context);

#if DEBUG
            if (!(context.Result is bool))
            {
                throw new ScriptException("Condition expression evaluates non boolean value");
            }
#endif
        }
        public override void Evaluate(IScriptContext context)
        {
            object switchValue = context.Result;

            cond.Evaluate(context);
            if (switchValue.Equals(context.Result))
            {
                statement.Evaluate(context);
                context.SetBreak(true);
            }
            else
            {
                context.Result = switchValue;
            }
        }
Пример #5
0
        public override void Evaluate(IScriptContext context)
        {
            expr.Evaluate(context);

            HandleOperatorArgs handler = OnHandleOperator(this, context, oper, context.Result);

            if (handler.Cancel)
            {
                context.Result = handler.Result;
            }
            else
            {
                context.Result = RuntimeHost.GetUnaryOperator(oper).Evaluate(context.Result);
            }
            //Context.EvaluateUnaryOperator(oper, Context.Result);
        }
        public override void Evaluate(IScriptContext context)
        {
            expr.Evaluate(context);

            IEnumerable enumeration = context.Result as IEnumerable;
            IEnumerator enumerator  = null;

            if (enumeration != null)
            {
                enumerator = enumeration.GetEnumerator();
            }
            else
            {
                IObjectBind bind = RuntimeHost.Binder.BindToMethod(context.Result, "GetEnumerator", new Type[0], new object[0]);
                if (bind != null)
                {
                    enumerator = bind.Invoke(context, null) as IEnumerator;
                }
            }

            if (enumerator == null)
            {
                throw new ScriptException("GetEnumerator() method did not found in object: " + context.Result.ToString());
            }

            enumerator.Reset();

            while (enumerator.MoveNext())
            {
                context.SetItem(name.Text, enumerator.Current);
                statement.Evaluate(context);
                if (context.IsBreak() || context.IsReturn())
                {
                    context.SetBreak(false);
                    break;
                }
                if (context.IsContinue())
                {
                    context.SetContinue(false);
                }
            }
        }
Пример #7
0
        public override void Evaluate(IScriptContext context)
        {
            object             leftVal, rightVal;
            HandleOperatorArgs handling;

            left.Evaluate(context);
            leftVal = context.Result;

            context.Result = RuntimeHost.NullValue;

            if ((oper == "&&" && false.Equals(leftVal)) || (oper == "||" && true.Equals(leftVal)))
            {
                handling = OnHandleOperator(this, context, oper, leftVal);

                if (handling.Cancel)
                {
                    context.Result = handling.Result;
                }
                else
                {
                    context.Result = leftVal;
                }

                return;
            }

            right.Evaluate(context);
            rightVal = context.Result;

            handling = OnHandleOperator(this, context, oper, leftVal, rightVal);
            if (handling.Cancel)
            {
                context.Result = handling.Result;
            }
            else
            {
                context.Result = operatorFunction.Evaluate(leftVal, rightVal);
                //RuntimeHost.GetBinaryOperator(oper).Evaluate(leftVal, rightVal);
                //RuntimeHost.GetBinaryOperator(oper).Evaluate(leftVal, rightVal);
            }
            //Context.EvaluateOperator(oper, leftVal, rightVal);
        }
 public override void Evaluate(IScriptContext context)
 {
     expr.Evaluate(context);
     context.Result = new object[] { name, context.Result };
 }