/// <summary> /// Try to get value for key from nested dictionaries. This function is /// used in the case that indexing into dictionaries that returned from /// a replicated function whose return type is dictionary. /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <param name="core"></param> /// <returns></returns> public bool TryGetValueFromNestedDictionaries(StackValue key, out StackValue value, RuntimeCore runtimeCore) { if (Dict != null && Dict.TryGetValue(key, out value)) { return(true); } var values = new List <StackValue>(); bool hasValue = false; foreach (var element in Values) { if (!(element.IsArray)) { continue; } StackValue valueInElement; DSArray subArray = heap.ToHeapObject <DSArray>(element); if (subArray.TryGetValueFromNestedDictionaries(key, out valueInElement, runtimeCore)) { hasValue = true; values.Add(valueInElement); } } if (hasValue) { try { value = heap.AllocateArray(values.ToArray()); return(true); } catch (RunOutOfMemoryException) { value = StackValue.Null; runtimeCore.RuntimeStatus.LogWarning(WarningID.RunOutOfMemory, Resources.RunOutOfMemory); return(false); } } else { value = StackValue.Null; return(false); } }
/// <summary> /// Try to get value for key from nested dictionaries. This function is /// used in the case that indexing into dictionaries that returned from /// a replicated function whose return type is dictionary. /// </summary> /// <param name="key"></param> /// <param name="value"></param> /// <param name="core"></param> /// <returns></returns> public bool TryGetValueFromNestedDictionaries(StackValue key, out StackValue value, RuntimeCore runtimeCore) { if (Dict != null && Dict.TryGetValue(key, out value)) { return(true); } var values = new List <StackValue>(); bool hasValue = false; foreach (var element in VisibleItems) { if (!(element.IsArray)) { continue; } StackValue valueInElement; DSArray subArray = heap.ToHeapObject <DSArray>(element); if (subArray.TryGetValueFromNestedDictionaries(key, out valueInElement, runtimeCore)) { hasValue = true; values.Add(valueInElement); } } if (hasValue) { value = heap.AllocateArray(values); return(true); } else { value = StackValue.Null; return(false); } }