コード例 #1
0
        /// <summary>
        /// array[index1][index2][...][indexN] = value, and
        /// indices = {index1, index2, ..., indexN}
        ///
        /// Note this function doesn't support the replication of array indexing.
        /// </summary>
        /// <param name="array"></param>
        /// <param name="indices"></param>
        /// <param name="value"></param>
        /// <param name="core"></param>
        /// <returns></returns>
        public static StackValue SetValueForIndices(StackValue array, StackValue[] indices, StackValue value, Core core)
        {
            Validity.Assert(array.IsArray || array.IsString);

            for (int i = 0; i < indices.Length - 1; ++i)
            {
                StackValue  index = indices[i];
                HeapElement he    = GetHeapElement(array, core);

                StackValue subArray;

                if (index.IsNumeric)
                {
                    index = index.ToInteger();
                    int absIndex = he.ExpandByAcessingAt((int)index.opdata);
                    subArray = he.Stack[absIndex];
                }
                else
                {
                    subArray = GetValueFromIndex(array, index, core);
                }

                // auto-promotion
                if (!subArray.IsArray)
                {
                    subArray = core.Heap.AllocateArray(new StackValue[] { subArray }, null);
                    GCUtils.GCRetain(subArray, core);
                    SetValueForIndex(array, index, subArray, core);
                }

                array = subArray;
            }

            return(SetValueForIndex(array, indices[indices.Length - 1], value, core));
        }
コード例 #2
0
        public static StackValue SetDataAtIndices(StackValue array, int[] indices, StackValue data, Core core)
        {
            Validity.Assert(array.optype == AddressType.ArrayPointer || array.optype == AddressType.String);

            StackValue arrayItem = array;

            for (int i = 0; i < indices.Length - 1; ++i)
            {
                HeapElement arrayHeap = core.Heap.Heaplist[(int)arrayItem.opdata];
                int         index     = arrayHeap.ExpandByAcessingAt(indices[i]);
                arrayItem = arrayHeap.Stack[index];

                if (arrayItem.optype == AddressType.String)
                {
                    core.RuntimeStatus.LogWarning(RuntimeData.WarningID.kOverIndexing, ProtoCore.RuntimeData.WarningMessage.kStringOverIndexed);
                    return(StackUtils.BuildNull());
                }
                else if (arrayItem.optype != AddressType.ArrayPointer)
                {
                    StackValue sv = HeapUtils.StoreArray(new StackValue[] { arrayItem }, core);
                    GCUtils.GCRetain(sv, core);
                    arrayHeap.Stack[index] = sv;
                    arrayItem = arrayHeap.Stack[index];
                }
            }

            return(ArrayUtils.SetDataAtIndex(arrayItem, indices[indices.Length - 1], data, core));
        }
コード例 #3
0
        /// <summary>
        /// array[index] = value. The array will be expanded if necessary.
        /// </summary>
        /// <param name="array"></param>
        /// <param name="index"></param>
        /// <param name="value"></param>
        /// <param name="core"></param>
        /// <returns></returns>
        public static StackValue SetValueForIndex(StackValue array, int index, StackValue value, RuntimeCore runtimeCore)
        {
            Validity.Assert(array.IsArray);

            HeapElement arrayHeap = GetHeapElement(array, runtimeCore);

            index = arrayHeap.ExpandByAcessingAt(index);
            StackValue oldValue = arrayHeap.SetValue(index, value);

            return(oldValue);
        }
コード例 #4
0
        /// <summary>
        /// array[index] = value. The array will be expanded if necessary.
        /// </summary>
        /// <param name="array"></param>
        /// <param name="index"></param>
        /// <param name="value"></param>
        /// <param name="core"></param>
        /// <returns></returns>
        public static StackValue SetValueForIndex(StackValue array, int index, StackValue value, Core core)
        {
            Validity.Assert(array.IsArray || array.IsString);
            if (array.IsString && !value.IsChar)
            {
                core.RuntimeStatus.LogWarning(RuntimeData.WarningID.kTypeMismatch, RuntimeData.WarningMessage.kAssignNonCharacterToString);
                return(StackValue.Null);
            }

            HeapElement arrayHeap = GetHeapElement(array, core);

            index = arrayHeap.ExpandByAcessingAt(index);
            StackValue oldValue = arrayHeap.SetValue(index, value);

            return(oldValue);
        }
コード例 #5
0
        /// <summary>
        /// array[index] = value. The array will be expanded if necessary.
        /// </summary>
        /// <param name="array"></param>
        /// <param name="index"></param>
        /// <param name="value"></param>
        /// <param name="core"></param>
        /// <returns></returns>
        public static StackValue SetValueForIndex(StackValue array, int index, StackValue value, Core core)
        {
            Validity.Assert(StackUtils.IsArray(array) || StackUtils.IsString(array));
            if (StackUtils.IsString(array) && value.optype != AddressType.Char)
            {
                core.RuntimeStatus.LogWarning(RuntimeData.WarningID.kTypeMismatch, RuntimeData.WarningMessage.kAssignNonCharacterToString);
                return(StackUtils.BuildNull());
            }

            lock (core.Heap.cslock)
            {
                HeapElement arrayHeap = GetHeapElement(array, core);
                index = arrayHeap.ExpandByAcessingAt(index);
                StackValue oldValue = arrayHeap.SetValue(index, value);
                return(oldValue);
            }
        }
コード例 #6
0
        public static StackValue SetDataAtIndex(StackValue svArray, int index, StackValue svData, Core core)
        {
            Validity.Assert(svArray.optype == AddressType.ArrayPointer || svArray.optype == AddressType.String);
            if (svArray.optype == AddressType.String && svData.optype != AddressType.Char)
            {
                core.RuntimeStatus.LogWarning(RuntimeData.WarningID.kTypeMismatch, RuntimeData.WarningMessage.kAssignNonCharacterToString);
                return(StackUtils.BuildNull());
            }

            lock (core.Heap.cslock)
            {
                HeapElement arrayHeap = core.Heap.Heaplist[(int)svArray.opdata];
                index = arrayHeap.ExpandByAcessingAt(index);
                StackValue oldValue = arrayHeap.SetValue(index, svData);
                return(oldValue);
            }
        }