src/Array.h
changeset 247 7721042bdb67
parent 234 26e3035cdffc
child 256 3c184218462d
     1.1 --- a/src/Array.h	Thu Dec 27 21:07:03 2012 -0800
     1.2 +++ b/src/Array.h	Fri Dec 28 17:13:51 2012 -0800
     1.3 @@ -32,6 +32,7 @@
     1.4  {
     1.5      friend class ArrayMap;
     1.6  
     1.7 +  protected:
     1.8      // Note: we do not write barrier |elements_|, since it can be set to
     1.9      // arbitrary pointers.
    1.10      uint32 length_;
    1.11 @@ -40,7 +41,7 @@
    1.12          Object *objelements_;
    1.13      };
    1.14  
    1.15 -  private:
    1.16 +  protected:
    1.17      void updateLengthAndElements(Zone *zone, unsigned length, Object *array) {
    1.18          length_ = length;
    1.19          write(zone, &objelements_, array);
    1.20 @@ -134,19 +135,50 @@
    1.21      // End GC Descriptor.
    1.22  
    1.23      static Array *cast(Object *obj) {
    1.24 -        assert(!obj || obj->is(MapKind_Array));
    1.25 +        assert(!obj ||
    1.26 +               obj->is(MapKind_Array) ||
    1.27 +               obj->is(MapKind_DependentArray));
    1.28          return reinterpret_cast<Array *>(obj);
    1.29      }
    1.30  };
    1.31  
    1.32 +class DependentArray : public Array
    1.33 +{
    1.34 +    Barriered<Array> root_;
    1.35 +
    1.36 +  public:
    1.37 +    static Array *New(Zone *zone, Handle<Array> source, Handle<ArrayMap> map, unsigned index);
    1.38 +
    1.39 +    // GC Descriptor.
    1.40 +    static inline size_t offsetOfRoot() {
    1.41 +        return offsetof(DependentArray, root_);
    1.42 +    }
    1.43 +    // End GC Descriptor.
    1.44 +
    1.45 +    static DependentArray *cast(Object *obj) {
    1.46 +        assert(!obj || obj->is(MapKind_DependentArray));
    1.47 +        return reinterpret_cast<DependentArray *>(obj);
    1.48 +    }
    1.49 +};
    1.50 +
    1.51  class ArrayMap : public Map
    1.52  {
    1.53      Barriered<ArrayType> type_;
    1.54  
    1.55    public:
    1.56 +    // The way array maps work is kind of clownshoes. In the future, these
    1.57 +    // should be created immediately (or lazily) on the Type directly, and not
    1.58 +    // manually created via ::Attach. :TODO: do this when we begin caching
    1.59 +    // array types.
    1.60      static ArrayMap *New(Zone *zone, Handle<ArrayType> type);
    1.61      static ArrayMap *Attach(Zone *zone, Handle<ArrayType> type);
    1.62  
    1.63 +    // DependentArray maps are never attached, and are just free-floating,
    1.64 +    // rooted ultimately by the bytecode. A :TODO: that we might need to
    1.65 +    // cache these, or attach them somewhere saner like ArrayType, which
    1.66 +    // itself will eventually be cached.
    1.67 +    static ArrayMap *NewDependent(Zone *zone, Handle<ArrayType> type);
    1.68 +
    1.69      ArrayType *type() {
    1.70          return type_;
    1.71      }
    1.72 @@ -169,6 +201,7 @@
    1.73      assert(!type()->contained()->isTraceable());
    1.74      assert(type()->hasInlineElements() ||
    1.75             type()->isExternalArray() ||
    1.76 +           is(MapKind_DependentArray) ||
    1.77             !length() ||
    1.78             ByteArray::cast((Object *)elements_));
    1.79