/// <summary> /// = array[index1][index2][...][indexN], 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="core"></param> /// <returns></returns> public StackValue GetValueFromIndices(StackValue[] indices, RuntimeCore runtimeCore) { DSArray array = this; for (int i = 0; i < indices.Length - 1; ++i) { StackValue index = indices[i]; StackValue svArray = StackValue.Null; if (index.IsNumeric) { index = index.ToInteger(); svArray = array.GetValueFromIndex((int)index.IntegerValue, runtimeCore); } else { svArray = array.GetValueFromIndex(index, runtimeCore); } if (!svArray.IsArray) { runtimeCore.RuntimeStatus.LogWarning(WarningID.OverIndexing, Resources.kArrayOverIndexed); return(StackValue.Null); } array = heap.ToHeapObject <DSArray>(svArray); } return(array.GetValueFromIndex(indices[indices.Length - 1], runtimeCore)); }
/// <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="indices"></param> /// <param name="value"></param> /// <param name="core"></param> /// <returns></returns> public StackValue SetValueForIndices(StackValue[] indices, StackValue value, RuntimeCore runtimeCore) { DSArray array = this; for (int i = 0; i < indices.Length - 1; ++i) { StackValue index = indices[i]; StackValue svSubArray; if (index.IsNumeric) { index = index.ToInteger(); int absIndex = array.ExpandByAcessingAt((int)index.opdata); svSubArray = array.GetValueAt(absIndex); } else { svSubArray = array.GetValueFromIndex(index, runtimeCore); } // auto-promotion if (!svSubArray.IsArray) { svSubArray = heap.AllocateArray(new StackValue[] { svSubArray }); array.SetValueForIndex(index, svSubArray, runtimeCore); } array = heap.ToHeapObject <DSArray>(svSubArray); } return(array.SetValueForIndex(indices[indices.Length - 1], value, runtimeCore)); }
/// <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="indices"></param> /// <param name="value"></param> /// <param name="core"></param> /// <returns></returns> public StackValue SetValueForIndices(StackValue[] indices, StackValue value, RuntimeCore runtimeCore) { DSArray array = this; for (int i = 0; i < indices.Length - 1; ++i) { StackValue index = indices[i]; StackValue svSubArray; if (index.IsNumeric) { index = index.ToInteger(); try { int absIndex = array.ExpandByAcessingAt((int)index.IntegerValue); svSubArray = array.GetValueAt(absIndex); } catch (RunOutOfMemoryException) { runtimeCore.RuntimeStatus.LogWarning(WarningID.RunOutOfMemory, Resources.RunOutOfMemory); return(StackValue.Null); } } else { svSubArray = array.GetValueFromIndex(index, runtimeCore); } // auto-promotion if (!svSubArray.IsArray) { try { svSubArray = heap.AllocateArray(new StackValue[] { svSubArray }); } catch (RunOutOfMemoryException) { svSubArray = StackValue.Null; runtimeCore.RuntimeStatus.LogWarning(WarningID.RunOutOfMemory, Resources.RunOutOfMemory); } array.SetValueForIndex(index, svSubArray, runtimeCore); } array = heap.ToHeapObject <DSArray>(svSubArray); } return(array.SetValueForIndex(indices[indices.Length - 1], value, runtimeCore)); }