示例#1
0
        private Object Eval(
            DynContext DynLanContext)
        {
            while (true)
            {
                if (DynLanContext.IsFinished)
                {
                    if (DynLanContext.Error != null)
                    {
                        throw DynLanContext.Error;
                    }
                    break;
                }

                try
                {
                    Boolean result = DynLan.Evaluator.ContextEvaluator.
                                     ExecuteNext(DynLanContext);

                    if (DynLanContext.BreakEveryLine && result)
                    {
                        break;
                    }
                }
                catch
                {
                    throw;
                }
            }
            return(DynLanContext.Result);
        }
示例#2
0
        public virtual Boolean SetValue(DynContext EvalContext, String Name, Object Value)
        {
#if CASE_INSENSITIVE
            Name = Name.ToUpper();
#endif

            DynContext DynLanContext = EvalContext as DynContext;
            if (DynLanContext == null)
            {
                return(false);
            }

            DynLanContext.CurrentState.Object[Name] = Value;

            return(true);
        }
示例#3
0
        private DynContext CreateContext(
            DynLanCodeLines Lines,
            IDictionary <String, Object> Values,
            Boolean BreakEveryLine,
            Boolean CopyParameters)
        {
            DynContext runContext = new DynContext(
                new DynLanProgram()
            {
                ID            = Guid.Empty,
                Lines         = Lines,
                ForceDecimals = ForceDecimals
            });

            runContext.BreakEveryLine = BreakEveryLine;
            runContext.ForceDecimals  = ForceDecimals;

            if (runContext.CurrentState.Program.Lines.Count > 0)
            {
                runContext.CurrentState.CurrentLineID = runContext.CurrentState.Program.Lines[0].ID;
            }

            if (Values != null)
            {
                if (CopyParameters)
                {
                    if (Values is ICloneShallow)
                    {
                        runContext.CurrentState.Object.DynamicValues = (IDictionary <String, Object>)((ICloneShallow)Values).CloneShallow();
                    }
                    else
                    {
                        runContext.CurrentState.Object.DynamicValues = new DictionaryCloneShallow <String, Object>(Values);
                    }
                }
                else
                {
                    runContext.CurrentState.Object.DynamicValues = Values;
                }
            }
            return(runContext);
        }
示例#4
0
        //////////////////////////////////////////////

        public virtual ExpressionValue GetValue(
            DynContext EvalContext,
            String Name,
            Boolean SeekForExtenders,
            Boolean SeekForMethods,
            Boolean SeekInContexts)
        {
#if CASE_INSENSITIVE
            Name = Name.ToUpper();
#endif

            DynContext DynLanContext = EvalContext as DynContext;
            if (DynLanContext == null)
            {
                return(null);
            }

            // szukanie extender'a
            if (SeekForExtenders)
            {
                ExpressionExtenderInfo extender = BuildinExtenders.FindByName(Name);
                if (extender != null)
                {
                    return(new ExpressionValue(extender));
                }
            }

            if (SeekInContexts)
            {
                // szukanie zmiennej w lokalnym kontekście
                if (DynLanContext.CurrentState != DynLanContext.GlobalState)
                {
                    // szukanie zmiennej w metodach gdzie została zadeklarowana metoda
                    if (DynLanContext.Stack != null)
                    {
#if !NET20
                        DynLanState currentState = DynLanContext.
                                                   Stack.
                                                   LastOrDefault();
#else
                        DynLanState currentState = Linq2.LastOrDefault(
                            DynLanContext.Stack);
#endif
                        DynLanMethod method = currentState == null ? null :
                                              currentState.Program as DynLanMethod;

                        if (method != null)
                        {
                            for (Int32 i = DynLanContext.Stack.Count - 2; i >= 0; i--)
                            {
                                DynLanState state = DynLanContext.Stack[i];

                                DynLanMethod thisMethod = state.Program as DynLanMethod;
                                DynLanObject thisObject = state.Object;
                                if (thisMethod == null)
                                {
                                    break;
                                }

                                if (thisMethod != null &&
                                    thisMethod.Methods != null &&
                                    thisMethod.Methods.Contains(method))
                                {
                                    if (thisObject != null &&
                                        thisObject.Contains(Name))
                                    {
                                        return(new ExpressionValue(thisObject[Name]));
                                    }
                                }
                                else
                                {
                                    break;
                                }

                                method = thisMethod;
                            }
                        }
                    }

                    if (DynLanContext.CurrentState.Object != null &&
                        DynLanContext.CurrentState.Object.Contains(Name))
                    {
                        return(new ExpressionValue(DynLanContext.CurrentState.Object[Name]));
                    }
                }

                // szukanie zmiennej w globalnym kontekście
                if (DynLanContext.GlobalState.Object != null &&
                    DynLanContext.GlobalState.Object.Contains(Name))
                {
                    return(new ExpressionValue(DynLanContext.GlobalState.Object[Name]));
                }
            }

            // przeniesione na dło aby metody i zmiennej których nazwy pokrywaja sie z globalnymi
            // mobly byc używane
            // szukanie metody
            if (SeekForMethods)
            {
                ExpressionMethodInfo method = BuildinMethods.FindByName(Name);
                if (method != null)
                {
                    return(new ExpressionValue(method));
                }
            }

            /*for (var i = DynLanContext.Stack.IndexOf(DynLanContext.Current); i >= 0; i--)
             * {
             *  DynLanState context = DynLanContext.Stack[i];
             *
             *  if ((context == DynLanContext.Current || context.ContextType == DynLanContextType.GLOBAL) &&
             *      context.Object != null &&
             *      context.Object.Contains(Name))
             *  {
             *      return new ExpressionValue(context.Object[Name]);
             *  }
             * }*/

            // szukanie po globalnych zmiennych

            /*if (DynLanContext.GlobalContext.ContextType == DynLanContextType.GLOBAL)
             * {
             *  if (DynLanContext.GlobalContext.Object.Contains(Name))
             *      return new ExpressionValue(DynLanContext.GlobalContext.Object[Name]);
             * }*/

            return(null);
        }
示例#5
0
 public Object Eval(
     IDictionary <String, Object> Parameters)
 {
     using (DynContext context = this.CreateContext(Parameters))
         return(Eval(context));
 }
示例#6
0
        //////////////////////////////////////////////////

        public Object Eval()
        {
            using (DynContext context = this.CreateContext(null))
                return(Eval(context));
        }