Example #1
0
        private object EvaluateParsedScript(DataTable args = null)
        {
            LastScript.Tag = DataMap;
            var root = LastScript.Root.AstNode as Ast.AstNode;

            root.DependentScopeInfo = MainScope.ScopeInfo;

            DataMap.ProgramRoot = root;

            Status = AppStatus.Evaluating;
            ScriptThread thread = null;

            try
            {
                thread = new ScriptThread(this);
                thread.CurrentFuncInfo = new FunctionInfo("<global>", -1, null, null, false);

                if (args != null)
                {
                    var argsBinding = thread.Bind("args", BindingRequestFlags.ExistingOrNew | BindingRequestFlags.Write);
                    argsBinding.SetValueRef(thread, args, TypeInfo.NotDefined);
                }

                var result = root.Evaluate(thread);

                Status = AppStatus.Ready;
                return(result);
            }
            catch (ScriptException se)
            {
                Status      = AppStatus.RuntimeError;
                se.Location = thread.CurrentNode.Location;
                if (se.ScriptStackTrace == null)
                {
                    se.ScriptStackTrace = thread.GetStackTrace(true);
                }
                LastException = se;
                if (RethrowExceptions)
                {
                    throw;
                }
                return(null);
            }
            catch (Exception ex)
            {
                Status = AppStatus.RuntimeError;
                var se = new ScriptException(ex.Message, ex, thread.CurrentNode.Location, thread.GetStackTrace(true));
                LastException = se;
                if (RethrowExceptions)
                {
                    throw se;
                }
                return(null);
            }
        }
Example #2
0
File: Stmts.cs Project: baban/lp
 protected override object DoEvaluate(ScriptThread thread)
 {
     try {
         Object.LpObject result = Object.LpNl.initialize();
         thread.CurrentNode = this;
         ChildNodes.ForEach((node) => result = (Object.LpObject)node.Evaluate(thread));
         thread.CurrentNode = Parent;
         return(result);
     }
     catch (System.Exception e)
     {
         var traces   = thread.GetStackTrace();
         var location = thread.CurrentNode.Location;
         System.Console.WriteLine(e.Message);
         System.Console.WriteLine(location);
         return(null);
     }
 }