/// <summary> /// = array[index] /// </summary> /// <param name="array"></param> /// <param name="index"></param> /// <param name="core"></param> /// <returns></returns> public static StackValue GetValueFromIndex(StackValue array, int index, RuntimeCore runtimeCore) { Validity.Assert(array.IsArray || array.IsString); RuntimeMemory rmem = runtimeCore.RuntimeMemory; if (array.IsString) { string str = rmem.Heap.GetString(array); if (str == null) { return(StackValue.Null); } if (index < 0) { index = index + str.Length; } if (index >= str.Length || index < 0) { runtimeCore.RuntimeStatus.LogWarning(ProtoCore.Runtime.WarningID.kOverIndexing, Resources.kArrayOverIndexed); return(StackValue.Null); } return(rmem.Heap.AllocateString(str.Substring(index, 1))); } else { HeapElement he = GetHeapElement(array, runtimeCore); return(StackUtils.GetValue(he, index, runtimeCore)); } }
/// <summary> /// = array[index] /// </summary> /// <param name="array"></param> /// <param name="index"></param> /// <param name="core"></param> /// <returns></returns> public static StackValue GetValueFromIndex(StackValue array, int index, Core core) { Validity.Assert(array.IsArray || array.IsString); if (!array.IsArray && !array.IsString) { return(StackValue.Null); } HeapElement he = GetHeapElement(array, core); return(StackUtils.GetValue(he, index, core)); }
/// <summary> /// = array[index] /// </summary> /// <param name="array"></param> /// <param name="index"></param> /// <param name="core"></param> /// <returns></returns> public static StackValue GetValueFromIndex(StackValue array, int index, Core core) { Validity.Assert(StackUtils.IsArray(array) || StackUtils.IsString(array)); if (!StackUtils.IsArray(array) && !StackUtils.IsString(array)) { return(StackUtils.BuildNull()); } HeapElement he = GetHeapElement(array, core); return(StackUtils.GetValue(he, index, core)); }
public static StackValue GetArrayElement(StackValue svPtr, List <StackValue> svDimList, Core core) { Validity.Assert(IsArray(svPtr)); HeapElement heapElem = null; StackValue svFinal = StackUtils.BuildNull(); foreach (StackValue sv in svDimList) { if (svPtr.optype != AddressType.ArrayPointer) { core.RuntimeStatus.LogWarning(RuntimeData.WarningID.kOverIndexing, ProtoCore.RuntimeData.WarningMessage.kArrayOverIndexed); return(StackUtils.BuildNull()); } heapElem = core.Heap.Heaplist[(int)svPtr.opdata]; svPtr = StackUtils.GetValue(heapElem, (int)sv.opdata, core); svFinal = svPtr; } return(svFinal); }