Пример #1
0
        /// <summary>
        /// Moves <i>n</i> items onto the stack (popss them off the substack and pushes them onto the stack).
        /// Returns the actual number of items moved from the Substack onto the main stack
        /// </summary>
        public int MoveFromSubstack(int n)
        {
            int x;

            for (x = 0; x < n; x++)
            {
                // is the substack empty?
                if (OnSubstack == 0)
                {
                    break; // uh oh
                }
                // Remove one from stack
                var obj = Substack[--OnSubstack];

                // Double stack if necessary
                if (OnStack == Stack.Length)
                {
                    var newstack = new ADFContext[Stack.Length * 2];
                    Array.Copy(Stack, 0, newstack, 0, Stack.Length);
                    Stack = newstack;
                }

                // Add to stack
                Stack[OnStack++] = obj;
            }
            return(x);
        }
Пример #2
0
        /// <summary>
        /// Pops off <i>n</i> items from the stack, if possible. Returns the number of items actually popped off.
        /// </summary>
        public int Pop(int n)
        {
            int x;

            for (x = 0; x < n; x++)
            {
                // Anything left on the stack?
                if (OnStack == 0)
                {
                    break;
                }

                // Remove one from stack
                var obj = Stack[--OnStack];

                // Double reserve if necessary
                if (InReserve == Reserve.Length)
                {
                    var newreserve = new ADFContext[Reserve.Length * 2];
                    Array.Copy(Reserve, 0, newreserve, 0, Reserve.Length);
                    Reserve = newreserve;
                }

                // Add to reserve
                Reserve[InReserve++] = obj;
            }
            return(x);
        }
Пример #3
0
        public virtual void  Setup(IEvolutionState state, IParameter paramBase)
        {
            // load our prototype

            var p = paramBase.Push(P_CONTEXT);
            var d = DefaultBase.Push(P_CONTEXT);

            ContextProto = (ADFContext)(state.Parameters.GetInstanceForParameterEq(p, d, typeof(ADFContext)));
            ContextProto.Setup(state, p);
        }
Пример #4
0
        /// <summary>
        /// Pushes an ADFContext onto the main stack.  The best way to get an
        /// ADFContext to push onto the stack is with get(). Returns obj.
        /// </summary>
        public ADFContext Push(ADFContext obj)
        {
            // Double stack if necessary
            if (OnStack == Stack.Length)
            {
                var newstack = new ADFContext[Stack.Length * 2];
                Array.Copy(Stack, 0, newstack, 0, Stack.Length);
                Stack = newstack;
            }

            // Add to stack
            Stack[OnStack++] = obj;

            // return it
            return(obj);
        }