Example #1
0
        //public DynLanState PushContext(String DisplayName, Guid ObjectID, DynLanContextType ContextType)
        public DynLanState PushContext(
            DynLanProgram Program,
            DynLanContextType ContextType,
            IList <Object> Parameters)
        {
            DynLanState  state = new DynLanState(Program, ContextType); // DisplayName, ObjectID, ContextType);
            DynLanObject obj   = state.Object;

            this.Stack.Add(state);
            this.CurrentState = state;

            List <DynLanMethodParam> finalParameters = new List <DynLanMethodParam>();
            Int32 index = -1;

            if (Program is DynLanMethod)
            {
                DynLanMethod method = (DynLanMethod)Program;
                foreach (String parameter in method.Parameters)
                {
                    index++;

                    Object parameterValue = Parameters == null ? null :
                                            index < Parameters.Count ?
                                            Parameters[index] :
                                            new Undefined();

                    if (obj != null)
                    {
                        obj[parameter] = parameterValue;
                        finalParameters.Add(new DynLanMethodParam()
                        {
                            Name  = parameter,
                            Value = parameterValue
                        });
                    }
                }
            }

            if (obj != null)
            {
                foreach (DynLanMethod DynLanMethod in Program.Methods)
                {
                    if (state.Program is DynLanClass)
                    {
                        DynLanMethod newMethod = (DynLanMethod)DynLanMethod.Clone();
                        newMethod.ParentObject = obj;
                        obj[newMethod.Name]    = newMethod;
                    }
                    else
                    {
                        obj[DynLanMethod.Name] = DynLanMethod;
                    }
                }

                foreach (DynLanClass DynLanClass in Program.Classes)
                {
                    obj[DynLanClass.Name] = DynLanClass;
                }
            }

            RaiseProgramStart(
                state,
                finalParameters);

            return(state);
        }
Example #2
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);
        }
Example #3
0
        ////////////////////////////////////////////////
#if !NET20
        public DynLanObject CloneBySerialize()
        {
            DynLanObject obj = this.SerializeToBytes().Deserialize <DynLanObject>();

            return(obj);
        }