Пример #1
0
        // heaper method to support negative index into stack
        public static StackValue GetValue(this HeapElement hs, int ix, Core core)
        {
            int index = ix < 0 ? ix + hs.VisibleSize : ix;

            if (index >= hs.VisibleSize || index < 0)
            {
                //throw new IndexOutOfRangeException();
                core.RuntimeStatus.LogWarning(ProtoCore.RuntimeData.WarningID.kOverIndexing, RuntimeData.WarningMessage.kArrayOverIndexed);
                return(StackUtils.BuildNull());
            }

            return(hs.Stack[index]);
        }
Пример #2
0
        //this method compares the heap for the stack variables and determines if the values of the heap are same
        private static bool CompareStackValuesFromHeap(StackValue sv1, StackValue sv2, Core c1, Core c2, ProtoCore.Runtime.Context context)
        {
            HeapElement heap1 = ArrayUtils.GetHeapElement(sv1, c1);
            HeapElement heap2 = ArrayUtils.GetHeapElement(sv1, c2);

            if (heap1.Stack.Length != heap2.Stack.Length)
            {
                return(false);
            }

            for (int i = 0; i < heap1.Stack.Length; i++)
            {
                if (!CompareStackValues(heap1.Stack[i], heap2.Stack[i], c1, c2, context))
                {
                    return(false);
                }
            }

            if (heap1.Dict != null && heap2.Dict != null)
            {
                if (heap1.Dict == heap2.Dict)
                {
                    return(true);
                }

                foreach (var key in heap1.Dict.Keys)
                {
                    StackValue value1 = heap1.Dict[key];
                    StackValue value2 = StackUtils.BuildNull();
                    if (!heap2.Dict.TryGetValue(key, out value2))
                    {
                        return(false);
                    }

                    if (!CompareStackValues(value1, value2, c1, c2))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            else if (heap1.Dict == null && heap2.Dict == null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #3
0
        public void RightShiftElements(int size)
        {
            Debug.Assert(VisibleSize + size <= AllocSize);
            if (size <= 0)
            {
                return;
            }

            for (int pos = VisibleSize - 1; pos >= 0; pos--)
            {
                int targetPos = pos + size;
                Stack[targetPos] = Stack[pos];
                Stack[pos]       = StackUtils.BuildNull();
            }

            VisibleSize = VisibleSize + size;
        }
Пример #4
0
        //
        // TODO Jun: Optimize the reallocation routines
        //      1. Copying the temps can be optimized.
        //      2. Explore using List for the HeapStack stack. In this case we take advantage of .Net List arrays
        //
        public void ReAllocate(int size)
        {
            int newAllocatedSize = GetNewSize(size);

            // Copy current contents into a temp array
            StackValue[] tempstack = new StackValue[AllocSize];
            Stack.CopyTo(tempstack, 0);

            // Reallocate the array and copy the temp contents to it
            Stack = new StackValue[newAllocatedSize];
            tempstack.CopyTo(Stack, 0);

            for (int i = AllocSize; i < newAllocatedSize; ++i)
            {
                Stack[i] = StackUtils.BuildNull();
            }

            AllocSize = newAllocatedSize;
            Debug.Assert(size <= AllocSize);
        }