コード例 #1
0
        protected override object DoEvaluate(ScriptThread thread)
        {
            thread.CurrentNode = this;
            if (DependentScopeInfo == null)
            {
                DependentScopeInfo = new ScopeInfo(this, Parent?.AsString ?? "");
            }
            FlowControl = FlowControl.Next;
            var lastFlowControl = FlowControl.Next;

            object result = thread.Runtime.NullValue;

            thread.PushScope(DependentScopeInfo, null);

            for (int i = 0; i < ChildNodes.Count && lastFlowControl == FlowControl.Next; i++)
            {
                result          = ChildNodes[i].Evaluate(thread);
                lastFlowControl = ChildNodes[i].FlowControl;
            }

            thread.PopScope();

            if (lastFlowControl != FlowControl.Next)
            {
                FlowControl = lastFlowControl;
            }

            thread.CurrentNode = Parent;
            return(result);
        }
コード例 #2
0
        public object DoEvalutate(ScriptThread thread, ScriptException se)
        {
            thread.CurrentNode = this;

            if (DependentScopeInfo == null)
            {
                DependentScopeInfo = new ScopeInfo(this, AsString);
            }

            thread.PushScope(DependentScopeInfo, null);

            if (exceptionVar != null)
            {
                var bind = thread.Bind(exceptionVar.Symbol, BindingRequestFlags.ExistingOrNew | BindingRequestFlags.Write);
                if (bind != null && !(bind is NullBinding) && bind.SetValueRef != null)
                {
                    bind.SetValueRef(thread, se.ToScriptObject(), TypeInfo.Table);
                }
            }

            block.Evaluate(thread);

            thread.CurrentNode = this.Parent;
            return(thread.Runtime.NullValue);
        }
コード例 #3
0
ファイル: ForNode.cs プロジェクト: hstde/Calc2
        protected override object DoEvaluate(ScriptThread thread)
        {
            thread.CurrentNode = this;
            object result = thread.Runtime.NullValue;
            bool   cond   = true;

            FlowControl = FlowControl.Next;

            if (DependentScopeInfo == null)
            {
                DependentScopeInfo = new ScopeInfo(this, Parent?.AsString ?? "");
            }

            thread.PushScope(DependentScopeInfo, null);
            InitBlock?.Evaluate(thread);

            if (Condition != null)
            {
                cond = thread.Runtime.IsTrue(Condition.Evaluate(thread));
            }

            while ((Condition == null || cond) && FlowControl == FlowControl.Next)
            {
                result = Block.Evaluate(thread);

                if (Block.FlowControl == FlowControl.Break)
                {
                    break;
                }

                if (Block.FlowControl == FlowControl.Continue)
                {
                    FlowControl = FlowControl.Next;
                }

                if (Block.FlowControl == FlowControl.Return)
                {
                    break;
                }

                IterBlock?.Evaluate(thread);

                if (Condition != null)
                {
                    cond = thread.Runtime.IsTrue(Condition.Evaluate(thread));
                }
            }
            thread.PopScope();

            if (Block.FlowControl == FlowControl.Return)
            {
                FlowControl = FlowControl.Return;
            }

            thread.CurrentNode = Parent;
            return(result);
        }
コード例 #4
0
ファイル: LambdaNode.cs プロジェクト: androdev4u/XLParser
 protected override object DoEvaluate(ScriptThread thread) {
   thread.CurrentNode = this;  //standard prolog
   lock (LockObject) {
     if (DependentScopeInfo == null) {
       var langCaseSensitive = thread.App.Language.Grammar.CaseSensitive;
       DependentScopeInfo = new ScopeInfo(this, langCaseSensitive);
     }
     // In the first evaluation the parameter list will add parameter's SlotInfo objects to Scope.ScopeInfo
     thread.PushScope(DependentScopeInfo, null);
     Parameters.Evaluate(thread);
     thread.PopScope();
     //Set Evaluate method and invoke it later
     this.Evaluate = EvaluateAfter;
   }
   var result = Evaluate(thread);
   thread.CurrentNode = Parent; //standard epilog
   return result;
 }
