diff -r 32ad0523b309 -r f8ac2633b4e3 jitcraft/Objects.h --- a/jitcraft/Objects.h Tue Jul 24 23:53:34 2012 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +0,0 @@ -/* vim: set ts=4 sw=4 tw=99 et: - * - * Copyright (C) 2012 David Anderson - * - * This file is part of JITCraft. - * - * JITCraft is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free - * Software Foundation, either version 3 of the License, or (at your option) - * any later version. - * - * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with - * JITCraft. If not, see http://www.gnu.org/licenses/. - */ -#ifndef _include_jitcraft_objects_h_ -#define _include_jitcraft_objects_h_ - -#include "Utility.h" -#include "Spaces.h" -#include "Barriers.h" - -namespace ke { - -class Zone; - -// Garbage-collection objects require a header to describe their layout. This -// header is called a "map". The different kinds of maps are enumerated below. -class Map; - -enum MapKind -{ - // Represents Type objects. - MapKind_Type, - - // Represents basic data structures. When adding to this, don't forget - // to update Zone::initialize(), or you'll get a NULL crash trying to - // allocate, since these maps are cached. - MapKind_FixedArray, - MapKind_ByteArray, - MapKind_Code, - MapKind_Reference, - MapKind_Module, - MapKind_Function, - MapKind_String, - MapKind_Native, - MapKind_FreeRegion, // Special map denoting freed space. - MapKind_EnvironmentSlotDescriptorArray, - MapKind_Environment, - - // Used to represent Arrays. This does not have a canonical map. - MapKind_Array, - - // These represent special Map subclasses that require special tracing. - MapKinds_Special, - MapKind_Meta, // (default map class) - MapKind_MetaArray, // ArrayMap instances - MapKind_MetaEnvironment, // EnvironmentMap instances - MapKinds_EndSpecial, - - MapKinds_Total -}; - -// All garbage collected objects must inherit from GCObject. Note that using -// virtual functions is illegal, as the |map| field would be displaced. -class Object -{ - Barriered map_; - - public: - void init(Map *map) { - map_ = map; - } - - Map *map() { - return map_; - } - inline bool is(MapKind map); - - inline void write(Zone *zone, Object **ptr, Object *value); - - static inline size_t offsetOfMap() { - return offsetof(Object, map_); - } -}; - -// Maps describe the layout of GCObjects. Every GCObject requires a map. -class Map : public Object -{ - MapKind kind_; - - public: - void setKind(MapKind kind) { - kind_ = kind; - } - MapKind kind() { - return kind_; - } - - static inline Map *cast(Object *obj) { - // Note that ArrayMap is a map, but a special one: since it is non- - assert(obj->map()->kind() > MapKinds_Special && - obj->map()->kind() < MapKinds_EndSpecial); - return reinterpret_cast(obj); - } -}; - -inline bool -Object::is(MapKind kind) -{ - return map()->kind() == kind; -} - -} - -#endif //_include_jitcraft_objects_h_