jitcraft/Code.h
changeset 13 627b6b94e774
parent 12 75e385f68b7e
child 14 0784ac5cc347
     1.1 --- a/jitcraft/Code.h	Sat Jun 30 19:38:53 2012 -0700
     1.2 +++ b/jitcraft/Code.h	Sat Jun 30 20:20:39 2012 -0700
     1.3 @@ -29,31 +29,17 @@
     1.4  class Module;
     1.5  class Type;
     1.6  
     1.7 +// A code object contains the bytecode compiled from a function (or global
     1.8 +// script), as well as all information needed to interpret or JIT-compile
     1.9 +// the bytecode.
    1.10  class Code : public Object
    1.11  {
    1.12 -    OBJECT_FIELD(ByteArray *, bytecode);
    1.13 -    OBJECT_FIELD(FixedArray *, locals);
    1.14 -    OBJECT_FIELD(FixedArray *, args);
    1.15 -    OBJECT_FIELD(uint32, maxStackDepth);
    1.16 -    OBJECT_FIELD(VoidPtr, module);
    1.17 -    OBJECT_FIELD(FixedArray *, maps);
    1.18 -
    1.19 -  private:
    1.20 -    void init(ByteArray *bytecode, FixedArray *locals, FixedArray *args,
    1.21 -              FixedArray *maps, unsigned maxStackDepth, Module *module);
    1.22 -
    1.23 -    ByteArray *code() {
    1.24 -        return ByteArray::cast(READ_FIELD_OBJ(bytecode));
    1.25 -    }
    1.26 -    FixedArray *locals() {
    1.27 -        return FixedArray::cast(READ_FIELD_OBJ(locals));
    1.28 -    }
    1.29 -    FixedArray *args() {
    1.30 -        return FixedArray::cast(READ_FIELD_OBJ(args));
    1.31 -    }
    1.32 -    FixedArray *maps() {
    1.33 -        return FixedArray::cast(READ_FIELD_OBJ(maps));
    1.34 -    }
    1.35 +    Module *module_;
    1.36 +    Unbarriered<ByteArray> bytecode_;
    1.37 +    Unbarriered<FixedArray> locals_;
    1.38 +    Unbarriered<FixedArray> args_;
    1.39 +    Unbarriered<FixedArray> maps_;
    1.40 +    unsigned maxStackDepth_;
    1.41  
    1.42    public:
    1.43      // :TODO: use handles
    1.44 @@ -61,33 +47,31 @@
    1.45                       FixedArray *maps, unsigned maxStackDepth, Module *module);
    1.46  
    1.47      Module *module() {
    1.48 -        return (Module *)READ_FIELD(module);
    1.49 +        return module_;
    1.50      }
    1.51      bytecode *start() {
    1.52 -        return code()->raw();
    1.53 +        return bytecode_->raw();
    1.54      }
    1.55      unsigned length() {
    1.56 -        return code()->length();
    1.57 +        return bytecode_->length();
    1.58      }
    1.59      Type *localType(size_t index) {
    1.60 -        assert(index < nlocals());
    1.61 -        return Type::cast(locals()->at(index));
    1.62 +        return Type::cast(locals_->at(index));
    1.63      }
    1.64      Type *argType(size_t index) {
    1.65 -        assert(index < nlocals());
    1.66 -        return Type::cast(args()->at(index));
    1.67 +        return Type::cast(args_->at(index));
    1.68      }
    1.69      unsigned nlocals() {
    1.70 -        return locals()->length();
    1.71 +        return locals_->length();
    1.72      }
    1.73      unsigned nargs() {
    1.74 -        return args()->length();
    1.75 +        return args_->length();
    1.76      }
    1.77      unsigned maxStackDepth() {
    1.78 -        return READ_FIELD(maxStackDepth);
    1.79 +        return maxStackDepth_;
    1.80      }
    1.81      Map *map(size_t index) {
    1.82 -        return Map::cast(maps()->at(index));
    1.83 +        return Map::cast(maps_->at(index));
    1.84      }
    1.85  
    1.86      static Code *cast(Object *obj) {