Added GC descriptors (lol, these are not descriptors).
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_jc_code_h_
19 #define _include_jc_code_h_
25 #include "FixedArray.h"
32 // A code object contains the bytecode compiled from a function (or global
33 // script), as well as all information needed to interpret or JIT-compile
35 class Code : public Object
37 Barriered<Module> module_;
38 Barriered<ByteArray> bytecode_;
39 Barriered<FixedArray> locals_;
40 Barriered<FixedArray> objects_;
41 unsigned maxStackDepth_;
44 static Code *New(Zone *zone, Handle<ByteArray> bytecode, Handle<FixedArray> locals,
45 Handle<FixedArray> objects, unsigned maxStackDepth, Handle<Module> module);
51 return bytecode_->raw();
54 return bytecode_->length();
56 Type *localType(size_t index) {
57 return Type::cast(locals_->at(index));
60 return locals_->length();
62 unsigned maxStackDepth() {
63 return maxStackDepth_;
65 Map *map(size_t index) {
66 return Map::cast(objects_->at(index));
68 Object *object(size_t index) {
69 return objects_->at(index);
73 static inline size_t offsetOfModule() {
74 return offsetof(Code, module_);
76 static inline size_t offsetOfBytecode() {
77 return offsetof(Code, bytecode_);
79 static inline size_t offsetOfLocals() {
80 return offsetof(Code, locals_);
82 static inline size_t offsetOfObjects() {
83 return offsetof(Code, objects_);
87 static Code *cast(Object *obj) {
88 assert(!obj || obj->is(MapKind_Code));
89 return reinterpret_cast<Code *>(obj);
95 #endif // _include_jc_code_h_