diff -r 75e385f68b7e -r 627b6b94e774 jitcraft/Code.h --- a/jitcraft/Code.h Sat Jun 30 19:38:53 2012 -0700 +++ b/jitcraft/Code.h Sat Jun 30 20:20:39 2012 -0700 @@ -29,31 +29,17 @@ class Module; class Type; +// A code object contains the bytecode compiled from a function (or global +// script), as well as all information needed to interpret or JIT-compile +// the bytecode. class Code : public Object { - OBJECT_FIELD(ByteArray *, bytecode); - OBJECT_FIELD(FixedArray *, locals); - OBJECT_FIELD(FixedArray *, args); - OBJECT_FIELD(uint32, maxStackDepth); - OBJECT_FIELD(VoidPtr, module); - OBJECT_FIELD(FixedArray *, maps); - - private: - void init(ByteArray *bytecode, FixedArray *locals, FixedArray *args, - FixedArray *maps, unsigned maxStackDepth, Module *module); - - ByteArray *code() { - return ByteArray::cast(READ_FIELD_OBJ(bytecode)); - } - FixedArray *locals() { - return FixedArray::cast(READ_FIELD_OBJ(locals)); - } - FixedArray *args() { - return FixedArray::cast(READ_FIELD_OBJ(args)); - } - FixedArray *maps() { - return FixedArray::cast(READ_FIELD_OBJ(maps)); - } + Module *module_; + Unbarriered bytecode_; + Unbarriered locals_; + Unbarriered args_; + Unbarriered maps_; + unsigned maxStackDepth_; public: // :TODO: use handles @@ -61,33 +47,31 @@ FixedArray *maps, unsigned maxStackDepth, Module *module); Module *module() { - return (Module *)READ_FIELD(module); + return module_; } bytecode *start() { - return code()->raw(); + return bytecode_->raw(); } unsigned length() { - return code()->length(); + return bytecode_->length(); } Type *localType(size_t index) { - assert(index < nlocals()); - return Type::cast(locals()->at(index)); + return Type::cast(locals_->at(index)); } Type *argType(size_t index) { - assert(index < nlocals()); - return Type::cast(args()->at(index)); + return Type::cast(args_->at(index)); } unsigned nlocals() { - return locals()->length(); + return locals_->length(); } unsigned nargs() { - return args()->length(); + return args_->length(); } unsigned maxStackDepth() { - return READ_FIELD(maxStackDepth); + return maxStackDepth_; } Map *map(size_t index) { - return Map::cast(maps()->at(index)); + return Map::cast(maps_->at(index)); } static Code *cast(Object *obj) {