Temporary checkin of rooting stuff (breaks build).
2 * Copyright (C) 2012 David Anderson
4 * This file is part of JITCraft.
6 * JITCraft is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3 of the License, or (at your option)
11 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * JITCraft. If not, see http://www.gnu.org/licenses/.
18 #ifndef _include_jitcraft_rooting_h_
19 #define _include_jitcraft_rooting_h_
27 template <typename T> class Local;
28 template <typename T> class ScopedRoot;
36 template <typename S> Handle(const Handle<S> &handle) {
38 thingp_ = reinterpret_cast<const T **>(handle.thingp_);
40 template <typename S> inline Handle(const Local<S> &local);
41 template <typename S> inline Handle(const ScopedRoot<S> &root);
50 operator T() { return *thingp_; }
51 operator bool() const {
52 return thingp_ && *thingp_;
79 Local<Object> *prev() {
82 Local<Object> *toRaw() {
83 return reinterpret_cast<Local<Object>*>(this);
87 inline explicit Local(Zone *zone);
88 inline explicit Local(Zone *zone, T *thing);
91 const Local &operator =(T *thing) {
95 T *operator ->() const {
98 T *operator *() const {
101 operator bool () const {
106 return (Object **)&thing_;
108 Object * const *addr() const {
109 return (Object * const *)&thing_;
116 // Disallow heap allocation.
117 void *operator new(size_t size);
118 void *operator new[](size_t size);
120 // Disallow copy construction.
121 Local(const Local<T> &other);
122 Local &operator =(const Local &other);
125 // A ScopedRoot is a special kind of handle for storing references on the
127 template <typename T>
133 inline T **make(const T *&other);
134 inline void assign(const T *&other) {
136 thingp_ = make(other);
144 inline ScopedRoot(const T *&thing);
145 inline ScopedRoot(const ScopedRoot<T> &other);
146 ScopedRoot &operator =(const ScopedRoot<T> &other) {
150 ScopedRoot &operator =(const T *&other) {
154 T *operator ->() const {
157 T *operator *() const {
160 operator bool () const {
165 template <typename T> template <typename S> inline
166 Handle<T>::Handle(const Local<S> &local)
169 thingp_ = reinterpret_cast<T * const*>(local.addr());
172 // A RootScope is necessary for using ScopedRoot<>.
179 static const size_t kItemsPerBlock = 4096 / sizeof(Object *);
186 Block(Block *prev, Object **base)
189 end(base + kItemsPerBlock),
201 #endif // _include_jitcraft_rooting_h_