public static StackValue Repack(Obj obj, ProtoCore.DSASM.Heap heap) { if (obj.Type.IsIndexable) { //Unpack each of the elements DsasmArray arr = (DsasmArray)obj.Payload; StackValue[] sv = new StackValue[arr.members.Length]; //recurse over the array for (int i = 0; i < sv.Length; i++) sv[i] = Repack(arr.members[i], heap); int size = sv.Length; lock (heap.cslock) { int ptr = heap.Allocate(size); ++heap.Heaplist[ptr].Refcount; for (int n = size - 1; n >= 0; --n) { heap.Heaplist[ptr].Stack[n] = sv[n]; } StackValue overallSv = StackUtils.BuildArrayPointer(ptr); return overallSv; } } // For non-arrays, there is nothing to repack so just return the original stackvalue return obj.DsasmValue; }