示例#1
0
文件: Funcall.cs 项目: baban/lp
        object EvaluateInStmts(Object.LpObject function, ScriptThread thread)
        {
            var newScopeInfo = new ScopeInfo(thread.CurrentNode, false);

            var args = (Object.LpObject[])Args.Evaluate(thread);

            thread.PushClosureScope(newScopeInfo, thread.CurrentScope, args);

            var scope = thread.CurrentScope;

            var dic = scope.AsDictionary();

            dic["methods"]   = new Dictionary <string, object>();
            dic["variables"] = new Dictionary <string, object>();
            var methods   = (Dictionary <string, object>)dic["methods"];
            var variables = (Dictionary <string, object>)dic["variables"];

            /*
             * var parameters = scope.Parameters;
             *
             * for(int i=0; i < args.Length ; i++)
             * {
             *  var v = args[i];
             *  variables[i.ToString()] = v;
             * }
             */
            var result = function.statements.Evaluate(thread);

            thread.PopScope();

            return(result);
        }
示例#2
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);
        }
示例#3
0
        public object Call(Scope creatorScope, ScriptThread thread, object thisRef, object[] parameters)
        {
            FlowControl = FlowControl.Next;
            var save = thread.CurrentNode;

            thread.CurrentNode = this;

            CheckParams(thread, ref thisRef, ref parameters);

            object[] par = new object[] { thisRef }.Concat(parameters).ToArray();

            thread.PushClosureScope(DependentScopeInfo, creatorScope, par);

            lock (lockObject)
            {
                Parameters.Evaluate(thread);
            }
            var result = Body.Evaluate(thread);

            thread.PopScope();
            thread.CurrentNode = save;

            if (!(Body is BlockNode) && !(Body is ReturnNode))
            {
                FlowControl = FlowControl.Return;
            }

            if (Body.FlowControl != FlowControl.Return && FlowControl != FlowControl.Return)
            {
                result = thread.Runtime.NullValue;
            }

            FlowControl = FlowControl.Next;
            return(result);
        }
示例#4
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);
        }
示例#5
0
 public object Call(Scope creatorScope, ScriptThread thread, object[] parameters) {
   var save = thread.CurrentNode; //prolog, not standard - the caller is NOT target node's parent
   thread.CurrentNode = this;
   thread.PushClosureScope(DependentScopeInfo, creatorScope, parameters);
   Parameters.Evaluate(thread); // pre-process parameters
   var result = Body.Evaluate(thread);
   thread.PopScope();
   thread.CurrentNode = save; //epilog, restoring caller 
   return result;
 }
示例#6
0
        public object Call(Scope creatorScope, ScriptThread thread, object[] parameters)
        {
            var save = thread.CurrentNode; //prolog, not standard - the caller is NOT target node's parent

            thread.CurrentNode = this;
            thread.PushClosureScope(DependentScopeInfo, creatorScope, parameters);
            Parameters.Evaluate(thread); // pre-process parameters
            var result = Body.Evaluate(thread);

            thread.PopScope();
            thread.CurrentNode = save; //epilog, restoring caller
            return(result);
        }
示例#7
0
文件: DefineClass.cs 项目: baban/lp
        protected override object DoEvaluate(ScriptThread thread)
        {
            thread.CurrentNode = this;

            var scope        = thread.CurrentScope;
            var newScopeInfo = new ScopeInfo(thread.CurrentNode, false);
            var klass        = Object.LpClass.initialize(className.Token.Text, Body, false, scope);

            thread.PushClosureScope(newScopeInfo, thread.CurrentScope, new object[] { });
            Body.Evaluate(thread);
            thread.PopScope();

            thread.CurrentNode = Parent;

            return(klass);
        }
示例#8
0
 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;
 }
示例#9
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();
            }
        }
示例#10
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);
        }
示例#11
0
        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();
            }
        }
示例#12
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);
        }
示例#13
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);
        }