jitcraft/Objects.h
changeset 87 f8ac2633b4e3
parent 86 32ad0523b309
child 88 fc3f34f928dd
     1.1 --- a/jitcraft/Objects.h	Tue Jul 24 23:53:34 2012 -0700
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,119 +0,0 @@
     1.4 -/* vim: set ts=4 sw=4 tw=99 et:
     1.5 - *
     1.6 - * Copyright (C) 2012 David Anderson
     1.7 - *
     1.8 - * This file is part of JITCraft.
     1.9 - *
    1.10 - * JITCraft is free software: you can redistribute it and/or modify it under
    1.11 - * the terms of the GNU General Public License as published by the Free
    1.12 - * Software Foundation, either version 3 of the License, or (at your option)
    1.13 - * any later version.
    1.14 - * 
    1.15 - * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
    1.16 - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.17 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    1.18 - *
    1.19 - * You should have received a copy of the GNU General Public License along with
    1.20 - * JITCraft. If not, see http://www.gnu.org/licenses/.
    1.21 - */
    1.22 -#ifndef _include_jitcraft_objects_h_
    1.23 -#define _include_jitcraft_objects_h_
    1.24 -
    1.25 -#include "Utility.h"
    1.26 -#include "Spaces.h"
    1.27 -#include "Barriers.h"
    1.28 -
    1.29 -namespace ke {
    1.30 -
    1.31 -class Zone;
    1.32 -
    1.33 -// Garbage-collection objects require a header to describe their layout. This
    1.34 -// header is called a "map". The different kinds of maps are enumerated below.
    1.35 -class Map;
    1.36 -
    1.37 -enum MapKind
    1.38 -{
    1.39 -    // Represents Type objects.
    1.40 -    MapKind_Type,
    1.41 -
    1.42 -    // Represents basic data structures. When adding to this, don't forget
    1.43 -    // to update Zone::initialize(), or you'll get a NULL crash trying to
    1.44 -    // allocate, since these maps are cached.
    1.45 -    MapKind_FixedArray,
    1.46 -    MapKind_ByteArray,
    1.47 -    MapKind_Code,
    1.48 -    MapKind_Reference,
    1.49 -    MapKind_Module,
    1.50 -    MapKind_Function,
    1.51 -    MapKind_String,
    1.52 -    MapKind_Native,
    1.53 -    MapKind_FreeRegion,     // Special map denoting freed space.
    1.54 -    MapKind_EnvironmentSlotDescriptorArray,
    1.55 -    MapKind_Environment,
    1.56 -
    1.57 -    // Used to represent Arrays. This does not have a canonical map.
    1.58 -    MapKind_Array,
    1.59 -
    1.60 -    // These represent special Map subclasses that require special tracing.
    1.61 -    MapKinds_Special,
    1.62 -    MapKind_Meta,               // (default map class)
    1.63 -    MapKind_MetaArray,          // ArrayMap instances
    1.64 -    MapKind_MetaEnvironment,    // EnvironmentMap instances
    1.65 -    MapKinds_EndSpecial,
    1.66 -
    1.67 -    MapKinds_Total
    1.68 -};
    1.69 -
    1.70 -// All garbage collected objects must inherit from GCObject. Note that using
    1.71 -// virtual functions is illegal, as the |map| field would be displaced.
    1.72 -class Object
    1.73 -{
    1.74 -    Barriered<Map> map_;
    1.75 -
    1.76 -  public:
    1.77 -    void init(Map *map) {
    1.78 -        map_ = map;
    1.79 -    }
    1.80 -
    1.81 -    Map *map() {
    1.82 -        return map_;
    1.83 -    }
    1.84 -    inline bool is(MapKind map);
    1.85 -
    1.86 -    inline void write(Zone *zone, Object **ptr, Object *value);
    1.87 -
    1.88 -    static inline size_t offsetOfMap() {
    1.89 -        return offsetof(Object, map_);
    1.90 -    }
    1.91 -};
    1.92 -
    1.93 -// Maps describe the layout of GCObjects. Every GCObject requires a map.
    1.94 -class Map : public Object
    1.95 -{
    1.96 -    MapKind kind_;
    1.97 -
    1.98 -  public:
    1.99 -    void setKind(MapKind kind) {
   1.100 -        kind_ = kind;
   1.101 -    }
   1.102 -    MapKind kind() {
   1.103 -        return kind_;
   1.104 -    }
   1.105 -
   1.106 -    static inline Map *cast(Object *obj) {
   1.107 -        // Note that ArrayMap is a map, but a special one: since it is non-
   1.108 -        assert(obj->map()->kind() > MapKinds_Special &&
   1.109 -               obj->map()->kind() < MapKinds_EndSpecial);
   1.110 -        return reinterpret_cast<Map *>(obj);
   1.111 -    }
   1.112 -};
   1.113 -
   1.114 -inline bool
   1.115 -Object::is(MapKind kind)
   1.116 -{
   1.117 -    return map()->kind() == kind;
   1.118 -}
   1.119 -
   1.120 -}
   1.121 -
   1.122 -#endif //_include_jitcraft_objects_h_