コード例 #5
0
        public override object Call(ScriptThread thread, object[] parameters)
        {
            thread.PushScope(ScopeInfo, parameters);

            try
            {
                var expression =
                    parameters != null && parameters.Length > 0 ?
                    parameters[0] as PassiveExpression : null;

                Block.InputExpression = expression;
                Block.BlockPattern    = null;

                return(Block.Evaluate(thread));
            }
            finally
            {
                thread.PopScope();
            }
        }
コード例 #6
0
        protected override object DoEvaluate(ScriptThread thread)
        {
            thread.CurrentNode = this; //standard prolog
            lock (LockObject) {
                if (DependentScopeInfo == null)
                {
                    base.DependentScopeInfo = new ScopeInfo(this, _languageCaseSensitive);
                }
                // In the first evaluation the parameter list will add parameter's SlotInfo objects to Scope.ScopeInfo
                thread.PushScope(DependentScopeInfo, null);
                Parameters.Evaluate(thread);
                thread.PopScope();
                //Set Evaluate method and invoke it later
                this.Evaluate = EvaluateAfter;
            }
            var result = Evaluate(thread);

            thread.CurrentNode = Parent; //standard epilog
            return(result);
        }
コード例 #7
0
ファイル: LibraryFunction.cs プロジェクト: jmptrader/Irony-2
        public object Call(ScriptThread thread, object[] parameters)
        {
            var astNode      = new AstNode();        // TODO: figure it out
            var newScopeInfo = new ScopeInfo(astNode, thread.App.Language.Grammar.CaseSensitive);

            thread.PushScope(newScopeInfo, parameters);

            try
            {
                var expression =
                    parameters != null && parameters.Length > 0 ?
                    parameters[0] as PassiveExpression : null;

                return(Function(expression));
            }
            finally
            {
                thread.PopScope();
            }
        }
コード例 #8
0
        protected override object DoEvaluate(ScriptThread thread)
        {
            thread.CurrentNode = this;
            lock (lockObject)
            {
                if (DependentScopeInfo == null)
                {
                    DependentScopeInfo = new ScopeInfo(this);
                }

                thread.PushScope(DependentScopeInfo, null);
                Parameters.Evaluate(thread);
                thread.PopScope();
                Evaluate = EvaluateAfter;
            }

            var result = Evaluate(thread);

            thread.CurrentNode = Parent;
            return(result);
        }
コード例 #9
0
        protected override object DoEvaluate(ScriptThread thread)
        {
            thread.CurrentNode = this;
            object result = thread.Runtime.NullValue;

            FlowControl = FlowControl.Next;

            if (DependentScopeInfo == null)
            {
                DependentScopeInfo = new ScopeInfo(this, Parent?.AsString ?? "");
            }

            thread.PushScope(DependentScopeInfo, null);

            IterVarBlock?.Evaluate(thread);
            DataTable foreachObject = null;
            var       rawobject     = InExpr.Evaluate(thread);

            if (rawobject is string)
            {
                foreachObject = new DataTable((string)rawobject, thread);
            }
            else if (rawobject is DataTable)
            {
                foreachObject = (DataTable)rawobject;
            }
            else if (rawobject is IEnumerable)
            {
                foreachObject = new DataTable((IEnumerable)rawobject, thread);
            }
            else
            {
                thread.ThrowScriptError("Can't iterate over object of type {0}", rawobject.GetType().Name);
            }

            foreach (var e in foreachObject)
            {
                IterVarBlock.SetValue(thread, e, TypeInfo.NotDefined);
                result = Block.Evaluate(thread);

                if (Block.FlowControl == FlowControl.Break)
                {
                    break;
                }

                if (Block.FlowControl == FlowControl.Continue)
                {
                    FlowControl = FlowControl.Next;
                }

                if (Block.FlowControl == FlowControl.Return)
                {
                    break;
                }
            }
            thread.PopScope();

            if (Block.FlowControl == FlowControl.Return)
            {
                FlowControl = FlowControl.Return;
            }

            thread.CurrentNode = Parent;
            return(result);
        }