1.1 --- a/src/Interpreter.cpp Sun Aug 05 00:31:20 2012 -0700
1.2 +++ b/src/Interpreter.cpp Sun Aug 05 00:45:06 2012 -0700
1.3 @@ -81,19 +81,41 @@
1.4 return true;
1.5 }
1.6
1.7 +static bool CopyStruct(Zone *zone, Struct *left, Struct *right);
1.8 +
1.9 // Even though this function can fail, we immediately bail out, so it doesn't
1.10 // matter if we've leaving things unrooted.
1.11 static bool
1.12 CopyArray(Zone *zone, Array *source, Array *dest)
1.13 {
1.14 - assert(source->type()->levels() == 1);
1.15 - assert(dest->type()->levels() == 1);
1.16 - assert(source->type()->contained()->primitive() ==
1.17 - dest->type()->contained()->primitive());
1.18 - assert(source->nelements() >= dest->nelements());
1.19 - assert(dest->elementSize() == source->elementSize());
1.20 + if (source->type()->contained()->isArray()) {
1.21 + assert(dest->type()->contained()->isArray());
1.22 + assert(source->length() == dest->length());
1.23 +
1.24 + for (unsigned i = 0; i < source->length(); i++) {
1.25 + Array *left = Array::cast(source->readObject(i));
1.26 + Array *right = Array::cast(dest->readObject(i));
1.27 + if (!CopyArray(zone, left, right))
1.28 + return false;
1.29 + }
1.30 + } else if (source->type()->contained()->isStruct()) {
1.31 + assert(dest->type()->contained() == source->type()->contained());
1.32 + assert(source->length() == dest->length());
1.33
1.34 - memcpy(source->vec(), dest->vec(), dest->nelements() * dest->elementSize());
1.35 + for (unsigned i = 0; i < source->length(); i++) {
1.36 + Struct *left = Struct::cast(source->readObject(i));
1.37 + Struct *right = Struct::cast(dest->readObject(i));
1.38 + if (!CopyStruct(zone, left, right))
1.39 + return false;
1.40 + }
1.41 + } else {
1.42 + assert(source->type()->pod() == dest->type()->pod());
1.43 + assert(source->type()->pod() == PrimitiveType_Char
1.44 + ? source->length() >= dest->length()
1.45 + : source->length() == dest->length());
1.46 +
1.47 + memcpy(source->vec(), dest->vec(), dest->length() * dest->elementSize());
1.48 + }
1.49 return true;
1.50 }
1.51
1.52 @@ -673,8 +695,8 @@
1.53 {
1.54 Array *array = top.sp[-2].array;
1.55 int index = top.sp[-1].i32;
1.56 - if (index < 0 || unsigned(index) >= array->nelements()) {
1.57 - zone->reportError(Message_ArrayIndexOutOfBounds, index, array->nelements());
1.58 + if (index < 0 || unsigned(index) >= array->length()) {
1.59 + zone->reportError(Message_ArrayIndexOutOfBounds, index, array->length());
1.60 goto error;
1.61 }
1.62 break;