Refactored Array, Code to be Objects. Removed Object tagging.
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 class Code : public Object
34 OBJECT_FIELD(ByteArray *, bytecode);
35 OBJECT_FIELD(FixedArray *, locals);
36 OBJECT_FIELD(FixedArray *, args);
37 OBJECT_FIELD(uint32, maxStackDepth);
38 OBJECT_FIELD(VoidPtr, module);
39 OBJECT_FIELD(FixedArray *, maps);
42 void init(ByteArray *bytecode, FixedArray *locals, FixedArray *args,
43 FixedArray *maps, unsigned maxStackDepth, Module *module);
46 return ByteArray::cast(READ_FIELD_OBJ(bytecode));
48 FixedArray *locals() {
49 return FixedArray::cast(READ_FIELD_OBJ(locals));
52 return FixedArray::cast(READ_FIELD_OBJ(args));
55 return FixedArray::cast(READ_FIELD_OBJ(maps));
60 static Code *New(Zone *zone, ByteArray *bytecode, FixedArray *locals, FixedArray *args,
61 FixedArray *maps, unsigned maxStackDepth, Module *module);
64 return (Module *)READ_FIELD(module);
70 return code()->length();
72 Type *localType(size_t index) {
73 assert(index < nlocals());
74 return Type::cast(locals()->at(index));
76 Type *argType(size_t index) {
77 assert(index < nlocals());
78 return Type::cast(args()->at(index));
81 return locals()->length();
84 return args()->length();
86 unsigned maxStackDepth() {
87 return READ_FIELD(maxStackDepth);
89 Map *map(size_t index) {
90 return Map::cast(maps()->at(index));
93 static Code *cast(Object *obj) {
94 assert(obj->is(MapKind_Code));
95 return reinterpret_cast<Code *>(obj);
101 #endif // _include_jc_code_h_