src/compiler/BytecodeEmitter.h
changeset 230 fb3cd08bc7fb
parent 222 0cde1379b29f
child 234 26e3035cdffc
     1.1 --- a/src/compiler/BytecodeEmitter.h	Sat Dec 22 16:42:20 2012 -0800
     1.2 +++ b/src/compiler/BytecodeEmitter.h	Sat Dec 22 18:22:14 2012 -0800
     1.3 @@ -137,6 +137,8 @@
     1.4      StringTable strings_;
     1.5      Vector<Symbol *> locals_;
     1.6      Vector<Object *> objects_;
     1.7 +    unsigned loopDepth_;
     1.8 +    unsigned maxLoopDepth_;
     1.9  
    1.10    private:
    1.11      // The maximum size of a code object must be such that the distance between
    1.12 @@ -342,7 +344,8 @@
    1.13          if (oom())
    1.14              return;
    1.15  
    1.16 -        assert(op == OP_JT || op == OP_JF || op == OP_JUMP);
    1.17 +        assert(op == OP_JT || op == OP_JF || op == OP_JUMP ||
    1.18 +               op == OP_CONTINUE || op == OP_BREAK);
    1.19          ensure(OP_JUMP_LENGTH);
    1.20  
    1.21          if (label->bound()) {
    1.22 @@ -433,43 +436,30 @@
    1.23              markOop(1);
    1.24      }
    1.25  
    1.26 -#if 0
    1.27 -    void getglobal(Variable *var) {
    1.28 -        ensure(OP_GETGLOBAL_F_LENGTH);
    1.29 -        if (var->type()->isPrimitive()) {
    1.30 -            switch (var->type()->primitive()) {
    1.31 -              case PrimitiveType_Float:
    1.32 -                writeOp(OP_GETGLOBAL_F);
    1.33 -                break;
    1.34 -              default:
    1.35 -                assert(var->type()->primitive() == PrimitiveType_Int32);
    1.36 -                writeOp(OP_GETGLOBAL_I);
    1.37 -                break;
    1.38 -            }
    1.39 -        } else {
    1.40 -            writeOp(OP_GETGLOBAL_O);
    1.41 -            markOop(1);
    1.42 -        }
    1.43 -        writeUint32(var->slot());
    1.44 +    int enterloop() {
    1.45 +        int offset = position();
    1.46 +
    1.47 +        ensure(OP_ENTERLOOP);
    1.48 +        writeOp(OP_ENTERLOOP);
    1.49 +        writeUint8(0);
    1.50 +
    1.51 +        loopDepth_++;
    1.52 +        if (loopDepth_ > maxLoopDepth_)
    1.53 +            maxLoopDepth_ = loopDepth_;
    1.54 +
    1.55 +        return offset;
    1.56      }
    1.57 -    void setglobal(Variable *var) {
    1.58 -        ensure(OP_SETGLOBAL_F_LENGTH);
    1.59 -        if (var->type()->isPrimitive()) {
    1.60 -            switch (var->type()->primitive()) {
    1.61 -              case PrimitiveType_Float:
    1.62 -                writeOp(OP_SETGLOBAL_F);
    1.63 -                break;
    1.64 -              default:
    1.65 -                assert(var->type()->primitive() == PrimitiveType_Int32);
    1.66 -                writeOp(OP_SETGLOBAL_I);
    1.67 -                break;
    1.68 -            }
    1.69 -        } else {
    1.70 -            writeOp(OP_SETGLOBAL_O);
    1.71 -        }
    1.72 -        writeUint32(var->slot());
    1.73 +    void leaveloop() {
    1.74 +        singleByteOp(OP_LEAVELOOP);
    1.75 +
    1.76 +        assert(loopDepth_);
    1.77 +        loopDepth_--;
    1.78      }
    1.79 -#endif
    1.80 +    void setLoopUsesLifoStack(int pos) {
    1.81 +        assert(pos >= 0 && pos < position());
    1.82 +        assert(*(buffer() + pos) == OP_ENTERLOOP);
    1.83 +        *(buffer() + pos + 1) = 1;
    1.84 +    }
    1.85  
    1.86      void float_(float value) {
    1.87          ensure(OP_FLOAT_LENGTH);