Пример #1
0
        //////////////////////////////////////////////

        /*public PainState(String DisplayName, Guid ObjectID, PainContextType ContextType)
         * {
         *  this.DisplayName = DisplayName ?? "";
         *  this.ObjectID = ObjectID;
         *  this.ID = Guid.NewGuid();
         *  this.ContextType = ContextType;
         *  this.Object = new PainObject();
         *  this.Lines = new PainCodeLines();
         *  this.CurrentLineIndex = 0;
         * }*/

        public PainState(PainProgram Program, PainContextType ContextType)
        {
            this.Program = Program;
            //this.DisplayName = DisplayName ?? "";
            //this.ObjectID = ObjectID;
            this.ID          = Guid.NewGuid();
            this.ContextType = ContextType;
            this.Object      = new PainObject();
            //this.Lines = new PainCodeLines();
            this.CurrentLineIndex = 0;
        }
Пример #2
0
        //////////////////////////////////////////////

        public PainContext(PainProgram MainProgram)
        {
            this.GlobalState = new PainState(
                MainProgram,
                PainContextType.GLOBAL);

            this.Stack = new PainStates();
            this.Stack.Push(this.GlobalState);
            this.CurrentState = this.GlobalState;

            this.ID = Guid.NewGuid();
        }
Пример #3
0
        //////////////////////////////////////////////////

        public virtual Object Clone()
        {
            PainProgram item = (PainProgram)this.MemberwiseClone();

            if (item.Lines != null)
            {
                item.Lines = new PainCodeLines(item.Lines.Select(i => i.Clone()));
            }
            if (item.Classes != null)
            {
                item.Classes = new PainClasses(item.Classes.Select(i => i.Clone() as PainClass));
            }
            if (item.Methods != null)
            {
                item.Methods = new PainMethods(item.Methods.Select(i => i.Clone() as PainMethod));
            }
            return(item);
        }
Пример #4
0
        //////////////////////////////////////////////

        //public PainState PushContext(String DisplayName, Guid ObjectID, PainContextType ContextType)
        public PainState PushContext(
            PainProgram Program,
            PainContextType ContextType,
            IList <Object> Parameters)
        {
            PainState  state = new PainState(Program, ContextType); // DisplayName, ObjectID, ContextType);
            PainObject obj   = state.Object;

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

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

            if (Program is PainMethod)
            {
                PainMethod method = (PainMethod)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 PainMethodParam()
                        {
                            Name  = parameter,
                            Value = parameterValue
                        });
                    }
                }
            }

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

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

            RaiseProgramStart(
                state,
                finalParameters);

            return(state);
        }