1.1 --- a/src/Structures.cpp Mon Sep 17 00:10:01 2012 -0700
1.2 +++ b/src/Structures.cpp Sat Nov 17 18:41:01 2012 -0800
1.3 @@ -51,7 +51,7 @@
1.4 }
1.5
1.6 Descriptor *
1.7 -Descriptor::New(Zone *zone, Handle<String> name, Handle<Type> type, unsigned offset)
1.8 +Descriptor::New(Zone *zone, Handle<String> name, Handle<Type> type)
1.9 {
1.10 Local<Descriptor> desc(zone,
1.11 Descriptor::cast(zone->allocate(MapKind_Descriptor, sizeof(Descriptor), Heap::Tenure_Old)));
1.12 @@ -60,13 +60,31 @@
1.13
1.14 desc->name_ = name;
1.15 desc->type_ = type;
1.16 - desc->offset_ = offset;
1.17 + desc->offset_ = unsigned(-1);
1.18 return desc;
1.19 }
1.20
1.21 StructMap *
1.22 -StructMap::New(Zone *zone, const StructureBufferBuilder &builder, Handle<FixedArray> composed)
1.23 +StructMap::New(Zone *zone, const StructureBufferBuilder &builder, Handle<StructType> type)
1.24 {
1.25 + Vector<unsigned> composedIndexes;
1.26 + for (size_t i = 0; i < type->fields()->length(); i++) {
1.27 + Descriptor *desc = Descriptor::cast(type->fields()->at(i));
1.28 + if (desc->type()->isArray() || desc->type()->isStruct()) {
1.29 + if (!composedIndexes.append(i))
1.30 + return NULL;
1.31 + }
1.32 + }
1.33 +
1.34 + Local<FixedArray> composed(zone, FixedArray::New(zone, composedIndexes.length(), Heap::Tenure_Old));
1.35 + if (!composed)
1.36 + return NULL;
1.37 +
1.38 + for (size_t i = 0; i < composedIndexes.length(); i++) {
1.39 + Descriptor *desc = Descriptor::cast(type->fields()->at(composedIndexes[i]));
1.40 + composed->set(zone, i, desc);
1.41 + }
1.42 +
1.43 size_t bytesNeeded = sizeof(StructMap) +
1.44 (builder.traceableOffsetCount() * sizeof(unsigned));
1.45
1.46 @@ -77,7 +95,7 @@
1.47
1.48 map->structureSize_ = builder.structureSize();
1.49 map->traceOffsetCount_ = builder.traceableOffsetCount();
1.50 - map->type_ = NULL;
1.51 + map->type_ = type;
1.52 map->composed_ = composed;
1.53 memcpy(const_cast<unsigned *>(map->traceOffsets()), builder.offsets(),
1.54 sizeof(unsigned) * builder.traceableOffsetCount());
1.55 @@ -107,14 +125,17 @@
1.56 desc = Descriptor::cast(map->composed()->at(i));
1.57
1.58 if (desc->type()->isStruct()) {
1.59 - childStructMap = StructMap::cast(desc->type()->newMap());
1.60 + childStructMap = StructMap::cast(StructType::cast(desc->type())->newMap());
1.61 child = Struct::New(zone, childStructMap, tenure);
1.62 } else if (desc->type()->isArray()) {
1.63 + assert(false);
1.64 +#if 0
1.65 childArrayMap = ArrayMap::cast(desc->type()->newMap());
1.66 if (desc->type()->isFixedLength())
1.67 child = Array::NewFixed(zone, childArrayMap, tenure);
1.68 else
1.69 child = Array::NewEmpty(zone, childArrayMap, tenure);
1.70 +#endif
1.71 }
1.72 if (!child)
1.73 return NULL;